Merge pull request #5536 from totten/4.5-httpclient
[civicrm-core.git] / CRM / Campaign / Form / Task / Interview.php
index c081d195554c067c5f2f1c3e6ebba7dfd707fa8b..cfee48b717ac8ecc8f29fe00691a928fbae768df 100755 (executable)
@@ -3,7 +3,7 @@
  +--------------------------------------------------------------------+
  | CiviCRM version 4.6                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2014                                |
+ | Copyright CiviCRM LLC (c) 2004-2015                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
  | GNU Affero General Public License or the licensing of CiviCRM,     |
  | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
  +--------------------------------------------------------------------+
-*/
+ */
 
 /**
  *
  * @package CRM
- * @copyright CiviCRM LLC (c) 2004-2014
+ * @copyright CiviCRM LLC (c) 2004-2015
  * $Id$
  *
  */
@@ -47,7 +47,6 @@ class CRM_Campaign_Form_Task_Interview extends CRM_Campaign_Form_Task {
 
   /**
    * Variable to store redirect path
-   *
    */
   private $_userContext;
 
@@ -70,7 +69,7 @@ class CRM_Campaign_Form_Task_Interview extends CRM_Campaign_Form_Task {
   private $_allowAjaxReleaseButton;
 
   /**
-   * Build all the data structures needed to build the form
+   * Build all the data structures needed to build the form.
    *
    * @return void
    */
@@ -80,7 +79,10 @@ class CRM_Campaign_Form_Task_Interview extends CRM_Campaign_Form_Task {
     if ($this->_reserveToInterview || $this->_votingTab) {
       //user came from voting tab / reserve form.
       foreach (array(
-                 'surveyId', 'contactIds', 'interviewerId') as $fld) {
+                 'surveyId',
+                 'contactIds',
+                 'interviewerId',
+               ) as $fld) {
         $this->{"_$fld"} = $this->get($fld);
       }
       //get the target voter ids.
@@ -95,22 +97,22 @@ class CRM_Campaign_Form_Task_Interview extends CRM_Campaign_Form_Task {
       $this->_interviewerId = CRM_Utils_Array::value('survey_interviewer_id', $this->get('formValues'));
     }
 
-    if ( $this->_surveyId ) {
+    if ($this->_surveyId) {
       $params = array('id' => $this->_surveyId);
       CRM_Campaign_BAO_Survey::retrieve($params, $this->_surveyDetails);
     }
 
-    $orderClause = false;
-    $buttonName  = $this->controller->getButtonName();
-    if ( $buttonName == '_qf_Interview_submit_orderBy' && !empty($_POST['order_bys'])) {
+    $orderClause = FALSE;
+    $buttonName = $this->controller->getButtonName();
+    if ($buttonName == '_qf_Interview_submit_orderBy' && !empty($_POST['order_bys'])) {
       $orderByParams = CRM_Utils_Array::value('order_bys', $_POST);
     }
-    elseif ( CRM_Core_OptionGroup::getValue('activity_type','WalkList') == $this->_surveyDetails['activity_type_id'] ) {
-      $orderByParams =
-        array(
+    elseif (CRM_Core_OptionGroup::getValue('activity_type', 'WalkList') == $this->_surveyDetails['activity_type_id']) {
+      $orderByParams
+        array(
           1 => array(
             'column' => 'civicrm_address.street_name',
-            'order'  => 'ASC',
+            'order' => 'ASC',
           ),
           2 => array(
             'column' => 'civicrm_address.street_number%2',
@@ -128,13 +130,13 @@ class CRM_Campaign_Form_Task_Interview extends CRM_Campaign_Form_Task {
     }
 
     $orderBy = array();
-    if ( !empty($orderByParams) ) {
-      foreach ( $orderByParams as $key => $val ) {
+    if (!empty($orderByParams)) {
+      foreach ($orderByParams as $key => $val) {
         if (!empty($val['column'])) {
           $orderBy[] = "{$val['column']} {$val['order']}";
         }
       }
-      if ( !empty($orderBy) ) {
+      if (!empty($orderBy)) {
         $orderClause = "ORDER BY " . implode(', ', $orderBy);
       }
     }
@@ -142,7 +144,7 @@ class CRM_Campaign_Form_Task_Interview extends CRM_Campaign_Form_Task {
     $this->_contactIds = array_unique($this->_contactIds);
     if (!empty($this->_contactIds) && $orderClause) {
       $clause = 'contact_a.id IN ( ' . implode(',', $this->_contactIds) . ' ) ';
-      $sql    = "
+      $sql = "
 SELECT contact_a.id
 FROM civicrm_contact contact_a
 LEFT JOIN civicrm_address ON contact_a.id = civicrm_address.contact_id
@@ -156,7 +158,6 @@ WHERE {$clause}
       }
     }
 
-
     //get the contact read only fields to display.
     $readOnlyFields = array_merge(array(
       'contact_type' => '',
@@ -178,8 +179,8 @@ WHERE {$clause}
 
     $activityIds = array();
     foreach ($this->_contactIds as $key => $voterId) {
-      $actVals    = CRM_Utils_Array::value($voterId, $this->_surveyActivityIds);
-      $statusId   = CRM_Utils_Array::value('status_id', $actVals);
+      $actVals = CRM_Utils_Array::value($voterId, $this->_surveyActivityIds);
+      $statusId = CRM_Utils_Array::value('status_id', $actVals);
       $activityId = CRM_Utils_Array::value('activity_id', $actVals);
       if ($activityId &&
         $statusId &&
@@ -229,7 +230,7 @@ WHERE {$clause}
     $this->assign('surveyValues', $this->_surveyValues);
 
     $result = CRM_Campaign_BAO_Survey::getReportID($this->_surveyId);
-    $this->assign("instanceId",$result);
+    $this->assign("instanceId", $result);
 
     //get the survey result options.
     $this->_resultOptions = $this->get('resultOptions');
@@ -257,7 +258,8 @@ WHERE {$clause}
   }
 
   public function validateIds() {
-    $required = array('surveyId' => ts('Could not find Survey.'),
+    $required = array(
+      '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.'),
@@ -278,7 +280,7 @@ WHERE {$clause}
   }
 
   /**
-   * Build the form object
+   * Build the form object.
    *
    *
    * @return void
@@ -286,16 +288,20 @@ WHERE {$clause}
   public function buildQuickForm() {
     $this->assign('surveyTypeId', $this->_surveyTypeId);
 
-    $options =
-      array('' => ' - none - ',
-        'civicrm_address.street_name'     => 'Street Name',
+    $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',
+        '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' => 'Ascending', 'DESC' => 'Descending'));
+      $this->addElement('select', "order_bys[{$i}][order]", ts('Order by Order'), array(
+          'ASC' => 'Ascending',
+          'DESC' => 'Descending',
+        ));
     }
 
     //pickup the uf fields.
@@ -306,7 +312,7 @@ WHERE {$clause}
     foreach ($this->_contactIds as $contactId) {
       //build the profile fields.
       foreach ($this->_surveyFields as $name => $field) {
-        if ($field){
+        if ($field) {
           CRM_Core_BAO_UFGroup::buildProfile($this, $field, NULL, $contactId);
         }
       }
@@ -315,8 +321,9 @@ WHERE {$clause}
       if (!empty($this->_resultOptions)) {
         $this->add('select', "field[$contactId][result]", ts('Result'),
           array(
-            '' => ts('- select -')) +
-            array_combine($this->_resultOptions, $this->_resultOptions)
+            '' => ts('- select -'),
+          ) +
+          array_combine($this->_resultOptions, $this->_resultOptions)
         );
       }
 
@@ -338,11 +345,13 @@ WHERE {$clause}
     }
 
     $buttons = array(
-      array('type' => 'cancel',
+      array(
+        'type' => 'cancel',
         'name' => ts('Done'),
         'subName' => 'interview',
         'isDefault' => TRUE,
-      ));
+      ),
+    );
 
     $buttons[] = array(
       'type' => 'submit',
@@ -398,12 +407,12 @@ WHERE {$clause}
       }
     }
 
-    if ( CRM_Core_OptionGroup::getValue('activity_type','WalkList') == $this->_surveyDetails['activity_type_id'] ) {
-      $defaults['order_bys'] =
-        array(
+    if (CRM_Core_OptionGroup::getValue('activity_type', 'WalkList') == $this->_surveyDetails['activity_type_id']) {
+      $defaults['order_bys']
+        array(
           1 => array(
             'column' => 'civicrm_address.street_name',
-            'order'  => 'ASC',
+            'order' => 'ASC',
           ),
           2 => array(
             'column' => 'civicrm_address.street_number%2',
@@ -420,10 +429,9 @@ WHERE {$clause}
         );
     }
     else {
-      $defaults['order_bys'] =
-        array(
-          1 =>
-          array(
+      $defaults['order_bys']
+        = array(
+          1 => array(
             'column' => 'contact_a.sort_name',
             'order' => 'ASC',
           ),
@@ -433,7 +441,7 @@ WHERE {$clause}
   }
 
   /**
-   * Process the form after the input has been submitted and validated
+   * Process the form after the input has been submitted and validated.
    *
    *
    * @return void
@@ -447,14 +455,16 @@ WHERE {$clause}
     elseif ($buttonName == '_qf_Interview_next_interviewToRelease') {
       //get ready to jump to release form.
       foreach (array(
-                 'surveyId', 'contactIds', 'interviewerId') as $fld) {
+                 'surveyId',
+                 'contactIds',
+                 'interviewerId',
+               ) as $fld) {
         $this->controller->set($fld, $this->{"_$fld"});
       }
       $this->controller->set('interviewToRelease', TRUE);
     }
 
     // vote is done through ajax
-    return;
   }
 
   /**
@@ -536,8 +546,7 @@ WHERE {$clause}
     $subject = '';
     $surveyTitle = CRM_Utils_Array::value('surveyTitle', $params);
     if ($surveyTitle) {
-      $subject = ts('%1', array(1 => $surveyTitle));
-      $subject .= ' - ';
+      $subject = $surveyTitle . ' - ';
     }
     $subject .= ts('Respondent Interview');
 
@@ -551,7 +560,7 @@ WHERE {$clause}
       'source_contact_id' => 'source_contact',
       'location' => 'activity_location',
       'campaign_id' => 'activity_campaign_id',
-      'duration' => 'activity_duration'
+      'duration' => 'activity_duration',
     );
     foreach ($activityParams as $key => $field) {
       if (!empty($params[$field])) {
@@ -575,8 +584,8 @@ WHERE {$clause}
     }
     if (!$this->_surveyId) {
       // use default survey id
-      $dao             = new CRM_Campaign_DAO_Survey();
-      $dao->is_active  = 1;
+      $dao = new CRM_Campaign_DAO_Survey();
+      $dao->is_active = 1;
       $dao->is_default = 1;
       $dao->find(TRUE);
       $this->_surveyId = $dao->id;
@@ -595,7 +604,9 @@ WHERE {$clause}
         $statusIds
       );
       $this->_contactIds = array();
-      foreach ($surveyActivities as $val) $this->_contactIds[$val['voter_id']] = $val['voter_id'];
+      foreach ($surveyActivities as $val) {
+        $this->_contactIds[$val['voter_id']] = $val['voter_id'];
+      }
       $this->set('contactIds', $this->_contactIds);
     }
   }
@@ -650,4 +661,5 @@ INNER JOIN  {$tempTableName} ON ( {$tempTableName}.survey_contact_id = contact.i
       }
     }
   }
+
 }