mirror of
https://github.com/moodle/moodle.git
synced 2025-01-18 05:58:34 +01:00
MDL-35668 filebrowser: small improvements to modules
- Store cm_info in file_info_context_module instead of object - Use correct API calls to component_callback_exists - Use human readable name of module type
This commit is contained in:
parent
ade66228fa
commit
10122f009e
@ -193,7 +193,7 @@ class file_browser {
|
||||
/**
|
||||
* Returns info about the files at Course category context
|
||||
*
|
||||
* @param stdClass $context context object
|
||||
* @param context $context context object
|
||||
* @param string $component component
|
||||
* @param string $filearea file area
|
||||
* @param int $itemid item ID
|
||||
@ -202,38 +202,18 @@ class file_browser {
|
||||
* @return file_info|null file_info instance or null if not found or access not allowed
|
||||
*/
|
||||
private function get_file_info_context_module($context, $component, $filearea, $itemid, $filepath, $filename) {
|
||||
global $COURSE, $DB, $CFG;
|
||||
|
||||
static $cachedmodules = array();
|
||||
|
||||
if (!array_key_exists($context->instanceid, $cachedmodules)) {
|
||||
$cachedmodules[$context->instanceid] = get_coursemodule_from_id('', $context->instanceid);
|
||||
if (!($context instanceof context_module)) {
|
||||
return null;
|
||||
}
|
||||
$coursecontext = $context->get_course_context();
|
||||
$modinfo = get_fast_modinfo($coursecontext->instanceid);
|
||||
$cm = $modinfo->get_cm($context->instanceid);
|
||||
|
||||
if (!($cm = $cachedmodules[$context->instanceid])) {
|
||||
if (empty($cm->uservisible)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($cm->course == $COURSE->id) {
|
||||
$course = $COURSE;
|
||||
} else if (!$course = $DB->get_record('course', array('id'=>$cm->course))) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$modinfo = get_fast_modinfo($course);
|
||||
if (empty($modinfo->cms[$cm->id]->uservisible)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$modname = $modinfo->cms[$cm->id]->modname;
|
||||
|
||||
if (!file_exists("$CFG->dirroot/mod/$modname/lib.php")) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// ok, we know that module exists, and user may access it
|
||||
|
||||
$level = new file_info_context_module($this, $context, $course, $cm, $modname);
|
||||
$level = new file_info_context_module($this, $context, $cm->get_course(), $cm, $cm->modname);
|
||||
return $level->get_file_info($component, $filearea, $itemid, $filepath, $filename);
|
||||
}
|
||||
|
||||
|
@ -35,7 +35,7 @@ defined('MOODLE_INTERNAL') || die();
|
||||
class file_info_context_module extends file_info {
|
||||
/** @var stdClass Course object */
|
||||
protected $course;
|
||||
/** @var stdClass Course module object */
|
||||
/** @var cm_info Course module object */
|
||||
protected $cm;
|
||||
/** @var string Module name */
|
||||
protected $modname;
|
||||
@ -58,23 +58,17 @@ class file_info_context_module extends file_info {
|
||||
|
||||
parent::__construct($browser, $context);
|
||||
$this->course = $course;
|
||||
$this->cm = $cm;
|
||||
$this->modname = $modname;
|
||||
$this->cm = cm_info::create($cm);
|
||||
$this->modname = $this->cm->modname;
|
||||
$this->nonemptychildren = null;
|
||||
|
||||
include_once("$CFG->dirroot/mod/$modname/lib.php");
|
||||
|
||||
//find out all supported areas
|
||||
$functionname = 'mod_'.$modname.'_get_file_areas';
|
||||
$functionname_old = $modname.'_get_file_areas';
|
||||
|
||||
if (function_exists($functionname)) {
|
||||
if ($functionname = component_callback_exists('mod_'.$modname, 'get_file_areas')) {
|
||||
$cm = $this->cm->get_course_module_record();
|
||||
$this->areas = $functionname($course, $cm, $context);
|
||||
} else if (function_exists($functionname_old)) {
|
||||
$this->areas = $functionname_old($course, $cm, $context);
|
||||
} else {
|
||||
$this->areas = array();
|
||||
}
|
||||
|
||||
unset($this->areas['intro']); // hardcoded, ignore attempts to override it
|
||||
}
|
||||
|
||||
@ -104,9 +98,7 @@ class file_info_context_module extends file_info {
|
||||
return null;
|
||||
}
|
||||
|
||||
$modinfo = get_fast_modinfo($this->course);
|
||||
$cminfo = $modinfo->get_cm($this->cm->id);
|
||||
if (!$cminfo->uservisible) {
|
||||
if (!$this->cm->uservisible) {
|
||||
// activity hidden sorry
|
||||
return null;
|
||||
}
|
||||
@ -121,13 +113,10 @@ class file_info_context_module extends file_info {
|
||||
return $this->get_area_backup($itemid, $filepath, $filename);
|
||||
}
|
||||
|
||||
$functionname = 'mod_'.$this->modname.'_get_file_info';
|
||||
$functionname_old = $this->modname.'_get_file_info';
|
||||
|
||||
if (function_exists($functionname)) {
|
||||
return $functionname($this->browser, $this->areas, $this->course, $this->cm, $this->context, $filearea, $itemid, $filepath, $filename);
|
||||
} else if (function_exists($functionname_old)) {
|
||||
return $functionname_old($this->browser, $this->areas, $this->course, $this->cm, $this->context, $filearea, $itemid, $filepath, $filename);
|
||||
if ($functionname = component_callback_exists('mod_'.$this->modname, 'get_file_info')) {
|
||||
$cm = $this->cm->get_course_module_record();
|
||||
return $functionname($this->browser, $this->areas, $this->course, $cm,
|
||||
$this->context, $filearea, $itemid, $filepath, $filename);
|
||||
}
|
||||
|
||||
return null;
|
||||
@ -206,7 +195,7 @@ class file_info_context_module extends file_info {
|
||||
* @return string
|
||||
*/
|
||||
public function get_visible_name() {
|
||||
return $this->cm->name.' ('.get_string('modulename', $this->cm->modname).')';
|
||||
return $this->cm->get_formatted_name().' ('.$this->cm->get_module_type_name().')';
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user