3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
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 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
18 use Civi\Api4\Participant
;
21 * Class for event form task actions.
22 * FIXME: This needs refactoring to properly inherit from CRM_Core_Form_Task and share more functions.
24 class CRM_Event_Form_Task
extends CRM_Core_Form_Task
{
27 * The array that holds all the participant ids.
31 protected $_participantIds;
36 * Each row will have a participant ID & a contact ID using
37 * the keys the token processor expects.
44 * Build all the data structures needed to build the form.
50 public function preProcess() {
51 self
::preProcessCommon($this);
55 * @param CRM_Core_Form_Task $form
57 public static function preProcessCommon(&$form) {
58 $form->_participantIds
= [];
60 $values = $form->getSearchFormValues();
62 $form->_task
= $values['task'];
63 $tasks = CRM_Event_Task
::permissionedTaskTitles(CRM_Core_Permission
::getPermission());
64 if (!array_key_exists($form->_task
, $tasks)) {
65 CRM_Core_Error
::statusBounce(ts('You do not have permission to access this page.'));
68 $ids = $form->getSelectedIDs($values);
71 $queryParams = $form->get('queryParams');
73 if ($form->get(CRM_Utils_Sort
::SORT_ORDER
)) {
74 $sortOrder = $form->get(CRM_Utils_Sort
::SORT_ORDER
);
77 $query = new CRM_Contact_BAO_Query($queryParams, NULL, NULL, FALSE, FALSE,
78 CRM_Contact_BAO_Query
::MODE_EVENT
80 $query->_distinctComponentClause
= "civicrm_participant.id";
81 $query->_groupByComponentClause
= " GROUP BY civicrm_participant.id ";
82 $result = $query->searchQuery(0, 0, $sortOrder);
83 while ($result->fetch()) {
84 $ids[] = $result->participant_id
;
89 $form->_componentClause
= ' civicrm_participant.id IN ( ' . implode(',', $ids) . ' ) ';
90 $form->assign('totalSelectedParticipants', count($ids));
93 $form->_participantIds
= $form->_componentIds
= $ids;
95 $form->setNextUrl('event');
99 * Get the participant IDs.
103 public function getIDs(): array {
104 return $this->_participantIds
;
108 * Given the participant id, compute the contact id
109 * since its used for things like send email
111 public function setContactIDs(): void
{
112 $this->_contactIds
= $this->getContactIDs();
116 * Get the relevant contact IDs.
120 protected function getContactIDs(): array {
121 if (isset($this->_contactIds
)) {
122 return $this->_contactIds
;
124 foreach ($this->getRows() as $row) {
125 $this->_contactIds
[] = $row['contact_id'];
127 return $this->_contactIds
;
131 * Simple shell that derived classes can call to add buttons to.
132 * the form with a customized title for the main Submit
134 * @param string $title
135 * Title of the main button.
136 * @param string $nextType
137 * @param string $backType
138 * @param bool $submitOnce
142 public function addDefaultButtons($title, $nextType = 'next', $backType = 'back', $submitOnce = FALSE) {
151 'name' => ts('Cancel'),
157 * Get the rows form the search, keyed to make the token processor happy.
159 * @throws \API_Exception
161 protected function getRows(): array {
162 if (empty($this->rows
)) {
163 // checkPermissions set to false - in case form is bypassing in some way.
164 $participants = Participant
::get(FALSE)
165 ->addWhere('id', 'IN', $this->getIDs())
166 ->setSelect(['id', 'contact_id'])->execute();
167 foreach ($participants as $participant) {
169 'contact_id' => $participant['contact_id'],
170 'participant_id' => $participant['id'],
172 'contactId' => $participant['contact_id'],
173 'participantId' => $participant['id'],
182 * Get the token processor schema required to list any tokens for this task.
186 public function getTokenSchema(): array {
187 return ['participantId', 'contactId', 'eventId'];