Permalink
Browse files

Add support for searching for graduate and undergraduate courses

  • Loading branch information...
1 parent d2897fd commit f488bcf2e919f576c40b947a71a28344e68c8cd5 @saltybeagle saltybeagle committed Apr 15, 2012
@@ -74,4 +74,12 @@ function prerequisiteQuery($prereq)
{
return $this->driver->prerequisiteQuery($prereq);
}
+ function undergraduateQuery()
+ {
+ return $this->driver->undergraduateQuery();
+ }
+ function graduateQuery()
+ {
+ return $this->driver->graduateQuery();
+ }
}
@@ -12,6 +12,8 @@
abstract function creditQuery($credits);
abstract function prerequisiteQuery($prereq);
abstract function intersectQuery($query1, $query2);
+ abstract function graduateQuery();
+ abstract function undergraduateQuery();
function filterQuery($query)
{
@@ -46,6 +48,20 @@ public function byPrerequisite($query, $offset = 0, $limit = null)
return $this->getQueryResult($query, $offset, $limit);
}
+ public function graduateCourses($offset = 0, $limit = null)
+ {
+ $query = $this->graduateQuery();
+
+ return $this->getQueryResult($query, $offset, $limit);
+ }
+
+ public function undergraduateCourses($offset = 0, $limit = null)
+ {
+ $query = $this->undergraduateQuery();
+
+ return $this->getQueryResult($query, $offset, $limit);
+ }
+
public function byAny($query, $offset = 0, $limit = null)
{
$query = $this->filterQuery($query);
@@ -206,6 +206,26 @@ function numberQuery($number, $letter = null)
}
/**
+ * Construct a query for undergraduate courses
+ *
+ * @return string XPath query
+ */
+ function undergraduateQuery()
+ {
+ return "default:courseCodes/default:courseCode[default:courseNumber<'500']/parent::*/parent::*";
+ }
+
+ /**
+ * Construct a query for graduate courses
+ *
+ * @return string XPath query
+ */
+ function graduateQuery()
+ {
+ return "default:courseCodes/default:courseCode[default:courseNumber>='500']/parent::*/parent::*";
+ }
+
+ /**
* Construct part of an XPath query for matching a course letter
*
* @param string $letter Letter, e.g. H
View
@@ -30,6 +30,10 @@ $query = $search->intersectQuery($query1, $query2);
$courses = $search->driver->getQueryResult($query);
$test->assertEquals(1, count($courses), 'Intersection of two queries');
+$courses = $search->graduateCourses();
+$test->assertEquals(1, count($courses), 'One graduate course returned');
+
+
?>
===DONE===
--EXPECT--

0 comments on commit f488bcf

Please sign in to comment.