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
17 class CRM_Event_BAO_ParticipantStatusType
extends CRM_Event_DAO_ParticipantStatusType
{
20 * @param array $params
24 public static function add(&$params) {
28 $dao = new CRM_Event_DAO_ParticipantStatusType();
29 $dao->copyValues($params);
34 * @param array $params
38 public static function &create(&$params) {
39 $transaction = new CRM_Core_Transaction();
40 $statusType = self
::add($params);
41 if (is_a($statusType, 'CRM_Core_Error')) {
42 $transaction->rollback();
45 $transaction->commit();
54 public static function deleteParticipantStatusType($id) {
55 // return early if there are participants with this status
56 $participant = new CRM_Event_DAO_Participant();
57 $participant->status_id
= $id;
58 if ($participant->find()) {
62 CRM_Utils_Weight
::delWeight('CRM_Event_DAO_ParticipantStatusType', $id);
64 $dao = new CRM_Event_DAO_ParticipantStatusType();
74 * @param array $params
77 * @return CRM_Event_DAO_ParticipantStatusType|null
79 public static function retrieve(&$params, &$defaults) {
82 $dao = new CRM_Event_DAO_ParticipantStatusType();
83 $dao->copyValues($params);
84 if ($dao->find(TRUE)) {
85 CRM_Core_DAO
::storeValues($dao, $defaults);
98 public static function setIsActive($id, $isActive) {
99 return CRM_Core_DAO
::setFieldValue('CRM_Event_BAO_ParticipantStatusType', $id, 'is_active', $isActive);
103 * @param array $params
107 public static function process($params) {
109 $returnMessages = [];
111 $pendingStatuses = CRM_Event_PseudoConstant
::participantStatus(NULL, "class = 'Pending'");
112 $expiredStatuses = CRM_Event_PseudoConstant
::participantStatus(NULL, "class = 'Negative'");
113 $waitingStatuses = CRM_Event_PseudoConstant
::participantStatus(NULL, "class = 'Waiting'");
115 //build the required status ids.
116 $statusIds = '(' . implode(',', array_merge(array_keys($pendingStatuses), array_keys($waitingStatuses))) . ')';
118 $participantDetails = $fullEvents = [];
119 $expiredParticipantCount = $waitingConfirmCount = $waitingApprovalCount = 0;
121 //get all participant who's status in class pending and waiting
123 SELECT participant.id,
124 participant.contact_id,
125 participant.status_id,
126 participant.register_date,
127 participant.registered_by_id,
128 participant.event_id,
129 event.title as eventTitle,
130 event.registration_start_date,
131 event.registration_end_date,
133 event.expiration_time,
134 event.requires_approval
135 FROM civicrm_participant participant
136 LEFT JOIN civicrm_event event ON ( event.id = participant.event_id )
137 WHERE participant.status_id IN {$statusIds}
138 AND (event.end_date > now() OR event.end_date IS NULL)
139 AND event.is_active = 1
140 ORDER BY participant.register_date, participant.id
142 $dao = CRM_Core_DAO
::executeQuery($query);
143 while ($dao->fetch()) {
144 $participantDetails[$dao->id
] = [
146 'event_id' => $dao->event_id
,
147 'status_id' => $dao->status_id
,
148 'contact_id' => $dao->contact_id
,
149 'register_date' => $dao->register_date
,
150 'registered_by_id' => $dao->registered_by_id
,
151 'eventTitle' => $dao->eventTitle
,
152 'registration_start_date' => $dao->registration_start_date
,
153 'registration_end_date' => $dao->registration_end_date
,
154 'end_date' => $dao->end_date
,
155 'expiration_time' => $dao->expiration_time
,
156 'requires_approval' => $dao->requires_approval
,
160 if (!empty($participantDetails)) {
161 //cron 1. move participant from pending to expire if needed
162 foreach ($participantDetails as $participantId => $values) {
163 //process the additional participant at the time of
164 //primary participant, don't process separately.
165 if (!empty($values['registered_by_id'])) {
169 $expirationTime = $values['expiration_time'] ??
NULL;
170 if ($expirationTime && array_key_exists($values['status_id'], $pendingStatuses)) {
172 //get the expiration and registration pending time.
173 $expirationSeconds = $expirationTime * 3600;
174 $registrationPendingSeconds = CRM_Utils_Date
::unixTime($values['register_date']);
176 // expired registration since registration cross allow confirmation time.
177 if (($expirationSeconds +
$registrationPendingSeconds) < time()) {
179 //lets get the transaction mechanism.
180 $transaction = new CRM_Core_Transaction();
182 $ids = [$participantId];
183 $expiredId = array_search('Expired', $expiredStatuses);
184 $results = CRM_Event_BAO_Participant
::transitionParticipants($ids, $expiredId, $values['status_id'], TRUE, TRUE);
185 $transaction->commit();
187 if (!empty($results)) {
188 //diaplay updated participants
189 if (is_array($results['updatedParticipantIds']) && !empty($results['updatedParticipantIds'])) {
190 foreach ($results['updatedParticipantIds'] as $processedId) {
191 $expiredParticipantCount +
= 1;
192 $returnMessages[] .= "<br />Status updated to: Expired";
194 //mailed participants.
195 if (is_array($results['mailedParticipants']) &&
196 array_key_exists($processedId, $results['mailedParticipants'])
198 $returnMessages[] .= "<br />Expiration Mail sent to: {$results['mailedParticipants'][$processedId]}";
208 //cron 2. lets move participants from waiting list to pending status
209 foreach ($participantDetails as $participantId => $values) {
210 //process the additional participant at the time of
211 //primary participant, don't process separately.
212 if (!empty($values['registered_by_id'])) {
216 if (array_key_exists($values['status_id'], $waitingStatuses) &&
217 !array_key_exists($values['event_id'], $fullEvents)
220 if ($waitingStatuses[$values['status_id']] == 'On waitlist' &&
221 CRM_Event_BAO_Event
::validRegistrationDate($values)
224 //check the target event having space.
225 $eventOpenSpaces = CRM_Event_BAO_Participant
::eventFull($values['event_id'], TRUE, FALSE);
227 if ($eventOpenSpaces && is_numeric($eventOpenSpaces) ||
($eventOpenSpaces === NULL)) {
229 //get the additional participant if any.
230 $additionalIds = CRM_Event_BAO_Participant
::getAdditionalParticipantIds($participantId);
232 $allIds = [$participantId];
233 if (!empty($additionalIds)) {
234 $allIds = array_merge($allIds, $additionalIds);
236 $pClause = ' participant.id IN ( ' . implode(' , ', $allIds) . ' )';
237 $requiredSpaces = CRM_Event_BAO_Event
::eventTotalSeats($values['event_id'], $pClause);
239 //need to check as to see if event has enough speces
240 if (($requiredSpaces <= $eventOpenSpaces) ||
($eventOpenSpaces === NULL)) {
241 $transaction = new CRM_Core_Transaction();
243 $ids = [$participantId];
244 $updateStatusId = array_search('Pending from waitlist', $pendingStatuses);
246 //lets take a call to make pending or need approval
247 if ($values['requires_approval']) {
248 $updateStatusId = array_search('Awaiting approval', $waitingStatuses);
250 $results = CRM_Event_BAO_Participant
::transitionParticipants($ids, $updateStatusId,
251 $values['status_id'], TRUE, TRUE
253 //commit the transaction.
254 $transaction->commit();
256 if (!empty($results)) {
257 //diaplay updated participants
258 if (is_array($results['updatedParticipantIds']) &&
259 !empty($results['updatedParticipantIds'])
261 foreach ($results['updatedParticipantIds'] as $processedId) {
262 if ($values['requires_approval']) {
263 $waitingApprovalCount +
= 1;
264 $returnMessages[] .= "<br /><br />- status updated to: Awaiting approval";
265 $returnMessages[] .= "<br />Will send you Confirmation Mail when registration gets approved.";
268 $waitingConfirmCount +
= 1;
269 $returnMessages[] .= "<br /><br />- status updated to: Pending from waitlist";
270 if (is_array($results['mailedParticipants']) &&
271 array_key_exists($processedId, $results['mailedParticipants'])
273 $returnMessages[] .= "<br />Confirmation Mail sent to: {$results['mailedParticipants'][$processedId]}";
281 //target event is full.
282 $fullEvents[$values['event_id']] = $values['eventTitle'];
286 //target event is full.
287 $fullEvents[$values['event_id']] = $values['eventTitle'];
295 $returnMessages[] .= "<br /><br />Number of Expired registration(s) = {$expiredParticipantCount}";
296 $returnMessages[] .= "<br />Number of registration(s) require approval = {$waitingApprovalCount}";
297 $returnMessages[] .= "<br />Number of registration changed to Pending from waitlist = {$waitingConfirmCount}<br /><br />";
298 if (!empty($fullEvents)) {
299 foreach ($fullEvents as $eventId => $title) {
300 $returnMessages[] .= "Full Event : {$title}<br />";
304 return ['is_error' => 0, 'messages' => $returnMessages];