X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=CRM%2FCampaign%2FForm%2FPetition.php;h=f203c3d88fe97ae135d4b7c1e095fac2f5c9ae61;hb=9585cabb995de30da705ab3349d15f048f128ab4;hp=e1e005eda01fc2b4b6e4e3d58bae0c6a5322822c;hpb=edf46151353baa2cd74f5ad5ac1c7edef424831f;p=civicrm-core.git diff --git a/CRM/Campaign/Form/Petition.php b/CRM/Campaign/Form/Petition.php index e1e005eda0..f203c3d88f 100644 --- a/CRM/Campaign/Form/Petition.php +++ b/CRM/Campaign/Form/Petition.php @@ -90,9 +90,9 @@ class CRM_Campaign_Form_Petition extends CRM_Core_Form { $this->_values = $this->get('values'); if (!is_array($this->_values)) { - $this->_values = array(); + $this->_values = []; if ($this->_surveyId) { - $params = array('id' => $this->_surveyId); + $params = ['id' => $this->_surveyId]; CRM_Campaign_BAO_Survey::retrieve($params, $this->_values); } $this->set('values', $this->_values); @@ -116,7 +116,7 @@ class CRM_Campaign_Form_Petition extends CRM_Core_Form { $url = CRM_Utils_System::url('civicrm/campaign', 'reset=1&subPage=petition'); $session->pushUserContext($url); - CRM_Utils_System::appendBreadCrumb(array(array('title' => ts('Petition Dashboard'), 'url' => $url))); + CRM_Utils_System::appendBreadCrumb([['title' => ts('Petition Dashboard'), 'url' => $url]]); } /** @@ -129,20 +129,20 @@ class CRM_Campaign_Form_Petition extends CRM_Core_Form { public function setDefaultValues() { $defaults = $this->_values; - $ufContactJoinParams = array( + $ufContactJoinParams = [ 'entity_table' => 'civicrm_survey', 'entity_id' => $this->_surveyId, 'weight' => 2, - ); + ]; if ($ufContactGroupId = CRM_Core_BAO_UFJoin::findUFGroupId($ufContactJoinParams)) { $defaults['contact_profile_id'] = $ufContactGroupId; } - $ufActivityJoinParams = array( + $ufActivityJoinParams = [ 'entity_table' => 'civicrm_survey', 'entity_id' => $this->_surveyId, 'weight' => 1, - ); + ]; if ($ufActivityGroupId = CRM_Core_BAO_UFJoin::findUFGroupId($ufActivityJoinParams)) { $defaults['profile_id'] = $ufActivityGroupId; @@ -160,22 +160,21 @@ class CRM_Campaign_Form_Petition extends CRM_Core_Form { return $defaults; } - public function buildQuickForm() { if ($this->_action & CRM_Core_Action::DELETE) { $this->addButtons( - array( - array( + [ + [ 'type' => 'next', 'name' => ts('Delete'), 'isDefault' => TRUE, - ), - array( + ], + [ 'type' => 'cancel', 'name' => ts('Cancel'), - ), - ) + ], + ] ); return; } @@ -196,20 +195,20 @@ class CRM_Campaign_Form_Petition extends CRM_Core_Form { 'select' => ['minimumInputLength' => 0], ]); - $customContactProfiles = CRM_Core_BAO_UFGroup::getProfiles(array('Individual')); + $customContactProfiles = CRM_Core_BAO_UFGroup::getProfiles(['Individual']); // custom group id $this->add('select', 'contact_profile_id', ts('Contact Profile'), - array( + [ '' => ts('- select -'), - ) + $customContactProfiles, TRUE + ] + $customContactProfiles, TRUE ); - $customProfiles = CRM_Core_BAO_UFGroup::getProfiles(array('Activity')); + $customProfiles = CRM_Core_BAO_UFGroup::getProfiles(['Activity']); // custom group id $this->add('select', 'profile_id', ts('Activity Profile'), - array( + [ '' => ts('- select -'), - ) + $customProfiles + ] + $customProfiles ); // thank you title and text (html allowed in text) @@ -230,26 +229,26 @@ class CRM_Campaign_Form_Petition extends CRM_Core_Form { // add buttons $this->addButtons( - array( - array( + [ + [ 'type' => 'next', 'name' => ts('Save'), 'isDefault' => TRUE, - ), - array( + ], + [ 'type' => 'next', 'name' => ts('Save and New'), 'subName' => 'new', - ), - array( + ], + [ 'type' => 'cancel', 'name' => ts('Cancel'), - ), - ) + ], + ] ); // add a form rule to check default value - $this->addFormRule(array('CRM_Campaign_Form_Petition', 'formRule'), $this); + $this->addFormRule(['CRM_Campaign_Form_Petition', 'formRule'], $this); } /** @@ -260,14 +259,14 @@ class CRM_Campaign_Form_Petition extends CRM_Core_Form { * @return array|bool */ public static function formRule($fields, $files, $form) { - $errors = array(); + $errors = []; // Petitions should be unique by: title, campaign ID (if assigned) and activity type ID // NOTE: This class is called for both Petition create / update AND for Survey Results tab, but this rule is only for Petition. - $where = array('activity_type_id = %1', 'title = %2'); - $params = array( - 1 => array($fields['activity_type_id'], 'Integer'), - 2 => array($fields['title'], 'String'), - ); + $where = ['activity_type_id = %1', 'title = %2']; + $params = [ + 1 => [$fields['activity_type_id'], 'Integer'], + 2 => [$fields['title'], 'String'], + ]; $uniqueRuleErrorMessage = ts('This title is already associated with the selected activity type. Please specify a unique title.'); if (empty($fields['campaign_id'])) { @@ -275,14 +274,14 @@ class CRM_Campaign_Form_Petition extends CRM_Core_Form { } else { $where[] = 'campaign_id = %3'; - $params[3] = array($fields['campaign_id'], 'Integer'); + $params[3] = [$fields['campaign_id'], 'Integer']; $uniqueRuleErrorMessage = ts('This title is already associated with the selected campaign and activity type. Please specify a unique title.'); } // Exclude current Petition row if UPDATE. if ($form->_surveyId) { $where[] = 'id != %4'; - $params[4] = array($form->_surveyId, 'Integer'); + $params[4] = [$form->_surveyId, 'Integer']; } $whereClause = implode(' AND ', $where); @@ -300,7 +299,6 @@ WHERE $whereClause return empty($errors) ? TRUE : $errors; } - public function postProcess() { // store the submitted values in an array $params = $this->controller->exportValues($this->_name); @@ -336,12 +334,12 @@ WHERE $whereClause $surveyId = CRM_Campaign_BAO_Survey::create($params); // also update the ProfileModule tables - $ufJoinParams = array( + $ufJoinParams = [ 'is_active' => 1, 'module' => 'CiviCampaign', 'entity_table' => 'civicrm_survey', 'entity_id' => $surveyId->id, - ); + ]; // first delete all past entries if ($this->_surveyId) {