[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

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

   1  <?php
   2  // This file is part of Moodle - http://moodle.org/
   3  //
   4  // Moodle is free software: you can redistribute it and/or modify
   5  // it under the terms of the GNU General Public License as published by
   6  // the Free Software Foundation, either version 3 of the License, or
   7  // (at your option) any later version.
   8  //
   9  // Moodle is distributed in the hope that it will be useful,
  10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12  // GNU General Public License for more details.
  13  //
  14  // You should have received a copy of the GNU General Public License
  15  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  16  
  17  /**
  18   * Course list block.
  19   *
  20   * @package    block_course_list
  21   * @copyright  1999 onwards Martin Dougiamas (http://dougiamas.com)
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  include_once($CFG->dirroot . '/course/lib.php');
  26  include_once($CFG->libdir . '/coursecatlib.php');
  27  
  28  class block_course_list extends block_list {
  29      function init() {
  30          $this->title = get_string('pluginname', 'block_course_list');
  31      }
  32  
  33      function has_config() {
  34          return true;
  35      }
  36  
  37      function get_content() {
  38          global $CFG, $USER, $DB, $OUTPUT;
  39  
  40          if($this->content !== NULL) {
  41              return $this->content;
  42          }
  43  
  44          $this->content = new stdClass;
  45          $this->content->items = array();
  46          $this->content->icons = array();
  47          $this->content->footer = '';
  48  
  49          $icon  = '<img src="' . $OUTPUT->pix_url('i/course') . '" class="icon" alt="" />';
  50  
  51          $adminseesall = true;
  52          if (isset($CFG->block_course_list_adminview)) {
  53             if ( $CFG->block_course_list_adminview == 'own'){
  54                 $adminseesall = false;
  55             }
  56          }
  57  
  58          if (empty($CFG->disablemycourses) and isloggedin() and !isguestuser() and
  59            !(has_capability('moodle/course:update', context_system::instance()) and $adminseesall)) {    // Just print My Courses
  60              // As this is producing navigation sort order should default to $CFG->navsortmycoursessort instead
  61              // of using the default.
  62              if (!empty($CFG->navsortmycoursessort)) {
  63                  $sortorder = 'visible DESC, ' . $CFG->navsortmycoursessort . ' ASC';
  64              } else {
  65                  $sortorder = 'visible DESC, sortorder ASC';
  66              }
  67              if ($courses = enrol_get_my_courses(NULL, $sortorder)) {
  68                  foreach ($courses as $course) {
  69                      $coursecontext = context_course::instance($course->id);
  70                      $linkcss = $course->visible ? "" : " class=\"dimmed\" ";
  71                      $this->content->items[]="<a $linkcss title=\"" . format_string($course->shortname, true, array('context' => $coursecontext)) . "\" ".
  72                                 "href=\"$CFG->wwwroot/course/view.php?id=$course->id\">".$icon.format_string(get_course_display_name_for_list($course)). "</a>";
  73                  }
  74                  $this->title = get_string('mycourses');
  75              /// If we can update any course of the view all isn't hidden, show the view all courses link
  76                  if (has_capability('moodle/course:update', context_system::instance()) || empty($CFG->block_course_list_hideallcourseslink)) {
  77                      $this->content->footer = "<a href=\"$CFG->wwwroot/course/index.php\">".get_string("fulllistofcourses")."</a> ...";
  78                  }
  79              }
  80              $this->get_remote_courses();
  81              if ($this->content->items) { // make sure we don't return an empty list
  82                  return $this->content;
  83              }
  84          }
  85  
  86          $categories = coursecat::get(0)->get_children();  // Parent = 0   ie top-level categories only
  87          if ($categories) {   //Check we have categories
  88              if (count($categories) > 1 || (count($categories) == 1 && $DB->count_records('course') > 200)) {     // Just print top level category links
  89                  foreach ($categories as $category) {
  90                      $categoryname = $category->get_formatted_name();
  91                      $linkcss = $category->visible ? "" : " class=\"dimmed\" ";
  92                      $this->content->items[]="<a $linkcss href=\"$CFG->wwwroot/course/index.php?categoryid=$category->id\">".$icon . $categoryname . "</a>";
  93                  }
  94              /// If we can update any course of the view all isn't hidden, show the view all courses link
  95                  if (has_capability('moodle/course:update', context_system::instance()) || empty($CFG->block_course_list_hideallcourseslink)) {
  96                      $this->content->footer .= "<a href=\"$CFG->wwwroot/course/index.php\">".get_string('fulllistofcourses').'</a> ...';
  97                  }
  98                  $this->title = get_string('categories');
  99              } else {                          // Just print course names of single category
 100                  $category = array_shift($categories);
 101                  $courses = get_courses($category->id);
 102  
 103                  if ($courses) {
 104                      foreach ($courses as $course) {
 105                          $coursecontext = context_course::instance($course->id);
 106                          $linkcss = $course->visible ? "" : " class=\"dimmed\" ";
 107  
 108                          $this->content->items[]="<a $linkcss title=\""
 109                                     . format_string($course->shortname, true, array('context' => $coursecontext))."\" ".
 110                                     "href=\"$CFG->wwwroot/course/view.php?id=$course->id\">"
 111                                     .$icon. format_string(get_course_display_name_for_list($course), true, array('context' => context_course::instance($course->id))) . "</a>";
 112                      }
 113                  /// If we can update any course of the view all isn't hidden, show the view all courses link
 114                      if (has_capability('moodle/course:update', context_system::instance()) || empty($CFG->block_course_list_hideallcourseslink)) {
 115                          $this->content->footer .= "<a href=\"$CFG->wwwroot/course/index.php\">".get_string('fulllistofcourses').'</a> ...';
 116                      }
 117                      $this->get_remote_courses();
 118                  } else {
 119  
 120                      $this->content->icons[] = '';
 121                      $this->content->items[] = get_string('nocoursesyet');
 122                      if (has_capability('moodle/course:create', context_coursecat::instance($category->id))) {
 123                          $this->content->footer = '<a href="'.$CFG->wwwroot.'/course/edit.php?category='.$category->id.'">'.get_string("addnewcourse").'</a> ...';
 124                      }
 125                      $this->get_remote_courses();
 126                  }
 127                  $this->title = get_string('courses');
 128              }
 129          }
 130  
 131          return $this->content;
 132      }
 133  
 134      function get_remote_courses() {
 135          global $CFG, $USER, $OUTPUT;
 136  
 137          if (!is_enabled_auth('mnet')) {
 138              // no need to query anything remote related
 139              return;
 140          }
 141  
 142          $icon = '<img src="'.$OUTPUT->pix_url('i/mnethost') . '" class="icon" alt="" />';
 143  
 144          // shortcut - the rest is only for logged in users!
 145          if (!isloggedin() || isguestuser()) {
 146              return false;
 147          }
 148  
 149          if ($courses = get_my_remotecourses()) {
 150              $this->content->items[] = get_string('remotecourses','mnet');
 151              $this->content->icons[] = '';
 152              foreach ($courses as $course) {
 153                  $this->content->items[]="<a title=\"" . format_string($course->shortname, true) . "\" ".
 154                      "href=\"{$CFG->wwwroot}/auth/mnet/jump.php?hostid={$course->hostid}&amp;wantsurl=/course/view.php?id={$course->remoteid}\">"
 155                      .$icon. format_string(get_course_display_name_for_list($course)) . "</a>";
 156              }
 157              // if we listed courses, we are done
 158              return true;
 159          }
 160  
 161          if ($hosts = get_my_remotehosts()) {
 162              $this->content->items[] = get_string('remotehosts', 'mnet');
 163              $this->content->icons[] = '';
 164              foreach($USER->mnet_foreign_host_array as $somehost) {
 165                  $this->content->items[] = $somehost['count'].get_string('courseson','mnet').'<a title="'.$somehost['name'].'" href="'.$somehost['url'].'">'.$icon.$somehost['name'].'</a>';
 166              }
 167              // if we listed hosts, done
 168              return true;
 169          }
 170  
 171          return false;
 172      }
 173  
 174      /**
 175       * Returns the role that best describes the course list block.
 176       *
 177       * @return string
 178       */
 179      public function get_aria_role() {
 180          return 'navigation';
 181      }
 182  }
 183  
 184  


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1