/**
  * Handles the evaluation for an event.  Shows the user the evaluation and
  * saves the data from the evaluation.
  *
  */
 public function indexAction()
 {
     $get = Zend_Registry::get('getFilter');
     if (!isset($get->eventId)) {
         throw new Ot_Exception_Input('msg-error-eventIdNotSet');
     }
     $event = new Event();
     $eu = new Evaluation_User();
     $evaluation = new Evaluation();
     $thisEvent = $event->find($get->eventId);
     if (is_null($thisEvent)) {
         throw new Ot_Exception_Data('msg-error-noEvent');
     }
     $this->view->event = $thisEvent->toArray();
     $thisAccount = Zend_Auth::getInstance()->getIdentity();
     $status = $event->getStatusOfUserForEvent($thisAccount->accountId, $thisEvent->eventId);
     if ($status == "instructor") {
         throw new Ot_Exception_Access('msg-error-cannotEval');
     }
     if ($status != "attending") {
         throw new Ot_Exception_Access('msg-error-notAttended');
     }
     $config = Zend_Registry::get('config');
     $endDt = strtotime($thisEvent->date . " " . $thisEvent->endTime);
     if (time() > $endDt + $config->user->numHoursEvaluationAvailability->val * 3600) {
         throw new Ot_Exception_Access('msg-error-evalEnded');
     }
     if ($eu->hasCompleted($thisAccount->accountId, $thisEvent->eventId)) {
         throw new Ot_Exception_Access('msg-error-alreadyEval');
     }
     $workshop = new Workshop();
     $thisWorkshop = $workshop->find($thisEvent->workshopId);
     if (is_null($thisWorkshop)) {
         throw new Ot_Exception_Data('msg-error-noWorkshop');
     }
     $this->view->workshop = $thisWorkshop->toArray();
     $instructor = new Event_Instructor();
     $instructors = $instructor->getInstructorsForEvent($thisEvent->eventId);
     $inst = array();
     foreach ($instructors as $i) {
         $inst[] = $i['firstName'] . ' ' . $i['lastName'];
     }
     $this->view->instructors = $inst;
     // lookup the location of the event
     $location = new Location();
     $thisLocation = $location->find($thisEvent->locationId);
     if (is_null($thisLocation)) {
         throw new Ot_Exception_Data('msg-error-noLocation');
     }
     $this->view->location = $thisLocation->toArray();
     if ($thisEvent->evaluationType == 'custom') {
         $form = $evaluation->form();
         $this->view->form = $form;
     }
     if ($this->_request->isPost()) {
         if ($thisEvent->evaluationType == 'custom') {
             if ($form->isValid($_POST)) {
                 $custom = new Ot_Custom();
                 $attributes = $custom->getAttributesForObject('evaluations');
                 $data = array();
                 foreach ($attributes as $a) {
                     $data[$a['attributeId']] = is_null($form->getValue('custom_' . $a['attributeId'])) ? '' : $form->getValue('custom_' . $a['attributeId']);
                 }
                 // custom attributes is the custom array that will be save by the CustomAttributes model
                 $evaluation->saveEvaluation($thisEvent->eventId, $thisAccount->accountId, $data);
                 $this->_helper->flashMessenger->addMessage('msg-info-evalThanks');
                 $this->_redirect('/');
             }
         } elseif ($thisEvent->evaluationType == 'google' && isset($_POST['googleSubmit'])) {
             $eu = new Evaluation_User();
             $dba = $eu->getAdapter();
             $dba->beginTransaction();
             $data = array('eventId' => $get->eventId, 'accountId' => $thisAccount->accountId);
             try {
                 $eu->insert($data);
             } catch (Exception $e) {
                 $dba->rollBack();
                 throw $e;
             }
             $dba->commit();
             $this->_helper->flashMessenger->addMessage('msg-info-evalThanks');
             $this->_redirect('/');
         }
     }
     if ($thisEvent->evaluationType == 'google') {
         $evaluationKeys = new Evaluation_Key();
         $keys = $evaluationKeys->find($get->eventId);
         if (is_null($keys)) {
             throw new Ot_Exception_Data('msg-error-noFormKey');
         }
         $this->view->keys = $keys->toArray();
     }
     $this->_helper->pageTitle('workshop-evaluate-index:title');
 }
 /**
  * Displays the results of an evaluation as long as the user requesting the
  * page is an instructor of the event.
  *
  */
 public function evaluationResultsAction()
 {
     $get = Zend_Registry::get('getFilter');
     if (!isset($get->eventId)) {
         throw new Ot_Exception_Input('msg-error-eventIdNotSet');
     }
     $event = new Event();
     $thisEvent = $event->find($get->eventId);
     if (is_null($thisEvent)) {
         throw new Ot_Exception_Data('msg-error-noEvent');
     }
     $this->view->event = $thisEvent->toArray();
     $workshop = new Workshop();
     $thisWorkshop = $workshop->find($thisEvent->workshopId);
     if (is_null($thisWorkshop)) {
         throw new Ot_Exception_Data('msg-error-noWorkshop');
     }
     $this->view->workshop = $thisWorkshop->toArray();
     $location = new Location();
     $thisLocation = $location->find($thisEvent->locationId);
     if (is_null($thisLocation)) {
         throw new Ot_Exception_Data('msg-error-noLocation');
     }
     $this->view->location = $thisLocation->toArray();
     $instructor = new Event_Instructor();
     $instructors = $instructor->getInstructorsForEvent($thisEvent->eventId);
     $instructorList = array();
     foreach ($instructors as $i) {
         $instructorList[] = $i['firstName'] . ' ' . $i['lastName'];
     }
     $this->view->instructors = $instructorList;
     $this->_checkValidViewer($instructors);
     if ($thisEvent['evaluationType'] == 'custom') {
         // get the evaluationId from the eventId
         $evaluation = new Evaluation();
         $where = $evaluation->getAdapter()->quoteInto('eventId = ?', $thisEvent->eventId);
         $evaluations = $evaluation->fetchAll($where);
         if ($evaluations->count() == 0) {
             $this->view->noEvaluationsYet = true;
         }
         $this->view->totalEvaluations = $evaluations->count();
         $ca = new Ot_Custom();
         $questions = $ca->getAttributesForObject('evaluations');
         foreach ($questions as &$q) {
             $q['options'] = $ca->convertOptionsToArray($q['options']);
             $answers = array();
             foreach ($evaluations as $e) {
                 $tmpAnswers = $ca->getData($q['objectId'], $e->evaluationId);
                 $tmp = array();
                 foreach ($tmpAnswers as $ta) {
                     $tmp[$ta['attribute']['attributeId']] = $ta['value'];
                 }
                 $answers[] = $tmp;
             }
             if ($q['type'] == 'ranking' || $q['type'] == 'select' || $q['type'] == 'radio') {
                 foreach ($q['options'] as $value) {
                     $answerCount = 0;
                     foreach ($answers as $a) {
                         if ($a[$q['attributeId']] == $value) {
                             $answerCount++;
                         }
                     }
                     $q['results'][] = array('answerLabel' => $value, 'answerCount' => $answerCount);
                 }
             } else {
                 foreach ($answers as $a) {
                     $q['results'][] = $a[$q['attributeId']];
                 }
             }
         }
         $this->view->evaluationResults = $questions;
     } elseif ($thisEvent['evaluationType'] == 'google') {
         $evaluationKeys = new Evaluation_Key();
         $keys = $evaluationKeys->find($get->eventId);
         if (is_null($keys)) {
             throw new Ot_Exception_Data('msg-error-noFormKey');
         }
         $this->view->keys = $keys->toArray();
     }
     $this->view->headScript()->appendFile($this->view->baseUrl() . '/scripts/jquery.gchart.min.js');
 }
 /**
  * Allows a user to edit an events details
  *
  */
 public function editEventAction()
 {
     $messages = array();
     $get = Zend_Registry::get('getFilter');
     if (!isset($get->eventId)) {
         throw new Ot_Exception_Input('msg-error-eventIdNotSet');
     }
     $event = new Event();
     $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();
     if ($thisEvent['evaluationType'] == 'google') {
         $evaluationKey = new Evaluation_Key();
         $keys = $evaluationKey->find($get->eventId);
         if (is_null($keys)) {
             throw new Ot_Exception_Data('Missing Form Keys');
         }
         $thisEvent['formKey'] = $keys['formKey'];
         $thisEvent['answerKey'] = $keys['answerKey'];
     }
     $thisEvent['instructorIds'] = $currentInstructors;
     $originalMaxSize = $thisEvent['maxSize'];
     $form = $event->form($thisEvent);
     if ($this->_request->isPost()) {
         if ($form->isValid($_POST)) {
             $eventId = $form->getValue('eventId');
             $workshopId = $form->getValue('workshop');
             $locationId = $form->getValue('location');
             $startTime = $form->getValue('startTime');
             $endTime = $form->getValue('endTime');
             $date = $form->getValue('date');
             $minSize = $form->getValue('minSize');
             $maxSize = $form->getValue('maxSize');
             $waitlistSize = $form->getValue('waitlistSize');
             $instructors = $form->getValue('instructors');
             $evaluationType = $form->getValue('evaluationType');
             if ($evaluationType == 'google') {
                 if (ctype_alnum($form->getValue('formKey'))) {
                     $formKey = $form->getValue('formKey');
                 } else {
                     $regex = '(?<=key\\=)\\w*';
                     $matches = array();
                     preg_match_all('/' . $regex . '/is', $form->getValue('formKey'), $matches);
                     if (isset($matches[0][0])) {
                         $formKey = $matches[0][0];
                     } else {
                         throw new Ot_Exception_Data('The Google Form Key is incorrect');
                     }
                 }
                 if (ctype_alnum($form->getValue('answerKey'))) {
                     $answerKey = $form->getValue('answerKey');
                 } else {
                     $regex = '(?<=key\\=)\\w*';
                     preg_match_all("/" . $regex . "/is", $form->getValue('answerKey'), $matches);
                     if (count($matches) > 0) {
                         $answerKey = $matches[0][0];
                     } else {
                         throw new Ot_Exception_Data('The Google Answer Key is incorrect');
                     }
                 }
             }
             $date = strtotime($date);
             $date = strftime('%Y', $date) . "-" . strftime('%m', $date) . "-" . strftime('%d', $date);
             if (strtolower($startTime['meridian']) == "pm" && $startTime['hour'] < 12) {
                 $startTime['hour'] += 12;
             }
             if (strtolower($startTime['meridian']) == "am" && $startTime['hour'] == 12) {
                 $startTime['hour'] = 0;
             }
             if (strtolower($endTime['meridian']) == "pm" && $endTime['hour'] < 12) {
                 $endTime['hour'] += 12;
             }
             if (strtolower($endTime['meridian']) == "am" && $endTime['hour'] == 12) {
                 $endTime['hour'] = 0;
             }
             $timesOk = true;
             $st = new Zend_Date($date);
             $st->setHour($startTime['hour'])->setMinute($startTime['minute']);
             $et = new Zend_Date($date);
             $et->setHour($endTime['hour'])->setMinute($endTime['minute']);
             if ($st->isLater($et)) {
                 $timesOk = false;
                 $messages[] = "msg-error-eventStartsAfter";
             } else {
                 if ($st->equals($et)) {
                     $timesOk = false;
                     $messages[] = "msg-error-eventTimesEqual";
                 }
             }
             $startTime = $startTime['hour'] . ":" . $startTime['minute'] . ":00";
             $endTime = $endTime['hour'] . ":" . $endTime['minute'] . ":00";
             $where = $event->getAdapter()->quoteInto('date = ?', $date) . " AND " . $event->getAdapter()->quoteInto('locationId = ?', $locationId) . " AND " . $event->getAdapter()->quoteInto('eventId != ?', $eventId) . " AND " . $event->getAdapter()->quoteInto('status = ?', 'open');
             $possibleConflicts = $event->fetchAll($where);
             $conflictFound = false;
             if ($possibleConflicts->count() > 0) {
                 $startTs = strtotime($startTime);
                 $endTs = strtotime($endTime);
                 foreach ($possibleConflicts as $pc) {
                     $pcStart = strtotime($pc->startTime);
                     $pcEnd = strtotime($pc->endTime);
                     if ($startTs == $pcStart) {
                         $conflictFound = true;
                     } else {
                         if ($startTs < $pcStart && $endTs > $pcStart) {
                             $conflictFound = true;
                         } else {
                             if ($startTs >= $pcStart && $endTs <= $pcEnd) {
                                 $conflictFound = true;
                             } else {
                                 if ($startTs < $pcEnd && $endTs >= $pcEnd) {
                                     $conflictFound = true;
                                 } else {
                                     if ($startTs < $pcStart && $endTime > $pcEnd) {
                                         $conflictFound = true;
                                     }
                                 }
                             }
                         }
                     }
                     if ($conflictFound) {
                         $messages[] = "msg-error-eventAlreadyScheduled";
                         break;
                     }
                 }
             }
             $evaluationCheck = true;
             /*
              * TODO: Make this work better (see the regex section above)
              */
             if ($evaluationType == 'google') {
                 $evaluationCheck = isset($formKey) && isset($answerKey);
             } else {
                 $evaluationCheck = $evaluationType == 'default';
             }
             if (!$evaluationCheck) {
                 $messages[] = 'msg-error-eventFormKeyMissing';
             }
             if (!$conflictFound && $timesOk && $evaluationCheck) {
                 $data = array('eventId' => $eventId, 'locationId' => $locationId, 'workshopId' => $workshopId, 'startTime' => $startTime, 'endTime' => $endTime, 'date' => $date, 'minSize' => $minSize, 'maxSize' => $maxSize, 'waitlistSize' => $waitlistSize, 'evaluationType' => $evaluationType, 'formKey' => $formKey, 'answerKey' => $answerKey);
                 $event->update($data, null);
                 $instructor = new Event_Instructor();
                 $where = $instructor->getAdapter()->quoteInto('eventId = ?', $eventId);
                 $instructor->delete($where);
                 foreach ($instructors as $i) {
                     $instructor->insert(array('accountId' => $i, 'eventId' => $eventId));
                 }
                 // move people on the waitlist (if any) to the newly added spots
                 if ($maxSize > $originalMaxSize) {
                     $attendee = new Event_Attendee();
                     $attendee->fillEvent($eventId);
                 }
                 $this->_helper->flashMessenger->addMessage('msg-info-eventSaved');
                 if (isset($get->itools)) {
                     $this->_helper->redirector->gotoUrl('/workshop/instructor?eventId=' . $eventId);
                 } else {
                     $date = explode('-', $date);
                     $this->_helper->redirector->gotoUrl('/workshop/schedule?startYear=' . $date[0] . '&startMonth=' . (int) $date[1]);
                 }
             }
         } else {
             $messages[] = "msg-error-formSubmitProblem";
         }
     }
     $this->view->messages = $messages;
     $this->view->headScript()->appendFile($this->view->baseUrl() . '/scripts/workshop/schedule/help.js');
     $this->view->headScript()->appendFile($this->view->baseUrl() . '/scripts/jquery.autocomplete.js');
     $this->view->headScript()->appendFile($this->view->baseUrl() . '/scripts/jquery.tooltip.min.js');
     $this->view->headLink()->appendStylesheet($this->view->baseUrl() . '/css/jquery.autocomplete.css');
     $this->view->headLink()->appendStylesheet($this->view->baseUrl() . '/css/workshop/schedule/help.css');
     $this->view->form = $form;
     $this->_helper->pageTitle('workshop-schedule-editEvent:title');
 }
Exemple #4
0
 public function update(array $data, $where)
 {
     $keys = array();
     $dba = $this->getAdapter();
     $inTransaction = false;
     try {
         $dba->beginTransaction();
     } catch (Exception $e) {
         $inTransaction = true;
     }
     $evaluationKey = new Evaluation_Key();
     if ($data['evaluationType'] == 'google') {
         $keys['eventId'] = $data['eventId'];
         $keys['formKey'] = $data['formKey'];
         $keys['answerKey'] = $data['answerKey'];
         try {
             $evaluationKey->update($keys, null);
         } catch (Exception $e) {
             $dba->rollBack();
             throw $e;
         }
     } elseif ($data['evaluationType'] == 'default') {
         $where = $evaluationKey->getAdapter()->quoteInto('eventId = ?', $data['eventId']);
         try {
             $evaluationKey->delete($where);
         } catch (Exception $e) {
             $dba->rollBack();
             throw $e;
         }
     }
     unset($data['formKey'], $data['answerKey']);
     try {
         parent::update($data, $where);
     } catch (Exception $e) {
         $dba->rollBack();
         throw $e;
     }
     if (!$inTransaction) {
         $dba->commit();
     }
 }