|
|
@@ -174,7 +174,8 @@ function iassign_grade_item ($iassign) {
|
|
|
$iassign->grade = 0;
|
|
|
$grades = NULL;
|
|
|
|
|
|
- if (array_key_exists('cmidnumber', $iassign)) { //it may not be always present
|
|
|
+ //RR if (array_key_exists('cmidnumber', $iassign)) //it may not be always present
|
|
|
+ if (isset($iassign->cmidnumber)) { //it may not be always present
|
|
|
$params = array('itemname' => $iassign->name, 'idnumber' => $iassign->cmidnumber);
|
|
|
}
|
|
|
else {
|
|
|
@@ -454,7 +455,10 @@ function restore_one_submission ($info, $restore, $iassign, $submission) {
|
|
|
}
|
|
|
|
|
|
|
|
|
-/// Serves the data attachments. Implements needed access control ;-)
|
|
|
+/// Used by Moodle file system to return iLM file content
|
|
|
+// It is called under URL http://.../pluginfile.php/2470/mod_iassign/exercise/903/aula5-baricentro_EF_web.geo
|
|
|
+// (1) (2) (3) (4) (5)
|
|
|
+// Where (1), (2), (3), (4) and (5) are (respctivelly) field 'contextid', 'component', 'fileare', 'itemid' and 'filename' of {files}
|
|
|
// @param object $course
|
|
|
// @param object $cm
|
|
|
// @param object $context
|
|
|
@@ -462,6 +466,8 @@ function restore_one_submission ($info, $restore, $iassign, $submission) {
|
|
|
// @param array $args
|
|
|
// @param bool $forcedownload
|
|
|
// @return bool false if file not found, does not return if found - justsend the file
|
|
|
+// @calledby /lib/filelib.php: function file_pluginfile($relativepath, $forcedownload, $preview = null, $offline = false, $embed = false)
|
|
|
+// $filefunction = $component.'_pluginfile'; if (function_exists($filefunction)) $filefunction($course, $cm, $context, $filearea, $args, $forcedownload, $sendfileoptions);
|
|
|
function iassign_pluginfile ($course, $cm, $context, $filearea, $args, $forcedownload) {
|
|
|
global $CFG, $DB;
|
|
|
|
|
|
@@ -472,18 +478,41 @@ function iassign_pluginfile ($course, $cm, $context, $filearea, $args, $forcedow
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
$fs = get_file_storage();
|
|
|
- $postid = (int) array_shift($args);
|
|
|
+ $itemid = (int) array_shift($args); // must be {files}.itemid
|
|
|
$relativepath = implode('/', $args);
|
|
|
- $fullpath = "/$context->id/mod_iassign/$filearea/$postid/$relativepath";
|
|
|
-
|
|
|
- if (!$file = $fs->get_file_by_hash(sha1($fullpath)) or $file->is_directory()) {
|
|
|
- return false;
|
|
|
+ $fullpath = "/" . $context->id . "/mod_iassign/" . $filearea . "/" . $itemid . "/" . $relativepath;
|
|
|
+
|
|
|
+ //D echo "lib.php: iassign_pluginfile(.): context.id=" . $context->id . ": fullpath=" . $fullpath . "<br/>\n"; //exit;
|
|
|
+ //D echo "sha1(" . $fullpath . ")=". sha1($fullpath) . "<br/>";
|
|
|
+ //lib.php: iassign_pluginfile(.): context.id=55853: fullpath=/55853/mod_iassign/exercise/6023/ex4_7_laco_simples_for_imprimir_n_primeiros_termos_pa.ivph
|
|
|
+ // (1) (2) (3) (4) (5)
|
|
|
+ // They are {files}'s fields: (1)=contextid ; (2)=component ; (3)=filearea ; (4)=itemid ; (5)=filename
|
|
|
+
|
|
|
+ // ./lib/filestorage/file_storage.php: public function get_file_by_hash($pathnamehash)
|
|
|
+ // Try to recover iLM content file through {files}.pathnamehash
|
|
|
+ $one_file = $fs->get_file_by_hash(sha1($fullpath));
|
|
|
+ if (!$one_file || $one_file->is_directory()) { // if different Moodle version created iAssign {files}...
|
|
|
+ //D echo "Erro: via sha1 falhou!<br/>\n";
|
|
|
+ // ./lib/filestorage/file_storage.php: public function get_area_files($contextid, $component, $filearea, $itemid = false,...)
|
|
|
+ $array_files = $fs->get_area_files($context->id, "mod_iassign", $filearea, $itemid);
|
|
|
+ foreach ($array_files as $one_file) {
|
|
|
+ $filename = $one_file->get_filename();
|
|
|
+ if ($filename!=".")
|
|
|
+ break; // found the {iassign_statement} associated {files}
|
|
|
+ //D echo "{files} : id=" . $one_file->get_id() . ", filename=" . $one_file->get_filename() . "<br/>\n";
|
|
|
+ }
|
|
|
+ if (!$one_file || $one_file->filename == ".") {
|
|
|
+ //D echo "Ops! Not found...<br/>"; exit;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- // finally send the file
|
|
|
- send_stored_file($file, 0, 0, false); // download MUST be forced - security!
|
|
|
+ //D echo "one_file: id=" . $one_file->get_id() . ", filename=" . $one_file->get_filename() . "<br/>"; //exit;
|
|
|
+
|
|
|
+ // If error "Object of class stored_file could not be converted to string" => lost reference
|
|
|
+ // Finally send the file
|
|
|
+ send_stored_file($one_file, 0, 0, false); // download MUST be forced - security!
|
|
|
|
|
|
return false;
|
|
|
}
|