From 40793eaa041ad8216a09d29caeddb48f31ab637d Mon Sep 17 00:00:00 2001
From: Tim Steiner <tsteiner2@unl.edu>
Date: Thu, 30 Aug 2007 19:55:58 +0000
Subject: [PATCH] Colleges listed correctly in list of requests on home page.

---
 application/models/rows/CourseGeneration.php | 17 +++++-
 application/models/rows/Department.php       | 28 ++++++++++
 application/models/rows/Subject.php          | 18 ++++++
 application/models/tables/Departments.php    |  2 +-
 application/models/tables/Subjects.php       | 58 ++++++++++++++++++++
 application/views/home.xhtml                 |  6 +-
 6 files changed, 124 insertions(+), 5 deletions(-)
 create mode 100644 application/models/rows/Department.php
 create mode 100644 application/models/rows/Subject.php
 create mode 100644 application/models/tables/Subjects.php

diff --git a/application/models/rows/CourseGeneration.php b/application/models/rows/CourseGeneration.php
index 8e6af833..c4c36704 100644
--- a/application/models/rows/CourseGeneration.php
+++ b/application/models/rows/CourseGeneration.php
@@ -8,6 +8,11 @@
  */
 class CourseGeneration extends Asset
 {
+    /**
+     * Home crosslisting
+     *
+     * @var CourseCrosslisting
+     */
     protected $_homeCrosslisting;
 
     public function _init()
@@ -146,7 +151,8 @@ class CourseGeneration extends Asset
         }
 
         $parentGeneration = CourseGenerations::getInstance()->findOne($this->parent);
-        while($offical && $parentGeneration && $parentGeneration->type != 'official') {
+        $foo = $parentGeneration->type;
+        while($official && $parentGeneration && $parentGeneration->type != 'official') {
             $parentGeneration = CourseGenerations::getInstance()->findOne($parentGeneration->parent);
         }
         return $parentGeneration;
@@ -168,6 +174,15 @@ class CourseGeneration extends Asset
         return CourseEsDesignations::getInstance()->isCourseCodeEssentialStudies($courseCode, $college);
     }
 
+    public function getHomeCollege()
+    {
+        $subject = Subjects::getInstance()->fetchSubject($this->subject);
+        $department = $subject->department;
+        $college = $department->college;
+
+        return $college;
+    }
+
     /**
      * Returns a reference to the home crosslist
      *
diff --git a/application/models/rows/Department.php b/application/models/rows/Department.php
new file mode 100644
index 00000000..52113f5a
--- /dev/null
+++ b/application/models/rows/Department.php
@@ -0,0 +1,28 @@
+<?php
+
+class Department extends Nmc_Db_Table_Row
+{
+
+    public function _init()
+    {
+        parent::_init();
+
+        $subjectsRelation = new Nmc_Db_Table_Relation_HasMany(
+            Subjects::getInstance(),
+            $this,
+            'department',
+            'subjects'
+        );
+        $this->_registerRelation($subjectsRelation);
+
+        $collegeRelation = new Nmc_Db_Table_Relation_HasOne(
+            Colleges::getInstance(),
+            $this,
+            'college',
+            'college',
+            true
+        );
+        $this->_registerRelation($collegeRelation);
+    }
+
+}
\ No newline at end of file
diff --git a/application/models/rows/Subject.php b/application/models/rows/Subject.php
new file mode 100644
index 00000000..2e1e3900
--- /dev/null
+++ b/application/models/rows/Subject.php
@@ -0,0 +1,18 @@
+<?php
+
+class Subject extends Nmc_Db_Table_Row
+{
+    protected function _init()
+    {
+        parent::_init();
+
+        $departmentRelation = new Nmc_Db_Table_Relation_HasOne(
+            Departments::getInstance(),
+            $this,
+            'department',
+            'department',
+            true
+        );
+        $this->_registerRelation($departmentRelation);
+    }
+}
\ No newline at end of file
diff --git a/application/models/tables/Departments.php b/application/models/tables/Departments.php
index 8e716a87..2bbd970a 100644
--- a/application/models/tables/Departments.php
+++ b/application/models/tables/Departments.php
@@ -3,7 +3,7 @@
 class Departments extends Nmc_Db_Table
 {
     protected $_primary = 'departmentId';
-    //protected $_rowClass = 'Department';
+    protected $_rowClass = 'Department';
 
     /**
      * The one true instance
diff --git a/application/models/tables/Subjects.php b/application/models/tables/Subjects.php
new file mode 100644
index 00000000..c47a5406
--- /dev/null
+++ b/application/models/tables/Subjects.php
@@ -0,0 +1,58 @@
+<?php
+
+class Subjects extends Nmc_Db_Table
+{
+    protected $_primary = 'subjectId';
+    protected $_rowClass = 'Subject';
+
+    /**
+     * The one true instance
+     *
+     * @var Subjects
+     */
+    static protected $_instance;
+
+    /**
+     * Return the one true instance
+     *
+     * @return Subjects
+     */
+    static public function getInstance($config = array())
+    {
+        if (!self::$_instance) {
+            self::$_instance = new Subjects($config);
+        }
+        return self::$_instance;
+    }
+
+
+    public function getSubjectList()
+    {
+        $allRows = $this->fetchAll();
+
+        $subjects = array();
+        foreach($allRows as $row) {
+            $subjects[] = $row->name;
+        }
+
+        sort($subjects);
+
+        return $subjects;
+    }
+
+    /**
+     * Return the db row for the given subject, if it exists.
+     *
+     * @param string $subject
+     * @return Subject
+     */
+    public function fetchSubject($subject)
+    {
+        $db = $this->getAdapter();
+        $where = $db->quoteInto('name = ?', $subject);
+        $row = $this->fetchRow($where);
+        return $row;
+    }
+
+}
+
diff --git a/application/views/home.xhtml b/application/views/home.xhtml
index f6165cad..8aceae83 100755
--- a/application/views/home.xhtml
+++ b/application/views/home.xhtml
@@ -51,7 +51,7 @@
                 <td><?php echo $originalCourse->subject . ' '
                              . $originalCourse->courseNumber
                              . $originalCourse->courseLetter; ?></td>
-                <td>NONC</td>
+                <td><?php echo $originalCourse->getHomeCollege()->name; ?></td>
                 <td><?php echo $request->type->name; ?></td>
                 <td>
                 <td>
@@ -105,7 +105,7 @@
                 <td><?php echo $originalCourse->subject . ' '
                              . $originalCourse->courseNumber
                              . $originalCourse->courseLetter; ?></td>
-                <td><?php echo get_class($course->subject); ?></td>
+                <td><?php echo $originalCourse->getHomeCollege()->name; ?></td>
                 <td><?php echo $request->type->name; ?></td>
                 <td><?php echo $request->getCurrentApprovalBody()->name; ?></td>
                 <td>
@@ -181,7 +181,7 @@
                     <td><?php echo $originalCourse->subject . ' '
                                  . $originalCourse->courseNumber
                                  . $originalCourse->courseLetter; ?></td>
-                    <td>NONC</td>
+                    <td><?php echo $originalCourse->getHomeCollege()->name; ?></td>
                     <td><?php echo $request->type->name; ?></td>
                     <td><?php echo $request->getCurrentAction()->name; ?></td>
                     <td>
-- 
GitLab