X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=CRM%2FContact%2FForm%2FTask.php;h=8e1c3a3aa14543abacc470e6728522606ad855a2;hb=3afe475309fde9f4b7437e424f924e94f0764056;hp=74a62c32a00fe059bcdcaee0c57e6216e941a573;hpb=159e1665690892da1c21509045b8e26d97126cb4;p=civicrm-core.git diff --git a/CRM/Contact/Form/Task.php b/CRM/Contact/Form/Task.php index 74a62c32a0..8e1c3a3aa1 100644 --- a/CRM/Contact/Form/Task.php +++ b/CRM/Contact/Form/Task.php @@ -80,6 +80,7 @@ class CRM_Contact_Form_Task extends CRM_Core_Form_Task { /** * This includes the submitted values of the search form + * @var array */ static protected $_searchFormValues; @@ -98,8 +99,8 @@ class CRM_Contact_Form_Task extends CRM_Core_Form_Task { * @throws \CRM_Core_Exception */ public static function preProcessCommon(&$form) { - $form->_contactIds = array(); - $form->_contactTypes = array(); + $form->_contactIds = []; + $form->_contactTypes = []; $useTable = (CRM_Utils_System::getClassName($form->controller->getStateMachine()) == 'CRM_Export_StateMachine_Standalone'); @@ -153,12 +154,10 @@ class CRM_Contact_Form_Task extends CRM_Core_Form_Task { $form->assign('taskName', CRM_Utils_Array::value($form->_task, $crmContactTaskTasks)); if ($useTable) { - $form->_componentTable = CRM_Utils_SQL_TempTable::build()->setCategory('tskact')->setDurable()->setId($qfKey)->getName(); - $sql = " DROP TABLE IF EXISTS {$form->_componentTable}"; - CRM_Core_DAO::executeQuery($sql); - - $sql = "CREATE TABLE {$form->_componentTable} ( contact_id int primary key) ENGINE=InnoDB DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci"; - CRM_Core_DAO::executeQuery($sql); + $tempTable = CRM_Utils_SQL_TempTable::build()->setCategory('tskact')->setDurable()->setId($qfKey)->setUtf8(); + $form->_componentTable = $tempTable->getName(); + $tempTable->drop(); + $tempTable->createWithColumns('contact_id int primary key'); } // all contacts or action = save a search @@ -175,10 +174,10 @@ class CRM_Contact_Form_Task extends CRM_Core_Form_Task { $allCids[$cacheKey] = self::getContactIds($form); } - $form->_contactIds = array(); + $form->_contactIds = []; if ($useTable) { $count = 0; - $insertString = array(); + $insertString = []; foreach ($allCids[$cacheKey] as $cid => $ignore) { $count++; $insertString[] = " ( {$cid} ) "; @@ -186,7 +185,7 @@ class CRM_Contact_Form_Task extends CRM_Core_Form_Task { $string = implode(',', $insertString); $sql = "REPLACE INTO {$form->_componentTable} ( contact_id ) VALUES $string"; CRM_Core_DAO::executeQuery($sql); - $insertString = array(); + $insertString = []; } } if (!empty($insertString)) { @@ -210,7 +209,7 @@ class CRM_Contact_Form_Task extends CRM_Core_Form_Task { elseif (CRM_Utils_Array::value('radio_ts', self::$_searchFormValues) == 'ts_sel') { // selected contacts only // need to perform action on only selected contacts - $insertString = array(); + $insertString = []; // refire sql in case of custom search if ($form->_action == CRM_Core_Action::COPY) { @@ -315,7 +314,7 @@ class CRM_Contact_Form_Task extends CRM_Core_Form_Task { // fix for CRM-5165 $sortByCharacter = $form->get('sortByCharacter'); if ($sortByCharacter && $sortByCharacter != 1) { - $params[] = array('sortByCharacter', '=', $sortByCharacter, 0, 0); + $params[] = ['sortByCharacter', '=', $sortByCharacter, 0, 0]; } $queryOperator = $form->get('queryOperator'); if (!$queryOperator) { @@ -326,7 +325,7 @@ class CRM_Contact_Form_Task extends CRM_Core_Form_Task { $queryOperator ); - $contactIds = array(); + $contactIds = []; while ($dao->fetch()) { $contactIds[$dao->contact_id] = $dao->contact_id; } @@ -334,7 +333,6 @@ class CRM_Contact_Form_Task extends CRM_Core_Form_Task { return $contactIds; } - /** * Set default values for the form. Relationship that in edit/view action. * @@ -343,7 +341,7 @@ class CRM_Contact_Form_Task extends CRM_Core_Form_Task { * @return array */ public function setDefaultValues() { - $defaults = array(); + $defaults = []; return $defaults; } @@ -379,19 +377,18 @@ class CRM_Contact_Form_Task extends CRM_Core_Form_Task { * @param bool $submitOnce */ public function addDefaultButtons($title, $nextType = 'next', $backType = 'back', $submitOnce = FALSE) { - $this->addButtons(array( - array( - 'type' => $nextType, - 'name' => $title, - 'isDefault' => TRUE, - ), - array( - 'type' => $backType, - 'name' => ts('Cancel'), - 'icon' => 'fa-times', - ), - ) - ); + $this->addButtons([ + [ + 'type' => $nextType, + 'name' => $title, + 'isDefault' => TRUE, + ], + [ + 'type' => $backType, + 'name' => ts('Cancel'), + 'icon' => 'fa-times', + ], + ]); } /** @@ -417,10 +414,10 @@ class CRM_Contact_Form_Task extends CRM_Core_Form_Task { // Get Head of Household & Household Member relationships $relationKeyMOH = CRM_Utils_Array::key('Household Member of', $contactRelationshipTypes); $relationKeyHOH = CRM_Utils_Array::key('Head of Household for', $contactRelationshipTypes); - $householdRelationshipTypes = array( + $householdRelationshipTypes = [ $relationKeyMOH => $contactRelationshipTypes[$relationKeyMOH], $relationKeyHOH => $contactRelationshipTypes[$relationKeyHOH], - ); + ]; $relID = implode(',', $this->_contactIds); @@ -456,20 +453,19 @@ class CRM_Contact_Form_Task extends CRM_Core_Form_Task { $this->_contactIds[] = $householdsDAO->household_id; } } - $householdsDAO->free(); } // If contact list has changed, households will probably be at the end of // the list. Sort it again by sort_name. if (implode(',', $this->_contactIds) != $relID) { - $result = civicrm_api3('Contact', 'get', array( - 'return' => array('id'), - 'id' => array('IN' => $this->_contactIds), - 'options' => array( + $result = civicrm_api3('Contact', 'get', [ + 'return' => ['id'], + 'id' => ['IN' => $this->_contactIds], + 'options' => [ 'limit' => 0, 'sort' => "sort_name", - ), - )); + ], + ]); $this->_contactIds = array_keys($result['values']); } } @@ -484,7 +480,7 @@ class CRM_Contact_Form_Task extends CRM_Core_Form_Task { $qfKey = CRM_Utils_Request::retrieve('qfKey', 'String'); $cacheKey = "civicrm search {$qfKey}"; - $cids = array(); + $cids = []; // Gymanstic time! foreach (Civi::service('prevnext')->getSelection($cacheKey) as $cacheKey => $values) { $cids = array_unique(array_merge($cids, array_keys($values))); @@ -509,17 +505,18 @@ class CRM_Contact_Form_Task extends CRM_Core_Form_Task { $searchParams = $this->controller->exportValues(); if ($searchParams['radio_ts'] == 'ts_sel') { // Create a static group. - $randID = md5(time() . rand(1, 1000)); // groups require a unique name + // groups require a unique name + $randID = md5(time() . rand(1, 1000)); $grpTitle = "Hidden Group {$randID}"; $grpID = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Group', $grpTitle, 'id', 'title'); if (!$grpID) { - $groupParams = array( + $groupParams = [ 'title' => $grpTitle, 'is_active' => 1, 'is_hidden' => 1, - 'group_type' => array('2' => 1), - ); + 'group_type' => ['2' => 1], + ]; $group = CRM_Contact_BAO_Group::create($groupParams); $grpID = $group->id; @@ -527,33 +524,33 @@ class CRM_Contact_Form_Task extends CRM_Core_Form_Task { CRM_Contact_BAO_GroupContact::addContactsToGroup($this->_contactIds, $group->id); $newGroupTitle = "Hidden Group {$grpID}"; - $groupParams = array( + $groupParams = [ 'id' => $grpID, 'name' => CRM_Utils_String::titleToVar($newGroupTitle), 'title' => $newGroupTitle, - 'group_type' => array('2' => 1), - ); + 'group_type' => ['2' => 1], + ]; CRM_Contact_BAO_Group::create($groupParams); } // note at this point its a static group - return array($grpID, NULL); + return [$grpID, NULL]; } else { // Create a smart group. $ssId = $this->get('ssID'); - $hiddenSmartParams = array( - 'group_type' => array('2' => 1), + $hiddenSmartParams = [ + 'group_type' => ['2' => 1], // queryParams have been preprocessed esp WRT any entity reference fields - see + // https://github.com/civicrm/civicrm-core/pull/13250 'form_values' => $this->get('queryParams'), 'saved_search_id' => $ssId, 'search_custom_id' => $this->get('customSearchID'), 'search_context' => $this->get('context'), - ); + ]; list($smartGroupId, $savedSearchId) = CRM_Contact_BAO_Group::createHiddenSmartGroup($hiddenSmartParams); - return array($smartGroupId, $savedSearchId); + return [$smartGroupId, $savedSearchId]; } }