Skip to content

Commit

Permalink
MDL-27520 core_grades: make constant names clearer
Browse files Browse the repository at this point in the history
Also using them in more locations.
  • Loading branch information
mdjnelson committed Oct 17, 2018
1 parent b7a9b6f commit 80b6fb7
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 15 deletions.
10 changes: 8 additions & 2 deletions backup/moodle2/backup_stepslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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.
Expand Down
16 changes: 11 additions & 5 deletions backup/moodle2/restore_stepslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion grade/report/history/classes/output/tablelog.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
);

Expand Down
7 changes: 5 additions & 2 deletions lib/filelib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
}
Expand All @@ -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]);
Expand Down
6 changes: 3 additions & 3 deletions lib/grade/constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
4 changes: 2 additions & 2 deletions lib/grade/grade_grade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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);
}
}

Expand Down

0 comments on commit 80b6fb7

Please sign in to comment.