/** * Create Student query. * */ protected function createQuery($array, $search) { $this->objects = StudentQuery::create()->useSchoolYearQuery()->orderByYear('desc')->endUse()->orderByIdentificationNumber(); if (isset($array['IdentificationNumber']) && $array['IdentificationNumber'] !== "") { $this->objects->where("student.identification_number = ?", $array['IdentificationNumber']); } if (isset($array['SchoolYearId']) && $array['SchoolYearId'] !== "") { $this->objects->where("student.school_year_id = ?", $array['SchoolYearId']); } if (isset($array['CourseId']) && $array['CourseId'] !== "") { $this->objects->where("student.course_id = '" . $array['CourseId'] . "'"); } if (isset($array['FirstName']) && $array['FirstName'] !== "") { $this->objects->where("student.first_name like '%" . $array['FirstName'] . "%'"); } if (isset($array['LastName']) && $array['LastName'] !== "") { $this->objects->where("student.last_name like '%" . $array['LastName'] . "%'"); } if (isset($array['BirthPlace']) && $array['BirthPlace'] !== "") { $this->objects->where("student.birth_place like '%" . $array['BirthPlace'] . "%'"); } if (isset($array['BirthdayFrom']) && $array['BirthdayFrom'] !== "") { $this->objects->where("student.birthday >= ?", $array['BirthdayFrom']); } if (isset($array['BirthdayTo']) && $array['BirthdayTo'] !== "") { $this->objects->where("student.birthday <= ?", $array['BirthdayTo']); } if (isset($array['PhoneNumber']) && $array['PhoneNumber'] !== "") { $this->objects->where("student.phone_number like '%" . $array['PhoneNumber'] . "%'"); } if ($search) { session(['student_filter' => $array]); } }
private function getStudents() { $students = StudentQuery::create()->useSchoolYearQuery()->orderByYear('desc')->endUse()->orderByIdentificationNumber()->find(); $students_arr = []; foreach ($students as $student) { $name = $student->__toString(); $id = $student->getId(); $students_arr[$id] = $name; } return $students_arr; }
public function customValidation($validator) { $validator->after(function ($validator) { $arr = Request::all(); $idn = $arr['IdentificationNumber']; $idn_orig = isset($arr['IdentificationNumberOrig']) ? $arr['IdentificationNumberOrig'] : false; $syid = $arr['SchoolYearId']; $syid_orig = isset($arr['SchoolYearIdOrig']) ? $arr['SchoolYearIdOrig'] : false; if ($idn !== $idn_orig || $syid !== $syid_orig) { $student = StudentQuery::create()->where('Student.identification_number = ?', $idn)->where('Student.school_year_id = ?', $syid)->findOne(); if (!is_null($student)) { $validator->errors()->add('IdentificationNumber', 'This combination of identification number and school year is taken.'); $validator->errors()->add('SchoolYearId', 'This combination of identification number and school year is taken.'); } } }); }
private function getStudents($status) { $students = StudentQuery::create()->useSchoolYearQuery()->orderByYear('desc')->endUse()->orderByIdentificationNumber(); if ($status === 'professor') { $students->join('Student.Course'); $students->join('Course.Engagement'); $students->where('Engagement.professor_id = ?', \Auth::user()->getProfessorId()); } $students->orderByIdentificationNumber()->find(); $students_arr = ['' => '']; foreach ($students as $student) { $name = $student->__toString(); $id = $student->getId(); $students_arr[$id] = $name; } return $students_arr; }
/** * Get the associated ChildStudent object * * @param ConnectionInterface $con Optional Connection object. * @return ChildStudent The associated ChildStudent object. * @throws PropelException */ public function getStudent(ConnectionInterface $con = null) { if ($this->aStudent === null && $this->student_id !== null) { $this->aStudent = ChildStudentQuery::create()->findPk($this->student_id, $con); /* The following can be used additionally to guarantee the related object contains a reference to this object. This level of coupling may, however, be undesirable since it could result in an only partially populated collection in the referenced object. $this->aStudent->addApplications($this); */ } return $this->aStudent; }
/** * 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 = ChildStudentQuery::create(); $criteria->add(StudentTableMap::COL_ID, $this->id); return $criteria; }
/** * 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 Students 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|ChildStudent[] List of ChildStudent objects */ public function getStudentsJoinSchoolYear(Criteria $criteria = null, ConnectionInterface $con = null, $joinBehavior = Criteria::LEFT_JOIN) { $query = ChildStudentQuery::create(null, $criteria); $query->joinWith('SchoolYear', $joinBehavior); return $this->getStudents($query, $con); }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($id) { $student = StudentQuery::create()->findPK($id); $student->delete(); flash()->success("DELETED"); session(['attribute' => \Lang::get('general.STUDENT')]); return redirect($this->main_page); }
/** * Performs an INSERT on the database, given a Student or Criteria object. * * @param mixed $criteria Criteria or Student 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(StudentTableMap::DATABASE_NAME); } if ($criteria instanceof Criteria) { $criteria = clone $criteria; // rename for clarity } else { $criteria = $criteria->buildCriteria(); // build Criteria from Student object } if ($criteria->containsKey(StudentTableMap::COL_ID) && $criteria->keyContainsValue(StudentTableMap::COL_ID)) { throw new PropelException('Cannot insert a value for auto-increment primary key (' . StudentTableMap::COL_ID . ')'); } // Set the correct dbName $query = StudentQuery::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); }); }