Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
39de6fd5 | 4 | | CiviCRM version 4.6 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
e7112fa7 | 6 | | Copyright CiviCRM LLC (c) 2004-2015 | |
6a488035 TO |
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 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
6a488035 TO |
27 | |
28 | /** | |
29 | * | |
30 | * @package CRM | |
e7112fa7 | 31 | * @copyright CiviCRM LLC (c) 2004-2015 |
6a488035 TO |
32 | * $Id$ |
33 | * | |
34 | */ | |
35 | ||
36 | /** | |
37 | * This class generates form components for relationship | |
38 | * | |
39 | */ | |
40 | class CRM_Campaign_Form_Task extends CRM_Core_Form { | |
41 | ||
42 | /** | |
43 | * The additional clause that we restrict the search. | |
44 | * | |
45 | * @var string | |
46 | */ | |
47 | protected $_componentClause = NULL; | |
48 | ||
49 | /** | |
100fef9d | 50 | * The task being performed |
6a488035 TO |
51 | * |
52 | * @var int | |
53 | */ | |
54 | protected $_task; | |
55 | ||
56 | /** | |
57 | * The array that holds all the contact ids | |
58 | * | |
59 | * @var array | |
60 | */ | |
61 | public $_contactIds; | |
62 | ||
63 | /** | |
64 | * The array that holds all the component ids | |
65 | * | |
66 | * @var array | |
67 | */ | |
68 | protected $_componentIds; | |
69 | ||
70 | /** | |
71 | * The array that holds all the voter ids | |
72 | * | |
73 | * @var array | |
74 | */ | |
75 | protected $_voterIds; | |
76 | ||
77 | /** | |
fe482240 | 78 | * Build all the data structures needed to build the form. |
6a488035 TO |
79 | * |
80 | * @param | |
81 | * | |
82 | * @return void | |
95ea96be | 83 | */ |
87a890cc | 84 | public function preProcess() { |
6a488035 TO |
85 | $values = $this->controller->exportValues('Search'); |
86 | ||
353ffa53 | 87 | $this->_task = $values['task']; |
6a488035 | 88 | $campaignTasks = CRM_Campaign_Task::tasks(); |
353ffa53 | 89 | $taskName = CRM_Utils_Array::value($this->_task, $campaignTasks); |
6a488035 TO |
90 | $this->assign('taskName', $taskName); |
91 | ||
92 | $ids = array(); | |
93 | if ($values['radio_ts'] == 'ts_sel') { | |
94 | foreach ($values as $name => $value) { | |
95 | if (substr($name, 0, CRM_Core_Form::CB_PREFIX_LEN) == CRM_Core_Form::CB_PREFIX) { | |
96 | $ids[] = substr($name, CRM_Core_Form::CB_PREFIX_LEN); | |
97 | } | |
98 | } | |
99 | } | |
100 | else { | |
353ffa53 | 101 | $qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', $this); |
6a488035 | 102 | $cacheKey = "civicrm search {$qfKey}"; |
353ffa53 | 103 | $allCids = CRM_Core_BAO_PrevNextCache::getSelection($cacheKey, "getall"); |
6a488035 TO |
104 | $ids = array_keys($allCids[$cacheKey]); |
105 | $this->assign('totalSelectedVoters', count($ids)); | |
106 | } | |
107 | ||
108 | if (!empty($ids)) { | |
109 | $this->_componentClause = 'contact_a.id IN ( ' . implode(',', $ids) . ' ) '; | |
110 | $this->assign('totalSelectedVoters', count($ids)); | |
111 | } | |
112 | $this->_voterIds = $this->_contactIds = $this->_componentIds = $ids; | |
113 | ||
114 | $this->assign('totalSelectedContacts', count($this->_contactIds)); | |
115 | ||
116 | //set the context for redirection for any task actions | |
353ffa53 TO |
117 | $session = CRM_Core_Session::singleton(); |
118 | $qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', $this); | |
6a488035 TO |
119 | $urlParams = 'force=1'; |
120 | if (CRM_Utils_Rule::qfKey($qfKey)) { | |
121 | $urlParams .= '&qfKey=' . $qfKey; | |
122 | } | |
123 | $session->replaceUserContext(CRM_Utils_System::url('civicrm/survey/search', $urlParams)); | |
124 | } | |
125 | ||
126 | /** | |
127 | * Given the voter id, compute the contact id | |
128 | * since its used for things like send email | |
129 | */ | |
130 | public function setContactIDs() { | |
131 | $this->_contactIds = $this->_voterIds; | |
132 | } | |
133 | ||
134 | /** | |
fe482240 | 135 | * Simple shell that derived classes can call to add buttons to. |
6a488035 TO |
136 | * the form with a customized title for the main Submit |
137 | * | |
7aaf6db0 TO |
138 | * @param string $title |
139 | * Title of the main button. | |
140 | * @param string $nextType | |
141 | * Button type for the form after processing. | |
da6b46f4 EM |
142 | * @param string $backType |
143 | * @param bool $submitOnce | |
144 | * | |
6a488035 | 145 | * @return void |
6a488035 | 146 | */ |
00be9182 | 147 | public function addDefaultButtons($title, $nextType = 'next', $backType = 'back', $submitOnce = FALSE) { |
6a488035 TO |
148 | $this->addButtons(array( |
149 | array( | |
150 | 'type' => $nextType, | |
151 | 'name' => $title, | |
152 | 'isDefault' => TRUE, | |
153 | ), | |
154 | array( | |
155 | 'type' => $backType, | |
156 | 'name' => ts('Cancel'), | |
157 | ), | |
158 | ) | |
159 | ); | |
160 | } | |
96025800 | 161 | |
6a488035 | 162 | } |