Ejemplo n.º 1
0
function SearchByClass($criteria, $sortOrder)
{
    assert(isValidSortOrder($sortOrder));
    assert(isset($criteria['courseAbbrev']));
    assert(isset($criteria['courseNum']));
    $subject = $criteria['courseAbbrev'];
    $number = $criteria['courseNum'];
    assert(isValidCourseNumber($subject, $number));
    $dbHandle = GetCachedDBConnection();
    $courseid = GetCourseId($subject, $number);
    if (is_null($courseid)) {
        return null;
    }
    if ($sortOrder == "date") {
        $profids = $dbHandle->SelectAll("SELECT DISTINCT c.profid, \n       UNIX_TIMESTAMP(max(o.created)) AS lastrating FROM or_comment c, \n       or_comment a, or_objects o, or_professor p WHERE \n       c.courseid='{$courseid}' AND c.profid = p.profid AND p.status NOT IN \n       " . PROFESSOR_INVISIBLE_STATES . " AND c.status NOT IN \n       " . COMMENT_INVISIBLE_STATES . " AND a.status NOT IN \n       " . COMMENT_INVISIBLE_STATES . " AND a.profid=p.profid AND \n       a.objectid=o.objectid GROUP BY a.profid ORDER BY lastrating desc, \n       p.lname, p.fname");
    } else {
        if ($sortOrder == "rating") {
            $profids = $dbHandle->SelectAll("SELECT DISTINCT c.profid, \n       ifnull(round(avg(c.ques3), " . EVAL_ROUND_DIGITS . "), -1)\n       as coursescore, ifnull(round(avg(a.ques3), \n       " . EVAL_ROUND_DIGITS . "), -1) as score FROM or_comment c, \n       or_professor p, or_comment a WHERE c.courseid='{$courseid}' and \n       c.profid=p.profid and a.profid=p.profid and p.status NOT \n       IN " . PROFESSOR_INVISIBLE_STATES . " and c.status NOT IN \n       " . COMMENT_INVISIBLE_STATES . " and a.status NOT IN \n       " . COMMENT_INVISIBLE_STATES . " GROUP BY c.profid ORDER BY \n       score desc, p.lname, p.fname");
        } else {
            $profids = $dbHandle->SelectAll("SELECT DISTINCT c.profid \n       FROM or_comment c, or_professor p WHERE courseid='{$courseid}' and \n       c.profid=p.profid AND p.status NOT IN \n       " . PROFESSOR_INVISIBLE_STATES . " AND c.status NOT IN \n       " . COMMENT_INVISIBLE_STATES . " ORDER BY p.lname, p.fname");
        }
    }
    return $profids;
}
Ejemplo n.º 2
0
function GetCourseID($abv, $num)
{
    assert(isValidCourseNumber($abv, $num));
    $dbh = GetCachedDBConnection();
    $cid = $dbh->SelectRow("SELECT courseid FROM or_course WHERE abbrev='{$abv}'\n    AND number='{$num}'");
    // if the course doesn't exist, this will be null
    // so we're still good
    return $cid['courseid'];
}
Ejemplo n.º 3
0
function CreateCourse($abbrev, $number, $type, $title)
{
    assert(isValidCourseNumber($abbrev, $number));
    $dbh = GetCachedDBConnection();
    $transactionID = $dbh->BeginTransaction('course-new');
    assert(!is_null($transactionID));
    $deptid = $dbh->SelectRow("SELECT deptid FROM or_abbrev_map WHERE \n    abbrev='{$abbrev}'");
    assert(!is_null($deptid['deptid']) && $deptid['deptid'] > 0);
    $did = $deptid['deptid'];
    $oid = $dbh->GetObjectID();
    $sqlCourseTitle = $dbh->Quote($title);
    $rows = $dbh->DoOp("INSERT INTO or_course (deptid, abbrev, number, type, \n    title, objectid) VALUES ('{$did}', '{$abbrev}', '{$number}', '{$type}', \n    '{$sqlCourseTitle}', '{$oid}')");
    assert($rows == 1);
    $courseid = $dbh->SelectRow("SELECT courseid FROM or_course WHERE \n    objectid='{$oid}'");
    $transactionEnd = $dbh->EndTransaction();
    assert($transactionEnd);
    return $courseid['courseid'];
}