/** * Display a listing of the resource. * * @return Response */ public function index(Request $request) { $storage_path = storage_path(); $sms_request = $request->all(); $phone_number = $sms_request['sender']; $description = json_encode($sms_request); $student = StudentQuery::retrieveByPhoneNumber($phone_number); if (is_null($student)) { $msg_text = 'Niste registrovani. Kontaktirajte administratora PMF-a.'; //$this->sendSms($phone_number, $msg_text, $description); exit; } if ($sms_request['sms_prefix'] !== 'PRIJAVA_ISPITA') { $msg_text = "Nepostojeca komanda! Za prijavu ispita poslati: ‘PRIJAVA_ISPITA <šifra_predmeta> <ispitni_rok>'"; $this->sendSms($phone_number, $msg_text, $description); exit; } $fullsms = explode(" ", $sms_request['fullsms']); $subject_code = isset($fullsms[1]) ? $fullsms[1] : null; $period_name = isset($fullsms[2]) ? $fullsms[2] : null; if (!isset($subject_code) && !isset($period_name)) { $msg_text = 'Doslo je do greske, proverite unete podatke.'; $this->sendSms($phone_number, $msg_text, $description); exit; } $subject = SubjectQuery::retrieveByCode($subject_code); if (is_null($subject)) { $msg_text = 'Nepostojeca šifra predmeta.'; $this->sendSms($phone_number, $msg_text, $description); exit; } $period = $this->getPeriodIdByName($period_name); if (is_null($period)) { $msg_text = 'Ispitni rok ne postoji'; $this->sendSms($phone_number, $msg_text, $description); exit; } $school_year_id = $this->getSchoolYearIdByDate(); $periodSchoolYear = PeriodSchoolYearQuery::create()->findPk([$period->getId(), $school_year_id]); if (is_null($periodSchoolYear)) { $msg_text = 'Ispitni rok ne postoji'; $this->sendSms($phone_number, $msg_text, $description); exit; } $studyProgram = StudyProgramQuery::create()->findPk([$subject->getId(), $student->getCourseId()]); if (is_null($studyProgram)) { $msg_text = 'Ovaj predmet nije u vašem studijskom programu.'; $this->sendSms($phone_number, $msg_text, $description); exit; } $msg_text = $this->allowedToApply($student->getId(), $subject, $period->getId(), $school_year_id); if ($msg_text !== null) { $this->sendSms($phone_number, $msg_text, $description); exit; } $application = new Application(); $application->setStudentId($student->getId()); $application->setSubjectId($subject->getId()); $application->setPeriodId(8); $application->setSchoolYearId(8); $application->setApplicationDate(date('Y-m-d')); $application->save(); $msg_text = 'Uspesno ste prijavili ispit.'; $this->sendSms($phone_number, $msg_text, $description, $application->getId()); exit; }