| 1 | <?php |
| 2 | /* |
| 3 | +--------------------------------------------------------------------+ |
| 4 | | CiviCRM version 5 | |
| 5 | +--------------------------------------------------------------------+ |
| 6 | | Copyright CiviCRM LLC (c) 2004-2018 | |
| 7 | +--------------------------------------------------------------------+ |
| 8 | | This file is a part of CiviCRM. | |
| 9 | | | |
| 10 | | CiviCRM is free software; you can copy, modify, and distribute it | |
| 11 | | under the terms of the GNU Affero General Public License | |
| 12 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | |
| 13 | | | |
| 14 | | CiviCRM is distributed in the hope that it will be useful, but | |
| 15 | | WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 16 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | |
| 17 | | See the GNU Affero General Public License for more details. | |
| 18 | | | |
| 19 | | You should have received a copy of the GNU Affero General Public | |
| 20 | | License and the CiviCRM Licensing Exception along | |
| 21 | | with this program; if not, contact CiviCRM LLC | |
| 22 | | at info[AT]civicrm[DOT]org. If you have questions about the | |
| 23 | | GNU Affero General Public License or the licensing of CiviCRM, | |
| 24 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | |
| 25 | +--------------------------------------------------------------------+ |
| 26 | */ |
| 27 | |
| 28 | /** |
| 29 | * |
| 30 | * @package CRM |
| 31 | * @copyright CiviCRM LLC (c) 2004-2018 |
| 32 | */ |
| 33 | |
| 34 | /** |
| 35 | * This class generates form components for relationship. |
| 36 | */ |
| 37 | class CRM_Campaign_Form_Task extends CRM_Core_Form { |
| 38 | |
| 39 | /** |
| 40 | * The additional clause that we restrict the search. |
| 41 | * |
| 42 | * @var string |
| 43 | */ |
| 44 | protected $_componentClause = NULL; |
| 45 | |
| 46 | /** |
| 47 | * The task being performed |
| 48 | * |
| 49 | * @var int |
| 50 | */ |
| 51 | protected $_task; |
| 52 | |
| 53 | /** |
| 54 | * The array that holds all the contact ids |
| 55 | * |
| 56 | * @var array |
| 57 | */ |
| 58 | public $_contactIds; |
| 59 | |
| 60 | /** |
| 61 | * The array that holds all the component ids |
| 62 | * |
| 63 | * @var array |
| 64 | */ |
| 65 | protected $_componentIds; |
| 66 | |
| 67 | /** |
| 68 | * The array that holds all the voter ids |
| 69 | * |
| 70 | * @var array |
| 71 | */ |
| 72 | protected $_voterIds; |
| 73 | |
| 74 | /** |
| 75 | * Build all the data structures needed to build the form. |
| 76 | */ |
| 77 | public function preProcess() { |
| 78 | $values = $this->controller->exportValues('Search'); |
| 79 | |
| 80 | $this->_task = $values['task']; |
| 81 | $campaignTasks = CRM_Campaign_Task::tasks(); |
| 82 | $taskName = CRM_Utils_Array::value($this->_task, $campaignTasks); |
| 83 | $this->assign('taskName', $taskName); |
| 84 | |
| 85 | $ids = array(); |
| 86 | if ($values['radio_ts'] == 'ts_sel') { |
| 87 | foreach ($values as $name => $value) { |
| 88 | if (substr($name, 0, CRM_Core_Form::CB_PREFIX_LEN) == CRM_Core_Form::CB_PREFIX) { |
| 89 | $ids[] = substr($name, CRM_Core_Form::CB_PREFIX_LEN); |
| 90 | } |
| 91 | } |
| 92 | } |
| 93 | else { |
| 94 | $qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', $this); |
| 95 | $cacheKey = "civicrm search {$qfKey}"; |
| 96 | $allCids = CRM_Core_BAO_PrevNextCache::getSelection($cacheKey, "getall"); |
| 97 | $ids = array_keys($allCids[$cacheKey]); |
| 98 | $this->assign('totalSelectedVoters', count($ids)); |
| 99 | } |
| 100 | |
| 101 | if (!empty($ids)) { |
| 102 | $this->_componentClause = 'contact_a.id IN ( ' . implode(',', $ids) . ' ) '; |
| 103 | $this->assign('totalSelectedVoters', count($ids)); |
| 104 | } |
| 105 | $this->_voterIds = $this->_contactIds = $this->_componentIds = $ids; |
| 106 | |
| 107 | $this->assign('totalSelectedContacts', count($this->_contactIds)); |
| 108 | |
| 109 | //set the context for redirection for any task actions |
| 110 | $session = CRM_Core_Session::singleton(); |
| 111 | $qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', $this); |
| 112 | $urlParams = 'force=1'; |
| 113 | if (CRM_Utils_Rule::qfKey($qfKey)) { |
| 114 | $urlParams .= '&qfKey=' . $qfKey; |
| 115 | } |
| 116 | $session->replaceUserContext(CRM_Utils_System::url('civicrm/survey/search', $urlParams)); |
| 117 | } |
| 118 | |
| 119 | /** |
| 120 | * Given the voter id, compute the contact id |
| 121 | * since its used for things like send email |
| 122 | */ |
| 123 | public function setContactIDs() { |
| 124 | $this->_contactIds = $this->_voterIds; |
| 125 | } |
| 126 | |
| 127 | /** |
| 128 | * Simple shell that derived classes can call to add buttons to. |
| 129 | * the form with a customized title for the main Submit |
| 130 | * |
| 131 | * @param string $title |
| 132 | * Title of the main button. |
| 133 | * @param string $nextType |
| 134 | * Button type for the form after processing. |
| 135 | * @param string $backType |
| 136 | * @param bool $submitOnce |
| 137 | */ |
| 138 | public function addDefaultButtons($title, $nextType = 'next', $backType = 'back', $submitOnce = FALSE) { |
| 139 | $this->addButtons(array( |
| 140 | array( |
| 141 | 'type' => $nextType, |
| 142 | 'name' => $title, |
| 143 | 'isDefault' => TRUE, |
| 144 | ), |
| 145 | array( |
| 146 | 'type' => $backType, |
| 147 | 'name' => ts('Cancel'), |
| 148 | ), |
| 149 | ) |
| 150 | ); |
| 151 | } |
| 152 | |
| 153 | } |