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