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); } }