public function execute($lastRunDt = null) { $config = Zend_Registry::get('config'); $checkDtStart = new Zend_Date($this->_lastRunDt); $checkDtStart->subHour($config->user->numHoursEvaluationReminder->val); $checkDtEnd = new Zend_Date(); $checkDtEnd->subHour($config->user->numHoursEvaluationReminder->val); $event = new Event(); $events = $event->getEvents(null, null, null, $checkDtStart->getTimestamp(), $checkDtEnd->getTimestamp(), 'open'); $location = new Location(); $workshop = new Workshop(); $instructor = new Event_Instructor(); $attendee = new Event_Attendee(); $eu = new Evaluation_User(); foreach ($events as $e) { $startDt = strtotime($e->date . ' ' . $e->startTime); $endDt = strtotime($e->date . ' ' . $e->endTime); if ($checkDtStart->getTimestamp() < $endDt && $checkDtEnd->getTimestamp() >= $endDt) { $evalAvailableDt = new Zend_Date($endDt); $evalAvailableDt->addHour($config->user->numHoursEvaluationAvailability->val); if ($evalAvailableDt->getTimestamp() > time()) { $taken = $eu->getCompleted($e->eventId); $thisLocation = $location->find($e->locationId); if (is_null($thisLocation)) { throw new Ot_Exception_Data('msg-error-noLocation'); } $thisWorkshop = $workshop->find($e->workshopId); if (is_null($thisWorkshop)) { throw new Ot_Exception_Data('msg-error-noWorkshop'); } $instructors = $instructor->getInstructorsForEvent($e->eventId); $instructorNames = array(); $instructorEmails = array(); foreach ($instructors as $i) { $instructorNames[] = $i['firstName'] . ' ' . $i['lastName']; $instructorEmails[] = $i['emailAddress']; } $data = array('workshopName' => $thisWorkshop->title, 'workshopDate' => date('m/d/Y', $startDt), 'workshopStartTime' => date('g:i a', $startDt), 'workshopEndTime' => date('g:i a', $endDt), 'workshopMinimumEnrollment' => $e->minSize, 'workshopCurrentEnrollment' => $e->roleSize, 'locationName' => $thisLocation->name, 'locationAddress' => $thisLocation->address, 'instructorNames' => implode(', ', $instructorNames), 'instructorEmails' => implode(', ', $instructorEmails)); $attending = $attendee->getAttendeesForEvent($e->eventId, 'attending'); foreach ($attending as $a) { if ($a['attended'] == 1 && !in_array($a['accountId'], $taken)) { $trigger = new Ot_Trigger(); $trigger->setVariables($data); $trigger->accountId = $a['accountId']; $trigger->studentEmail = $a['emailAddress']; $trigger->studentName = $a['firstName'] . ' ' . $a['lastName']; $trigger->studentUsername = $a['username']; $trigger->dispatch('Event_Evaluation_Reminder'); } } } } } }
public function getReportCsv($fromDate, $toDate) { $event = new Event(); $workshop = new Workshop(); $location = new Location(); $attendee = new Event_Attendee(); // go ahead and get all the workshops so we don't have to do loads of DB queries $workshopList = $workshop->fetchAll(); $workshops = array(); foreach ($workshopList as $w) { $workshops[$w->workshopId] = $w->toArray(); } // go ahead and get all the locations so we don't have to do loads of DB queries $locationList = $location->fetchAll(); $locations = array(); foreach ($locationList as $l) { $locations[$l->locationId] = $l->toArray(); } $events = $event->getEvents(null, null, null, $fromDate, $toDate)->toArray(); $fileName = 'report-' . date('Ymd-B') . '.csv'; $tmpName = tempnam('/tmp', $fileName); $fp = fopen($tmpName, 'w'); $columnNames = array('eventId' => 'eventId', 'workshopId' => 'workshopId', 'workshopTitle' => 'workshopTitle', 'locationId' => 'locationId', 'locationName' => 'locationName', 'eventDate' => 'eventDate', 'startTime' => 'startTime', 'endTime' => 'endTime', 'accountId' => 'accountId', 'username' => 'username', 'firstName' => 'firstName', 'lastName' => 'lastName', 'status' => 'status', 'attended' => 'attended'); $ret = fputcsv($fp, $columnNames, ',', '"'); if ($ret === false) { throw new Ot_Exception_Data('Error writing backup CSV file'); } foreach ($events as &$e) { $e['workshop'] = $workshops[$e['workshopId']]; $e['location'] = $locations[$e['locationId']]; $e['attendees'] = $attendee->getAttendeesForEvent($e['eventId']); foreach ($e['attendees'] as $a) { $data = array(); $data = array('eventId' => $e['eventId'], 'workshopId' => $e['workshopId'], 'workshopTitle' => $e['workshop']['title'], 'locationId' => $e['locationId'], 'locationName' => $e['location']['name'], 'eventDate' => $e['date'], 'startTime' => $e['startTime'], 'endTime' => $e['endTime'], 'accountId' => $a['accountId'], 'username' => $a['username'], 'firstName' => $a['firstName'], 'lastName' => $a['lastName'], 'status' => $a['status'], 'attended' => $a['attended']); $ret = fputcsv($fp, $data, ',', '"'); if ($ret === false) { throw new Ot_Exception_Data('Error writing backup CSV file'); } } } fclose($fp); file_get_contents($tmpName); header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header('Content-Length: ' . filesize($tmpName)); header("Content-Disposition: attachment; filename={$fileName}"); readfile($tmpName); unlink($tmpName); }
public function execute($lastRunDt = null) { $config = Zend_Registry::get('config'); $event = new Event(); $events = $event->getEvents(null, null, null, time(), null, 'open'); $location = new Location(); $workshop = new Workshop(); $instructor = new Event_Instructor(); $attendees = new Event_Attendee(); $lastRunDt = new Zend_Date($this->_lastRunDt); $currentDt = new Zend_Date(); foreach ($events as $e) { $startDt = strtotime($e->date . ' ' . $e->startTime); $endDt = strtotime($e->date . ' ' . $e->endTime); $firstDt = new Zend_Date($startDt); $firstDt->subHour($config->user->numHoursFirstReminder->val); $finalDt = new Zend_Date($startDt); $finalDt->subHour($config->user->numHoursFinalReminder->val); $notification = null; if ($firstDt->getTimestamp() > $lastRunDt->getTimestamp() && $firstDt->getTimestamp() < $currentDt->getTimestamp()) { $notification = 'first'; } if ($finalDt->getTimestamp() > $lastRunDt->getTimestamp() && $finalDt->getTimestamp() < $currentDt->getTimestamp()) { $notification = 'final'; } if (!is_null($notification)) { $thisLocation = $location->find($e->locationId); if (is_null($thisLocation)) { throw new Ot_Exception_Data('msg-error-noLocation'); } $thisWorkshop = $workshop->find($e->workshopId); if (is_null($thisWorkshop)) { throw new Ot_Exception_Data('msg-error-noWorkshop'); } $instructors = $instructor->getInstructorsForEvent($e->eventId); $instructorNames = array(); $instructorEmails = array(); foreach ($instructors as $i) { $instructorNames[] = $i['firstName'] . ' ' . $i['lastName']; $instructorEmails[] = $i['emailAddress']; } $data = array('workshopName' => $thisWorkshop->title, 'workshopDate' => date('m/d/Y', $startDt), 'workshopStartTime' => date('g:i a', $startDt), 'workshopEndTime' => date('g:i a', $endDt), 'workshopMinimumEnrollment' => $e->minSize, 'workshopCurrentEnrollment' => $e->roleSize, 'locationName' => $thisLocation->name, 'locationAddress' => $thisLocation->address, 'instructorNames' => implode(', ', $instructorNames), 'instructorEmails' => implode(', ', $instructorEmails)); $attending = $attendees->getAttendeesForEvent($e->eventId, 'attending'); foreach ($attending as $a) { $trigger = new Ot_Trigger(); $trigger->setVariables($data); $trigger->accountId = $a['accountId']; $trigger->studentEmail = $a['emailAddress']; $trigger->studentName = $a['firstName'] . ' ' . $a['lastName']; if ($notification == 'final') { $trigger->dispatch('Event_Attendee_Final_Reminder'); } else { $trigger->dispatch('Event_Attendee_First_Reminder'); } } $trigger = new Ot_Trigger(); $trigger->setVariables($data); if ($notification == 'final') { $trigger->dispatch('Event_Instructor_Final_Reminder'); } else { $trigger->dispatch('Event_Instructor_First_Reminder'); } } } }
public function addAttendeeForm($values = array()) { if (!isset($values['eventId'])) { throw new Ot_Exception_Input('The event ID must be provided.'); } $form = new Zend_Form(); $form->setAttrib('id', 'locationForm')->setDecorators(array('FormElements', array('HtmlTag', array('tag' => 'div', 'class' => 'zend_form')), 'Form')); $eventId = $form->createElement('hidden', 'eventId'); $eventId->setValue($values['eventId']); $eventId->setDecorators(array(array('ViewHelper', array('helper' => 'formHidden')))); $form->addElement($eventId); $type = $form->createElement('select', 'type', array('label' => 'How to Add:')); $type->addMultiOption('firstAvailable', 'First Available Spot')->addMultiOption('attending', 'Add To Attending List')->setValue(isset($values['type']) ? $values['type'] : ''); // get all the users available for the instructor list $otAccount = new Ot_Account(); $accounts = $otAccount->fetchAll(null, array('lastName', 'firstName'))->toArray(); $userList = array(); foreach ($accounts as $a) { $userList[$a['accountId']] = $a['lastName'] . ", " . $a['firstName']; } // remove anyone who's either in the attendee list, waitlist, or an instructor // for this event so they can't be added to the list $attendee = new Event_Attendee(); $attendeeList = $attendee->getAttendeesForEvent($values['eventId'], 'attending'); $waitlist = $attendee->getAttendeesForEvent($values['eventId'], 'waitlist'); $instructors = $this->getInstructorsForEvent($values['eventId']); foreach ($attendeeList as $a) { unset($userList[$a['accountId']]); } foreach ($waitlist as $w) { unset($userList[$w['accountId']]); } foreach ($instructors as $i) { unset($userList[$i['accountId']]); } $users = $form->createElement('multiselect', 'users', array('label' => 'User Search:')); $users->setMultiOptions($userList)->setAttrib('size', 10)->setValue(isset($values['accountIds']) ? $values['accountIds'] : ''); $submit = $form->createElement('submit', 'submitButton', array('label' => 'Submit')); $submit->setDecorators(array(array('ViewHelper', array('helper' => 'formSubmit')))); $cancel = $form->createElement('button', 'cancel', array('label' => 'Cancel')); $cancel->setAttrib('id', 'cancel'); $cancel->setDecorators(array(array('ViewHelper', array('helper' => 'formButton')))); $form->addElements(array($type, $users)); $form->setElementDecorators(array('ViewHelper', 'Errors', array('HtmlTag', array('tag' => 'div', 'class' => 'elm')), array('Label', array('tag' => 'span'))))->addElements(array($submit, $cancel)); return $form; }
/** * Allows a user to cancel an event * */ public function cancelEventAction() { $get = Zend_Registry::get('getFilter'); if (!isset($get->eventId)) { throw new Ot_Exception_Input('msg-error-eventIdNotSet'); } $workshop = new Workshop(); $event = new Event(); $location = new Location(); $thisEvent = $event->find($get->eventId); if (is_null($thisEvent)) { throw new Ot_Exception_Data('msg-error-noEvent'); } $i = new Event_Instructor(); $where = $i->getAdapter()->quoteInto('eventId = ?', $get->eventId); $results = $i->fetchAll($where); $currentInstructors = array(); foreach ($results as $r) { $currentInstructors[] = $r->accountId; } if (!$this->_helper->hasAccess('view-all-instructor-pages') && !in_array(Zend_Auth::getInstance()->getIdentity()->accountId, $currentInstructors)) { throw new Ot_Exception_Access('msg-error-noWorkshopAccess'); } $thisEvent = $thisEvent->toArray(); $thisEvent['startTime'] = strftime('%l:%M %p', strtotime($thisEvent['startTime'])); $thisEvent['endTime'] = strftime('%l:%M %p', strtotime($thisEvent['endTime'])); $thisEvent['location'] = $location->find($thisEvent['locationId'])->toArray(); $thisEvent['workshop'] = $workshop->find($thisEvent['workshopId'])->toArray(); $this->view->event = $thisEvent; $form = Ot_Form_Template::delete('eventDelete', 'workshop-schedule-cancelEvent:cancel'); if ($this->_request->isPost() && $form->isValid($_POST)) { $dba = $event->getAdapter(); $dba->beginTransaction(); $where = $dba->quoteInto('eventId = ?', $get->eventId); $data = array('status' => 'canceled'); try { $result = $event->update($data, $where); } catch (Exception $e) { $dba->rollback(); throw $e; } $attendee = new Event_Attendee(); try { $attendee->update($data, $where); } catch (Exception $e) { $dba->rollback(); throw $e; } $dba->commit(); $this->_helper->flashMessenger->addMessage('msg-info-eventCanceled'); $date = explode('-', $thisEvent['date']); $this->_helper->redirector->gotoUrl('/workshop/schedule?startYear=' . $date[0] . '&startMonth=' . (int) $date[1]); } $this->_helper->pageTitle('workshop-schedule-cancelEvent:title'); $this->view->form = $form; }
/** * Allows a user to contact all the people in their event. * */ public function contactAction() { if ($this->_request->isXmlHttpRequest()) { $this->_helper->layout->disableLayout(); } else { $this->_helper->pageTitle('workshop-instructor-contact:title'); } $get = Zend_Registry::get('getFilter'); if (!isset($get->eventId)) { throw new Ot_Exception_Input('msg-error-eventIdNotSet'); } $messages = array(); $event = new Event(); $eventId = $get->eventId; $thisEvent = $event->find($eventId); if (is_null($thisEvent)) { throw new Ot_Exception_Data('msg-error-noEvent'); } $otAccount = new Ot_Account(); $thisAccount = $otAccount->find(Zend_Auth::getInstance()->getIdentity()->accountId); $status = $event->getStatusOfUserForEvent($thisAccount->accountId, $eventId); if ($status != 'instructor' && !$this->_helper->hasAccess('view-all-instructor-pages')) { throw new Ot_Exception_Access('msg-error-notInstructor'); } $form = $event->contactForm(array('eventId' => $eventId)); if ($this->_request->isPost()) { if ($form->isValid($_POST)) { $recipients = array(); $attendees = new Event_Attendee(); $recipients = $attendees->getAttendeesForEvent($thisEvent->eventId, $form->getValue('recipients')); if ($form->getValue('emailInstructors')) { $instructor = new Event_Instructor(); $instructorList = $instructor->getInstructorsForEvent($thisEvent->eventId); $recipients = array_merge($recipients, $instructorList); } $this->_checkValidViewer($instructorList); $mail = new Zend_Mail(); $mail->setFrom($thisAccount->emailAddress, $thisAccount->firstName . ' ' . $thisAccount->lastName); $mail->setSubject($form->getValue('subject')); $mail->setBodyText($form->getValue('message')); $mail->addTo($thisAccount->emailAddress); foreach ($recipients as $r) { $mail->addBcc($r['emailAddress']); } $eq = new Ot_Email_Queue(); $data = array('attributeName' => 'eventId', 'attributeId' => $thisEvent->eventId, 'zendMailObject' => $mail); $eq->queueEmail($data); //$mail->send(); $this->_helper->flashMessenger->addMessage('msg-info-emailQueued'); $this->_redirect('/workshop/instructor/?eventId=' . $thisEvent->eventId); } else { $messages[] = "msg-error-formSubmitProblem"; } } $this->view->messages = $messages; $this->view->thisAccount = $thisAccount; $this->view->form = $form; }
public function rollForm($values = array()) { if (!isset($values['eventId'])) { throw new Ot_Exception_Data('Event ID must be provided'); } $form = new Zend_Form(); $form->setAttrib('id', 'rollForm')->setDecorators(array('FormElements', array('HtmlTag', array('tag' => 'div', 'class' => 'zend_form')), 'Form')); $attendee = new Event_Attendee(); $attendees = $attendee->getAttendeesForEvent($values['eventId'], 'attending'); $otAccount = new Ot_Account(); $attendeeList = array(); foreach ($attendees as $a) { $thisAccount = $otAccount->find($a['accountId']); if (!is_null($thisAccount)) { $attendeeList[$a['accountId']] = $thisAccount->firstName . ' ' . $thisAccount->lastName . ' (' . $thisAccount->username . ')'; } } $attendeeElement = $form->createElement('multiCheckbox', 'attendees'); $attendeeElement->setMultiOptions($attendeeList)->setValue(isset($values['attendees']) ? $values['attendees'] : ''); $submit = $form->createElement('submit', 'submitButton', array('label' => 'Submit')); $submit->setDecorators(array(array('ViewHelper', array('helper' => 'formSubmit')))); $cancel = $form->createElement('button', 'cancel', array('label' => 'Cancel')); $cancel->setAttrib('id', 'cancel'); $cancel->setDecorators(array(array('ViewHelper', array('helper' => 'formButton')))); $form->addElements(array($attendeeElement)); $form->setElementDecorators(array('ViewHelper', 'Errors', array('HtmlTag', array('tag' => 'div', 'class' => 'elm')), array('Label', array('tag' => 'span'))))->addElements(array($submit, $cancel)); $eventId = $form->createElement('hidden', 'eventId'); $eventId->setValue($values['eventId']); $eventId->setDecorators(array(array('ViewHelper', array('helper' => 'formHidden')))); $form->addElement($eventId); return $form; }
/** * Allows a user to cancel their reservation for an event. * */ public function cancelAction() { $get = Zend_Registry::get('getFilter'); if (!isset($get->eventId)) { throw new Ot_Exception_Input('msg-error-eventIdNotSet'); } $event = new Event(); $location = new Location(); $workshop = new Workshop(); $instructor = new Event_Instructor(); $attendee = new Event_Attendee(); $thisEvent = $event->find($get->eventId); if (is_null($thisEvent)) { throw new Ot_Exception_Data('msg-error-noEvent'); } $this->view->event = $thisEvent->toArray(); $status = $event->getStatusOfUserForEvent(Zend_Auth::getInstance()->getIdentity()->accountId, $thisEvent->eventId); if ($status != 'waitlist' && $status != 'attending') { throw new Ot_Exception_Data('msg-error-notAttending'); } $this->view->status = $status; $this->view->reservationCancelable = $event->isReservationCancelable($thisEvent->eventId); $thisLocation = $location->find($thisEvent->locationId); if (is_null($thisLocation)) { throw new Ot_Exception_Data('msg-error-noLocation'); } $this->view->location = $thisLocation->toArray(); $thisWorkshop = $workshop->find($thisEvent->workshopId); if (is_null($thisWorkshop)) { throw new Ot_Exception_Data('msg-error-noWorkshop'); } $this->view->workshop = $thisWorkshop->toArray(); $instructors = $instructor->getInstructorsForEvent($thisEvent->eventId); $inst = array(); foreach ($instructors as $i) { $inst[] = $i['firstName'] . ' ' . $i['lastName']; } $this->view->instructors = $inst; $events = $event->getEvents($thisWorkshop->workshopId, null, null, time(), null, 'open')->toArray(); $newEvents = array(); foreach ($events as $e) { if ($e['eventId'] != $thisEvent->eventId) { $e['status'] = $event->getStatusOfUserForEvent(Zend_Auth::getInstance()->getIdentity()->accountId, $e['eventId']); $e['workshop'] = $thisWorkshop->toArray(); $newEvents[] = $e; } } $this->view->events = $newEvents; $form = Ot_Form_Template::delete('cancelReservation', 'workshop-signup-cancel:cancel', 'workshop-signup-cancel:keep'); if ($this->_request->isPost() && $form->isValid($_POST)) { $instructorNames = array(); $instructorEmails = array(); foreach ($instructors as $i) { $instructorNames[] = $i['firstName'] . ' ' . $i['lastName']; $instructorEmails[] = $i['emailAddress']; } $attendee->cancelReservation(Zend_Auth::getInstance()->getIdentity()->accountId, $thisEvent->eventId); $startDt = strtotime($thisEvent->date . ' ' . $thisEvent->startTime); $endDt = strtotime($thisEvent->date . ' ' . $thisEvent->endTime); $data = array('workshopName' => $thisWorkshop->title, 'workshopDate' => date('m/d/Y', $startDt), 'workshopStartTime' => date('g:i a', $startDt), 'workshopEndTime' => date('g:i a', $endDt), 'workshopMinimumEnrollment' => $thisEvent->minSize, 'locationName' => $thisLocation->name, 'locationAddress' => $thisLocation->address, 'instructorNames' => implode(', ', $instructorNames), 'instructorEmails' => implode(', ', $instructorEmails), 'studentEmail' => Zend_Auth::getInstance()->getIdentity()->emailAddress, 'studentName' => Zend_Auth::getInstance()->getIdentity()->firstName . ' ' . Zend_Auth::getInstance()->getIdentity()->lastName, 'studentUsername' => Zend_Auth::getInstance()->getIdentity()->username); $this->_helper->flashMessenger->addMessage($this->view->translate('msg-info-canceled', $thisWorkshop->title)); $trigger = new Ot_Trigger(); $trigger->setVariables($data); $trigger->dispatch('Event_Cancel_Reservation'); $account = new Ot_Account(); if ($status != 'waitlist') { $waiting = $attendee->getAttendeesForEvent($thisEvent->eventId, 'waitlist'); if (count($waiting) != 0) { $newAccount = $account->find($waiting[0]['accountId']); if (!is_null($newAccount)) { $attendee->makeReservation($newAccount->accountId, $thisEvent->eventId); $data['studentEmail'] = $newAccount->emailAddress; $data['studentName'] = $newAccount->firstName . ' ' . $newAccount->lastName; $data['studentUsername'] = $newAccount->username; $trigger = new Ot_Trigger(); $trigger->setVariables($data); $trigger->dispatch('Event_Waitlist_To_Attending'); } } } $this->_redirect('/'); } $this->view->form = $form; $this->view->layout()->setLayout('twocolumn'); $this->view->layout()->rightContent = $this->view->render('signup/right.phtml'); }