/** * Executes query and hydrate this object * * @param string $query the query being searched for */ public function query($query, PropelPDO $propelConnection = null) { $refQuery = trim($query); if (strlen($refQuery) < 3) { throw new Exception("Too few characters in the query string"); } elseif (helperFunctions::isMaliciousString($refQuery)) { throw new Exception("Malicious string detected. Are you trying to wreck our system?"); } else { // search for courses $c = new Criteria(); $idCrit = $c->getNewCriterion(CoursePeer::ID, $refQuery . "%", Criteria::LIKE); $nameCrit = $c->getNewCriterion(CoursePeer::DESCR, "%" . $refQuery . "%", Criteria::LIKE); $idCrit->addOr($nameCrit); $c->addAnd($idCrit); $c->setDistinct(); $c->addAscendingOrderByColumn(CoursePeer::ID); $this->_courseList = CoursePeer::doselect($c, $propelConnection); // search for professors $c = new Criteria(); $firstNameCrit = $c->getNewCriterion(InstructorPeer::FIRST_NAME, "%" . $refQuery . "%", Criteria::LIKE); $lastNameCrit = $c->getNewCriterion(InstructorPeer::LAST_NAME, "%" . $refQuery . "%", Criteria::LIKE); $firstNameCrit->addOr($lastNameCrit); $c->addAnd($firstNameCrit); $c->setDistinct(); $c->addAscendingOrderByColumn(InstructorPeer::LAST_NAME); $this->_profList = InstructorPeer::doSelect($c, $propelConnection); // search for programs $c = new Criteria(); $descrCrit = $c->getNewCriterion(DisciplinePeer::DESCR, "%" . $refQuery . "%", Criteria::LIKE); $c->addAnd($descrCrit); $c->setDistinct(); $c->addAscendingOrderByColumn(DisciplinePeer::DESCR); $this->_programList = DisciplinePeer::doSelect($c, $propelConnection); } }
public static function getInstructorsForCourseAndYear($courseId, $year, PropelPDO $propelConnection) { $c = new Criteria(); $c->addJoin(CourseInstructorAssociationPeer::INSTRUCTOR_ID, InstructorPeer::ID); $crit1 = $c->getNewCriterion(CourseInstructorAssociationPeer::COURSE_ID, $courseId); $crit2 = $c->getNewCriterion(CourseInstructorAssociationPeer::YEAR, $year); $c->addAnd($crit1); $c->addAnd($crit2); $c->addAscendingOrderByColumn(InstructorPeer::LAST_NAME); return InstructorPeer::doSelect($c, $propelConnection); }
public function executeUpdate(sfWebRequest $request) { $this->forward404Unless($request->isMethod('post') || $request->isMethod('put')); $this->forward404Unless($instructor = InstructorPeer::retrieveByPk($request->getParameter('id')), sprintf('Object instructor does not exist (%s).', $request->getParameter('id'))); $this->form = new InstructorForm($instructor); $this->form = new InstructorForm($instructor); $c = new Criteria(); $c->add(InstructorDetailPeer::INSTRUCTOR_ID, $request->getParameter('id')); $instructDetail = InstructorDetailPeer::doSelectOne($c); if ($instructDetail !== null) { $this->form2 = new InstructorDetailForm($instructDetail); } else { $this->form2 = new InstructorDetailForm(new InstructorDetail()); } //$this->processForm($request, $this->form); $this->submitForm($request, $this->form, $this->form2); $this->instructor_list = InstructorPeer::doSelect(new Criteria()); $this->setTemplate('index'); }
/** * Retrieve multiple objects by pkey. * * @param array $pks List of primary keys * @param PropelPDO $con the connection to use * @throws PropelException Any exceptions caught during processing will be * rethrown wrapped into a PropelException. */ public static function retrieveByPKs($pks, PropelPDO $con = null) { if ($con === null) { $con = Propel::getConnection(InstructorPeer::DATABASE_NAME, Propel::CONNECTION_READ); } $objs = null; if (empty($pks)) { $objs = array(); } else { $criteria = new Criteria(InstructorPeer::DATABASE_NAME); $criteria->add(InstructorPeer::ID, $pks, Criteria::IN); $objs = InstructorPeer::doSelect($criteria, $con); } return $objs; }
public static function getAll(PropelPDO $propelConnection) { $c = new Criteria(); $c->addAscendingOrderByColumn(InstructorPeer::LAST_NAME); return InstructorPeer::doSelect($c, $propelConnection); }
/** * Gets an array of Instructor objects which contain a foreign key that references this object. * * If this collection has already been initialized with an identical Criteria, it returns the collection. * Otherwise if this Department has previously been saved, it will retrieve * related Instructors from storage. If this Department is new, it will return * an empty collection or the current collection, the criteria is ignored on a new object. * * @param PropelPDO $con * @param Criteria $criteria * @return array Instructor[] * @throws PropelException */ public function getInstructors($criteria = null, PropelPDO $con = null) { if ($criteria === null) { $criteria = new Criteria(DepartmentPeer::DATABASE_NAME); } elseif ($criteria instanceof Criteria) { $criteria = clone $criteria; } if ($this->collInstructors === null) { if ($this->isNew()) { $this->collInstructors = array(); } else { $criteria->add(InstructorPeer::DEPT_ID, $this->id); InstructorPeer::addSelectColumns($criteria); $this->collInstructors = InstructorPeer::doSelect($criteria, $con); } } else { // criteria has no effect for a new object if (!$this->isNew()) { // the following code is to determine if a new query is // called for. If the criteria is the same as the last // one, just return the collection. $criteria->add(InstructorPeer::DEPT_ID, $this->id); InstructorPeer::addSelectColumns($criteria); if (!isset($this->lastInstructorCriteria) || !$this->lastInstructorCriteria->equals($criteria)) { $this->collInstructors = InstructorPeer::doSelect($criteria, $con); } } } $this->lastInstructorCriteria = $criteria; return $this->collInstructors; }