Commit | Line | Data |
---|---|---|
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 | * $Id$ |
17 | * | |
18 | */ | |
19 | ||
20 | /** | |
31aaf096 MW |
21 | * Class for event form task actions. |
22 | * FIXME: This needs refactoring to properly inherit from CRM_Core_Form_Task and share more functions. | |
6a488035 | 23 | */ |
31aaf096 | 24 | class CRM_Event_Form_Task extends CRM_Core_Form_Task { |
6a488035 TO |
25 | |
26 | /** | |
66f9e52b | 27 | * The array that holds all the participant ids. |
6a488035 TO |
28 | * |
29 | * @var array | |
30 | */ | |
31 | protected $_participantIds; | |
32 | ||
33 | /** | |
66f9e52b | 34 | * Build all the data structures needed to build the form. |
6a488035 TO |
35 | * |
36 | * @param | |
37 | * | |
38 | * @return void | |
6a488035 | 39 | */ |
00be9182 | 40 | public function preProcess() { |
6a488035 TO |
41 | self::preProcessCommon($this); |
42 | } | |
43 | ||
0cf587a7 | 44 | /** |
c490a46a | 45 | * @param CRM_Core_Form $form |
0cf587a7 | 46 | */ |
2b089ce1 | 47 | public static function preProcessCommon(&$form) { |
be2fb01f | 48 | $form->_participantIds = []; |
6a488035 TO |
49 | |
50 | $values = $form->controller->exportValues($form->get('searchFormName')); | |
51 | ||
52 | $form->_task = $values['task']; | |
8fd26836 MW |
53 | $tasks = CRM_Event_Task::permissionedTaskTitles(CRM_Core_Permission::getPermission()); |
54 | if (!array_key_exists($form->_task, $tasks)) { | |
55 | CRM_Core_Error::statusBounce(ts('You do not have permission to access this page.')); | |
56 | } | |
57 | $form->assign('taskName', $tasks[$form->_task]); | |
6a488035 | 58 | |
be2fb01f | 59 | $ids = []; |
6a488035 TO |
60 | if ($values['radio_ts'] == 'ts_sel') { |
61 | foreach ($values as $name => $value) { | |
62 | if (substr($name, 0, CRM_Core_Form::CB_PREFIX_LEN) == CRM_Core_Form::CB_PREFIX) { | |
63 | $ids[] = substr($name, CRM_Core_Form::CB_PREFIX_LEN); | |
64 | } | |
65 | } | |
66 | } | |
67 | else { | |
68 | $queryParams = $form->get('queryParams'); | |
69 | $sortOrder = NULL; | |
70 | if ($form->get(CRM_Utils_Sort::SORT_ORDER)) { | |
71 | $sortOrder = $form->get(CRM_Utils_Sort::SORT_ORDER); | |
72 | } | |
73 | ||
74 | $query = new CRM_Contact_BAO_Query($queryParams, NULL, NULL, FALSE, FALSE, | |
75 | CRM_Contact_BAO_Query::MODE_EVENT | |
76 | ); | |
77 | $query->_distinctComponentClause = "civicrm_participant.id"; | |
78 | $query->_groupByComponentClause = " GROUP BY civicrm_participant.id "; | |
79 | $result = $query->searchQuery(0, 0, $sortOrder); | |
80 | while ($result->fetch()) { | |
81 | $ids[] = $result->participant_id; | |
82 | } | |
83 | } | |
84 | ||
85 | if (!empty($ids)) { | |
86 | $form->_componentClause = ' civicrm_participant.id IN ( ' . implode(',', $ids) . ' ) '; | |
87 | $form->assign('totalSelectedParticipants', count($ids)); | |
88 | } | |
89 | ||
90 | $form->_participantIds = $form->_componentIds = $ids; | |
91 | ||
92 | //set the context for redirection for any task actions | |
93 | $session = CRM_Core_Session::singleton(); | |
94 | ||
ffa4f50c | 95 | $qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', $form); |
6a488035 TO |
96 | $urlParams = 'force=1'; |
97 | if (CRM_Utils_Rule::qfKey($qfKey)) { | |
98 | $urlParams .= "&qfKey=$qfKey"; | |
99 | } | |
100 | ||
101 | $searchFormName = strtolower($form->get('searchFormName')); | |
102 | if ($searchFormName == 'search') { | |
103 | $session->replaceUserContext(CRM_Utils_System::url('civicrm/event/search', $urlParams)); | |
104 | } | |
105 | else { | |
106 | $session->replaceUserContext(CRM_Utils_System::url("civicrm/contact/search/$searchFormName", | |
353ffa53 TO |
107 | $urlParams |
108 | )); | |
6a488035 TO |
109 | } |
110 | } | |
111 | ||
112 | /** | |
113 | * Given the participant id, compute the contact id | |
114 | * since its used for things like send email | |
115 | */ | |
116 | public function setContactIDs() { | |
a301608a | 117 | $this->_contactIds = CRM_Core_DAO::getContactIDsFromComponent($this->_participantIds, |
6a488035 TO |
118 | 'civicrm_participant' |
119 | ); | |
120 | } | |
121 | ||
122 | /** | |
66f9e52b | 123 | * Simple shell that derived classes can call to add buttons to. |
6a488035 TO |
124 | * the form with a customized title for the main Submit |
125 | * | |
d4dd1e85 TO |
126 | * @param string $title |
127 | * Title of the main button. | |
da6b46f4 EM |
128 | * @param string $nextType |
129 | * @param string $backType | |
130 | * @param bool $submitOnce | |
131 | * | |
6a488035 | 132 | * @return void |
6a488035 | 133 | */ |
00be9182 | 134 | public function addDefaultButtons($title, $nextType = 'next', $backType = 'back', $submitOnce = FALSE) { |
be2fb01f | 135 | $this->addButtons([ |
90b461f1 SL |
136 | [ |
137 | 'type' => $nextType, | |
138 | 'name' => $title, | |
139 | 'isDefault' => TRUE, | |
140 | ], | |
141 | [ | |
142 | 'type' => $backType, | |
143 | 'name' => ts('Cancel'), | |
144 | ], | |
145 | ]); | |
6a488035 | 146 | } |
96025800 | 147 | |
6a488035 | 148 | } |