weekly release 2.2.6+
[moodle.git] / mod / workshop / fileinfolib.php
blobf8f0e49b06ab10fb73388993824684012ca3967f
1 <?php
3 // This file is part of Moodle - http://moodle.org/
4 //
5 // Moodle is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // Moodle is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18 /**
19 * Defines workshop_file_info class
21 * @package mod
22 * @subpackage workshop
23 * @copyright 2009 David Mudrak <david.mudrak@gmail.com>
24 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
27 defined('MOODLE_INTERNAL') || die();
29 /**
30 * Represents virtual root node for all submissions
32 * Workshop submission uses two fileareas: workshop_submission_content
33 * for editor's embeded media and workshop_submission_attachment for attachments.
34 * In both, the itemid represents the submission id.
36 class workshop_file_info_submissions_container extends file_info {
37 protected $course;
38 protected $cm;
39 protected $areas;
40 protected $filearea;
42 public function __construct($browser, $course, $cm, $context, $areas, $filearea) {
43 parent::__construct($browser, $context);
44 $this->course = $course;
45 $this->cm = $cm;
46 $this->areas = $areas;
47 $this->filearea = $filearea;
50 /**
51 * Returns list of standard virtual file/directory identification.
52 * The difference from stored_file parameters is that null values
53 * are allowed in all fields
54 * @return array with keys contextid, filearea, itemid, filepath and filename
56 public function get_params() {
57 return array('contextid'=>$this->context->id,
58 'component'=>'mod_workshop',
59 'filearea' =>$this->filearea,
60 'itemid' =>null,
61 'filepath' =>null,
62 'filename' =>null);
65 /**
66 * Returns localised visible name.
67 * @return string
69 public function get_visible_name() {
70 return $this->areas[$this->filearea];
73 /**
74 * Can I add new files or directories?
75 * @return bool
77 public function is_writable() {
78 return false;
81 /**
82 * Is directory?
83 * @return bool
85 public function is_directory() {
86 return true;
89 /**
90 * Returns list of children.
91 * @return array of file_info instances
93 public function get_children() {
94 global $DB;
96 $children = array();
97 $itemids = $DB->get_records('files', array('contextid' => $this->context->id, 'component' => 'mod_workshop', 'filearea' => $this->filearea),
98 'itemid', "DISTINCT itemid");
99 foreach ($itemids as $itemid => $unused) {
100 if ($child = $this->browser->get_file_info($this->context, $this->filearea, $itemid)) {
101 $children[] = $child;
104 return $children;
108 * Returns parent file_info instance
109 * @return file_info or null for root
111 public function get_parent() {
112 return $this->browser->get_file_info($this->context);