MDL-27148 whitespace fix
[moodle.git] / lib / filebrowser / file_info_context_system.php
bloba3908ef755bef73d1b63b517345c0ca2734e502b
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/>.
19 /**
20 * Utility class for browsing of system files.
22 * @package core
23 * @subpackage filebrowser
24 * @copyright 2008 Petr Skoda (http://skodak.org)
25 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
28 defined('MOODLE_INTERNAL') || die();
30 /**
31 * Represents the system context in the tree navigated by @see{file_browser}.
33 * @package core
34 * @subpackage filebrowser
35 * @copyright 2008 Petr Skoda (http://skodak.org)
36 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
38 class file_info_context_system extends file_info {
39 public function __construct($browser, $context) {
40 parent::__construct($browser, $context);
43 /**
44 * Return information about this specific part of context level
45 * @param $component
46 * @param $filearea
47 * @param $itemid
48 * @param $filepath
49 * @param $filename
51 public function get_file_info($component, $filearea, $itemid, $filepath, $filename) {
52 if (empty($component)) {
53 return $this;
56 // no components supported at this level yet
57 return null;
60 /**
61 * Returns localised visible name.
62 * @return string
64 public function get_visible_name() {
65 return get_string('arearoot', 'repository');
68 /**
69 * Can I add new files or directories?
70 * @return bool
72 public function is_writable() {
73 return false;
76 /**
77 * Is directory?
78 * @return bool
80 public function is_directory() {
81 return true;
84 /**
85 * Returns list of children.
86 * @return array of file_info instances
88 public function get_children() {
89 global $DB, $USER;
91 $children = array();
93 if ($child = $this->browser->get_file_info(get_context_instance(CONTEXT_USER, $USER->id))) {
94 $children[] = $child;
97 $course_cats = $DB->get_records('course_categories', array('parent'=>0), 'sortorder', 'id,visible');
98 foreach ($course_cats as $category) {
99 $context = get_context_instance(CONTEXT_COURSECAT, $category->id);
100 if (!$category->visible and !has_capability('moodle/category:viewhiddencategories', $context)) {
101 continue;
103 if ($child = $this->browser->get_file_info($context)) {
104 $children[] = $child;
108 $courses = $DB->get_records('course', array('category'=>0), 'sortorder', 'id,visible');
109 foreach ($courses as $course) {
110 if (!$course->visible and !has_capability('moodle/course:viewhiddencourses', $context)) {
111 continue;
113 $context = get_context_instance(CONTEXT_COURSE, $course->id);
114 if ($child = $this->browser->get_file_info($context)) {
115 $children[] = $child;
119 return $children;
123 * Returns parent file_info instance
124 * @return file_info or null for root
126 public function get_parent() {
127 return null;