MDL-18111 improving file api comments and docs, fixing license header
[moodle.git] / lib / file / file_info_coursecat.php
CommitLineData
64a19b38 1<?php
2
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.
14//
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/>.
17
18
19/**
20 * Utility class for browsing of curse category files.
21 *
22 * @package moodlecore
23 * @subpackage file-browser
24 * @copyright 2008 Petr Skoda (http://skodak.org)
25 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26 */
172dd12c 27
b81fd01d 28/**
29 * Represents a course category context in the tree navigated by @see{file_browser}.
30 */
172dd12c 31class file_info_coursecat extends file_info {
32 protected $category;
33
34 public function __construct($browser, $context, $category) {
35 parent::__construct($browser, $context);
36 $this->category = $category;
37 }
38
39 public function get_params() {
40 return array('contextid'=>$this->context->id,
41 'filearea' =>null,
42 'itemid' =>null,
43 'filepath' =>null,
44 'filename' =>null);
45 }
46
47 public function get_visible_name() {
48 return format_string($this->category->name);
49 }
50
cf7ec8e9 51 public function is_writable() {
52 return false;
53 }
54
172dd12c 55 public function is_directory() {
56 return true;
57 }
58
59 public function get_children() {
60 global $DB;
61
62 $children = array();
63
64 if ($child = $this->browser->get_file_info($this->context, 'coursecat_intro', 0)) {
65 $children[] = $child;
66 }
67
68 $course_cats = $DB->get_records('course_categories', array('parent'=>$this->category->id), 'sortorder');
69 foreach ($course_cats as $category) {
70 $context = get_context_instance(CONTEXT_COURSECAT, $category->id);
71 if (!$category->visible and !has_capability('moodle/course:viewhiddencourses', $context)) {
72 continue;
73 }
74 if ($child = $this->browser->get_file_info($context)) {
75 $children[] = $child;
76 }
77 }
78
79 $courses = $DB->get_records('course', array('category'=>$this->category->id), 'sortorder');
80 foreach ($courses as $course) {
81 $context = get_context_instance(CONTEXT_COURSE, $course->id);
82 if (!$course->visible and !has_capability('moodle/course:viewhiddencourses', $context)) {
83 continue;
84 }
85 if ($child = $this->browser->get_file_info($context)) {
86 $children[] = $child;
87 }
88 }
89
90 return $children;
91 }
92
93 public function get_parent() {
94 $cid = get_parent_contextid($this->context);
95 $parent = get_context_instance_by_id($cid);
96 return $this->browser->get_file_info($parent);
97 }
98}