Skip to content

Commit

Permalink
Files embedded into the form description are now served by the core i…
Browse files Browse the repository at this point in the history
…tself

The grading form description is in the core scope so it should be served
by the core, not by the plugin.
  • Loading branch information
mudrd8mz committed Nov 8, 2011
1 parent b02b7c5 commit b2c16c6
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 44 deletions.
47 changes: 3 additions & 44 deletions grade/grading/form/rubric/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public function update_or_check_rubric(stdClass $newdefinition, $usermodified =
$newdefinition->options = json_encode($newdefinition->rubric['options']);
$editoroptions = self::description_form_field_options($this->get_context());
$newdefinition = file_postupdate_standard_editor($newdefinition, 'description', $editoroptions, $this->get_context(),
'gradingform_rubric', 'definition_description', $this->definition->id);
'grading', 'description', $this->definition->id);

// reload the definition from the database
$currentdefinition = $this->get_definition(true);
Expand Down Expand Up @@ -353,7 +353,7 @@ public function get_definition_for_editing() {
}
$options = self::description_form_field_options($this->get_context());
$properties = file_prepare_standard_editor($properties, 'description', $options, $this->get_context(),
'gradingform_rubric', 'definition_description', $definition->id);
'grading', 'description', $definition->id);
}
$properties->rubric = array('criteria' => array(), 'options' => $this->get_options());
if (!empty($definition->rubric_criteria)) {
Expand Down Expand Up @@ -422,7 +422,7 @@ public function get_formatted_description() {

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

$formatoptions = array(
'noclean' => false,
Expand Down Expand Up @@ -776,44 +776,3 @@ public function render_grading_element($page, $gradingformelement) {
return $html;
}
}


/**
* Processes file requests for the gradingform_rubric
*
* Required to serve files for this plugin
* Called from pluginfile.php
*
* @global moodle_database $DB
* @param stdClass $course
* @param null $cm
* @param stdClass $context
* @param string $filearea
* @param array $args
* @param bool $forcedownload
* @return void|false
*/
function gradingform_rubric_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload) {
global $CFG, $DB;
// First argument should ALWAYS be the itemid
$itemid = (int)array_shift($args);
// Construct a URL to the file and check it exists
$fs = get_file_storage();
$relativepath = implode('/', $args);
$fullpath = "/$context->id/gradingform_rubric/$filearea/$itemid/$relativepath";
if (!$file = $fs->get_file_by_hash(sha1($fullpath)) or $file->is_directory()) {
// File doesnt exist anyway no point proceeding.
return false;
}
// Switch by the fileare and check the appropriate information
switch ($filearea) {
case 'definition_description' :
// Make sure the itemid points to a valid definition
if ($DB->record_exists('grading_definitions', array('id' => $itemid))) {
send_stored_file($file, 0, 0, $forcedownload);
}
break;
}
// Obviosly bogus comething or other in there
return false;
}
37 changes: 37 additions & 0 deletions pluginfile.php
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,43 @@
question_pluginfile($course, $context, 'question', $filearea, $args, $forcedownload);
send_file_not_found();

// ========================================================================================================================
} else if ($component === 'grading') {
if ($filearea === 'description') {
// files embedded into the form definition description

if ($context->contextlevel == CONTEXT_SYSTEM) {
require_login();

} else if ($context->contextlevel >= CONTEXT_COURSE) {
require_login($course, false, $cm);

} else {
send_file_not_found();
}

$formid = (int)array_shift($args);

$sql = "SELECT ga.id
FROM {grading_areas} ga
JOIN {grading_definitions} gd ON (gd.areaid = ga.id)
WHERE gd.id = ? AND ga.contextid = ?";
$areaid = $DB->get_field_sql($sql, array($formid, $context->id), IGNORE_MISSING);

if (!$areaid) {
send_file_not_found();
}

$fullpath = "/$context->id/$component/$filearea/$formid/".implode('/', $args);

if (!$file = $fs->get_file_by_hash(sha1($fullpath)) or $file->is_directory()) {
send_file_not_found();
}

session_get_instance()->write_close(); // unlock session during fileserving
send_stored_file($file, 60*60, 0, $forcedownload);
}

// ========================================================================================================================
} else if (strpos($component, 'mod_') === 0) {
$modname = substr($component, 4);
Expand Down

0 comments on commit b2c16c6

Please sign in to comment.