/** * Returns the largest available ID for a given parent id * If none available, returns 0 * @param PropelPDO $parentId * @param $conn * @return unknown_type */ public static function getLargestAvailableIdForNodeId($parentId, PropelPDO $conn = null) { if (!isset($conn)) { $conn = Propel::getConnection(); } $query = "SELECT MAX(%s) FROM %s WHERE %s=%s"; $query = sprintf($query, EnumItemPeer::ID, EnumItemPeer::TABLE_NAME, EnumItemPeer::PARENT_ID, $parentId); $statement = $conn->prepare($query); $statement->execute(); $resultset = $statement->fetchAll(PDO::FETCH_COLUMN, 0); $id = $resultset[0] + 1; $item = EnumItemPeer::retrieveByPK($id, $conn); if (!isset($item)) { return $id; } else { return 0; } }
public function executeSearchByProgram(sfWebRequest $request) { $conn = Propel::getConnection(); $today = getdate(); $this->searchType = searchActions::SEARCH_BY_PROGRAM; $rawProgList = EnumItemPeer::getAllForParentNodeId(EnumItemPeer::DISCIPLINES_NODE_ID, $conn); $this->programList = array(); foreach ($rawProgList as $obj) { $this->programList[$obj->getId()] = $obj->getDescr(); } $this->yearList = array("0" => "All", "1" => "First Year", "2" => "Second Year", "3" => "Third Year", "4" => "Fourth Year"); if ($request->hasParameter("year") && $request->hasParameter("program")) { $this->programId = $request->getParameter("program"); if (helperFunctions::isMaliciousString($this->programId)) { $this->forward404(); } $this->year = $request->getParameter("year"); if (helperFunctions::isMaliciousString($this->year)) { $this->forward404(); } // get result set $enum = EnumItemPeer::retrieveByPK($this->programId, $conn); $this->resultTitle = "Results for " . $enum->getDescr(); $this->results = CoursePeer::findCoursesByDisciplineIdAndYear($this->programId, $this->year, $conn); } else { $this->programId = $rawProgList[0]->getId(); $this->year = 1; } }