Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

MDL-30709: Fixed bug with inserting files from Recent files repository

Two parts of changes: in assignment module function assignment_get_file_info was missing
and when populating the list of recent files the function get_file_info was not called, which caused populating the list of recent files with the files that could not later be inserted
  • Loading branch information...
commit 7d3ebf4c1945485db13323a3edc6211c711abae2 1 parent baa5cd8
@marinaglancy marinaglancy authored
Showing with 52 additions and 9 deletions.
  1. +39 −0 mod/assignment/lib.php
  2. +13 −9 repository/recent/lib.php
View
39 mod/assignment/lib.php
@@ -3941,6 +3941,45 @@ function assignment_get_file_areas($course, $cm, $context) {
}
/**
+ * File browsing support for assignment module.
+ *
+ * @param object $browser
+ * @param object $areas
+ * @param object $course
+ * @param object $cm
+ * @param object $context
+ * @param string $filearea
+ * @param int $itemid
+ * @param string $filepath
+ * @param string $filename
+ * @return object file_info instance or null if not found
+ */
+function assignment_get_file_info($browser, $areas, $course, $cm, $context, $filearea, $itemid, $filepath, $filename) {
+ global $CFG, $DB, $USER;
+
+ if ($context->contextlevel != CONTEXT_MODULE || $filearea != 'submission') {
+ return null;
+ }
+ if (!$submission = $DB->get_record('assignment_submissions', array('id' => $itemid))) {
+ return null;
+ }
+ if (!(($submission->userid == $USER->id && has_capability('mod/assignment:view', $context))
+ || has_capability('mod/assignment:grade', $context))) {
+ // no permission to view this submission
+ return null;
+ }
+
+ $fs = get_file_storage();
+ $filepath = is_null($filepath) ? '/' : $filepath;
+ $filename = is_null($filename) ? '.' : $filename;
+ if (!($storedfile = $fs->get_file($context->id, 'mod_assignment', $filearea, $itemid, $filepath, $filename))) {
+ return null;
+ }
+ $urlbase = $CFG->wwwroot.'/pluginfile.php';
+ return new file_info_stored($browser, $context, $storedfile, $urlbase, $filearea, $itemid, true, true, false);
+}
+
+/**
* Return a list of page types
* @param string $pagetype current page type
* @param stdClass $parentcontext Block's parent context
View
22 repository/recent/lib.php
@@ -97,7 +97,7 @@ private function get_recent_files($limitfrom = 0, $limit = DEFAULT_RECENT_FILES_
* @return mixed
*/
public function get_listing($encodedpath = '', $page = '') {
- global $CFG, $USER, $OUTPUT;
+ global $OUTPUT;
$ret = array();
$ret['dynload'] = true;
$ret['nosearch'] = true;
@@ -108,14 +108,18 @@ public function get_listing($encodedpath = '', $page = '') {
try {
foreach ($files as $file) {
$params = base64_encode(serialize($file));
- $node = array(
- 'title' => $file['filename'],
- 'size' => 0,
- 'date' => '',
- 'source'=> $params,
- 'thumbnail' => $OUTPUT->pix_url(file_extension_icon($file['filename'], 32))->out(false),
- );
- $list[] = $node;
+ // Check that file exists and accessible
+ $filesize = $this->get_file_size($params);
+ if (!empty($filesize)) {
+ $node = array(
+ 'title' => $file['filename'],
+ 'size' => $filesize,
+ 'date' => '',
+ 'source'=> $params,
+ 'thumbnail' => $OUTPUT->pix_url(file_extension_icon($file['filename'], 32))->out(false),
+ );
+ $list[] = $node;
+ }
}
} catch (Exception $e) {
throw new repository_exception('emptyfilelist', 'repository_recent');
Please sign in to comment.
Something went wrong with that request. Please try again.