public function bookAction() { $variables = array(); $config = $this->getServiceLocator()->get('Config'); $query = $this->getServiceLocator()->get('wrapperQuery')->setEntity('Courses\\Entity\\Course'); $options['query'] = $query; $examBook = new \Courses\Entity\ExamBook(); $examModel = $this->getServiceLocator()->get('Courses\\Model\\Exam'); $validationResult = $this->getServiceLocator()->get('aclValidator')->validateOrganizationAccessControl($this->getResponse(), Role::TEST_CENTER_ADMIN_ROLE); if ($validationResult["isValid"] === false && !empty($validationResult["redirectUrl"])) { return $this->redirect()->toUrl($validationResult["redirectUrl"]); } $auth = new AuthenticationService(); $storage = $auth->getIdentity(); //checking if user is admin or test center admin if ($auth->hasIdentity()) { if (!(in_array(Role::ADMIN_ROLE, $storage['roles']) || in_array(Role::TEST_CENTER_ADMIN_ROLE, $storage['roles']))) { $this->getResponse()->setStatusCode(302); $url = $this->getEvent()->getRouter()->assemble(array(), array('name' => 'noaccess')); $this->redirect()->toUrl($url); } } $form = new \Courses\Form\BookExam(null, $options); $request = $this->getRequest(); if ($request->isPost()) { $data = $request->getPost()->toArray(); $form->setInputFilter($examBook->getInputFilter()); $form->setData($data); if ($form->isValid()) { // save exam rquest $examModel->saveBookingRequest($data, $config); // // redirect $url = $this->getEvent()->getRouter()->assemble(array('action' => 'calendar'), array('name' => "coursesCalendar")); $this->redirect()->toUrl($url); } } $variables['bookExamForm'] = $this->getFormView($form); return new ViewModel($variables); }
public function saveBookingRequest($data, $config) { $bookObj = new \Courses\Entity\ExamBook(); $course = $this->query->findOneBy('Courses\\Entity\\Course', array('id' => $data['courseId'])); $atc = $this->query->findOneBy('Organizations\\Entity\\Organization', array('id' => $data['atcId'])); // exam date $bookObj->setDate(\DateTime::createFromFormat(Time::DATE_FORMAT, $data['date'])); // creation time $bookObj->setCreatedAt(new \DateTime()); // number of students $bookObj->setStudentNum($data['studentsNo']); // assign request to course $bookObj->setCourse($course); // assign request to atc $bookObj->setAtc($atc); // admin pending request $bookObj->setAdminStatus(\Courses\Entity\ExamBook::ADMIN_PENDING); // tvtc nothing $bookObj->setTvtcStatus(Null); $this->query->setEntity('Courses\\Entity\\ExamBook')->save($bookObj); $forceFlush = APPLICATION_ENV == "production" ? false : true; $cachedSystemData = $this->systemCacheHandler->getCachedSystemData($forceFlush); $settings = $cachedSystemData[CacheHandler::SETTINGS_KEY]; if (array_key_exists(Settings::TVTC_EMAIL, $settings)) { $tvtcMail = $settings[Settings::TVTC_EMAIL]; } $toBeNotifiedArray = array(); if (array_key_exists(Settings::ADMIN_EMAIL, $settings) && array_key_exists(Settings::OPERATIONS_EMAIL, $settings)) { $toBeNotifiedArray[] = $settings[Settings::ADMIN_EMAIL]; $toBeNotifiedArray[] = $settings[Settings::OPERATIONS_EMAIL]; } if (isset($tvtcMail)) { // send tvtc new mail $this->sendMail($bookObj, $tvtcMail); } if (count($toBeNotifiedArray) > 0) { // send admin new mail $this->sendMail($bookObj, $toBeNotifiedArray, true); } }