Ejemplo n.º 1
0
 /**
  * This function loads the course settings that are available for the user
  *
  * @param bool $forceopen If set to true the course node will be forced open
  * @return navigation_node|false
  */
 protected function load_course_settings($forceopen = false)
 {
     global $CFG;
     $course = $this->page->course;
     $coursecontext = context_course::instance($course->id);
     // note: do not test if enrolled or viewing here because we need the enrol link in Course administration section
     $coursenode = $this->add(get_string('courseadministration'), null, self::TYPE_COURSE, null, 'courseadmin');
     if ($forceopen) {
         $coursenode->force_open();
     }
     if ($this->page->user_allowed_editing()) {
         // Add the turn on/off settings
         if ($this->page->url->compare(new moodle_url('/course/view.php'), URL_MATCH_BASE)) {
             // We are on the course page, retain the current page params e.g. section.
             $baseurl = clone $this->page->url;
             $baseurl->param('sesskey', sesskey());
         } else {
             // Edit on the main course page.
             $baseurl = new moodle_url('/course/view.php', array('id' => $course->id, 'return' => $this->page->url->out_as_local_url(false), 'sesskey' => sesskey()));
         }
         $editurl = clone $baseurl;
         if ($this->page->user_is_editing()) {
             $editurl->param('edit', 'off');
             $editstring = get_string('turneditingoff');
         } else {
             $editurl->param('edit', 'on');
             $editstring = get_string('turneditingon');
         }
         $coursenode->add($editstring, $editurl, self::TYPE_SETTING, null, 'turneditingonoff', new pix_icon('i/edit', ''));
     }
     if (has_capability('moodle/course:update', $coursecontext)) {
         // Add the course settings link
         $url = new moodle_url('/course/edit.php', array('id' => $course->id));
         $coursenode->add(get_string('editsettings'), $url, self::TYPE_SETTING, null, 'editsettings', new pix_icon('i/settings', ''));
         // Add the course completion settings link
         if ($CFG->enablecompletion && $course->enablecompletion) {
             $url = new moodle_url('/course/completion.php', array('id' => $course->id));
             $coursenode->add(get_string('coursecompletion', 'completion'), $url, self::TYPE_SETTING, null, null, new pix_icon('i/settings', ''));
         }
     } else {
         if (has_capability('moodle/course:tag', $coursecontext)) {
             $url = new moodle_url('/course/tags.php', array('id' => $course->id));
             $coursenode->add(get_string('coursetags', 'tag'), $url, self::TYPE_SETTING, null, 'coursetags', new pix_icon('i/settings', ''));
         }
     }
     // add enrol nodes
     enrol_add_course_navigation($coursenode, $course);
     // Manage filters
     if (has_capability('moodle/filter:manage', $coursecontext) && count(filter_get_available_in_context($coursecontext)) > 0) {
         $url = new moodle_url('/filter/manage.php', array('contextid' => $coursecontext->id));
         $coursenode->add(get_string('filters', 'admin'), $url, self::TYPE_SETTING, null, null, new pix_icon('i/filter', ''));
     }
     // View course reports.
     if (has_capability('moodle/site:viewreports', $coursecontext)) {
         // Basic capability for listing of reports.
         $reportnav = $coursenode->add(get_string('reports'), null, self::TYPE_CONTAINER, null, 'coursereports', new pix_icon('i/stats', ''));
         $coursereports = core_component::get_plugin_list('coursereport');
         foreach ($coursereports as $report => $dir) {
             $libfile = $CFG->dirroot . '/course/report/' . $report . '/lib.php';
             if (file_exists($libfile)) {
                 require_once $libfile;
                 $reportfunction = $report . '_report_extend_navigation';
                 if (function_exists($report . '_report_extend_navigation')) {
                     $reportfunction($reportnav, $course, $coursecontext);
                 }
             }
         }
         $reports = get_plugin_list_with_function('report', 'extend_navigation_course', 'lib.php');
         foreach ($reports as $reportfunction) {
             $reportfunction($reportnav, $course, $coursecontext);
         }
     }
     // Add view grade report is permitted
     $reportavailable = false;
     if (has_capability('moodle/grade:viewall', $coursecontext)) {
         $reportavailable = true;
     } else {
         if (!empty($course->showgrades)) {
             $reports = core_component::get_plugin_list('gradereport');
             if (is_array($reports) && count($reports) > 0) {
                 // Get all installed reports
                 arsort($reports);
                 // user is last, we want to test it first
                 foreach ($reports as $plugin => $plugindir) {
                     if (has_capability('gradereport/' . $plugin . ':view', $coursecontext)) {
                         //stop when the first visible plugin is found
                         $reportavailable = true;
                         break;
                     }
                 }
             }
         }
     }
     if ($reportavailable) {
         $url = new moodle_url('/grade/report/index.php', array('id' => $course->id));
         $gradenode = $coursenode->add(get_string('grades'), $url, self::TYPE_SETTING, null, 'grades', new pix_icon('i/grades', ''));
     }
     // Check if we can view the gradebook's setup page.
     if (has_capability('moodle/grade:manage', $coursecontext)) {
         $url = new moodle_url('/grade/edit/tree/index.php', array('id' => $course->id));
         $coursenode->add(get_string('gradebooksetup', 'grades'), $url, self::TYPE_SETTING, null, 'gradebooksetup', new pix_icon('i/settings', ''));
     }
     //  Add outcome if permitted
     if (!empty($CFG->enableoutcomes) && has_capability('moodle/course:update', $coursecontext)) {
         $url = new moodle_url('/grade/edit/outcome/course.php', array('id' => $course->id));
         $coursenode->add(get_string('outcomes', 'grades'), $url, self::TYPE_SETTING, null, 'outcomes', new pix_icon('i/outcomes', ''));
     }
     //Add badges navigation
     if (!empty($CFG->enablebadges)) {
         require_once $CFG->libdir . '/badgeslib.php';
         badges_add_course_navigation($coursenode, $course);
     }
     // Backup this course
     if (has_capability('moodle/backup:backupcourse', $coursecontext)) {
         $url = new moodle_url('/backup/backup.php', array('id' => $course->id));
         $coursenode->add(get_string('backup'), $url, self::TYPE_SETTING, null, 'backup', new pix_icon('i/backup', ''));
     }
     // Restore to this course
     if (has_capability('moodle/restore:restorecourse', $coursecontext)) {
         $url = new moodle_url('/backup/restorefile.php', array('contextid' => $coursecontext->id));
         $coursenode->add(get_string('restore'), $url, self::TYPE_SETTING, null, 'restore', new pix_icon('i/restore', ''));
     }
     // Import data from other courses
     if (has_capability('moodle/restore:restoretargetimport', $coursecontext)) {
         $url = new moodle_url('/backup/import.php', array('id' => $course->id));
         $coursenode->add(get_string('import'), $url, self::TYPE_SETTING, null, 'import', new pix_icon('i/import', ''));
     }
     // Publish course on a hub
     if (has_capability('moodle/course:publish', $coursecontext)) {
         $url = new moodle_url('/course/publish/index.php', array('id' => $course->id));
         $coursenode->add(get_string('publish'), $url, self::TYPE_SETTING, null, 'publish', new pix_icon('i/publish', ''));
     }
     // Reset this course
     if (has_capability('moodle/course:reset', $coursecontext)) {
         $url = new moodle_url('/course/reset.php', array('id' => $course->id));
         $coursenode->add(get_string('reset'), $url, self::TYPE_SETTING, null, 'reset', new pix_icon('i/return', ''));
     }
     // Questions
     require_once $CFG->libdir . '/questionlib.php';
     question_extend_settings_navigation($coursenode, $coursecontext)->trim_if_empty();
     if (has_capability('moodle/course:update', $coursecontext)) {
         // Repository Instances
         if (!$this->cache->cached('contexthasrepos' . $coursecontext->id)) {
             require_once $CFG->dirroot . '/repository/lib.php';
             $editabletypes = repository::get_editable_types($coursecontext);
             $haseditabletypes = !empty($editabletypes);
             unset($editabletypes);
             $this->cache->set('contexthasrepos' . $coursecontext->id, $haseditabletypes);
         } else {
             $haseditabletypes = $this->cache->{'contexthasrepos' . $coursecontext->id};
         }
         if ($haseditabletypes) {
             $url = new moodle_url('/repository/manage_instances.php', array('contextid' => $coursecontext->id));
             $coursenode->add(get_string('repositories'), $url, self::TYPE_SETTING, null, null, new pix_icon('i/repository', ''));
         }
     }
     // Manage files
     if ($course->legacyfiles == 2 and has_capability('moodle/course:managefiles', $coursecontext)) {
         // hidden in new courses and courses where legacy files were turned off
         $url = new moodle_url('/files/index.php', array('contextid' => $coursecontext->id));
         $coursenode->add(get_string('courselegacyfiles'), $url, self::TYPE_SETTING, null, 'coursefiles', new pix_icon('i/folder', ''));
     }
     // Switch roles
     $roles = array();
     $assumedrole = $this->in_alternative_role();
     if ($assumedrole !== false) {
         $roles[0] = get_string('switchrolereturn');
     }
     if (has_capability('moodle/role:switchroles', $coursecontext)) {
         $availableroles = get_switchable_roles($coursecontext);
         if (is_array($availableroles)) {
             foreach ($availableroles as $key => $role) {
                 if ($assumedrole == (int) $key) {
                     continue;
                 }
                 $roles[$key] = $role;
             }
         }
     }
     if (is_array($roles) && count($roles) > 0) {
         $switchroles = $this->add(get_string('switchroleto'), null, self::TYPE_CONTAINER, null, 'switchroleto');
         if (count($roles) == 1 && array_key_exists(0, $roles) || $assumedrole !== false) {
             $switchroles->force_open();
         }
         foreach ($roles as $key => $name) {
             $url = new moodle_url('/course/switchrole.php', array('id' => $course->id, 'sesskey' => sesskey(), 'switchrole' => $key, 'returnurl' => $this->page->url->out_as_local_url(false)));
             $switchroles->add($name, $url, self::TYPE_SETTING, null, $key, new pix_icon('i/switchrole', ''));
         }
     }
     // Let plugins hook into course navigation.
     $pluginsfunction = get_plugins_with_function('extend_navigation_course', 'lib.php');
     foreach ($pluginsfunction as $plugintype => $plugins) {
         // Ignore the report plugin as it was already loaded above.
         if ($plugintype == 'report') {
             continue;
         }
         foreach ($plugins as $pluginfunction) {
             $pluginfunction($coursenode, $course, $coursecontext);
         }
     }
     // Return we are done
     return $coursenode;
 }
Ejemplo n.º 2
0
 /**
  * This function loads the course settings that are available for the user
  *
  * @param bool $forceopen If set to true the course node will be forced open
  * @return navigation_node|false
  */
 protected function load_course_settings($forceopen = false)
 {
     global $CFG;
     require_once $CFG->dirroot . '/course/lib.php';
     $course = $this->page->course;
     $coursecontext = context_course::instance($course->id);
     $adminoptions = course_get_user_administration_options($course, $coursecontext);
     // note: do not test if enrolled or viewing here because we need the enrol link in Course administration section
     $coursenode = $this->add(get_string('courseadministration'), null, self::TYPE_COURSE, null, 'courseadmin');
     if ($forceopen) {
         $coursenode->force_open();
     }
     if ($adminoptions->update) {
         // Add the course settings link
         $url = new moodle_url('/course/edit.php', array('id' => $course->id));
         $coursenode->add(get_string('editsettings'), $url, self::TYPE_SETTING, null, 'editsettings', new pix_icon('i/settings', ''));
     }
     if ($this->page->user_allowed_editing()) {
         // Add the turn on/off settings
         if ($this->page->url->compare(new moodle_url('/course/view.php'), URL_MATCH_BASE)) {
             // We are on the course page, retain the current page params e.g. section.
             $baseurl = clone $this->page->url;
             $baseurl->param('sesskey', sesskey());
         } else {
             // Edit on the main course page.
             $baseurl = new moodle_url('/course/view.php', array('id' => $course->id, 'return' => $this->page->url->out_as_local_url(false), 'sesskey' => sesskey()));
         }
         $editurl = clone $baseurl;
         if ($this->page->user_is_editing()) {
             $editurl->param('edit', 'off');
             $editstring = get_string('turneditingoff');
         } else {
             $editurl->param('edit', 'on');
             $editstring = get_string('turneditingon');
         }
         $coursenode->add($editstring, $editurl, self::TYPE_SETTING, null, 'turneditingonoff', new pix_icon('i/edit', ''));
     }
     if ($adminoptions->update) {
         // Add the course completion settings link
         if ($CFG->enablecompletion && $course->enablecompletion) {
             $url = new moodle_url('/course/completion.php', array('id' => $course->id));
             $coursenode->add(get_string('coursecompletion', 'completion'), $url, self::TYPE_SETTING, null, null, new pix_icon('i/settings', ''));
         }
     } else {
         if ($adminoptions->tags) {
             $url = new moodle_url('/course/tags.php', array('id' => $course->id));
             $coursenode->add(get_string('coursetags', 'tag'), $url, self::TYPE_SETTING, null, 'coursetags', new pix_icon('i/settings', ''));
         }
     }
     // add enrol nodes
     enrol_add_course_navigation($coursenode, $course);
     // Manage filters
     if ($adminoptions->filters) {
         $url = new moodle_url('/filter/manage.php', array('contextid' => $coursecontext->id));
         $coursenode->add(get_string('filters', 'admin'), $url, self::TYPE_SETTING, null, null, new pix_icon('i/filter', ''));
     }
     // View course reports.
     if ($adminoptions->reports) {
         $reportnav = $coursenode->add(get_string('reports'), null, self::TYPE_CONTAINER, null, 'coursereports', new pix_icon('i/stats', ''));
         $coursereports = core_component::get_plugin_list('coursereport');
         foreach ($coursereports as $report => $dir) {
             $libfile = $CFG->dirroot . '/course/report/' . $report . '/lib.php';
             if (file_exists($libfile)) {
                 require_once $libfile;
                 $reportfunction = $report . '_report_extend_navigation';
                 if (function_exists($report . '_report_extend_navigation')) {
                     $reportfunction($reportnav, $course, $coursecontext);
                 }
             }
         }
         $reports = get_plugin_list_with_function('report', 'extend_navigation_course', 'lib.php');
         foreach ($reports as $reportfunction) {
             $reportfunction($reportnav, $course, $coursecontext);
         }
     }
     // Check if we can view the gradebook's setup page.
     if ($adminoptions->gradebook) {
         $url = new moodle_url('/grade/edit/tree/index.php', array('id' => $course->id));
         $coursenode->add(get_string('gradebooksetup', 'grades'), $url, self::TYPE_SETTING, null, 'gradebooksetup', new pix_icon('i/settings', ''));
     }
     //  Add outcome if permitted
     if ($adminoptions->outcomes) {
         $url = new moodle_url('/grade/edit/outcome/course.php', array('id' => $course->id));
         $coursenode->add(get_string('outcomes', 'grades'), $url, self::TYPE_SETTING, null, 'outcomes', new pix_icon('i/outcomes', ''));
     }
     //Add badges navigation
     if ($adminoptions->badges) {
         require_once $CFG->libdir . '/badgeslib.php';
         badges_add_course_navigation($coursenode, $course);
     }
     // Backup this course
     if ($adminoptions->backup) {
         $url = new moodle_url('/backup/backup.php', array('id' => $course->id));
         $coursenode->add(get_string('backup'), $url, self::TYPE_SETTING, null, 'backup', new pix_icon('i/backup', ''));
     }
     // Restore to this course
     if ($adminoptions->restore) {
         $url = new moodle_url('/backup/restorefile.php', array('contextid' => $coursecontext->id));
         $coursenode->add(get_string('restore'), $url, self::TYPE_SETTING, null, 'restore', new pix_icon('i/restore', ''));
     }
     // Import data from other courses
     if ($adminoptions->import) {
         $url = new moodle_url('/backup/import.php', array('id' => $course->id));
         $coursenode->add(get_string('import'), $url, self::TYPE_SETTING, null, 'import', new pix_icon('i/import', ''));
     }
     // Publish course on a hub
     if ($adminoptions->publish) {
         $url = new moodle_url('/course/publish/index.php', array('id' => $course->id));
         $coursenode->add(get_string('publish'), $url, self::TYPE_SETTING, null, 'publish', new pix_icon('i/publish', ''));
     }
     // Reset this course
     if ($adminoptions->reset) {
         $url = new moodle_url('/course/reset.php', array('id' => $course->id));
         $coursenode->add(get_string('reset'), $url, self::TYPE_SETTING, null, 'reset', new pix_icon('i/return', ''));
     }
     // Questions
     require_once $CFG->libdir . '/questionlib.php';
     question_extend_settings_navigation($coursenode, $coursecontext)->trim_if_empty();
     if ($adminoptions->update) {
         // Repository Instances
         if (!$this->cache->cached('contexthasrepos' . $coursecontext->id)) {
             require_once $CFG->dirroot . '/repository/lib.php';
             $editabletypes = repository::get_editable_types($coursecontext);
             $haseditabletypes = !empty($editabletypes);
             unset($editabletypes);
             $this->cache->set('contexthasrepos' . $coursecontext->id, $haseditabletypes);
         } else {
             $haseditabletypes = $this->cache->{'contexthasrepos' . $coursecontext->id};
         }
         if ($haseditabletypes) {
             $url = new moodle_url('/repository/manage_instances.php', array('contextid' => $coursecontext->id));
             $coursenode->add(get_string('repositories'), $url, self::TYPE_SETTING, null, null, new pix_icon('i/repository', ''));
         }
     }
     // Manage files
     if ($adminoptions->files) {
         // hidden in new courses and courses where legacy files were turned off
         $url = new moodle_url('/files/index.php', array('contextid' => $coursecontext->id));
         $coursenode->add(get_string('courselegacyfiles'), $url, self::TYPE_SETTING, null, 'coursefiles', new pix_icon('i/folder', ''));
     }
     // Let plugins hook into course navigation.
     $pluginsfunction = get_plugins_with_function('extend_navigation_course', 'lib.php');
     foreach ($pluginsfunction as $plugintype => $plugins) {
         // Ignore the report plugin as it was already loaded above.
         if ($plugintype == 'report') {
             continue;
         }
         foreach ($plugins as $pluginfunction) {
             $pluginfunction($coursenode, $course, $coursecontext);
         }
     }
     // Return we are done
     return $coursenode;
 }