/** * 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; }
public function getStatusOfUserForEvent($accountId, $eventId) { $dba = $this->getAdapter(); $instructor = new Event_Instructor(); $where = $dba->quoteInto('accountId = ?', $accountId) . ' AND ' . $dba->quoteInto('eventId = ?', $eventId); $res = $instructor->fetchAll($where); if ($res->count() != 0) { return 'instructor'; } $where .= ' AND ' . $dba->quoteInto('status != ?', 'canceled'); $attendee = new Event_Attendee(); $res = $attendee->fetchAll($where); if ($res->count() != 0) { if ($res->current()->status == 'waitlist') { return 'waitlist'; } return 'attending'; } return ''; }