/**
  * generate list of course tools
  *
  * @author Guy Thomas
  * @date 2014-04-23
  * @return string
  */
 public static function appendices()
 {
     global $CFG, $COURSE, $PAGE, $OUTPUT;
     $links = array();
     $localplugins = core_component::get_plugin_list('local');
     $coursecontext = context_course::instance($COURSE->id);
     // Turn editing on.
     $iconsrc = $OUTPUT->pix_url('icon', 'label');
     $editcourseicon = '<img class="svg-icon" alt="" title="" src="' . $iconsrc . '">';
     $url = new moodle_url('/course/view.php', ['id' => $COURSE->id, 'sesskey' => sesskey()]);
     if ($PAGE->user_is_editing()) {
         $url->param('edit', 'off');
         $editstring = get_string('turneditingoff');
     } else {
         $url->param('edit', 'on');
         $editstring = get_string('editcoursecontent', 'theme_snap');
     }
     $links[] = array('link' => $url, 'title' => $editcourseicon . $editstring, 'capability' => 'moodle/course:update');
     // Course settings.
     $settingsicon = '<svg viewBox="0 0 100 100" class="svg-icon">
     <use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#coursetools-settings"></use></svg>';
     $links[] = array('link' => 'course/edit.php?id=' . $COURSE->id, 'title' => $settingsicon . get_string('editcoursesettings', 'theme_snap'), 'capability' => 'moodle/course:update');
     // Participants.
     $participanticon = '<svg viewBox="0 0 100 100" class="svg-icon">
     <use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#coursetools-participants"></use></svg>';
     $links[] = array('link' => 'user/index.php?id=' . $COURSE->id . '&mode=1', 'title' => $participanticon . get_string('participants'), 'capability' => 'moodle/course:viewparticipants');
     // Gradebook.
     $gradebookicon = '<svg viewBox="0 0 100 100" class="svg-icon">
     <use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#coursetools-gradbook"></use></svg>';
     if (self::gradebook_accessible($coursecontext)) {
         // Gradebook.
         $links[] = array('link' => 'grade/index.php?id=' . $COURSE->id, 'title' => $gradebookicon . get_string('gradebook', 'grades'));
     }
     // Only show if joule grader is installed.
     if (array_key_exists('joulegrader', $localplugins)) {
         if (has_capability('local/joulegrader:grade', $coursecontext) || has_capability('local/joulegrader:view', $coursecontext)) {
             $links[] = array('link' => 'local/joulegrader/view.php?courseid=' . $COURSE->id, 'title' => $gradebookicon . get_string('pluginname', 'local_joulegrader'));
         }
     }
     // Only show Norton grader if installed.
     if (array_key_exists('nortongrader', $localplugins)) {
         if (has_capability('local/nortongrader:grade', $coursecontext) || has_capability('local/nortongrader:view', $coursecontext)) {
             $links[] = array('link' => $CFG->wwwroot . '/local/nortongrader/view.php?courseid=' . $COURSE->id, 'title' => $gradebookicon . get_string('pluginname', 'local_nortongrader'));
         }
     }
     // Only show core outcomes if enabled.
     $outcomesicon = '<svg viewBox="0 0 100 100" class="svg-icon">
     <use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#coursetools-outcomes"></use></svg>';
     if (!empty($CFG->core_outcome_enable) && has_capability('moodle/grade:edit', $coursecontext)) {
         $links[] = array('link' => 'outcome/course.php?contextid=' . $coursecontext->id, 'title' => $outcomesicon . get_string('outcomes', 'outcome'));
     } else {
         if (!empty($CFG->core_outcome_enable) && !is_guest($coursecontext)) {
             $outcomesets = new \core_outcome\model\outcome_set_repository();
             if ($outcomesets->course_has_any_outcome_sets($COURSE->id)) {
                 $links[] = array('link' => 'outcome/course.php?contextid=' . $coursecontext->id . '&action=report_course_user_performance_table', 'title' => $participanticon . get_string('report:course_user_performance_table', 'outcome'));
             }
         }
     }
     $badgesicon = '<svg viewBox="0 0 100 100" class="svg-icon">
         <use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#coursetools-badges"></use></svg>';
     // Course badges.
     if (!empty($CFG->enablebadges) && !empty($CFG->badges_allowcoursebadges)) {
         // Match capabilities used by badges subsystem.
         $studentcaps = array('moodle/badges:earnbadge', 'moodle/badges:viewbadges');
         $teachercaps = array('moodle/badges:viewawarded', 'moodle/badges:createbadge', 'moodle/badges:awardbadge', 'moodle/badges:configuremessages', 'moodle/badges:configuredetails', 'moodle/badges:deletebadge');
         // Show link for students.
         if (!is_guest($coursecontext) && has_any_capability($studentcaps, $coursecontext)) {
             $links[] = array('link' => 'badges/view.php?type=' . BADGE_TYPE_COURSE . '&id=' . $COURSE->id, 'title' => $badgesicon . get_string('badgesview', 'badges'), 'capability' => '!moodle/course:update');
         }
         // Show link for trachers / admin staff.
         if (!is_guest($coursecontext) && has_any_capability($teachercaps, $coursecontext)) {
             $links[] = array('link' => 'badges/index.php?type=' . BADGE_TYPE_COURSE . '&id=' . $COURSE->id, 'title' => $badgesicon . get_string('managebadges', 'badges'));
         }
     }
     // Only show Joule reports if installed.
     $reportsicon = '<svg viewBox="0 0 100 100" class="svg-icon">
         <use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#coursetools-reports"></use></svg>';
     if (array_key_exists('reports', core_component::get_plugin_list('block'))) {
         if (has_capability('block/reports:viewown', $coursecontext, null, false) || has_capability('block/reports:view', $coursecontext)) {
             $links[] = array('link' => $CFG->wwwroot . '/blocks/reports/view.php?action=dashboard&courseid=' . $COURSE->id, 'title' => $reportsicon . get_string('joulereports', 'block_reports'));
         }
     }
     // Personalised Learning Designer.
     $pldicon = '<svg viewBox="0 0 100 100" class="svg-icon">
     <use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#coursetools-pld"></use></svg>';
     $pldname = get_string('pld', 'theme_snap');
     $links[] = array('link' => 'local/pld/view.php?courseid=' . $COURSE->id, 'title' => $pldicon . $pldname, 'capability' => 'moodle/course:update');
     // Course enrolment link.
     $plugins = enrol_get_plugins(true);
     $instances = enrol_get_instances($COURSE->id, true);
     $selfenrol = false;
     foreach ($instances as $instance) {
         // Need to check enrolment methods for self enrol.
         if ($instance->enrol === 'self') {
             $plugin = $plugins[$instance->enrol];
             if (is_enrolled($coursecontext)) {
                 // Prepare unenrolment link.
                 $enrolurl = $plugin->get_unenrolself_link($instance);
                 if ($enrolurl) {
                     $selfenrol = true;
                     $enrolstr = get_string('unenrolme', 'theme_snap');
                     break;
                 }
             } else {
                 if ($plugin->show_enrolme_link($instance)) {
                     // Prepare enrolment link.
                     $selfenrol = true;
                     $enrolurl = new moodle_url('/enrol/index.php', array('id' => $COURSE->id));
                     $enrolstr = get_string('enrolme', 'core_enrol');
                     break;
                 }
             }
         }
     }
     if ($selfenrol) {
         $enrolicon = '<svg viewBox="0 0 100 100" class="svg-icon">
         <use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#coursetools-settings"></use></svg>';
         $links[] = array('link' => $enrolurl, 'title' => $enrolicon . $enrolstr);
     }
     $toolssvg = self::inline_svg('tools.svg');
     // Output course tools.
     $coursetools = get_string('coursetools', 'theme_snap');
     $o = "<h2>{$coursetools}</h2>";
     $o .= "<div class='row'><div class='col-xs-4'>{$toolssvg}</div><div class='col-xs-8'><div id='coursetools-list'>" . self::render_appendices($links) . "</div></div></div><hr>";
     return $o;
 }
 /**
  * generate list of course tools
  *
  * @author Guy Thomas
  * @date 2014-04-23
  * @return string
  */
 public static function appendices()
 {
     global $CFG, $COURSE, $PAGE, $OUTPUT;
     $links = array();
     $localplugins = core_component::get_plugin_list('local');
     $coursecontext = context_course::instance($COURSE->id);
     // Turn editing on.
     $iconsrc = $OUTPUT->pix_url('icon', 'label');
     $editcourseicon = '<img class="svg-icon" alt="" title="" src="' . $iconsrc . '">';
     $url = new moodle_url('/course/view.php', ['id' => $COURSE->id, 'sesskey' => sesskey()]);
     if ($PAGE->user_is_editing()) {
         $url->param('edit', 'off');
         $editstring = get_string('turneditingoff');
     } else {
         $url->param('edit', 'on');
         $editstring = get_string('editcoursecontent', 'theme_snap');
     }
     $links[] = array('link' => $url, 'title' => $editcourseicon . $editstring, 'capability' => 'moodle/course:update');
     // Course settings.
     $settingsicon = '<svg viewBox="0 0 100 100" class="svg-icon">
     <use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#coursetools-settings"></use></svg>';
     $links[] = array('link' => 'course/edit.php?id=' . $COURSE->id, 'title' => $settingsicon . get_string('editcoursesettings', 'theme_snap'), 'capability' => 'moodle/course:update');
     // Participants.
     $participanticon = '<svg viewBox="0 0 100 100" class="svg-icon">
     <use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#coursetools-participants"></use></svg>';
     $links[] = array('link' => 'user/index.php?id=' . $COURSE->id . '&mode=1', 'title' => $participanticon . get_string('participants'), 'capability' => 'moodle/course:viewparticipants');
     // Gradebook.
     $gradebookicon = '<svg viewBox="0 0 100 100" class="svg-icon">
     <use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#coursetools-gradbook"></use></svg>';
     if (self::gradebook_accessible($coursecontext)) {
         // Gradebook.
         $links[] = array('link' => 'grade/index.php?id=' . $COURSE->id, 'title' => $gradebookicon . get_string('gradebook', 'grades'));
     }
     // Only show if joule grader is installed.
     if (array_key_exists('joulegrader', $localplugins)) {
         if (has_capability('local/joulegrader:grade', $coursecontext) || has_capability('local/joulegrader:view', $coursecontext)) {
             $links[] = array('link' => 'local/joulegrader/view.php?courseid=' . $COURSE->id, 'title' => $gradebookicon . get_string('pluginname', 'local_joulegrader'));
         }
     }
     // Only show Norton grader if installed.
     if (array_key_exists('nortongrader', $localplugins)) {
         if (has_capability('local/nortongrader:grade', $coursecontext) || has_capability('local/nortongrader:view', $coursecontext)) {
             $links[] = array('link' => $CFG->wwwroot . '/local/nortongrader/view.php?courseid=' . $COURSE->id, 'title' => $gradebookicon . get_string('pluginname', 'local_nortongrader'));
         }
     }
     // Only show core outcomes if enabled.
     $outcomesicon = '<svg viewBox="0 0 100 100" class="svg-icon">
     <use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#coursetools-outcomes"></use></svg>';
     if (!empty($CFG->core_outcome_enable) && has_capability('moodle/grade:edit', $coursecontext)) {
         $links[] = array('link' => 'outcome/course.php?contextid=' . $coursecontext->id, 'title' => $outcomesicon . get_string('outcomes', 'outcome'));
     } else {
         if (!empty($CFG->core_outcome_enable) && !is_guest($coursecontext)) {
             $outcomesets = new \core_outcome\model\outcome_set_repository();
             if ($outcomesets->course_has_any_outcome_sets($COURSE->id)) {
                 $links[] = array('link' => 'outcome/course.php?contextid=' . $coursecontext->id . '&action=report_course_user_performance_table', 'title' => $participanticon . get_string('report:course_user_performance_table', 'outcome'));
             }
         }
     }
     $badgesicon = '<svg viewBox="0 0 100 100" class="svg-icon">
         <use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#coursetools-badges"></use></svg>';
     // Course badges.
     if (!is_guest($coursecontext)) {
         $links[] = array('link' => 'badges/view.php?type=2&id=' . $COURSE->id, 'title' => $badgesicon . get_string('badgesview', 'badges'), 'capability' => '!moodle/course:update');
     }
     // Manage badges.
     $links[] = array('link' => 'badges/index.php?type=2&id=' . $COURSE->id, 'title' => $badgesicon . get_string('managebadges', 'badges'), 'capability' => 'moodle/course:update');
     // Only show Joule reports if installed.
     $reportsicon = '<svg viewBox="0 0 100 100" class="svg-icon">
         <use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#coursetools-reports"></use></svg>';
     if (array_key_exists('reports', core_component::get_plugin_list('block'))) {
         if (has_capability('block/reports:viewown', $coursecontext, null, false) || has_capability('block/reports:view', $coursecontext)) {
             $links[] = array('link' => $CFG->wwwroot . '/blocks/reports/view.php?action=dashboard&courseid=' . $COURSE->id, 'title' => $reportsicon . get_string('joulereports', 'block_reports'));
         }
     }
     // Personalised Learning Designer.
     $pldicon = '<svg viewBox="0 0 100 100" class="svg-icon">
     <use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#coursetools-pld"></use></svg>';
     $pldname = get_string('pld', 'theme_snap');
     $links[] = array('link' => 'local/pld/view.php?courseid=' . $COURSE->id, 'title' => $pldicon . $pldname, 'capability' => 'moodle/course:update');
     $toolssvg = self::inline_svg('tools.svg');
     // Output course tools.
     $coursetools = get_string('coursetools', 'theme_snap');
     $o = "<h2>{$coursetools}</h2>";
     $o .= "<div class='row'><div class='col-xs-4'>{$toolssvg}</div><div class='col-xs-8'><div id='coursetools-list'>" . self::render_appendices($links) . "</div></div></div><hr>";
     return $o;
 }