Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'wip-MDL-31738-MOODLE_22_STABLE' of git://github.com/mar…

…inaglancy/moodle into MOODLE_22_STABLE
  • Loading branch information...
commit 46ccd8b12bc44b56b01d64fb386fffb27146413d 2 parents 313f98c + ccd6fa9
@stronk7 stronk7 authored
Showing with 131 additions and 0 deletions.
  1. +72 −0 mod/data/lib.php
  2. +59 −0 mod/glossary/lib.php
View
72 mod/data/lib.php
@@ -2865,6 +2865,78 @@ function data_get_file_areas($course, $cm, $context) {
}
/**
+ * File browsing support for data module.
+ *
+ * @param file_browser $browser
+ * @param array $areas
+ * @param stdClass $course
+ * @param cm_info $cm
+ * @param context $context
+ * @param string $filearea
+ * @param int $itemid
+ * @param string $filepath
+ * @param string $filename
+ * @return file_info_stored file_info_stored instance or null if not found
+ */
+function mod_data_get_file_info($browser, $areas, $course, $cm, $context, $filearea, $itemid, $filepath, $filename) {
+ global $CFG, $DB;
+
+ if ($context->contextlevel != CONTEXT_MODULE) {
+ return null;
+ }
+
+ if ($filearea === 'content') {
+ if (!$content = $DB->get_record('data_content', array('id'=>$itemid))) {
+ return null;
+ }
+
+ if (!$field = $DB->get_record('data_fields', array('id'=>$content->fieldid))) {
+ return null;
+ }
+
+ if (!$record = $DB->get_record('data_records', array('id'=>$content->recordid))) {
+ return null;
+ }
+
+ if (!$data = $DB->get_record('data', array('id'=>$field->dataid))) {
+ return null;
+ }
+
+ //check if approved
+ if ($data->approval and !$record->approved and !data_isowner($record) and !has_capability('mod/data:approve', $context)) {
+ return null;
+ }
+
+ // group access
+ if ($record->groupid) {
+ $groupmode = groups_get_activity_groupmode($cm, $course);
+ if ($groupmode == SEPARATEGROUPS and !has_capability('moodle/site:accessallgroups', $context)) {
+ if (!groups_is_member($record->groupid)) {
+ return null;
+ }
+ }
+ }
+
+ $fieldobj = data_get_field($field, $data, $cm);
+
+ $filepath = is_null($filepath) ? '/' : $filepath;
+ $filename = is_null($filename) ? '.' : $filename;
+ if (!$fieldobj->file_ok($filepath.$filename)) {
+ return null;
+ }
+
+ $fs = get_file_storage();
+ if (!($storedfile = $fs->get_file($context->id, 'mod_data', $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 null;
+}
+
+/**
* Serves the data attachments. Implements needed access control ;-)
*
* @param object $course
View
59 mod/glossary/lib.php
@@ -1462,6 +1462,65 @@ function glossary_get_file_areas($course, $cm, $context) {
}
/**
+ * File browsing support for glossary module.
+ *
+ * @param file_browser $browser
+ * @param array $areas
+ * @param stdClass $course
+ * @param cm_info $cm
+ * @param context $context
+ * @param string $filearea
+ * @param int $itemid
+ * @param string $filepath
+ * @param string $filename
+ * @return file_info_stored file_info_stored instance or null if not found
+ */
+function mod_glossary_get_file_info($browser, $areas, $course, $cm, $context, $filearea, $itemid, $filepath, $filename) {
+ global $CFG, $DB;
+
+ if ($context->contextlevel != CONTEXT_MODULE) {
+ return null;
+ }
+
+ if ($filearea === 'attachment' or $filearea === 'entry') {
+ if (!$entry = $DB->get_record('glossary_entries', array('id' => $itemid))) {
+ return null;
+ }
+
+ if (!$glossary = $DB->get_record('glossary', array('id' => $cm->instance))) {
+ return null;
+ }
+
+ if ($glossary->defaultapproval and !$entry->approved and !has_capability('mod/glossary:approve', $context)) {
+ return null;
+ }
+
+ // this trickery here is because we need to support source glossary access
+ if ($entry->glossaryid == $cm->instance) {
+ $filecontext = $context;
+ } else if ($entry->sourceglossaryid == $cm->instance) {
+ if (!$maincm = get_coursemodule_from_instance('glossary', $entry->glossaryid)) {
+ return null;
+ }
+ $filecontext = get_context_instance(CONTEXT_MODULE, $maincm->id);
+ } else {
+ return null;
+ }
+
+ $fs = get_file_storage();
+ $filepath = is_null($filepath) ? '/' : $filepath;
+ $filename = is_null($filename) ? '.' : $filename;
+ if (!($storedfile = $fs->get_file($filecontext->id, 'mod_glossary', $filearea, $itemid, $filepath, $filename))) {
+ return null;
+ }
+ $urlbase = $CFG->wwwroot.'/pluginfile.php';
+ return new file_info_stored($browser, $filecontext, $storedfile, $urlbase, $filearea, $itemid, true, true, false);
+ }
+
+ return null;
+}
+
+/**
* Serves the glossary attachments. Implements needed access control ;-)
*
* @param object $course
Please sign in to comment.
Something went wrong with that request. Please try again.