adding some strings
[moodle-linuxchix.git] / blocks / course_list / block_course_list.php
blobcf3fac55a0465d8916a04ec147a6793350fec55e
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 = 2004111600;
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("course")."\" />";
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)) {
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 $this->content->footer .= "<a href=\"$CFG->wwwroot/course/index.php\">".get_string('searchcourses').'</a> ...<br />';
72 /// If we can update any course of the view all isn't hidden, show the view all courses link
73 if (has_capability('moodle/course:update', get_context_instance(CONTEXT_SYSTEM)) || empty($CFG->block_course_list_hideallcourseslink)) {
74 $this->content->footer .= "<a href=\"$CFG->wwwroot/course/index.php\">".get_string('fulllistofcourses').'</a> ...';
76 $this->title = get_string('categories');
77 } else { // Just print course names of single category
78 $category = array_shift($categories);
79 $courses = get_courses($category->id);
81 if ($courses) {
82 foreach ($courses as $course) {
83 $linkcss = $course->visible ? "" : " class=\"dimmed\" ";
85 $this->content->items[]="<a $linkcss title=\""
86 . format_string($course->shortname)."\" ".
87 "href=\"$CFG->wwwroot/course/view.php?id=$course->id\">"
88 . format_string($course->fullname) . "</a>";
89 $this->content->icons[]=$icon;
91 /// If we can update any course of the view all isn't hidden, show the view all courses link
92 if (has_capability('moodle/course:update', get_context_instance(CONTEXT_SYSTEM)) || empty($CFG->block_course_list_hideallcourseslink)) {
93 $this->content->footer .= "<a href=\"$CFG->wwwroot/course/index.php\">".get_string('fulllistofcourses').'</a> ...';
95 $this->get_remote_courses();
96 } else {
98 $this->content->icons[] = '';
99 $this->content->items[] = get_string('nocoursesyet');
100 if (has_capability('moodle/course:create', get_context_instance(CONTEXT_COURSECAT, $category->id))) {
101 $this->content->footer = '<a href="'.$CFG->wwwroot.'/course/edit.php?category='.$category->id.'">'.get_string("addnewcourse").'</a> ...';
103 $this->get_remote_courses();
105 $this->title = get_string('courses');
109 return $this->content;
112 function get_remote_courses() {
113 global $THEME, $CFG, $USER;
114 $icon = '<img src="'.$CFG->pixpath.'/i/mnethost.gif" class="icon" alt="'.get_string('course').'" />';
116 // only for logged in users!
117 if (!isloggedin() || isguest()) {
118 return false;
121 if ($courses = get_my_remotecourses()) {
122 $this->content->items[] = get_string('remotecourses','mnet');
123 $this->content->icons[] = '';
124 foreach ($courses as $course) {
125 $this->content->items[]="<a title=\"" . format_string($course->shortname) . "\" ".
126 "href=\"{$CFG->wwwroot}/auth/mnet/jump.php?hostid={$course->hostid}&amp;wantsurl=/course/view.php?id={$course->remoteid}\">"
127 . format_string($course->fullname) . "</a>";
128 $this->content->icons[]=$icon;
130 // if we listed courses, we are done
131 return true;
134 if ($hosts = get_my_remotehosts()) {
135 $this->content->items[] = get_string('remotemoodles','mnet');
136 $this->content->icons[] = '';
137 foreach($USER->mnet_foreign_host_array as $somehost) {
138 $this->content->items[] = $somehost['count'].get_string('courseson','mnet').'<a title="'.$somehost['name'].'" href="'.$somehost['url'].'">'.$somehost['name'].'</a>';
139 $this->content->icons[] = $icon;
141 // if we listed hosts, done
142 return true;
145 return false;