diff --git a/application/views/scripts/offerings/searchxml.phtml b/application/views/scripts/offerings/searchxml.phtml deleted file mode 100755 index 498a77c2..00000000 --- a/application/views/scripts/offerings/searchxml.phtml +++ /dev/null @@ -1,220 +0,0 @@ -pathAsAbsoluteUrl($view->url(array( - 'controller' => 'terms', - 'action' => 'view', - 'term' => $view->getStringFromOsidId($term->getId()), - 'offering' => null - ))); - - $start_date = $term->getStartTime()->format('Y-m-d'); - $end_date = $term->getEndTime()->format('Y-m-d'); - // PHP >= 5.3 -// $span = $term->getEndTime()->diff($term->getStartTime()); -// $weeks = ceil($span->days / 7); - // PHP < 5.3 - $weeks = ceil(abs($term->getEndTime()->format('U') - $term->getStartTime()->format('U'))/60/60/24/7); - - print "\n".$tabs."getStringFromOsidId($term->getId())."\" href=\"".$termUrl."\" start_date=\"".$start_date."\" end_date=\"".$end_date."\" weeks=\"".$weeks."\">"; - print $view->escape($term->getDisplayName()); - print " "; -} - -print ' - - - '.$this->feedTitle.' - '.$this->feedLink.' - - '.date('r').' - Course Catalog - http://blogs.law.harvard.edu/tech/rss -'; - -if (isset($this->previousTerm)) - printTerm($this, $this->previousTerm, 'previous_term', "\t\t"); -if (isset($this->term)) - printTerm($this, $this->term, 'chosen_term', "\t\t"); -if (isset($this->nextTerm)) - printTerm($this, $this->nextTerm, 'next_term', "\t\t"); - - -if (isset($this->terms)) { - print "\n\t\t"; - while ($this->terms->hasNext()) { - printTerm($this, $this->terms->getNextTerm()); - } - print "\n\t\t"; -} - -print "\n"; - -$alternateType = new phpkit_type_URNInetType('urn:inet:middlebury.edu:record:alternates'); -while ($this->sections->hasNext()) { - $section = $this->sections->getNextCourseOffering(); - - $offeringParams = array( - 'controller' => 'offerings', - 'action' => 'view', - 'offering' => $this->getStringFromOsidId($section->getId()) - ); - $resourceParams = array( - 'controller' => 'resources', - 'action' => 'view', - 'offering' => null - ); - - $term = $section->getTerm(); - $topicParams = array( - 'controller' => 'topics', - 'action' => 'view', - 'offering' => null, - 'term' => $this->getStringFromOsidId($term->getId()) - ); - - // Topics - $allTopics = $this->topicListAsArray($section->getTopics()); -?> - - - <?php print $this->escape($section->getDisplayName()); ?> - pathAsAbsoluteUrl($this->url($offeringParams)); ?> - getDescription(); ?>]]> - escape($section->getTitle()); ?> - escape($this->getStringFromOsidId($section->getId())); ?> -hasRecordType($alternateType)) { - $record = $section->getCourseOfferingRecord($alternateType); - print "\n\t\t\t"; - print $record->isPrimary()?"true":"false"; - print " "; - if ($record->hasAlternates()) { - $alternates = $record->getAlternates(); - while ($alternates->hasNext()) { - $alternate = $alternates->getNextCourseOffering(); - $offeringParams['offering'] = $this->getStringFromOsidId($alternate->getId()); - print "\n\t\t\tgetStringFromOsidId($alternate->getId())."\" href=\"".$this->pathAsAbsoluteUrl($this->url($offeringParams))."\">"; - print $this->escape($alternate->getDisplayName()); - print " "; - } - } -} - -print "\n\t\t\tgetStringFromOsidType($section->getGenusType())."\" "; -print "href=\"".$this->pathAsAbsoluteUrl($this->url($offeringParams))."\">"; -print $this->escape($section->getGenusType()->getDisplayName()); -print " "; - -printTerm($this, $term); - -$topicType = new phpkit_type_URNInetType("urn:inet:middlebury.edu:genera:topic.subject"); -$topicTypeString = $this->getStringFromOsidType($topicType); -$topics = $this->filterTopicsByType($allTopics, $topicType); -foreach ($topics as $topic) { - $topicParams['topic'] = $this->getStringFromOsidId($topic->getId()); - print "\n\t\t\tgetStringFromOsidId($topic->getId())."\" href=\"".$this->pathAsAbsoluteUrl($this->url($topicParams))."\">"; - print $this->escape($topic->getDisplayName()); - print " "; -} - -$topicType = new phpkit_type_URNInetType("urn:inet:middlebury.edu:genera:topic.department"); -$topicTypeString = $this->getStringFromOsidType($topicType); -$topics = $this->filterTopicsByType($allTopics, $topicType); -foreach ($topics as $topic) { - $topicParams['topic'] = $this->getStringFromOsidId($topic->getId()); - print "\n\t\t\tgetStringFromOsidId($topic->getId())."\" href=\"".$this->pathAsAbsoluteUrl($this->url($topicParams))."\">"; - print $this->escape($topic->getDisplayName()); - print " "; -} - -$topicType = new phpkit_type_URNInetType("urn:inet:middlebury.edu:genera:topic.requirement"); -$topicTypeString = $this->getStringFromOsidType($topicType); -$topics = $this->filterTopicsByType($allTopics, $topicType); -foreach ($topics as $topic) { - $topicParams['topic'] = $this->getStringFromOsidId($topic->getId()); - print "\n\t\t\tgetStringFromOsidId($topic->getId())."\" href=\"".$this->pathAsAbsoluteUrl($this->url($topicParams))."\">"; - print $this->escape($topic->getDisplayName()); - print " "; -} - -$topicType = new phpkit_type_URNInetType("urn:inet:middlebury.edu:genera:topic.level"); -$topicTypeString = $this->getStringFromOsidType($topicType); -$topics = $this->filterTopicsByType($allTopics, $topicType); -foreach ($topics as $topic) { - $topicParams['topic'] = $this->getStringFromOsidId($topic->getId()); - print "\n\t\t\tgetStringFromOsidId($topic->getId())."\" href=\"".$this->pathAsAbsoluteUrl($this->url($topicParams))."\">"; - print $this->escape($topic->getDisplayName()); - print " "; -} - -$topicType = new phpkit_type_URNInetType("urn:inet:middlebury.edu:genera:topic.block"); -$topicTypeString = $this->getStringFromOsidType($topicType); -$topics = $this->filterTopicsByType($allTopics, $topicType); -foreach ($topics as $topic) { - $topicParams['topic'] = $this->getStringFromOsidId($topic->getId()); - print "\n\t\t\tgetStringFromOsidId($topic->getId())."\" href=\"".$this->pathAsAbsoluteUrl($this->url($topicParams))."\">"; - print $this->escape($topic->getDisplayName()); - print " "; -} - - -$instructorsType = new phpkit_type_URNInetType('urn:inet:middlebury.edu:record:instructors'); -if ($section->hasRecordType($instructorsType)) { - $instructorsRecord = $section->getCourseOfferingRecord($instructorsType); - $instructors = $instructorsRecord->getInstructors(); - while ($instructors->hasNext()) { - $instructor = $instructors->getNextResource(); - $resourceParams['resource'] = $this->getStringFromOsidId($instructor->getId()); - print "\n\t\t\tgetStringFromOsidId($instructor->getId())."\" href=\"".$this->pathAsAbsoluteUrl($this->url($resourceParams))."\">"; - print $this->escape($instructor->getDisplayName()); - print " "; - } -} - -if ($section->hasLocation()) { - try { - $locationResource = $section->getLocation(); - $resourceParams['resource'] = $this->getStringFromOsidId($locationResource->getId()); - print "\n\t\t\tgetStringFromOsidId($locationResource->getId())."\" href=\"".$this->pathAsAbsoluteUrl($this->url($resourceParams))."\">"; - print $this->escape($locationResource->getDisplayName()); - print " "; -// if ($locationResource->getDescription()) -// print "(".$this->escape($locationResource->getDescription()).")"; -// print "\n\t\t"; - } catch (osid_OperationFailedException $e) { - print "\n\t\t\t".$this->escape($section->getLocationInfo()).""; - } -} else if ($section->getLocationInfo()) { - print "\n\t\t\t".$this->escape($section->getLocationInfo()).""; -} -print "\n\t\t\thasRecordType($weeklyScheduleType)) { - $scheduleRecord = $section->getCourseOfferingRecord($weeklyScheduleType); - if ($scheduleRecord->hasMeetingStartDate()) { - print ' meeting_start_date="' . $scheduleRecord->getMeetingStartDate()->format('Y-m-d') . '"'; - } - if ($scheduleRecord->hasMeetingEndDate()) { - print ' meeting_end_date="' . $scheduleRecord->getMeetingEndDate()->format('Y-m-d') . '"'; - } -} -print ">".$this->escape($section->getScheduleInfo()).""; - -$properties = $section->getProperties(); -while ($properties->hasNext()) { - $property = $properties->getNextProperty(); - print "\n\t\t\t"; - print "\n\t\t\t\t".$property->getDisplayName().""; - print "\n\t\t\t\t".$property->getDisplayLabel().""; - print "\n\t\t\t\tgetDescription()."]]>"; - print "\n\t\t\t\tgetValue()."]]>"; - print "\n\t\t\t"; -} -?> - - - - - diff --git a/config/services.yaml b/config/services.yaml index 5262ce94..7e46208b 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -46,6 +46,10 @@ services: tags: - { name: 'twig.extension' } + App\Twig\DateRangeFormatter: + tags: + - { name: 'twig.extension' } + # Service aliases. osid.runtime: class: App\Service\Osid\Runtime diff --git a/src/Controller/Offerings.php b/src/Controller/Offerings.php index 2ed78ec4..eb20d4de 100755 --- a/src/Controller/Offerings.php +++ b/src/Controller/Offerings.php @@ -13,7 +13,7 @@ use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Annotation\Route; - +use Symfony\Component\Routing\Generator\UrlGeneratorInterface; /** * A controller for working with courses. @@ -697,13 +697,22 @@ protected function viewBase($idString) $data['title'] = $offering->getDisplayName(); + $data['previousTerm'] = NULL; $data['term'] = $offering->getTerm(); + $data['nextTerm'] = NULL; + $data['terms'] = NULL; $data['location'] = NULL; if ($offering->hasLocation()) { $data['location'] = $offering->getLocation(); } + $data['weekly_schedule'] = NULL; + $weeklyScheduleType = new \phpkit_type_URNInetType('urn:inet:middlebury.edu:record:weekly_schedule'); + if ($offering->hasRecordType($weeklyScheduleType)) { + $data['weekly_schedule'] = $offering->getCourseOfferingRecord($weeklyScheduleType); + } + // Instructors $data['instructors'] = NULL; $instructorsType = new \phpkit_type_URNInetType('urn:inet:middlebury.edu:record:instructors'); @@ -717,9 +726,11 @@ protected function viewBase($idString) } // Alternates. + $data['is_primary'] = TRUE; $data['alternates'] = NULL; if ($offering->hasRecordType($this->getAlternateType())) { $record = $offering->getCourseOfferingRecord($this->getAlternateType()); + $data['is_primary'] = $record->isPrimary(); if ($record->hasAlternates()) { $data['alternates'] = []; $alternates = $record->getAlternates(); @@ -758,25 +769,19 @@ protected function viewBase($idString) return $data; } - /** - * Answer search results as an xml feed. - * - * @return void - * - * @since 10/21/09 - */ - public function viewxmlAction() + #[Route('/offerings/viewxml/{id}', name: 'view_offering_xml')] + public function viewxmlAction($id) { - $this->_helper->layout->disableLayout(); - $this->_helper->viewRenderer->setRender('searchxml'); - $this->getResponse()->setHeader('Content-Type', 'text/xml'); + $data = $this->viewBase($id); - $this->viewBase(); + $data['feedLink'] = $this->generateUrl('view_offering', ['id' => $id], UrlGeneratorInterface::ABSOLUTE_URL); - $this->view->feedTitle = $this->view->title; - $this->view->feedLink = $this->_helper->pathAsAbsoluteUrl('/offerings/view/'.$catalog.'/offering/'.$this->_getParam('offering')); - $this->view->sections = new \phpkit_course_ArrayCourseOfferingList([$this->view->offering]); - $this->postDispatch(); + + $data['sections'] = [$data['offering']]; + + $response = new Response($this->renderView('offerings/search.xml.twig', $data)); + $response->headers->set('Content-Type', 'text/xml; charset=utf-8'); + return $response; } protected function getAlternateType() { diff --git a/src/Service/Osid/IdMap.php b/src/Service/Osid/IdMap.php index c22f7007..2402e02d 100755 --- a/src/Service/Osid/IdMap.php +++ b/src/Service/Osid/IdMap.php @@ -50,4 +50,44 @@ public function toString(\osid_id_Id $id) return \phpkit_id_URNInetId::getInetURNString($id); } } + + /** + * Get and OSID Type object from a string. + * + * @param string $typeString + * + * @return osid_type_Type + * + * @since 4/21/09 + */ + public function typeFromString($typeString) + { + try { + return new \phpkit_type_URNInetType($typeString); + } catch (\osid_InvalidArgumentException $e) { + if ($this->getIdAuthorityToShorten()) { + return new \phpkit_type_Type($this->getIdAuthorityToShorten(), 'urn', $typeString); + } else { + throw $e; + } + } + } + + /** + * Answer a string representation of an OSID type object. + * + * @return string + * + * @since 4/21/09 + */ + public function typeToString(\osid_type_Type $type) + { + if ($this->getIdAuthorityToShorten() + && 'urn' == strtolower($type->getIdentifierNamespace()) + && strtolower($type->getAuthority()) == $this->getIdAuthorityToShorten()) { + return $type->getIdentifier(); + } else { + return \phpkit_type_URNInetType::getInetURNString($type); + } + } } diff --git a/src/Twig/DateRangeFormatter.php b/src/Twig/DateRangeFormatter.php new file mode 100644 index 00000000..eb0b8f74 --- /dev/null +++ b/src/Twig/DateRangeFormatter.php @@ -0,0 +1,24 @@ +format('U') - $start->format('U'))/60/60/24/7); + } +} diff --git a/src/Twig/OsidIdExtension.php b/src/Twig/OsidIdExtension.php index 230f28f7..0b9bcb69 100644 --- a/src/Twig/OsidIdExtension.php +++ b/src/Twig/OsidIdExtension.php @@ -30,6 +30,7 @@ public function getFunctions(): array { return [ new TwigFunction('osidIdToString', [$this, 'osidIdToString']), + new TwigFunction('osidTypeToString', [$this, 'osidTypeToString']), ]; } @@ -37,4 +38,9 @@ public function osidIdToString(\osid_id_Id $id): string { return $this->idMap->toString($id); } + + public function osidTypeToString(\osid_type_Type $type): string + { + return $this->idMap->typeToString($type); + } } diff --git a/templates/offerings/search.xml.twig b/templates/offerings/search.xml.twig new file mode 100755 index 00000000..4ea4987c --- /dev/null +++ b/templates/offerings/search.xml.twig @@ -0,0 +1,83 @@ + + + + {{ title }} + {{ feedLink }} + + {{ 'now' | date('r') }} + Course Catalog + http://blogs.law.harvard.edu/tech/rss + {% if previousTerm %}{{ include('partials/term.xml.twig', {term: previousTerm, key: 'previous_term'}) }}{% endif %} + {% if term %}{{ include('partials/term.xml.twig', {term: term, key: 'chosen_term'}) }}{% endif %} + {% if nextTerm %}{{ include('partials/term.xml.twig', {term: nextTerm, key: 'next_term'}) }}{% endif %} +{% if terms %} + + {% for t in terms %} + {{ include('partials/term.xml.twig', {term: t, key: 'term'}) }} + {% endfor %} + +{% endif %} + +{% for section in sections %} + + {{ section.displayname }} + {{ url('view_offering', {'id': osidIdToString(section.id)}) }} + + {{ section.title }} + {{ osidIdToString(section.id) }} + {%~ if is_primary is not null %} + {{ is_primary ? 'true':'false' }} + {% endif ~%} +{%- if alternates is not empty %} +{%- for alternate in alternates %} + {{ alternate.displayname }} +{% endfor ~%} +{% endif %} + {{ offering.genustype.displayname }} + {{ include('partials/term.xml.twig', {term: section.term, key: 'term'}) }} + +{%- for topic in subjectTopics %} + {{ topic.displayname }} +{% endfor %} +{%- for topic in departmentTopics %} + {{ topic.displayname }} +{% endfor %} +{%- for topic in divisionTopics %} + {{ topic.displayname }} +{% endfor %} +{%- for topic in requirementTopics %} + {{ topic.displayname }} +{% endfor %} +{%- if blockTopics is not empty %} + {%- for topic in blockTopics %} + {{ topic.displayname }} + {% endfor %} +{% endif %} +{%- if levelTopics is not empty %} + {%- for topic in levelTopics %} + {{ topic.displayname }} + {% endfor ~%} +{% endif %} +{%- if instructors is not null %} + {%- for instructor in instructors %} + {{ instructor.displayname }} + {% endfor %} +{% endif %} +{%- if location %} + {{ location.displayname }} +{% elseif offering.locationinfo %} + {{ offering.locationinfo }} +{% endif %} + {{ offering.scheduleinfo|raw }} +{% for property in properties %} + + {{ property.displayname }} + {{ property.displaylabel}} + + + +{% endfor %} +{% endfor %} + + + diff --git a/templates/partials/term.xml.twig b/templates/partials/term.xml.twig new file mode 100644 index 00000000..e3a771c7 --- /dev/null +++ b/templates/partials/term.xml.twig @@ -0,0 +1 @@ +{{ term.displayname }}