/**
  * Test course_get_user_administration_options for students in a normal course.
  */
 public function test_course_get_user_administration_options_for_students()
 {
     global $DB, $CFG;
     $this->resetAfterTest();
     $course = $this->getDataGenerator()->create_course();
     $context = context_course::instance($course->id);
     $user = $this->getDataGenerator()->create_user();
     $roleid = $DB->get_field('role', 'id', array('shortname' => 'student'));
     $this->getDataGenerator()->enrol_user($user->id, $course->id, $roleid);
     $this->setUser($user);
     $adminoptions = course_get_user_administration_options($course, $context);
     $this->assertFalse($adminoptions->update);
     $this->assertFalse($adminoptions->filters);
     $this->assertFalse($adminoptions->reports);
     $this->assertFalse($adminoptions->backup);
     $this->assertFalse($adminoptions->restore);
     $this->assertFalse($adminoptions->files);
     $this->assertFalse($adminoptions->tags);
     $this->assertFalse($adminoptions->gradebook);
     $this->assertFalse($adminoptions->outcomes);
     $this->assertTrue($adminoptions->badges);
     $this->assertFalse($adminoptions->import);
     $this->assertFalse($adminoptions->publish);
     $this->assertFalse($adminoptions->reset);
     $this->assertFalse($adminoptions->roles);
     $CFG->enablebadges = false;
     $adminoptions = course_get_user_administration_options($course, $context);
     $this->assertFalse($adminoptions->badges);
 }
Exemple #2
0
 /**
  * Return a list of administration options in a set of courses that are available or not for the current user.
  *
  * @param array $courseids a list of course ids
  * @return array of warnings and the options availability
  * @since Moodle 3.2
  * @throws moodle_exception
  */
 public static function get_user_administration_options($courseids)
 {
     global $CFG;
     require_once $CFG->dirroot . '/course/lib.php';
     // Parameter validation.
     $params = self::validate_parameters(self::get_user_administration_options_parameters(), array('courseids' => $courseids));
     $courseoptions = array();
     list($courses, $warnings) = external_util::validate_courses($params['courseids'], array(), true);
     if (!empty($courses)) {
         foreach ($courses as $course) {
             $adminoptions = course_get_user_administration_options($course, $course->context);
             $options = array();
             foreach ($adminoptions as $name => $available) {
                 $options[] = array('name' => $name, 'available' => $available);
             }
             $courseoptions[] = array('id' => $course->id, 'options' => $options);
         }
     }
     $result = array('courses' => $courseoptions, 'warnings' => $warnings);
     return $result;
 }
Exemple #3
0
 /**
  * This function loads all of the front page settings into the settings navigation.
  * This function is called when the user is on the front page, or $COURSE==$SITE
  * @param bool $forceopen (optional)
  * @return navigation_node
  */
 protected function load_front_page_settings($forceopen = false)
 {
     global $SITE, $CFG;
     require_once $CFG->dirroot . '/course/lib.php';
     $course = clone $SITE;
     $coursecontext = context_course::instance($course->id);
     // Course context
     $adminoptions = course_get_user_administration_options($course, $coursecontext);
     $frontpage = $this->add(get_string('frontpagesettings'), null, self::TYPE_SETTING, null, 'frontpage');
     if ($forceopen) {
         $frontpage->force_open();
     }
     $frontpage->id = 'frontpagesettings';
     if ($this->page->user_allowed_editing()) {
         // Add the turn on/off settings
         $url = new moodle_url('/course/view.php', array('id' => $course->id, 'sesskey' => sesskey()));
         if ($this->page->user_is_editing()) {
             $url->param('edit', 'off');
             $editstring = get_string('turneditingoff');
         } else {
             $url->param('edit', 'on');
             $editstring = get_string('turneditingon');
         }
         $frontpage->add($editstring, $url, self::TYPE_SETTING, null, null, new pix_icon('i/edit', ''));
     }
     if ($adminoptions->update) {
         // Add the course settings link
         $url = new moodle_url('/admin/settings.php', array('section' => 'frontpagesettings'));
         $frontpage->add(get_string('editsettings'), $url, self::TYPE_SETTING, null, null, new pix_icon('i/settings', ''));
     }
     // add enrol nodes
     enrol_add_course_navigation($frontpage, $course);
     // Manage filters
     if ($adminoptions->filters) {
         $url = new moodle_url('/filter/manage.php', array('contextid' => $coursecontext->id));
         $frontpage->add(get_string('filters', 'admin'), $url, self::TYPE_SETTING, null, null, new pix_icon('i/filter', ''));
     }
     // View course reports.
     if ($adminoptions->reports) {
         $frontpagenav = $frontpage->add(get_string('reports'), null, self::TYPE_CONTAINER, null, 'frontpagereports', 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($frontpagenav, $course, $coursecontext);
                 }
             }
         }
         $reports = get_plugin_list_with_function('report', 'extend_navigation_course', 'lib.php');
         foreach ($reports as $reportfunction) {
             $reportfunction($frontpagenav, $course, $coursecontext);
         }
     }
     // Backup this course
     if ($adminoptions->backup) {
         $url = new moodle_url('/backup/backup.php', array('id' => $course->id));
         $frontpage->add(get_string('backup'), $url, self::TYPE_SETTING, null, null, new pix_icon('i/backup', ''));
     }
     // Restore to this course
     if ($adminoptions->restore) {
         $url = new moodle_url('/backup/restorefile.php', array('contextid' => $coursecontext->id));
         $frontpage->add(get_string('restore'), $url, self::TYPE_SETTING, null, null, new pix_icon('i/restore', ''));
     }
     // Questions
     require_once $CFG->libdir . '/questionlib.php';
     question_extend_settings_navigation($frontpage, $coursecontext)->trim_if_empty();
     // Manage files
     if ($adminoptions->files) {
         //hiden in new installs
         $url = new moodle_url('/files/index.php', array('contextid' => $coursecontext->id));
         $frontpage->add(get_string('sitelegacyfiles'), $url, self::TYPE_SETTING, null, null, new pix_icon('i/folder', ''));
     }
     // Let plugins hook into frontpage navigation.
     $pluginsfunction = get_plugins_with_function('extend_navigation_frontpage', 'lib.php');
     foreach ($pluginsfunction as $plugintype => $plugins) {
         foreach ($plugins as $pluginfunction) {
             $pluginfunction($frontpage, $course, $coursecontext);
         }
     }
     return $frontpage;
 }