From 80b6fb7a7976af82125723b1b3b53a40ab518439 Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Tue, 16 Oct 2018 13:25:03 +0800 Subject: [PATCH] MDL-27520 core_grades: make constant names clearer Also using them in more locations. --- backup/moodle2/backup_stepslib.php | 10 ++++++++-- backup/moodle2/restore_stepslib.php | 16 +++++++++++----- grade/report/history/classes/output/tablelog.php | 2 +- lib/filelib.php | 7 +++++-- lib/grade/constants.php | 6 +++--- lib/grade/grade_grade.php | 4 ++-- 6 files changed, 30 insertions(+), 15 deletions(-) diff --git a/backup/moodle2/backup_stepslib.php b/backup/moodle2/backup_stepslib.php index 866e19b4d9d69..ef99fa6792042 100644 --- a/backup/moodle2/backup_stepslib.php +++ b/backup/moodle2/backup_stepslib.php @@ -2418,6 +2418,9 @@ protected function execute_condition() { } protected function define_structure() { + global $CFG; + + require_once($CFG->libdir . '/grade/constants.php'); // To know if we are including userinfo $userinfo = $this->get_setting_value('userinfo'); @@ -2474,7 +2477,7 @@ protected function define_structure() { // This only happens if we are including user info if ($userinfo) { $grade->set_source_table('grade_grades', array('itemid' => backup::VAR_PARENTID)); - $grade->annotate_files('grade', 'feedback', 'id'); + $grade->annotate_files(GRADE_FILE_COMPONENT, GRADE_FEEDBACK_FILEAREA, 'id'); } $letter->set_source_table('grade_letters', array('contextid' => backup::VAR_CONTEXTID)); @@ -2511,6 +2514,9 @@ protected function execute_condition() { } protected function define_structure() { + global $CFG; + + require_once($CFG->libdir . '/grade/constants.php'); // Settings to use. $userinfo = $this->get_setting_value('userinfo'); @@ -2538,7 +2544,7 @@ protected function define_structure() { JOIN {backup_ids_temp} bi ON ggh.itemid = bi.itemid WHERE bi.backupid = ? AND bi.itemname = 'grade_item'", array(backup::VAR_BACKUPID)); - $grade->annotate_files('grade', 'history', 'id'); + $grade->annotate_files(GRADE_FILE_COMPONENT, GRADE_HISTORY_FEEDBACK_FILEAREA, 'id'); } // Annotations. diff --git a/backup/moodle2/restore_stepslib.php b/backup/moodle2/restore_stepslib.php index 98c0a947271a2..1e78ee3100e16 100644 --- a/backup/moodle2/restore_stepslib.php +++ b/backup/moodle2/restore_stepslib.php @@ -3705,6 +3705,10 @@ protected function process_grade_item($data) { } protected function process_grade_grade($data) { + global $CFG; + + require_once($CFG->libdir . '/grade/constants.php'); + $data = (object)($data); $olduserid = $data->userid; $oldid = $data->id; @@ -3723,8 +3727,8 @@ protected function process_grade_grade($data) { $this->set_mapping('grade_grades', $oldid, $grade->id, true); $this->add_related_files( - 'grade', - 'feedback', + GRADE_FILE_COMPONENT, + GRADE_FEEDBACK_FILEAREA, 'grade_grades', null, $oldid @@ -3803,7 +3807,9 @@ protected function define_structure() { } protected function process_grade_grade($data) { - global $DB; + global $CFG, $DB; + + require_once($CFG->libdir . '/grade/constants.php'); $data = (object) $data; $oldhistoryid = $data->id; @@ -3823,8 +3829,8 @@ protected function process_grade_grade($data) { $this->set_mapping('grade_grades_history', $oldhistoryid, $newhistoryid, true); $this->add_related_files( - 'grade', - 'history', + GRADE_FILE_COMPONENT, + GRADE_HISTORY_FEEDBACK_FILEAREA, 'grade_grades_history', null, $oldhistoryid diff --git a/grade/report/history/classes/output/tablelog.php b/grade/report/history/classes/output/tablelog.php index 76ce731f1922f..4d9c9fcaf0113 100644 --- a/grade/report/history/classes/output/tablelog.php +++ b/grade/report/history/classes/output/tablelog.php @@ -323,7 +323,7 @@ public function col_feedback(\stdClass $history) { 'pluginfile.php', $context->id, GRADE_FILE_COMPONENT, - GRADE_HISTORY_FILEAREA, + GRADE_HISTORY_FEEDBACK_FILEAREA, $history->id ); diff --git a/lib/filelib.php b/lib/filelib.php index 7afd3c6550017..b096a5be1a97c 100644 --- a/lib/filelib.php +++ b/lib/filelib.php @@ -4198,6 +4198,9 @@ function file_pluginfile($relativepath, $forcedownload, $preview = null, $offlin // ======================================================================================================================== } else if ($component === 'grade') { + + require_once($CFG->libdir . '/grade/constants.php'); + if (($filearea === 'outcome' or $filearea === 'scale') and $context->contextlevel == CONTEXT_SYSTEM) { // Global gradebook files if ($CFG->forcelogin) { @@ -4213,7 +4216,7 @@ function file_pluginfile($relativepath, $forcedownload, $preview = null, $offlin \core\session\manager::write_close(); // Unlock session during file serving. send_stored_file($file, 60*60, 0, $forcedownload, $sendfileoptions); - } else if ($filearea === 'feedback' || $filearea == 'history') { + } else if ($filearea == GRADE_FEEDBACK_FILEAREA || $filearea == GRADE_HISTORY_FEEDBACK_FILEAREA) { if ($context->contextlevel != CONTEXT_MODULE) { send_file_not_found; } @@ -4222,7 +4225,7 @@ function file_pluginfile($relativepath, $forcedownload, $preview = null, $offlin $gradeid = (int) array_shift($args); $filename = array_pop($args); - if ($filearea == 'historyfeedback') { + if ($filearea == GRADE_HISTORY_FEEDBACK_FILEAREA) { $grade = $DB->get_record('grade_grades_history', ['id' => $gradeid]); } else { $grade = $DB->get_record('grade_grades', ['id' => $gradeid]); diff --git a/lib/grade/constants.php b/lib/grade/constants.php index dd629f38bd4ae..039ed3b8cca1a 100644 --- a/lib/grade/constants.php +++ b/lib/grade/constants.php @@ -270,11 +270,11 @@ define('GRADE_FILE_COMPONENT', 'grade'); /** - * The file area to store grade feedback files. + * The file area to store the associated grade_grades feedback files. */ define('GRADE_FEEDBACK_FILEAREA', 'feedback'); /** - * The file area to store grade history files. + * The file area to store the associated grade_grades_history feedback files. */ -define('GRADE_HISTORY_FILEAREA', 'history'); +define('GRADE_HISTORY_FEEDBACK_FILEAREA', 'historyfeedback'); diff --git a/lib/grade/grade_grade.php b/lib/grade/grade_grade.php index bc12419f7c174..9413c578242ac 100644 --- a/lib/grade/grade_grade.php +++ b/lib/grade/grade_grade.php @@ -1056,7 +1056,7 @@ public function insert($source=null) { $this->copy_feedback_files($context, GRADE_FEEDBACK_FILEAREA, $this->id); if (empty($CFG->disablegradehistory)) { - $this->copy_feedback_files($context, GRADE_HISTORY_FILEAREA, $historyid); + $this->copy_feedback_files($context, GRADE_HISTORY_FEEDBACK_FILEAREA, $historyid); } } @@ -1109,7 +1109,7 @@ public function update($source=null) { $this->copy_feedback_files($context, GRADE_FEEDBACK_FILEAREA, $this->id); if (empty($CFG->disablegradehistory)) { - $this->copy_feedback_files($context, GRADE_HISTORY_FILEAREA, $historyid); + $this->copy_feedback_files($context, GRADE_HISTORY_FEEDBACK_FILEAREA, $historyid); } }