public function __construct(\mod_mediagallery\collection $collection, array $galleries) { global $CFG, $DB; $this->collection = $collection; $this->galleries = $galleries; if ($collection->user_can_add_children()) { $this->maxreached = false; } if ($this->isassessable = $collection->is_assessable()) { $this->hassubmitted = $collection->has_submitted(); if ($this->linkedassigncmid = $collection->get_linked_assignid()) { require_once $CFG->dirroot . '/mod/assign/locallib.php'; $context = \context_module::instance($this->linkedassigncmid); $cm = get_coursemodule_from_id('assign', $this->linkedassigncmid, 0, false, MUST_EXIST); $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST); $assign = new \assign($context, $cm, $course); $this->submissionsopen = $assign->submissions_open(); } } $this->readonly = $collection->is_read_only(); $this->tags = $collection->get_tags(); $mygalleries = $collection->get_my_galleries(); $this->userorgrouphasgallery = !empty($mygalleries); foreach (array('id', 'mode', 'thumbnailsperrow', 'thumbnailsperpage') as $opt) { if (isset($collection->{$opt})) { $this->{$opt} = $collection->{$opt}; } } }
/** * Help function to return files matching extensions or their count * * @param string|array $extensions, either '*' or array of lowercase extensions, i.e. array('.gif','.jpg') * @param bool|int $countonly if false returns the children, if an int returns just the * count of children but stops counting when $countonly number of children is reached * @param bool $returnemptyfolders if true returns items that don't have matching files inside * @return array|int array of file_info instances or the count */ private function get_filtered_children($extensions = '*', $countonly = false, $returnemptyfolders = false) { $galleries = \mod_mediagallery\collection::get_public_galleries_by_contextid($this->context->id, false); $children = array(); $urlbase = $CFG->wwwroot . '/pluginfile.php'; foreach ($galleries as $id => $name) { $storedfile = new virtual_root_file($this->context->id, 'mod_mediagallery', 'gallery', $id); $child = new mod_mediagallery_file_info_area_gallery($this->browser, $this->context, $storedfile, $urlbase, $name, true, true, true, false); $children[] = $child; if ($countonly !== false && count($children) >= $countonly) { break; } } if ($countonly !== false) { return count($children); } return $children; }