diff --git a/application/models/tables/Requests.php b/application/models/tables/Requests.php index f669f12ec7285c53ffc21858b79be79e2c98bfd4..8a113f87ce32a397b673103ad8afdd8a9f3c5394 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; }