[ Index ]

PHP Cross Reference of Moodle 1.9.3 [Build 15-Oct-2008]

title

Body

[close]

/blocks/course_list/ -> block_course_list.php (source)

   1  <?PHP //$Id: block_course_list.php,v 1.46.2.6 2008/08/29 04:23:38 peterbulmer Exp $
   2  
   3  include_once($CFG->dirroot . '/course/lib.php');
   4  
   5  class block_course_list extends block_list {
   6      function init() {
   7          $this->title = get_string('courses');
   8          $this->version = 2007101509;
   9      }
  10      
  11      function has_config() {
  12          return true;
  13      }
  14  
  15      function get_content() {
  16          global $THEME, $CFG, $USER;
  17  
  18          if($this->content !== NULL) {
  19              return $this->content;
  20          }
  21  
  22          $this->content = new stdClass;
  23          $this->content->items = array();
  24          $this->content->icons = array();
  25          $this->content->footer = '';
  26  
  27          $icon  = "<img src=\"$CFG->pixpath/i/course.gif\"".
  28                   " class=\"icon\" alt=\"".get_string("coursecategory")."\" />";
  29         
  30          $adminseesall = true;
  31          if (isset($CFG->block_course_list_adminview)) {
  32             if ( $CFG->block_course_list_adminview == 'own'){
  33                 $adminseesall = false;
  34             }
  35          }
  36  
  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;
  45                      }
  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;
  50                  }
  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> ...";
  55                  }
  56              }
  57              $this->get_remote_courses();
  58              if ($this->content->items) { // make sure we don't return an empty list
  59                  return $this->content;
  60              }
  61          }
  62  
  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;
  70                  }
  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> ...';
  74                  }
  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);
  79  
  80                  if ($courses) {
  81                      foreach ($courses as $course) {
  82                          $linkcss = $course->visible ? "" : " class=\"dimmed\" ";
  83  
  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;
  89                      }
  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> ...';
  93                      }
  94                      $this->get_remote_courses();
  95                  } else {
  96                      
  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> ...';
 101                      }
 102                      $this->get_remote_courses();
 103                  }
 104                  $this->title = get_string('courses');
 105              }
 106          }
 107  
 108          return $this->content;
 109      }
 110  
 111      function get_remote_courses() {
 112          global $THEME, $CFG, $USER;
 113  
 114          if (!is_enabled_auth('mnet')) {
 115              // no need to query anything remote related
 116              return;
 117          }
 118  
 119          $icon  = '<img src="'.$CFG->pixpath.'/i/mnethost.gif" class="icon" alt="'.get_string('course').'" />';
 120  
 121          // only for logged in users!
 122          if (!isloggedin() || isguest()) {
 123              return false;
 124          }
 125  
 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;
 134              }
 135              // if we listed courses, we are done
 136              return true;
 137          }
 138  
 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;
 145              }
 146              // if we listed hosts, done
 147              return true;
 148          }
 149  
 150          return false;
 151      }
 152  
 153  }
 154  
 155  ?>


Generated: Wed Jan 14 11:33:29 2009 Cross-referenced by PHPXref 0.7