From 6a202bda339ec396e2f1e95e5584d36b9b52dee6 Mon Sep 17 00:00:00 2001 From: Adam Franco Date: Tue, 8 Oct 2024 14:39:39 -0400 Subject: [PATCH] #47: Add single course view. --- application/views/scripts/courses/view.phtml | 90 ----- application/views/scripts/offerings.phtml | 63 ---- src/Controller/Courses.php | 342 +++++++++++-------- templates/courses/view.html.twig | 78 +++++ templates/partials/offerings.html.twig | 26 ++ 5 files changed, 307 insertions(+), 292 deletions(-) delete mode 100755 application/views/scripts/courses/view.phtml delete mode 100755 application/views/scripts/offerings.phtml create mode 100755 templates/courses/view.html.twig create mode 100755 templates/partials/offerings.html.twig diff --git a/application/views/scripts/courses/view.phtml b/application/views/scripts/courses/view.phtml deleted file mode 100755 index c9c8967e..00000000 --- a/application/views/scripts/courses/view.phtml +++ /dev/null @@ -1,90 +0,0 @@ -render('schedules/bookmark_control.phtml'); - -// print "\n\t
".$this->escape($this->course->getDisplayName())."
"; -print "\n\t

".$this->escape($this->course->getTitle())."

"; -if ($this->course->getDescription()) - print "\n\t
".$this->course->getDescription()."
"; - -print "\n\t
"; -// Topics -$topicParams = array( - 'controller' => 'topics', - 'action' => 'view', - 'offering' => null - ); -if (isset($this->term)) { - $topicParams['term'] = $this->getStringFromOsidId($this->term->getId()); -} else if (isset($this->linkTermId)) { - $topicParams['term'] = $this->getStringFromOsidId($this->linkTermId); -} - -print "\n\t
Subject:
"; -print "\n\t\t
"; -foreach ($this->subjectTopics as $topic) { - $topicParams['topic'] = $this->getStringFromOsidId($topic->getId()); - print "url($topicParams)."\">"; - print $this->escape($topic->getDisplayName()); - print " "; -} -print "
"; - -print "\n\t\t
Department:
"; -print "\n\t\t
"; -foreach ($this->departmentTopics as $topic) { - $topicParams['topic'] = $this->getStringFromOsidId($topic->getId()); - print "url($topicParams)."\">"; - print $this->escape($topic->getDisplayName()); - print " "; -} -print "
"; - -print "\n\t\t
Division:
"; -print "\n\t\t
"; -foreach ($this->divisionTopics as $topic) { -// $topicParams['topic'] = $this->getStringFromOsidId($topic->getId()); -// print "url($topicParams)."\">"; - print $this->escape($topic->getDisplayName()); -// print " "; -} -print "
"; - -print "\n\t\t
Requirements Fulfilled:
"; -print "\n\t\t
"; -foreach ($this->requirementTopics as $topic) { - $topicParams['topic'] = $this->getStringFromOsidId($topic->getId()); - print "url($topicParams)."\">"; - print $this->escape($topic->getDisplayName()); - print " "; -} -print "
"; - -if (isset($this->alternates)) { - $alternateType = new phpkit_type_URNInetType('urn:inet:middlebury.edu:record:alternates'); - - print "\n\t\t
Equivalent Courses:
"; - print "\n\t\t
"; - while ($this->alternates->hasNext()) { - try { - $alternate = $this->alternates->getNextCourse(); - $altParams['course'] = $this->getStringFromOsidId($alternate->getId()); - print "url($altParams)."\">"; - print $this->escape($alternate->getDisplayName()); - print ""; - if ($alternate->hasRecordType($alternateType)) { - $alternateRecord = $alternate->getCourseRecord($alternateType); - if ($alternateRecord->isPrimary()) { - print " * "; - } - } - print "
\n\t\t"; - } catch(osid_NotFoundException $e) { - } - } - print "
"; -} - -print "\n\t
"; - -print $this->render('offerings.phtml'); diff --git a/application/views/scripts/offerings.phtml b/application/views/scripts/offerings.phtml deleted file mode 100755 index fa0af3bd..00000000 --- a/application/views/scripts/offerings.phtml +++ /dev/null @@ -1,63 +0,0 @@ -"; -if (isset($this->term)) { - print "\n\t

".$this->offeringsTitle." in ".$this->term->getDisplayName()."

"; - if (isset($this->offeringsForAllTermsUrl)) { - print "\n\t"; - } -} else { - print "\n\t

".$this->offeringsTitle."

"; -} - -$offeringParams = array( - 'controller' => 'offerings', - 'action' => 'view', - 'course' => null, - 'topic' => null, - 'resource' => null - ); -while ($this->offerings->hasNext()) { - $offering = $this->offerings->getNextCourseOffering(); - if (!isset($currentTerm) || $currentTerm->getId() != $offering->getTermId()) { - $currentTerm = $offering->getTerm(); - print "\n

".$currentTerm->getDisplayName()."

"; - } - - $offeringParams['offering'] = $this->getStringFromOsidId($offering->getId()); - - if (isset($this->offering) && $offering->getId()->isEqual($this->offering->getId())) - print "\n\t
"; - else - print "\n\t
"; - - print "".$this->escape($offering->getDisplayName()).""; - print " ".$this->escape($offering->getGenusType()->getDisplayName()).""; - - if (!isset($this->hideOfferingInstructors) || !$this->hideOfferingInstructors) { - if ($offering->hasRecordType($instructorsType)) { - $instructorsRecord = $offering->getCourseOfferingRecord($instructorsType); - $instructors = $instructorsRecord->getInstructors(); - if ($instructors->hasNext()) { - $instNames = array(); - while ($instructors->hasNext()) { - $instructor = $instructors->getNextResource(); - if ($instructor->hasRecordType($namesType)) { - $namesRecord = $instructor->getResourceRecord($namesType); - $instNames[] = $this->escape($namesRecord->getSurname()); - } else { - $instNames[] = $this->escape($instructor->getDisplayName()); - } - } - print " ("; - print implode(', ', $instNames); - print ")"; - } - } - } - print "
"; -} -print "\n\t
"; diff --git a/src/Controller/Courses.php b/src/Controller/Courses.php index 3e5648a1..1df9fe86 100755 --- a/src/Controller/Courses.php +++ b/src/Controller/Courses.php @@ -60,20 +60,9 @@ public function __construct(Runtime $osidRuntime, IdMap $osidIdMap, TermHelper $ $this->osidIdMap = $osidIdMap; $this->osidTermHelper = $osidTermHelper; $this->osidTopicHelper = $osidTopicHelper; - } - - /** - * Initialize object. - * - * Called from {@link __construct()} as final step of object instantiation. - * - * @return void - */ - public function init() - { - $this->alternateType = new phpkit_type_URNInetType('urn:inet:middlebury.edu:record:alternates'); - - parent::init(); + $this->alternateType = new \phpkit_type_URNInetType('urn:inet:middlebury.edu:record:alternates'); + $this->instructorsType = new \phpkit_type_URNInetType('urn:inet:middlebury.edu:record:instructors'); + $this->namesType = new \phpkit_type_URNInetType('urn:inet:middlebury.edu:record:person_names'); } /** @@ -86,11 +75,11 @@ public function init() public function listAction() { if ($this->_getParam('catalog')) { - $catalogId = $this->_helper->osidId->fromString($this->_getParam('catalog')); - $lookupSession = $this->_helper->osid->getCourseManager()->getCourseLookupSessionForCatalog($catalogId); + $catalogId = $this->osidIdMap->fromString($this->_getParam('catalog')); + $lookupSession = $this->osidRuntime->getCourseManager()->getCourseLookupSessionForCatalog($catalogId); $this->view->title = 'Courses in '.$lookupSession->getCourseCatalog()->getDisplayName(); } else { - $lookupSession = $this->_helper->osid->getCourseManager()->getCourseLookupSession(); + $lookupSession = $this->osidRuntime->getCourseManager()->getCourseLookupSession(); $this->view->title = 'Courses in All Catalogs'; } $lookupSession->useFederatedCourseCatalogView(); @@ -106,67 +95,111 @@ public function listAction() #[Route('/courses/view/{course}/{term}', name: 'view_course')] public function view($course, $term = NULL) { - $id = $this->_helper->osidId->fromString($course); - $lookupSession = $this->_helper->osid->getCourseManager()->getCourseLookupSession(); - $lookupSession->useFederatedCourseCatalogView(); - $this->view->course = $lookupSession->getCourse($id); - - // Load the topics into our view - $this->loadTopics($this->view->course->getTopics()); + $data = $this->getCourseDataByIdString($course, $term); // Set the selected Catalog Id. - $catalogSession = $this->_helper->osid->getCourseManager()->getCourseCatalogSession(); - $catalogIds = $catalogSession->getCatalogIdsByCourse($id); - if ($catalogIds->hasNext()) { - $this->setSelectedCatalogId($catalogIds->getNextId()); + // $catalogSession = $this->osidRuntime->getCourseManager()->getCourseCatalogSession(); + // $catalogIds = $catalogSession->getCatalogIdsByCourse($id); + // if ($catalogIds->hasNext()) { + // $this->setSelectedCatalogId($catalogIds->getNextId()); + // } + + // $this->view->menuIsCourses = true; + + // Bookmarked Courses and Schedules + // $data['bookmarks_CourseId'] = $course->getId(); + + return $this->render('courses/view.html.twig', $data); + + } + + protected function getCourseDataByIdString($idString, $termIdString = NULL) + { + $id = $this->osidIdMap->fromString($idString); + $lookupSession = $this->osidRuntime->getCourseManager()->getCourseLookupSession(); + $lookupSession->useFederatedCourseCatalogView(); + + if ($termIdString) { + $termId = $this->osidIdMap->fromString($termIdString); + $termLookupSession = $this->osidRuntime->getCourseManager()->getTermLookupSession(); + $termLookupSession->useFederatedCourseCatalogView(); + $term = $termLookupSession->getTerm($termId); + } + else { + $term = NULL; } - // Set the title - $this->view->title = $this->view->course->getDisplayName(); - $this->view->headTitle($this->view->title); + return $this->getCourseData($lookupSession->getCourse($id), $term); + } - $this->view->menuIsCourses = true; + protected function getCourseData(\osid_course_Course $course, \osid_course_Term|NULL $term = NULL) { + $data['course'] = $course; + // Load the topics into our view + $data = array_merge($data, $this->getTopics($course->getTopics())); // Alternates - if ($this->view->course->hasRecordType($this->alternateType)) { - $record = $this->view->course->getCourseRecord($this->alternateType); + $data['is_primary'] = TRUE; + $data['alternates'] = NULL; + if ($course->hasRecordType($this->alternateType)) { + $record = $course->getCourseRecord($this->alternateType); + $data['is_primary'] = $record->isPrimary(); if ($record->hasAlternates()) { - $this->view->alternates = $record->getAlternates(); + $data['alternates'] = []; + $alternates = $record->getAlternates(); + while ($alternates->hasNext()) { + $alternate = $alternates->getNextCourse(); + $alternate->is_primary = FALSE; + if ($alternate->hasRecordType($this->alternateType)) { + $alternateRecord = $alternate->getCourseRecord($this->alternateType); + if ($alternateRecord->isPrimary()) { + $alternate->is_primary = TRUE; + } + } + $data['alternates'][] = $alternate; + } } } // Term - if ($term) { - $termId = $this->_helper->osidId->fromString($term); - $termLookupSession = $this->_helper->osid->getCourseManager()->getTermLookupSession(); - $termLookupSession->useFederatedCourseCatalogView(); - $this->view->term = $termLookupSession->getTerm($termId); - - $allParams = []; - $allParams['course'] = $this->_getParam('course'); - if ($this->getSelectedCatalogId()) { - $allParams['catalog'] = $this->_helper->osidId->toString($this->getSelectedCatalogId()); - } - $this->view->offeringsForAllTermsUrl = $this->_helper->url('view', 'courses', null, $allParams); - } else { - $this->view->linkTermId = $this->_helper->osidTerms->getNextOrLatestTermId($this->getSelectedCatalogId()); - } - - // Bookmarked Courses and Schedules - $this->view->bookmarks_CourseId = $this->view->course->getId(); + $data['term'] = $term; - // offerings - $this->view->offeringsTitle = 'Sections'; - $offeringLookupSession = $this->_helper->osid->getCourseManager()->getCourseOfferingLookupSession(); + // offerings. + $data['offerings'] = []; + $offeringLookupSession = $this->osidRuntime->getCourseManager()->getCourseOfferingLookupSession(); $offeringLookupSession->useFederatedCourseCatalogView(); - if (isset($this->view->term)) { - $this->view->offerings = $offeringLookupSession->getCourseOfferingsByTermForCourse( - $this->view->term->getId(), - $id + if ($term) { + $offerings = $offeringLookupSession->getCourseOfferingsByTermForCourse( + $term->getId(), + $course->getId(), ); } else { - $this->view->offerings = $offeringLookupSession->getCourseOfferingsForCourse($id); + $offerings = $offeringLookupSession->getCourseOfferingsForCourse($course->getId()); } + while ($offerings->hasNext()) { + $offering = $offerings->getNextCourseOffering(); + + if ($offering->hasRecordType($this->instructorsType)) { + $instructorsRecord = $offering->getCourseOfferingRecord($this->instructorsType); + $instructors = $instructorsRecord->getInstructors(); + $offering->instructors = []; + if ($instructors->hasNext()) { + $instNames = array(); + while ($instructors->hasNext()) { + $instructor = $instructors->getNextResource(); + if ($instructor->hasRecordType($this->namesType)) { + $namesRecord = $instructor->getResourceRecord($this->namesType); + $offering->instructors[] = $namesRecord->getSurname(); + } else { + $offering->instructors[] = $instructor->getDisplayName(); + } + } + } + } + + $data['offerings'][] = $offering; + } + + return $data; } /** @@ -200,8 +233,8 @@ public function searchxmlAction() exit; } try { - $catalogId = $this->_helper->osidId->fromString($this->_getParam('catalog')); - $searchSession = $this->_helper->osid->getCourseManager()->getCourseOfferingSearchSessionForCatalog($catalogId); + $catalogId = $this->osidIdMap->fromString($this->_getParam('catalog')); + $searchSession = $this->osidRuntime->getCourseManager()->getCourseOfferingSearchSessionForCatalog($catalogId); } catch (osid_InvalidArgumentException $e) { header('HTTP/1.1 400 Bad Request'); echo 'The catalog id specified was not of the correct format.'; @@ -218,13 +251,13 @@ public function searchxmlAction() header('Content-Type: text/xml'); echo ' - - Course Search: "'.htmlspecialchars($keywords).'" - '.$searchUrl.' - - '.date('r').' - Course Catalog - http://blogs.law.harvard.edu/tech/rss + + Course Search: "'.htmlspecialchars($keywords).'" + '.$searchUrl.' + + '.date('r').' + Course Catalog + http://blogs.law.harvard.edu/tech/rss '; $courses = []; @@ -236,18 +269,18 @@ public function searchxmlAction() $query = $searchSession->getCourseOfferingQuery(); $query->matchKeyword( $keywords, - new phpkit_type_URNInetType('urn:inet:middlebury.edu:search:wildcard'), + new \phpkit_type_URNInetType('urn:inet:middlebury.edu:search:wildcard'), true); $offerings = $searchSession->getCourseOfferingsByQuery($query); while ($offerings->hasNext() && count($courses) <= 20) { $offering = $offerings->getNextCourseOffering(); - $courseIdString = $this->_helper->osidId->toString($offering->getCourseId()); + $courseIdString = $this->osidIdMap->toString($offering->getCourseId()); if (!isset($courses[$courseIdString])) { try { $courses[$courseIdString] = $offering->getCourse(); } catch (osid_OperationFailedException $e) { - // print "\nFailure on ".$offering->getDisplayName()."OfferingId:\n".print_r($offering->getId(), true)."\n\nCourseId:\n".print_r($offering->getCourseId(), true)."]]>"; + // print "\nFailure on ".$offering->getDisplayName()."OfferingId:\n".print_r($offering->getId(), true)."\n\nCourseId:\n".print_r($offering->getCourseId(), true)."]]>"; } } } @@ -278,7 +311,7 @@ public function searchxmlAction() } echo ' - + '; exit; @@ -302,10 +335,10 @@ public function topicxmlAction() exit; } try { - $catalogId = $this->_helper->osidId->fromString($this->_getParam('catalog')); - $searchSession = $this->_helper->osid->getCourseManager()->getCourseSearchSessionForCatalog($catalogId); + $catalogId = $this->osidIdMap->fromString($this->_getParam('catalog')); + $searchSession = $this->osidRuntime->getCourseManager()->getCourseSearchSessionForCatalog($catalogId); - $this->termLookupSession = $this->_helper->osid->getCourseManager()->getTermLookupSessionForCatalog($catalogId); + $this->termLookupSession = $this->osidRuntime->getCourseManager()->getTermLookupSessionForCatalog($catalogId); } catch (osid_InvalidArgumentException $e) { header('HTTP/1.1 400 Bad Request'); echo 'The catalog id specified was not of the correct format.'; @@ -325,10 +358,10 @@ public function topicxmlAction() $topicsIds = []; if (is_array($this->_getParam('topic'))) { foreach ($this->_getParam('topic') as $idString) { - $topicIds[] = $this->_helper->osidId->fromString($idString); + $topicIds[] = $this->osidIdMap->fromString($idString); } } else { - $topicIds[] = $this->_helper->osidId->fromString($this->_getParam('topic')); + $topicIds[] = $this->osidIdMap->fromString($this->_getParam('topic')); } $searchUrl = $this->_helper->pathAsAbsoluteUrl($this->_helper->url('search', 'offerings', null, [])); @@ -336,7 +369,7 @@ public function topicxmlAction() // Fetch courses $query = $searchSession->getCourseQuery(); - $topicRecord = $query->getCourseQueryRecord(new phpkit_type_URNInetType('urn:inet:middlebury.edu:record:topic')); + $topicRecord = $query->getCourseQueryRecord(new \phpkit_type_URNInetType('urn:inet:middlebury.edu:record:topic')); foreach ($topicIds as $topicId) { $topicRecord->matchTopicId($topicId, true); } @@ -345,22 +378,22 @@ public function topicxmlAction() $locationIds = []; if (is_array($this->_getParam('location'))) { foreach ($this->_getParam('location') as $idString) { - $locationIds[] = $this->_helper->osidId->fromString($idString); + $locationIds[] = $this->osidIdMap->fromString($idString); } } elseif ($this->_getParam('location')) { - $locationIds[] = $this->_helper->osidId->fromString($this->_getParam('location')); + $locationIds[] = $this->osidIdMap->fromString($this->_getParam('location')); } - $locationRecord = $query->getCourseQueryRecord(new phpkit_type_URNInetType('urn:inet:middlebury.edu:record:location')); + $locationRecord = $query->getCourseQueryRecord(new \phpkit_type_URNInetType('urn:inet:middlebury.edu:record:location')); foreach ($locationIds as $locationId) { $locationRecord->matchLocationId($locationId, true); } // Limit to just active courses - $query->matchGenusType(new phpkit_type_URNInetType('urn:inet:middlebury.edu:status-active'), true); + $query->matchGenusType(new \phpkit_type_URNInetType('urn:inet:middlebury.edu:status-active'), true); $courses = $searchSession->getCoursesByQuery($query)->getCourses(); - $topicLookup = $this->_helper->osid->getCourseManager()->getTopicLookupSession(); + $topicLookup = $this->osidRuntime->getCourseManager()->getTopicLookupSession(); $topicLookup->useFederatedCourseCatalogView(); $topic = $topicLookup->getTopic($topicId); @@ -389,9 +422,9 @@ public function byidxmlAction() exit; } try { - $catalogId = $this->_helper->osidId->fromString($this->_getParam('catalog')); - $lookupSession = $this->_helper->osid->getCourseManager()->getCourseLookupSessionForCatalog($catalogId); - $this->termLookupSession = $this->_helper->osid->getCourseManager()->getTermLookupSessionForCatalog($catalogId); + $catalogId = $this->osidIdMap->fromString($this->_getParam('catalog')); + $lookupSession = $this->osidRuntime->getCourseManager()->getCourseLookupSessionForCatalog($catalogId); + $this->termLookupSession = $this->osidRuntime->getCourseManager()->getTermLookupSessionForCatalog($catalogId); } catch (osid_InvalidArgumentException $e) { header('HTTP/1.1 400 Bad Request'); echo 'The catalog id specified was not of the correct format.'; @@ -411,10 +444,10 @@ public function byidxmlAction() $courseIds = []; if (is_array($this->_getParam('id'))) { foreach ($this->_getParam('id') as $idString) { - $courseIds[] = $this->_helper->osidId->fromString($idString); + $courseIds[] = $this->osidIdMap->fromString($idString); } } else { - $courseIds[] = $this->_helper->osidId->fromString($this->_getParam('id')); + $courseIds[] = $this->osidIdMap->fromString($this->_getParam('id')); } // Use Comparative view to include any found courses, ignoring missing ids. @@ -455,28 +488,28 @@ public function instructorxmlAction() $this->_helper->viewRenderer->setNoRender(); if (!$this->_getParam('catalog')) { - $offeringSearchSession = $this->_helper->osid->getCourseManager()->getCourseOfferingSearchSession(); + $offeringSearchSession = $this->osidRuntime->getCourseManager()->getCourseOfferingSearchSession(); $offeringSearchSession->useFederatedCourseCatalogView(); - $courseLookupSession = $this->_helper->osid->getCourseManager()->getCourseLookupSession(); + $courseLookupSession = $this->osidRuntime->getCourseManager()->getCourseLookupSession(); $courseLookupSession->useFederatedCourseCatalogView(); // Allow term current/past to be limited to a certain catalog while courses are fetched from many if ($this->_getParam('term_catalog')) { - $catalogId = $this->_helper->osidId->fromString($this->_getParam('term_catalog')); - $this->termLookupSession = $this->_helper->osid->getCourseManager()->getTermLookupSessionForCatalog($catalogId); + $catalogId = $this->osidIdMap->fromString($this->_getParam('term_catalog')); + $this->termLookupSession = $this->osidRuntime->getCourseManager()->getTermLookupSessionForCatalog($catalogId); } // fall back to terms from any catalog. else { - $this->termLookupSession = $this->_helper->osid->getCourseManager()->getTermLookupSession(); + $this->termLookupSession = $this->osidRuntime->getCourseManager()->getTermLookupSession(); $this->termLookupSession->useFederatedCourseCatalogView(); } } else { try { - $catalogId = $this->_helper->osidId->fromString($this->_getParam('catalog')); - $offeringSearchSession = $this->_helper->osid->getCourseManager()->getCourseOfferingSearchSessionForCatalog($catalogId); - $courseLookupSession = $this->_helper->osid->getCourseManager()->getCourseLookupSessionForCatalog($catalogId); + $catalogId = $this->osidIdMap->fromString($this->_getParam('catalog')); + $offeringSearchSession = $this->osidRuntime->getCourseManager()->getCourseOfferingSearchSessionForCatalog($catalogId); + $courseLookupSession = $this->osidRuntime->getCourseManager()->getCourseLookupSessionForCatalog($catalogId); - $this->termLookupSession = $this->_helper->osid->getCourseManager()->getTermLookupSessionForCatalog($catalogId); + $this->termLookupSession = $this->osidRuntime->getCourseManager()->getTermLookupSessionForCatalog($catalogId); } catch (osid_InvalidArgumentException $e) { throw new osid_InvalidArgumentException('The catalog id specified was not of the correct format.'); } catch (osid_NotFoundException $e) { @@ -495,10 +528,10 @@ public function instructorxmlAction() throw new InvalidArgumentException('An instructor must be specified.'); } - $instructorId = $this->_helper->osidId->fromString('resource.person.'.$instructor); + $instructorId = $this->osidIdMap->fromString('resource.person.'.$instructor); $searchUrl = $this->_helper->pathAsAbsoluteUrl($this->_helper->url('view', 'resources', null, ['catalog' => $this->_getParam('catalog'), 'resource' => 'resouce.person.'.$instructor])); - $resourceLookup = $this->_helper->osid->getCourseManager()->getResourceManager()->getResourceLookupSession(); + $resourceLookup = $this->osidRuntime->getCourseManager()->getResourceManager()->getResourceLookupSession(); try { $instructorResource = $resourceLookup->getResource($instructorId); } catch (osid_NotFoundException $e) { @@ -512,7 +545,7 @@ public function instructorxmlAction() // Fetch Offerings $query = $offeringSearchSession->getCourseOfferingQuery(); - $instructorRecord = $query->getCourseOfferingQueryRecord(new phpkit_type_URNInetType('urn:inet:middlebury.edu:record:instructors')); + $instructorRecord = $query->getCourseOfferingQueryRecord(new \phpkit_type_URNInetType('urn:inet:middlebury.edu:record:instructors')); $instructorRecord->matchInstructorId($instructorId, true); $order = $offeringSearchSession->getCourseOfferingSearchOrder(); @@ -554,13 +587,13 @@ protected function outputCourseFeed(Helper_RecentCourses_Interface $recentCourse header('Content-Type: text/xml'); echo ' - - '.htmlspecialchars($title).' - '.$url.' - - '.date('r').' - Course Catalog - http://blogs.law.harvard.edu/tech/rss + + '.htmlspecialchars($title).' + '.$url.' + + '.date('r').' + Course Catalog + http://blogs.law.harvard.edu/tech/rss '; @@ -570,26 +603,26 @@ protected function outputCourseFeed(Helper_RecentCourses_Interface $recentCourse flush(); // Set the next and previous terms - $currentTermId = $this->_helper->osidTerms->getCurrentTermId($this->termLookupSession->getCourseCatalogId()); + $currentTermId = $this->osidTermHelper->getCurrentTermId($this->termLookupSession->getCourseCatalogId()); $currentTerm = $this->termLookupSession->getTerm($currentTermId); $currentEndTime = $this->DateTime_getTimestamp($currentTerm->getEndTime()); - // print "debug()); - // print "]]>"; + // print "debug()); + // print "]]>"; - $catalogSession = $this->_helper->osid->getCourseManager()->getCourseCatalogSession(); - $termsType = new phpkit_type_URNInetType('urn:inet:middlebury.edu:record:terms'); + $catalogSession = $this->osidRuntime->getCourseManager()->getCourseCatalogSession(); + $termsType = new \phpkit_type_URNInetType('urn:inet:middlebury.edu:record:terms'); - // foreach ($groups as $key => $group) { - // print "\n$key"; - // foreach ($group as $course) { - // print "\n\t".$this->_helper->osidId->toString($course->getId()); - // } - // } + // foreach ($groups as $key => $group) { + // print "\n$key"; + // foreach ($group as $course) { + // print "\n\t".$this->osidIdMap->toString($course->getId()); + // } + // } foreach ($recentCourses->getPrimaryCourses() as $course) { - $courseIdString = $this->_helper->osidId->toString($course->getId()); + $courseIdString = $this->osidIdMap->toString($course->getId()); echo "\n\t\t"; @@ -605,7 +638,7 @@ protected function outputCourseFeed(Helper_RecentCourses_Interface $recentCourse echo "\n\t\t\t"; $catalog = $catalogSession->getCatalogIdsByCourse($course->getId()); if ($catalog->hasNext()) { - $catalogIdString = $this->_helper->osidId->toString($catalog->getNextId()); + $catalogIdString = $this->osidIdMap->toString($catalog->getNextId()); } else { $catalogIdString = null; } @@ -625,7 +658,7 @@ protected function outputCourseFeed(Helper_RecentCourses_Interface $recentCourse foreach ($alternates as $alt) { echo "\n\t\t\t"; - echo "\n\t\t\t\t".$this->_helper->osidId->toString($alt->getId()).''; + echo "\n\t\t\t\t".$this->osidIdMap->toString($alt->getId()).''; echo "\n\t\t\t\t".htmlspecialchars($alt->getDisplayName()).''; echo "\n\t\t\t\t".htmlspecialchars($alt->getTitle()).''; echo "\n\t\t\t"; @@ -635,7 +668,7 @@ protected function outputCourseFeed(Helper_RecentCourses_Interface $recentCourse if (count($recentTerms)) { $termStrings = []; foreach ($recentTerms as $term) { - echo "\n\t\t\t_helper->osidId->toString($term->getId()).'"'; + echo "\n\t\t\tosidIdMap->toString($term->getId()).'"'; if ($term->getId()->isEqual($currentTermId)) { echo ' type="current"'; } elseif ($currentEndTime < $this->DateTime_getTimestamp($term->getEndTime())) { @@ -649,33 +682,33 @@ protected function outputCourseFeed(Helper_RecentCourses_Interface $recentCourse } } - $allTopics = $this->_helper->topics->topicListAsArray($course->getTopics()); - $topicType = new phpkit_type_URNInetType('urn:inet:middlebury.edu:genera:topic.department'); + $allTopics = $this->osidTopicHelper->topicListAsArray($course->getTopics()); + $topicType = new \phpkit_type_URNInetType('urn:inet:middlebury.edu:genera:topic.department'); $topicTypeString = $this->_helper->osidType->toString($topicType); - $topics = $this->_helper->topics->filterTopicsByType($allTopics, $topicType); + $topics = $this->osidTopicHelper->filterTopicsByType($allTopics, $topicType); foreach ($topics as $topic) { - $topicParams['topic'] = $this->_helper->osidId->toString($topic->getId()); - echo "\n\t\t\t'; + $topicParams['topic'] = $this->osidIdMap->toString($topic->getId()); + echo "\n\t\t\t'; echo $this->view->escape($topic->getDisplayName()); echo ' '; } - $topicType = new phpkit_type_URNInetType('urn:inet:middlebury.edu:genera:topic.requirement'); + $topicType = new \phpkit_type_URNInetType('urn:inet:middlebury.edu:genera:topic.requirement'); $topicTypeString = $this->_helper->osidType->toString($topicType); - $topics = $this->_helper->topics->filterTopicsByType($allTopics, $topicType); + $topics = $this->osidTopicHelper->filterTopicsByType($allTopics, $topicType); foreach ($topics as $topic) { - $topicParams['topic'] = $this->_helper->osidId->toString($topic->getId()); - echo "\n\t\t\t'; + $topicParams['topic'] = $this->osidIdMap->toString($topic->getId()); + echo "\n\t\t\t'; echo $this->view->escape($topic->getDisplayName()); echo ' '; } - $topicType = new phpkit_type_URNInetType('urn:inet:middlebury.edu:genera:topic.level'); + $topicType = new \phpkit_type_URNInetType('urn:inet:middlebury.edu:genera:topic.level'); $topicTypeString = $this->_helper->osidType->toString($topicType); - $topics = $this->_helper->topics->filterTopicsByType($allTopics, $topicType); + $topics = $this->osidTopicHelper->filterTopicsByType($allTopics, $topicType); foreach ($topics as $topic) { - $topicParams['topic'] = $this->_helper->osidId->toString($topic->getId()); - echo "\n\t\t\t'; + $topicParams['topic'] = $this->osidIdMap->toString($topic->getId()); + echo "\n\t\t\t'; echo $this->view->escape($topic->getDisplayName()); echo ' '; } @@ -685,7 +718,7 @@ protected function outputCourseFeed(Helper_RecentCourses_Interface $recentCourse } echo ' - + '; exit; } @@ -705,4 +738,35 @@ public function DateTime_getTimestamp($dt) return gmmktime($hour, $minute, $second, $month, $day, $year); } + + /** + * Load topics into our view. + * + * @param osid_course_TopicList + * + * @return void + * + * @since 4/28/09 + */ + protected function getTopics(\osid_course_TopicList $topicList) + { + $data = []; + $topics = $this->osidTopicHelper->topicListAsArray($topicList); + + $data['subjectTopics'] = $this->osidTopicHelper->filterTopicsByType($topics, new \phpkit_type_URNInetType('urn:inet:middlebury.edu:genera:topic.subject')); + + $data['departmentTopics'] = $this->osidTopicHelper->filterTopicsByType($topics, new \phpkit_type_URNInetType('urn:inet:middlebury.edu:genera:topic.department')); + + $data['divisionTopics'] = $this->osidTopicHelper->filterTopicsByType($topics, new \phpkit_type_URNInetType('urn:inet:middlebury.edu:genera:topic.division')); + + $data['requirementTopics'] = $this->osidTopicHelper->filterTopicsByType($topics, new \phpkit_type_URNInetType('urn:inet:middlebury.edu:genera:topic.requirement')); + + $data['levelTopics'] = $this->osidTopicHelper->filterTopicsByType($topics, new \phpkit_type_URNInetType('urn:inet:middlebury.edu:genera:topic.level')); + + $data['blockTopics'] = $this->osidTopicHelper->filterTopicsByType($topics, new \phpkit_type_URNInetType('urn:inet:middlebury.edu:genera:topic.block')); + + $data['instructionMethodTopics'] = $this->osidTopicHelper->filterTopicsByType($topics, new \phpkit_type_URNInetType('urn:inet:middlebury.edu:genera:topic.instruction_method')); + + return $data; + } } diff --git a/templates/courses/view.html.twig b/templates/courses/view.html.twig new file mode 100755 index 00000000..3b9241db --- /dev/null +++ b/templates/courses/view.html.twig @@ -0,0 +1,78 @@ +print $this->render('schedules/bookmark_control.phtml'); + +
{{ course.displayname }}
+

{{ course.title }}

+{% if course.description %} +
{{ course.description|raw }}
+{% endif %} +
+
Subject:
+
+ {% for topic in subjectTopics %} + {{ topic.displayname }}{{ not loop.last ? ',' }} + {% endfor %} +
+ +
Department:
+
+ {% for topic in departmentTopics %} + {{ topic.displayname }}{{ not loop.last ? ',' }} + {% endfor %} +
+ +
Division:
+
+ {% for topic in divisionTopics %} + {{ topic.displayname }}{{ not loop.last ? ',' }} + {% endfor %} +
+ +
Requirements Fulfilled:
+
+ {% for topic in requirementTopics %} + {{ topic.displayname }}{{ not loop.last ? ',' }} + {% endfor %} +
+ +{% if blockTopics is not empty %} +
Additional Details:
+
+ {% for topic in blockTopics %} + {{ topic.displayname }}{{ not loop.last ? ',' }} + {% endfor %} +
+{% endif %} + +{% if levelTopics is not empty %} +
Levels:
+
+ {% for topic in levelTopics %} + {{ topic.displayname }}{{ not loop.last ? ',' }} + {% endfor %} +
+{% endif %} + +{% if alternates is not empty %} +
Equivalent Courses:
+
+ {% for alternate in alternates %} + {{ alternate.displayname }} + {{ alternate.is_primary ? ' * ' }} +
+ {% endfor %} +
+{% endif %} + +
+ +{{ include( + 'partials/offerings.html.twig', + { + offerings: offerings, + term: term, + offeringsForAllTermsUrl: url('view_course', {course: osidIdToString(course.id)}), + hideOfferingInstructors: FALSE, + selectedOffering: NULL + }, + with_context = false +)}} diff --git a/templates/partials/offerings.html.twig b/templates/partials/offerings.html.twig new file mode 100755 index 00000000..60e62e6d --- /dev/null +++ b/templates/partials/offerings.html.twig @@ -0,0 +1,26 @@ +
+{% if term %} +

Sections in {{ term.displayname }}

+ +{% else %} +

Sections

+{% endif %} + +{% set currentTerm = null %} +{% for offering in offerings %} + {% if currentTerm is null or currentTerm.id != offering.termid %} + {% set currentTerm = offering.term %} +

{{ currentTerm.displayname }}

+ {% endif %} + {% if selectedOffering and selectedOffering.id == offering.id %} +
+ {% else %} +
+ {% endif %} + {{offering.displayname}} + {{ offering.genustype.displayname }} + {% if offering.instructors %} + ({{ offering.instructors|join(', ') }}) + {% endif %} +
+{% endfor %}