Skip to content

Commit b2c16c6

Browse files
committedNov 8, 2011
Files embedded into the form description are now served by the core itself
The grading form description is in the core scope so it should be served by the core, not by the plugin.
1 parent b02b7c5 commit b2c16c6

File tree

2 files changed

+40
-44
lines changed

2 files changed

+40
-44
lines changed
 

‎grade/grading/form/rubric/lib.php

+3-44
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public function update_or_check_rubric(stdClass $newdefinition, $usermodified =
106106
$newdefinition->options = json_encode($newdefinition->rubric['options']);
107107
$editoroptions = self::description_form_field_options($this->get_context());
108108
$newdefinition = file_postupdate_standard_editor($newdefinition, 'description', $editoroptions, $this->get_context(),
109-
'gradingform_rubric', 'definition_description', $this->definition->id);
109+
'grading', 'description', $this->definition->id);
110110

111111
// reload the definition from the database
112112
$currentdefinition = $this->get_definition(true);
@@ -353,7 +353,7 @@ public function get_definition_for_editing() {
353353
}
354354
$options = self::description_form_field_options($this->get_context());
355355
$properties = file_prepare_standard_editor($properties, 'description', $options, $this->get_context(),
356-
'gradingform_rubric', 'definition_description', $definition->id);
356+
'grading', 'description', $definition->id);
357357
}
358358
$properties->rubric = array('criteria' => array(), 'options' => $this->get_options());
359359
if (!empty($definition->rubric_criteria)) {
@@ -422,7 +422,7 @@ public function get_formatted_description() {
422422

423423
$options = self::description_form_field_options($this->get_context());
424424
$description = file_rewrite_pluginfile_urls($this->definition->description, 'pluginfile.php', $context->id,
425-
'gradingform_rubric', 'definition_description', $this->definition->id, $options);
425+
'grading', 'description', $this->definition->id, $options);
426426

427427
$formatoptions = array(
428428
'noclean' => false,
@@ -776,44 +776,3 @@ public function render_grading_element($page, $gradingformelement) {
776776
return $html;
777777
}
778778
}
779-
780-
781-
/**
782-
* Processes file requests for the gradingform_rubric
783-
*
784-
* Required to serve files for this plugin
785-
* Called from pluginfile.php
786-
*
787-
* @global moodle_database $DB
788-
* @param stdClass $course
789-
* @param null $cm
790-
* @param stdClass $context
791-
* @param string $filearea
792-
* @param array $args
793-
* @param bool $forcedownload
794-
* @return void|false
795-
*/
796-
function gradingform_rubric_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload) {
797-
global $CFG, $DB;
798-
// First argument should ALWAYS be the itemid
799-
$itemid = (int)array_shift($args);
800-
// Construct a URL to the file and check it exists
801-
$fs = get_file_storage();
802-
$relativepath = implode('/', $args);
803-
$fullpath = "/$context->id/gradingform_rubric/$filearea/$itemid/$relativepath";
804-
if (!$file = $fs->get_file_by_hash(sha1($fullpath)) or $file->is_directory()) {
805-
// File doesnt exist anyway no point proceeding.
806-
return false;
807-
}
808-
// Switch by the fileare and check the appropriate information
809-
switch ($filearea) {
810-
case 'definition_description' :
811-
// Make sure the itemid points to a valid definition
812-
if ($DB->record_exists('grading_definitions', array('id' => $itemid))) {
813-
send_stored_file($file, 0, 0, $forcedownload);
814-
}
815-
break;
816-
}
817-
// Obviosly bogus comething or other in there
818-
return false;
819-
}

‎pluginfile.php

+37
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,43 @@
654654
question_pluginfile($course, $context, 'question', $filearea, $args, $forcedownload);
655655
send_file_not_found();
656656

657+
// ========================================================================================================================
658+
} else if ($component === 'grading') {
659+
if ($filearea === 'description') {
660+
// files embedded into the form definition description
661+
662+
if ($context->contextlevel == CONTEXT_SYSTEM) {
663+
require_login();
664+
665+
} else if ($context->contextlevel >= CONTEXT_COURSE) {
666+
require_login($course, false, $cm);
667+
668+
} else {
669+
send_file_not_found();
670+
}
671+
672+
$formid = (int)array_shift($args);
673+
674+
$sql = "SELECT ga.id
675+
FROM {grading_areas} ga
676+
JOIN {grading_definitions} gd ON (gd.areaid = ga.id)
677+
WHERE gd.id = ? AND ga.contextid = ?";
678+
$areaid = $DB->get_field_sql($sql, array($formid, $context->id), IGNORE_MISSING);
679+
680+
if (!$areaid) {
681+
send_file_not_found();
682+
}
683+
684+
$fullpath = "/$context->id/$component/$filearea/$formid/".implode('/', $args);
685+
686+
if (!$file = $fs->get_file_by_hash(sha1($fullpath)) or $file->is_directory()) {
687+
send_file_not_found();
688+
}
689+
690+
session_get_instance()->write_close(); // unlock session during fileserving
691+
send_stored_file($file, 60*60, 0, $forcedownload);
692+
}
693+
657694
// ========================================================================================================================
658695
} else if (strpos($component, 'mod_') === 0) {
659696
$modname = substr($component, 4);

0 commit comments

Comments
 (0)
Please sign in to comment.