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
19 class CRM_Event_BAO_ParticipantStatusType
extends CRM_Event_DAO_ParticipantStatusType
{
22 * @param array $params
26 public static function add(&$params) {
30 $dao = new CRM_Event_DAO_ParticipantStatusType();
31 $dao->copyValues($params);
36 * @param array $params
40 public static function &create(&$params) {
41 $transaction = new CRM_Core_Transaction();
42 $statusType = self
::add($params);
43 if (is_a($statusType, 'CRM_Core_Error')) {
44 $transaction->rollback();
47 $transaction->commit();
56 public static function deleteParticipantStatusType($id) {
57 // return early if there are participants with this status
58 $participant = new CRM_Event_DAO_Participant();
59 $participant->status_id
= $id;
60 if ($participant->find()) {
64 CRM_Utils_Weight
::delWeight('CRM_Event_DAO_ParticipantStatusType', $id);
66 $dao = new CRM_Event_DAO_ParticipantStatusType();
76 * @param array $params
79 * @return CRM_Event_DAO_ParticipantStatusType|null
81 public static function retrieve(&$params, &$defaults) {
84 $dao = new CRM_Event_DAO_ParticipantStatusType();
85 $dao->copyValues($params);
86 if ($dao->find(TRUE)) {
87 CRM_Core_DAO
::storeValues($dao, $defaults);
100 public static function setIsActive($id, $isActive) {
101 return CRM_Core_DAO
::setFieldValue('CRM_Event_BAO_ParticipantStatusType', $id, 'is_active', $isActive);
105 * @param array $params
109 public static function process($params) {
111 $returnMessages = [];
113 $pendingStatuses = CRM_Event_PseudoConstant
::participantStatus(NULL, "class = 'Pending'");
114 $expiredStatuses = CRM_Event_PseudoConstant
::participantStatus(NULL, "class = 'Negative'");
115 $waitingStatuses = CRM_Event_PseudoConstant
::participantStatus(NULL, "class = 'Waiting'");
117 //build the required status ids.
118 $statusIds = '(' . implode(',', array_merge(array_keys($pendingStatuses), array_keys($waitingStatuses))) . ')';
120 $participantDetails = $fullEvents = [];
121 $expiredParticipantCount = $waitingConfirmCount = $waitingApprovalCount = 0;
123 //get all participant who's status in class pending and waiting
125 SELECT participant.id,
126 participant.contact_id,
127 participant.status_id,
128 participant.register_date,
129 participant.registered_by_id,
130 participant.event_id,
131 event.title as eventTitle,
132 event.registration_start_date,
133 event.registration_end_date,
135 event.expiration_time,
136 event.requires_approval
137 FROM civicrm_participant participant
138 LEFT JOIN civicrm_event event ON ( event.id = participant.event_id )
139 WHERE participant.status_id IN {$statusIds}
140 AND (event.end_date > now() OR event.end_date IS NULL)
141 AND event.is_active = 1
142 ORDER BY participant.register_date, participant.id
144 $dao = CRM_Core_DAO
::executeQuery($query);
145 while ($dao->fetch()) {
146 $participantDetails[$dao->id
] = [
148 'event_id' => $dao->event_id
,
149 'status_id' => $dao->status_id
,
150 'contact_id' => $dao->contact_id
,
151 'register_date' => $dao->register_date
,
152 'registered_by_id' => $dao->registered_by_id
,
153 'eventTitle' => $dao->eventTitle
,
154 'registration_start_date' => $dao->registration_start_date
,
155 'registration_end_date' => $dao->registration_end_date
,
156 'end_date' => $dao->end_date
,
157 'expiration_time' => $dao->expiration_time
,
158 'requires_approval' => $dao->requires_approval
,
162 if (!empty($participantDetails)) {
163 //cron 1. move participant from pending to expire if needed
164 foreach ($participantDetails as $participantId => $values) {
165 //process the additional participant at the time of
166 //primary participant, don't process separately.
167 if (!empty($values['registered_by_id'])) {
171 $expirationTime = CRM_Utils_Array
::value('expiration_time', $values);
172 if ($expirationTime && array_key_exists($values['status_id'], $pendingStatuses)) {
174 //get the expiration and registration pending time.
175 $expirationSeconds = $expirationTime * 3600;
176 $registrationPendingSeconds = CRM_Utils_Date
::unixTime($values['register_date']);
178 // expired registration since registration cross allow confirmation time.
179 if (($expirationSeconds +
$registrationPendingSeconds) < time()) {
181 //lets get the transaction mechanism.
182 $transaction = new CRM_Core_Transaction();
184 $ids = [$participantId];
185 $expiredId = array_search('Expired', $expiredStatuses);
186 $results = CRM_Event_BAO_Participant
::transitionParticipants($ids, $expiredId, $values['status_id'], TRUE, TRUE);
187 $transaction->commit();
189 if (!empty($results)) {
190 //diaplay updated participants
191 if (is_array($results['updatedParticipantIds']) && !empty($results['updatedParticipantIds'])) {
192 foreach ($results['updatedParticipantIds'] as $processedId) {
193 $expiredParticipantCount +
= 1;
194 $returnMessages[] .= "<br />Status updated to: Expired";
196 //mailed participants.
197 if (is_array($results['mailedParticipants']) &&
198 array_key_exists($processedId, $results['mailedParticipants'])
200 $returnMessages[] .= "<br />Expiration Mail sent to: {$results['mailedParticipants'][$processedId]}";
210 //cron 2. lets move participants from waiting list to pending status
211 foreach ($participantDetails as $participantId => $values) {
212 //process the additional participant at the time of
213 //primary participant, don't process separately.
214 if (!empty($values['registered_by_id'])) {
218 if (array_key_exists($values['status_id'], $waitingStatuses) &&
219 !array_key_exists($values['event_id'], $fullEvents)
222 if ($waitingStatuses[$values['status_id']] == 'On waitlist' &&
223 CRM_Event_BAO_Event
::validRegistrationDate($values)
226 //check the target event having space.
227 $eventOpenSpaces = CRM_Event_BAO_Participant
::eventFull($values['event_id'], TRUE, FALSE);
229 if ($eventOpenSpaces && is_numeric($eventOpenSpaces) ||
($eventOpenSpaces === NULL)) {
231 //get the additional participant if any.
232 $additionalIds = CRM_Event_BAO_Participant
::getAdditionalParticipantIds($participantId);
234 $allIds = [$participantId];
235 if (!empty($additionalIds)) {
236 $allIds = array_merge($allIds, $additionalIds);
238 $pClause = ' participant.id IN ( ' . implode(' , ', $allIds) . ' )';
239 $requiredSpaces = CRM_Event_BAO_Event
::eventTotalSeats($values['event_id'], $pClause);
241 //need to check as to see if event has enough speces
242 if (($requiredSpaces <= $eventOpenSpaces) ||
($eventOpenSpaces === NULL)) {
243 $transaction = new CRM_Core_Transaction();
245 $ids = [$participantId];
246 $updateStatusId = array_search('Pending from waitlist', $pendingStatuses);
248 //lets take a call to make pending or need approval
249 if ($values['requires_approval']) {
250 $updateStatusId = array_search('Awaiting approval', $waitingStatuses);
252 $results = CRM_Event_BAO_Participant
::transitionParticipants($ids, $updateStatusId,
253 $values['status_id'], TRUE, TRUE
255 //commit the transaction.
256 $transaction->commit();
258 if (!empty($results)) {
259 //diaplay updated participants
260 if (is_array($results['updatedParticipantIds']) &&
261 !empty($results['updatedParticipantIds'])
263 foreach ($results['updatedParticipantIds'] as $processedId) {
264 if ($values['requires_approval']) {
265 $waitingApprovalCount +
= 1;
266 $returnMessages[] .= "<br /><br />- status updated to: Awaiting approval";
267 $returnMessages[] .= "<br />Will send you Confirmation Mail when registration gets approved.";
270 $waitingConfirmCount +
= 1;
271 $returnMessages[] .= "<br /><br />- status updated to: Pending from waitlist";
272 if (is_array($results['mailedParticipants']) &&
273 array_key_exists($processedId, $results['mailedParticipants'])
275 $returnMessages[] .= "<br />Confirmation Mail sent to: {$results['mailedParticipants'][$processedId]}";
283 //target event is full.
284 $fullEvents[$values['event_id']] = $values['eventTitle'];
288 //target event is full.
289 $fullEvents[$values['event_id']] = $values['eventTitle'];
297 $returnMessages[] .= "<br /><br />Number of Expired registration(s) = {$expiredParticipantCount}";
298 $returnMessages[] .= "<br />Number of registration(s) require approval = {$waitingApprovalCount}";
299 $returnMessages[] .= "<br />Number of registration changed to Pending from waitlist = {$waitingConfirmCount}<br /><br />";
300 if (!empty($fullEvents)) {
301 foreach ($fullEvents as $eventId => $title) {
302 $returnMessages[] .= "Full Event : {$title}<br />";
306 return ['is_error' => 0, 'messages' => $returnMessages];