Added .gitignore
[moodle-linuxchix.git] / blocks / course_list / block_course_list.php
blobb2475ac4e12931faf4902eeb2f3ff14a452f8fb7
1 <?PHP //$Id$
3 include_once($CFG->dirroot . '/course/lib.php');
5 class block_course_list extends block_list {
6 function init() {
7 $this->title = get_string('courses');
8 $this->version = 2007101509;
11 function has_config() {
12 return true;
15 function get_content() {
16 global $THEME, $CFG, $USER;
18 if($this->content !== NULL) {
19 return $this->content;
22 $this->content = new stdClass;
23 $this->content->items = array();
24 $this->content->icons = array();
25 $this->content->footer = '';
27 $icon = "<img src=\"$CFG->pixpath/i/course.gif\"".
28 " class=\"icon\" alt=\"".get_string("coursecategory")."\" />";
30 $adminseesall = true;
31 if (isset($CFG->block_course_list_adminview)) {
32 if ( $CFG->block_course_list_adminview == 'own'){
33 $adminseesall = false;
37 if (empty($CFG->disablemycourses) and
38 !empty($USER->id) and
39 !(has_capability('moodle/course:update', get_context_instance(CONTEXT_SYSTEM)) and $adminseesall) and
40 !isguest()) { // Just print My Courses
41 if ($courses = get_my_courses($USER->id, 'visible DESC, fullname ASC')) {
42 foreach ($courses as $course) {
43 if ($course->id == SITEID) {
44 continue;
46 $linkcss = $course->visible ? "" : " class=\"dimmed\" ";
47 $this->content->items[]="<a $linkcss title=\"" . format_string($course->shortname) . "\" ".
48 "href=\"$CFG->wwwroot/course/view.php?id=$course->id\">" . format_string($course->fullname) . "</a>";
49 $this->content->icons[]=$icon;
51 $this->title = get_string('mycourses');
52 /// If we can update any course of the view all isn't hidden, show the view all courses link
53 if (has_capability('moodle/course:update', get_context_instance(CONTEXT_SYSTEM)) || empty($CFG->block_course_list_hideallcourseslink)) {
54 $this->content->footer = "<a href=\"$CFG->wwwroot/course/index.php\">".get_string("fulllistofcourses")."</a> ...";
56 $this->get_remote_courses();
57 if ($this->content->items) { // make sure we don't return an empty list
58 return $this->content;
63 $categories = get_categories("0"); // Parent = 0 ie top-level categories only
64 if ($categories) { //Check we have categories
65 if (count($categories) > 1 || (count($categories) == 1 && count_records('course') > 200)) { // Just print top level category links
66 foreach ($categories as $category) {
67 $linkcss = $category->visible ? "" : " class=\"dimmed\" ";
68 $this->content->items[]="<a $linkcss href=\"$CFG->wwwroot/course/category.php?id=$category->id\">" . format_string($category->name) . "</a>";
69 $this->content->icons[]=$icon;
71 /// If we can update any course of the view all isn't hidden, show the view all courses link
72 if (has_capability('moodle/course:update', get_context_instance(CONTEXT_SYSTEM)) || empty($CFG->block_course_list_hideallcourseslink)) {
73 $this->content->footer .= "<a href=\"$CFG->wwwroot/course/index.php\">".get_string('fulllistofcourses').'</a> ...';
75 $this->title = get_string('categories');
76 } else { // Just print course names of single category
77 $category = array_shift($categories);
78 $courses = get_courses($category->id);
80 if ($courses) {
81 foreach ($courses as $course) {
82 $linkcss = $course->visible ? "" : " class=\"dimmed\" ";
84 $this->content->items[]="<a $linkcss title=\""
85 . format_string($course->shortname)."\" ".
86 "href=\"$CFG->wwwroot/course/view.php?id=$course->id\">"
87 . format_string($course->fullname) . "</a>";
88 $this->content->icons[]=$icon;
90 /// If we can update any course of the view all isn't hidden, show the view all courses link
91 if (has_capability('moodle/course:update', get_context_instance(CONTEXT_SYSTEM)) || empty($CFG->block_course_list_hideallcourseslink)) {
92 $this->content->footer .= "<a href=\"$CFG->wwwroot/course/index.php\">".get_string('fulllistofcourses').'</a> ...';
94 $this->get_remote_courses();
95 } else {
97 $this->content->icons[] = '';
98 $this->content->items[] = get_string('nocoursesyet');
99 if (has_capability('moodle/course:create', get_context_instance(CONTEXT_COURSECAT, $category->id))) {
100 $this->content->footer = '<a href="'.$CFG->wwwroot.'/course/edit.php?category='.$category->id.'">'.get_string("addnewcourse").'</a> ...';
102 $this->get_remote_courses();
104 $this->title = get_string('courses');
108 return $this->content;
111 function get_remote_courses() {
112 global $THEME, $CFG, $USER;
114 if (!is_enabled_auth('mnet')) {
115 // no need to query anything remote related
116 return;
119 $icon = '<img src="'.$CFG->pixpath.'/i/mnethost.gif" class="icon" alt="'.get_string('course').'" />';
121 // only for logged in users!
122 if (!isloggedin() || isguest()) {
123 return false;
126 if ($courses = get_my_remotecourses()) {
127 $this->content->items[] = get_string('remotecourses','mnet');
128 $this->content->icons[] = '';
129 foreach ($courses as $course) {
130 $this->content->items[]="<a title=\"" . format_string($course->shortname) . "\" ".
131 "href=\"{$CFG->wwwroot}/auth/mnet/jump.php?hostid={$course->hostid}&amp;wantsurl=/course/view.php?id={$course->remoteid}\">"
132 . format_string($course->fullname) . "</a>";
133 $this->content->icons[]=$icon;
135 // if we listed courses, we are done
136 return true;
139 if ($hosts = get_my_remotehosts()) {
140 $this->content->items[] = get_string('remotemoodles','mnet');
141 $this->content->icons[] = '';
142 foreach($USER->mnet_foreign_host_array as $somehost) {
143 $this->content->items[] = $somehost['count'].get_string('courseson','mnet').'<a title="'.$somehost['name'].'" href="'.$somehost['url'].'">'.$somehost['name'].'</a>';
144 $this->content->icons[] = $icon;
146 // if we listed hosts, done
147 return true;
150 return false;