MDL-27520 core_grades: make constant names clearer
authorMark Nelson <markn@moodle.com>
Tue, 16 Oct 2018 05:25:03 +0000 (13:25 +0800)
committerMark Nelson <markn@moodle.com>
Wed, 17 Oct 2018 07:57:27 +0000 (15:57 +0800)
Also using them in more locations.

backup/moodle2/backup_stepslib.php
backup/moodle2/restore_stepslib.php
grade/report/history/classes/output/tablelog.php
lib/filelib.php
lib/grade/constants.php
lib/grade/grade_grade.php

index 866e19b..ef99fa6 100644 (file)
@@ -2418,6 +2418,9 @@ class backup_activity_grades_structure_step extends backup_structure_step {
     }
 
     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 @@ class backup_activity_grades_structure_step extends backup_structure_step {
         // 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 @@ class backup_activity_grade_history_structure_step extends backup_structure_step
     }
 
     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 @@ class backup_activity_grade_history_structure_step extends backup_structure_step
                                      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.
index 98c0a94..1e78ee3 100644 (file)
@@ -3705,6 +3705,10 @@ class restore_activity_grades_structure_step extends restore_structure_step {
     }
 
     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 @@ class restore_activity_grades_structure_step extends restore_structure_step {
             $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 @@ class restore_activity_grade_history_structure_step extends restore_structure_st
     }
 
     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 @@ class restore_activity_grade_history_structure_step extends restore_structure_st
             $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
index 76ce731..4d9c9fc 100644 (file)
@@ -323,7 +323,7 @@ class tablelog extends \table_sql implements \renderable {
                 'pluginfile.php',
                 $context->id,
                 GRADE_FILE_COMPONENT,
-                GRADE_HISTORY_FILEAREA,
+                GRADE_HISTORY_FEEDBACK_FILEAREA,
                 $history->id
             );
 
index 7afd3c6..b096a5b 100644 (file)
@@ -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]);
index dd629f3..039ed3b 100644 (file)
@@ -270,11 +270,11 @@ define('GRADE_MIN_MAX_FROM_GRADE_GRADE', 2);
 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');
index bc12419..9413c57 100644 (file)
@@ -1056,7 +1056,7 @@ class grade_grade extends grade_object {
             $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 @@ class grade_grade extends grade_object {
             $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);
             }
         }