172dd12c |
1 | <?php //$Id$ |
2 | |
3 | class 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 | |
23 | public function is_directory() { |
24 | return true; |
25 | } |
26 | |
27 | public function get_children() { |
28 | global $DB; |
29 | |
30 | $children = array(); |
31 | |
32 | if ($child = $this->browser->get_file_info($this->context, 'coursecat_intro', 0)) { |
33 | $children[] = $child; |
34 | } |
35 | |
36 | $course_cats = $DB->get_records('course_categories', array('parent'=>$this->category->id), 'sortorder'); |
37 | foreach ($course_cats as $category) { |
38 | $context = get_context_instance(CONTEXT_COURSECAT, $category->id); |
39 | if (!$category->visible and !has_capability('moodle/course:viewhiddencourses', $context)) { |
40 | continue; |
41 | } |
42 | if ($child = $this->browser->get_file_info($context)) { |
43 | $children[] = $child; |
44 | } |
45 | } |
46 | |
47 | $courses = $DB->get_records('course', array('category'=>$this->category->id), 'sortorder'); |
48 | foreach ($courses as $course) { |
49 | $context = get_context_instance(CONTEXT_COURSE, $course->id); |
50 | if (!$course->visible and !has_capability('moodle/course:viewhiddencourses', $context)) { |
51 | continue; |
52 | } |
53 | if ($child = $this->browser->get_file_info($context)) { |
54 | $children[] = $child; |
55 | } |
56 | } |
57 | |
58 | return $children; |
59 | } |
60 | |
61 | public function get_parent() { |
62 | $cid = get_parent_contextid($this->context); |
63 | $parent = get_context_instance_by_id($cid); |
64 | return $this->browser->get_file_info($parent); |
65 | } |
66 | } |