/** * Run the page. * * This method is called after the page is created. It checks for the * type of action and executes that action. * Finally it calls the parent's run method. * * @return void * @access public * */ function run() { //get the event id. $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this, true); $config =& CRM_Core_Config::singleton(); require_once 'CRM/Event/BAO/Event.php'; // ensure that the user has permission to see this page if (!CRM_Core_Permission::event(CRM_Core_Permission::VIEW, $this->_id)) { CRM_Core_Error::fatal(ts('You do not have permission to view this event')); } $action = CRM_Utils_Request::retrieve('action', 'String', $this, false); $context = CRM_Utils_Request::retrieve('context', 'String', $this, false, 'register'); $this->assign('context', $context); // Sometimes we want to suppress the Event Full msg $noFullMsg = CRM_Utils_Request::retrieve('noFullMsg', 'String', $this, false, 'false'); // set breadcrumb to append to 2nd layer pages $breadCrumbPath = CRM_Utils_System::url("civicrm/event/info", "id={$this->_id}&reset=1"); $additionalBreadCrumb = "<a href=\"{$breadCrumbPath}\">" . ts('Events') . '</a>'; //retrieve event information $params = array('id' => $this->_id); CRM_Event_BAO_Event::retrieve($params, $values['event']); if (!$values['event']['is_active']) { // form is inactive, die a fatal death CRM_Core_Error::fatal(ts('The page you requested is currently unavailable.')); } $this->assign('isShowLocation', CRM_Utils_Array::value('is_show_location', $values['event'])); // show event fees. require_once 'CRM/Price/BAO/Set.php'; if ($this->_id && CRM_Utils_Array::value('is_monetary', $values['event'])) { // get price set options, - CRM-5209 if ($priceSetId = CRM_Price_BAO_Set::getFor('civicrm_event', $this->_id)) { $setDetails = CRM_Price_BAO_Set::getSetDetail($priceSetId); eval("\$priceSetFields = \$setDetails[{$priceSetId}][fields];"); if (is_array($priceSetFields)) { $fieldCnt = 1; foreach ($priceSetFields as $fid => $fieldValues) { if (!is_array($fieldValues['options']) || empty($fieldValues['options'])) { continue; } foreach ($fieldValues['options'] as $optionId => $optionVal) { $values['feeBlock']['value'][$fieldCnt] = $optionVal['value']; $values['feeBlock']['label'][$fieldCnt] = $optionVal['description']; $fieldCnt++; } } } } else { //retrieve event fee block. require_once 'CRM/Core/OptionGroup.php'; require_once 'CRM/Core/BAO/Discount.php'; $discountId = CRM_Core_BAO_Discount::findSet($this->_id, 'civicrm_event'); if ($discountId) { CRM_Core_OptionGroup::getAssoc(CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Discount', $discountId, 'option_group_id'), $values['feeBlock'], false, 'id'); } else { CRM_Core_OptionGroup::getAssoc("civicrm_event.amount.{$this->_id}", $values['feeBlock']); } } } $params = array('entity_id' => $this->_id, 'entity_table' => 'civicrm_event'); require_once 'CRM/Core/BAO/Location.php'; $values['location'] = CRM_Core_BAO_Location::getValues($params, true); //retrieve custom field information require_once 'CRM/Core/BAO/CustomGroup.php'; $groupTree =& CRM_Core_BAO_CustomGroup::getTree("Event", $this, $this->_id, 0, $values['event']['event_type_id']); CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree); $this->assign('action', CRM_Core_Action::VIEW); //To show the event location on maps directly on event info page $locations =& CRM_Event_BAO_Event::getMapInfo($this->_id); if (!empty($locations) && CRM_Utils_Array::value('is_map', $values['event'])) { $this->assign('locations', $locations); $this->assign('mapProvider', $config->mapProvider); $this->assign('mapKey', $config->mapAPIKey); $sumLat = $sumLng = 0; $maxLat = $maxLng = -400; $minLat = $minLng = +400; foreach ($locations as $location) { $sumLat += $location['lat']; $sumLng += $location['lng']; if ($location['lat'] > $maxLat) { $maxLat = $location['lat']; } if ($location['lat'] < $minLat) { $minLat = $location['lat']; } if ($location['lng'] > $maxLng) { $maxLng = $location['lng']; } if ($location['lng'] < $minLng) { $minLng = $location['lng']; } } $center = array('lat' => (double) $sumLat / count($locations), 'lng' => (double) $sumLng / count($locations)); $span = array('lat' => (double) ($maxLat - $minLat), 'lng' => (double) ($maxLng - $minLng)); $this->assign_by_ref('center', $center); $this->assign_by_ref('span', $span); } require_once 'CRM/Event/BAO/Participant.php'; $eventFullMessage = CRM_Event_BAO_Participant::eventFull($this->_id); if ($eventFullMessage and $noFullMsg == 'false') { if (CRM_Utils_Array::value('has_waitlist', $values['event'])) { $eventFullMessage = null; $statusMessage = CRM_Utils_Array::value('waitlist_text', $values['event'], 'Event is currently full, but you can register and be a part of waiting list.'); } else { $statusMessage = $eventFullMessage; } CRM_Core_Session::setStatus($statusMessage); } if (CRM_Utils_Array::value('is_online_registration', $values['event'])) { if (CRM_Event_BAO_Event::validRegistrationDate($values['event'], $this->_id)) { if (!$eventFullMessage) { $registerText = ts('Register Now'); if (CRM_Utils_Array::value('registration_link_text', $values['event'])) { $registerText = $values['event']['registration_link_text']; } //Fixed for CRM-4855 if (CRM_Event_BAO_Event::showHideRegistrationLink($values)) { $this->assign('allowRegistration', true); } $this->assign('registerText', $registerText); } // we always generate urls for the front end in joomla if ($action == CRM_Core_Action::PREVIEW) { $url = CRM_Utils_System::url('civicrm/event/register', "id={$this->_id}&reset=1&action=preview", true, null, true, true); } else { $url = CRM_Utils_System::url('civicrm/event/register', "id={$this->_id}&reset=1", true, null, true, true); } if (!$eventFullMessage) { $this->assign('registerURL', $url); } } if ($action == CRM_Core_Action::PREVIEW) { $mapURL = CRM_Utils_System::url('civicrm/contact/map/event', "eid={$this->_id}&reset=1&action=preview", true, null, true, true); } else { $mapURL = CRM_Utils_System::url('civicrm/contact/map/event', "eid={$this->_id}&reset=1", true, null, true, true); } $this->assign('mapURL', $mapURL); } // we do not want to display recently viewed items, so turn off $this->assign('displayRecent', false); // set page title = event title CRM_Utils_System::setTitle($values['event']['title']); $this->assign('event', $values['event']); if (isset($values['feeBlock'])) { $this->assign('feeBlock', $values['feeBlock']); } $this->assign('location', $values['location']); parent::run(); }
public function updateParticipantStatus() { require_once 'CRM/Event/PseudoConstant.php'; $participantRole = CRM_Event_PseudoConstant::participantRole(); $pendingStatuses = CRM_Event_PseudoConstant::participantStatus(NULL, "class = 'Pending'"); $expiredStatuses = CRM_Event_PseudoConstant::participantStatus(NULL, "class = 'Negative'"); $waitingStatuses = CRM_Event_PseudoConstant::participantStatus(NULL, "class = 'Waiting'"); //build the required status ids. $statusIds = '(' . implode(',', array_merge(array_keys($pendingStatuses), array_keys($waitingStatuses))) . ')'; $participantDetails = $fullEvents = array(); $expiredParticipantCount = $waitingConfirmCount = $waitingApprovalCount = 0; //get all participant who's status in class pending and waiting $query = "SELECT * FROM civicrm_participant WHERE status_id IN {$statusIds} ORDER BY register_date"; $query = "\n SELECT participant.id,\n participant.contact_id,\n participant.status_id,\n participant.register_date,\n participant.registered_by_id,\n participant.event_id,\n event.title as eventTitle,\n event.registration_start_date,\n event.registration_end_date,\n event.end_date,\n event.expiration_time,\n event.requires_approval\n FROM civicrm_participant participant\nLEFT JOIN civicrm_event event ON ( event.id = participant.event_id )\n WHERE participant.status_id IN {$statusIds}\n AND (event.end_date > now() OR event.end_date IS NULL)\n AND event.is_active = 1 \n ORDER BY participant.register_date, participant.id \n"; $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 (CRM_Utils_Array::value('registered_by_id', $values)) { 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 "<br /><br />- status updated to: Expired"; //mailed participants. if (is_array($results['mailedParticipants']) && array_key_exists($processedId, $results['mailedParticipants'])) { echo "<br />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 (CRM_Utils_Array::value('registered_by_id', $values)) { 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 "<br /><br />- status updated to: Awaiting approval"; echo "<br />Will send you Confirmation Mail when registration get approved."; } else { $waitingConfirmCount += 1; echo "<br /><br />- status updated to: Pending from waitlist"; if (is_array($results['mailedParticipants']) && array_key_exists($processedId, $results['mailedParticipants'])) { echo "<br />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 "<br /><br />Number of Expired registration(s) = {$expiredParticipantCount}"; echo "<br />Number of registration(s) require approval = {$waitingApprovalCount}"; echo "<br />Number of registration changed to Pending from waitlist = {$waitingConfirmCount}<br /><br />"; if (!empty($fullEvents)) { foreach ($fullEvents as $eventId => $title) { echo "Full Event : {$title}<br />"; } } }
/** * create the event blocks for upcoming events * * @return void * @access private */ private function setTemplateEventValues() { $config =& CRM_Core_Config::singleton(); require_once 'CRM/Event/BAO/Event.php'; $info = CRM_Event_BAO_Event::getCompleteInfo(); if ($info) { $session =& CRM_Core_Session::singleton(); // check if registration link should be displayed foreach ($info as $id => $event) { $info[$id]['onlineRegistration'] = CRM_Event_BAO_Event::validRegistrationDate($event, $session->get('userID')); } self::setProperty(self::EVENT, 'templateValues', array('eventBlock' => $info)); } }