Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
fee14197 | 4 | | CiviCRM version 5 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
6b83d5bd | 6 | | Copyright CiviCRM LLC (c) 2004-2019 | |
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 | |
6b83d5bd | 31 | * @copyright CiviCRM LLC (c) 2004-2019 |
6a488035 TO |
32 | */ |
33 | ||
34 | /** | |
3819f101 | 35 | * This class generates form components for relationship. |
6a488035 | 36 | */ |
31aaf096 | 37 | class CRM_Campaign_Form_Task extends CRM_Core_Form_Task { |
6a488035 TO |
38 | |
39 | /** | |
40 | * The array that holds all the voter ids | |
41 | * | |
42 | * @var array | |
43 | */ | |
44 | protected $_voterIds; | |
45 | ||
46 | /** | |
fe482240 | 47 | * Build all the data structures needed to build the form. |
95ea96be | 48 | */ |
87a890cc | 49 | public function preProcess() { |
6a488035 TO |
50 | $values = $this->controller->exportValues('Search'); |
51 | ||
353ffa53 | 52 | $this->_task = $values['task']; |
6a488035 | 53 | $campaignTasks = CRM_Campaign_Task::tasks(); |
353ffa53 | 54 | $taskName = CRM_Utils_Array::value($this->_task, $campaignTasks); |
6a488035 TO |
55 | $this->assign('taskName', $taskName); |
56 | ||
be2fb01f | 57 | $ids = []; |
6a488035 TO |
58 | if ($values['radio_ts'] == 'ts_sel') { |
59 | foreach ($values as $name => $value) { | |
60 | if (substr($name, 0, CRM_Core_Form::CB_PREFIX_LEN) == CRM_Core_Form::CB_PREFIX) { | |
61 | $ids[] = substr($name, CRM_Core_Form::CB_PREFIX_LEN); | |
62 | } | |
63 | } | |
64 | } | |
65 | else { | |
353ffa53 | 66 | $qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', $this); |
6a488035 | 67 | $cacheKey = "civicrm search {$qfKey}"; |
b7994703 | 68 | $allCids = Civi::service('prevnext')->getSelection($cacheKey, "getall"); |
6a488035 TO |
69 | $ids = array_keys($allCids[$cacheKey]); |
70 | $this->assign('totalSelectedVoters', count($ids)); | |
71 | } | |
72 | ||
73 | if (!empty($ids)) { | |
74 | $this->_componentClause = 'contact_a.id IN ( ' . implode(',', $ids) . ' ) '; | |
75 | $this->assign('totalSelectedVoters', count($ids)); | |
76 | } | |
77 | $this->_voterIds = $this->_contactIds = $this->_componentIds = $ids; | |
78 | ||
79 | $this->assign('totalSelectedContacts', count($this->_contactIds)); | |
80 | ||
81 | //set the context for redirection for any task actions | |
353ffa53 TO |
82 | $session = CRM_Core_Session::singleton(); |
83 | $qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', $this); | |
6a488035 TO |
84 | $urlParams = 'force=1'; |
85 | if (CRM_Utils_Rule::qfKey($qfKey)) { | |
86 | $urlParams .= '&qfKey=' . $qfKey; | |
87 | } | |
88 | $session->replaceUserContext(CRM_Utils_System::url('civicrm/survey/search', $urlParams)); | |
89 | } | |
90 | ||
91 | /** | |
92 | * Given the voter id, compute the contact id | |
93 | * since its used for things like send email | |
94 | */ | |
95 | public function setContactIDs() { | |
96 | $this->_contactIds = $this->_voterIds; | |
97 | } | |
98 | ||
99 | /** | |
fe482240 | 100 | * Simple shell that derived classes can call to add buttons to. |
6a488035 TO |
101 | * the form with a customized title for the main Submit |
102 | * | |
7aaf6db0 TO |
103 | * @param string $title |
104 | * Title of the main button. | |
105 | * @param string $nextType | |
106 | * Button type for the form after processing. | |
da6b46f4 EM |
107 | * @param string $backType |
108 | * @param bool $submitOnce | |
6a488035 | 109 | */ |
00be9182 | 110 | public function addDefaultButtons($title, $nextType = 'next', $backType = 'back', $submitOnce = FALSE) { |
be2fb01f CW |
111 | $this->addButtons([ |
112 | [ | |
6a488035 TO |
113 | 'type' => $nextType, |
114 | 'name' => $title, | |
115 | 'isDefault' => TRUE, | |
be2fb01f CW |
116 | ], |
117 | [ | |
6a488035 TO |
118 | 'type' => $backType, |
119 | 'name' => ts('Cancel'), | |
be2fb01f CW |
120 | ], |
121 | ] | |
6a488035 TO |
122 | ); |
123 | } | |
96025800 | 124 | |
6a488035 | 125 | } |