Ejemplo n.º 1
0
/**
 * Adds module specific settings to the settings block
 *
 * @param settings_navigation $settings The settings navigation object
 * @param navigation_node $node The node to add module settings to
 */
function booktool_wordimport_extend_settings_navigation(settings_navigation $settings, navigation_node $node)
{
    global $PAGE;
    if ($PAGE->cm->modname !== 'book') {
        return;
    }
    $params = $PAGE->url->params();
    if (empty($params['id']) and empty($params['cmid'])) {
        return;
    }
    if (empty($PAGE->cm->context)) {
        $PAGE->cm->context = get_context_module::instance($PAGE->cm->instance);
    }
    if (!(has_capability('booktool/wordimport:import', $PAGE->cm->context) and has_capability('mod/book:edit', $PAGE->cm->context))) {
        return;
    }
    // Configure Import link, and pass in the current chapter in case the insert should happen here rather than at the end.
    $url1 = new moodle_url('/mod/book/tool/wordimport/index.php', array('id' => $PAGE->cm->id, 'chapterid' => $params['chapterid']));
    $node->add(get_string('importchapters', 'booktool_wordimport'), $url1, navigation_node::TYPE_SETTING, null, null, new pix_icon('f/document', '', 'moodle', array('class' => 'iconsmall', 'title' => '')));
    // Configure Export links for book and current chapter.
    $url2 = new moodle_url('/mod/book/tool/wordimport/index.php', array('id' => $PAGE->cm->id, 'action' => 'export'));
    $node->add(get_string('exportbook', 'booktool_wordimport'), $url2, navigation_node::TYPE_SETTING, null, null, new pix_icon('f/document', '', 'moodle', array('class' => 'iconsmall', 'title' => '')));
    $url3 = new moodle_url('/mod/book/tool/wordimport/index.php', array('id' => $PAGE->cm->id, 'chapterid' => $params['chapterid'], 'action' => 'export'));
    $node->add(get_string('exportchapter', 'booktool_wordimport'), $url3, navigation_node::TYPE_SETTING, null, null, new pix_icon('f/document', '', 'moodle', array('class' => 'iconsmall', 'title' => '')));
}
Ejemplo n.º 2
0
/**
 * This function extends the course navigation with the report items
 *
 * @param navigation_node $navigation The navigation node to extend
 * @param stdClass $user
 * @param stdClass $course The course to object for the report
 */
function report_outline_extend_navigation_user($navigation, $user, $course)
{
    if (report_outline_can_access_user_report($user, $course)) {
        $url = new moodle_url('/report/outline/user.php', array('id' => $user->id, 'course' => $course->id, 'mode' => 'outline'));
        $navigation->add(get_string('outlinereport'), $url);
        $url = new moodle_url('/report/outline/user.php', array('id' => $user->id, 'course' => $course->id, 'mode' => 'complete'));
        $navigation->add(get_string('completereport'), $url);
    }
}
Ejemplo n.º 3
0
/**
 * This function extends the navigation with the report items
 *
 * @global stdClass $CFG
 * @global core_renderer $OUTPUT
 * @param navigation_node $navigation The navigation node to extend
 * @param stdClass        $course     The course to object for the report
 * @param context         $context    The context of the course
 */
function report_loglive_extend_navigation_course($navigation, $course, $context)
{
    if (has_capability('report/loglive:view', $context)) {
        $url = new moodle_url('/report/loglive/index.php', array('id' => $course->id));
        $navigation->add(get_string('pluginname', 'report_loglive'), $url, navigation_node::TYPE_SETTING, null, null, new pix_icon('i/report', ''));
    }
}
Ejemplo n.º 4
0
 public function test_node_remove()
 {
     $this->setup_node();
     $remove1 = $this->node->add('child to remove 1', null, navigation_node::TYPE_CUSTOM, null, 'remove1');
     $remove2 = $this->node->add('child to remove 2', null, navigation_node::TYPE_CUSTOM, null, 'remove2');
     $remove3 = $remove2->add('child to remove 3', null, navigation_node::TYPE_CUSTOM, null, 'remove3');
     $this->assertInstanceOf('navigation_node', $remove1);
     $this->assertInstanceOf('navigation_node', $remove2);
     $this->assertInstanceOf('navigation_node', $remove3);
     $this->assertInstanceOf('navigation_node', $this->node->get('remove1'));
     $this->assertInstanceOf('navigation_node', $this->node->get('remove2'));
     $this->assertInstanceOf('navigation_node', $remove2->get('remove3'));
     // Remove element and make sure this is no longer a child.
     $this->assertTrue($remove1->remove());
     $this->assertFalse($this->node->get('remove1'));
     $this->assertFalse(in_array('remove1', $this->node->get_children_key_list(), true));
     // Make sure that we can insert element after removal.
     $insertelement = navigation_node::create('extra element 4', null, navigation_node::TYPE_CUSTOM, null, 'element4');
     $this->node->add_node($insertelement, 'remove2');
     $this->assertNotEmpty($this->node->get('element4'));
     // Remove more elements.
     $this->assertTrue($this->node->get('remove2')->remove());
     $this->assertFalse($this->node->get('remove2'));
     // Make sure that we can add element after removal.
     $this->node->add('extra element 5', null, navigation_node::TYPE_CUSTOM, null, 'element5');
     $this->assertNotEmpty($this->node->get('element5'));
     $this->assertTrue($remove2->get('remove3')->remove());
     $this->assertFalse($this->node->get('remove1'));
     $this->assertFalse($this->node->get('remove2'));
 }
/**
 * This function extends the navigation with the report items
 *
 * @param navigation_node $navigation The navigation node to extend
 * @param stdClass $course The course to object for the report
 * @param stdClass $context The context of the course
 */
function engagement_report_extend_navigation($navigation, $course, $context)
{
    if (has_capability('report/engagement:view', $context)) {
        $url = new moodle_url('/course/report/engagement/index.php', array('id' => $course->id));
        $navigation->add(get_string('pluginname', 'coursereport_engagement'), $url, navigation_node::TYPE_SETTING, null, null, new pix_icon('i/report', ''));
    }
}
Ejemplo n.º 6
0
/**
 * Adds module specific settings to the settings block
 *
 * @param settings_navigation $settings The settings navigation object
 * @param navigation_node $node The node to add module settings to
 */
function booktool_print_extend_settings_navigation(settings_navigation $settings, navigation_node $node)
{
    global $USER, $PAGE, $CFG, $DB, $OUTPUT;
    $params = $PAGE->url->params();
    if (empty($params['id']) or empty($params['chapterid'])) {
        return;
    }
    if (has_capability('booktool/print:print', $PAGE->cm->context)) {
        $url1 = new moodle_url('/mod/book/tool/print/index.php', array('id' => $params['id']));
        $url2 = new moodle_url('/mod/book/tool/print/index.php', array('id' => $params['id'], 'chapterid' => $params['chapterid']));
        $action = new action_link($url1, get_string('printbook', 'booktool_print'), new popup_action('click', $url1));
        $node->add(get_string('printbook', 'booktool_print'), $action, navigation_node::TYPE_SETTING, null, null, new pix_icon('book', '', 'booktool_print', array('class' => 'icon')));
        $action = new action_link($url2, get_string('printchapter', 'booktool_print'), new popup_action('click', $url2));
        $node->add(get_string('printchapter', 'booktool_print'), $action, navigation_node::TYPE_SETTING, null, null, new pix_icon('chapter', '', 'booktool_print', array('class' => 'icon')));
    }
}
/**
 * This function extends the coursenavigation with the report items
 *
 * @param navigation_node $navigation The navigation node to extend
 * @param stdClass $course The course to object for the report
 * @param stdClass $context The context of the course
 */
function report_configreports_extend_navigation_course($navigation, $course, $context)
{
    if ($myreports = report_configreports_get_my_reports($course, $context)) {
        foreach ($myreports as $report) {
            $navigation->add($report['name'], $report['url'], navigation_node::TYPE_SETTING, null, null, new pix_icon('i/report', ''));
        }
    }
}
Ejemplo n.º 8
0
/**
 * This function extends the navigation with the report items
 *
 * @global stdClass $CFG
 * @global core_renderer $OUTPUT
 * @param navigation_node $navigation The navigation node to extend
 * @param stdClass        $course     The course to object for the report
 * @param stdClass        $context    The context of the course
 */
function report_loglive_extend_navigation_course($navigation, $course, $context) {
    global $CFG, $OUTPUT;
    if (has_capability('report/loglive:view', $context)) {
        $url = new moodle_url('/report/loglive/index.php', array('id'=>$course->id, 'inpopup'=>1));
        $action = new action_link($url, get_string('pluginname', 'report_loglive'), new popup_action('click', $url));
        $navigation->add('', $action, navigation_node::TYPE_SETTING, null, null, new pix_icon('i/report', ''));
    }
}
/**
 * This function extends the navigation with the report items
 *
 * @param navigation_node $navigation The navigation node to extend
 * @param stdClass $course The course to object for the report
 * @param stdClass $context The context of the course
 */
function participation_report_extend_navigation($navigation, $course, $context)
{
    global $CFG, $OUTPUT;
    if (has_capability('coursereport/participation:view', $context)) {
        $url = new moodle_url('/course/report/participation/index.php', array('id' => $course->id));
        $navigation->add(get_string('participationreport'), $url, navigation_node::TYPE_SETTING, null, null, new pix_icon('i/report', ''));
    }
}
Ejemplo n.º 10
0
/**
 * Adds module specific settings to the settings block
 *
 * @param settings_navigation $settings The settings navigation object
 * @param navigation_node $node The node to add module settings to
 */
function booktool_importhtml_extend_settings_navigation(settings_navigation $settings, navigation_node $node)
{
    global $PAGE;
    if (has_capability('booktool/importhtml:import', $PAGE->cm->context)) {
        $url = new moodle_url('/mod/book/tool/importhtml/index.php', array('id' => $PAGE->cm->id));
        $node->add(get_string('import', 'booktool_importhtml'), $url, navigation_node::TYPE_SETTING, null, null, null);
    }
}
/**
 * This function extends the course navigation with the report items
 *
 * @param navigation_node $navigation The navigation node to extend
 * @param stdClass $user
 * @param stdClass $course The course to object for the report
 */
function report_configurablereports_extend_navigation_user($navigation, $user, $course)
{
    return;
    //TODO: this plugin was not linked from navigation in 2.0, let's keep it that way for now --skodak
    if (report_configurablereports_can_access_user_report($user, $course)) {
        $url = new moodle_url('/report/configurablereports/index.php', array('userid' => $user->id, 'id' => $course->id));
        $navigation->add(get_string('pluginname', 'report_configurablereports'), $url);
    }
}
Ejemplo n.º 12
0
/**
 * Adds module specific settings to the settings block
 *
 * @param settings_navigation $settings The settings navigation object
 * @param navigation_node $node The node to add module settings to
 */
function booktool_exportimscp_extend_settings_navigation(settings_navigation $settings, navigation_node $node)
{
    global $PAGE;
    if (has_capability('booktool/exportimscp:export', $PAGE->cm->context)) {
        $url = new moodle_url('/mod/book/tool/exportimscp/index.php', array('id' => $PAGE->cm->id));
        $icon = new pix_icon('generate', '', 'booktool_exportimscp', array('class' => 'icon'));
        $node->add(get_string('generateimscp', 'booktool_exportimscp'), $url, navigation_node::TYPE_SETTING, null, null, $icon);
    }
}
Ejemplo n.º 13
0
/**
 * This function extends the course navigation with the report items
 *
 * @param navigation_node $navigation The navigation node to extend
 * @param stdClass $user
 * @param stdClass $course The course to object for the report
 */
function report_completion_extend_navigation_user($navigation, $user, $course)
{
    return;
    //TODO: this plugin was not linked from navigation in 2.0, let's keep it that way for now --skodak
    if (report_completion_can_access_user_report($user, $course)) {
        $url = new moodle_url('/report/completion/user.php', array('id' => $user->id, 'course' => $course->id));
        $navigation->add(get_string('coursecompletion'), $url);
    }
}
/**
 * This function extends the navigation with the report items
 *
 * @param navigation_node $navigation The navigation node to extend
 * @param stdClass $course The course to object for the report
 * @param stdClass $context The context of the course
 */
function report_teacherreport_extend_navigation_user($navigation, $user, $course)
{
    global $CFG, $DB, $PAGE, $USER;
    $context = context_user::instance($USER->id);
    if (has_capability('report/teacherreport:view', $context)) {
        $url = new moodle_url('/report/teacherreport/index.php', array('userid' => $USER->id));
        $navigation->add(get_string('pluginname', 'report_teacherreport'), $url, navigation_node::TYPE_SETTING, null, null, null);
    }
}
Ejemplo n.º 15
0
/**
 * This function extends the course navigation with the report items
 *
 * @param navigation_node $navigation The navigation node to extend
 * @param stdClass $user
 * @param stdClass $course The course to object for the report
 */
function report_stats_extend_navigation_user($navigation, $user, $course) {
    global $CFG;
    if (!empty($CFG->enablestats)) {
        return;
    }
    if (report_stats_can_access_user_report($user, $course)) {
        $url = new moodle_url('/report/stats/user.php', array('id'=>$user->id, 'course'=>$course->id));
        $navigation->add(get_string('stats'), $url);
    }
}
Ejemplo n.º 16
0
 /**
  * Extends the module navigation
  *
  * This function is called when the context for the page is an activity module with the
  * FEATURE_ADVANCED_GRADING and there is an area with the active grading method set to the given plugin.
  *
  * @param global_navigation $navigation {@link global_navigation}
  * @param navigation_node $node {@link navigation_node}
  */
 public function extend_navigation(global_navigation $navigation, navigation_node $node = null)
 {
     if (has_capability('moodle/grade:managegradingforms', $this->get_context())) {
         // no need for preview if user can manage forms, he will have link to manage.php in settings instead
         return;
     }
     if ($this->is_form_defined() && ($options = $this->get_options()) && !empty($options['alwaysshowdefinition'])) {
         $node->add(get_string('gradingof', 'gradingform_rubric', get_grading_manager($this->get_areaid())->get_area_title()), new moodle_url('/grade/grading/form/' . $this->get_method_name() . '/preview.php', array('areaid' => $this->get_areaid())), settings_navigation::TYPE_CUSTOM);
     }
 }
Ejemplo n.º 17
0
/**
 * This function extends the course navigation with the report items
 *
 * @param navigation_node $navigation The navigation node to extend
 * @param stdClass $user
 * @param stdClass $course The course to object for the report
 */
function report_comments_extend_navigation_user($navigation, $user, $course)
{
    global $CFG;
    $context = context_course::instance($course->id);
    if (has_capability('report/comments:view', $context)) {
        if ($CFG->usecomments) {
            $url = new moodle_url('/report/comments/index.php', array('course' => $course->id, 'id' => $user->id));
            $navigation->add(get_string('comments'), $url);
        }
    }
}
Ejemplo n.º 18
0
/**
 * This function extends the navigation with the report items
 *
 * @param navigation_node $navigation The navigation node to extend
 * @param stdClass $course The course to object for the report
 * @param stdClass $context The context of the course
 */
function report_competency_extend_navigation_course($navigation, $course, $context)
{
    if (!get_config('core_competency', 'enabled')) {
        return;
    }
    if (has_capability('moodle/competency:coursecompetencyview', $context)) {
        $url = new moodle_url('/report/competency/index.php', array('id' => $course->id));
        $name = get_string('pluginname', 'report_competency');
        $navigation->add($name, $url, navigation_node::TYPE_SETTING, null, null, new pix_icon('i/report', ''));
    }
}
Ejemplo n.º 19
0
function giportfoliotool_print_extend_settings_navigation(settings_navigation $settingsnav, navigation_node $giportfolionode)
{
    global $PAGE;
    if ($PAGE->cm->modname !== 'giportfolio') {
        return;
    }
    $context = context_module::instance($PAGE->cm->id);
    $params = $PAGE->url->params();
    if (empty($params['id']) or empty($params['chapterid'])) {
        return;
    }
    if (has_capability('giportfoliotool/print:print', $context)) {
        $url1 = new moodle_url('/mod/giportfolio/tool/print/index.php', array('id' => $params['id']));
        $url2 = new moodle_url('/mod/giportfolio/tool/print/index.php', array('id' => $params['id'], 'chapterid' => $params['chapterid']));
        $action = new action_link($url1, get_string('printgiportfolio', 'giportfoliotool_print'), new popup_action('click', $url1));
        $giportfolionode->add(get_string('printgiportfolio', 'giportfoliotool_print'), $action, navigation_node::TYPE_SETTING, null, null, new pix_icon('giportfolio', '', 'giportfoliotool_print', array('class' => 'icon')));
        $action = new action_link($url2, get_string('printchapter', 'giportfoliotool_print'), new popup_action('click', $url2));
        $giportfolionode->add(get_string('printchapter', 'giportfoliotool_print'), $action, navigation_node::TYPE_SETTING, null, null, new pix_icon('chapter', '', 'giportfoliotool_print', array('class' => 'icon')));
    }
}
Ejemplo n.º 20
0
 /**
  * Returns enrolment instance manage link.
  *
  * By defaults looks for manage.php file and tests for manage capability.
  *
  * @param navigation_node $instancesnode
  * @param stdClass $instance
  * @return moodle_url;
  */
 public function add_course_navigation($instancesnode, stdClass $instance)
 {
     if ($instance->enrol !== 'manual') {
         throw new coding_exception('Invalid enrol instance type!');
     }
     $context = context_course::instance($instance->courseid);
     if (has_capability('enrol/manual:config', $context)) {
         $managelink = new moodle_url('/enrol/manual/edit.php', array('courseid' => $instance->courseid));
         $instancesnode->add($this->get_instance_name($instance), $managelink, navigation_node::TYPE_SETTING);
     }
 }
Ejemplo n.º 21
0
/**
 * This function extends the navigation with the report items
 *
 * @param navigation_node $navigation The navigation node to extend
 * @param stdClass $course The course to object for the report
 * @param stdClass $context The context of the course
 */
function completion_report_extend_navigation($navigation, $course, $context)
{
    global $CFG, $OUTPUT;
    if (has_capability('coursereport/completion:view', $context)) {
        $completion = new completion_info($course);
        if ($completion->is_enabled() && $completion->has_criteria()) {
            $url = new moodle_url('/course/report/completion/index.php', array('course' => $course->id));
            $navigation->add(get_string('pluginname', 'coursereport_completion'), $url, navigation_node::TYPE_SETTING, null, null, new pix_icon('i/report', ''));
        }
    }
}
Ejemplo n.º 22
0
/**
 * This function extends the user navigation.
 *
 * @param navigation_node $navigation The navigation node to extend
 * @param stdClass $user The user object
 * @param context_user $usercontext The user context
 * @param stdClass $course The course object
 * @param context_course $coursecontext The context of the course
 */
function tool_lp_extend_navigation_user($navigation, $user, $usercontext, $course, $coursecontext)
{
    if (!get_config('core_competency', 'enabled')) {
        return;
    }
    if (\core_competency\plan::can_read_user($user->id)) {
        $node = $navigation->add(get_string('learningplans', 'tool_lp'), new moodle_url('/admin/tool/lp/plans.php', array('userid' => $user->id)));
        if (\core_competency\user_evidence::can_read_user($user->id)) {
            $node->add(get_string('userevidence', 'tool_lp'), new moodle_url('/admin/tool/lp/user_evidence_list.php', array('userid' => $user->id)));
        }
    }
}
Ejemplo n.º 23
0
function booktool_importhtml_extend_settings_navigation(settings_navigation $settingsnav, navigation_node $booknode)
{
    global $USER, $PAGE, $CFG, $DB, $OUTPUT;
    if ($PAGE->cm->modname !== 'book') {
        return;
    }
    if (empty($PAGE->cm->context)) {
        $PAGE->cm->context = get_context_instance(CONTEXT_MODULE, $PAGE->cm->instance);
    }
    if (has_capability('booktool/importhtml:import', $PAGE->cm->context)) {
        $url = new moodle_url('/mod/book/tool/importhtml/index.php', array('id' => $PAGE->cm->id));
        $booknode->add(get_string('import', 'booktool_importhtml'), $url, navigation_node::TYPE_SETTING, null, null, null);
    }
}
Ejemplo n.º 24
0
/**
 * This function extends the course navigation with the report items
 *
 * @param navigation_node $navigation The navigation node to extend
 * @param stdClass $user
 * @param stdClass $course The course to object for the report
 */
function report_usersessions_extend_navigation_user($navigation, $user, $course)
{
    global $USER;
    if (isguestuser() or !isloggedin()) {
        return;
    }
    if (\core\session\manager::is_loggedinas() or $USER->id != $user->id) {
        // No peeking at somebody else's sessions!
        return;
    }
    $context = context_user::instance($USER->id);
    if (has_capability('report/usersessions:manageownsessions', $context)) {
        $navigation->add(get_string('navigationlink', 'report_usersessions'), new moodle_url('/report/usersessions/user.php'), $navigation::TYPE_SETTING);
    }
}
Ejemplo n.º 25
0
function booktool_exportimscp_extend_settings_navigation(settings_navigation $settingsnav, navigation_node $booknode)
{
    global $USER, $PAGE, $CFG, $DB, $OUTPUT;
    if ($PAGE->cm->modname !== 'book') {
        return;
    }
    if (empty($PAGE->cm->context)) {
        $PAGE->cm->context = get_context_instance(CONTEXT_MODULE, $PAGE->cm->instance);
    }
    if (has_capability('booktool/exportimscp:export', $PAGE->cm->context)) {
        $url = new moodle_url('/mod/book/tool/exportimscp/index.php', array('id' => $PAGE->cm->id));
        $icon = new pix_icon('generate', '', 'booktool_exportimscp', array('class' => 'icon'));
        $booknode->add(get_string('generateimscp', 'booktool_exportimscp'), $url, navigation_node::TYPE_SETTING, null, null, $icon);
    }
}
Ejemplo n.º 26
0
/**
 * This function extends the navigation with the report items
 *
 * @param navigation_node $navigation The navigation node to extend
 * @param stdClass $course The course to object for the report
 * @param stdClass $context The context of the course
 */
function progress_report_extend_navigation($navigation, $course, $context)
{
    global $CFG, $OUTPUT;
    $showonnavigation = has_capability('coursereport/progress:view', $context);
    $group = groups_get_course_group($course, true);
    // Supposed to verify group
    if ($group === 0 && $course->groupmode == SEPARATEGROUPS) {
        $showonnavigation = $showonnavigation && has_capability('moodle/site:accessallgroups', $context);
    }
    $completion = new completion_info($course);
    $showonnavigation = $showonnavigation && $completion->is_enabled() && count($completion->get_activities()) > 0;
    if ($showonnavigation) {
        $url = new moodle_url('/course/report/progress/index.php', array('course' => $course->id));
        $navigation->add(get_string('pluginname', 'coursereport_progress'), $url, navigation_node::TYPE_SETTING, null, null, new pix_icon('i/report', ''));
    }
}
Ejemplo n.º 27
0
 public function test_remove()
 {
     $remove1 = $this->node->add('child to remove 1', null, navigation_node::TYPE_CUSTOM, null, 'remove1');
     $remove2 = $this->node->add('child to remove 2', null, navigation_node::TYPE_CUSTOM, null, 'remove2');
     $remove3 = $remove2->add('child to remove 3', null, navigation_node::TYPE_CUSTOM, null, 'remove3');
     $this->assertIsA($remove1, 'navigation_node');
     $this->assertIsA($remove2, 'navigation_node');
     $this->assertIsA($remove3, 'navigation_node');
     $this->assertIsA($this->node->get('remove1'), 'navigation_node');
     $this->assertIsA($this->node->get('remove2'), 'navigation_node');
     $this->assertIsA($remove2->get('remove3'), 'navigation_node');
     $this->assertTrue($remove1->remove());
     $this->assertTrue($this->node->get('remove2')->remove());
     $this->assertTrue($remove2->get('remove3')->remove());
     $this->assertFalse($this->node->get('remove1'));
     $this->assertFalse($this->node->get('remove2'));
 }
Ejemplo n.º 28
0
function booktool_exportepub_extend_settings_navigation(settings_navigation $settingsnav, navigation_node $booknode)
{
    global $PAGE;
    if ($PAGE->cm->modname !== 'book') {
        return;
    }
    if (empty($PAGE->cm->context)) {
        $PAGE->cm->context = context_module::instance($PAGE->cm->instance);
    }
    $params = $PAGE->url->params();
    if (empty($params['id'])) {
        return;
    }
    if (has_capability('booktool/exportepub:export', $PAGE->cm->context) and has_capability('mod/book:read', $PAGE->cm->context)) {
        $url = new moodle_url('/mod/book/tool/exportepub/index.php', array('id' => $params['id']));
        $booknode->add(get_string('downloadepub', 'booktool_exportepub'), $url, navigation_node::TYPE_SETTING, null, null, null);
    }
}
Ejemplo n.º 29
0
 /**
  * Override the parent function so that we can add preceeding hr's and set a
  * root node class against all first level element
  *
  * It does this by first calling the parent's add method {@link navigation_node::add()}
  * and then proceeds to use the key to set class and hr
  *
  * @param string $text text to be used for the link.
  * @param string|moodle_url $url url for the new node
  * @param int $type the type of node navigation_node::TYPE_*
  * @param string $shorttext
  * @param string|int $key a key to access the node by.
  * @param pix_icon $icon An icon that appears next to the node.
  * @return navigation_node with the new node added to it.
  */
 public function add($text, $url = null, $type = null, $shorttext = null, $key = null, pix_icon $icon = null)
 {
     $node = parent::add($text, $url, $type, $shorttext, $key, $icon);
     $node->add_class('root_node');
     return $node;
 }
Ejemplo n.º 30
0
/**
 * Adds module specific settings to the settings block
 *
 * @param settings_navigation $settings The settings navigation object
 * @param navigation_node $forumnode The node to add module settings to
 */
function forum_extend_settings_navigation(settings_navigation $settingsnav, navigation_node $forumnode) {
    global $USER, $PAGE, $CFG, $DB, $OUTPUT;

    $forumobject = $DB->get_record("forum", array("id" => $PAGE->cm->instance));
    if (empty($PAGE->cm->context)) {
        $PAGE->cm->context = context_module::instance($PAGE->cm->instance);
    }

    // for some actions you need to be enrolled, beiing admin is not enough sometimes here
    $enrolled = is_enrolled($PAGE->cm->context, $USER, '', false);
    $activeenrolled = is_enrolled($PAGE->cm->context, $USER, '', true);

    $canmanage  = has_capability('mod/forum:managesubscriptions', $PAGE->cm->context);
    $subscriptionmode = forum_get_forcesubscribed($forumobject);
    $cansubscribe = ($activeenrolled && $subscriptionmode != FORUM_FORCESUBSCRIBE && ($subscriptionmode != FORUM_DISALLOWSUBSCRIBE || $canmanage));

    if ($canmanage) {
        $mode = $forumnode->add(get_string('subscriptionmode', 'forum'), null, navigation_node::TYPE_CONTAINER);

        $allowchoice = $mode->add(get_string('subscriptionoptional', 'forum'), new moodle_url('/mod/forum/subscribe.php', array('id'=>$forumobject->id, 'mode'=>FORUM_CHOOSESUBSCRIBE, 'sesskey'=>sesskey())), navigation_node::TYPE_SETTING);
        $forceforever = $mode->add(get_string("subscriptionforced", "forum"), new moodle_url('/mod/forum/subscribe.php', array('id'=>$forumobject->id, 'mode'=>FORUM_FORCESUBSCRIBE, 'sesskey'=>sesskey())), navigation_node::TYPE_SETTING);
        $forceinitially = $mode->add(get_string("subscriptionauto", "forum"), new moodle_url('/mod/forum/subscribe.php', array('id'=>$forumobject->id, 'mode'=>FORUM_INITIALSUBSCRIBE, 'sesskey'=>sesskey())), navigation_node::TYPE_SETTING);
        $disallowchoice = $mode->add(get_string('subscriptiondisabled', 'forum'), new moodle_url('/mod/forum/subscribe.php', array('id'=>$forumobject->id, 'mode'=>FORUM_DISALLOWSUBSCRIBE, 'sesskey'=>sesskey())), navigation_node::TYPE_SETTING);

        switch ($subscriptionmode) {
            case FORUM_CHOOSESUBSCRIBE : // 0
                $allowchoice->action = null;
                $allowchoice->add_class('activesetting');
                break;
            case FORUM_FORCESUBSCRIBE : // 1
                $forceforever->action = null;
                $forceforever->add_class('activesetting');
                break;
            case FORUM_INITIALSUBSCRIBE : // 2
                $forceinitially->action = null;
                $forceinitially->add_class('activesetting');
                break;
            case FORUM_DISALLOWSUBSCRIBE : // 3
                $disallowchoice->action = null;
                $disallowchoice->add_class('activesetting');
                break;
        }

    } else if ($activeenrolled) {

        switch ($subscriptionmode) {
            case FORUM_CHOOSESUBSCRIBE : // 0
                $notenode = $forumnode->add(get_string('subscriptionoptional', 'forum'));
                break;
            case FORUM_FORCESUBSCRIBE : // 1
                $notenode = $forumnode->add(get_string('subscriptionforced', 'forum'));
                break;
            case FORUM_INITIALSUBSCRIBE : // 2
                $notenode = $forumnode->add(get_string('subscriptionauto', 'forum'));
                break;
            case FORUM_DISALLOWSUBSCRIBE : // 3
                $notenode = $forumnode->add(get_string('subscriptiondisabled', 'forum'));
                break;
        }
    }

    if ($cansubscribe) {
        if (forum_is_subscribed($USER->id, $forumobject)) {
            $linktext = get_string('unsubscribe', 'forum');
        } else {
            $linktext = get_string('subscribe', 'forum');
        }
        $url = new moodle_url('/mod/forum/subscribe.php', array('id'=>$forumobject->id, 'sesskey'=>sesskey()));
        $forumnode->add($linktext, $url, navigation_node::TYPE_SETTING);
    }

    if (has_capability('mod/forum:viewsubscribers', $PAGE->cm->context)){
        $url = new moodle_url('/mod/forum/subscribers.php', array('id'=>$forumobject->id));
        $forumnode->add(get_string('showsubscribers', 'forum'), $url, navigation_node::TYPE_SETTING);
    }

    if ($enrolled && forum_tp_can_track_forums($forumobject)) { // keep tracking info for users with suspended enrolments
        if ($forumobject->trackingtype != FORUM_TRACKING_OPTIONAL) {
            //tracking forced on or off in forum settings so dont provide a link here to change it
            //could add unclickable text like for forced subscription but not sure this justifies adding another menu item
        } else {
            if (forum_tp_is_tracked($forumobject)) {
                $linktext = get_string('notrackforum', 'forum');
            } else {
                $linktext = get_string('trackforum', 'forum');
            }
            $url = new moodle_url('/mod/forum/settracking.php', array('id'=>$forumobject->id));
            $forumnode->add($linktext, $url, navigation_node::TYPE_SETTING);
        }
    }

    if (!isloggedin() && $PAGE->course->id == SITEID) {
        $userid = guest_user()->id;
    } else {
        $userid = $USER->id;
    }

    $hascourseaccess = ($PAGE->course->id == SITEID) || can_access_course($PAGE->course, $userid);
    $enablerssfeeds = !empty($CFG->enablerssfeeds) && !empty($CFG->forum_enablerssfeeds);

    if ($enablerssfeeds && $forumobject->rsstype && $forumobject->rssarticles && $hascourseaccess) {

        if (!function_exists('rss_get_url')) {
            require_once("$CFG->libdir/rsslib.php");
        }

        if ($forumobject->rsstype == 1) {
            $string = get_string('rsssubscriberssdiscussions','forum');
        } else {
            $string = get_string('rsssubscriberssposts','forum');
        }

        $url = new moodle_url(rss_get_url($PAGE->cm->context->id, $userid, "mod_forum", $forumobject->id));
        $forumnode->add($string, $url, settings_navigation::TYPE_SETTING, null, null, new pix_icon('i/rss', ''));
    }
}