|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 00003 include_once($CFG->dirroot . '/course/lib.php'); 00004 00005 class block_course_list extends block_list { 00006 function init() { 00007 $this->title = get_string('courses'); 00008 } 00009 00010 function has_config() { 00011 return true; 00012 } 00013 00014 function get_content() { 00015 global $CFG, $USER, $DB, $OUTPUT; 00016 00017 if($this->content !== NULL) { 00018 return $this->content; 00019 } 00020 00021 $this->content = new stdClass; 00022 $this->content->items = array(); 00023 $this->content->icons = array(); 00024 $this->content->footer = ''; 00025 00026 $icon = '<img src="' . $OUTPUT->pix_url('i/course') . '" class="icon" alt="" /> '; 00027 00028 $adminseesall = true; 00029 if (isset($CFG->block_course_list_adminview)) { 00030 if ( $CFG->block_course_list_adminview == 'own'){ 00031 $adminseesall = false; 00032 } 00033 } 00034 00035 if (empty($CFG->disablemycourses) and isloggedin() and !isguestuser() and 00036 !(has_capability('moodle/course:update', get_context_instance(CONTEXT_SYSTEM)) and $adminseesall)) { // Just print My Courses 00037 if ($courses = enrol_get_my_courses(NULL, 'visible DESC, fullname ASC')) { 00038 foreach ($courses as $course) { 00039 $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id); 00040 $linkcss = $course->visible ? "" : " class=\"dimmed\" "; 00041 $this->content->items[]="<a $linkcss title=\"" . format_string($course->shortname, true, array('context' => $coursecontext)) . "\" ". 00042 "href=\"$CFG->wwwroot/course/view.php?id=$course->id\">".$icon.format_string($course->fullname). "</a>"; 00043 } 00044 $this->title = get_string('mycourses'); 00046 if (has_capability('moodle/course:update', get_context_instance(CONTEXT_SYSTEM)) || empty($CFG->block_course_list_hideallcourseslink)) { 00047 $this->content->footer = "<a href=\"$CFG->wwwroot/course/index.php\">".get_string("fulllistofcourses")."</a> ..."; 00048 } 00049 } 00050 $this->get_remote_courses(); 00051 if ($this->content->items) { // make sure we don't return an empty list 00052 return $this->content; 00053 } 00054 } 00055 00056 $categories = get_categories("0"); // Parent = 0 ie top-level categories only 00057 if ($categories) { //Check we have categories 00058 if (count($categories) > 1 || (count($categories) == 1 && $DB->count_records('course') > 200)) { // Just print top level category links 00059 foreach ($categories as $category) { 00060 $categoryname = format_string($category->name, true, array('context' => get_context_instance(CONTEXT_COURSECAT, $category->id))); 00061 $linkcss = $category->visible ? "" : " class=\"dimmed\" "; 00062 $this->content->items[]="<a $linkcss href=\"$CFG->wwwroot/course/category.php?id=$category->id\">".$icon . $categoryname . "</a>"; 00063 } 00065 if (has_capability('moodle/course:update', get_context_instance(CONTEXT_SYSTEM)) || empty($CFG->block_course_list_hideallcourseslink)) { 00066 $this->content->footer .= "<a href=\"$CFG->wwwroot/course/index.php\">".get_string('fulllistofcourses').'</a> ...'; 00067 } 00068 $this->title = get_string('categories'); 00069 } else { // Just print course names of single category 00070 $category = array_shift($categories); 00071 $courses = get_courses($category->id); 00072 00073 if ($courses) { 00074 foreach ($courses as $course) { 00075 $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id); 00076 $linkcss = $course->visible ? "" : " class=\"dimmed\" "; 00077 00078 $this->content->items[]="<a $linkcss title=\"" 00079 . format_string($course->shortname, true, array('context' => $coursecontext))."\" ". 00080 "href=\"$CFG->wwwroot/course/view.php?id=$course->id\">" 00081 .$icon. format_string($course->fullname, true, array('context' => get_context_instance(CONTEXT_COURSE, $course->id))) . "</a>"; 00082 } 00084 if (has_capability('moodle/course:update', get_context_instance(CONTEXT_SYSTEM)) || empty($CFG->block_course_list_hideallcourseslink)) { 00085 $this->content->footer .= "<a href=\"$CFG->wwwroot/course/index.php\">".get_string('fulllistofcourses').'</a> ...'; 00086 } 00087 $this->get_remote_courses(); 00088 } else { 00089 00090 $this->content->icons[] = ''; 00091 $this->content->items[] = get_string('nocoursesyet'); 00092 if (has_capability('moodle/course:create', get_context_instance(CONTEXT_COURSECAT, $category->id))) { 00093 $this->content->footer = '<a href="'.$CFG->wwwroot.'/course/edit.php?category='.$category->id.'">'.get_string("addnewcourse").'</a> ...'; 00094 } 00095 $this->get_remote_courses(); 00096 } 00097 $this->title = get_string('courses'); 00098 } 00099 } 00100 00101 return $this->content; 00102 } 00103 00104 function get_remote_courses() { 00105 global $CFG, $USER, $OUTPUT; 00106 00107 if (!is_enabled_auth('mnet')) { 00108 // no need to query anything remote related 00109 return; 00110 } 00111 00112 $icon = '<img src="'.$OUTPUT->pix_url('i/mnethost') . '" class="icon" alt="" /> '; 00113 00114 // shortcut - the rest is only for logged in users! 00115 if (!isloggedin() || isguestuser()) { 00116 return false; 00117 } 00118 00119 if ($courses = get_my_remotecourses()) { 00120 $this->content->items[] = get_string('remotecourses','mnet'); 00121 $this->content->icons[] = ''; 00122 foreach ($courses as $course) { 00123 $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id); 00124 $this->content->items[]="<a title=\"" . format_string($course->shortname, true, array('context' => $coursecontext)) . "\" ". 00125 "href=\"{$CFG->wwwroot}/auth/mnet/jump.php?hostid={$course->hostid}&wantsurl=/course/view.php?id={$course->remoteid}\">" 00126 .$icon. format_string($course->fullname) . "</a>"; 00127 } 00128 // if we listed courses, we are done 00129 return true; 00130 } 00131 00132 if ($hosts = get_my_remotehosts()) { 00133 $this->content->items[] = get_string('remotehosts', 'mnet'); 00134 $this->content->icons[] = ''; 00135 foreach($USER->mnet_foreign_host_array as $somehost) { 00136 $this->content->items[] = $somehost['count'].get_string('courseson','mnet').'<a title="'.$somehost['name'].'" href="'.$somehost['url'].'">'.$icon.$somehost['name'].'</a>'; 00137 } 00138 // if we listed hosts, done 00139 return true; 00140 } 00141 00142 return false; 00143 } 00144 00145 } 00146 00147