Merge pull request #14878 from civicrm/5.16
[civicrm-core.git] / CRM / Campaign / Form / Task / Interview.php
index 82fdf3b6d32429d7d927ea3a894d1c7833ac21b7..a1668fdb988fbe17dc55c0516dd65ac11e6ac760 100644 (file)
@@ -45,6 +45,7 @@ class CRM_Campaign_Form_Task_Interview extends CRM_Campaign_Form_Task {
 
   /**
    * Variable to store redirect path
+   * @var string
    */
   private $_userContext;
 
@@ -74,11 +75,11 @@ class CRM_Campaign_Form_Task_Interview extends CRM_Campaign_Form_Task {
     $this->_reserveToInterview = $this->get('reserveToInterview');
     if ($this->_reserveToInterview || $this->_votingTab) {
       //user came from voting tab / reserve form.
-      foreach (array(
-                 'surveyId',
-                 'contactIds',
-                 'interviewerId',
-               ) as $fld) {
+      foreach ([
+        'surveyId',
+        'contactIds',
+        'interviewerId',
+      ] as $fld) {
         $this->{"_$fld"} = $this->get($fld);
       }
       //get the target voter ids.
@@ -94,7 +95,7 @@ class CRM_Campaign_Form_Task_Interview extends CRM_Campaign_Form_Task {
     }
 
     if ($this->_surveyId) {
-      $params = array('id' => $this->_surveyId);
+      $params = ['id' => $this->_surveyId];
       CRM_Campaign_BAO_Survey::retrieve($params, $this->_surveyDetails);
     }
 
@@ -106,27 +107,27 @@ class CRM_Campaign_Form_Task_Interview extends CRM_Campaign_Form_Task {
     }
     elseif ($walkListActivityId == $this->_surveyDetails['activity_type_id']) {
       $orderByParams
-        = array(
-          1 => array(
+        = [
+          1 => [
             'column' => 'civicrm_address.street_name',
             'order' => 'ASC',
-          ),
-          2 => array(
+          ],
+          2 => [
             'column' => 'civicrm_address.street_number%2',
             'order' => 'ASC',
-          ),
-          3 => array(
+          ],
+          3 => [
             'column' => 'civicrm_address.street_number',
             'order' => 'ASC',
-          ),
-          4 => array(
+          ],
+          4 => [
             'column' => 'contact_a.sort_name',
             'order' => 'ASC',
-          ),
-        );
+          ],
+        ];
     }
 
-    $orderBy = array();
+    $orderBy = [];
     if (!empty($orderByParams)) {
       foreach ($orderByParams as $key => $val) {
         if (!empty($val['column'])) {
@@ -148,7 +149,7 @@ LEFT JOIN civicrm_address ON contact_a.id = civicrm_address.contact_id
 WHERE {$clause}
 {$orderClause}";
 
-      $this->_contactIds = array();
+      $this->_contactIds = [];
       $dao = CRM_Core_DAO::executeQuery($sql);
       while ($dao->fetch()) {
         $this->_contactIds[] = $dao->id;
@@ -156,10 +157,10 @@ WHERE {$clause}
     }
 
     //get the contact read only fields to display.
-    $readOnlyFields = array_merge(array(
+    $readOnlyFields = array_merge([
       'contact_type' => '',
       'sort_name' => ts('Name'),
-    ));
+    ]);
 
     //get the read only field data.
     $returnProperties = array_fill_keys(array_keys($readOnlyFields), 1);
@@ -173,7 +174,7 @@ WHERE {$clause}
     );
     $scheduledStatusId = CRM_Core_PseudoConstant::getKey('CRM_Activity_DAO_Activity', 'activity_status_id', 'Scheduled');
 
-    $activityIds = array();
+    $activityIds = [];
     foreach ($this->_contactIds as $key => $voterId) {
       $actVals = CRM_Utils_Array::value($voterId, $this->_surveyActivityIds);
       $statusId = CRM_Utils_Array::value('status_id', $actVals);
@@ -216,9 +217,9 @@ WHERE {$clause}
     //get the survey values.
     $this->_surveyValues = $this->get('surveyValues');
     if (!is_array($this->_surveyValues)) {
-      $this->_surveyValues = array();
+      $this->_surveyValues = [];
       if ($this->_surveyId) {
-        $surveyParams = array('id' => $this->_surveyId);
+        $surveyParams = ['id' => $this->_surveyId];
         CRM_Campaign_BAO_Survey::retrieve($surveyParams, $this->_surveyValues);
       }
       $this->set('surveyValues', $this->_surveyValues);
@@ -231,7 +232,7 @@ WHERE {$clause}
     //get the survey result options.
     $this->_resultOptions = $this->get('resultOptions');
     if (!is_array($this->_resultOptions)) {
-      $this->_resultOptions = array();
+      $this->_resultOptions = [];
       if ($resultOptionId = CRM_Utils_Array::value('result_id', $this->_surveyValues)) {
         $this->_resultOptions = CRM_Core_OptionGroup::valuesByID($resultOptionId);
       }
@@ -244,24 +245,24 @@ WHERE {$clause}
     //append breadcrumb to survey dashboard.
     if (CRM_Campaign_BAO_Campaign::accessCampaign()) {
       $url = CRM_Utils_System::url('civicrm/campaign', 'reset=1&subPage=survey');
-      CRM_Utils_System::appendBreadCrumb(array(array('title' => ts('Survey(s)'), 'url' => $url)));
+      CRM_Utils_System::appendBreadCrumb([['title' => ts('Survey(s)'), 'url' => $url]]);
     }
 
     //set the title.
     $this->_surveyTypeId = CRM_Utils_Array::value('activity_type_id', $this->_surveyValues);
     $surveyTypeLabel = CRM_Core_PseudoConstant::getLabel('CRM_Activity_BAO_Activity', 'activity_type_id', $this->_surveyTypeId);
-    CRM_Utils_System::setTitle(ts('Record %1 Responses', array(1 => $surveyTypeLabel)));
+    CRM_Utils_System::setTitle(ts('Record %1 Responses', [1 => $surveyTypeLabel]));
   }
 
   public function validateIds() {
-    $required = array(
+    $required = [
       'surveyId' => ts('Could not find Survey.'),
       'interviewerId' => ts('Could not find Interviewer.'),
       'contactIds' => ts('No respondents are currently reserved for you to interview.'),
       'resultOptions' => ts('Oops. It looks like there is no response option configured.'),
-    );
+    ];
 
-    $errorMessages = array();
+    $errorMessages = [];
     foreach ($required as $fld => $msg) {
       if (empty($this->{"_$fld"})) {
         if (!$this->_votingTab) {
@@ -282,19 +283,19 @@ WHERE {$clause}
     $this->assign('surveyTypeId', $this->_surveyTypeId);
 
     $options
-      = array(
+      = [
         '' => ' - none - ',
         'civicrm_address.street_name' => 'Street Name',
         'civicrm_address.street_number%2' => 'Odd / Even Street Number',
         'civicrm_address.street_number' => 'Street Number',
         'contact_a.sort_name' => 'Respondent Name',
-      );
+      ];
     for ($i = 1; $i < count($options); $i++) {
       $this->addElement('select', "order_bys[{$i}][column]", ts('Order by Column'), $options);
-      $this->addElement('select', "order_bys[{$i}][order]", ts('Order by Order'), array(
-          'ASC' => ts('Ascending'),
-          'DESC' => ts('Descending'),
-        ));
+      $this->addElement('select', "order_bys[{$i}][order]", ts('Order by Order'), [
+        'ASC' => ts('Ascending'),
+        'DESC' => ts('Descending'),
+      ]);
     }
 
     //pickup the uf fields.
@@ -313,9 +314,9 @@ WHERE {$clause}
       //build the result field.
       if (!empty($this->_resultOptions)) {
         $this->add('select', "field[$contactId][result]", ts('Result'),
-          array(
+          [
             '' => ts('- select -'),
-          ) +
+          ] +
           array_combine($this->_resultOptions, $this->_resultOptions)
         );
       }
@@ -326,7 +327,7 @@ WHERE {$clause}
       if ($this->_allowAjaxReleaseButton) {
         $this->addElement('hidden',
           "field[{$contactId}][is_release_or_reserve]", 0,
-          array('id' => "field_{$contactId}_is_release_or_reserve")
+          ['id' => "field_{$contactId}_is_release_or_reserve"]
         );
       }
     }
@@ -337,20 +338,20 @@ WHERE {$clause}
       return;
     }
 
-    $buttons = array(
-      array(
+    $buttons = [
+      [
         'type' => 'cancel',
         'name' => ts('Done'),
         'subName' => 'interview',
         'isDefault' => TRUE,
-      ),
-    );
+      ],
+    ];
 
-    $buttons[] = array(
+    $buttons[] = [
       'type' => 'submit',
       'name' => ts('Order By >>'),
       'subName' => 'orderBy',
-    );
+    ];
 
     $manageCampaign = CRM_Core_Permission::check('manage campaign');
     $adminCampaign = CRM_Core_Permission::check('administer CiviCampaign');
@@ -358,21 +359,21 @@ WHERE {$clause}
       $adminCampaign ||
       CRM_Core_Permission::check('release campaign contacts')
     ) {
-      $buttons[] = array(
+      $buttons[] = [
         'type' => 'next',
         'name' => ts('Release Respondents >>'),
         'subName' => 'interviewToRelease',
-      );
+      ];
     }
     if ($manageCampaign ||
       $adminCampaign ||
       CRM_Core_Permission::check('reserve campaign contacts')
     ) {
-      $buttons[] = array(
+      $buttons[] = [
         'type' => 'done',
         'name' => ts('Reserve More Respondents >>'),
         'subName' => 'interviewToReserve',
-      );
+      ];
     }
 
     $this->addButtons($buttons);
@@ -383,7 +384,7 @@ WHERE {$clause}
    */
   public function setDefaultValues() {
     //load default data for only contact fields.
-    $contactFields = $defaults = array();
+    $contactFields = $defaults = [];
     foreach ($this->_surveyFields as $name => $field) {
       $acceptable_types = CRM_Contact_BAO_ContactType::basicTypes();
       $acceptable_types[] = 'Contact';
@@ -400,33 +401,33 @@ WHERE {$clause}
     $walkListActivityId = CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity', 'activity_type_id', 'WalkList');
     if ($walkListActivityId == $this->_surveyDetails['activity_type_id']) {
       $defaults['order_bys']
-        = array(
-          1 => array(
+        = [
+          1 => [
             'column' => 'civicrm_address.street_name',
             'order' => 'ASC',
-          ),
-          2 => array(
+          ],
+          2 => [
             'column' => 'civicrm_address.street_number%2',
             'order' => 'ASC',
-          ),
-          3 => array(
+          ],
+          3 => [
             'column' => 'civicrm_address.street_number',
             'order' => 'ASC',
-          ),
-          4 => array(
+          ],
+          4 => [
             'column' => 'contact_a.sort_name',
             'order' => 'ASC',
-          ),
-        );
+          ],
+        ];
     }
     else {
       $defaults['order_bys']
-        = array(
-          1 => array(
+        = [
+          1 => [
             'column' => 'contact_a.sort_name',
             'order' => 'ASC',
-          ),
-        );
+          ],
+        ];
     }
     return $defaults;
   }
@@ -442,11 +443,11 @@ WHERE {$clause}
     }
     elseif ($buttonName == '_qf_Interview_next_interviewToRelease') {
       //get ready to jump to release form.
-      foreach (array(
-                 'surveyId',
-                 'contactIds',
-                 'interviewerId',
-               ) as $fld) {
+      foreach ([
+        'surveyId',
+        'contactIds',
+        'interviewerId',
+      ] as $fld) {
         $this->controller->set($fld, $this->{"_$fld"});
       }
       $this->controller->set('interviewToRelease', TRUE);
@@ -493,9 +494,9 @@ WHERE {$clause}
     CRM_Core_BAO_CustomValueTable::store($customParams, 'civicrm_activity', $activityId);
 
     //process contact data.
-    $contactParams = $fields = array();
+    $contactParams = $fields = [];
 
-    $contactFieldTypes = array_merge(array('Contact'), CRM_Contact_BAO_ContactType::basicTypes());
+    $contactFieldTypes = array_merge(['Contact'], CRM_Contact_BAO_ContactType::basicTypes());
     $responseFields = CRM_Campaign_BAO_Survey::getSurveyResponseFields($params['survey_id']);
     if (!empty($responseFields)) {
       foreach ($params as $key => $value) {
@@ -538,7 +539,7 @@ WHERE {$clause}
     $subject .= ts('Respondent Interview');
 
     $activity->subject = $subject;
-    $activityParams = array(
+    $activityParams = [
       'details' => 'details',
       'result' => 'result',
       'engagement_level' => 'activity_engagement_level',
@@ -548,7 +549,7 @@ WHERE {$clause}
       'location' => 'activity_location',
       'campaign_id' => 'activity_campaign_id',
       'duration' => 'activity_duration',
-    );
+    ];
     foreach ($activityParams as $key => $field) {
       if (!empty($params[$field])) {
         $activity->$key = $params[$field];
@@ -585,7 +586,7 @@ WHERE {$clause}
         $this->_interviewerId,
         $statusIds
       );
-      $this->_contactIds = array();
+      $this->_contactIds = [];
       foreach ($surveyActivities as $val) {
         $this->_contactIds[$val['voter_id']] = $val['voter_id'];
       }
@@ -635,7 +636,7 @@ WHERE {$clause}
 INNER JOIN  {$tempTableName} ON ( {$tempTableName}.survey_contact_id = contact.id )
      WHERE  contact.contact_type != %1";
         $removeContact = CRM_Core_DAO::executeQuery($query,
-          array(1 => array($profileType, 'String'))
+          [1 => [$profileType, 'String']]
         );
         while ($removeContact->fetch()) {
           unset($this->_contactIds[$removeContact->id]);