MDL-14967 DB upgrades. All done. Just bug fixing now ;)
This commit is contained in:
@@ -80,7 +80,7 @@ $mform->set_data($data);
|
||||
if ($mform->is_cancelled()) {
|
||||
redirect($returnurl);
|
||||
|
||||
} else if ($data = $mform->get_data()) {
|
||||
} else if ($data = $mform->get_data(false)) {
|
||||
if (!$admin and empty($data->override)) {
|
||||
$DB->delete_records('grade_letters', array('contextid' => $context->id));
|
||||
redirect($returnurl);
|
||||
|
||||
@@ -105,7 +105,7 @@ foreach ($standardoutcomes as $oid=>$outcome) {
|
||||
|
||||
|
||||
/// form processing
|
||||
if ($data = data_submitted()) {
|
||||
if ($data = data_submitted(false)) {
|
||||
require_capability('moodle/grade:manageoutcomes', $context);
|
||||
if (!empty($data->add) && !empty($data->addoutcomes)) {
|
||||
/// add all selected to course list
|
||||
|
||||
@@ -56,7 +56,7 @@ $gpr = new grade_plugin_return(array('type'=>'edit', 'plugin'=>'outcome', 'cours
|
||||
require_once('import_outcomes_form.php');
|
||||
$upload_form = new import_outcomes_form();
|
||||
|
||||
if ($upload_form_data = $upload_form->get_data()) {
|
||||
if ($upload_form_data = $upload_form->get_data(false)) {
|
||||
require_once('import.php');
|
||||
exit();
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ $mform->set_data($settings);
|
||||
if ($mform->is_cancelled()) {
|
||||
redirect($returnurl);
|
||||
|
||||
} else if ($data = $mform->get_data()) {
|
||||
} else if ($data = $mform->get_data(false)) {
|
||||
$data = (array)$data;
|
||||
$general = array('displaytype', 'decimalpoints', 'aggregationposition');
|
||||
foreach ($data as $key=>$value) {
|
||||
|
||||
@@ -33,7 +33,7 @@ $id = required_param('id', PARAM_INT);
|
||||
$section = optional_param('section', 'calculation', PARAM_ALPHA);
|
||||
$idnumbers = optional_param('idnumbers', null, PARAM_RAW);
|
||||
|
||||
if (!$course = get_record('course', 'id', $courseid)) {
|
||||
if (!$course = $DB->get_record('course', array('id' => $courseid))) {
|
||||
print_error('nocourseid');
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ if (!$grade_item = grade_item::fetch(array('id'=>$id, 'courseid'=>$course->id)))
|
||||
|
||||
// activity items and items without grade can not have calculation
|
||||
if ($grade_item->is_external_item() or ($grade_item->gradetype != GRADE_TYPE_VALUE and $grade_item->gradetype != GRADE_TYPE_SCALE)) {
|
||||
redirect($returnurl, get_string('errornocalculationallowed', 'grades'));
|
||||
redirect($returnurl, get_string('errornocalculationallowed', 'grades'));
|
||||
}
|
||||
|
||||
$mform = new edit_calculation_form(null, array('gpr'=>$gpr, 'itemid' => $grade_item->id));
|
||||
|
||||
@@ -31,7 +31,7 @@ require_once 'category_form.php';
|
||||
$courseid = required_param('courseid', PARAM_INT);
|
||||
$id = optional_param('id', 0, PARAM_INT);
|
||||
|
||||
if (!$course = get_record('course', 'id', $courseid)) {
|
||||
if (!$course = $DB->get_record('course', array('id' => $courseid))) {
|
||||
print_error('nocourseid');
|
||||
}
|
||||
|
||||
|
||||
@@ -234,7 +234,7 @@ class edit_category_form extends moodleform {
|
||||
$mform->setHelpButton('aggregationcoef', array('aggregationcoef', get_string('aggregationcoef', 'grades'), 'grade'), true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
if ($grade_item->is_calculated()) {
|
||||
@@ -258,7 +258,7 @@ class edit_category_form extends moodleform {
|
||||
$mform->removeElement('aggregatesubcats');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// If it is a course category, remove the "required" rule from the "fullname" element
|
||||
if ($grade_category->is_course_category()) {
|
||||
unset($mform->_rules['fullname']);
|
||||
@@ -268,8 +268,8 @@ class edit_category_form extends moodleform {
|
||||
|
||||
// If it is a course category and its fullname is ?, show an empty field
|
||||
if ($grade_category->is_course_category() && $mform->getElementValue('fullname') == '?') {
|
||||
$mform->setDefault('fullname', '');
|
||||
}
|
||||
$mform->setDefault('fullname', '');
|
||||
}
|
||||
}
|
||||
|
||||
// no parent header for course category
|
||||
@@ -277,7 +277,7 @@ class edit_category_form extends moodleform {
|
||||
$mform->removeElement('headerparent');
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
@@ -33,7 +33,7 @@ $id = optional_param('id', 0, PARAM_INT);
|
||||
$itemid = optional_param('itemid', 0, PARAM_INT);
|
||||
$userid = optional_param('userid', 0, PARAM_INT);
|
||||
|
||||
if (!$course = get_record('course', 'id', $courseid)) {
|
||||
if (!$course = $DB->get_record('course', array('id' => $courseid))) {
|
||||
print_error('nocourseid');
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ $returnurl = $gpr->get_return_url($CFG->wwwroot.'/grade/report.php?id='.$course-
|
||||
|
||||
// security checks!
|
||||
if (!empty($id)) {
|
||||
if (!$grade = get_record('grade_grades', 'id', $id)) {
|
||||
if (!$grade = $DB->get_record('grade_grades', array('id' => $id))) {
|
||||
print_error('invalidgroupid');
|
||||
}
|
||||
|
||||
@@ -92,7 +92,7 @@ if (groups_get_course_groupmode($COURSE) == SEPARATEGROUPS and !has_capability('
|
||||
|
||||
$mform = new edit_grade_form(null, array('grade_item'=>$grade_item, 'gpr'=>$gpr));
|
||||
|
||||
if ($grade = get_record('grade_grades', 'itemid', $grade_item->id, 'userid', $userid)) {
|
||||
if ($grade = $DB->get_record('grade_grades', array('itemid' => $grade_item->id, 'userid' => $userid))) {
|
||||
|
||||
// always clean existing feedback - grading should not have XSS risk
|
||||
if (can_use_html_editor()) {
|
||||
|
||||
@@ -28,7 +28,7 @@ require_once $CFG->libdir.'/formslib.php';
|
||||
class edit_grade_form extends moodleform {
|
||||
|
||||
function definition() {
|
||||
global $CFG, $COURSE;
|
||||
global $CFG, $COURSE, $DB;
|
||||
|
||||
$mform =& $this->_form;
|
||||
|
||||
@@ -60,7 +60,7 @@ class edit_grade_form extends moodleform {
|
||||
}
|
||||
|
||||
$i = 1;
|
||||
if ($scale = get_record('scale', 'id', $grade_item->scaleid)) {
|
||||
if ($scale = $DB->get_record('scale', array('id' => $grade_item->scaleid))) {
|
||||
foreach (split(",", $scale->scale) as $option) {
|
||||
$scaleopt[$i] = $option;
|
||||
$i++;
|
||||
@@ -124,7 +124,7 @@ class edit_grade_form extends moodleform {
|
||||
}
|
||||
|
||||
function definition_after_data() {
|
||||
global $CFG, $COURSE;
|
||||
global $CFG, $COURSE, $DB;
|
||||
|
||||
$context = get_context_instance(CONTEXT_COURSE, $COURSE->id);
|
||||
|
||||
@@ -133,7 +133,7 @@ class edit_grade_form extends moodleform {
|
||||
|
||||
// fill in user name if user still exists
|
||||
$userid = $mform->getElementValue('userid');
|
||||
if ($user = get_record('user', 'id', $userid)) {
|
||||
if ($user = $DB->get_record('user', array('id' => $userid))) {
|
||||
$username = '<a href="'.$CFG->wwwroot.'/user/view.php?id='.$userid.'">'.fullname($user).'</a>';
|
||||
$user_el =& $mform->getElement('user');
|
||||
$user_el->setValue($username);
|
||||
|
||||
@@ -34,7 +34,7 @@ $eid = optional_param('eid', 0, 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');
|
||||
}
|
||||
|
||||
@@ -258,7 +258,7 @@ function element_deletable($element) {
|
||||
}
|
||||
|
||||
$grade_item = $element['object'];
|
||||
|
||||
|
||||
if ($grade_item->itemtype != 'mod' or $grade_item->is_outcome_item() or $grade_item->gradetype == GRADE_TYPE_NONE) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ require_once 'item_form.php';
|
||||
$courseid = required_param('courseid', PARAM_INT);
|
||||
$id = optional_param('id', 0, PARAM_INT);
|
||||
|
||||
if (!$course = get_record('course', 'id', $courseid)) {
|
||||
if (!$course = $DB->get_record('course', array('id' => $courseid))) {
|
||||
print_error('nocourseid');
|
||||
}
|
||||
|
||||
|
||||
@@ -26,10 +26,10 @@
|
||||
require_once $CFG->libdir.'/formslib.php';
|
||||
|
||||
class edit_item_form extends moodleform {
|
||||
var $displayoptions;
|
||||
private $displayoptions;
|
||||
|
||||
function definition() {
|
||||
global $COURSE, $CFG;
|
||||
global $COURSE, $CFG, $DB;
|
||||
|
||||
$mform =& $this->_form;
|
||||
|
||||
@@ -57,7 +57,7 @@ class edit_item_form extends moodleform {
|
||||
//$mform->disabledIf('calculation', 'gradetype', 'eq', GRADE_TYPE_NONE);
|
||||
|
||||
$options = array(0=>get_string('usenoscale', 'grades'));
|
||||
if ($scales = get_records('scale')) {
|
||||
if ($scales = $DB->get_records('scale')) {
|
||||
foreach ($scales as $scale) {
|
||||
$options[$scale->id] = format_string($scale->name);
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ require_once 'outcomeitem_form.php';
|
||||
$courseid = required_param('courseid', PARAM_INT);
|
||||
$id = optional_param('id', 0, PARAM_INT);
|
||||
|
||||
if (!$course = get_record('course', 'id', $courseid)) {
|
||||
if (!$course = $DB->get_record('course', array('id' => $courseid))) {
|
||||
print_error('nocourseid');
|
||||
}
|
||||
|
||||
@@ -139,9 +139,10 @@ if ($data = $mform->get_data(false)) {
|
||||
$grade_item->itemnumber = 0;
|
||||
|
||||
} else {
|
||||
$module = get_record_sql("SELECT cm.*, m.name as modname
|
||||
$params = array($data->cmid);
|
||||
$module = $DB->get_record_sql("SELECT cm.*, m.name as modname
|
||||
FROM {modules} m, {course_modules} cm
|
||||
WHERE cm.id = {$data->cmid} AND cm.module = m.id ");
|
||||
WHERE cm.id = ? AND cm.module = m.id ", $params);
|
||||
$grade_item->itemtype = 'mod';
|
||||
$grade_item->itemmodule = $module->modname;
|
||||
$grade_item->iteminstance = $module->instance;
|
||||
|
||||
@@ -27,7 +27,7 @@ require_once $CFG->libdir.'/formslib.php';
|
||||
|
||||
class grade_export_form extends moodleform {
|
||||
function definition() {
|
||||
global $CFG, $COURSE, $USER;
|
||||
global $CFG, $COURSE, $USER, $DB;
|
||||
|
||||
$mform =& $this->_form;
|
||||
if (isset($this->_customdata)) { // hardcoding plugin names here is hacky
|
||||
@@ -42,8 +42,8 @@ class grade_export_form extends moodleform {
|
||||
$mform->setDefault('export_feedback', 0);
|
||||
|
||||
$options = array('10'=>10, '20'=>20, '100'=>100, '1000'=>1000, '100000'=>100000);
|
||||
$mform->addElement('select', 'previewrows', get_string('previewrows', 'grades'), $options);
|
||||
|
||||
$mform->addElement('select', 'previewrows', get_string('previewrows', 'grades'), $options);
|
||||
|
||||
if (!empty($features['updategradesonly'])) {
|
||||
$mform->addElement('advcheckbox', 'updatedgradesonly', get_string('updatedgradesonly', 'grades'));
|
||||
}
|
||||
@@ -53,7 +53,7 @@ class grade_export_form extends moodleform {
|
||||
$options = array(GRADE_DISPLAY_TYPE_REAL => get_string('real', 'grades'),
|
||||
GRADE_DISPLAY_TYPE_PERCENTAGE => get_string('percentage', 'grades'),
|
||||
GRADE_DISPLAY_TYPE_LETTER => get_string('letter', 'grades'));
|
||||
|
||||
|
||||
/*
|
||||
foreach ($options as $key=>$option) {
|
||||
if ($key == $default_gradedisplaytype) {
|
||||
@@ -62,9 +62,9 @@ class grade_export_form extends moodleform {
|
||||
}
|
||||
}
|
||||
*/
|
||||
$mform->addElement('select', 'display', get_string('gradeexportdisplaytype', 'grades'), $options);
|
||||
$mform->addElement('select', 'display', get_string('gradeexportdisplaytype', 'grades'), $options);
|
||||
$mform->setDefault('display', $CFG->grade_export_displaytype);
|
||||
|
||||
|
||||
//$default_gradedecimals = $CFG->grade_export_decimalpoints;
|
||||
$options = array(0=>0, 1=>1, 2=>2, 3=>3, 4=>4, 5=>5);
|
||||
$mform->addElement('select', 'decimals', get_string('gradeexportdecimalpoints', 'grades'), $options);
|
||||
@@ -87,7 +87,9 @@ class grade_export_form extends moodleform {
|
||||
if (!empty($CFG->gradepublishing) and !empty($features['publishing'])) {
|
||||
$mform->addElement('header', 'publishing', get_string('publishing', 'grades'));
|
||||
$options = array(get_string('nopublish', 'grades'), get_string('createnewkey', 'userkey'));
|
||||
if ($keys = get_records_select('user_private_key', "script='grade/export' AND instance={$COURSE->id} AND userid={$USER->id}")) {
|
||||
$keys = $DB->get_records_select('user_private_key', "script='grade/export' AND instance=? AND userid=?",
|
||||
array($COURSE->id, $USER->id));
|
||||
if ($keys) {
|
||||
foreach ($keys as $key) {
|
||||
$options[$key->value] = $key->value; // TODO: add more details - ip restriction, valid until ??
|
||||
}
|
||||
@@ -110,7 +112,7 @@ class grade_export_form extends moodleform {
|
||||
}
|
||||
|
||||
$mform->addElement('header', 'gradeitems', get_string('gradeitemsinc', 'grades'));
|
||||
|
||||
|
||||
$switch = grade_get_setting($COURSE->id, 'aggregationposition', $CFG->grade_aggregationposition);
|
||||
|
||||
// Grab the grade_seq for this course
|
||||
@@ -128,7 +130,7 @@ class grade_export_form extends moodleform {
|
||||
$needs_multiselect = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ($needs_multiselect) {
|
||||
$this->add_checkbox_controller(1, null, null, 1); // 1st argument is group name, 2nd is link text, 3rd is attributes and 4th is original value
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ $delete = optional_param('delete', 0, PARAM_BOOL);
|
||||
$confirm = optional_param('confirm', 0, PARAM_BOOL);
|
||||
|
||||
if ($id) {
|
||||
if (!$key = get_record('user_private_key', 'id', $id)) {
|
||||
if (!$key = $DB->get_record('user_private_key', array('id' => $id))) {
|
||||
print_error('invalidgroupid');
|
||||
}
|
||||
if (empty($courseid)) {
|
||||
@@ -43,12 +43,12 @@ if ($id) {
|
||||
print_error('invalidcourseid');
|
||||
}
|
||||
|
||||
if (!$course = get_record('course', 'id', $courseid)) {
|
||||
if (!$course = $DB->get_record('course', array('id'=>$id))) {
|
||||
print_error('invalidcourseid');
|
||||
}
|
||||
|
||||
} else {
|
||||
if (!$course = get_record('course', 'id', $courseid)) {
|
||||
if (!$course = $DB->get_record('course', array('id'=>$id))) {
|
||||
print_error('invalidcourseid');
|
||||
}
|
||||
$key = new object();
|
||||
@@ -77,7 +77,7 @@ if ($id and $delete) {
|
||||
die;
|
||||
|
||||
} else if (confirm_sesskey()){
|
||||
delete_records('user_private_key', 'id', $id);
|
||||
$DB->delete_records('user_private_key', array('id' => $id));
|
||||
redirect('keymanager.php?id='.$course->id);
|
||||
}
|
||||
}
|
||||
@@ -89,14 +89,14 @@ $editform->set_data($key);
|
||||
if ($editform->is_cancelled()) {
|
||||
redirect($returnurl);
|
||||
|
||||
} elseif ($data = $editform->get_data()) {
|
||||
} elseif ($data = $editform->get_data(false)) {
|
||||
|
||||
if ($data->id) {
|
||||
$record = new object();
|
||||
$record->id = $data->id;
|
||||
$record->iprestriction = $data->iprestriction;
|
||||
$record->validuntil = $data->validuntil;
|
||||
update_record('user_private_key', $record);
|
||||
$DB->update_record('user_private_key', $record);
|
||||
} else {
|
||||
create_user_key('grade/export', $USER->id, $course->id, $data->iprestriction, $data->validuntil);
|
||||
}
|
||||
|
||||
@@ -47,7 +47,8 @@ $stredit = get_string('edit');
|
||||
$strdelete = get_string('delete');
|
||||
|
||||
$data = array();
|
||||
if ($keys = get_records_select('user_private_key', "script='grade/export' AND instance={$course->id} AND userid={$USER->id}")) {
|
||||
$keys = $DB->get_records_select('user_private_key', "script='grade/export' AND instance=? AND userid=?", array($course->id, $USER->id));
|
||||
if ($keys) {
|
||||
foreach($keys as $key) {
|
||||
$line = array();
|
||||
$line[0] = format_string($key->value);
|
||||
|
||||
+35
-32
@@ -30,25 +30,26 @@ require_once($CFG->dirroot.'/grade/export/grade_export_form.php');
|
||||
/**
|
||||
* Base export class
|
||||
*/
|
||||
class grade_export {
|
||||
abstract class grade_export {
|
||||
|
||||
var $plugin; // plgin name - must be filled in subclasses!
|
||||
public $plugin; // plgin name - must be filled in subclasses!
|
||||
|
||||
var $grade_items; // list of all course grade items
|
||||
var $groupid; // groupid, 0 means all groups
|
||||
var $course; // course object
|
||||
var $columns; // array of grade_items selected for export
|
||||
public $grade_items; // list of all course grade items
|
||||
public $groupid; // groupid, 0 means all groups
|
||||
public $course; // course object
|
||||
public $columns; // array of grade_items selected for export
|
||||
|
||||
var $previewrows; // number of rows in preview
|
||||
var $export_letters; // export letters
|
||||
var $export_feedback; // export feedback
|
||||
var $userkey; // export using private user key
|
||||
public $previewrows; // number of rows in preview
|
||||
public $export_letters; // export letters
|
||||
public $export_feedback; // export feedback
|
||||
public $userkey; // export using private user key
|
||||
|
||||
var $updatedgradesonly; // only export updated grades
|
||||
var $displaytype; // display type (e.g. real, percentages, letter) for exports
|
||||
var $decimalpoints; // number of decimal points for exports
|
||||
public $updatedgradesonly; // only export updated grades
|
||||
public $displaytype; // display type (e.g. real, percentages, letter) for exports
|
||||
public $decimalpoints; // number of decimal points for exports
|
||||
/**
|
||||
* Constructor should set up all the private variables ready to be pulled
|
||||
* @access public
|
||||
* @param object $course
|
||||
* @param int $groupid id of selected group, 0 means all
|
||||
* @param string $itemlist comma separated list of item ids, empty means all
|
||||
@@ -56,7 +57,7 @@ class grade_export {
|
||||
* @param boolean $export_letters
|
||||
* @note Exporting as letters will lead to data loss if that exported set it re-imported.
|
||||
*/
|
||||
function grade_export($course, $groupid=0, $itemlist='', $export_feedback=false, $updatedgradesonly = false, $displaytype = GRADE_DISPLAY_TYPE_REAL, $decimalpoints = 2) {
|
||||
public function grade_export($course, $groupid=0, $itemlist='', $export_feedback=false, $updatedgradesonly = false, $displaytype = GRADE_DISPLAY_TYPE_REAL, $decimalpoints = 2) {
|
||||
$this->course = $course;
|
||||
$this->groupid = $groupid;
|
||||
$this->grade_items = grade_item::fetch_all(array('courseid'=>$this->course->id));
|
||||
@@ -131,7 +132,7 @@ class grade_export {
|
||||
* Update exported field in grade_grades table
|
||||
* @return boolean
|
||||
*/
|
||||
function track_exports() {
|
||||
public function track_exports() {
|
||||
global $CFG;
|
||||
|
||||
/// Whether this plugin is entitled to update export time
|
||||
@@ -151,7 +152,7 @@ class grade_export {
|
||||
* @param $object $grade instance of grade_grade class
|
||||
* @return string
|
||||
*/
|
||||
function format_grade($grade) {
|
||||
public function format_grade($grade) {
|
||||
return grade_format_gradevalue($grade->finalgrade, $this->grade_items[$grade->itemid], false, $this->displaytype, $this->decimalpoints);
|
||||
}
|
||||
|
||||
@@ -161,7 +162,7 @@ class grade_export {
|
||||
* @param boolena $feedback feedback colum
|
||||
* &return string
|
||||
*/
|
||||
function format_column_name($grade_item, $feedback=false) {
|
||||
public function format_column_name($grade_item, $feedback=false) {
|
||||
if ($grade_item->itemtype == 'mod') {
|
||||
$name = get_string('modulename', $grade_item->itemmodule).': '.$grade_item->get_name();
|
||||
} else {
|
||||
@@ -180,19 +181,19 @@ class grade_export {
|
||||
* @param object $feedback object with properties feedback and feedbackformat
|
||||
* @return string
|
||||
*/
|
||||
function format_feedback($feedback) {
|
||||
public function format_feedback($feedback) {
|
||||
return strip_tags(format_text($feedback->feedback, $feedback->feedbackformat));
|
||||
}
|
||||
|
||||
/**
|
||||
* Implemented by child class
|
||||
*/
|
||||
function print_grades() { }
|
||||
public abstract function print_grades();
|
||||
|
||||
/**
|
||||
* Prints preview of exported grades on screen as a feedback mechanism
|
||||
*/
|
||||
function display_preview() {
|
||||
public function display_preview() {
|
||||
|
||||
print_heading(get_string('previewrows', 'grades'));
|
||||
|
||||
@@ -270,7 +271,7 @@ class grade_export {
|
||||
* Returns array of parameters used by dump.php and export.php.
|
||||
* @return array
|
||||
*/
|
||||
function get_export_params() {
|
||||
public function get_export_params() {
|
||||
$itemids = array_keys($this->columns);
|
||||
|
||||
$params = array('id' =>$this->course->id,
|
||||
@@ -290,7 +291,7 @@ class grade_export {
|
||||
* or prints the URL for the published data.
|
||||
* @return void
|
||||
*/
|
||||
function print_continue() {
|
||||
public function print_continue() {
|
||||
global $CFG;
|
||||
|
||||
$params = $this->get_export_params();
|
||||
@@ -324,24 +325,26 @@ class grade_export {
|
||||
* It does internal buffering to speedup the db operations.
|
||||
*/
|
||||
class grade_export_update_buffer {
|
||||
var $update_list;
|
||||
var $export_time;
|
||||
public $update_list;
|
||||
public $export_time;
|
||||
|
||||
/**
|
||||
* Constructor - creates the buffer and initialises the time stamp
|
||||
*/
|
||||
function grade_export_update_buffer() {
|
||||
public function grade_export_update_buffer() {
|
||||
$this->update_list = array();
|
||||
$this->export_time = time();
|
||||
}
|
||||
|
||||
function flush($buffersize) {
|
||||
global $CFG;
|
||||
public function flush($buffersize) {
|
||||
global $CFG, $DB;
|
||||
|
||||
if (count($this->update_list) > $buffersize) {
|
||||
$list = implode(',', $this->update_list);
|
||||
$sql = "UPDATE {grade_grades} SET exported = {$this->export_time} WHERE id IN ($list)";
|
||||
execute_sql($sql, false);
|
||||
list($usql, $params) = $DB->get_in_or_equal($this->update_list);
|
||||
$params = array_merge(array($this->export_time), $params);
|
||||
|
||||
$sql = "UPDATE {grade_grades} SET exported = ? WHERE id $usql";
|
||||
$DB->execute_sql($sql, $params, false);
|
||||
$this->update_list = array();
|
||||
}
|
||||
}
|
||||
@@ -351,7 +354,7 @@ class grade_export_update_buffer {
|
||||
* @param object $grade_grade
|
||||
* @return string $status (unknow, new, regrade, nochange)
|
||||
*/
|
||||
function track($grade_grade) {
|
||||
public function track($grade_grade) {
|
||||
|
||||
if (empty($grade_grade->exported) or empty($grade_grade->timemodified)) {
|
||||
if (is_null($grade_grade->finalgrade)) {
|
||||
@@ -382,7 +385,7 @@ class grade_export_update_buffer {
|
||||
/**
|
||||
* Flush and close the buffer.
|
||||
*/
|
||||
function close() {
|
||||
public function close() {
|
||||
$this->flush(0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ require_once($CFG->dirroot.'/grade/export/lib.php');
|
||||
|
||||
class grade_export_ods extends grade_export {
|
||||
|
||||
var $plugin = 'ods';
|
||||
public $plugin = 'ods';
|
||||
|
||||
/**
|
||||
* To be implemented by child classes
|
||||
|
||||
@@ -54,7 +54,7 @@ if (!empty($CFG->gradepublishing)) {
|
||||
$mform = new grade_export_form(null, array('publishing' => true));
|
||||
|
||||
// process post information
|
||||
if ($data = $mform->get_data()) {
|
||||
if ($data = $mform->get_data(false)) {
|
||||
$export = new grade_export_ods($course, groups_get_course_group($course), '', false, false, $data->display, $data->decimals);
|
||||
|
||||
// print the grades on screen for feedbacks
|
||||
|
||||
@@ -26,29 +26,29 @@ require_once($CFG->dirroot.'/grade/export/lib.php');
|
||||
|
||||
class grade_export_txt extends grade_export {
|
||||
|
||||
var $plugin = 'txt';
|
||||
public $plugin = 'txt';
|
||||
|
||||
var $separator; // default separator
|
||||
public $separator; // default separator
|
||||
|
||||
function grade_export_txt($course, $groupid=0, $itemlist='', $export_feedback=false, $updatedgradesonly = false, $displaytype = GRADE_DISPLAY_TYPE_REAL, $decimalpoints = 2, $separator='comma') {
|
||||
public function grade_export_txt($course, $groupid=0, $itemlist='', $export_feedback=false, $updatedgradesonly = false, $displaytype = GRADE_DISPLAY_TYPE_REAL, $decimalpoints = 2, $separator='comma') {
|
||||
$this->grade_export($course, $groupid, $itemlist, $export_feedback, $updatedgradesonly, $displaytype, $decimalpoints);
|
||||
$this->separator = $separator;
|
||||
}
|
||||
|
||||
function process_form($formdata) {
|
||||
parent::process_form($formdata);
|
||||
public function __construct($formdata) {
|
||||
parent::__construct($formdata);
|
||||
if (isset($formdata->separator)) {
|
||||
$this->separator = $formdata->separator;
|
||||
}
|
||||
}
|
||||
|
||||
function get_export_params() {
|
||||
public function get_export_params() {
|
||||
$params = parent::get_export_params();
|
||||
$params['separator'] = $this->separator;
|
||||
return $params;
|
||||
}
|
||||
|
||||
function print_grades() {
|
||||
public function print_grades() {
|
||||
global $CFG;
|
||||
|
||||
$export_tracking = $this->track_exports();
|
||||
|
||||
@@ -54,7 +54,7 @@ if (!empty($CFG->gradepublishing)) {
|
||||
$mform = new grade_export_form(null, array('includeseparator'=>true, 'publishing' => true));
|
||||
|
||||
// process post information
|
||||
if ($data = $mform->get_data()) {
|
||||
if ($data = $mform->get_data(false)) {
|
||||
$export = new grade_export_txt($course, groups_get_course_group($course), '', false, false, $data->display, $data->decimals);
|
||||
|
||||
// print the grades on screen for feedback
|
||||
|
||||
@@ -27,12 +27,12 @@ require_once($CFG->dirroot.'/grade/export/lib.php');
|
||||
|
||||
class grade_export_xls extends grade_export {
|
||||
|
||||
var $plugin = 'xls';
|
||||
public $plugin = 'xls';
|
||||
|
||||
/**
|
||||
* To be implemented by child classes
|
||||
*/
|
||||
function print_grades() {
|
||||
public function print_grades() {
|
||||
global $CFG;
|
||||
require_once($CFG->dirroot.'/lib/excellib.class.php');
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ if (!empty($CFG->gradepublishing)) {
|
||||
$mform = new grade_export_form(null, array('publishing' => true));
|
||||
|
||||
// process post information
|
||||
if ($data = $mform->get_data()) {
|
||||
if ($data = $mform->get_data(false)) {
|
||||
$export = new grade_export_xls($course, groups_get_course_group($course), '', false, false, $data->display, $data->decimals);
|
||||
|
||||
// print the grades on screen for feedbacks
|
||||
|
||||
@@ -27,16 +27,16 @@ require_once($CFG->dirroot.'/grade/export/lib.php');
|
||||
|
||||
class grade_export_xml extends grade_export {
|
||||
|
||||
var $plugin = 'xml';
|
||||
var $updatedgradesonly = false; // default to export ALL grades
|
||||
|
||||
public $plugin = 'xml';
|
||||
public $updatedgradesonly = false; // default to export ALL grades
|
||||
|
||||
/**
|
||||
* To be implemented by child classes
|
||||
* @param boolean $feedback
|
||||
* @param boolean $publish Whether to output directly, or send as a file
|
||||
* @return string
|
||||
*/
|
||||
function print_grades($feedback = false) {
|
||||
public function print_grades($feedback = false) {
|
||||
global $CFG;
|
||||
require_once($CFG->libdir.'/filelib.php');
|
||||
|
||||
@@ -75,12 +75,12 @@ class grade_export_xml extends grade_export {
|
||||
$grade_item = $this->grade_items[$itemid];
|
||||
$grade->grade_item =& $grade_item;
|
||||
$gradestr = $this->format_grade($grade); // no formating for now
|
||||
|
||||
|
||||
// MDL-11669, skip exported grades or bad grades (if setting says so)
|
||||
if ($export_tracking) {
|
||||
$status = $geub->track($grade);
|
||||
if ($this->updatedgradesonly && ($status == 'nochange' || $status == 'unknown')) {
|
||||
continue;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ if (!empty($CFG->gradepublishing)) {
|
||||
$mform = new grade_export_form(null, array('idnumberrequired'=>true, 'publishing'=>true, 'updategradesonly'=>true));
|
||||
|
||||
// process post information
|
||||
if ($data = $mform->get_data()) {
|
||||
if ($data = $mform->get_data(false)) {
|
||||
$export = new grade_export_xml($course, groups_get_course_group($course), '', false, $data->updatedgradesonly, $data->display, $data->decimals);
|
||||
|
||||
// print the grades on screen for feedbacks
|
||||
|
||||
+13
-13
@@ -89,7 +89,7 @@ if ($importcode = optional_param('importcode', '', PARAM_FILE)) {
|
||||
$mform2 = new grade_import_mapping_form(null, array('gradeitems'=>$gradeitems, 'header'=>$header));
|
||||
|
||||
// if import form is submitted
|
||||
if ($formdata = $mform->get_data()) {
|
||||
if ($formdata = $mform->get_data(false)) {
|
||||
|
||||
// Large files are likely to take their time and memory. Let PHP know
|
||||
// that we'll take longer, and that the process should be recycled soon
|
||||
@@ -151,10 +151,10 @@ if ($formdata = $mform->get_data()) {
|
||||
$mform2->set_data(array('importcode'=>$importcode, 'id'=>$id));
|
||||
$mform2->display();
|
||||
|
||||
//} else if (($formdata = data_submitted()) && !empty($formdata->map)) {
|
||||
//} else if (($formdata = data_submitted(false)) && !empty($formdata->map)) {
|
||||
|
||||
// else if grade import mapping form is submitted
|
||||
} else if ($formdata = $mform2->get_data()) {
|
||||
} else if ($formdata = $mform2->get_data(false)) {
|
||||
|
||||
$importcode = clean_param($formdata->importcode, PARAM_FILE);
|
||||
$filename = $CFG->dataroot.'/temp/gradeimport/cvs/'.$USER->id.'/'.$importcode;
|
||||
@@ -255,7 +255,7 @@ if ($formdata = $mform->get_data()) {
|
||||
|
||||
switch ($t0) {
|
||||
case 'userid': //
|
||||
if (!$user = get_record('user','id', addslashes($value))) {
|
||||
if (!$user = $DB->get_record('user', array('id' => $value))) {
|
||||
// user not found, abort whold import
|
||||
import_cleanup($importcode);
|
||||
notify("user mapping error, could not find user with id \"$value\"");
|
||||
@@ -265,7 +265,7 @@ if ($formdata = $mform->get_data()) {
|
||||
$studentid = $value;
|
||||
break;
|
||||
case 'useridnumber':
|
||||
if (!$user = get_record('user', 'idnumber', addslashes($value))) {
|
||||
if (!$user = $DB->get_record('user', array('idnumber' => $value))) {
|
||||
// user not found, abort whold import
|
||||
import_cleanup($importcode);
|
||||
notify("user mapping error, could not find user with idnumber \"$value\"");
|
||||
@@ -275,7 +275,7 @@ if ($formdata = $mform->get_data()) {
|
||||
$studentid = $user->id;
|
||||
break;
|
||||
case 'useremail':
|
||||
if (!$user = get_record('user', 'email', addslashes($value))) {
|
||||
if (!$user = $DB->get_record('user', array('email' => $value))) {
|
||||
import_cleanup($importcode);
|
||||
notify("user mapping error, could not find user with email address \"$value\"");
|
||||
$status = false;
|
||||
@@ -284,7 +284,7 @@ if ($formdata = $mform->get_data()) {
|
||||
$studentid = $user->id;
|
||||
break;
|
||||
case 'username':
|
||||
if (!$user = get_record('user', 'username', addslashes($value))) {
|
||||
if (!$user = $DB->get_record('user', array('username' => $value))) {
|
||||
import_cleanup($importcode);
|
||||
notify("user mapping error, could not find user with username \"$value\"");
|
||||
$status = false;
|
||||
@@ -303,7 +303,7 @@ if ($formdata = $mform->get_data()) {
|
||||
$newgradeitem->importer = $USER->id;
|
||||
|
||||
// failed to insert into new grade item buffer
|
||||
if (!$newgradeitems[$key] = insert_record('grade_import_newitem', addslashes_recursive($newgradeitem))) {
|
||||
if (!$newgradeitems[$key] = $DB->insert_record('grade_import_newitem', $newgradeitem)) {
|
||||
$status = false;
|
||||
import_cleanup($importcode);
|
||||
notify(get_string('importfailed', 'grades'));
|
||||
@@ -413,7 +413,7 @@ if ($formdata = $mform->get_data()) {
|
||||
$newgrade->importcode = $importcode;
|
||||
$newgrade->userid = $studentid;
|
||||
$newgrade->importer = $USER->id;
|
||||
if (!insert_record('grade_import_values', addslashes_recursive($newgrade))) {
|
||||
if (!$DB->insert_record('grade_import_values', $newgrade)) {
|
||||
// could not insert into temporary table
|
||||
$status = false;
|
||||
import_cleanup($importcode);
|
||||
@@ -428,17 +428,17 @@ if ($formdata = $mform->get_data()) {
|
||||
foreach ($newfeedbacks as $newfeedback) {
|
||||
$sql = "SELECT *
|
||||
FROM {grade_import_values}
|
||||
WHERE importcode=$importcode AND userid=$studentid AND itemid=$newfeedback->itemid AND importer={$USER->id}";
|
||||
if ($feedback = get_record_sql($sql)) {
|
||||
WHERE importcode=? AND userid=? AND itemid=? AND importer=?";
|
||||
if ($feedback = $DB->get_record_sql($sql, array($importcode, $studentid, $newfeedback->itemid, $USER->id))) {
|
||||
$newfeedback->id = $feedback->id;
|
||||
update_record('grade_import_values', addslashes_recursive($newfeedback));
|
||||
$DB->update_record('grade_import_values', $newfeedback);
|
||||
|
||||
} else {
|
||||
// the grade item for this is not updated
|
||||
$newfeedback->importcode = $importcode;
|
||||
$newfeedback->userid = $studentid;
|
||||
$newfeedback->importer = $USER->id;
|
||||
insert_record('grade_import_values', addslashes_recursive($newfeedback));
|
||||
$DB->insert_record('grade_import_values', $newfeedback);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ $delete = optional_param('delete', 0, PARAM_BOOL);
|
||||
$confirm = optional_param('confirm', 0, PARAM_BOOL);
|
||||
|
||||
if ($id) {
|
||||
if (!$key = get_record('user_private_key', 'id', $id)) {
|
||||
if (!$key = $DB->get_record('user_private_key', array('id' => $id))) {
|
||||
print_error('invalidgroupid');
|
||||
}
|
||||
if (empty($courseid)) {
|
||||
@@ -43,12 +43,12 @@ if ($id) {
|
||||
print_error('invalidcourseid');
|
||||
}
|
||||
|
||||
if (!$course = get_record('course', 'id', $courseid)) {
|
||||
if (!$course = $DB->get_record('course', array('id' => $courseid))) {
|
||||
print_error('invalidcourseid');
|
||||
}
|
||||
|
||||
} else {
|
||||
if (!$course = get_record('course', 'id', $courseid)) {
|
||||
if (!$course = $DB->get_record('course', array('id' => $courseid))) {
|
||||
print_error('invalidcourseid');
|
||||
}
|
||||
$key = new object();
|
||||
@@ -77,7 +77,7 @@ if ($id and $delete) {
|
||||
die;
|
||||
|
||||
} else if (confirm_sesskey()){
|
||||
delete_records('user_private_key', 'id', $id);
|
||||
$DB->delete_records('user_private_key', array('id' => $id));
|
||||
redirect('keymanager.php?id='.$course->id);
|
||||
}
|
||||
}
|
||||
@@ -89,14 +89,14 @@ $editform->set_data($key);
|
||||
if ($editform->is_cancelled()) {
|
||||
redirect($returnurl);
|
||||
|
||||
} elseif ($data = $editform->get_data()) {
|
||||
} elseif ($data = $editform->get_data(false)) {
|
||||
|
||||
if ($data->id) {
|
||||
$record = new object();
|
||||
$record->id = $data->id;
|
||||
$record->iprestriction = $data->iprestriction;
|
||||
$record->validuntil = $data->validuntil;
|
||||
update_record('user_private_key', $record);
|
||||
$DB->update_record('user_private_key', $record);
|
||||
} else {
|
||||
create_user_key('grade/import', $USER->id, $course->id, $data->iprestriction, $data->validuntil);
|
||||
}
|
||||
|
||||
@@ -47,7 +47,8 @@ $stredit = get_string('edit');
|
||||
$strdelete = get_string('delete');
|
||||
|
||||
$data = array();
|
||||
if ($keys = get_records_select('user_private_key', "script='grade/import' AND instance={$course->id} AND userid={$USER->id}")) {
|
||||
$params = array($course->id, $USER->id);
|
||||
if ($keys = $DB->get_records_select('user_private_key', "script='grade/import' AND instance=? AND userid=?"), $params) {
|
||||
foreach($keys as $key) {
|
||||
$line = array();
|
||||
$line[0] = format_string($key->value);
|
||||
|
||||
+23
-19
@@ -30,10 +30,10 @@ require_once($CFG->libdir.'/gradelib.php');
|
||||
* @return int importcode
|
||||
*/
|
||||
function get_new_importcode() {
|
||||
global $USER;
|
||||
global $USER, $DB;
|
||||
|
||||
$importcode = time();
|
||||
while (get_record('grade_import_values', 'importcode', $importcode, 'importer', $USER->id)) {
|
||||
while ($DB->get_record('grade_import_values', array('importcode' => $importcode, 'importer' => $USER->id))) {
|
||||
$importcode--;
|
||||
}
|
||||
|
||||
@@ -51,16 +51,16 @@ function get_new_importcode() {
|
||||
* @return bool success
|
||||
*/
|
||||
function grade_import_commit($courseid, $importcode, $importfeedback=true, $verbose=true) {
|
||||
global $CFG, $USER;
|
||||
global $CFG, $USER, $DB;
|
||||
|
||||
$commitstart = time(); // start time in case we need to roll back
|
||||
$newitemids = array(); // array to hold new grade_item ids from grade_import_newitem table, mapping array
|
||||
|
||||
/// first select distinct new grade_items with this batch
|
||||
|
||||
if ($newitems = get_records_sql("SELECT *
|
||||
FROM {grade_import_newitem}
|
||||
WHERE importcode = $importcode AND importer={$USER->id}")) {
|
||||
$params = array($importcode, $USER->id);
|
||||
if ($newitems = $DB->get_records_sql("SELECT *
|
||||
FROM {grade_import_newitem}
|
||||
WHERE importcode = ? AND importer=?", $params)) {
|
||||
|
||||
// instances of the new grade_items created, cached
|
||||
// in case grade_update fails, so that we can remove them
|
||||
@@ -69,7 +69,7 @@ function grade_import_commit($courseid, $importcode, $importfeedback=true, $verb
|
||||
foreach ($newitems as $newitem) {
|
||||
// get all grades with this item
|
||||
|
||||
if ($grades = get_records('grade_import_values', 'newgradeitem', $newitem->id)) {
|
||||
if ($grades = $DB->get_records('grade_import_values', array('newgradeitem' => $newitem->id))) {
|
||||
/// create a new grade item for this - must use false as second param!
|
||||
/// TODO: we need some bounds here too
|
||||
$gradeitem = new grade_item(array('courseid'=>$courseid, 'itemtype'=>'manual', 'itemname'=>$newitem->itemname), false);
|
||||
@@ -97,9 +97,10 @@ function grade_import_commit($courseid, $importcode, $importfeedback=true, $verb
|
||||
|
||||
/// then find all existing items
|
||||
|
||||
if ($gradeitems = get_records_sql("SELECT DISTINCT (itemid)
|
||||
FROM {grade_import_values}
|
||||
WHERE importcode = $importcode AND importer={$USER->id} AND itemid > 0")) {
|
||||
if ($gradeitems = $DB->get_records_sql("SELECT DISTINCT (itemid)
|
||||
FROM {grade_import_values}
|
||||
WHERE importcode = ? AND importer=? AND itemid > 0",
|
||||
array($importcode, $USER->id))) {
|
||||
|
||||
$modifieditems = array();
|
||||
|
||||
@@ -111,7 +112,7 @@ function grade_import_commit($courseid, $importcode, $importfeedback=true, $verb
|
||||
return false;
|
||||
}
|
||||
// get all grades with this item
|
||||
if ($grades = get_records('grade_import_values', 'itemid', $itemid)) {
|
||||
if ($grades = $DB->get_records('grade_import_values', array('itemid' => $itemid))) {
|
||||
|
||||
// make the grades array for update_grade
|
||||
foreach ($grades as $grade) {
|
||||
@@ -168,9 +169,11 @@ function grade_import_commit($courseid, $importcode, $importfeedback=true, $verb
|
||||
* @return mixed and array of user objects, or false if none.
|
||||
*/
|
||||
function get_unenrolled_users_in_import($importcode, $courseid) {
|
||||
global $CFG;
|
||||
global $CFG, $DB;
|
||||
$relatedctxcondition = get_related_contexts_string(get_context_instance(CONTEXT_COURSE, $courseid));
|
||||
|
||||
list($usql, $params) = $DB->get_in_or_equal(explode(',', $CFG->gradebookroles));
|
||||
|
||||
$sql = "SELECT giv.id, u.firstname, u.lastname, u.idnumber AS useridnumber,
|
||||
COALESCE(gi.idnumber, gin.itemname) AS gradeidnumber
|
||||
FROM
|
||||
@@ -179,13 +182,14 @@ function get_unenrolled_users_in_import($importcode, $courseid) {
|
||||
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.roleid $usql AND
|
||||
ra.contextid $relatedctxcondition)
|
||||
WHERE giv.importcode = $importcode
|
||||
WHERE giv.importcode = ?
|
||||
AND ra.id IS NULL
|
||||
ORDER BY gradeidnumber, u.lastname, u.firstname";
|
||||
$params[] = $importcode;
|
||||
|
||||
return get_records_sql($sql);
|
||||
return $DB->get_records_sql($sql, $params);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -194,11 +198,11 @@ function get_unenrolled_users_in_import($importcode, $courseid) {
|
||||
* @param string importcode - import batch identifier
|
||||
*/
|
||||
function import_cleanup($importcode) {
|
||||
global $USER;
|
||||
global $USER, $DB;
|
||||
|
||||
// remove entries from buffer table
|
||||
delete_records('grade_import_values', 'importcode', $importcode, 'importer', $USER->id);
|
||||
delete_records('grade_import_newitem', 'importcode', $importcode, 'importer', $USER->id);
|
||||
$DB->delete_records('grade_import_values', array('importcode' => $importcode, 'importer' => $USER->id));
|
||||
$DB->delete_records('grade_import_newitem', array('importcode' => $importcode, 'importer' => $USER->id));
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
@@ -26,7 +26,7 @@ require_once $CFG->libdir.'/formslib.php';
|
||||
|
||||
class grade_import_form extends moodleform {
|
||||
function definition () {
|
||||
global $COURSE, $USER, $CFG;
|
||||
global $COURSE, $USER, $CFG, $DB;
|
||||
|
||||
$mform =& $this->_form;
|
||||
|
||||
@@ -51,7 +51,10 @@ class grade_import_form extends moodleform {
|
||||
if (!empty($CFG->gradepublishing)) {
|
||||
$mform->addElement('header', 'publishing', get_string('publishing', 'grades'));
|
||||
$options = array(get_string('nopublish', 'grades'), get_string('createnewkey', 'userkey'));
|
||||
if ($keys = get_records_select('user_private_key', "script='grade/import' AND instance={$COURSE->id} AND userid={$USER->id}")) {
|
||||
$keys = $DB->get_records_select('user_private_key',
|
||||
"script='grade/import' AND instance=? AND userid=?",
|
||||
array($COURSE->id, $USER->id));
|
||||
if ($keys) {
|
||||
foreach ($keys as $key) {
|
||||
$options[$key->value] = $key->value; // TODO: add more details - ip restriction, valid until ??
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ if (!empty($CFG->gradepublishing)) {
|
||||
|
||||
$mform = new grade_import_form();
|
||||
|
||||
if ($data = $mform->get_data()) {
|
||||
if ($data = $mform->get_data(false)) {
|
||||
// Large files are likely to take their time and memory. Let PHP know
|
||||
// that we'll take longer, and that the process should be recycled soon
|
||||
// to free up memory.
|
||||
|
||||
@@ -29,7 +29,7 @@ require_once $CFG->dirroot.'/grade/lib.php';
|
||||
require_once $CFG->dirroot.'/grade/import/lib.php';
|
||||
|
||||
function import_xml_grades($text, $course, &$error) {
|
||||
global $USER;
|
||||
global $USER, $DB;
|
||||
|
||||
$importcode = get_new_importcode();
|
||||
|
||||
@@ -65,7 +65,7 @@ function import_xml_grades($text, $course, &$error) {
|
||||
|
||||
// check if user exist and convert idnumber to user id
|
||||
$useridnumber = $result['#']['student'][0]['#'];
|
||||
if (!$user = get_record('user', 'idnumber', addslashes($useridnumber))) {
|
||||
if (!$user = $DB->get_record('user', array('idnumber' =>$useridnumber))) {
|
||||
// no user found, abort
|
||||
$status = false;
|
||||
$error = get_string('errincorrectuseridnumber', 'gradeimport_xml', $useridnumber);
|
||||
@@ -110,7 +110,7 @@ function import_xml_grades($text, $course, &$error) {
|
||||
}
|
||||
|
||||
// insert this grade into a temp table
|
||||
if (!insert_record('grade_import_values', addslashes_recursive($newgrade))) {
|
||||
if (!$DB->insert_record('grade_import_values', $newgrade)) {
|
||||
$status = false;
|
||||
// could not insert into temp table
|
||||
$error = get_string('importfailed', 'grades');
|
||||
|
||||
+13
-4
@@ -117,7 +117,7 @@ class graded_users_iterator {
|
||||
FROM {user} u
|
||||
INNER JOIN {role_assignments} ra ON u.id = ra.userid
|
||||
$groupsql
|
||||
WHERE ra.roleid $gradebookroles_sql;
|
||||
WHERE ra.roleid $gradebookroles_sql
|
||||
AND ra.contextid $relatedcontexts
|
||||
$groupwheresql
|
||||
ORDER BY $order";
|
||||
@@ -157,12 +157,15 @@ class graded_users_iterator {
|
||||
return false; // no users present
|
||||
}
|
||||
|
||||
if (!$user = $this->users_rs->next()) {
|
||||
if (!$this->users_rs->valid()) {
|
||||
if ($current = $this->_pop()) {
|
||||
// this is not good - user or grades updated between the two reads above :-(
|
||||
}
|
||||
|
||||
return false; // no more users
|
||||
} else {
|
||||
$user = $this->users_rs->current();
|
||||
$this->users_rs->next();
|
||||
}
|
||||
|
||||
// find grades of this user
|
||||
@@ -172,6 +175,10 @@ class graded_users_iterator {
|
||||
break; // no more grades
|
||||
}
|
||||
|
||||
if (empty($current->userid)) {
|
||||
break;
|
||||
}
|
||||
|
||||
if ($current->userid != $user->id) {
|
||||
// grade of the next user, we have all for this user
|
||||
$this->_push($current);
|
||||
@@ -241,11 +248,11 @@ class graded_users_iterator {
|
||||
return NULL; // no grades present
|
||||
}
|
||||
|
||||
if (!$grade = $this->grades_rs->next()) {
|
||||
if ($this->grades_rs->next()) {
|
||||
return NULL; // no more grades
|
||||
}
|
||||
|
||||
return $grade;
|
||||
return $this->grades_rs->current();
|
||||
} else {
|
||||
return array_pop($this->gradestack);
|
||||
}
|
||||
@@ -279,6 +286,8 @@ function print_graded_users_selector($course, $actionpage, $userid=null, $return
|
||||
$menu[0] = get_string('allusers', 'grades');
|
||||
}
|
||||
|
||||
$nextuser = $gui->next_user();
|
||||
|
||||
while ($userdata = $gui->next_user()) {
|
||||
$user = $userdata->user;
|
||||
$menu[$user->id] = fullname($user);
|
||||
|
||||
@@ -77,7 +77,7 @@ switch ($action) {
|
||||
}
|
||||
|
||||
if ($errorstr) {
|
||||
$user = get_record('user', 'id', $userid, '', '', '', '', 'id, firstname, lastname');
|
||||
$user = $DB->get_record('user', array('id' => $userid), 'id, firstname, lastname');
|
||||
$gradestr = new object();
|
||||
$gradestr->username = fullname($user);
|
||||
$gradestr->itemname = $grade_item->get_name();
|
||||
@@ -119,8 +119,8 @@ switch ($action) {
|
||||
// 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 {grade_grades} gg, {grade_items} gi WHERE "
|
||||
. "gi.courseid = $courseid AND gg.itemid = gi.id AND gg.userid = $userid";
|
||||
$records = get_records_sql($sql);
|
||||
. "gi.courseid = ? AND gg.itemid = gi.id AND gg.userid = ?";
|
||||
$records = $DB->get_records_sql($sql, array($courseid, $userid));
|
||||
$json_object->row = $records;
|
||||
echo json_encode($json_object);
|
||||
die();
|
||||
|
||||
@@ -149,7 +149,7 @@ if (ajaxenabled() && $report->get_pref('enableajax')) {
|
||||
}
|
||||
|
||||
/// processing posted grades & feedback here
|
||||
if ($data = data_submitted() and confirm_sesskey() and has_capability('moodle/grade:edit', $context)) {
|
||||
if ($data = data_submitted(false) and confirm_sesskey() and has_capability('moodle/grade:edit', $context)) {
|
||||
$warnings = $report->process_data($data);
|
||||
} else {
|
||||
$warnings = array();
|
||||
|
||||
@@ -157,6 +157,7 @@ class grade_report_grader extends grade_report {
|
||||
* @return array empty array if success, array of warnings if something fails.
|
||||
*/
|
||||
public function process_data($data) {
|
||||
global $DB;
|
||||
$warnings = array();
|
||||
|
||||
// always initialize all arrays
|
||||
@@ -213,7 +214,7 @@ class grade_report_grader extends grade_report {
|
||||
$errorstr = 'morethanmax';
|
||||
}
|
||||
if ($errorstr) {
|
||||
$user = get_record('user', 'id', $userid, '', '', '', '', 'id, firstname, lastname');
|
||||
$user = $DB->get_record('user', array('id' => $userid), 'id, firstname, lastname');
|
||||
$gradestr = new object();
|
||||
$gradestr->username = fullname($user);
|
||||
$gradestr->itemname = $grade_item->get_name();
|
||||
|
||||
@@ -31,7 +31,7 @@ $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');
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ if ($mform->is_cancelled()){
|
||||
}
|
||||
|
||||
// If data submitted, then process and store.
|
||||
if ($data = $mform->get_data()) {
|
||||
if ($data = $mform->get_data(false)) {
|
||||
foreach ($data as $preference => $value) {
|
||||
if (substr($preference, 0, 6) !== 'grade_') {
|
||||
continue;
|
||||
|
||||
@@ -27,7 +27,7 @@ require '../../config.php';
|
||||
$courseid = required_param('id', PARAM_INT);
|
||||
|
||||
/// 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);
|
||||
|
||||
@@ -139,7 +139,7 @@ abstract class grade_report {
|
||||
* @param int $page The current page being viewed (when report is paged)
|
||||
*/
|
||||
public function __construct($courseid, $gpr, $context, $page=null) {
|
||||
global $CFG, $COURSE;
|
||||
global $CFG, $COURSE, $DB;
|
||||
|
||||
if (empty($CFG->gradebookroles)) {
|
||||
error ('no roles defined in admin->appearance->graderoles');
|
||||
@@ -150,7 +150,7 @@ abstract class grade_report {
|
||||
if ($this->courseid == $COURSE->id) {
|
||||
$this->course = $COURSE;
|
||||
} else {
|
||||
$this->course = get_record('course', 'id', $this->courseid);
|
||||
$this->course = $DB->get_record('course', array('id' => $this->courseid));
|
||||
}
|
||||
|
||||
$this->gpr = $gpr;
|
||||
|
||||
@@ -29,7 +29,7 @@ require_once $CFG->dirroot.'/grade/lib.php';
|
||||
|
||||
$courseid = required_param('id', PARAM_INT); // course id
|
||||
|
||||
if (!$course = get_record('course', 'id', $courseid)) {
|
||||
if (!$course = $DB->get_record('course', array('id' => $courseid))) {
|
||||
print_error('nocourseid');
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ $outcomes = grade_outcome::fetch_all_available($courseid);
|
||||
|
||||
// Get grade_items that use each outcome
|
||||
foreach ($outcomes as $outcomeid => $outcome) {
|
||||
$report_info[$outcomeid]['items'] = get_records_select('grade_items', "outcomeid = $outcomeid AND courseid = $courseid");
|
||||
$report_info[$outcomeid]['items'] = $DB->get_records_select('grade_items', "outcomeid = ? AND courseid = ?", array($outcomeid, $courseid));
|
||||
$report_info[$outcomeid]['outcome'] = $outcome;
|
||||
|
||||
// Get average grades for each item
|
||||
@@ -65,9 +65,9 @@ foreach ($outcomes as $outcomeid => $outcome) {
|
||||
foreach ($report_info[$outcomeid]['items'] as $itemid => $item) {
|
||||
$sql = "SELECT itemid, AVG(finalgrade) AS avg, COUNT(finalgrade) AS count
|
||||
FROM {grade_grades}
|
||||
WHERE itemid = $itemid
|
||||
WHERE itemid = ?
|
||||
GROUP BY itemid";
|
||||
$info = get_records_sql($sql);
|
||||
$info = $DB->get_records_sql($sql, array($itemid));
|
||||
|
||||
if (!$info) {
|
||||
unset($report_info[$outcomeid]['items'][$itemid]);
|
||||
|
||||
@@ -31,7 +31,7 @@ $courseid = optional_param('id', $COURSE->id, PARAM_INT);
|
||||
$userid = optional_param('userid', $USER->id, PARAM_INT);
|
||||
|
||||
/// 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);
|
||||
|
||||
@@ -41,18 +41,18 @@ class grade_report_overview extends grade_report {
|
||||
* The user.
|
||||
* @var object $user
|
||||
*/
|
||||
var $user;
|
||||
public $user;
|
||||
|
||||
/**
|
||||
* A flexitable to hold the data.
|
||||
* @var object $table
|
||||
*/
|
||||
var $table;
|
||||
public $table;
|
||||
|
||||
/**
|
||||
* show student ranks
|
||||
*/
|
||||
var $showrank;
|
||||
public $showrank;
|
||||
|
||||
/**
|
||||
* Constructor. Sets local copies of user preferences and initialises grade_tree.
|
||||
@@ -60,14 +60,14 @@ class grade_report_overview extends grade_report {
|
||||
* @param object $gpr grade plugin return tracking object
|
||||
* @param string $context
|
||||
*/
|
||||
function grade_report_overview($userid, $gpr, $context) {
|
||||
global $CFG, $COURSE;
|
||||
parent::grade_report($COURSE->id, $gpr, $context);
|
||||
public function __construct($userid, $gpr, $context) {
|
||||
global $CFG, $COURSE, $DB;
|
||||
parent::__construct($COURSE->id, $gpr, $context);
|
||||
|
||||
$this->showrank = grade_get_setting($this->courseid, 'report_overview_showrank', !empty($CFG->grade_report_overview_showrank));
|
||||
|
||||
// get the user (for full name)
|
||||
$this->user = get_record('user', 'id', $userid);
|
||||
$this->user = $DB->get_record('user', array('id' => $userid));
|
||||
|
||||
// base url for sorting by first/last name
|
||||
$this->baseurl = $CFG->wwwroot.'/grade/overview/index.php?id='.$userid;
|
||||
@@ -79,7 +79,7 @@ class grade_report_overview extends grade_report {
|
||||
/**
|
||||
* Prepares the headers and attributes of the flexitable.
|
||||
*/
|
||||
function setup_table() {
|
||||
public function setup_table() {
|
||||
/*
|
||||
* Table has 3 columns
|
||||
*| course | final grade | rank (optional) |
|
||||
@@ -109,7 +109,7 @@ class grade_report_overview extends grade_report {
|
||||
$this->table->setup();
|
||||
}
|
||||
|
||||
function fill_table() {
|
||||
public function fill_table() {
|
||||
global $CFG;
|
||||
|
||||
// MDL-11679, only show 'mycourses' instead of all courses
|
||||
@@ -140,11 +140,12 @@ class grade_report_overview extends grade_report {
|
||||
|
||||
} else if (!is_null($finalgrade)) {
|
||||
/// find the number of users with a higher grade
|
||||
$params = array($finalgrade, $grade_item->id);
|
||||
$sql = "SELECT COUNT(DISTINCT(userid))
|
||||
FROM {grade_grades}
|
||||
WHERE finalgrade IS NOT NULL AND finalgrade > $finalgrade
|
||||
AND itemid = {$grade_item->id}";
|
||||
$rank = count_records_sql($sql) + 1;
|
||||
WHERE finalgrade IS NOT NULL AND finalgrade > ?
|
||||
AND itemid = ?";
|
||||
$rank = $DB->count_records_sql($sql, $params) + 1;
|
||||
|
||||
$data[] = "$rank/$numusers";
|
||||
|
||||
@@ -168,7 +169,7 @@ class grade_report_overview extends grade_report {
|
||||
* @param bool $return Whether or not to return the data instead of printing it directly.
|
||||
* @return string
|
||||
*/
|
||||
function print_table($return=false) {
|
||||
public function print_table($return=false) {
|
||||
ob_start();
|
||||
$this->table->print_html();
|
||||
$html = ob_get_clean();
|
||||
@@ -184,7 +185,10 @@ class grade_report_overview extends grade_report {
|
||||
* @var array $data
|
||||
* @return bool Success or Failure (array of errors).
|
||||
*/
|
||||
function process_data($data) {
|
||||
public function process_data($data) {
|
||||
}
|
||||
|
||||
public function process_action($target, $action) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ $courseid = required_param('id');
|
||||
$userid = optional_param('userid', $USER->id, PARAM_INT);
|
||||
|
||||
/// 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);
|
||||
@@ -115,18 +115,18 @@ if ($access) {
|
||||
print_heading(get_string('modulename', 'gradereport_user'). ' - '.fullname($report->user));
|
||||
if ($report->fill_table()) {
|
||||
echo $report->print_table(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else { //Students will see just their own report
|
||||
} else { //Students will see just their own report
|
||||
|
||||
// Create a report instance
|
||||
$report = new grade_report_user($courseid, $gpr, $context, $userid);
|
||||
// Create a report instance
|
||||
$report = new grade_report_user($courseid, $gpr, $context, $userid);
|
||||
|
||||
// print the page
|
||||
print_heading(get_string('modulename', 'gradereport_user'). ' - '.fullname($report->user));
|
||||
// print the page
|
||||
print_heading(get_string('modulename', 'gradereport_user'). ' - '.fullname($report->user));
|
||||
|
||||
if ($report->fill_table()) {
|
||||
echo $report->print_table(true);
|
||||
if ($report->fill_table()) {
|
||||
echo $report->print_table(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+17
-15
@@ -41,28 +41,28 @@ class grade_report_user extends grade_report {
|
||||
* The user.
|
||||
* @var object $user
|
||||
*/
|
||||
var $user;
|
||||
public $user;
|
||||
|
||||
/**
|
||||
* A flexitable to hold the data.
|
||||
* @var object $table
|
||||
*/
|
||||
var $table;
|
||||
public $table;
|
||||
|
||||
/**
|
||||
* Flat structure similar to grade tree
|
||||
*/
|
||||
var $gseq;
|
||||
public $gseq;
|
||||
|
||||
/**
|
||||
* show student ranks
|
||||
*/
|
||||
var $showrank;
|
||||
public $showrank;
|
||||
|
||||
/**
|
||||
* Show hidden items even when user does not have required cap
|
||||
*/
|
||||
var $showhiddenitems;
|
||||
public $showhiddenitems;
|
||||
|
||||
/**
|
||||
* Constructor. Sets local copies of user preferences and initialises grade_tree.
|
||||
@@ -71,9 +71,9 @@ class grade_report_user extends grade_report {
|
||||
* @param string $context
|
||||
* @param int $userid The id of the user
|
||||
*/
|
||||
function grade_report_user($courseid, $gpr, $context, $userid) {
|
||||
global $CFG;
|
||||
parent::grade_report($courseid, $gpr, $context);
|
||||
public function __construct($courseid, $gpr, $context, $userid) {
|
||||
global $CFG, $DB;
|
||||
parent::__construct($courseid, $gpr, $context);
|
||||
|
||||
$this->showrank = grade_get_setting($this->courseid, 'report_user_showrank', $CFG->grade_report_user_showrank);
|
||||
$this->showhiddenitems = grade_get_setting($this->courseid, 'report_user_showhiddenitems', $CFG->grade_report_user_showhiddenitems);
|
||||
@@ -84,7 +84,7 @@ class grade_report_user extends grade_report {
|
||||
$this->gseq = new grade_seq($this->courseid, $switch);
|
||||
|
||||
// get the user (for full name)
|
||||
$this->user = get_record('user', 'id', $userid);
|
||||
$this->user = $DB->get_record('user', array('id' => $userid));
|
||||
|
||||
// base url for sorting by first/last name
|
||||
$this->baseurl = $CFG->wwwroot.'/grade/report?id='.$courseid.'&userid='.$userid;
|
||||
@@ -97,7 +97,7 @@ class grade_report_user extends grade_report {
|
||||
/**
|
||||
* Prepares the headers and attributes of the flexitable.
|
||||
*/
|
||||
function setup_table() {
|
||||
public function setup_table() {
|
||||
global $CFG;
|
||||
/*
|
||||
* Table has 5-6 columns
|
||||
@@ -124,8 +124,7 @@ class grade_report_user extends grade_report {
|
||||
$this->table->define_baseurl($this->baseurl);
|
||||
|
||||
$this->table->set_attribute('cellspacing', '0');
|
||||
$this->table->set_attribute('id', 'user-grade');
|
||||
$this->table->set_attribute('class', 'boxaligncenter generaltable');
|
||||
$this->table->set_attribute('class', 'user-grades boxaligncenter generaltable');
|
||||
|
||||
// not sure tables should be sortable or not, because if we allow it then sorted results distort grade category structure and sortorder
|
||||
$this->table->set_control_variables(array(
|
||||
@@ -140,7 +139,7 @@ class grade_report_user extends grade_report {
|
||||
$this->table->setup();
|
||||
}
|
||||
|
||||
function fill_table() {
|
||||
public function fill_table() {
|
||||
global $CFG;
|
||||
$numusers = $this->get_numusers(false); // total course users
|
||||
$items =& $this->gseq->items;
|
||||
@@ -293,7 +292,7 @@ class grade_report_user extends grade_report {
|
||||
* @param bool $return Whether or not to return the data instead of printing it directly.
|
||||
* @return string
|
||||
*/
|
||||
function print_table($return=false) {
|
||||
public function print_table($return=false) {
|
||||
ob_start();
|
||||
$this->table->print_html();
|
||||
$html = ob_get_clean();
|
||||
@@ -309,7 +308,10 @@ class grade_report_user extends grade_report {
|
||||
* @var array $data
|
||||
* @return bool Success or Failure (array of errors).
|
||||
*/
|
||||
function process_data($data) {
|
||||
public function process_data($data) {
|
||||
}
|
||||
|
||||
public function process_action($target, $action) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
|
||||
.grade-report-user table#user-grade .datesubmitted {
|
||||
.grade-report-user table.user-grades .datesubmitted {
|
||||
font-size: 0.7em;
|
||||
}
|
||||
|
||||
.grade-report-user table#user-grade .courseitem,
|
||||
.grade-report-user table#user-grade .categoryitem {
|
||||
.grade-report-user table.user-grades .courseitem,
|
||||
.grade-report-user table.user-grades .categoryitem {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.grade-report-user table#user-grade td.cell {
|
||||
.grade-report-user table.user-grades td.cell {
|
||||
padding-left: 5px;
|
||||
padding-right: 5px;
|
||||
}
|
||||
@@ -19,7 +19,7 @@
|
||||
}
|
||||
|
||||
/* this must be last if we want to override other category and course item colors */
|
||||
.grade-report-user table#user-grade .hidden,
|
||||
.grade-report-user table#user-grade .hidden a {
|
||||
.grade-report-user table.user-grades .hidden,
|
||||
.grade-report-user table.user-grades .hidden a {
|
||||
color:#aaaaaa;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user