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 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2014
35 class CRM_Event_BAO_ParticipantStatusType
extends CRM_Event_DAO_ParticipantStatusType
{
36 static function add(&$params) {
40 $dao = new CRM_Event_DAO_ParticipantStatusType
;
41 $dao->copyValues($params);
45 static function &create(&$params) {
46 $transaction = new CRM_Core_Transaction();
47 $statusType = self
::add($params);
48 if (is_a($statusType, 'CRM_Core_Error')) {
49 $transaction->rollback();
52 $transaction->commit();
56 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
;
73 static function retrieve(&$params, &$defaults) {
76 $dao = new CRM_Event_DAO_ParticipantStatusType
;
77 $dao->copyValues($params);
78 if ($dao->find(TRUE)) {
79 CRM_Core_DAO
::storeValues($dao, $defaults);
86 static function setIsActive($id, $isActive) {
87 return CRM_Core_DAO
::setFieldValue('CRM_Event_BAO_ParticipantStatusType', $id, 'is_active', $isActive);
90 public function process($params) {
92 $returnMessages = array();
94 $participantRole = CRM_Event_PseudoConstant
::participantRole();
95 $pendingStatuses = CRM_Event_PseudoConstant
::participantStatus(NULL, "class = 'Pending'");
96 $expiredStatuses = CRM_Event_PseudoConstant
::participantStatus(NULL, "class = 'Negative'");
97 $waitingStatuses = CRM_Event_PseudoConstant
::participantStatus(NULL, "class = 'Waiting'");
99 //build the required status ids.
100 $statusIds = '(' . implode(',', array_merge(array_keys($pendingStatuses), array_keys($waitingStatuses))) . ')';
102 $participantDetails = $fullEvents = array();
103 $expiredParticipantCount = $waitingConfirmCount = $waitingApprovalCount = 0;
105 //get all participant who's status in class pending and waiting
106 $query = "SELECT * FROM civicrm_participant WHERE status_id IN {$statusIds} ORDER BY register_date";
109 SELECT participant.id,
110 participant.contact_id,
111 participant.status_id,
112 participant.register_date,
113 participant.registered_by_id,
114 participant.event_id,
115 event.title as eventTitle,
116 event.registration_start_date,
117 event.registration_end_date,
119 event.expiration_time,
120 event.requires_approval
121 FROM civicrm_participant participant
122 LEFT JOIN civicrm_event event ON ( event.id = participant.event_id )
123 WHERE participant.status_id IN {$statusIds}
124 AND (event.end_date > now() OR event.end_date IS NULL)
125 AND event.is_active = 1
126 ORDER BY participant.register_date, participant.id
128 $dao = CRM_Core_DAO
::executeQuery($query);
129 while ($dao->fetch()) {
130 $participantDetails[$dao->id
] = array(
132 'event_id' => $dao->event_id
,
133 'status_id' => $dao->status_id
,
134 'contact_id' => $dao->contact_id
,
135 'register_date' => $dao->register_date
,
136 'registered_by_id' => $dao->registered_by_id
,
137 'eventTitle' => $dao->eventTitle
,
138 'registration_start_date' => $dao->registration_start_date
,
139 'registration_end_date' => $dao->registration_end_date
,
140 'end_date' => $dao->end_date
,
141 'expiration_time' => $dao->expiration_time
,
142 'requires_approval' => $dao->requires_approval
,
146 if (!empty($participantDetails)) {
147 //cron 1. move participant from pending to expire if needed
148 foreach ($participantDetails as $participantId => $values) {
149 //process the additional participant at the time of
150 //primary participant, don't process separately.
151 if (!empty($values['registered_by_id'])) {
155 $expirationTime = CRM_Utils_Array
::value('expiration_time', $values);
156 if ($expirationTime && array_key_exists($values['status_id'], $pendingStatuses)) {
158 //get the expiration and registration pending time.
159 $expirationSeconds = $expirationTime * 3600;
160 $registrationPendingSeconds = CRM_Utils_Date
::unixTime($values['register_date']);
162 // expired registration since registration cross allow confirmation time.
163 if (($expirationSeconds +
$registrationPendingSeconds) < time()) {
165 //lets get the transaction mechanism.
166 $transaction = new CRM_Core_Transaction();
168 $ids = array($participantId);
169 $expiredId = array_search('Expired', $expiredStatuses);
170 $results = CRM_Event_BAO_Participant
::transitionParticipants($ids, $expiredId, $values['status_id'], TRUE, TRUE);
171 $transaction->commit();
173 if (!empty($results)) {
174 //diaplay updated participants
175 if (is_array($results['updatedParticipantIds']) && !empty($results['updatedParticipantIds'])) {
176 foreach ($results['updatedParticipantIds'] as $processedId) {
177 $expiredParticipantCount +
= 1;
178 $returnMessages[] .= "<br />Status updated to: Expired";
180 //mailed participants.
181 if (is_array($results['mailedParticipants']) &&
182 array_key_exists($processedId, $results['mailedParticipants'])
184 $returnMessages[] .= "<br />Expiration Mail sent to: {$results['mailedParticipants'][$processedId]}";
194 //cron 2. lets move participants from waiting list to pending status
195 foreach ($participantDetails as $participantId => $values) {
196 //process the additional participant at the time of
197 //primary participant, don't process separately.
198 if (!empty($values['registered_by_id'])) {
202 if (array_key_exists($values['status_id'], $waitingStatuses) &&
203 !array_key_exists($values['event_id'], $fullEvents)
206 if ($waitingStatuses[$values['status_id']] == 'On waitlist' &&
207 CRM_Event_BAO_Event
::validRegistrationDate($values)
210 //check the target event having space.
211 $eventOpenSpaces = CRM_Event_BAO_Participant
::eventFull($values['event_id'], TRUE, FALSE);
213 if ($eventOpenSpaces && is_numeric($eventOpenSpaces) ||
($eventOpenSpaces === NULL)) {
215 //get the additional participant if any.
216 $additionalIds = CRM_Event_BAO_Participant
::getAdditionalParticipantIds($participantId);
218 $allIds = array($participantId);
219 if (!empty($additionalIds)) {
220 $allIds = array_merge($allIds, $additionalIds);
222 $pClause = ' participant.id IN ( ' . implode(' , ', $allIds) . ' )';
223 $requiredSpaces = CRM_Event_BAO_Event
::eventTotalSeats($values['event_id'], $pClause);
225 //need to check as to see if event has enough speces
226 if (($requiredSpaces <= $eventOpenSpaces) ||
($eventOpenSpaces === NULL)) {
227 $transaction = new CRM_Core_Transaction();
229 $ids = array($participantId);
230 $updateStatusId = array_search('Pending from waitlist', $pendingStatuses);
232 //lets take a call to make pending or need approval
233 if ($values['requires_approval']) {
234 $updateStatusId = array_search('Awaiting approval', $waitingStatuses);
236 $results = CRM_Event_BAO_Participant
::transitionParticipants($ids, $updateStatusId,
237 $values['status_id'], TRUE, TRUE
239 //commit the transaction.
240 $transaction->commit();
242 if (!empty($results)) {
243 //diaplay updated participants
244 if (is_array($results['updatedParticipantIds']) &&
245 !empty($results['updatedParticipantIds'])
247 foreach ($results['updatedParticipantIds'] as $processedId) {
248 if ($values['requires_approval']) {
249 $waitingApprovalCount +
= 1;
250 $returnMessages[] .= "<br /><br />- status updated to: Awaiting approval";
251 $returnMessages[] .= "<br />Will send you Confirmation Mail when registration gets approved.";
254 $waitingConfirmCount +
= 1;
255 $returnMessages[] .= "<br /><br />- status updated to: Pending from waitlist";
256 if (is_array($results['mailedParticipants']) &&
257 array_key_exists($processedId, $results['mailedParticipants'])
259 $returnMessages[] .= "<br />Confirmation Mail sent to: {$results['mailedParticipants'][$processedId]}";
267 //target event is full.
268 $fullEvents[$values['event_id']] = $values['eventTitle'];
272 //target event is full.
273 $fullEvents[$values['event_id']] = $values['eventTitle'];
281 $returnMessages[] .= "<br /><br />Number of Expired registration(s) = {$expiredParticipantCount}";
282 $returnMessages[] .= "<br />Number of registration(s) require approval = {$waitingApprovalCount}";
283 $returnMessages[] .= "<br />Number of registration changed to Pending from waitlist = {$waitingConfirmCount}<br /><br />";
284 if (!empty($fullEvents)) {
285 foreach ($fullEvents as $eventId => $title) {
286 $returnMessages[] .= "Full Event : {$title}<br />";
290 return array('is_error' => 0, 'messages' => $returnMessages);