Merge pull request #18400 from aydun/class_api_tweak_2
[civicrm-core.git] / CRM / Campaign / Form / Task.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
10 */
11
12 /**
13 *
14 * @package CRM
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
16 */
17
18 /**
19 * This class generates form components for relationship.
20 */
21 class CRM_Campaign_Form_Task extends CRM_Core_Form_Task {
22
23 /**
24 * The array that holds all the voter ids
25 *
26 * @var array
27 */
28 protected $_voterIds;
29
30 /**
31 * Build all the data structures needed to build the form.
32 */
33 public function preProcess() {
34 $values = $this->controller->exportValues('Search');
35
36 $this->_task = $values['task'];
37
38 $ids = [];
39 if ($values['radio_ts'] == 'ts_sel') {
40 foreach ($values as $name => $value) {
41 if (substr($name, 0, CRM_Core_Form::CB_PREFIX_LEN) == CRM_Core_Form::CB_PREFIX) {
42 $ids[] = substr($name, CRM_Core_Form::CB_PREFIX_LEN);
43 }
44 }
45 }
46 else {
47 $qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', $this);
48 $cacheKey = "civicrm search {$qfKey}";
49 $allCids = Civi::service('prevnext')->getSelection($cacheKey, "getall");
50 $ids = array_keys($allCids[$cacheKey]);
51 $this->assign('totalSelectedVoters', count($ids));
52 }
53
54 if (!empty($ids)) {
55 $this->_componentClause = 'contact_a.id IN ( ' . implode(',', $ids) . ' ) ';
56 $this->assign('totalSelectedVoters', count($ids));
57 }
58 $this->_voterIds = $this->_contactIds = $this->_componentIds = $ids;
59
60 $this->assign('totalSelectedContacts', count($this->_contactIds));
61
62 //set the context for redirection for any task actions
63 $session = CRM_Core_Session::singleton();
64 $qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', $this);
65 $urlParams = 'force=1';
66 if (CRM_Utils_Rule::qfKey($qfKey)) {
67 $urlParams .= '&qfKey=' . $qfKey;
68 }
69 $session->replaceUserContext(CRM_Utils_System::url('civicrm/survey/search', $urlParams));
70 }
71
72 /**
73 * Given the voter id, compute the contact id
74 * since its used for things like send email
75 */
76 public function setContactIDs() {
77 $this->_contactIds = $this->_voterIds;
78 }
79
80 /**
81 * Simple shell that derived classes can call to add buttons to.
82 * the form with a customized title for the main Submit
83 *
84 * @param string $title
85 * Title of the main button.
86 * @param string $nextType
87 * Button type for the form after processing.
88 * @param string $backType
89 * @param bool $submitOnce
90 */
91 public function addDefaultButtons($title, $nextType = 'next', $backType = 'back', $submitOnce = FALSE) {
92 $this->addButtons([
93 [
94 'type' => $nextType,
95 'name' => $title,
96 'isDefault' => TRUE,
97 ],
98 [
99 'type' => $backType,
100 'name' => ts('Cancel'),
101 ],
102 ]);
103 }
104
105 }