MDL-14967 DB upgrades. Not finished yet.

This commit is contained in:
nicolasconnault 2008-06-02 16:06:33 +00:00
parent 8a44548456
commit d24832f9af
32 changed files with 391 additions and 342 deletions

View File

@ -72,7 +72,7 @@ foreach ($letters as $boundary=>$letter) {
$data->$gradeboundaryname = $boundary;
$i++;
}
$data->override = record_exists('grade_letters', 'contextid', $contextid);
$data->override = $DB->record_exists('grade_letters', array('contextid' => $contextid));
$mform = new edit_letter_form(null, array('num'=>$num, 'admin'=>$admin));
$mform->set_data($data);
@ -82,7 +82,7 @@ if ($mform->is_cancelled()) {
} else if ($data = $mform->get_data()) {
if (!$admin and empty($data->override)) {
delete_records('grade_letters', 'contextid', $context->id);
$DB->delete_records('grade_letters', array('contextid' => $context->id));
redirect($returnurl);
}
@ -102,7 +102,7 @@ if ($mform->is_cancelled()) {
krsort($letters, SORT_NUMERIC);
$old_ids = array();
if ($records = get_records('grade_letters', 'contextid', $context->id, 'lowerboundary ASC', 'id')) {
if ($records = $DB->get_records('grade_letters', array('contextid' => $context->id), 'lowerboundary ASC', 'id')) {
$old_ids = array_keys($records);
}
@ -114,14 +114,14 @@ if ($mform->is_cancelled()) {
if ($old_id = array_pop($old_ids)) {
$record->id = $old_id;
update_record('grade_letters', $record);
$DB->update_record('grade_letters', $record);
} else {
insert_record('grade_letters', $record);
$DB->insert_record('grade_letters', $record);
}
}
foreach($old_ids as $old_id) {
delete_records('grade_letters', 'id', $old_id);
$DB->delete_records('grade_letters', array('id' => $old_id));
}
redirect($returnurl);

View File

@ -27,13 +27,13 @@ require_once $CFG->libdir.'/formslib.php';
class edit_letter_form extends moodleform {
function definition() {
public function definition() {
$mform =& $this->_form;
$num = $this->_customdata['num'];
$admin = $this->_customdata['admin'];
$mform->addElement('header', 'gradeletters', get_string('gradeletters', 'grades'));
// Only show "override site defaults" checkbox if editing the course grade letters
if (!$admin) {
$mform->addElement('checkbox', 'override', get_string('overridesitedefaultgradedisplaytype', 'grades'));
@ -59,7 +59,7 @@ class edit_letter_form extends moodleform {
$mform->setHelpButton($gradelettername, array('gradeletter', get_string('gradeletter', 'grades'), 'grade'));
}
$mform->setType($gradelettername, PARAM_TEXT);
if (!$admin) {
$mform->disabledIf($gradelettername, 'override', 'notchecked');
$mform->disabledIf($gradelettername, $gradeboundaryname, 'eq', -1);
@ -71,7 +71,7 @@ class edit_letter_form extends moodleform {
}
$mform->setDefault($gradeboundaryname, -1);
$mform->setType($gradeboundaryname, PARAM_INT);
if (!$admin) {
$mform->disabledIf($gradeboundaryname, 'override', 'notchecked');
}

View File

@ -30,7 +30,7 @@ require_once $CFG->libdir.'/gradelib.php';
$courseid = optional_param('id', SITEID, PARAM_INT);
$action = optional_param('action', '', PARAM_ALPHA);
if (!$course = get_record('course', 'id', $courseid)) {
if (!$course = $DB->get_record('course', array('id' => $courseid))) {
print_error('nocourseid');
}
require_login($course);

View File

@ -31,7 +31,7 @@ require_once $CFG->libdir.'/gradelib.php';
$courseid = required_param('id', PARAM_INT);
/// Make sure they can even access this course
if (!$course = get_record('course', 'id', $courseid)) {
if (!$course = $DB->get_record('course', array('id' => $courseid))) {
print_error('nocourseid');
}
require_login($course);
@ -47,7 +47,7 @@ $co_custom = grade_outcome::fetch_all_local($courseid);
$co_standard_used = array();
$co_standard_notused = array();
if ($courseused = get_records('grade_outcomes_courses', 'courseid', $courseid, '', 'outcomeid')) {
if ($courseused = $DB->get_records('grade_outcomes_courses', array('courseid' => $courseid), '', 'outcomeid')) {
$courseused = array_keys($courseused);
} else {
$courseused = array();
@ -56,7 +56,7 @@ if ($courseused = get_records('grade_outcomes_courses', 'courseid', $courseid, '
// fix wrong entries in outcomes_courses
foreach ($courseused as $oid) {
if (!array_key_exists($oid, $standardoutcomes) and !array_key_exists($oid, $co_custom)) {
delete_records('grade_outcomes_courses', 'outcomeid', $oid, 'courseid', $courseid);
$DB->delete_records('grade_outcomes_courses', array('outcomeid' => $oid, 'courseid' => $courseid));
}
}
@ -67,15 +67,16 @@ foreach($co_custom as $oid=>$outcome) {
$goc = new object();
$goc->courseid = $courseid;
$goc->outcomeid = $oid;
insert_record('grade_outcomes_courses', $goc);
$DB->insert_record('grade_outcomes_courses', $goc);
}
}
// now check all used standard outcomes are in outcomes_course too
$params = array($courseid);
$sql = "SELECT DISTINCT outcomeid
FROM {$CFG->prefix}grade_items
WHERE courseid=$courseid and outcomeid IS NOT NULL";
if ($realused = get_records_sql($sql)) {
FROM {grade_items}
WHERE courseid=? and outcomeid IS NOT NULL";
if ($realused = $DB->get_records_sql($sql, $params)) {
$realused = array_keys($realused);
foreach ($realused as $oid) {
if (array_key_exists($oid, $standardoutcomes)) {
@ -88,7 +89,7 @@ if ($realused = get_records_sql($sql)) {
$goc = new object();
$goc->courseid = $courseid;
$goc->outcomeid = $oid;
insert_record('grade_outcomes_courses', $goc);
$DB->insert_record('grade_outcomes_courses', $goc);
}
}
}
@ -116,7 +117,7 @@ if ($data = data_submitted()) {
$goc = new object();
$goc->courseid = $courseid;
$goc->outcomeid = $add;
insert_record('grade_outcomes_courses', $goc);
$DB->insert_record('grade_outcomes_courses', $goc);
}
} else if (!empty($data->remove) && !empty($data->removeoutcomes)) {
@ -126,7 +127,7 @@ if ($data = data_submitted()) {
if (!array_key_exists($remove, $co_standard_notused)) {
continue;
}
delete_records('grade_outcomes_courses', 'courseid', $courseid, 'outcomeid', $remove);
$DB->delete_records('grade_outcomes_courses', array('courseid' => $courseid, 'outcomeid' => $remove));
}
}
redirect('course.php?id='.$courseid); // we must redirect to get fresh data

View File

@ -36,12 +36,12 @@ $systemcontext = get_context_instance(CONTEXT_SYSTEM);
// a bit complex access control :-O
if ($id) {
/// editing existing outcome
if (!$outcome_rec = get_record('grade_outcomes', 'id', $id)) {
if (!$outcome_rec = $DB->get_record('grade_outcomes', array('id' => $id))) {
print_error('invalidoutcome');
}
if ($outcome_rec->courseid) {
$outcome_rec->standard = 0;
if (!$course = get_record('course', 'id', $outcome_rec->courseid)) {
if (!$course = $DB->get_record('course', array('id' => $outcome_rec->courseid))) {
print_error('invalidcourseid');
}
require_login($course);
@ -50,7 +50,7 @@ if ($id) {
$courseid = $course->id;
} else {
if ($courseid) {
if (!$course = get_record('course', 'id', $courseid)) {
if (!$course = $DB->get_record('course', array('id' => $courseid))) {
print_error('invalidcourseid');
}
}
@ -62,7 +62,7 @@ if ($id) {
} else if ($courseid){
/// adding new outcome from course
if (!$course = get_record('course', 'id', $courseid)) {
if (!$course = $DB->get_record('course', array('id' => $courseid))) {
print_error('nocourseid');
}
$outcome_rec = new object();

View File

@ -26,7 +26,7 @@
require_once $CFG->libdir.'/formslib.php';
class edit_outcome_form extends moodleform {
function definition() {
public function definition() {
global $CFG, $COURSE;
$mform =& $this->_form;

View File

@ -1,5 +1,5 @@
<?php // $Id$
// Exports selected outcomes in CSV format.
// Exports selected outcomes in CSV format.
require_once '../../../config.php';
require_once $CFG->dirroot.'/grade/lib.php';
@ -10,7 +10,7 @@ $action = optional_param('action', '', PARAM_ALPHA);
/// Make sure they can even access this course
if ($courseid) {
if (!$course = get_record('course', 'id', $courseid)) {
if (!$course = $DB->get_record('course', array('id' => $courseid))) {
print_error('nocourseid');
}
require_login($course);
@ -34,7 +34,7 @@ if (!confirm_sesskey()) {
$systemcontext = get_context_instance(CONTEXT_SYSTEM);
header("Content-Type: text/csv; charset=utf-8");
// TODO: make the filename more useful, include a date, a specific name, something...
// TODO: make the filename more useful, include a date, a specific name, something...
header('Content-Disposition: attachment; filename=outcomes.csv');
// sending header with clear names, to make 'what is what' as easy as possible to understand
@ -44,7 +44,7 @@ echo format_csv($header, ';', '"');
$outcomes = array();
if ( $courseid ) {
$outcomes = array_merge(grade_outcome::fetch_all_global(), grade_outcome::fetch_all_local($courseid));
} else {
} else {
$outcomes = grade_outcome::fetch_all_global();
}
@ -55,12 +55,12 @@ foreach($outcomes as $outcome) {
$line[] = $outcome->get_name();
$line[] = $outcome->get_shortname();
$line[] = $outcome->description;
$scale = $outcome->load_scale();
$line[] = $scale->get_name();
$line[] = $scale->compact_items();
$line[] = $scale->description;
echo format_csv($line, ';', '"');
}

View File

@ -35,7 +35,7 @@ $scope = optional_param('scope', 'global', PARAM_ALPHA);
/// Make sure they can even access this course
if ($courseid) {
if (!$course = get_record('course', 'id', $courseid)) {
if (!$course = $DB->get_record('course', array('id' => $courseid))) {
print_error('nocourseid');
}
require_login($course);
@ -114,7 +114,7 @@ if (isset($courseid) && ($scope == 'local')) {
// open the file, start importing data
if ($handle = fopen($imported_file['userfile']['tmp_name'], 'r')) {
$line = 0; // will keep track of current line, to give better error messages.
$line = 0; // will keep track of current line, to give better error messages.
$file_headers = '';
// $csv_data needs to have at least these columns, the value is the default position in the data file.
@ -122,21 +122,21 @@ if ($handle = fopen($imported_file['userfile']['tmp_name'], 'r')) {
$optional_headers = array('outcome_description'=>2, 'scale_description' => 5);
$imported_headers = array(); // will later be initialized with the values found in the file
// data should be separated by a ';'. *NOT* by a comma! TODO: version 2.0
// data should be separated by a ';'. *NOT* by a comma! TODO: version 2.0
// or whenever we can depend on PHP5, set the second parameter (8192) to 0 (unlimited line length) : the database can store over 128k per line.
while ( $csv_data = fgetcsv($handle, 8192, ';', '"')) { // if the line is over 8k, it won't work...
$line++;
// be tolerant on input, as fgetcsv returns "an array comprising a single null field" on blank lines
if ($csv_data == array(null)) {
continue;
}
// on first run, grab and analyse the header
if ($file_headers == '') {
$file_headers = array_flip($csv_data); // save the header line ... TODO: use the header line to let import work with columns in arbitrary order
$error = false;
foreach($headers as $key => $value) {
// sanity check #1: make sure the file contains all the mandatory headers
@ -158,13 +158,13 @@ if ($handle = fopen($imported_file['userfile']['tmp_name'], 'r')) {
continue; // we don't import headers
}
// sanity check #2: every line must have the same number of columns as there are
// sanity check #2: every line must have the same number of columns as there are
// headers. If not, processing stops.
if ( count($csv_data) != count($file_headers) ) {
if ( count($csv_data) != count($file_headers) ) {
print_box(get_string('importoutcomenofile', 'grades', $line));
//print_box(var_export($csv_data, true) ."<br />". var_export($header, true));
break;
}
}
// sanity check #3: all required fields must be present on the current line.
foreach ($headers as $header => $position) {
@ -176,12 +176,17 @@ if ($handle = fopen($imported_file['userfile']['tmp_name'], 'r')) {
//var_dump($csv_data);
$params = array($csv_data[$imported_headers['outcome_shortname']]);
$wheresql = 'shortname = ? ';
if ($local_scope) {
$outcome = get_records_select('grade_outcomes', 'shortname = "'. $csv_data[$imported_headers['outcome_shortname']] .'" and courseid = '. $courseid );
$params[] = $courseid;
$wheresql .= ' AND courseid = ?';
} else {
$outcome = get_records_select('grade_outcomes', 'shortname = "'. $csv_data[$imported_headers['outcome_shortname']] .'" and courseid is null');
$wheresql .= ' AND courseid IS NULL';
}
//var_export($outcome);
$outcome = $DB->get_records_select('grade_outcomes', $wheresql, $params);
if ($outcome) {
// already exists, print a message and skip.
@ -190,7 +195,9 @@ if ($handle = fopen($imported_file['userfile']['tmp_name'], 'r')) {
}
// new outcome will be added, search for compatible existing scale...
$scale = get_records_select('scale', 'name ="'. $csv_data[$imported_headers['scale_name']] .'" and scale ="'. $csv_data[$imported_headers['scale_items']] .'" and (courseid = '. $courseid .' or courseid = 0)');
$params = array($csv_data[$imported_headers['scale_name']], $csv_data[$imported_headers['scale_items']], $courseid);
$wheresql = 'name = ? AND scale = ? AND (courseid = ? OR courseid = 0)';
$scale = $DB->get_records_select('scale', $wheresql, $params);
if ($scale) {
// already exists in the right scope: use it.
@ -199,11 +206,11 @@ if ($handle = fopen($imported_file['userfile']['tmp_name'], 'r')) {
if (!has_capability('moodle/course:managescales', $context)) {
print_box(get_string('importskippednomanagescale', 'grades', $csv_data[$imported_headers['outcome_shortname']]));
continue;
} else {
} else {
// scale doesn't exists : create it.
$scale_data = array('name' => $csv_data[$imported_headers['scale_name']],
'scale' => $csv_data[$imported_headers['scale_items']],
'description' => $csv_data[$imported_headers['scale_description']],
$scale_data = array('name' => $csv_data[$imported_headers['scale_name']],
'scale' => $csv_data[$imported_headers['scale_items']],
'description' => $csv_data[$imported_headers['scale_description']],
'userid' => $USER->id);
if ($local_scope) {
@ -217,10 +224,10 @@ if ($handle = fopen($imported_file['userfile']['tmp_name'], 'r')) {
}
// add outcome
$outcome_data = array('shortname' => $csv_data[$imported_headers['outcome_shortname']],
'fullname' => $csv_data[$imported_headers['outcome_name']],
'scaleid' => $scale_id,
'description' => $csv_data[$imported_headers['outcome_description']],
$outcome_data = array('shortname' => $csv_data[$imported_headers['outcome_shortname']],
'fullname' => $csv_data[$imported_headers['outcome_name']],
'scaleid' => $scale_id,
'description' => $csv_data[$imported_headers['outcome_description']],
'usermodified' => $USER->id);
if ($local_scope) {

View File

@ -4,7 +4,7 @@ require_once($CFG->dirroot.'/lib/formslib.php');
class import_outcomes_form extends moodleform {
function definition() {
public function definition() {
global $COURSE, $USER;
$mform =& $this->_form;
@ -19,7 +19,7 @@ class import_outcomes_form extends moodleform {
$mform->addElement('radio', 'scope', get_string('importstandard', 'grades'), null, 'global');
$mform->setDefault('scope', 'custom');
}
$mform->addElement('file', 'userfile', get_string('importoutcomes', 'grades'));
$mform->addElement('submit', 'save', get_string('uploadthisfile'));

View File

@ -34,7 +34,7 @@ $action = optional_param('action', '', PARAM_ALPHA);
/// Make sure they can even access this course
if ($courseid) {
if (!$course = get_record('course', 'id', $courseid)) {
if (!$course = $DB->get_record('course', array('id' => $courseid))) {
print_error('nocourseid');
}
require_login($course);
@ -103,11 +103,11 @@ switch ($action) {
if(!$deleteconfirmed){
print_header(get_string('outcomedelete', 'grades'));
notice_yesno(get_string('outcomeconfirmdelete', 'grades', $outcome->fullname),
notice_yesno(get_string('outcomeconfirmdelete', 'grades', $outcome->fullname),
"index.php?id={$courseid}", "index.php?id={$courseid}",
array('outcomeid' => $outcome->id,
'action'=> 'delete',
'sesskey' => $USER->sesskey,
array('outcomeid' => $outcome->id,
'action'=> 'delete',
'sesskey' => $USER->sesskey,
'deleteconfirmed'=> 1)
);
print_footer();
@ -180,7 +180,7 @@ if ($courseid and $outcomes = grade_outcome::fetch_all_local($courseid)) {
" src=\"$CFG->pixpath/t/delete.gif\" class=\"iconsmall\" alt=\"$strdelete\" /></a> ";
}
$line[] = $buttons;
$data[] = $line;
}
$table = new object();
@ -196,7 +196,7 @@ if ($courseid and $outcomes = grade_outcome::fetch_all_local($courseid)) {
if ($outcomes = grade_outcome::fetch_all_global()) {
$return = print_heading($strstandardoutcome, '', 2, 'main', true);
$return = print_heading($strstandardoutcome, '', 2, 'main', true);
$data = array();
foreach($outcomes as $outcome) {
$line = array();

View File

@ -36,12 +36,12 @@ $systemcontext = get_context_instance(CONTEXT_SYSTEM);
// a bit complex access control :-O
if ($id) {
/// editing existing scale
if (!$scale_rec = get_record('scale', 'id', $id)) {
if (!$scale_rec = $DB->get_record('scale', array('id' => $id))) {
print_error('invalidscaleid');
}
if ($scale_rec->courseid) {
$scale_rec->standard = 0;
if (!$course = get_record('course', 'id', $scale_rec->courseid)) {
if (!$course = $DB->get_record('course', array('id' => $scale_rec->courseid))) {
print_error('invalidcourseid');
}
require_login($course);
@ -50,7 +50,7 @@ if ($id) {
$courseid = $course->id;
} else {
if ($courseid) {
if (!$course = get_record('course', 'id', $courseid)) {
if (!$course = $DB->get_record('course', array('id' => $courseid))) {
print_error('invalidcourseid');
}
}
@ -62,7 +62,7 @@ if ($id) {
} else if ($courseid){
/// adding new scale from course
if (!$course = get_record('course', 'id', $courseid)) {
if (!$course = $DB->get_record('course', array('id' => $courseid))) {
print_error('nocourseid');
}
$scale_rec = new object();

View File

@ -33,7 +33,7 @@ $action = optional_param('action', '', PARAM_ALPHA);
/// Make sure they can even access this course
if ($courseid) {
if (!$course = get_record('course', 'id', $courseid)) {
if (!$course = $DB->get_record('course', array('id' => $courseid))) {
print_error('nocourseid');
}
require_login($course);

View File

@ -35,7 +35,7 @@ class course_settings_form extends moodleform {
global $USER, $CFG;
$mform =& $this->_form;
$systemcontext = get_context_instance(CONTEXT_SYSTEM);
$can_view_admin_links = false;
if (has_capability('moodle/grade:manage', $systemcontext)) {
@ -102,7 +102,7 @@ class course_settings_form extends moodleform {
if ($can_view_admin_links) {
$link = '<a href="' . $CFG->wwwroot . '/admin/settings.php?section=gradereport' . $plugin . '">' . $strchangedefaults . '</a>';
$mform->addElement('static', 'gradeitemsettingslink', $link);
}
}
$functionname($mform);
}
}

View File

@ -30,7 +30,7 @@ require_once 'form.php';
$courseid = optional_param('id', SITEID, PARAM_INT);
if (!$course = get_record('course', 'id', $courseid)) {
if (!$course = $DB->get_record('course', array('id' => $courseid))) {
print_error('nocourseid');
}
require_login($course);

View File

@ -31,7 +31,7 @@ $action = required_param('action', PARAM_ALPHA);
$eid = required_param('eid', PARAM_ALPHANUM);
/// Make sure they can even access this course
if (!$course = get_record('course', 'id', $courseid)) {
if (!$course = $DB->get_record('course', array('id' => $courseid))) {
print_error('nocourseid');
}
require_login($course);

View File

@ -26,8 +26,8 @@
require_once $CFG->libdir.'/formslib.php';
class edit_calculation_form extends moodleform {
var $available;
var $noidnumbers;
public $available;
public $noidnumbers;
function definition() {
global $COURSE;

View File

@ -140,7 +140,7 @@ if ($data = $mform->get_data(false)) {
} else {
$module = get_record_sql("SELECT cm.*, m.name as modname
FROM {$CFG->prefix}modules m, {$CFG->prefix}course_modules cm
FROM {modules} m, {course_modules} cm
WHERE cm.id = {$data->cmid} AND cm.module = m.id ");
$grade_item->itemtype = 'mod';
$grade_item->itemmodule = $module->modname;

View File

@ -80,7 +80,7 @@ class grade_export {
$this->userkey = '';
$this->previewrows = false;
$this->updatedgradesonly = $updatedgradesonly;
$this->displaytype = $displaytype;
$this->decimalpoints = $decimalpoints;
}
@ -227,12 +227,12 @@ class grade_export {
// if (empty($user->idnumber)) { // Not sure why this was here, ccommented out for MDL-13722
// continue;
// }
$gradeupdated = false; // if no grade is update at all for this user, do not display this row
$rowstr = '';
foreach ($this->columns as $itemid=>$unused) {
$gradetxt = $this->format_grade($userdata->grades[$itemid]);
// get the status of this grade, and put it through track to get the status
$g = new grade_export_update_buffer();
$grade_grade = new grade_grade(array('itemid'=>$itemid, 'userid'=>$user->id));
@ -244,22 +244,22 @@ class grade_export {
$rowstr .= "<td>$gradetxt</td>";
$gradeupdated = true;
}
if ($this->export_feedback) {
$rowstr .= '<td>'.$this->format_feedback($userdata->feedbacks[$itemid]).'</td>';
}
}
// if we are requesting updated grades only, we are not interested in this user at all
// if we are requesting updated grades only, we are not interested in this user at all
if (!$gradeupdated && $this->updatedgradesonly) {
continue;
continue;
}
echo '<tr>';
echo "<td>$user->firstname</td><td>$user->lastname</td><td>$user->idnumber</td><td>$user->institution</td><td>$user->department</td><td>$user->email</td>";
echo "<td>$user->firstname</td><td>$user->lastname</td><td>$user->idnumber</td><td>$user->institution</td><td>$user->department</td><td>$user->email</td>";
echo $rowstr;
echo "</tr>";
$i++; // increment the counter
}
echo '</table>';
@ -340,7 +340,7 @@ class grade_export_update_buffer {
if (count($this->update_list) > $buffersize) {
$list = implode(',', $this->update_list);
$sql = "UPDATE {$CFG->prefix}grade_grades SET exported = {$this->export_time} WHERE id IN ($list)";
$sql = "UPDATE {grade_grades} SET exported = {$this->export_time} WHERE id IN ($list)";
execute_sql($sql, false);
$this->update_list = array();
}

View File

@ -152,7 +152,7 @@ if ($formdata = $mform->get_data()) {
$mform2->display();
//} else if (($formdata = data_submitted()) && !empty($formdata->map)) {
// else if grade import mapping form is submitted
} else if ($formdata = $mform2->get_data()) {
@ -427,7 +427,7 @@ if ($formdata = $mform->get_data()) {
if ($status and !empty($newfeedbacks)) {
foreach ($newfeedbacks as $newfeedback) {
$sql = "SELECT *
FROM {$CFG->prefix}grade_import_values
FROM {grade_import_values}
WHERE importcode=$importcode AND userid=$studentid AND itemid=$newfeedback->itemid AND importer={$USER->id}";
if ($feedback = get_record_sql($sql)) {
$newfeedback->id = $feedback->id;

View File

@ -59,7 +59,7 @@ function grade_import_commit($courseid, $importcode, $importfeedback=true, $verb
/// first select distinct new grade_items with this batch
if ($newitems = get_records_sql("SELECT *
FROM {$CFG->prefix}grade_import_newitem
FROM {grade_import_newitem}
WHERE importcode = $importcode AND importer={$USER->id}")) {
// instances of the new grade_items created, cached
@ -98,7 +98,7 @@ function grade_import_commit($courseid, $importcode, $importfeedback=true, $verb
/// then find all existing items
if ($gradeitems = get_records_sql("SELECT DISTINCT (itemid)
FROM {$CFG->prefix}grade_import_values
FROM {grade_import_values}
WHERE importcode = $importcode AND importer={$USER->id} AND itemid > 0")) {
$modifieditems = array();
@ -157,7 +157,7 @@ function grade_import_commit($courseid, $importcode, $importfeedback=true, $verb
/**
* This function returns an array of grades that were included in the import,
* but wherer the user does not currenly have a graded role on the course. These gradse
* but wherer the user does not currenly have a graded role on the course. These gradse
* are still stored in the database, but will not be visible in the gradebook unless
* this user subsequently enrols on the course in a graded roles.
*
@ -170,15 +170,15 @@ function grade_import_commit($courseid, $importcode, $importfeedback=true, $verb
function get_unenrolled_users_in_import($importcode, $courseid) {
global $CFG;
$relatedctxcondition = get_related_contexts_string(get_context_instance(CONTEXT_COURSE, $courseid));
$sql = "SELECT giv.id, u.firstname, u.lastname, u.idnumber AS useridnumber,
$sql = "SELECT giv.id, u.firstname, u.lastname, u.idnumber AS useridnumber,
COALESCE(gi.idnumber, gin.itemname) AS gradeidnumber
FROM
{$CFG->prefix}grade_import_values giv
JOIN {$CFG->prefix}user u ON giv.userid = u.id
LEFT JOIN {$CFG->prefix}grade_items gi ON gi.id = giv.itemid
LEFT JOIN {$CFG->prefix}grade_import_newitem gin ON gin.id = giv.newgradeitem
LEFT JOIN {$CFG->prefix}role_assignments ra ON (giv.userid = ra.userid AND
{grade_import_values} giv
JOIN {user} u ON giv.userid = u.id
LEFT JOIN {grade_items} gi ON gi.id = giv.itemid
LEFT JOIN {grade_import_newitem} gin ON gin.id = giv.newgradeitem
LEFT JOIN {role_assignments} ra ON (giv.userid = ra.userid AND
ra.roleid IN ($CFG->gradebookroles) AND
ra.contextid $relatedctxcondition)
WHERE giv.importcode = $importcode

View File

@ -30,16 +30,16 @@ require_once $CFG->libdir.'/gradelib.php';
* Returns detailed info about users and their grades.
*/
class graded_users_iterator {
var $course;
var $grade_items;
var $groupid;
var $users_rs;
var $grades_rs;
var $gradestack;
var $sortfield1;
var $sortorder1;
var $sortfield2;
var $sortorder2;
public $course;
public $grade_items;
public $groupid;
public $users_rs;
public $grades_rs;
public $gradestack;
public $sortfield1;
public $sortorder1;
public $sortfield2;
public $sortorder2;
/**
* Constructor
@ -51,7 +51,7 @@ class graded_users_iterator {
* @param string $sortfield2 The second field of the users table by which the array of users will be sorted
* @param string $sortorder2 The order in which the second sorting field will be sorted (ASC or DESC)
*/
function graded_users_iterator($course, $grade_items=null, $groupid=0, $sortfield1='lastname', $sortorder1='ASC', $sortfield2='firstname', $sortorder2='ASC') {
public function graded_users_iterator($course, $grade_items=null, $groupid=0, $sortfield1='lastname', $sortorder1='ASC', $sortfield2='firstname', $sortorder2='ASC') {
$this->course = $course;
$this->grade_items = $grade_items;
$this->groupid = $groupid;
@ -67,8 +67,8 @@ class graded_users_iterator {
* Initialise the iterator
* @return boolean success
*/
function init() {
global $CFG;
public function init() {
global $CFG, $DB;
$this->close();
@ -79,17 +79,15 @@ class graded_users_iterator {
return false;
}
if (strpos($CFG->gradebookroles, ',') === false) {
$gradebookroles = " = {$CFG->gradebookroles}";
} else {
$gradebookroles = " IN ({$CFG->gradebookroles})";
}
list($gradebookroles_sql, $params) = $DB->get_in_or_equal(explode(',', $CFG->gradebookroles));
$relatedcontexts = get_related_contexts_string(get_context_instance(CONTEXT_COURSE, $this->course->id));
if ($this->groupid) {
$groupsql = "INNER JOIN {$CFG->prefix}groups_members gm ON gm.userid = u.id";
$groupwheresql = "AND gm.groupid = {$this->groupid}";
$groupsql = "INNER JOIN {groups_members} gm ON gm.userid = u.id";
$groupwheresql = "AND gm.groupid = ?";
// $params contents: gradebookroles
$params[] = $this->groupid;
} else {
$groupsql = "";
$groupwheresql = "";
@ -114,32 +112,35 @@ class graded_users_iterator {
}
}
// $params contents: gradebookroles and groupid (for $groupwheresql)
$users_sql = "SELECT u.* $ofields
FROM {$CFG->prefix}user u
INNER JOIN {$CFG->prefix}role_assignments ra ON u.id = ra.userid
FROM {user} u
INNER JOIN {role_assignments} ra ON u.id = ra.userid
$groupsql
WHERE ra.roleid $gradebookroles
WHERE ra.roleid $gradebookroles_sql;
AND ra.contextid $relatedcontexts
$groupwheresql
ORDER BY $order";
$this->users_rs = get_recordset_sql($users_sql);
$this->users_rs = $DB->get_recordset_sql($users_sql, $params);
if (!empty($this->grade_items)) {
$itemids = array_keys($this->grade_items);
$itemids = implode(',', $itemids);
list($itemidsql, $grades_params) = $DB->get_in_or_equal($itemids);
$params = array_merge($params, $grades_params);
// $params contents: gradebookroles, groupid (for $groupwheresql) and itemids
$grades_sql = "SELECT g.* $ofields
FROM {$CFG->prefix}grade_grades g
INNER JOIN {$CFG->prefix}user u ON g.userid = u.id
INNER JOIN {$CFG->prefix}role_assignments ra ON u.id = ra.userid
FROM {grade_grades} g
INNER JOIN {user} u ON g.userid = u.id
INNER JOIN {role_assignments} ra ON u.id = ra.userid
$groupsql
WHERE ra.roleid $gradebookroles
WHERE ra.roleid $gradebookroles_sql
AND ra.contextid $relatedcontexts
AND g.itemid IN ($itemids)
$groupwheresql
AND g.itemid $itemidsql
ORDER BY $order, g.itemid ASC";
$this->grades_rs = get_recordset_sql($grades_sql);
$this->grades_rs = $DB->get_recordset_sql($grades_sql, $params);
} else {
$this->grades_rs = false;
}
@ -156,7 +157,7 @@ class graded_users_iterator {
return false; // no users present
}
if (!$user = rs_fetch_next_record($this->users_rs)) {
if (!$user = $this->users_rs->next()) {
if ($current = $this->_pop()) {
// this is not good - user or grades updated between the two reads above :-(
}
@ -213,11 +214,11 @@ class graded_users_iterator {
*/
function close() {
if ($this->users_rs) {
rs_close($this->users_rs);
$this->users_rs->close();
$this->users_rs = null;
}
if ($this->grades_rs) {
rs_close($this->grades_rs);
$this->grades_rs->close();
$this->grades_rs = null;
}
$this->gradestack = array();
@ -234,12 +235,13 @@ class graded_users_iterator {
* Internal function
*/
function _pop() {
global $DB;
if (empty($this->gradestack)) {
if (!$this->grades_rs) {
return NULL; // no grades present
}
if (!$grade = rs_fetch_next_record($this->grades_rs)) {
if (!$grade = $this->grades_rs->next()) {
return NULL; // no more grades
}
@ -458,17 +460,17 @@ function print_grade_plugin_selector($courseid, $active_type, $active_plugin, $r
* Utility class used for return tracking when using edit and other forms in grade plugins
*/
class grade_plugin_return {
var $type;
var $plugin;
var $courseid;
var $userid;
var $page;
public $type;
public $plugin;
public $courseid;
public $userid;
public $page;
/**
* Constructor
* @param array $params - associative array with return parameters, if null parameter are taken from _GET or _POST
*/
function grade_plugin_return ($params=null) {
public function grade_plugin_return ($params=null) {
if (empty($params)) {
$this->type = optional_param('gpr_type', null, PARAM_SAFEDIR);
$this->plugin = optional_param('gpr_plugin', null, PARAM_SAFEDIR);
@ -489,7 +491,7 @@ class grade_plugin_return {
* Returns return parameters as options array suitable for buttons.
* @return array options
*/
function get_options() {
public function get_options() {
if (empty($this->type)) {
return array();
}
@ -520,7 +522,7 @@ class grade_plugin_return {
* @param string $default default url when params not set
* @return string url
*/
function get_return_url($default, $extras=null) {
public function get_return_url($default, $extras=null) {
global $CFG;
if (empty($this->type) or empty($this->plugin)) {
@ -559,7 +561,7 @@ class grade_plugin_return {
* Returns string with hidden return tracking form elements.
* @return string
*/
function get_form_fields() {
public function get_form_fields() {
if (empty($this->type)) {
return '';
}
@ -588,7 +590,7 @@ class grade_plugin_return {
* @param object $mform moodle form object
* @return void
*/
function add_mform_elements(&$mform) {
public function add_mform_elements(&$mform) {
if (empty($this->type)) {
return;
}
@ -622,7 +624,7 @@ class grade_plugin_return {
* @param string $url
* @return string $url with erturn tracking params
*/
function add_url_params($url) {
public function add_url_params($url) {
if (empty($this->type)) {
return $url;
}
@ -760,14 +762,14 @@ function grade_build_nav($path, $pagename=null, $id=null) {
* General structure representing grade items in course
*/
class grade_structure {
var $context;
public $context;
var $courseid;
public $courseid;
/**
* 1D array of grade items only
*/
var $items;
public $items;
/**
* Returns icon of element
@ -775,7 +777,7 @@ class grade_structure {
* @param bool $spacerifnone return spacer if no icon found
* @return string icon or spacer
*/
function get_element_icon(&$element, $spacerifnone=false) {
public function get_element_icon(&$element, $spacerifnone=false) {
global $CFG;
switch ($element['type']) {
@ -832,7 +834,7 @@ class grade_structure {
* @param bool $spacerifnone return spacer if no icon found
* @return header string
*/
function get_element_header(&$element, $withlink=false, $icon=true, $spacerifnone=false) {
public function get_element_header(&$element, $withlink=false, $icon=true, $spacerifnone=false) {
global $CFG;
$header = '';
@ -874,7 +876,7 @@ class grade_structure {
* @param $grade_grade object
* @return string eid
*/
function get_grade_eid($grade_grade) {
public function get_grade_eid($grade_grade) {
if (empty($grade_grade->id)) {
return 'n'.$grade_grade->itemid.'u'.$grade_grade->userid;
} else {
@ -887,7 +889,7 @@ class grade_structure {
* @param $grade_item object
* @return string eid
*/
function get_item_eid($grade_item) {
public function get_item_eid($grade_item) {
return 'i'.$grade_item->id;
}
@ -922,7 +924,7 @@ class grade_structure {
* @param object $element
* @return string
*/
function get_edit_icon($element, $gpr) {
public function get_edit_icon($element, $gpr) {
global $CFG;
if (!has_capability('moodle/grade:manage', $this->context)) {
@ -999,7 +1001,7 @@ class grade_structure {
* @param object $element
* @return string
*/
function get_hiding_icon($element, $gpr) {
public function get_hiding_icon($element, $gpr) {
global $CFG;
if (!has_capability('moodle/grade:manage', $this->context) and !has_capability('moodle/grade:hide', $this->context)) {
@ -1038,19 +1040,19 @@ class grade_structure {
* @param object $element
* @return string
*/
function get_locking_icon($element, $gpr) {
public function get_locking_icon($element, $gpr) {
global $CFG;
$strparams = $this->get_params_for_iconstr($element);
$strunlock = get_string('unlockverbose', 'grades', $strparams);
$strlock = get_string('lockverbose', 'grades', $strparams);
// Don't allow an unlocking action for a grade whose grade item is locked: just print a state icon
if ($element['type'] == 'grade' && $element['object']->grade_item->is_locked()) {
$strparamobj = new stdClass();
$strparamobj->itemname = $element['object']->grade_item->itemname;
$strnonunlockable = get_string('nonunlockableverbose', 'grades', $strparamobj);
$action = '<img src="'.$CFG->pixpath.'/t/unlock_gray.gif" alt="'.$strnonunlockable.'" class="iconsmall" title="'.$strnonunlockable.'"/>';
$action = '<img src="'.$CFG->pixpath.'/t/unlock_gray.gif" alt="'.$strnonunlockable.'" class="iconsmall" title="'.$strnonunlockable.'"/>';
} elseif ($element['object']->is_locked()) {
$icon = 'unlock';
$tooltip = $strunlock;
@ -1086,7 +1088,7 @@ class grade_structure {
* @param object $element
* @return string
*/
function get_calculation_icon($element, $gpr) {
public function get_calculation_icon($element, $gpr) {
global $CFG;
if (!has_capability('moodle/grade:manage', $this->context)) {
return '';
@ -1129,12 +1131,12 @@ class grade_seq extends grade_structure {
* A string of GET URL variables, namely courseid and sesskey, used in most URLs built by this class.
* @var string $commonvars
*/
var $commonvars;
public $commonvars;
/**
* 1D array of elements
*/
var $elements;
public $elements;
/**
* Constructor, retrieves and stores array of all grade_category and grade_item
@ -1143,7 +1145,7 @@ class grade_seq extends grade_structure {
* @param boolean $category_grade_last category grade item is the last child
* @param array $collapsed array of collapsed categories
*/
function grade_seq($courseid, $category_grade_last=false, $nooutcomes=false) {
public function grade_seq($courseid, $category_grade_last=false, $nooutcomes=false) {
global $USER, $CFG;
$this->courseid = $courseid;
@ -1166,7 +1168,7 @@ class grade_seq extends grade_structure {
* @param array $element The seed of the recursion
* @return void
*/
function flatten(&$element, $category_grade_last, $nooutcomes) {
public function flatten(&$element, $category_grade_last, $nooutcomes) {
if (empty($element['children'])) {
return array();
}
@ -1204,7 +1206,7 @@ class grade_seq extends grade_structure {
* @param int $eid
* @return object element
*/
function locate_element($eid) {
public function locate_element($eid) {
// it is a grade - construct a new object
if (strpos($eid, 'n') === 0) {
if (!preg_match('/n(\d+)u(\d+)/', $eid, $matches)) {
@ -1261,23 +1263,23 @@ class grade_tree extends grade_structure {
* The basic representation of the tree as a hierarchical, 3-tiered array.
* @var object $top_element
*/
var $top_element;
public $top_element;
/**
* A string of GET URL variables, namely courseid and sesskey, used in most URLs built by this class.
* @var string $commonvars
*/
var $commonvars;
public $commonvars;
/**
* 2D array of grade items and categories
*/
var $levels;
public $levels;
/**
* Grade items
*/
var $items;
public $items;
/**
* Constructor, retrieves and stores a hierarchical array of all grade_category and grade_item
@ -1287,7 +1289,7 @@ class grade_tree extends grade_structure {
* @param boolean $category_grade_last category grade item is the last child
* @param array $collapsed array of collapsed categories
*/
function grade_tree($courseid, $fillers=true, $category_grade_last=false, $collapsed=null, $nooutcomes=false) {
public function grade_tree($courseid, $fillers=true, $category_grade_last=false, $collapsed=null, $nooutcomes=false) {
global $USER, $CFG;
$this->courseid = $courseid;
@ -1331,7 +1333,7 @@ class grade_tree extends grade_structure {
* @param array $collapsed array of collapsed categories
* @return void
*/
function category_collapse(&$element, $collapsed) {
public function category_collapse(&$element, $collapsed) {
if ($element['type'] != 'category') {
return;
}
@ -1361,7 +1363,7 @@ class grade_tree extends grade_structure {
* @param array $element The seed of the recursion
* @return void
*/
function no_outcomes(&$element) {
public function no_outcomes(&$element) {
if ($element['type'] != 'category') {
return;
}
@ -1382,7 +1384,7 @@ class grade_tree extends grade_structure {
* @param array $element The seed of the recursion
* @return void
*/
function category_grade_last(&$element) {
public function category_grade_last(&$element) {
if (empty($element['children'])) {
return;
}
@ -1409,7 +1411,7 @@ class grade_tree extends grade_structure {
* @param int $depth
* @return void
*/
function fill_levels(&$levels, &$element, $depth) {
public function fill_levels(&$levels, &$element, $depth) {
if (!array_key_exists($depth, $levels)) {
$levels[$depth] = array();
}
@ -1442,7 +1444,7 @@ class grade_tree extends grade_structure {
/**
* Static recursive helper - makes full tree (all leafes are at the same level)
*/
function inject_fillers(&$element, $depth) {
public function inject_fillers(&$element, $depth) {
$depth++;
if (empty($element['children'])) {
@ -1482,7 +1484,7 @@ class grade_tree extends grade_structure {
/**
* Static recursive helper - add colspan information into categories
*/
function inject_colspans(&$element) {
public function inject_colspans(&$element) {
if (empty($element['children'])) {
return 1;
}
@ -1500,7 +1502,7 @@ class grade_tree extends grade_structure {
* @param int $eid
* @return object element
*/
function locate_element($eid) {
public function locate_element($eid) {
// it is a grade - construct a new object
if (strpos($eid, 'n') === 0) {
if (!preg_match('/n(\d+)u(\d+)/', $eid, $matches)) {
@ -1548,13 +1550,13 @@ class grade_tree extends grade_structure {
return null;
}
/**
* Returns a well-formed XML representation of the grade-tree using recursion.
* @param array $root The current element in the recursion. If null, starts at the top of the tree.
* @return string $xml
*/
function exportToXML($root=null, $tabs="\t") {
public function exportToXML($root=null, $tabs="\t") {
$xml = null;
$first = false;
if (is_null($root)) {
@ -1563,7 +1565,7 @@ class grade_tree extends grade_structure {
$xml .= "<gradetree>\n";
$first = true;
}
$type = 'undefined';
if (strpos($root['object']->table, 'grade_categories') !== false) {
$type = 'category';
@ -1572,7 +1574,7 @@ class grade_tree extends grade_structure {
} elseif (strpos($root['object']->table, 'grade_outcomes') !== false) {
$type = 'outcome';
}
$xml .= "$tabs<element type=\"$type\">\n";
foreach ($root['object'] as $var => $value) {
if (!is_object($value) && !is_array($value) && !empty($value)) {
@ -1587,16 +1589,16 @@ class grade_tree extends grade_structure {
}
$xml .= "$tabs\t</children>\n";
}
$xml .= "$tabs</element>\n";
if ($first) {
$xml .= "</gradetree>";
}
return $xml;
}
/**
* Returns a JSON representation of the grade-tree using recursion.
* @param array $root The current element in the recursion. If null, starts at the top of the tree.
@ -1604,28 +1606,28 @@ class grade_tree extends grade_structure {
* @param int $switch The position (first or last) of the aggregations
* @return string $xml
*/
function exportToJSON($root=null, $tabs="\t") {
public function exportToJSON($root=null, $tabs="\t") {
$json = null;
$first = false;
if (is_null($root)) {
$root = $this->top_element;
$first = true;
}
$name = '';
if (strpos($root['object']->table, 'grade_categories') !== false) {
$name = $root['object']->fullname;
if ($name == '?') {
$name = $root['object']->get_name();
$name = $root['object']->get_name();
}
} elseif (strpos($root['object']->table, 'grade_items') !== false) {
$name = $root['object']->itemname;
} elseif (strpos($root['object']->table, 'grade_outcomes') !== false) {
$name = $root['object']->itemname;
}
$json .= "$tabs {\n";
$json .= "$tabs\t \"type\": \"{$root['type']}\",\n";
$json .= "$tabs\t \"name\": \"$name\",\n";
@ -1635,9 +1637,9 @@ class grade_tree extends grade_structure {
$json .= "$tabs\t \"$var\": \"$value\",\n";
}
}
$json = substr($json, 0, strrpos($json, ','));
if (!empty($root['children'])) {
$json .= ",\n$tabs\t\"children\": [\n";
foreach ($root['children'] as $sortorder => $child) {
@ -1645,16 +1647,32 @@ class grade_tree extends grade_structure {
}
$json = substr($json, 0, strrpos($json, ','));
$json .= "\n$tabs\t]\n";
}
}
if ($first) {
$json .= "\n}";
} else {
$json .= "\n$tabs},\n";
}
return $json;
}
public function get_levels() {
return $this->levels;
}
public function get_items() {
return $this->items;
}
public function get_item($itemid) {
if (array_key_exists($itemid, $this->items)) {
return $this->items[$itemid];
} else {
return false;
}
}
}
?>

View File

@ -222,13 +222,14 @@ function grade_get_course_grade($userid, $courseid_or_ids=null) {
* @return mixed - array of grade item instances (one if $only_main_item true), false if error or not found
*/
function grade_get_grade_items_for_activity($cm, $only_main_item=false) {
global $CFG;
global $CFG, $DB;
if (!isset($cm->modname)) {
$cm = get_record_sql("SELECT cm.*, m.name, md.name as modname
FROM {$CFG->prefix}course_modules cm,
{$CFG->prefix}modules md,
WHERE cm.id = {$cm->id} AND md.id = cm.module");
$params = array($cm->id);
$cm = $DB->get_record_sql("SELECT cm.*, m.name, md.name as modname
FROM {course_modules} cm,
{modules} md,
WHERE cm.id = ? AND md.id = cm.module", $params);
}
@ -288,10 +289,10 @@ function grade_is_user_graded_in_activity($cm, $userid) {
* @return array $cm objects
*/
function grade_get_gradable_activities($courseid, $modulename='') {
global $CFG;
global $CFG, $DB;
if (empty($modulename)) {
if (!$modules = get_records('modules', 'visible', '1')) {
if (!$modules = $DB->get_records('modules', array('visible' => '1'))) {
return false;
}
$result = array();
@ -307,18 +308,19 @@ function grade_get_gradable_activities($courseid, $modulename='') {
}
}
$params = array($courseid, $modulename, GRADE_TYPE_NONE, $modulename);
$sql = "SELECT cm.*, m.name, md.name as modname
FROM {$CFG->prefix}grade_items gi, {$CFG->prefix}course_modules cm, {$CFG->prefix}modules md, {$CFG->prefix}$modulename m
WHERE gi.courseid = $courseid AND
FROM {grade_items} gi, {course_modules} cm, {modules} md, {$modulename} m
WHERE gi.courseid = ? AND
gi.itemtype = 'mod' AND
gi.itemmodule = '$modulename' AND
gi.itemmodule = ? AND
gi.itemnumber = 0 AND
gi.gradetype != ".GRADE_TYPE_NONE." AND
gi.gradetype != ? AND
gi.iteminstance = cm.instance AND
cm.instance = m.id AND
md.name = '$modulename' AND
md.name = ? AND
md.id = cm.module";
return get_records_sql($sql);
return $DB->get_records_sql($sql, $params);
}
?>
?>

View File

@ -23,7 +23,7 @@
///////////////////////////////////////////////////////////////////////////
require_once '../../../config.php';
require_once '../../../config.php';
require_once $CFG->libdir.'/gradelib.php';
require_once $CFG->dirroot.'/grade/lib.php';
// require_once $CFG->dirroot.'/grade/report/grader/ajaxlib.php';
@ -43,7 +43,7 @@ switch ($action) {
if (!$grade_item = grade_item::fetch(array('id'=>$itemid, 'courseid'=>$courseid))) { // we must verify course id here!
print_error('invalidgradeitmeid');
}
/**
* Code copied from grade/report/grader/lib.php line 187+
*/
@ -83,7 +83,7 @@ switch ($action) {
$gradestr->itemname = $grade_item->get_name();
$json_object->message = get_string($errorstr, 'grades', $gradestr);
$json_object->result = "error";
}
$finalvalue = $finalgrade;
@ -99,13 +99,13 @@ switch ($action) {
$finalvalue = $feedback;
}
if (!empty($json_object->result) && $json_object->result == 'error') {
echo json_encode($json_object);
die();
} else {
$json_object->gradevalue = $finalvalue;
if ($grade_item->update_final_grade($userid, $finalgrade, 'gradebook', $feedback, FORMAT_MOODLE)) {
$json_object->result = 'success';
$json_object->message = false;
@ -115,10 +115,10 @@ switch ($action) {
echo json_encode();
die();
}
// Get row data
$sql = "SELECT gg.id, gi.id AS itemid, gi.scaleid AS scale, gg.userid AS userid, finalgrade, gg.overridden AS overridden "
. "FROM {$CFG->prefix}grade_grades gg, {$CFG->prefix}grade_items gi WHERE "
. "FROM {grade_grades} gg, {grade_items} gi WHERE "
. "gi.courseid = $courseid AND gg.itemid = gi.id AND gg.userid = $userid";
$records = get_records_sql($sql);
$json_object->row = $records;
@ -128,7 +128,7 @@ switch ($action) {
} else {
$json_object = new stdClass();
$json_object->result = "error";
$json_object->message = "Missing parameter to ajax UPDATE callback: \n" .
$json_object->message = "Missing parameter to ajax UPDATE callback: \n" .
" userid: $userid,\n itemid: $itemid\n, type: $type\n, newvalue: $newvalue";
echo json_encode($json_object);
}

View File

@ -42,7 +42,7 @@ $toggle = optional_param('toggle', NULL, PARAM_INT);
$toggle_type = optional_param('toggle_type', 0, PARAM_ALPHANUM);
/// basic access checks
if (!$course = get_record('course', 'id', $courseid)) {
if (!$course = $DB->get_record('course', array('id' => $courseid))) {
print_error('nocourseid');
}
require_login($course);
@ -124,12 +124,12 @@ $report = new grade_report_grader($courseid, $gpr, $context, $page, $sortitemid)
// Initialise the grader report object
if (ajaxenabled() && $report->get_pref('enableajax')) {
require_once $CFG->dirroot.'/grade/report/grader/ajaxlib.php';
require_js(array('yui_yahoo',
'yui_dom',
'yui_event',
'yui_json',
'yui_connection',
require_js(array('yui_yahoo',
'yui_dom',
'yui_event',
'yui_json',
'yui_connection',
'yui_dragdrop',
'yui_animation'));
@ -219,7 +219,7 @@ echo $reporthtml;
// print submit button
if ($USER->gradeediting[$course->id] && ($report->get_pref('showquickfeedback')
||
||
$report->get_pref('quickgrading')) && !$report->get_pref('enableajax')) {
echo '<div class="submit"><input type="submit" value="'.get_string('update').'" /></div>';
echo '</div></form>';

View File

@ -40,13 +40,13 @@ class grade_report_grader extends grade_report {
* The final grades.
* @var array $grades
*/
var $grades;
public $grades;
/**
* Array of errors for bulk grades updating.
* @var array $gradeserror
*/
var $gradeserror = array();
public $gradeserror = array();
//// SQL-RELATED
@ -54,36 +54,42 @@ class grade_report_grader extends grade_report {
* The id of the grade_item by which this report will be sorted.
* @var int $sortitemid
*/
var $sortitemid;
public $sortitemid;
/**
* Sortorder used in the SQL selections.
* @var int $sortorder
*/
var $sortorder;
public $sortorder;
/**
* An SQL fragment affecting the search for users.
* @var string $userselect
*/
var $userselect;
public $userselect;
/**
* The bound params for $userselect
* @var array $userselect_params
*/
public $userselect_params = array();
/**
* List of collapsed categories from user preference
* @var array $collapsed
*/
var $collapsed;
public $collapsed;
/**
* A count of the rows, used for css classes.
* @var int $rowcount
*/
var $rowcount = 0;
public $rowcount = 0;
/**
* Capability check caching
* */
var $canviewhidden;
public $canviewhidden;
/**
* Constructor. Sets local copies of user preferences and initialises grade_tree.
@ -93,9 +99,9 @@ class grade_report_grader extends grade_report {
* @param int $page The current page being viewed (when report is paged)
* @param int $sortitemid The id of the grade_item by which to sort the table
*/
function grade_report_grader($courseid, $gpr, $context, $page=null, $sortitemid=null) {
public function __construct($courseid, $gpr, $context, $page=null, $sortitemid=null) {
global $CFG;
parent::grade_report($courseid, $gpr, $context, $page);
parent::__construct($courseid, $gpr, $context, $page);
$this->canviewhidden = has_capability('moodle/grade:viewhidden', get_context_instance(CONTEXT_COURSE, $this->course->id));
@ -150,7 +156,7 @@ class grade_report_grader extends grade_report {
* @param array $data form submission (with magic quotes)
* @return array empty array if success, array of warnings if something fails.
*/
function process_data($data) {
public function process_data($data) {
$warnings = array();
// always initialize all arrays
@ -236,7 +242,7 @@ class grade_report_grader extends grade_report {
* all this should be in the new table class that we might need to use
* for displaying grades.
*/
function setup_sortitemid() {
private function setup_sortitemid() {
global $SESSION;
@ -251,7 +257,7 @@ class grade_report_grader extends grade_report {
// this is the first sort, i.e. by last name
if (!isset($SESSION->gradeuserreport->sortitemid)) {
if ($this->sortitemid == 'firstname' || $this->sortitemid == 'lastname') {
$this->sortorder = $SESSION->gradeuserreport->sort = 'ASC';
$this->sortorder = $SESSION->gradeuserreport->sort = 'ASC';
} else {
$this->sortorder = $SESSION->gradeuserreport->sort = 'DESC';
}
@ -295,18 +301,21 @@ class grade_report_grader extends grade_report {
* this is check for user roles because there could be some users with grades
* but not supposed to be displayed
*/
function load_users() {
global $CFG;
public function load_users() {
global $CFG, $DB;
$params = array();
list($usql, $gbr_params) = $DB->get_in_or_equal(explode(',', $this->gradebookroles));
if (is_numeric($this->sortitemid)) {
$params = array_merge(array($this->sortitemid), $gbr_params, $this->groupwheresql_params);
$sort = "g.finalgrade $this->sortorder";
$sql = "SELECT u.id, u.firstname, u.lastname, u.imagealt, u.picture, u.idnumber
FROM {$CFG->prefix}grade_grades g RIGHT OUTER JOIN
{$CFG->prefix}user u ON (u.id = g.userid AND g.itemid = $this->sortitemid)
LEFT JOIN {$CFG->prefix}role_assignments ra ON u.id = ra.userid
FROM {grade_grades} g RIGHT OUTER JOIN
{user} u ON (u.id = g.userid AND g.itemid = ?)
LEFT JOIN {role_assignments} ra ON u.id = ra.userid
$this->groupsql
WHERE ra.roleid in ($this->gradebookroles)
WHERE ra.roleid in $usql
$this->groupwheresql
AND ra.contextid ".get_related_contexts_string($this->context)."
ORDER BY $sort";
@ -322,25 +331,27 @@ class grade_report_grader extends grade_report {
$sort = "u.idnumber $this->sortorder"; break;
}
$params = array_merge($gbr_params, $this->groupwheresql_params);
$sql = "SELECT u.id, u.firstname, u.lastname, u.imagealt, u.picture, u.idnumber
FROM {$CFG->prefix}user u
JOIN {$CFG->prefix}role_assignments ra ON u.id = ra.userid
FROM {user} u
JOIN {role_assignments} ra ON u.id = ra.userid
$this->groupsql
WHERE ra.roleid in ($this->gradebookroles)
WHERE ra.roleid $usql
$this->groupwheresql
AND ra.contextid ".get_related_contexts_string($this->context)."
ORDER BY $sort";
}
$this->users = get_records_sql($sql, $this->get_pref('studentsperpage') * $this->page,
$this->get_pref('studentsperpage'));
$this->users = $DB->get_records_sql($sql, $params, $this->get_pref('studentsperpage') * $this->page, $this->get_pref('studentsperpage'));
if (empty($this->users)) {
$this->userselect = '';
$this->users = array();
} else {
$this->userselect = 'AND g.userid in ('.implode(',', array_keys($this->users)).')';
list($usql, $params) = $DB->get_in_or_equal(array_keys($this->users));
$this->userselect = "AND g.userid $usql";
$this->userselect_params = $params;
}
return $this->users;
@ -350,35 +361,36 @@ class grade_report_grader extends grade_report {
* we supply the userids in this query, and get all the grades
* pulls out all the grades, this does not need to worry about paging
*/
function load_final_grades() {
global $CFG;
public function load_final_grades() {
global $CFG, $DB;
// please note that we must fetch all grade_grades fields if we want to contruct grade_grade object from it!
$params = array_merge(array($this->courseid), $this->userselect_params);
$sql = "SELECT g.*
FROM {$CFG->prefix}grade_items gi,
{$CFG->prefix}grade_grades g
WHERE g.itemid = gi.id AND gi.courseid = {$this->courseid} {$this->userselect}";
FROM {grade_items} gi,
{grade_grades} g
WHERE g.itemid = gi.id AND gi.courseid = ? {$this->userselect}";
$userids = array_keys($this->users);
if ($grades = get_records_sql($sql)) {
if ($grades = $DB->get_records_sql($sql, $params)) {
foreach ($grades as $graderec) {
if (in_array($graderec->userid, $userids) and array_key_exists($graderec->itemid, $this->gtree->items)) { // some items may not be present!!
if (in_array($graderec->userid, $userids) and array_key_exists($graderec->itemid, $this->gtree->get_items())) { // some items may not be present!!
$this->grades[$graderec->userid][$graderec->itemid] = new grade_grade($graderec, false);
$this->grades[$graderec->userid][$graderec->itemid]->grade_item =& $this->gtree->items[$graderec->itemid]; // db caching
$this->grades[$graderec->userid][$graderec->itemid]->grade_item =& $this->gtree->get_item($graderec->itemid); // db caching
}
}
}
// prefil grades that do not exist yet
foreach ($userids as $userid) {
foreach ($this->gtree->items as $itemid=>$unused) {
foreach ($this->gtree->get_items() as $itemid=>$unused) {
if (!isset($this->grades[$userid][$itemid])) {
$this->grades[$userid][$itemid] = new grade_grade();
$this->grades[$userid][$itemid]->itemid = $itemid;
$this->grades[$userid][$itemid]->userid = $userid;
$this->grades[$userid][$itemid]->grade_item =& $this->gtree->items[$itemid]; // db caching
$this->grades[$userid][$itemid]->grade_item =& $this->gtree->get_item($itemid); // db caching
}
}
}
@ -388,7 +400,7 @@ class grade_report_grader extends grade_report {
* Builds and returns a div with on/off toggles.
* @return string HTML code
*/
function get_toggles_html() {
public function get_toggles_html() {
global $CFG, $USER;
$html = '<div id="grade-report-toggles">';
@ -434,7 +446,7 @@ class grade_report_grader extends grade_report {
* @param bool $return Whether to return the HTML string rather than printing it
* @return void
*/
function print_toggle($type, $return=false) {
public function print_toggle($type, $return=false) {
global $CFG;
$icons = array('eyecons' => 't/hide.gif',
@ -488,7 +500,7 @@ class grade_report_grader extends grade_report {
* Builds and returns the HTML code for the headers.
* @return string $headerhtml
*/
function get_headerhtml() {
public function get_headerhtml() {
global $CFG, $USER;
$strsortasc = $this->get_lang_string('sortasc', 'grades');
@ -519,12 +531,12 @@ class grade_report_grader extends grade_report {
// Prepare Table Headers
$headerhtml = '';
$numrows = count($this->gtree->levels);
$numrows = count($this->gtree->get_levels());
$columns_to_unset = array();
foreach ($this->gtree->levels as $key=>$row) {
foreach ($this->gtree->get_levels() as $key=>$row) {
$columncount = 0;
if ($key == 0) {
// do not display course grade category
@ -644,7 +656,7 @@ class grade_report_grader extends grade_report {
* Builds and return the HTML rows of the table (grades headed by student).
* @return string HTML
*/
function get_studentshtml() {
public function get_studentshtml() {
global $CFG, $USER, $DB;
$studentshtml = '';
@ -659,7 +671,7 @@ class grade_report_grader extends grade_report {
$scales_list = array();
$tabindices = array();
foreach ($this->gtree->items as $item) {
foreach ($this->gtree->get_items() as $item) {
if (!empty($item->scaleid)) {
$scales_list[] = $item->scaleid;
}
@ -673,7 +685,7 @@ class grade_report_grader extends grade_report {
if (!empty($scales_list)) {
$scales_array = $DB->get_records_list('scale', 'id', $scales_list);
}
$row_classes = array(' even ', ' odd ');
$row_classes = array(' even ', ' odd ');
@ -684,7 +696,7 @@ class grade_report_grader extends grade_report {
$altered = array();
$unknown = array();
} else {
$hiding_affected = grade_grade::get_hiding_affected($this->grades[$userid], $this->gtree->items);
$hiding_affected = grade_grade::get_hiding_affected($this->grades[$userid], $this->gtree->get_items());
$altered = $hiding_affected['altered'];
$unknown = $hiding_affected['unknown'];
unset($hiding_affected);
@ -707,8 +719,8 @@ class grade_report_grader extends grade_report {
$user->idnumber.'</a></th>';
}
foreach ($this->gtree->items as $itemid=>$unused) {
$item =& $this->gtree->items[$itemid];
foreach ($this->gtree->get_items() as $itemid=>$unused) {
$item =& $this->gtree->get_item($itemid);
$grade = $this->grades[$userid][$item->id];
// Get the decimal points preference for this item
@ -769,7 +781,7 @@ class grade_report_grader extends grade_report {
$hidden = ' hidden ';
}
$gradepass = ' gradefail ';
$gradepass = ' gradefail ';
if ($grade->is_passed($item)) {
$gradepass = ' gradepass ';
} elseif (is_null($grade->is_passed($item))) {
@ -891,8 +903,8 @@ class grade_report_grader extends grade_report {
* @param bool $grouponly Whether to return only group averages or all averages.
* @return string HTML
*/
function get_avghtml($grouponly=false) {
global $CFG, $USER;
public function get_avghtml($grouponly=false) {
global $CFG, $USER, $DB;
if (!$this->canviewhidden) {
// totals might be affected by hiding, if user can not see hidden grades the aggregations might be altered
@ -914,12 +926,14 @@ class grade_report_grader extends grade_report {
$showaverages = $this->currentgroup && $this->get_pref('showgroups');
$groupsql = $this->groupsql;
$groupwheresql = $this->groupwheresql;
$groupwheresql_params = $this->groupwheresql_params;
$avgcssclass = 'groupavg';
} else {
$straverage = get_string('overallaverage', 'grades');
$showaverages = $this->get_pref('showaverages');
$groupsql = "";
$groupwheresql = "";
$groupwheresql_params = array();
}
if ($shownumberofgrades) {
@ -928,23 +942,26 @@ class grade_report_grader extends grade_report {
$totalcount = $this->get_numusers($grouponly);
list($usql, $roles_params) = $DB->get_in_or_equal(explode(',', $this->gradebookroles));
if ($showaverages) {
$params = array_merge(array($this->courseid), $roles_params, $groupwheresql_params);
// find sums of all grade items in course
$SQL = "SELECT g.itemid, SUM(g.finalgrade) AS sum
FROM {$CFG->prefix}grade_items gi
JOIN {$CFG->prefix}grade_grades g ON g.itemid = gi.id
JOIN {$CFG->prefix}user u ON u.id = g.userid
JOIN {$CFG->prefix}role_assignments ra ON ra.userid = u.id
FROM {grade_items} gi
JOIN {grade_grades} g ON g.itemid = gi.id
JOIN {user} u ON u.id = g.userid
JOIN {role_assignments} ra ON ra.userid = u.id
$groupsql
WHERE gi.courseid = $this->courseid
AND ra.roleid in ($this->gradebookroles)
WHERE gi.courseid = ?
AND ra.roleid $usql
AND ra.contextid ".get_related_contexts_string($this->context)."
AND g.finalgrade IS NOT NULL
$groupwheresql
GROUP BY g.itemid";
$sum_array = array();
if ($sums = get_records_sql($SQL)) {
if ($sums = $DB->get_records_sql($SQL, $params)) {
foreach ($sums as $itemid => $csum) {
$sum_array[$itemid] = $csum->sum;
}
@ -964,20 +981,21 @@ class grade_report_grader extends grade_report {
// MDL-10875 Empty grades must be evaluated as grademin, NOT always 0
// This query returns a count of ungraded grades (NULL finalgrade OR no matching record in grade_grades table)
$params = array_merge(array($this->courseid), $roles_params, $groupwheresql_params);
$SQL = "SELECT gi.id, COUNT(u.id) AS count
FROM {$CFG->prefix}grade_items gi
CROSS JOIN {$CFG->prefix}user u
JOIN {$CFG->prefix}role_assignments ra ON ra.userid = u.id
LEFT OUTER JOIN {$CFG->prefix}grade_grades g ON (g.itemid = gi.id AND g.userid = u.id AND g.finalgrade IS NOT NULL)
FROM {grade_items} gi
CROSS JOIN {user} u
JOIN {role_assignments} ra ON ra.userid = u.id
LEFT OUTER JOIN {grade_grades} g ON (g.itemid = gi.id AND g.userid = u.id AND g.finalgrade IS NOT NULL)
$groupsql
WHERE gi.courseid = $this->courseid
AND ra.roleid in ($this->gradebookroles)
WHERE gi.courseid = ?
AND ra.roleid $usql
AND ra.contextid ".get_related_contexts_string($this->context)."
AND g.id IS NULL
$groupwheresql
GROUP BY gi.id";
$ungraded_counts = get_records_sql($SQL);
$ungraded_counts = $DB->get_records_sql($SQL, $params);
foreach ($this->gtree->items as $itemid=>$unused) {
$item =& $this->gtree->items[$itemid];
@ -1049,7 +1067,7 @@ class grade_report_grader extends grade_report {
* Builds and return the HTML row of ranges for each column (i.e. range).
* @return string HTML
*/
function get_rangehtml() {
public function get_rangehtml() {
global $USER;
$showuseridnumber = $this->get_pref('showuseridnumber');
@ -1071,8 +1089,8 @@ class grade_report_grader extends grade_report {
$columncount++;
}
foreach ($this->gtree->items as $itemid=>$unused) {
$item =& $this->gtree->items[$itemid];
foreach ($this->gtree->get_items() as $itemid=>$unused) {
$item =& $this->gtree->get_item($itemid);
// Determine which display type to use for this average
if ($USER->gradeediting[$this->courseid]) {
@ -1113,12 +1131,12 @@ class grade_report_grader extends grade_report {
}
return $scalehtml;
}
/**
* Builds and return the HTML row of ranges for each column (i.e. range).
* @return string HTML
*/
function get_iconshtml() {
public function get_iconshtml() {
global $USER;
$iconshtml = '';
@ -1133,10 +1151,10 @@ class grade_report_grader extends grade_report {
. '<th class="header c0 range" scope="row" '.$colspan.'>'.$this->get_lang_string('controls','grades').'</th>';
$columncount = 1;
foreach ($this->gtree->items as $itemid=>$unused) {
foreach ($this->gtree->get_items() as $itemid=>$unused) {
// emulate grade element
$item =& $this->gtree->items[$itemid];
$item =& $this->gtree->get_item($itemid);
$eid = $this->gtree->get_item_eid($item);
$element = $this->gtree->locate_element($eid);
@ -1155,7 +1173,7 @@ class grade_report_grader extends grade_report {
* @param object $object
* @return string HTML
*/
function get_icons($element) {
protected function get_icons($element) {
global $CFG, $USER;
if (!$USER->gradeediting[$this->courseid]) {
@ -1191,7 +1209,7 @@ class grade_report_grader extends grade_report {
* @param object $object
* @return string HTML
*/
function get_collapsing_icon($element) {
protected function get_collapsing_icon($element) {
global $CFG;
$contract_expand_icon = '';
@ -1223,7 +1241,7 @@ class grade_report_grader extends grade_report {
* @param string $action Which action to take (edit, delete etc...)
* @return
*/
function process_action($target, $action) {
public function process_action($target, $action) {
// TODO: this code should be in some grade_tree static method
$targettype = substr($target, 0, 1);
$targetid = substr($target, 1);

View File

@ -34,18 +34,18 @@ require_once($CFG->libdir.'/gradelib.php');
* @abstract
* @package gradebook
*/
class grade_report {
abstract class grade_report {
/**
* The courseid.
* @var int $courseid
*/
var $courseid;
public $courseid;
/**
* The course.
* @var object $course
*/
var $course;
public $course;
/** Grade plugin return tracking object.
var $gpr;
@ -54,49 +54,49 @@ class grade_report {
* The context.
* @var int $context
*/
var $context;
public $context;
/**
* The grade_tree object.
* @var object $gtree
*/
var $gtree;
public $gtree;
/**
* User preferences related to this report.
* @var array $prefs
*/
var $prefs = array();
public $prefs = array();
/**
* The roles for this report.
* @var string $gradebookroles
*/
var $gradebookroles;
public $gradebookroles;
/**
* base url for sorting by first/last name.
* @var string $baseurl
*/
var $baseurl;
public $baseurl;
/**
* base url for paging.
* @var string $pbarurl
*/
var $pbarurl;
public $pbarurl;
/**
* Current page (for paging).
* @var int $page
*/
var $page;
public $page;
/**
* Array of cached language strings (using get_string() all the time takes a long time!).
* @var array $lang_strings
*/
var $lang_strings = array();
public $lang_strings = array();
//// GROUP VARIABLES (including SQL)
@ -104,25 +104,31 @@ class grade_report {
* The current group being displayed.
* @var int $currentgroup
*/
var $currentgroup;
public $currentgroup;
/**
* A HTML select element used to select the current group.
* @var string $group_selector
*/
var $group_selector;
public $group_selector;
/**
* An SQL fragment used to add linking information to the group tables.
* @var string $groupsql
*/
var $groupsql;
protected $groupsql;
/**
* An SQL constraint to append to the queries used by this object to build the report.
* @var string $groupwheresql
*/
var $groupwheresql;
protected $groupwheresql;
/**
* The ordered params for $groupwheresql
* @var array $groupwheresql_params
*/
protected $groupwheresql_params = array();
/**
@ -132,7 +138,7 @@ class grade_report {
* @param string $context
* @param int $page The current page being viewed (when report is paged)
*/
function grade_report($courseid, $gpr, $context, $page=null) {
public function __construct($courseid, $gpr, $context, $page=null) {
global $CFG, $COURSE;
if (empty($CFG->gradebookroles)) {
@ -167,7 +173,7 @@ class grade_report {
* @param int $objectid An optional itemid or categoryid to check for a more fine-grained preference
* @return mixed The value of the preference
*/
function get_pref($pref, $objectid=null) {
public function get_pref($pref, $objectid=null) {
global $CFG;
$fullprefname = 'grade_report_' . $pref;
$shortprefname = 'grade_' . $pref;
@ -180,7 +186,7 @@ class grade_report {
} elseif (isset($CFG->$fullprefname)) {
$retval = get_user_preferences($fullprefname, $CFG->$fullprefname);
} elseif (isset($CFG->$shortprefname)) {
$retval = get_user_preferences($fullprefname, $CFG->$shortprefname);
$retval = get_user_preferences($fullprefname, $CFG->$shortprefname);
} else {
$retval = null;
}
@ -215,7 +221,7 @@ class grade_report {
* @param int $itemid An optional itemid to which the preference will be assigned
* @return bool Success or failure.
*/
function set_pref($pref, $pref_value='default', $itemid=null) {
public function set_pref($pref, $pref_value='default', $itemid=null) {
$fullprefname = 'grade_report_' . $pref;
if ($pref_value == 'default') {
return unset_user_preference($fullprefname.$itemid);
@ -230,9 +236,7 @@ class grade_report {
* @param array $data
* @return mixed True or array of errors
*/
function process_data($data) {
// Implement in children classes
}
abstract function process_data($data);
/**
* Processes a single action against a category, grade_item or grade.
@ -240,9 +244,7 @@ class grade_report {
* @param string $action Which action to take (edit, delete etc...)
* @return
*/
function process_action($target, $action) {
//implement if needed
}
abstract function process_action($target, $action);
/**
* First checks the cached language strings, then returns match if found, or uses get_string()
@ -251,7 +253,7 @@ class grade_report {
* @param string $section Optional language section
* @return string
*/
function get_lang_string($strcode, $section=null) {
public function get_lang_string($strcode, $section=null) {
if (empty($this->lang_strings[$strcode])) {
$this->lang_strings[$strcode] = get_string($strcode, $section);
}
@ -263,31 +265,34 @@ class grade_report {
* @param boolean $groups include groups limit
* @return int Count of users
*/
function get_numusers($groups=true) {
global $CFG;
public function get_numusers($groups=true) {
global $CFG, $DB;
$groupsql = "";
$groupwheresql = "";
list($usql, $params) = $DB->get_in_or_equal(explode(',', $this->gradebookroles));
if ($groups) {
$groupsql = $this->groupsql;
$groupwheresql = $this->groupwheresql;
$params = array_merge($params, $this->groupwheresql_params);
}
$countsql = "SELECT COUNT(DISTINCT u.id)
FROM {$CFG->prefix}grade_grades g RIGHT OUTER JOIN
{$CFG->prefix}user u ON u.id = g.userid
LEFT JOIN {$CFG->prefix}role_assignments ra ON u.id = ra.userid
FROM {grade_grades} g RIGHT OUTER JOIN
{user} u ON u.id = g.userid
LEFT JOIN {role_assignments} ra ON u.id = ra.userid
$groupsql
WHERE ra.roleid in ($this->gradebookroles)
WHERE ra.roleid $usql
$groupwheresql
AND ra.contextid ".get_related_contexts_string($this->context);
return count_records_sql($countsql);
return $DB->count_records_sql($countsql, $params);
}
/**
* Sets up this object's group variables, mainly to restrict the selection of users to display.
*/
function setup_groups() {
private function setup_groups() {
global $CFG;
/// find out current groups mode
@ -295,8 +300,9 @@ class grade_report {
$this->currentgroup = groups_get_course_group($this->course);
if ($this->currentgroup) {
$this->groupsql = " LEFT JOIN {$CFG->prefix}groups_members gm ON gm.userid = u.id ";
$this->groupwheresql = " AND gm.groupid = $this->currentgroup ";
$this->groupsql = " LEFT JOIN {groups_members} gm ON gm.userid = u.id ";
$this->groupwheresql = " AND gm.groupid = ? ";
$this->groupwheresql_params = array($this->currentgroup);
}
}
@ -306,7 +312,7 @@ class grade_report {
* @param string $sort_link
* @param string HTML
*/
function get_sort_arrow($direction='move', $sort_link=null) {
protected function get_sort_arrow($direction='move', $sort_link=null) {
$matrix = array('up' => 'asc', 'down' => 'desc', 'move' => 'desc');
$strsort = $this->get_lang_string('sort' . $matrix[$direction]);
$arrow = print_arrow($direction, $strsort, true);

View File

@ -64,7 +64,7 @@ foreach ($outcomes as $outcomeid => $outcome) {
if (is_array($report_info[$outcomeid]['items'])) {
foreach ($report_info[$outcomeid]['items'] as $itemid => $item) {
$sql = "SELECT itemid, AVG(finalgrade) AS avg, COUNT(finalgrade) AS count
FROM {$CFG->prefix}grade_grades
FROM {grade_grades}
WHERE itemid = $itemid
GROUP BY itemid";
$info = get_records_sql($sql);

View File

@ -141,7 +141,7 @@ class grade_report_overview extends grade_report {
} else if (!is_null($finalgrade)) {
/// find the number of users with a higher grade
$sql = "SELECT COUNT(DISTINCT(userid))
FROM {$CFG->prefix}grade_grades
FROM {grade_grades}
WHERE finalgrade IS NOT NULL AND finalgrade > $finalgrade
AND itemid = {$grade_item->id}";
$rank = count_records_sql($sql) + 1;
@ -202,7 +202,7 @@ function grade_report_overview_settings_definition(&$mform) {
}
$mform->addElement('select', 'report_overview_showrank', get_string('showrank', 'grades'), $options);
$mform->setHelpButton('report_overview_showrank', array('showrank', get_string('showrank', 'grades'), 'grade'));
$mform->setHelpButton('report_overview_showrank', array('showrank', get_string('showrank', 'grades'), 'grade'));
}
?>

View File

@ -265,7 +265,7 @@ class grade_report_user extends grade_report {
} else {
/// find the number of users with a higher grade
$sql = "SELECT COUNT(DISTINCT(userid))
FROM {$CFG->prefix}grade_grades
FROM {grade_grades}
WHERE finalgrade > {$grade_grade->finalgrade}
AND itemid = {$grade_item->id}";
$rank = count_records_sql($sql) + 1;
@ -327,7 +327,7 @@ function grade_report_user_settings_definition(&$mform) {
}
$mform->addElement('select', 'report_user_showrank', get_string('showrank', 'grades'), $options);
$mform->setHelpButton('report_user_showrank', array('showrank', get_string('showrank', 'grades'), 'grade'));
$mform->setHelpButton('report_user_showrank', array('showrank', get_string('showrank', 'grades'), 'grade'));
$options = array(-1 => get_string('default', 'grades'),
0 => get_string('hide'),
@ -341,7 +341,7 @@ function grade_report_user_settings_definition(&$mform) {
}
$mform->addElement('select', 'report_user_showhiddenitems', get_string('showhiddenitems', 'grades'), $options);
$mform->setHelpButton('report_user_showhiddenitems', array('showhiddenitems', get_string('showhiddenitems', 'grades'), 'grade'));
$mform->setHelpButton('report_user_showhiddenitems', array('showhiddenitems', get_string('showhiddenitems', 'grades'), 'grade'));
}
function grade_report_user_profilereport($course, $user) {

View File

@ -1212,7 +1212,7 @@ abstract class moodle_database {
/**
* Returns SQL WHERE conditions
* @param array conditions - must not contain numeric indexes
* @return array sql part and params
* @return array sql part and params
*/
public function where_clause(array $conditions=null) {
$allowed_types = $this->allowed_param_types();

View File

@ -1,10 +1,10 @@
<?php //$Id$
/**
* Abstarct class for resultsets returned from database functions.
* Abstract class for resultsets returned from database functions.
* This is a simple Iterator with needed recorset closing support.
*
* The differnece from old recorset is that the records are returned
* The difference from old recorset is that the records are returned
* as objects, not arrays. You should use "foreach ($recordset as $record) {}"
* followed by "$recordset->close()".
*
@ -47,4 +47,4 @@ abstract class moodle_recordset implements Iterator {
* @return void
*/
public abstract function close();
}
}

View File

@ -145,7 +145,7 @@ abstract class grade_object {
* @static final protected
* @return mixed array of object instances or false if not found
*/
protected static function fetch_all_helper($table, $classname, $params) {
public static function fetch_all_helper($table, $classname, $params) {
$instance = new $classname();
$classvars = (array)$instance;
@ -153,9 +153,6 @@ abstract class grade_object {
$wheresql = array();
// remove incorrect params
$params = array();
foreach ($params as $var=>$value) {
if (!in_array($var, $instance->required_fields) and !array_key_exists($var, $instance->optional_fields)) {
continue;