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