MDL-19247 Adjusted detection and cleaned up sniff files.
[moodle.git] / lib / file / file_info_coursecat.php
CommitLineData
172dd12c 1<?php //$Id$
2
b81fd01d 3/**
4 * Represents a course category context in the tree navigated by @see{file_browser}.
5 */
172dd12c 6class file_info_coursecat extends file_info {
7 protected $category;
8
9 public function __construct($browser, $context, $category) {
10 parent::__construct($browser, $context);
11 $this->category = $category;
12 }
13
14 public function get_params() {
15 return array('contextid'=>$this->context->id,
16 'filearea' =>null,
17 'itemid' =>null,
18 'filepath' =>null,
19 'filename' =>null);
20 }
21
22 public function get_visible_name() {
23 return format_string($this->category->name);
24 }
25
cf7ec8e9 26 public function is_writable() {
27 return false;
28 }
29
172dd12c 30 public function is_directory() {
31 return true;
32 }
33
34 public function get_children() {
35 global $DB;
36
37 $children = array();
38
39 if ($child = $this->browser->get_file_info($this->context, 'coursecat_intro', 0)) {
40 $children[] = $child;
41 }
42
43 $course_cats = $DB->get_records('course_categories', array('parent'=>$this->category->id), 'sortorder');
44 foreach ($course_cats as $category) {
45 $context = get_context_instance(CONTEXT_COURSECAT, $category->id);
46 if (!$category->visible and !has_capability('moodle/course:viewhiddencourses', $context)) {
47 continue;
48 }
49 if ($child = $this->browser->get_file_info($context)) {
50 $children[] = $child;
51 }
52 }
53
54 $courses = $DB->get_records('course', array('category'=>$this->category->id), 'sortorder');
55 foreach ($courses as $course) {
56 $context = get_context_instance(CONTEXT_COURSE, $course->id);
57 if (!$course->visible and !has_capability('moodle/course:viewhiddencourses', $context)) {
58 continue;
59 }
60 if ($child = $this->browser->get_file_info($context)) {
61 $children[] = $child;
62 }
63 }
64
65 return $children;
66 }
67
68 public function get_parent() {
69 $cid = get_parent_contextid($this->context);
70 $parent = get_context_instance_by_id($cid);
71 return $this->browser->get_file_info($parent);
72 }
73}