add status preference dao to ignore list
[civicrm-core.git] / CRM / Campaign / Form / Task / Reserve.php
index caa0fdc87580b750310c6f7eef824839e7eb0069..5498890223617be76a907357a58c9509e27ff268 100644 (file)
@@ -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$
  *
  */
@@ -68,7 +68,7 @@ class CRM_Campaign_Form_Task_Reserve extends CRM_Campaign_Form_Task {
   protected $_numVoters;
 
   /**
-   * Build all the data structures needed to build the form
+   * Build all the data structures needed to build the form.
    *
    * @return void
    */
@@ -94,8 +94,7 @@ class CRM_Campaign_Form_Task_Reserve extends CRM_Campaign_Form_Task {
     //get the survey activities.
     $activityStatus = CRM_Core_PseudoConstant::activityStatus('name');
     $statusIds = array();
-    foreach (array(
-      'Scheduled') as $name) {
+    foreach (array('Scheduled') as $name) {
       if ($statusId = array_search($name, $activityStatus)) {
         $statusIds[] = $statusId;
       }
@@ -133,16 +132,22 @@ class CRM_Campaign_Form_Task_Reserve extends CRM_Campaign_Form_Task {
         $errorMsg = ts('The maximum number of contacts is already reserved for this interviewer.');
       }
       elseif (count($this->_contactIds) > ($maxVoters - $this->_numVoters)) {
-        $errorMsg = ts('You can reserve a maximum of %1 contact(s) at a time for this survey.',
-          array(1 => $maxVoters - $this->_numVoters)
+        $errorMsg = ts('You can reserve a maximum of %count contact at a time for this survey.',
+          array(
+            'plural' => 'You can reserve a maximum of %count contacts at a time for this survey.',
+            'count' => $maxVoters - $this->_numVoters,
+          )
         );
       }
     }
 
     $defaultNum = CRM_Utils_Array::value('default_number_of_contacts', $this->_surveyDetails);
     if (!$errorMsg && $defaultNum && (count($this->_contactIds) > $defaultNum)) {
-      $errorMsg = ts('You can reserve a maximum of %1 contact(s) at a time for this survey.',
-        array(1 => $defaultNum)
+      $errorMsg = ts('You can reserve a maximum of %count contact at a time for this survey.',
+        array(
+          'plural' => 'You can reserve a maximum of %count contacts at a time for this survey.',
+          'count' => $defaultNum,
+        )
       );
     }
 
@@ -152,7 +157,7 @@ class CRM_Campaign_Form_Task_Reserve extends CRM_Campaign_Form_Task {
   }
 
   /**
-   * Build the form object
+   * Build the form object.
    *
    *
    * @return void
@@ -174,11 +179,12 @@ class CRM_Campaign_Form_Task_Reserve extends CRM_Campaign_Form_Task {
 
     $buttons = array(
       array(
-    'type' => 'done',
+        'type' => 'done',
         'name' => ts('Reserve'),
         'subName' => 'reserve',
         'isDefault' => TRUE,
-      ));
+      ),
+    );
 
     if (CRM_Core_Permission::check('manage campaign') ||
       CRM_Core_Permission::check('administer CiviCampaign') ||
@@ -200,7 +206,7 @@ class CRM_Campaign_Form_Task_Reserve extends CRM_Campaign_Form_Task {
   }
 
   /**
-   * Global validation rules for the form
+   * Global validation rules for the form.
    *
    * @param array $fields
    *   Posted values of the form.
@@ -210,19 +216,18 @@ class CRM_Campaign_Form_Task_Reserve extends CRM_Campaign_Form_Task {
    *
    * @return array
    *   list of errors to be posted back to the form
-   * @static
    */
   public static function formRule($fields, $files, $self) {
     $errors = array();
     $invalidGroupName = FALSE;
     if (!empty($fields['newGroupName'])) {
-      $title  = trim($fields['newGroupName']);
-      $name   = CRM_Utils_String::titleToVar($title);
-      $query  = 'select count(*) from civicrm_group where name like %1 OR title like %2';
+      $title = trim($fields['newGroupName']);
+      $name = CRM_Utils_String::titleToVar($title);
+      $query = 'select count(*) from civicrm_group where name like %1 OR title like %2';
       $grpCnt = CRM_Core_DAO::singleValueQuery($query, array(
-      1 => array($name, 'String'),
-          2 => array($title, 'String'),
-        ));
+        1 => array($name, 'String'),
+        2 => array($title, 'String'),
+      ));
       if ($grpCnt) {
         $invalidGroupName = TRUE;
         $errors['newGroupName'] = ts('Group \'%1\' already exists.', array(1 => $fields['newGroupName']));
@@ -234,24 +239,24 @@ class CRM_Campaign_Form_Task_Reserve extends CRM_Campaign_Form_Task {
   }
 
   /**
-   * Process the form after the input has been submitted and validated
+   * Process the form after the input has been submitted and validated.
    *
    *
    * @return void
    */
   public function postProcess() {
     //add reservation.
-    $countVoters    = 0;
-    $maxVoters      = CRM_Utils_Array::value('max_number_of_contacts', $this->_surveyDetails);
+    $countVoters = 0;
+    $maxVoters = CRM_Utils_Array::value('max_number_of_contacts', $this->_surveyDetails);
     $activityStatus = CRM_Core_PseudoConstant::activityStatus('name');
-    $statusHeld     = array_search('Scheduled', $activityStatus);
+    $statusHeld = array_search('Scheduled', $activityStatus);
 
     $reservedVoterIds = array();
     foreach ($this->_contactIds as $cid) {
-      $subject        = ts('%1', array(1 => $this->_surveyDetails['title'])) . ' - ' . ts('Respondent Reservation');
-      $session        = CRM_Core_Session::singleton();
+      $subject = $this->_surveyDetails['title'] . ' - ' . ts('Respondent Reservation');
+      $session = CRM_Core_Session::singleton();
       $activityParams = array(
-      'source_contact_id' => $session->get('userID'),
+        'source_contact_id' => $session->get('userID'),
         'assignee_contact_id' => array($this->_interviewerId),
         'target_contact_id' => array($cid),
         'source_record_id' => $this->_surveyId,
@@ -277,18 +282,21 @@ class CRM_Campaign_Form_Task_Reserve extends CRM_Campaign_Form_Task {
 
     // Success message
     if ($countVoters > 0) {
-      $status = '<p>' . ts("%1 Contact(s) have been reserved.", array(1 => $countVoters)) . '</p>';
+      $status = '<p>' . ts("%count contact has been reserved.", array('plural' => '%count contacts have been reserved.', 'count' => $countVoters)) . '</p>';
       if ($groupAdditions) {
-        $status .= '<p>' . ts('Respondent(s) has been added to %1 group(s).',
-          array(1 => implode(', ', $groupAdditions))
-        ) . '</p>';
+        $status .= '<p>' . ts('They have been added to %1.',
+            array(1 => implode(' ' . ts('and') . ' ', $groupAdditions))
+          ) . '</p>';
       }
       CRM_Core_Session::setStatus($status, ts('Reservation Added'), 'success');
     }
     // Error message
     if (count($this->_contactIds) > $countVoters) {
-      CRM_Core_Session::setStatus(ts('Reservation did not add for %1 contact(s).',
-        array(1 => (count($this->_contactIds) - $countVoters))
+      CRM_Core_Session::setStatus(ts('Reservation did not add for %count contact.',
+        array(
+          'plural' => 'Reservation did not add for %count contacts.',
+          'count' => (count($this->_contactIds) - $countVoters),
+        )
       ), ts('Notice'));
     }
 
@@ -315,8 +323,8 @@ class CRM_Campaign_Form_Task_Reserve extends CRM_Campaign_Form_Task {
       return $groupAdditions;
     }
 
-    $params       = $this->controller->exportValues($this->_name);
-    $groups       = CRM_Utils_Array::value('groups', $params, array());
+    $params = $this->controller->exportValues($this->_name);
+    $groups = CRM_Utils_Array::value('groups', $params, array());
     $newGroupName = CRM_Utils_Array::value('newGroupName', $params);
     $newGroupDesc = CRM_Utils_Array::value('newGroupDesc', $params);
 
@@ -357,4 +365,5 @@ class CRM_Campaign_Form_Task_Reserve extends CRM_Campaign_Form_Task {
 
     return $groupAdditions;
   }
+
 }