public function customValidation($validator) { $validator->after(function ($validator) { $arr = Request::all(); $sid = $arr['SubjectId']; $sid_orig = isset($arr['SubjectIdOrig']) ? $arr['SubjectIdOrig'] : false; $cid = $arr['CourseId']; $cid_orig = isset($arr['CourseIdOrig']) ? $arr['CourseIdOrig'] : false; if ($sid !== $sid_orig || $cid !== $cid_orig) { $studyProgram = StudyProgramQuery::create()->findPk([$sid, $cid]); if (!is_null($studyProgram)) { $validator->errors()->add('SubjectId', 'This combination of subject and course is taken.'); $validator->errors()->add('CourseId', 'This combination of subject and course is taken.'); } } }); }
/** * Create StudyProgram query. * */ protected function createQuery($array, $search) { $this->objects = StudyProgramQuery::create()->useCourseQuery()->orderByName()->endUse()->orderByYear()->orderBySemester()->useSubjectQuery()->orderByName()->endUse(); if (isset($array['SubjectId']) && $array['SubjectId'] !== "") { $this->objects->where("StudyProgram.subject_id = ?", $array['SubjectId']); } if (isset($array['CourseId']) && $array['CourseId'] !== "") { $this->objects->where("StudyProgram.course_id = ?", $array['CourseId']); } if (isset($array['Year']) && $array['Year'] !== "") { $this->objects->where("StudyProgram.year = ?", $array['Year']); } if (isset($array['Semester']) && $array['Semester'] !== "") { $this->objects->where("StudyProgram.semester = ?", $array['Semester']); } if ($search) { session(['study_program_filter' => $array]); } }
/** * If this collection has already been initialized with * an identical criteria, it returns the collection. * Otherwise if this Course is new, it will return * an empty collection; or if this Course has previously * been saved, it will retrieve related StudyPrograms from storage. * * This method is protected by default in order to keep the public * api reasonable. You can provide public methods for those you * actually need in Course. * * @param Criteria $criteria optional Criteria object to narrow the query * @param ConnectionInterface $con optional connection object * @param string $joinBehavior optional join type to use (defaults to Criteria::LEFT_JOIN) * @return ObjectCollection|ChildStudyProgram[] List of ChildStudyProgram objects */ public function getStudyProgramsJoinSubject(Criteria $criteria = null, ConnectionInterface $con = null, $joinBehavior = Criteria::LEFT_JOIN) { $query = ChildStudyProgramQuery::create(null, $criteria); $query->joinWith('Subject', $joinBehavior); return $this->getStudyPrograms($query, $con); }
/** * Returns a new ChildStudyProgramQuery object. * * @param string $modelAlias The alias of a model in the query * @param Criteria $criteria Optional Criteria to build the query from * * @return ChildStudyProgramQuery */ public static function create($modelAlias = null, Criteria $criteria = null) { if ($criteria instanceof ChildStudyProgramQuery) { return $criteria; } $query = new ChildStudyProgramQuery(); if (null !== $modelAlias) { $query->setModelAlias($modelAlias); } if ($criteria instanceof Criteria) { $query->mergeWith($criteria); } return $query; }
/** * 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; }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($subject_id, $course_id) { $study_program = StudyProgramQuery::create()->findPK([$subject_id, $course_id]); $study_program->delete(); flash()->success("DELETED"); session(['attribute' => \Lang::get('general.STUDY_PROGRAM')]); return redirect($this->main_page); }
/** * Builds a Criteria object containing the primary key for this object. * * Unlike buildCriteria() this method includes the primary key values regardless * of whether or not they have been modified. * * @throws LogicException if no primary key is defined * * @return Criteria The Criteria object containing value(s) for primary key(s). */ public function buildPkeyCriteria() { $criteria = ChildStudyProgramQuery::create(); $criteria->add(StudyProgramTableMap::COL_SUBJECT_ID, $this->subject_id); $criteria->add(StudyProgramTableMap::COL_COURSE_ID, $this->course_id); return $criteria; }
private function getSubjectYears() { $studyPrograms = StudyProgramQuery::create()->find(); $study_programs_arr = []; foreach ($studyPrograms as $studyProgram) { $study_programs_arr[$studyProgram->getSubjectId()][$studyProgram->getCourseId()] = $studyProgram->getYear(); } return $study_programs_arr; }
/** * Performs an INSERT on the database, given a StudyProgram or Criteria object. * * @param mixed $criteria Criteria or StudyProgram object containing data that is used to create the INSERT statement. * @param ConnectionInterface $con the ConnectionInterface connection to use * @return mixed The new primary key. * @throws PropelException Any exceptions caught during processing will be * rethrown wrapped into a PropelException. */ public static function doInsert($criteria, ConnectionInterface $con = null) { if (null === $con) { $con = Propel::getServiceContainer()->getWriteConnection(StudyProgramTableMap::DATABASE_NAME); } if ($criteria instanceof Criteria) { $criteria = clone $criteria; // rename for clarity } else { $criteria = $criteria->buildCriteria(); // build Criteria from StudyProgram object } // Set the correct dbName $query = StudyProgramQuery::create()->mergeWith($criteria); // use transaction because $criteria could contain info // for more than one table (I guess, conceivably) return $con->transaction(function () use($con, $query) { return $query->doInsert($con); }); }