3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
30 * This file check and updates the status of all participant records.
32 * EventParticipantion.php prior to running this script.
35 require_once '../civicrm.config.php';
36 require_once 'CRM/Core/Config.php';
37 class CRM_ParticipantProcessor
{
38 function __construct() {
39 $config = CRM_Core_Config
::singleton();
41 //this does not return on failure
42 require_once 'CRM/Utils/System.php';
43 require_once 'CRM/Utils/Hook.php';
45 CRM_Utils_System
::authenticateScript(TRUE);
47 //log the execution time of script
48 CRM_Core_Error
::debug_log_message('ParticipantProcessor.php');
51 public function updateParticipantStatus() {
52 require_once 'CRM/Event/PseudoConstant.php';
53 $participantRole = CRM_Event_PseudoConstant
::participantRole();
54 $pendingStatuses = CRM_Event_PseudoConstant
::participantStatus(NULL, "class = 'Pending'");
55 $expiredStatuses = CRM_Event_PseudoConstant
::participantStatus(NULL, "class = 'Negative'");
56 $waitingStatuses = CRM_Event_PseudoConstant
::participantStatus(NULL, "class = 'Waiting'");
58 //build the required status ids.
59 $statusIds = '(' . implode(',', array_merge(array_keys($pendingStatuses), array_keys($waitingStatuses))) . ')';
61 $participantDetails = $fullEvents = array();
62 $expiredParticipantCount = $waitingConfirmCount = $waitingApprovalCount = 0;
64 //get all participant who's status in class pending and waiting
65 $query = "SELECT * FROM civicrm_participant WHERE status_id IN {$statusIds} ORDER BY register_date";
68 SELECT participant.id,
69 participant.contact_id,
70 participant.status_id,
71 participant.register_date,
72 participant.registered_by_id,
74 event.title as eventTitle,
75 event.registration_start_date,
76 event.registration_end_date,
78 event.expiration_time,
79 event.requires_approval
80 FROM civicrm_participant participant
81 LEFT JOIN civicrm_event event ON ( event.id = participant.event_id )
82 WHERE participant.status_id IN {$statusIds}
83 AND (event.end_date > now() OR event.end_date IS NULL)
84 AND event.is_active = 1
85 ORDER BY participant.register_date, participant.id
87 $dao = CRM_Core_DAO
::executeQuery($query);
88 while ($dao->fetch()) {
89 $participantDetails[$dao->id
] = array(
91 'event_id' => $dao->event_id
,
92 'status_id' => $dao->status_id
,
93 'contact_id' => $dao->contact_id
,
94 'register_date' => $dao->register_date
,
95 'registered_by_id' => $dao->registered_by_id
,
96 'eventTitle' => $dao->eventTitle
,
97 'registration_start_date' => $dao->registration_start_date
,
98 'registration_end_date' => $dao->registration_end_date
,
99 'end_date' => $dao->end_date
,
100 'expiration_time' => $dao->expiration_time
,
101 'requires_approval' => $dao->requires_approval
,
105 if (!empty($participantDetails)) {
106 //cron 1. move participant from pending to expire if needed
107 foreach ($participantDetails as $participantId => $values) {
108 //process the additional participant at the time of
109 //primary participant, don't process separately.
110 if (!empty($values['registered_by_id'])) {
114 $expirationTime = CRM_Utils_Array
::value('expiration_time', $values);
115 if ($expirationTime && array_key_exists($values['status_id'], $pendingStatuses)) {
117 //get the expiration and registration pending time.
118 $expirationSeconds = $expirationTime * 3600;
119 $registrationPendingSeconds = CRM_Utils_Date
::unixTime($values['register_date']);
121 // expired registration since registration cross allow confirmation time.
122 if (($expirationSeconds +
$registrationPendingSeconds) < time()) {
124 //lets get the transaction mechanism.
125 require_once 'CRM/Core/Transaction.php';
126 $transaction = new CRM_Core_Transaction();
128 require_once 'CRM/Event/BAO/Participant.php';
129 $ids = array($participantId);
130 $expiredId = array_search('Expired', $expiredStatuses);
131 $results = CRM_Event_BAO_Participant
::transitionParticipants($ids, $expiredId, $values['status_id'], TRUE, TRUE);
132 $transaction->commit();
134 if (!empty($results)) {
135 //diaplay updated participants
136 if (is_array($results['updatedParticipantIds']) && !empty($results['updatedParticipantIds'])) {
137 foreach ($results['updatedParticipantIds'] as $processedId) {
138 $expiredParticipantCount +
= 1;
139 echo "<br /><br />- status updated to: Expired";
141 //mailed participants.
142 if (is_array($results['mailedParticipants']) &&
143 array_key_exists($processedId, $results['mailedParticipants'])
145 echo "<br />Expiration Mail sent to: {$results['mailedParticipants'][$processedId]}";
155 //cron 2. lets move participants from waiting list to pending status
156 foreach ($participantDetails as $participantId => $values) {
157 //process the additional participant at the time of
158 //primary participant, don't process separately.
159 if (!empty($values['registered_by_id'])) {
163 if (array_key_exists($values['status_id'], $waitingStatuses) &&
164 !array_key_exists($values['event_id'], $fullEvents)
167 if ($waitingStatuses[$values['status_id']] == 'On waitlist' &&
168 CRM_Event_BAO_Event
::validRegistrationDate($values)
171 //check the target event having space.
172 require_once 'CRM/Event/BAO/Participant.php';
173 $eventOpenSpaces = CRM_Event_BAO_Participant
::eventFull($values['event_id'], TRUE, FALSE);
175 if ($eventOpenSpaces && is_numeric($eventOpenSpaces) ||
($eventOpenSpaces === NULL)) {
177 //get the additional participant if any.
178 $additionalIds = CRM_Event_BAO_Participant
::getAdditionalParticipantIds($participantId);
180 $allIds = array($participantId);
181 if (!empty($additionalIds)) {
182 $allIds = array_merge($allIds, $additionalIds);
184 $pClause = ' participant.id IN ( ' . implode(' , ', $allIds) . ' )';
185 $requiredSpaces = CRM_Event_BAO_Event
::eventTotalSeats($values['event_id'], $pClause);
187 //need to check as to see if event has enough speces
188 if (($requiredSpaces <= $eventOpenSpaces) ||
($eventOpenSpaces === NULL)) {
189 require_once 'CRM/Core/Transaction.php';
190 $transaction = new CRM_Core_Transaction();
192 require_once 'CRM/Event/BAO/Participant.php';
193 $ids = array($participantId);
194 $updateStatusId = array_search('Pending from waitlist', $pendingStatuses);
196 //lets take a call to make pending or need approval
197 if ($values['requires_approval']) {
198 $updateStatusId = array_search('Awaiting approval', $waitingStatuses);
200 $results = CRM_Event_BAO_Participant
::transitionParticipants($ids, $updateStatusId,
201 $values['status_id'], TRUE, TRUE
203 //commit the transaction.
204 $transaction->commit();
206 if (!empty($results)) {
207 //diaplay updated participants
208 if (is_array($results['updatedParticipantIds']) &&
209 !empty($results['updatedParticipantIds'])
211 foreach ($results['updatedParticipantIds'] as $processedId) {
212 if ($values['requires_approval']) {
213 $waitingApprovalCount +
= 1;
214 echo "<br /><br />- status updated to: Awaiting approval";
215 echo "<br />Will send you Confirmation Mail when registration get approved.";
218 $waitingConfirmCount +
= 1;
219 echo "<br /><br />- status updated to: Pending from waitlist";
220 if (is_array($results['mailedParticipants']) &&
221 array_key_exists($processedId, $results['mailedParticipants'])
223 echo "<br />Confirmation Mail sent to: {$results['mailedParticipants'][$processedId]}";
231 //target event is full.
232 $fullEvents[$values['event_id']] = $values['eventTitle'];
236 //target event is full.
237 $fullEvents[$values['event_id']] = $values['eventTitle'];
245 echo "<br /><br />Number of Expired registration(s) = {$expiredParticipantCount}";
246 echo "<br />Number of registration(s) require approval = {$waitingApprovalCount}";
247 echo "<br />Number of registration changed to Pending from waitlist = {$waitingConfirmCount}<br /><br />";
248 if (!empty($fullEvents)) {
249 foreach ($fullEvents as $eventId => $title) {
250 echo "Full Event : {$title}<br />";
256 $obj = new CRM_ParticipantProcessor();
258 $obj->updateParticipantStatus();
259 echo "<br />Participant records updated. (Done)";