Пример #1
0
 /**
  * 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;
 }
Пример #2
0
 public function getEventsForUser($accountId)
 {
     $config = Zend_Registry::get('config');
     $attendee = new Event_Attendee();
     $instructor = new Event_Instructor();
     $location = new Location();
     $document = new Workshop_Document();
     $account = new Ot_Account();
     $eu = new Evaluation_User();
     $stayOpen = new Zend_Date();
     $stayOpen->subHour($config->user->numHoursEvaluationAvailability->val);
     $locationCache = array();
     $reservations = $attendee->getEventsForAttendee($accountId);
     $time = time();
     foreach ($reservations as &$r) {
         $r['active'] = false;
         // we determine if the class is open
         $startDt = new Zend_Date(strtotime($r['date'] . ' ' . $r['startTime']));
         $endDt = new Zend_Date(strtotime($r['date'] . ' ' . $r['endTime']));
         $endDt->addHour($config->user->numHoursEvaluationAvailability->val);
         $r['evaluatable'] = $this->isEvaluatable($r['eventId']);
         // checks to see if its possible that the class is open for evaluation
         if ($r['evaluatable'] && !$eu->hasCompleted($accountId, $r['eventId'])) {
             $r['active'] = true;
         } elseif ($startDt->getTimestamp() > $time) {
             $r['active'] = true;
         }
         $r = array_merge(array('startDt' => $startDt->getTimestamp()), $r);
         $r['hasHandouts'] = false;
         $documents = $document->getDocumentsForWorkshop($r['workshopId']);
         if (count($documents) > 0) {
             $r['hasHandouts'] = true;
         }
         $r['cancelable'] = false;
         if ($r['active']) {
             $startDt->subHour($config->user->numHoursEventCancel->val);
             $r['cancelable'] = $startDt->getTimestamp() > $time;
             if ($r['status'] == 'waitlist') {
                 $waiting = $attendee->getAttendeesForEvent($r['eventId'], 'waitlist');
                 $position = 1;
                 foreach ($waiting as $w) {
                     if ($accountId == $w['accountId']) {
                         break;
                     }
                     $position++;
                 }
                 $r['waitlistPosition'] = $position;
             }
         }
     }
     // Get presently taught classes
     $teaching = $instructor->getEventsForInstructor($accountId);
     foreach ($teaching as &$t) {
         $startDt = new Zend_Date(strtotime($t['date'] . ' ' . $t['startTime']));
         $endDt = new Zend_Date(strtotime($t['date'] . ' ' . $t['endTime']));
         $endDt->addHour($config->user->numHoursEvaluationAvailability->val);
         $t = array_merge(array('startDt' => $startDt->getTimestamp()), $t);
         $t['active'] = false;
         // checks to see if its possible that the class is open for evaluation
         if ($endDt->getTimestamp() > $time) {
             $t['active'] = true;
         }
         $t['status'] = 'instructor';
     }
     $events = array_merge($reservations, $teaching);
     // sort by event order
     $eDates = array();
     foreach ($events as $key => $value) {
         $eDates[$key] = $value['startDt'];
     }
     asort($eDates);
     $newEvents = array();
     foreach (array_keys($eDates) as $key) {
         $newEvents[] = $events[$key];
     }
     $events = $newEvents;
     $currentEvents = array();
     $pastEvents = array();
     foreach ($events as $e) {
         $where = $instructor->getAdapter()->quoteInto('eventId = ?', $e['eventId']);
         $instructors = $instructor->fetchAll($where);
         $instructorIds = array();
         foreach ($instructors as $i) {
             $instructorIds[] = $i->accountId;
         }
         if (count($instructorIds) != 0) {
             $accounts = $account->fetchAll($account->getAdapter()->quoteInto('accountId IN (?)', $instructorIds), array('lastName', 'firstName'));
             foreach ($accounts as $a) {
                 $e['instructors'][] = $a->firstName . ' ' . $a->lastName;
             }
         }
         if (isset($locationCache[$e['locationId']])) {
             $e['location'] = $locationCache[$e['locationId']];
         } else {
             $thisLocation = $location->find($e['locationId']);
             if (is_null($thisLocation)) {
                 throw new Ot_Exception_Data('Location not found');
             }
             $e['location'] = $thisLocation->toArray();
             $locationCache[$e['locationId']] = $e['location'];
         }
         if ($e['active']) {
             $currentEvents[] = $e;
         } else {
             if ($e['status'] != 'waitlist') {
                 $pastEvents[] = $e;
             }
         }
     }
     $ret = array('currentEvents' => $currentEvents, 'pastEvents' => array_reverse($pastEvents));
     return $ret;
 }