Example #1
0
 static function getElectives($program, $elective_type, $elective_group, $exclude = [])
 {
     $results = array();
     foreach (explode("|", $elective_group) as $group) {
         $q = new Query("electives");
         $q->select("course_code");
         $q->where("program_id=?\n\t\t\t\t\t\t\tAND elective_type=?\n\t\t\t\t\t\t\tAND note=?\n\t\t\t\t\t\t\tAND course_code NOT IN " . Query::valuelistsql($exclude), array_merge([$program, $elective_type, $group], $exclude));
         $results = array_merge($results, $q->executeFetchAll());
     }
     return $results;
 }
Example #2
0
    /** Return unsatisfied prerequsites.
     * 
     * Note: code is an sql expression.
     */
    static function query_prerequisites($code, $completed, $taking = [], $values = [])
    {
        global $db;
        // Convert all the courses to strings.
        foreach ($completed as &$c) {
            if (is_a($c, 'Course')) {
                $c = $c->getcode();
            }
        }
        foreach ($taking as &$c) {
            if (is_a($c, 'Course')) {
                $c = $c->getcode();
            }
        }
        // Warning: Dragons Ahead!  This is a complex query. With a lot
        // of parts.
        ///// Inner query.
        // This inner query counts how many courses in $completed are
        // in the elgible group and not in the excluded group.
        $haspreq = new Query('coursegroups elg');
        $haspreq->select('count(elg.id)');
        $haspreq->where('elg.id = prerequisites.eligible');
        $haspreq->join('coursegroup_courses elgc', 'elgc.id = elg.id');
        // Where the course is in the completed group.
        // Or it can be taken concurrently and it is in the taking group.
        $haspreq->where('(
				elgc.course_code IN ' . Query::valuelistsql($completed) . '
				OR (
					elgc.course_code IN ' . Query::valuelistsql($taking) . '
					AND elgc.concurrent
				)
			)', array_merge($completed, $taking));
        // And it is not one of the courses that is excluded.
        $haspreq->where('NOT EXISTS (
				SELECT course_code
				FROM coursegroup_courses
				WHERE coursegroup_courses.id = prerequisites.excluded
				AND   coursegroup_courses.course_code = elgc.course_code
			)', []);
        ///// Outer Query
        // This query selects prerequsites where the number of credits
        // earned is less then the required credits.
        $q = new Query('prerequisites');
        $q->select('course_code');
        $q->select('eligible');
        $q->select('excluded');
        $q->where('course_code = ' . $code, $values);
        $q->where('(' . $haspreq->sql() . ') < credits', $haspreq->values());
        return $q;
    }
    $programQuery = new Query("program_elements e");
    $programQuery->select("course_code");
    $programQuery->select("credit_type");
    $programQuery->select("elective_note");
    $programQuery->select("term");
    $programQuery->select("element_year");
    $programQuery->where("program_id = ?\n\t\t\t\t\t\t\t  AND ((credit_type <> 0 AND e.element_year>={$completed_year} AND e.term >= {$term}) OR course_code NOT IN\n\t\t\t\t\t\t\t  " . Query::valuelistsql($completed) . ") AND \n\t\t\t\t\t\t\t  ((EXISTS \n\t\t\t\t\t\t\t   (SELECT * FROM course_offerings o\n\t\t\t\t\t\t\t   WHERE o.course_code = e.course_code\n\t\t\t\t\t\t\t   AND o.year={$year}\n\t\t\t\t\t\t\t   AND o.term={$term}))\n\t\t\t\t\t\t\t   OR\n\t\t\t\t\t\t\t   (credit_type <> 0))\n\t\t\t\t\t\t\t   ORDER BY element_year ASC, term ASC, credit_type DESC", array_merge([$_GET['program_select']], $completed));
    $pattern = $programQuery->executeFetchAll();
} else {
    $programQuery = new Query("program_elements e");
    $programQuery->select("course_code");
    $programQuery->select("credit_type");
    $programQuery->select("elective_note");
    $programQuery->select("term");
    $programQuery->select("element_year");
    $programQuery->where("program_id = ?\n\t\t                      AND ((credit_type <> 0) OR course_code NOT IN\n\t\t                      " . Query::valuelistsql($completed) . ") AND\n\t\t                      ((EXISTS\n\t\t                       (SELECT * FROM course_offerings o\n\t\t                       WHERE o.course_code = e.course_code\n\t\t                       AND o.year={$year}\n\t\t                       AND o.term={$term}))\n\t\t                       OR\n\t\t                       (credit_type <> 0))\n\t\t                       ORDER BY element_year ASC, term ASC, credit_type DESC", array_merge([$_GET['program_select']], $completed));
    $pattern = $programQuery->executeFetchAll();
    //See which of their electives they have fulfilled and remove them from consideration in the pattern
    foreach ($pattern as $key => $course) {
        if ($course[1] != '0') {
            foreach ($completed as $considering) {
                if (Elective::isElective($_GET['program_select'], $considering[0], $course[1], $course[2])) {
                    unset($pattern[$key]);
                }
            }
        }
    }
}
$found = 0;
$discarded = array();
$scheduling = array();