Skip to content
Snippets Groups Projects
Commit 4acba20b authored by Brett Bieber's avatar Brett Bieber
Browse files

Install UNL_Services_CourseApproval lib

parent ab6daa16
Branches
Tags
No related merge requests found
Showing
with 1213 additions and 1 deletion
No preview for this file type
<?xml version="1.0" encoding="UTF-8"?>
<package xmlns="http://pear.php.net/dtd/package-2.1" xmlns:tasks="http://pear.php.net/dtd/tasks-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.1" xsi:schemaLocation="http://pear.php.net/dtd/tasks-1.0 http://pear.php.net/dtd/tasks-1.0.xsd http://pear.php.net/dtd/package-2.1 http://pear.php.net/dtd/package-2.1.xsd">
<name>UNL_Services_CourseApproval</name>
<channel>pear.unl.edu</channel>
<summary>Client API for the curriculum request system at creq.unl.edu
</summary>
<description>
This project provides a simple API for the course data within the creq system
built by Tim Steiner.
This project requires the UNL_Autoload package, and optionally Cache_Lite for
caching data from the creq system.
Currently data is cached on the local system in /tmp/cache_* files and stored
for one week.
See the docs/examples/ directory for examples.
For information on the XML format, see the XSD -
http://courseapproval.unl.edu/schema/courses.xsd</description>
<lead>
<name>Brett Bieber</name>
<user>saltybeagle</user>
<email>brett.bieber@gmail.com</email>
<active>yes</active>
</lead>
<date>2013-09-24</date>
<time>10:29:31</time>
<version>
<release>0.4.0</release>
<api>0.1.0</api>
</version>
<stability>
<release>alpha</release>
<api>alpha</api>
</stability>
<license uri="http://www.opensource.org/licenses/bsd-license.php">New BSD License</license>
<notes>Feature Release!
New tools for filtering out courses
Features:
* Add support for searching by course number suffix. E.g. 41 for 141, 241, 341
</notes>
<contents>
<dir name="/">
<file role="test" name="tests/test_framework.php" md5sum="e4f9bc1757951877325604c19e3ab217"/>
<file role="test" name="tests/subsequent_courses.phpt" md5sum="f64a2e44fbeb29244d1f513dc9345614"/>
<file role="test" name="tests/subjects.phpt" md5sum="2cad4c38c985bf9ad5447cd125f722e4"/>
<file role="test" name="tests/search.phpt" md5sum="96138fa9c28c562d58cfc34a015df468"/>
<file role="test" name="tests/sample.phpt" md5sum="3aa1605f14db215adbecb5aea6fb9e7e"/>
<file role="test" name="tests/listing.phpt" md5sum="09c4d745744c0d1868940c784c818ec1"/>
<file role="test" name="tests/isset.phpt" md5sum="894be932fa8e4a53fe5ab6a6a09cf108"/>
<file role="test" name="tests/dfremoval.phpt" md5sum="1d7731d25166be2846dca42482d0e9d8"/>
<file role="test" name="tests/credits.phpt" md5sum="d8a226bcd8df76eba52d2be3fcd1f232"/>
<file role="test" name="tests/array_details.phpt" md5sum="a594d847a39c1e4f252ab6f224a4f7f1"/>
<file role="test" name="tests/activities.phpt" md5sum="8fc02ef556eebeb64845686c5329a915"/>
<file role="php" name="src/UNL/Services/CourseApproval/XCRIService/MockService.php" md5sum="6ce3e7960cc96859324b01d3689e483c"/>
<file role="php" name="src/UNL/Services/CourseApproval/XCRIService/creq.php" md5sum="fa8f0b57588220b7b1d27d9c310ea438"/>
<file role="php" name="src/UNL/Services/CourseApproval/XCRIService.php" md5sum="43510f6da18f84d84906db84e85c12ec"/>
<file role="php" name="src/UNL/Services/CourseApproval/SubjectArea/Groups.php" md5sum="1366c9b03a537a89738761649f6f9192"/>
<file role="php" name="src/UNL/Services/CourseApproval/SubjectArea/Courses.php" md5sum="5d8f10bdb2abd05623f2d17c4e03ead0"/>
<file role="php" name="src/UNL/Services/CourseApproval/SubjectArea.php" md5sum="37a06f138ab00f42acca4ba2fa4cedbc"/>
<file role="php" name="src/UNL/Services/CourseApproval/SearchInterface/XPath.php" md5sum="b3b89c725efffcc1dd0f5224a337b291"/>
<file role="php" name="src/UNL/Services/CourseApproval/SearchInterface.php" md5sum="51d01d912970c154eaf804e98ca541c3"/>
<file role="php" name="src/UNL/Services/CourseApproval/Search/Results.php" md5sum="fec9d8c559335a6f7e7b894a85056772"/>
<file role="php" name="src/UNL/Services/CourseApproval/Search.php" md5sum="6c17f58d0f4a7f4e83a441a75e064716"/>
<file role="php" name="src/UNL/Services/CourseApproval/Listing.php" md5sum="0d2b6c93325511b5d4a06db12d709200"/>
<file role="php" name="src/UNL/Services/CourseApproval/Filter/ExcludeUndergraduateCourses.php" md5sum="17a5e0f582d8f8d086108df6e24a6959"/>
<file role="php" name="src/UNL/Services/CourseApproval/Filter/ExcludeGraduateCourses.php" md5sum="099d7af04e732e1851840901c5be3a41"/>
<file role="php" name="src/UNL/Services/CourseApproval/Courses.php" md5sum="867d1cf75bf8af88b4eb273c9384e417"/>
<file role="php" name="src/UNL/Services/CourseApproval/Course/Credits.php" md5sum="32be56ea6645167ce0a5a7cc62c4ba96"/>
<file role="php" name="src/UNL/Services/CourseApproval/Course/Codes.php" md5sum="fae6d972149685f84d70dd7273552661"/>
<file role="php" name="src/UNL/Services/CourseApproval/Course/Activities.php" md5sum="05600adcb178cb7630337b52969633a9"/>
<file role="php" name="src/UNL/Services/CourseApproval/Course.php" md5sum="d3da6078336cae6b2b794ed2c40e8e47"/>
<file role="php" name="src/UNL/Services/CourseApproval/College.php" md5sum="90b76d7bbac0738920d6439b37f49d97"/>
<file role="php" name="src/UNL/Services/CourseApproval/CachingService/Null.php" md5sum="c830c9993bfa2e7367f52dacb2857ef5"/>
<file role="php" name="src/UNL/Services/CourseApproval/CachingService/CacheLite.php" md5sum="45e0a57bdcdb743c006c9a9b754260d4"/>
<file role="php" name="src/UNL/Services/CourseApproval/CachingService.php" md5sum="9ff7d4e53553663a7b12f8f89da48fd5"/>
<file role="php" name="src/UNL/Services/CourseApproval.php" md5sum="9aa460c3b7225ab2987762fd526a36c7"/>
<file role="doc" name="docs/examples/Courses_by_Subject_Code.php" md5sum="7c2172b207b574d0fa0ed31013993fd3"/>
</dir>
</contents>
<dependencies>
<required>
<php>
<min>5.2.0</min>
</php>
<pearinstaller>
<min>2.0.0a1</min>
</pearinstaller>
</required>
</dependencies>
<phprelease/>
</package>
<?php
chdir(dirname(dirname(dirname(__FILE__))).'/src');
require_once 'UNL/Autoload.php';
UNL_Templates::$options['version'] = 3;
$page = UNL_Templates::factory('Fixed');
$page->addStyleDeclaration('
.course .subjectCode {background-color:#E7F0F9;margin-bottom:-1px;color:#818489;display:block;float:left;min-width:85px;text-align:center;}
.course .number {font-size:2.5em;padding:7px 0px;margin:0 5px 0 0;background-color:#E7F0F9;display:block;clear:left;float:left;font-weight:bold;min-width:85px;text-align:center;}
.course .title {font-size:1.5em; display:block; border-bottom:1px solid #C8C8C8;font-style:normal;font-weight:bold;margin-left:95px;}
.course .crosslistings {margin:4px 0 4px 95px;display:block;}
.course .crosslistings .crosslisting {font-size:1em;color:#C60203;background:none;}
.course .prereqs,
.course .notes,
.course .description {margin:4px 0;float:left;clear:left;width:450px;}
.course .prereqs {color:#0F900A;font-weight:bold;}
.course .notes {font-style:italic;}
.course .description {border-left:3px solid #C8C8C8;padding-left:5px;}
.course .details {width:220px;border-collapse:collapse;right:0px;float:right;}
.course .details tr.alt td {border:1px solid #C9E2F6;border-right:none;border-left:none;background-color:#E3F0FF;}
.course .details td {}
.course .details .label {font-weight:bold;}
.course .details .value {text-align:right;}
dd {margin:0 0 3em 0;padding-left:0 !important;position:relative;overflow:hidden;}
dt {padding:3em 0 0 0 !important;}
.course {clear:both;}
');
$page->titlegraphic = '<h1>Undergraduate Bulletin</h1>
<h2>Your Academic Guide</h2>';
$page->doctitle = '<title>UNL | Undergraduate Bulletin</title>';
$page->breadcrumbs = '<ul>
<li><a href="http://www.unl.edu/">UNL</a></li>
<li>Undergraduate Bulletin</li></ul>';
$page->navlinks = '
<ul>
<li><a href="#">Academic Policies</a></li>
<li><a href="#">Achievement-Centered Education (ACE)</a></li>
<li><a href="#">Academic Colleges</a></li>
<li><a href="#">Areas of Study</a></li>
<li><a href="#">Courses</a></li>
</ul>
';
$page->leftRandomPromo = '';
$page->maincontentarea = '';
if (!isset($_GET['subject'])) {
echo 'Enter a subject code';
exit();
}
$subject = new UNL_Services_CourseApproval_SubjectArea($_GET['subject']);
$page->maincontentarea .= '<h1>There are '.count($subject->courses).' courses for '.htmlentities($subject).'</h1>';
$page->maincontentarea .= implode(', ', $subject->groups);
$page->maincontentarea .= '<dl>';
foreach ($subject->courses as $course) {
$listings = '';
$crosslistings = '';
$groups = '';
foreach ($course->codes as $listing) {
if ($listing->subjectArea == $subject->subject) {
if ($listing->hasGroups()) {
$groups = implode(', ', $listing->groups);
}
$listings .= $listing->courseNumber.'/';
} else {
$crosslistings .= '<span class="crosslisting">'.$listing->subjectArea.' '.$listing->courseNumber.'</span>, ';
}
}
$listings = trim($listings, '/');
$crosslistings = trim($crosslistings, ', ');
$credits = '';
if (isset($course->credits['Single Value'])) {
$credits = $course->credits['Single Value'];
}
$format = '';
foreach ($course->activities as $type=>$activity) {
switch ($type) {
case 'lec':
$format .= 'Lecture';
break;
case 'lab':
$format .= 'Lab';
break;
case 'quz':
$format .= 'Quiz';
break;
case 'rct':
$format .= 'Recitation';
break;
case 'stu':
$format .= 'Studio';
break;
case 'fld':
$format .= 'Field';
break;
case 'ind':
$format .= 'Independent Study';
break;
case 'psi':
$format .= 'Personalized System of Instruction';
break;
default:
throw new Exception('Unknown activity type! '.$type);
break;
}
$format .= ' '.$activity->hours.', ';
}
$format = trim($format, ', ');
$page->maincontentarea .= "
<dt class='course'>
<span class='subjectCode'>".htmlentities($subject->subject)."</span>
<span class='number'>$listings</span>
<span class='title'>".htmlentities($course->title)."</span>";
if (!empty($crosslistings)) {
$page->maincontentarea .= '<span class="crosslistings">Crosslisted as '.$crosslistings.'</span>';
}
$page->maincontentarea .= "</dt>
<dd class='course'>";
$page->maincontentarea .= '<table class="zentable cool details">';
$page->maincontentarea .= '<tr class="credits">
<td class="label">Credit Hours:</td>
<td class="value">'.$credits.'</td>
</tr>';
if (!empty($format)) {
$page->maincontentarea .= '<tr class="format">
<td class="label">Course Format:</td>
<td class="value">'.$format.'</td>
</tr>';
}
if (count($course->campuses) == 1
&& $course->campuses[0] != 'UNL') {
$page->maincontentarea .= '<tr class="campus">
<td class="label">Campus:</td>
<td class="value">'.implode(', ', $course->campuses).'</td>
</tr>';
}
// $page->maincontentarea .= '<tr class="termsOffered alt">
// <td class="label">Terms Offered:</td>
// <td class="value">'.implode(', ', $course->termsOffered).'</td>
// </tr>';
$page->maincontentarea .= '<tr class="deliveryMethods">
<td class="label">Course Delivery:</td>
<td class="value">'.implode(', ', $course->deliveryMethods).'</td>
</tr>';
$ace = '';
if (!empty($course->aceOutcomes)) {
$ace = implode(', ', $course->aceOutcomes);
$page->maincontentarea .= '<tr class="aceOutcomes">
<td class="label">ACE Outcomes:</td>
<td class="value">'.$ace.'</td>
</tr>';
}
if (!empty($groups)) {
$page->maincontentarea .= '<tr class="groups">
<td class="label">Groups:</td>
<td class="value">'.$groups.'</td>
</tr>';
}
$page->maincontentarea .= '</table>';
if (!empty($course->prerequisite)) {
$page->maincontentarea .= "<p class='prereqs'>Prereqs: ".htmlentities($course->prerequisite)."</p>";
}
if (!empty($course->notes)) {
$page->maincontentarea .= "<p class='notes'>".htmlentities($course->notes)."</p>";
}
$page->maincontentarea .= "<p class='description'>".htmlentities($course->description)."</p>";
$page->maincontentarea .= "</dd>";
}
$page->maincontentarea .= '</dl>';
echo $page;
\ No newline at end of file
...@@ -836,7 +836,7 @@ class Savvy ...@@ -836,7 +836,7 @@ class Savvy
} }
} }
protected function fetch($mixed, $template = null) public function fetch($mixed, $template = null)
{ {
if ($template) { if ($template) {
$this->template = $template; $this->template = $template;
......
<?php
class UNL_Services_CourseApproval
{
/**
* The caching service used.
*
* @var UNL_Services_CourseApproval_CachingService
*/
protected static $_cache;
/**
* The XCRI service used.
*
* @var UNL_Services_CourseApproval_XCRIService
*/
protected static $_xcri;
/**
* Get the static caching service
*
* @return UNL_Services_CourseApproval_CachingService
*/
public static function getCachingService()
{
if (!isset(self::$_cache)) {
try {
self::setCachingService(new UNL_Services_CourseApproval_CachingService_CacheLite());
} catch(Exception $e) {
self::setCachingService(new UNL_Services_CourseApproval_CachingService_Null());
}
}
return self::$_cache;
}
/**
* Set the static caching service
*
* @param UNL_Services_CourseApproval_CachingService $service The caching service to use
*
* @return UNL_Services_CourseApproval_CachingService
*/
public static function setCachingService(UNL_Services_CourseApproval_CachingService $service)
{
self::$_cache = $service;
return self::$_cache;
}
/**
* Gets the XCRI service we're subscribed to.
*
* @return UNL_Services_CourseApproval_XCRIService
*/
public static function getXCRIService()
{
if (!isset(self::$_xcri)) {
self::setXCRIService(new UNL_Services_CourseApproval_XCRIService_creq());
}
return self::$_xcri;
}
/**
* Set the static XCRI service
*
* @param UNL_Services_CourseApproval_XCRIService $xcri The XCRI service object
*
* @return UNL_Services_CourseApproval_XCRIService
*/
public static function setXCRIService(UNL_Services_CourseApproval_XCRIService $xcri)
{
self::$_xcri = $xcri;
return self::$_xcri;
}
}
<?php
interface UNL_Services_CourseApproval_CachingService
{
function save($key, $data);
function get($key);
}
<?php
class UNL_Services_CourseApproval_CachingService_CacheLite implements UNL_Services_CourseApproval_CachingService
{
protected $cache;
function __construct()
{
@include_once 'Cache/Lite.php';
if (!class_exists('Cache_Lite')) {
throw new Exception('Unable to include Cache_Lite, is it installed?');
}
$options = array('lifeTime'=>604800); //one week lifetime
$this->cache = new Cache_Lite();
}
function save($key, $data)
{
return $this->cache->save($data, $key, 'ugbulletin');
}
function get($key)
{
if ($data = $this->cache->get($key, 'ugbulletin')) {
return $data;
}
return false;
}
}
<?php
class UNL_Services_CourseApproval_CachingService_Null implements UNL_Services_CourseApproval_CachingService
{
function get($key)
{
// Expired cache always.
return false;
}
function save($key, $data)
{
// Make it appear as though it was saved.
return true;
}
}
<?php
class UNL_Services_CourseApproval_College
{
public $areas_of_study;
}
<?php
class UNL_Services_CourseApproval_Course
{
/**
* The internal object
*
* @var SimpleXMLElement
*/
protected $_internal;
/**
* Collection of course codes
*
* @var UNL_Services_CourseApproval_Course_Codes
*/
public $codes;
protected $_getMap = array('credits' => 'getCredits',
'dfRemoval' => 'getDFRemoval',
'campuses' => 'getCampuses',
'deliveryMethods' => 'getDeliveryMethods',
'termsOffered' => 'getTermsOffered',
'activities' => 'getActivities',
'aceOutcomes' => 'getACEOutcomes',
);
protected $ns_prefix = '';
function __construct(SimpleXMLElement $xml)
{
$this->_internal = $xml;
//Fetch all namespaces
$namespaces = $this->_internal->getNamespaces(true);
if (isset($namespaces[''])
&& $namespaces[''] == 'http://courseapproval.unl.edu/courses') {
$this->_internal->registerXPathNamespace('default', $namespaces['']);
$this->ns_prefix = 'default:';
//Register the rest with their prefixes
foreach ($namespaces as $prefix => $ns) {
$this->_internal->registerXPathNamespace($prefix, $ns);
}
}
$this->codes = new UNL_Services_CourseApproval_Course_Codes($this->_internal->courseCodes->children());
}
function __get($var)
{
if (array_key_exists($var, $this->_getMap)) {
return $this->{$this->_getMap[$var]}();
}
if (isset($this->_internal->$var)
&& count($this->_internal->$var->children())) {
if (isset($this->_internal->$var->div)) {
return str_replace(' xmlns="http://www.w3.org/1999/xhtml"',
'',
html_entity_decode($this->_internal->$var->div->asXML()));
}
}
return (string)$this->_internal->$var;
}
function __isset($var)
{
$elements = $this->_internal->xpath($this->ns_prefix.$var);
if (count($elements)) {
return true;
}
return false;
}
function getCampuses()
{
return $this->getArray('campuses');
}
function getTermsOffered()
{
return $this->getArray('termsOffered');
}
function getDeliveryMethods()
{
return $this->getArray('deliveryMethods');
}
function getActivities()
{
return new UNL_Services_CourseApproval_Course_Activities($this->_internal->activities->children());
}
function getACEOutcomes()
{
return $this->getArray('aceOutcomes');
}
function getArray($var)
{
$results = array();
foreach ($this->_internal->$var->children() as $el) {
$results[] = (string)$el;
}
return $results;
}
/**
* Gets the types of credits offered for this course.
*
* @return UNL_Services_CourseApproval_Course_Credits
*/
function getCredits()
{
return new UNL_Services_CourseApproval_Course_Credits($this->_internal->credits->children());
}
/**
* Checks whether this course can remove a previous grade of D or F for the same course.
*
* @return bool
*/
function getDFRemoval()
{
if ($this->_internal->dfRemoval == 'true') {
return true;
}
return false;
}
/**
* Verifies that the course number is in the correct format.
*
* @param $number The course number eg 201H, 4004I
* @param $parts Array of matched parts
*
* @return bool
*/
public static function validCourseNumber($number, &$parts = null)
{
$matches = array();
if (preg_match('/^([\d]?[\d]{2,3})([A-Z])?$/i', $number, $matches)) {
$parts['courseNumber'] = $matches[1];
if (isset($matches[2])) {
$parts['courseLetter'] = $matches[2];
}
return true;
}
return false;
}
public static function courseNumberFromCourseCode(SimpleXMLElement $xml)
{
$number = (string)$xml->courseNumber;
if (isset($xml->courseLetter)) {
$number .= (string)$xml->courseLetter;
}
return $number;
}
public static function getListingGroups(SimpleXMLElement $xml)
{
$groups = array();
if (isset($xml->courseGroup)) {
foreach ($xml->courseGroup as $group) {
$groups[] = $group;
}
}
return $groups;
}
function getHomeListing()
{
$home_listing = $this->_internal->xpath($this->ns_prefix.'courseCodes/'.$this->ns_prefix.'courseCode[@type="home listing"]');
if ($home_listing === false
|| count($home_listing) < 1) {
return false;
}
$number = UNL_Services_CourseApproval_Course::courseNumberFromCourseCode($home_listing[0]);
return new UNL_Services_CourseApproval_Listing($home_listing[0]->subject,
$number,
UNL_Services_CourseApproval_Course::getListingGroups($home_listing[0]));
}
/**
* Search for subsequent courses
*
* (reverse prereqs)
*
* @param UNL_Services_CourseApproval_Search $search_driver
*
* @return UNL_Services_CourseApproval_Courses
*/
function getSubsequentCourses($search_driver = null)
{
$searcher = new UNL_Services_CourseApproval_Search($search_driver);
$query = $this->getHomeListing()->subjectArea.' '.$this->getHomeListing()->courseNumber;
return $searcher->byPrerequisite($query);
}
function asXML()
{
return $this->_internal->asXML();
}
public static function getPossibleActivities()
{
//Value=>Description
return array('lec' => 'Lecture',
'lab' => 'Lab',
'stu' => 'Studio',
'fld' => 'Field',
'quz' => 'Quiz',
'rct' => 'Recitation',
'ind' => 'Independent Study',
'psi' => 'Personalized System of Instruction');
}
public static function getPossibleAceOutcomes()
{
//Value=>Description
return array(1 => 'ACE 1',
2 => 'ACE 2',
3 => 'ACE 3',
4 => 'ACE 4',
5 => 'ACE 5',
6 => 'ACE 6',
7 => 'ACE 7',
8 => 'ACE 8',
9 => 'ACE 9',
10 => 'ACE 10');
}
public static function getPossibleCampuses()
{
//Value=>Description
return array('UNL' => 'University of Nebraska Lincoln',
'UNO' => 'University of Nebraska Omaha',
'UNMC' => 'University of Nebraska Medical University',
'UNK' => 'University of Nebraska Kearney');
}
public static function getPossibleDeliveryMethods()
{
//Value=>Description
return array('Classroom' => 'Classroom',
'Web' => 'Online',
'Correspondence' => 'Correspondence');
}
public static function getPossibleTermsOffered()
{
//Value=>Description
return array('Fall' => 'Fall',
'Spring' => 'Spring',
'Summer' => 'Summer');
}
}
<?php
class UNL_Services_CourseApproval_Course_Activities implements Countable, Iterator
{
protected $_xmlActivities;
protected $_currentActivity = 0;
function __construct(SimpleXMLElement $xml)
{
$this->_xmlActivities = $xml;
}
function current()
{
return $this->_xmlActivities[$this->_currentActivity];
}
function next()
{
++$this->_currentActivity;
}
function rewind()
{
$this->_currentActivity = 0;
}
function valid()
{
if ($this->_currentActivity >= $this->count()) {
return false;
}
return true;
}
function key()
{
return (string)$this->current()->type;
}
function count()
{
return count($this->_xmlActivities);
}
public static function getFullDescription($activity)
{
$activities = UNL_Services_CourseApproval_Course::getPossibleActivities();
if (!isset($activities[$activity])) {
throw new Exception('Unknown activity type! '.$activity);
}
return $activities[$activity];
}
}
<?php
/**
* Collection of course codes for this course
*
* @author Brett Bieber <brett.bieber@gmail.com>
*/
class UNL_Services_CourseApproval_Course_Codes extends ArrayIterator
{
/**
* Array of results, usually from an xpath query
*
* @param array $courseCodes
*/
function __construct($courseCodes)
{
$codes = array();
foreach ($courseCodes as $code) {
$codes[] = $code;
}
parent::__construct($codes);
}
/**
* Get the listing
*
* @return UNL_Services_CourseApproval_Listing
*/
function current()
{
$number = UNL_Services_CourseApproval_Course::courseNumberFromCourseCode(parent::current());
return new UNL_Services_CourseApproval_Listing(parent::current()->subject,
$number,
UNL_Services_CourseApproval_Course::getListingGroups(parent::current()));
}
/**
* Get the course number
*
* @return string course number
*/
function key()
{
return $this->current()->courseNumber;
}
}
<?php
class UNL_Services_CourseApproval_Course_Credits implements Countable, ArrayAccess
{
protected $_xmlCredits;
protected $_currentCredit = 0;
function __construct(SimpleXMLElement $xml)
{
$this->_xmlCredits = $xml;
}
function current()
{
return $this->_xmlCredits[$this->_currentCredit];
}
function next()
{
++$this->_currentCredit;
}
function rewind()
{
$this->_currentCredit = 0;
}
function valid()
{
if ($this->_currentCredit >= $this->count()) {
return false;
}
return true;
}
function count()
{
return count($this->_xmlCredits);
}
function key()
{
$credit = $this->current();
return $credit['creditType'];
}
function offsetExists($type)
{
foreach ($this->_xmlCredits as $credit) {
if ($credit['type'] == $type) {
return true;
}
}
return false;
}
function offsetGet($type)
{
foreach ($this->_xmlCredits as $credit) {
if ($credit['type'] == $type) {
return (int)$credit;
}
}
}
function offsetSet($type, $var)
{
throw new Exception('Not available.');
}
function offsetUnset($type)
{
throw new Exception('Not available.');
}
}
<?php
class UNL_Services_CourseApproval_Courses extends ArrayIterator
{
function __construct($courses)
{
parent::__construct($courses);
}
/**
* Get the current course
*
* @return UNL_Services_CourseApproval_Course
*/
function current()
{
return new UNL_Services_CourseApproval_Course(parent::current());
}
}
\ No newline at end of file
<?php
class UNL_Services_CourseApproval_Filter_ExcludeGraduateCourses extends FilterIterator
{
function accept()
{
$course = $this->getInnerIterator()->current();
foreach ($course->codes as $listing) {
if ($listing->courseNumber < 500) {
return true;
}
}
return false;
}
}
\ No newline at end of file
<?php
class UNL_Services_CourseApproval_Filter_ExcludeUndergraduateCourses extends FilterIterator
{
function accept()
{
$course = $this->getInnerIterator()->current();
foreach ($course->codes as $listing) {
if ($listing->courseNumber >= 500) {
return true;
}
}
return false;
}
}
\ No newline at end of file
<?php
class UNL_Services_CourseApproval_Listing
{
/**
* Internal subject area object
*
* @var UNL_Services_CourseApproval_SubjectArea
*/
protected $_subjectArea;
/**
* The subject area for this listing eg ACCT
*
* @var string
*/
public $subjectArea;
/**
* The course number eg 201
*
* @var string|int
*/
public $courseNumber;
public $groups = array();
function __construct($subject, $number, $groups = array())
{
$this->subjectArea = $subject;
$this->courseNumber = $number;
$this->groups = $groups;
}
function __get($var)
{
if ($var == 'course') {
if (!isset($this->_subjectArea)) {
$this->_subjectArea = new UNL_Services_CourseApproval_SubjectArea($this->subjectArea);
}
return $this->_subjectArea->courses[$this->courseNumber];
}
// Delegate to the course
return $this->course->$var;
}
function __isset($var)
{
// Delegate to the course
return isset($this->course->$var);
}
function hasGroups()
{
return count($this->groups)? true : false;
}
}
<?php
class UNL_Services_CourseApproval_Search extends UNL_Services_CourseApproval_SearchInterface
{
/**
* The driver that performs the searches
* @var UNL_Services_CourseApproval_SearchInterface
*/
public $driver;
function __construct(UNL_Services_CourseApproval_SearchInterface $driver = null)
{
if (!isset($driver)) {
$this->driver = new UNL_Services_CourseApproval_SearchInterface_XPath();
} else {
$this->driver = $driver;
}
}
/**
* Combine two queries into one which will return the intersect
*
* @return string
*/
function intersectQuery($query1, $query2)
{
return $this->driver->intersectQuery($query1, $query2);
}
function aceQuery($ace)
{
return $this->driver->aceQuery($ace);
}
function aceAndNumberPrefixQuery($number)
{
return $this->driver->aceAndNumberPrefixQuery($number);
}
function subjectAndNumberQuery($subject, $number, $letter = null)
{
return $this->driver->subjectAndNumberQuery($subject, $number, $letter);
}
function subjectAndNumberPrefixQuery($subject, $number)
{
return $this->driver->subjectAndNumberPrefixQuery($subject, $number);
}
function subjectAndNumberSuffixQuery($subject, $number)
{
return $this->driver->subjectAndNumberSuffixQuery($subject, $number);
}
function numberPrefixQuery($number)
{
return $this->driver->numberPrefixQuery($number);
}
function numberSuffixQuery($number)
{
return $this->driver->numberSuffixQuery($number);
}
function honorsQuery()
{
return $this->driver->honorsQuery();
}
function titleQuery($title)
{
return $this->driver->titleQuery($title);
}
function subjectAreaQuery($subject)
{
return $this->driver->subjectAreaQuery($subject);
}
function getQueryResult($query, $offset = 0, $limit = -1)
{
return $this->driver->getQueryResult($query, $offset, $limit);
}
function numberQuery($number, $letter = null)
{
return $this->driver->numberQuery($number, $letter);
}
function creditQuery($credits)
{
return $this->driver->creditQuery($credits);
}
function prerequisiteQuery($prereq)
{
return $this->driver->prerequisiteQuery($prereq);
}
function undergraduateQuery()
{
return $this->driver->undergraduateQuery();
}
function graduateQuery()
{
return $this->driver->graduateQuery();
}
}
\ No newline at end of file
<?php
class UNL_Services_CourseApproval_Search_Results extends UNL_Services_CourseApproval_Courses implements Countable
{
protected $total;
function __construct($results, $offset = 0, $limit = -1)
{
$this->total = count($results);
if (
$limit > 0
&&
$this->total < $offset + $limit
) {
$results = array_slice($results, $offset, $limit);
}
parent::__construct($results);
}
function count()
{
return $this->total;
}
}
\ No newline at end of file
<?php
abstract class UNL_Services_CourseApproval_SearchInterface
{
abstract function aceQuery($ace);
abstract function subjectAndNumberQuery($subject, $number, $letter = null);
abstract function subjectAndNumberPrefixQuery($subject, $number);
abstract function subjectAndNumberSuffixQuery($subject, $number);
abstract function numberPrefixQuery($number);
abstract function numberSuffixQuery($number);
abstract function honorsQuery();
abstract function titleQuery($title);
abstract function subjectAreaQuery($subject);
abstract function numberQuery($number, $letter = null);
abstract function creditQuery($credits);
abstract function prerequisiteQuery($prereq);
abstract function intersectQuery($query1, $query2);
abstract function graduateQuery();
abstract function undergraduateQuery();
function filterQuery($query)
{
return trim($query);
}
public function byTitle($query, $offset = 0, $limit = -1)
{
$query = $this->titleQuery($this->filterQuery($query));
return $this->getQueryResult($query, $offset, $limit);
}
public function byNumber($query, $offset = 0, $limit = -1)
{
$query = $this->numberQuery($this->filterQuery($query));
return $this->getQueryResult($query, $offset, $limit);
}
public function bySubject($query, $offset = 0, $limit = -1)
{
$query = $this->subjectAreaQuery($this->filterQuery($query));
return $this->getQueryResult($query, $offset, $limit);
}
public function byPrerequisite($query, $offset = 0, $limit = -1)
{
$query = $this->prerequisiteQuery($query);
return $this->getQueryResult($query, $offset, $limit);
}
public function graduateCourses($offset = 0, $limit = -1)
{
$query = $this->graduateQuery();
return $this->getQueryResult($query, $offset, $limit);
}
public function undergraduateCourses($offset = 0, $limit = -1)
{
$query = $this->undergraduateQuery();
return $this->getQueryResult($query, $offset, $limit);
}
public function byAny($query, $offset = 0, $limit = -1)
{
$query = $this->filterQuery($query);
switch (true) {
case preg_match('/([\d]+)\scredits?/i', $query, $match):
// Credit search
$query = $this->creditQuery($match[1]);
break;
case preg_match('/^ace\s*:?\s*([0-9])(X+|\*+)/i', $query, $matches):
// ACE course, and number range, eg: ACE 2XX
$query = $this->aceAndNumberPrefixQuery($matches[1]);
break;
case preg_match('/^ace\s*:?\s*(10|[1-9])$/i', $query, $match):
// ACE outcome number
$query = $this->aceQuery($match[1]);
break;
case preg_match('/^([A-Z]{3,4})\s+([0-9])(X+|\*+)?$/i', $query, $matches):
// Course subject and number range, eg: MRKT 3XX
$subject = strtoupper($matches[1]);
$query = $this->subjectAndNumberPrefixQuery($subject, $matches[2]);
break;
case preg_match('/^([A-Z]{3,4})\s+(X+|\*+)([0-9]+)$/i', $query, $matches):
// Course subject and number suffix, eg: MUDC *41
$subject = strtoupper($matches[1]);
$query = $this->subjectAndNumberSuffixQuery($subject, $matches[3]);
break;
case preg_match('/^([A-Z]{3,4})\s+([\d]?[\d]{2,3})([A-Z])?:?.*$/i', $query, $matches):
// Course subject code and number
$subject = strtoupper($matches[1]);
$letter = null;
if (isset($matches[3])) {
$letter = $matches[3];
}
$query = $this->subjectAndNumberQuery($subject, $matches[2], $letter);
break;
case preg_match('/^([0-9])(X+|\*+)?$/i', $query, $match):
// Course number range
$query = $this->numberPrefixQuery($match[1]);
break;
case preg_match('/^(X+|\*+)([0-9]+)?$/i', $query, $match):
// Course number suffix
$query = $this->numberSuffixQuery($match[1]);
break;
case preg_match('/^([\d]?[\d]{2,3})([A-Z])?(\*+)?$/i', $query, $matches):
$letter = null;
if (isset($matches[2])) {
$letter = $matches[2];
}
$query = $this->numberQuery($matches[1], $letter);
break;
case preg_match('/^([A-Z]{3,4})(\s*:\s*.*)?(\s[Xx]+|\s\*+)?$/', $query, $matches):
// Subject code search
$query = $this->subjectAreaQuery($matches[1]);
break;
case preg_match('/^honors$/i', $query):
$query = $this->honorsQuery();
break;
default:
// Do a title text search
$query = $this->titleQuery($query);
}
return $this->getQueryResult($query, $offset, $limit);
}
abstract function getQueryResult($query, $offset = 0, $limit = -1);
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment