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