From 00a5bae59ea4c309c12a9f39018e217dbf422cb0 Mon Sep 17 00:00:00 2001 From: Tim Steiner <tsteiner2@unl.edu> Date: Fri, 26 Jan 2007 16:28:04 +0000 Subject: [PATCH] Order requests by course code in Requests.php functions --- application/models/tables/Requests.php | 38 ++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/application/models/tables/Requests.php b/application/models/tables/Requests.php index f669f12e..8a113f87 100644 --- a/application/models/tables/Requests.php +++ b/application/models/tables/Requests.php @@ -25,13 +25,39 @@ class Requests extends Nmc_Db_Table { public function getRequestsForUser(Person $user) { - $usersTable = Users::getInstance(); - $usersPrimaryKey = $usersTable->getPrimaryKeyName(); - $inflector = new Zend_Db_Inflector(); - $usersPrimaryKey = $inflector->camelize($usersPrimaryKey); + $db = $this->getAdapter(); + $where = $db->quoteInto('owner = ?', $user->getPrimaryKey()); + $requests = $this->fetchAllSorted($where); + + return $requests; + } + + public function fetchAllSorted($where = null) + { + $db = $this->getAdapter(); + + $rq = $this->getTableName(); + $cg = CourseGenerations::getInstance()->getTableName(); + $cx = CourseCrosslistings::getInstance()->getTableName(); + $cc = CourseCodes::getInstance()->getTableName(); + + $select = $db->select(); + $select->from($rq, '*'); + $select->join($cg, $rq . '.' . $this->getPrimaryKeyName() . ' = ' . $cg . '.request'); + $select->join($cx, $cg . '.' . CourseGenerations::getInstance()->getPrimaryKeyName() . ' = ' . $cx . '.generation'); + $select->join($cc, $cx . '.course_code = ' . $cc . '.' . CourseCodes::getInstance()->getPrimaryKeyName()); + $select->where($cx . ".type = 'home listing'"); + if ($where) { + $select->where($where); + } + $select->order('subject, course_number, course_letter'); + + $data = $db->fetchAll($select); + $config['db'] = $db; + $config['table'] = $this; + $config['data'] = $data; + $requests = new Nmc_Db_Table_Rowset($config); - $where = $this->_db->quoteInto('owner = ?', $user->$usersPrimaryKey); - $requests = $this->fetchAll($where); return $requests; } -- GitLab