diff --git a/src/UNL/Catalog.php b/src/UNL/Catalog.php index f6e448165d806e19033f57a5cae5a66a1909bce2..ac6a42bc59753b9e2fc6143d984b0ce8cd73b4ad 100644 --- a/src/UNL/Catalog.php +++ b/src/UNL/Catalog.php @@ -381,21 +381,14 @@ class UNL_Catalog if (!isset($id) && isset($_GET['id'])) { $id = $_GET['id']; } - // Do not cache course search results - //UNL_UndergraduateBulletin_Editions::$editions = array(2012,2011,2010); - //UNL_UndergraduateBulletin_Editions::$latest = 2012; - UNL_Services_CourseApproval::setCachingService(new UNL_Services_CourseApproval_CachingService_Null()); - UNL_Services_CourseApproval::setXCRIService(new UNL_UndergraduateBulletin_CourseDataDriver()); - $course_data = new UNL_Services_CourseApproval_Search(); - if ($listings = $course_data->byAny($id. ' 8')) { + $course_data = $this->getCourseSearcher(); + + if ($listings = $course_data->bySubject($id, 0, -1)) { $subject = new UNL_Services_CourseApproval_SubjectArea($id); $this->p->doctitle = '<title>UNL | Graduate Studies Bulletin | Courses for '.$subject->subject.'</title>'; if (count($listings)) { - $savvy = new Savvy(); - $savvy->setEscape('htmlentities'); - $savvy->setClassToTemplateMapper(new UNL_UndergraduateBulletin_ClassToTemplateMapper()); - $savvy->setTemplatePath($this->undergraduate_bulletin_dir . '/www/templates/html/'); + $savvy = $this->getCourseRenderer(); $this->p->maincontentarea .= '<a name="'.$subject->subject.'"></a><div class="subject" id="div_'.$subject->subject.'">'.PHP_EOL . '<h2 class="sec_header" id="'.$subject->subject.'">Courses for '.$subject->subject.' ('.$subject->subject.') </h2>'.PHP_EOL; foreach ($listings as $course) { @@ -411,7 +404,36 @@ class UNL_Catalog $this->send404('Could not find any courses matching that subject code.'); } } - + + /** + * Get the course search service + * + * @return UNL_Services_CourseApproval_Search + */ + protected function getCourseSearcher() + { + // Do not cache course search results + UNL_Services_CourseApproval::setCachingService(new UNL_Services_CourseApproval_CachingService_Null()); + UNL_Services_CourseApproval::setXCRIService(new UNL_UndergraduateBulletin_CourseDataDriver()); + $driver = new UNL_Catalog_CourseSearch_DBSearcher(); + $course_data = new UNL_Services_CourseApproval_Search($driver); + return $course_data; + } + + protected function getCourseRenderer() + { + static $savvy = false; + + if (!$savvy) { + $savvy = new Savvy(); + $savvy->setEscape('htmlentities'); + $savvy->setClassToTemplateMapper(new UNL_UndergraduateBulletin_ClassToTemplateMapper()); + $savvy->setTemplatePath($this->undergraduate_bulletin_dir . '/www/templates/html/'); + } + + return $savvy; + } + public function send404($message = '404 Not found.') { header('HTTP/1.0 404 Not Found'); @@ -431,8 +453,7 @@ class UNL_Catalog } else { $format = 'toHtml'; } - $savvy = new Savvy(); - $savvy->setTemplatePath($this->undergraduate_bulletin_dir . '/www/templates/html/'); + $savvy = $this->getCourseRenderer(); $this->p->maincontentarea .= $savvy->render($listing, 'Listing.tpl.php'); } diff --git a/src/UNL/Catalog/CourseSearch/DBSearcher.php b/src/UNL/Catalog/CourseSearch/DBSearcher.php new file mode 100644 index 0000000000000000000000000000000000000000..e59e99c6707a0b8b55921f10b832bf0421941419 --- /dev/null +++ b/src/UNL/Catalog/CourseSearch/DBSearcher.php @@ -0,0 +1,10 @@ +<?php +class UNL_Catalog_CourseSearch_DBSearcher extends UNL_UndergraduateBulletin_CourseSearch_DBSearcher +{ + + function getQueryResult($query, $offset = 0, $limit = null) + { + $query = 'SELECT DISTINCT courses.id, courses.xml FROM courses INNER JOIN crosslistings ON courses.id=crosslistings.course_id WHERE crosslistings.courseNumber >= "500" AND (' . $query . ');'; + return new UNL_UndergraduateBulletin_CourseSearch_DBSearchResults($query, $offset, $limit); + } +} \ No newline at end of file