now() OR event.end_date IS NULL) AND event.is_active = 1 ORDER BY participant.register_date, participant.id "; $dao = CRM_Core_DAO::executeQuery($query); while ($dao->fetch()) { $participantDetails[$dao->id] = array( 'id' => $dao->id, 'event_id' => $dao->event_id, 'status_id' => $dao->status_id, 'contact_id' => $dao->contact_id, 'register_date' => $dao->register_date, 'registered_by_id' => $dao->registered_by_id, 'eventTitle' => $dao->eventTitle, 'registration_start_date' => $dao->registration_start_date, 'registration_end_date' => $dao->registration_end_date, 'end_date' => $dao->end_date, 'expiration_time' => $dao->expiration_time, 'requires_approval' => $dao->requires_approval, ); } if (!empty($participantDetails)) { //cron 1. move participant from pending to expire if needed foreach ($participantDetails as $participantId => $values) { //process the additional participant at the time of //primary participant, don't process separately. if (!empty($values['registered_by_id'])) { continue; } $expirationTime = CRM_Utils_Array::value('expiration_time', $values); if ($expirationTime && array_key_exists($values['status_id'], $pendingStatuses)) { //get the expiration and registration pending time. $expirationSeconds = $expirationTime * 3600; $registrationPendingSeconds = CRM_Utils_Date::unixTime($values['register_date']); // expired registration since registration cross allow confirmation time. if (($expirationSeconds + $registrationPendingSeconds) < time()) { //lets get the transaction mechanism. require_once 'CRM/Core/Transaction.php'; $transaction = new CRM_Core_Transaction(); require_once 'CRM/Event/BAO/Participant.php'; $ids = array($participantId); $expiredId = array_search('Expired', $expiredStatuses); $results = CRM_Event_BAO_Participant::transitionParticipants($ids, $expiredId, $values['status_id'], TRUE, TRUE); $transaction->commit(); if (!empty($results)) { //diaplay updated participants if (is_array($results['updatedParticipantIds']) && !empty($results['updatedParticipantIds'])) { foreach ($results['updatedParticipantIds'] as $processedId) { $expiredParticipantCount += 1; echo "

- status updated to: Expired"; //mailed participants. if (is_array($results['mailedParticipants']) && array_key_exists($processedId, $results['mailedParticipants']) ) { echo "
Expiration Mail sent to: {$results['mailedParticipants'][$processedId]}"; } } } } } } } //cron 1 end. //cron 2. lets move participants from waiting list to pending status foreach ($participantDetails as $participantId => $values) { //process the additional participant at the time of //primary participant, don't process separately. if (!empty($values['registered_by_id'])) { continue; } if (array_key_exists($values['status_id'], $waitingStatuses) && !array_key_exists($values['event_id'], $fullEvents) ) { if ($waitingStatuses[$values['status_id']] == 'On waitlist' && CRM_Event_BAO_Event::validRegistrationDate($values) ) { //check the target event having space. require_once 'CRM/Event/BAO/Participant.php'; $eventOpenSpaces = CRM_Event_BAO_Participant::eventFull($values['event_id'], TRUE, FALSE); if ($eventOpenSpaces && is_numeric($eventOpenSpaces) || ($eventOpenSpaces === NULL)) { //get the additional participant if any. $additionalIds = CRM_Event_BAO_Participant::getAdditionalParticipantIds($participantId); $allIds = array($participantId); if (!empty($additionalIds)) { $allIds = array_merge($allIds, $additionalIds); } $pClause = ' participant.id IN ( ' . implode(' , ', $allIds) . ' )'; $requiredSpaces = CRM_Event_BAO_Event::eventTotalSeats($values['event_id'], $pClause); //need to check as to see if event has enough speces if (($requiredSpaces <= $eventOpenSpaces) || ($eventOpenSpaces === NULL)) { require_once 'CRM/Core/Transaction.php'; $transaction = new CRM_Core_Transaction(); require_once 'CRM/Event/BAO/Participant.php'; $ids = array($participantId); $updateStatusId = array_search('Pending from waitlist', $pendingStatuses); //lets take a call to make pending or need approval if ($values['requires_approval']) { $updateStatusId = array_search('Awaiting approval', $waitingStatuses); } $results = CRM_Event_BAO_Participant::transitionParticipants($ids, $updateStatusId, $values['status_id'], TRUE, TRUE ); //commit the transaction. $transaction->commit(); if (!empty($results)) { //diaplay updated participants if (is_array($results['updatedParticipantIds']) && !empty($results['updatedParticipantIds']) ) { foreach ($results['updatedParticipantIds'] as $processedId) { if ($values['requires_approval']) { $waitingApprovalCount += 1; echo "

- status updated to: Awaiting approval"; echo "
Will send you Confirmation Mail when registration get approved."; } else { $waitingConfirmCount += 1; echo "

- status updated to: Pending from waitlist"; if (is_array($results['mailedParticipants']) && array_key_exists($processedId, $results['mailedParticipants']) ) { echo "
Confirmation Mail sent to: {$results['mailedParticipants'][$processedId]}"; } } } } } } else { //target event is full. $fullEvents[$values['event_id']] = $values['eventTitle']; } } else { //target event is full. $fullEvents[$values['event_id']] = $values['eventTitle']; } } } } //cron 2 ends. } echo "

Number of Expired registration(s) = {$expiredParticipantCount}"; echo "
Number of registration(s) require approval = {$waitingApprovalCount}"; echo "
Number of registration changed to Pending from waitlist = {$waitingConfirmCount}

"; if (!empty($fullEvents)) { foreach ($fullEvents as $eventId => $title) { echo "Full Event : {$title}
"; } } } } $obj = new CRM_ParticipantProcessor(); echo "Updating.."; $obj->updateParticipantStatus(); echo "
Participant records updated. (Done)";