MDL-46678 gradereport_history: Move hardcoded sql from index.php to an api

Part of MDL-46191
This commit is contained in:
Ankit Agarwal 2014-08-08 13:43:39 +08:00
parent 1f2ebf779f
commit 9f3523767e
2 changed files with 28 additions and 12 deletions

View File

@ -156,4 +156,31 @@ class helper {
return array($sql, $params);
}
/**
* Get a list of graders.
*
* @param int $courseid Id of course for which we need to fetch graders.
*
* @return array list of graders.
*/
public static function get_graders($courseid) {
global $DB;
$ufields = get_all_user_name_fields(true, 'u');
$sql = "SELECT u.id, $ufields
FROM {user} u
JOIN {grade_grades_history} ggh ON ggh.usermodified = u.id
JOIN {grade_items} gi ON gi.id = ggh.itemid
WHERE gi.courseid = :courseid
GROUP BY u.id, $ufields
ORDER BY u.lastname ASC, u.firstname ASC";
$graders = $DB->get_records_sql($sql, array('courseid' => $courseid));
$return = array(0 => get_string('allgraders', 'gradereport_history'));
foreach ($graders as $grader) {
$return[$grader->id] = fullname($grader);
}
return $return;
}
}

View File

@ -52,19 +52,8 @@ $select = "itemtype != 'course' AND itemname != '' AND courseid = :courseid";
$itemids = $DB->get_records_select_menu('grade_items', $select, array('courseid' => $course->id), 'itemname ASC', 'id, itemname');
$itemids = array(0 => get_string('allgradeitems', 'gradereport_history')) + $itemids;
$sql = "SELECT u.id, ".$DB->sql_concat('u.lastname', "' '", 'u.firstname')."
FROM {user} u
JOIN {grade_grades_history} ggh ON ggh.usermodified = u.id
JOIN {grade_items} gi ON gi.id = ggh.itemid
WHERE gi.courseid = :courseid
GROUP BY u.id
ORDER BY u.lastname ASC, u.firstname ASC";
$graders = $DB->get_records_sql_menu($sql, array('courseid' => $course->id));
$graders = array(0 => get_string('allgraders', 'gradereport_history')) + $graders;
$output = $PAGE->get_renderer('gradereport_history');
$graders = \gradereport_history\helper::get_graders($course->id);
$params = array('course' => $course, 'itemids' => $itemids, 'graders' => $graders, 'userbutton' => null);
$mform = new \gradereport_history\filter_form(null, $params);
$filters = array();