/** * 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 set the attendance status of a user * */ public function takeRollAction() { if ($this->_request->isXmlHttpRequest()) { $this->_helper->layout->disableLayout(); } else { $this->_helper->pageTitle('workshop-instructor-takeRoll:title'); } $get = Zend_Registry::get('getFilter'); $messages = array(); if (!isset($get->eventId)) { throw new Ot_Exception_Input('msg-error-eventIdNotSet'); } $eventId = $get->eventId; $event = new Event(); $status = $event->getStatusOfUserForEvent(Zend_Auth::getInstance()->getIdentity()->accountId, $eventId); if ($status != 'instructor' && !$this->_helper->hasAccess('view-all-instructor-pages')) { throw new Ot_Exception_Access('msg-error-notInstructor'); } $attendee = new Event_Attendee(); $where = $attendee->getAdapter()->quoteInto('eventId = ?', $eventId); $attendees = $attendee->fetchAll($where); $hasAttendedList = array(); $attendeeList = array(); foreach ($attendees as $a) { $attendeeList[] = $a->accountId; if ($a->attended) { $hasAttendedList[] = $a->accountId; } } if (count($attendeeList) == 0) { throw new Ot_Exception_Data('msg-error-noAttendees'); } $form = $event->rollForm(array('eventId' => $eventId, 'attendees' => $hasAttendedList)); if ($this->_request->isPost()) { if ($form->isValid($_POST)) { $attendees = $form->getValue('attendees'); if (!is_array($attendees)) { $attendees = array($attendees); } // make checked people as attended $where = $attendee->getAdapter()->quoteInto("accountId IN (?)", $attendees) . ' AND ' . $attendee->getAdapter()->quoteInto('eventId = ?', $eventId); $data = array('attended' => 1); $attendee->update($data, $where); // make everyone else as not attended $where = $attendee->getAdapter()->quoteInto("accountId NOT IN (?)", $attendees) . ' AND ' . $attendee->getAdapter()->quoteInto('eventId = ?', $eventId); $data = array('attended' => 0); $attendee->update($data, $where); $this->_helper->flashMessenger->addMessage('msg-info-attendanceRecorded'); $this->_redirect('/workshop/instructor/?eventId=' . $eventId); } else { $messages[] = "msg-error-formSubmitProblem"; } } $this->view->messages = $messages; $this->view->form = $form; }