Commit ae58a997 authored by mattwire's avatar mattwire
Browse files

Convert to short array syntax

parent cfb858c3
......@@ -39,7 +39,7 @@ class CRM_AdvancedEvents_BAO_Query extends CRM_Core_BAO_Query {
*
* @var array
*/
public static $_openedPanes = array();
public static $_openedPanes = [];
/**
* The various search modes.
......@@ -103,11 +103,11 @@ class CRM_AdvancedEvents_BAO_Query extends CRM_Core_BAO_Query {
) {
$this->_params = &$params;
if ($this->_params == NULL) {
$this->_params = array();
$this->_params = [];
}
if ($returnProperties === self::NO_RETURN_PROPERTIES) {
$this->_returnProperties = array();
$this->_returnProperties = [];
}
elseif (empty($returnProperties)) {
$this->_returnProperties = self::defaultReturnProperties();
......@@ -138,7 +138,7 @@ class CRM_AdvancedEvents_BAO_Query extends CRM_Core_BAO_Query {
* @param $operator
*/
public function setOperator($operator) {
$validOperators = array('AND', 'OR');
$validOperators = ['AND', 'OR'];
if (!in_array($operator, $validOperators)) {
$operator = 'AND';
}
......@@ -153,16 +153,16 @@ class CRM_AdvancedEvents_BAO_Query extends CRM_Core_BAO_Query {
* This sort-of duplicates $mode in a confusing way. Probably not by design.
*/
public function initialize($apiEntity = NULL) {
$this->_select = array();
$this->_element = array();
$this->_tables = array();
$this->_whereTables = array();
$this->_where = array();
$this->_qill = array();
$this->_options = array();
$this->_cfIDs = array();
$this->_paramLookup = array();
$this->_having = array();
$this->_select = [];
$this->_element = [];
$this->_tables = [];
$this->_whereTables = [];
$this->_where = [];
$this->_qill = [];
$this->_options = [];
$this->_cfIDs = [];
$this->_paramLookup = [];
$this->_having = [];
$this->_customQuery = NULL;
......@@ -206,7 +206,7 @@ class CRM_AdvancedEvents_BAO_Query extends CRM_Core_BAO_Query {
$cfID = CRM_Core_BAO_CustomField::getKeyID($value[0]);
if ($cfID) {
if (!array_key_exists($cfID, $this->_cfIDs)) {
$this->_cfIDs[$cfID] = array();
$this->_cfIDs[$cfID] = [];
}
// Set wildcard value based on "and/or" selection
foreach ($this->_params as $key => $param) {
......@@ -219,7 +219,7 @@ class CRM_AdvancedEvents_BAO_Query extends CRM_Core_BAO_Query {
}
if (!array_key_exists($value[0], $this->_paramLookup)) {
$this->_paramLookup[$value[0]] = array();
$this->_paramLookup[$value[0]] = [];
}
if ($value[0] !== 'group') {
// Just trying to unravel how group interacts here! This whole function is weird.
......@@ -282,7 +282,7 @@ class CRM_AdvancedEvents_BAO_Query extends CRM_Core_BAO_Query {
if ($cfID) {
// add to cfIDs array if not present
if (!array_key_exists($cfID, $this->_cfIDs)) {
$this->_cfIDs[$cfID] = array();
$this->_cfIDs[$cfID] = [];
}
}
}
......@@ -291,7 +291,7 @@ class CRM_AdvancedEvents_BAO_Query extends CRM_Core_BAO_Query {
// this is a custom field with range search enabled, so we better check for two/from values
if (!empty($this->_paramLookup[$name . '_from'])) {
if (!array_key_exists($cfID, $this->_cfIDs)) {
$this->_cfIDs[$cfID] = array();
$this->_cfIDs[$cfID] = [];
}
foreach ($this->_paramLookup[$name . '_from'] as $pID => $p) {
// search in the cdID array for the same grouping
......@@ -303,14 +303,14 @@ class CRM_AdvancedEvents_BAO_Query extends CRM_Core_BAO_Query {
}
}
if (!$fnd) {
$p[2] = array('from' => $p[2]);
$p[2] = ['from' => $p[2]];
$this->_cfIDs[$cfID][] = $p;
}
}
}
if (!empty($this->_paramLookup[$name . '_to'])) {
if (!array_key_exists($cfID, $this->_cfIDs)) {
$this->_cfIDs[$cfID] = array();
$this->_cfIDs[$cfID] = [];
}
foreach ($this->_paramLookup[$name . '_to'] as $pID => $p) {
// search in the cdID array for the same grouping
......@@ -322,7 +322,7 @@ class CRM_AdvancedEvents_BAO_Query extends CRM_Core_BAO_Query {
}
}
if (!$fnd) {
$p[2] = array('to' => $p[2]);
$p[2] = ['to' => $p[2]];
$this->_cfIDs[$cfID][] = $p;
}
}
......@@ -356,8 +356,8 @@ class CRM_AdvancedEvents_BAO_Query extends CRM_Core_BAO_Query {
* @return string
*/
public function whereClause($apiEntity = NULL) {
$this->_where[0] = array();
$this->_qill[0] = array();
$this->_where[0] = [];
$this->_qill[0] = [];
if (!empty($this->_params)) {
foreach (array_keys($this->_params) as $id) {
......@@ -372,8 +372,8 @@ class CRM_AdvancedEvents_BAO_Query extends CRM_Core_BAO_Query {
//CRM_Contact_BAO_Query_Hook::singleton()->alterSearchQuery($this, 'where');
}
$clauses = array();
$andClauses = array();
$clauses = [];
$andClauses = [];
$validClauses = 0;
if (!empty($this->_where)) {
......@@ -457,7 +457,7 @@ class CRM_AdvancedEvents_BAO_Query extends CRM_Core_BAO_Query {
$tempTable[$k . ".$key"] = $key;
}
ksort($tempTable);
$newTables = array();
$newTables = [];
foreach ($tempTable as $key) {
$newTables[$key] = $tables[$key];
}
......@@ -511,9 +511,9 @@ class CRM_AdvancedEvents_BAO_Query extends CRM_Core_BAO_Query {
}
// pane name to table mapper
$panesMapper = array(
$panesMapper = [
ts('Events') => 'civicrm_event',
);
];
CRM_Contact_BAO_Query_Hook::singleton()->getPanesMapper($panesMapper);
foreach (array_keys($this->_whereTables) as $table) {
......@@ -534,9 +534,9 @@ class CRM_AdvancedEvents_BAO_Query extends CRM_Core_BAO_Query {
* Associative array of contribution fields
*/
public static function &getFields($checkPermission = TRUE) {
return array (
return [
'event_title' =>
array (
[
'name' => 'title',
'type' => 2,
'title' => 'Event Title',
......@@ -553,12 +553,12 @@ class CRM_AdvancedEvents_BAO_Query extends CRM_Core_BAO_Query {
'bao' => 'CRM_Event_BAO_Event',
'localizable' => 1,
'html' =>
array (
[
'type' => 'Text',
),
),
],
],
'event_start_date' =>
array (
[
'name' => 'start_date',
'type' => 12,
'title' => 'Event Start Date',
......@@ -573,13 +573,13 @@ class CRM_AdvancedEvents_BAO_Query extends CRM_Core_BAO_Query {
'bao' => 'CRM_Event_BAO_Event',
'localizable' => 0,
'html' =>
array (
[
'type' => 'Select Date',
'formatType' => 'activityDateTime',
),
),
],
],
'event_end_date' =>
array (
[
'name' => 'end_date',
'type' => 12,
'title' => 'Event End Date',
......@@ -594,12 +594,12 @@ class CRM_AdvancedEvents_BAO_Query extends CRM_Core_BAO_Query {
'bao' => 'CRM_Event_BAO_Event',
'localizable' => 0,
'html' =>
array (
[
'type' => 'Select Date',
'formatType' => 'activityDateTime',
),
),
);
],
],
];
}
/**
......@@ -720,7 +720,7 @@ class CRM_AdvancedEvents_BAO_Query extends CRM_Core_BAO_Query {
$thisEventHasParent = CRM_Core_BAO_RecurringEntity::getParentFor($value, 'civicrm_event');
if ($thisEventHasParent) {
$getAllConnections = CRM_Core_BAO_RecurringEntity::getEntitiesForParent($thisEventHasParent, 'civicrm_event');
$allEventIds = array();
$allEventIds = [];
foreach ($getAllConnections as $key => $val) {
$allEventIds[] = $val['id'];
}
......@@ -739,11 +739,11 @@ class CRM_AdvancedEvents_BAO_Query extends CRM_Core_BAO_Query {
case 'event_type_id':
case 'event_title':
$qillName = $name;
if (in_array($name, array(
if (in_array($name, [
'event_id',
'event_title',
'event_is_public',
)
]
)
) {
$name = str_replace('event_', '', $name);
......@@ -755,8 +755,8 @@ class CRM_AdvancedEvents_BAO_Query extends CRM_Core_BAO_Query {
if (!array_key_exists($qillName, $fields)) {
break;
}
list($op, $value) = CRM_Contact_BAO_Query::buildQillForFieldValue('CRM_Event_DAO_Event', $name, $value, $op, array('check_permission' => $checkPermission));
$query->_qill[$grouping][] = ts('%1 %2 %3', array(1 => $fields[$qillName]['title'], 2 => $op, 3 => $value));
list($op, $value) = CRM_Contact_BAO_Query::buildQillForFieldValue('CRM_Event_DAO_Event', $name, $value, $op, ['check_permission' => $checkPermission]);
$query->_qill[$grouping][] = ts('%1 %2 %3', [1 => $fields[$qillName]['title'], 2 => $op, 3 => $value]);
return;
}
}
......@@ -924,7 +924,7 @@ class CRM_AdvancedEvents_BAO_Query extends CRM_Core_BAO_Query {
// ideally this code would be removed as it appears to be to support CRM-1203
// and passing in the required returnProperties from the url would
// make more sense that globally applying the requirements of one form.
if (($this->_returnProperties != array('contact_id'))) {
if (($this->_returnProperties != ['contact_id'])) {
$this->_select['group_contact_id'] = "$tbName.id as group_contact_id";
$this->_element['group_contact_id'] = 1;
$this->_select['status'] = "$tbName.status as status";
......@@ -969,7 +969,7 @@ class CRM_AdvancedEvents_BAO_Query extends CRM_Core_BAO_Query {
$this->filterRelatedContacts($from, $where, $having);
}
return array($select, $from, $where, $having);
return [$select, $from, $where, $having];
}
/**
......@@ -1034,7 +1034,7 @@ class CRM_AdvancedEvents_BAO_Query extends CRM_Core_BAO_Query {
return NULL;
}
$sort = is_string($sort) ? $sort : $sort->orderBy();
$present = array();
$present = [];
foreach ($this->_pseudoConstantsSelect as $name => $value) {
if (!empty($value['table'])) {
......@@ -1060,7 +1060,7 @@ class CRM_AdvancedEvents_BAO_Query extends CRM_Core_BAO_Query {
$this->_fromClause = $this->_fromClause . $presentClause;
$this->_simpleFromClause = $this->_simpleFromClause . $presentSimpleFromClause;
return array($presentClause, $presentSimpleFromClause);
return [$presentClause, $presentSimpleFromClause];
}
/**
......@@ -1085,7 +1085,7 @@ class CRM_AdvancedEvents_BAO_Query extends CRM_Core_BAO_Query {
*/
protected function prepareOrderBy($sort, $sortByChar, $sortOrder, $additionalFromClause) {
$order = NULL;
$orderByArray = array();
$orderByArray = [];
$config = CRM_Core_Config::singleton();
if ($config->includeOrderByClause) {
if ($sort) {
......@@ -1114,7 +1114,7 @@ class CRM_AdvancedEvents_BAO_Query extends CRM_Core_BAO_Query {
}
}
if (!$order && empty($orderByArray)) {
return array($order, $additionalFromClause);
return [$order, $additionalFromClause];
}
// Remove this here & add it at the end for simplicity.
$order = trim(str_replace('ORDER BY', '', $order));
......@@ -1137,7 +1137,7 @@ class CRM_AdvancedEvents_BAO_Query extends CRM_Core_BAO_Query {
$cfID = CRM_Core_BAO_CustomField::getKeyID($field);
// add to cfIDs array if not present
if (!empty($cfID) && !array_key_exists($cfID, $this->_cfIDs)) {
$this->_cfIDs[$cfID] = array();
$this->_cfIDs[$cfID] = [];
$this->_customQuery = new CRM_Core_BAO_CustomQuery($this->_cfIDs, TRUE, $this->_locationSpecificCustomFields);
$this->_customQuery->query();
$this->_select = array_merge($this->_select, $this->_customQuery->_select);
......@@ -1157,9 +1157,9 @@ class CRM_AdvancedEvents_BAO_Query extends CRM_Core_BAO_Query {
&& isset($pseudoConstantMetadata['pseudoconstant']['optionGroupName'])
&& $field === CRM_Utils_Array::value('optionGroupName', $pseudoConstantMetadata['pseudoconstant'])
) {
$sortedOptions = $pseudoConstantMetadata['bao']::buildOptions($pseudoConstantMetadata['pseudoField'], NULL, array(
$sortedOptions = $pseudoConstantMetadata['bao']::buildOptions($pseudoConstantMetadata['pseudoField'], NULL, [
'orderColumn' => 'label',
));
]);
$order = str_replace("$field $direction", "field({$pseudoConstantMetadata['pseudoField']}," . implode(',', array_keys($sortedOptions)) . ") $direction", $order);
}
//CRM-12565 add "`" around $field if it is a pseudo constant
......@@ -1178,11 +1178,11 @@ class CRM_AdvancedEvents_BAO_Query extends CRM_Core_BAO_Query {
// clause. But this magic helper which forgivingly reescapes ORDER BY.
// Note: $sortByChar implies that $order was hard-coded/trusted, so it can do funky things.
if ($sortByChar) {
return array(' ORDER BY ' . $order, $additionalFromClause);
return [' ORDER BY ' . $order, $additionalFromClause];
}
if ($order) {
$order = CRM_Utils_Type::escape($order, 'MysqlOrderBy');
return array(' ORDER BY ' . $order, $additionalFromClause);
return [' ORDER BY ' . $order, $additionalFromClause];
}
}
......@@ -1193,13 +1193,13 @@ class CRM_AdvancedEvents_BAO_Query extends CRM_Core_BAO_Query {
* @return array|null
*/
public static function defaultReturnProperties($includeCustomFields = TRUE) {
$properties = array(
$properties = [
'event_id' => 1,
'event_title' => 1,
'event_start_date' => 1,
'event_end_date' => 1,
'event_type' => 1,
);
];
if ($includeCustomFields) {
// also get all the custom event properties
......@@ -1218,30 +1218,30 @@ class CRM_AdvancedEvents_BAO_Query extends CRM_Core_BAO_Query {
* @param CRM_Core_Form $form
*/
public static function buildSearchForm(&$form) {
$form->addEntityRef('event_id', ts('Event Name'), array(
$form->addEntityRef('event_id', ts('Event Name'), [
'entity' => 'event',
'placeholder' => ts('- any -'),
'multiple' => 1,
'select' => array('minimumInputLength' => 0),
)
'select' => ['minimumInputLength' => 0],
]
);
$form->addEntityRef('event_type_id', ts('Event Type'), array(
$form->addEntityRef('event_type_id', ts('Event Type'), [
'entity' => 'option_value',
'placeholder' => ts('- any -'),
'select' => array('minimumInputLength' => 0),
'api' => array(
'params' => array('option_group_id' => 'event_type'),
),
)
'select' => ['minimumInputLength' => 0],
'api' => [
'params' => ['option_group_id' => 'event_type'],
],
]
);
CRM_Core_Form_Date::buildDateRange($form, 'event', 1, '_start_date_low', '_end_date_high', ts('From'), FALSE);
$form->addElement('hidden', 'event_date_range_error');
$form->addFormRule(array('CRM_AdvancedEvents_BAO_Query', 'formRule'), $form);
$form->addFormRule(['CRM_AdvancedEvents_BAO_Query', 'formRule'], $form);
$form->addElement('checkbox', "event_include_repeating_events", NULL, ts('Include all events in the %1 series', array(1 => '<em>%1</em>')));
$form->addElement('checkbox', "event_include_repeating_events", NULL, ts('Include all events in the %1 series', [1 => '<em>%1</em>']));
self::addCustomFormFields($form, array('Event'));
self::addCustomFormFields($form, ['Event']);
$form->assign('validCiviEvent', TRUE);
}
......@@ -1258,7 +1258,7 @@ class CRM_AdvancedEvents_BAO_Query extends CRM_Core_BAO_Query {
* @return bool|array
*/
public static function formRule($fields, $files, $form) {
$errors = array();
$errors = [];
if ((empty($fields['event_start_date_low']) || empty($fields['event_end_date_high']))) {
return TRUE;
......
......@@ -39,32 +39,32 @@ require_once 'packages/When/When.php';
class CRM_AdvancedEvents_BAO_RecurringEntity extends CRM_Core_DAO_RecurringEntity {
const RUNNING = 1;
public $schedule = array();
public $schedule = [];
public $scheduleId = NULL;
public $scheduleFormValues = array();
public $scheduleFormValues = [];
public $dateColumns = array();
public $intervalDateColumns = array();
public $excludeDates = array();
public $dateColumns = [];
public $intervalDateColumns = [];
public $excludeDates = [];
protected $recursion = NULL;
protected $recursion_start_date = NULL;
public static $_entitiesToBeDeleted = array();
public static $_entitiesToBeDeleted = [];
public static $status = NULL;
static $_dateColumns
= array(
'civicrm_event' => array(
'dateColumns' => array('start_date'),
'excludeDateRangeColumns' => array('start_date', 'end_date'),
'intervalDateColumns' => array('end_date'),
),
);
= [
'civicrm_event' => [
'dateColumns' => ['start_date'],
'excludeDateRangeColumns' => ['start_date', 'end_date'],
'intervalDateColumns' => ['end_date'],
],
];
static $_tableDAOMapper
= array(
= [
'civicrm_event' => 'CRM_Event_DAO_Event',
'civicrm_price_set_entity' => 'CRM_Price_DAO_PriceSetEntity',
'civicrm_uf_join' => 'CRM_Core_DAO_UFJoin',
......@@ -72,7 +72,7 @@ class CRM_AdvancedEvents_BAO_RecurringEntity extends CRM_Core_DAO_RecurringEntit
'civicrm_pcp_block' => 'CRM_PCP_DAO_PCPBlock',
'civicrm_activity' => 'CRM_Activity_DAO_Activity',
'civicrm_activity_contact' => 'CRM_Activity_DAO_ActivityContact',
);
];
/**
* Getter for status.
......@@ -139,7 +139,7 @@ class CRM_AdvancedEvents_BAO_RecurringEntity extends CRM_Core_DAO_RecurringEntit
public function generateEntities() {
self::setStatus(self::RUNNING);
$newEntities = array();
$newEntities = [];
if (!empty($this->recursionDates)) {
if (empty($this->entity_id)) {
CRM_Core_Error::fatal("Find criteria missing to generate form. Make sure entity_id and table is set.");
......@@ -280,8 +280,8 @@ class CRM_AdvancedEvents_BAO_RecurringEntity extends CRM_Core_DAO_RecurringEntit
*
* @return array
*/
public function mapFormValuesToDB($formParams = array()) {
$dbParams = array();
public function mapFormValuesToDB($formParams = []) {
$dbParams = [];
if (!empty($formParams['used_for'])) {
$dbParams['used_for'] = $formParams['used_for'];
}
......@@ -358,9 +358,9 @@ class CRM_AdvancedEvents_BAO_RecurringEntity extends CRM_Core_DAO_RecurringEntit
AND id = %1";
}
$dao = CRM_Core_DAO::executeQuery($query,
array(
1 => array($scheduleReminderId, 'Integer'),
)
[
1 => [$scheduleReminderId, 'Integer'],
]
);
$dao->fetch();
return $dao;
......@@ -375,7 +375,7 @@ class CRM_AdvancedEvents_BAO_RecurringEntity extends CRM_Core_DAO_RecurringEntit
* @return array
*/
public function getScheduleParams($scheduleReminderId) {
$scheduleReminderDetails = array();
$scheduleReminderDetails = [];
if ($scheduleReminderId) {
//Get all the details from schedule reminder table
$scheduleReminderDetails = self::getScheduleReminderDetailsById($scheduleReminderId);
......@@ -394,7 +394,7 @@ class CRM_AdvancedEvents_BAO_RecurringEntity extends CRM_Core_DAO_RecurringEntit
* @return object
* When object
*/
public function getRecursionFromSchedule($scheduleReminderDetails = array()) {
public function getRecursionFromSchedule($scheduleReminderDetails = []) {
$r = new When();
//If there is some data for this id
if ($scheduleReminderDetails['repetition_frequency_unit']) {
......@@ -427,7 +427,7 @@ class CRM_AdvancedEvents_BAO_RecurringEntity extends CRM_Core_DAO_RecurringEntit
if ($scheduleReminderDetails['start_action_condition']) {
$startActionCondition = $scheduleReminderDetails['start_action_condition'];
$explodeStartActionCondition = explode(',', $startActionCondition);
$buildRuleArray = array();
$buildRuleArray = [];
foreach ($explodeStartActionCondition as $key => $val) {
$buildRuleArray[] = strtoupper(substr($val, 0, 2));
}
......@@ -461,10 +461,10 @@ class CRM_AdvancedEvents_BAO_RecurringEntity extends CRM_Core_DAO_RecurringEntit
break;
}
$concatStartActionDateBits = $startActionDate1 . strtoupper(substr($startActionDate[1], 0, 2));
$r->byday(array($concatStartActionDateBits));
$r->byday([$concatStartActionDateBits]);
}
elseif ($scheduleReminderDetails['limit_to']) {
$r->bymonthday(array($scheduleReminderDetails['limit_to']));
$r->bymonthday([$scheduleReminderDetails['limit_to']]);
}
}
......@@ -531,10 +531,10 @@ class CRM_AdvancedEvents_BAO_RecurringEntity extends CRM_Core_DAO_RecurringEntit
if ($used_for) {
$query .= " AND used_for = %2";
}
$params = array(
1 => array($entityId, 'Integer'),
2 => array($used_for, 'String'),
);
$params = [
1 => [$entityId, 'Integer'],
2 => [$used_for, 'String'],
];
$dao = CRM_Core_DAO::executeQuery($query, $params);
$dao->fetch();
}
......
......@@ -115,17 +115,17 @@ class CRM_AdvancedEvents_Form_ManageEvent_Delete extends CRM_Core_Form {
*/
public function buildQuickForm() {
$this->add('hidden', 'id');
$buttons = array(
array(
$buttons = [
[
'type' => 'next',
'name' => ts('Delete'),
'isDefault' => TRUE,
),
array(
],
[
'type' => 'cancel',
'name' => ts('Cancel'),
),
);
],
];
$this->addButtons($buttons);
}
......@@ -140,14 +140,14 @@ class CRM_AdvancedEvents_Form_ManageEvent_Delete extends CRM_Core_Form {
public function postProcess() {
$this->checkForParticipants();
civicrm_api3('Event', 'delete', ['id' => $this->_id]);
CRM_Core_Session::setStatus(ts("'%1' has been deleted.", array(1 => $this->_title)), ts('Event Deleted'), 'success');
CRM_Core_Session::setStatus(ts("'%1' has been deleted.", [1 => $this->_title]), ts('Event Deleted'), 'success');
}
public function checkForParticipants() {
if (!empty(civicrm_api3('Participant', 'getcount', ['event_id' => $this->_id,]))) {
$searchURL = CRM_Utils_System::url('civicrm/event/search', 'reset=1');
CRM_Core_Error::statusBounce(ts('This event cannot be deleted because there are participant records linked to it. If you want to delete this event, you must first find the participants linked to this event and delete them. You can use use <a href=\'%1\'> CiviEvent >> Find Participants page </a>.',
array(1 => $searchURL)
[1 => $searchURL]
), ts('Deletion Error'), 'error');
}
}
......
......@@ -49,7 +49,7 @@ class CRM_AdvancedEvents_Form_RecurringEntity {
/**
* Schedule Reminder data
*/
protected static $_scheduleReminderDetails = array();
protected static $_scheduleReminderDetails = [];
/**
* Parent Entity ID
......@@ -59,7 +59,7 @@ class CRM_AdvancedEvents_Form_RecurringEntity {
/**
* Exclude date information
*/
public static $_excludeDateInfo = array();
public static $_excludeDateInfo = [];
/**
* Return a descriptive name for the page, used in wizard header
......@@ -78,9 +78,9 @@ class CRM_AdvancedEvents_Form_RecurringEntity {
*/
public static function setDefaultValues() {