From 345abb0e72794124f888f5579320209a7fe85d41 Mon Sep 17 00:00:00 2001 From: Tim Steiner <tsteiner2@unl.edu> Date: Mon, 22 Feb 2010 21:38:34 +0000 Subject: [PATCH] When getting the xml dump for a specific subject code, order as if that subject were the home subject for every course. --- .../controllers/PublicViewController.php | 3 ++ .../modules/courses/models/CourseModel.php | 31 ++++++++++++++++--- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/application/modules/courses/controllers/PublicViewController.php b/application/modules/courses/controllers/PublicViewController.php index f19cb3b3..e874200f 100644 --- a/application/modules/courses/controllers/PublicViewController.php +++ b/application/modules/courses/controllers/PublicViewController.php @@ -20,6 +20,9 @@ class Courses_PublicViewController extends App_Controller_Action { if ($subject) { $criteria = array('subject' => $subject); $courses = Courses_CourseModel::findWithCriteria($criteria); + foreach ($courses as $course) { + $course->setEffectiveHomeSubject($subject); + } } else { $courses = Courses_CourseModel::findAllActive(); } diff --git a/application/modules/courses/models/CourseModel.php b/application/modules/courses/models/CourseModel.php index 6b949ad7..f34d01ed 100644 --- a/application/modules/courses/models/CourseModel.php +++ b/application/modules/courses/models/CourseModel.php @@ -1743,7 +1743,20 @@ class Courses_CourseModel extends Unl_Model { $this->_data['title'] = $title; } + + /** + * Used when displaying the course code as if the home subject were something else + * ie: MATH 340 (CSCE 340) instead of CSCE 340 (MATH 340) + * @var unknown_type + */ + protected $_effectiveHomeSubject = ''; + + public function setEffectiveHomeSubject($subject) + { + $this->_effectiveHomeSubject = $subject; + } + public function getCourseCode() { $courseCode = ''; @@ -1752,14 +1765,14 @@ class Courses_CourseModel extends Unl_Model $courseNumbers = array(); foreach ($this->_data['crosslistings'] as $crosslisting) { - if ($crosslisting['type'] != 'home listing') { + if (!$this->_isEffectiveHomeCrosslisting($crosslisting)) { continue; } $homeSubject = $crosslisting['subject']; $courseNumbers[] = str_pad($crosslisting['courseNumber'], 3, '0', STR_PAD_LEFT) . $crosslisting['courseLetter']; } foreach ($this->_data['crosslistings'] as $crosslisting) { - if ($crosslisting['type'] == 'home listing') { + if ($this->_isEffectiveHomeCrosslisting($crosslisting)) { continue; } if ($crosslisting['subject'] != $homeSubject) { @@ -1777,14 +1790,14 @@ class Courses_CourseModel extends Unl_Model if (in_array('Correspondence', $this->getDeliveryMethods())) { $courseNumbers = array(); foreach ($this->_data['crosslistings'] as $crosslisting) { - if ($crosslisting['type'] != 'home listing') { + if (!$this->_isEffectiveHomeCrosslisting($crosslisting)) { continue; } $homeSubject = $crosslisting['subject']; $courseNumbers[] = str_pad($crosslisting['courseNumber'], 3, '0', STR_PAD_LEFT) . $crosslisting['courseLetter']; } foreach ($this->_data['crosslistings'] as $crosslisting) { - if ($crosslisting['type'] == 'home listing') { + if ($this->_isEffectiveHomeCrosslisting($crosslisting)) { continue; } if ($crosslisting['subject'] != $homeSubject) { @@ -1802,7 +1815,15 @@ class Courses_CourseModel extends Unl_Model return $homeSubject . ' ' . $courseCode; } - + + protected function _isEffectiveHomeCrosslisting($crosslisting) + { + if (!$this->_effectiveHomeSubject && $crosslisting['type'] == 'home listing' || $this->_effectiveHomeSubject == $crosslisting['subject']) { + return true; + } + return false; + } + public function setCourseCode($subject, $courseNumber, $courseLetter = null) { if (!self::isSubjectValid($subject)) { -- GitLab