Ejemplo n.º 1
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'));
 }
Ejemplo n.º 2
0
/**
 * This function extends the navigation with the tool items for user settings node.
 *
 * @param navigation_node $navigation  The navigation node to extend
 * @param stdClass        $user        The user object
 * @param context         $usercontext The context of the user
 * @param stdClass        $course      The course to object for the tool
 * @param context         $coursecontext     The context of the course
 */
function tool_kent_extend_navigation_user_settings($navigation, $user, $usercontext, $course, $coursecontext)
{
    $url = new moodle_url('/local/kent/preferences.php');
    $subsnode = navigation_node::create('Kent Preferences', $url, navigation_node::TYPE_SETTING, null, 'kent');
    if (isset($subsnode) && !empty($navigation)) {
        $navigation->add_node($subsnode);
    }
}
Ejemplo n.º 3
0
/**
 * This function extends the navigation with the tool items for user settings node.
 *
 * @param navigation_node $navigation  The navigation node to extend
 * @param stdClass        $user        The user object
 * @param context         $usercontext The context of the user
 * @param stdClass        $course      The course to object for the tool
 * @param context         $coursecontext     The context of the course
 */
function tool_monitor_extend_navigation_user_settings($navigation, $user, $usercontext, $course, $coursecontext)
{
    global $USER;
    if ($USER->id == $user->id && has_capability('tool/monitor:subscribe', $coursecontext)) {
        $url = new moodle_url('/admin/tool/monitor/index.php', array('courseid' => $course->id));
        $subsnode = navigation_node::create(get_string('managesubscriptions', 'tool_monitor'), $url, navigation_node::TYPE_SETTING, null, null, new pix_icon('i/settings', ''));
        if (isset($subsnode) && !empty($navigation)) {
            $navigation->add_node($subsnode);
        }
    }
}
Ejemplo n.º 4
0
/**
 * This function extends the navigation with the tool items for user settings node.
 *
 * @param navigation_node $navigation  The navigation node to extend
 * @param stdClass        $user        The user object
 * @param context         $usercontext The context of the user
 * @param stdClass        $course      The course to object for the tool
 * @param context         $coursecontext     The context of the course
 */
function tool_monitor_extend_navigation_user_settings($navigation, $user, $usercontext, $course, $coursecontext)
{
    global $USER, $SITE;
    // Don't show the setting if the event monitor isn't turned on. No access to other peoples subscriptions.
    if (get_config('tool_monitor', 'enablemonitor') && $USER->id == $user->id) {
        // Now let's check to see if the user has any courses / site rules that they can subscribe to.
        if ($courses = tool_monitor_get_user_courses()) {
            $url = new moodle_url('/admin/tool/monitor/index.php');
            $subsnode = navigation_node::create(get_string('managesubscriptions', 'tool_monitor'), $url, navigation_node::TYPE_SETTING, null, 'monitor', new pix_icon('i/settings', ''));
            if (isset($subsnode) && !empty($navigation)) {
                $navigation->add_node($subsnode);
            }
        }
    }
}
Ejemplo n.º 5
0
/**
 * This function extends the navigation with the tool items for user settings node.
 *
 * @param navigation_node $navigation  The navigation node to extend
 * @param stdClass        $user        The user object
 * @param context         $usercontext The context of the user
 * @param stdClass        $course      The course to object for the tool
 * @param context         $coursecontext     The context of the course
 */
function tool_monitor_extend_navigation_user_settings($navigation, $user, $usercontext, $course, $coursecontext)
{
    global $USER, $SITE;
    if ($USER->id == $user->id && (has_capability('tool/monitor:subscribe', $coursecontext) && get_config('tool_monitor', 'enablemonitor'))) {
        // The $course->id will always be the course that corresponds to the current context.
        $courseid = $course->id;
        // A $course->id of $SITE->id might either be the frontpage or the site. So if we get the site ID back, check the...
        // ...courseid parameter passed to the page so we can know if we are looking at the frontpage rules or site level rules.
        if ($course->id == $SITE->id && optional_param('courseid', $course->id, PARAM_INT) == 0) {
            $courseid = 0;
        }
        $url = new moodle_url('/admin/tool/monitor/index.php', array('courseid' => $courseid));
        $subsnode = navigation_node::create(get_string('managesubscriptions', 'tool_monitor'), $url, navigation_node::TYPE_SETTING, null, null, new pix_icon('i/settings', ''));
        if (isset($subsnode) && !empty($navigation)) {
            $navigation->add_node($subsnode);
        }
    }
}
Ejemplo n.º 6
0
 public function test_add_before()
 {
     global $CFG;
     // Create 3 nodes
     $node1 = navigation_node::create('test_add_1', null, navigation_node::TYPE_CUSTOM, 'test 1', 'testadd1');
     $node2 = navigation_node::create('test_add_2', null, navigation_node::TYPE_CUSTOM, 'test 2', 'testadd2');
     $node3 = navigation_node::create('test_add_3', null, navigation_node::TYPE_CUSTOM, 'test 3', 'testadd3');
     // Add node 2, then node 1 before 2, then node 3 at end
     $this->node->add_node($node2);
     $this->node->add_node($node1, 'testadd2');
     $this->node->add_node($node3);
     // Check the last 3 nodes are in 1, 2, 3 order and have those indexes
     foreach ($this->node->children as $child) {
         $keys[] = $child->key;
     }
     $this->assertEqual('testadd1', $keys[count($keys) - 3]);
     $this->assertEqual('testadd2', $keys[count($keys) - 2]);
     $this->assertEqual('testadd3', $keys[count($keys) - 1]);
 }
Ejemplo n.º 7
0
/**
 * This function extends the category navigation to add learning plan links.
 *
 * @param navigation_node $navigation The navigation node to extend
 * @param context $coursecategorycontext The context of the course category
 */
function tool_lp_extend_navigation_category_settings($navigation, $coursecategorycontext)
{
    if (!get_config('core_competency', 'enabled')) {
        return false;
    }
    // We check permissions before renderring the links.
    $templatereadcapability = \core_competency\template::can_read_context($coursecategorycontext);
    $competencyreadcapability = \core_competency\competency_framework::can_read_context($coursecategorycontext);
    if (!$templatereadcapability && !$competencyreadcapability) {
        return false;
    }
    // The link to the learning plan page.
    if ($templatereadcapability) {
        $title = get_string('templates', 'tool_lp');
        $path = new moodle_url("/admin/tool/lp/learningplans.php", array('pagecontextid' => $coursecategorycontext->id));
        $settingsnode = navigation_node::create($title, $path, navigation_node::TYPE_SETTING, null, null, new pix_icon('competency', '', 'tool_lp'));
        if (isset($settingsnode)) {
            $navigation->add_node($settingsnode);
        }
    }
    // The link to the competency frameworks page.
    if ($competencyreadcapability) {
        $title = get_string('competencyframeworks', 'tool_lp');
        $path = new moodle_url("/admin/tool/lp/competencyframeworks.php", array('pagecontextid' => $coursecategorycontext->id));
        $settingsnode = navigation_node::create($title, $path, navigation_node::TYPE_SETTING, null, null, new pix_icon('competency', '', 'tool_lp'));
        if (isset($settingsnode)) {
            $navigation->add_node($settingsnode);
        }
    }
}
Ejemplo n.º 8
0
/**
 * Extends the settings navigation with the studyplan settings
 *
 * This function is called when the context for the page is a studyplan module. This is not called by AJAX
 * so it is safe to rely on the $PAGE.
 *
 * @param settings_navigation $settingsnav {@link settings_navigation}
 * @param navigation_node $studyplannode {@link navigation_node}
 */
function studyplan_extend_settings_navigation(settings_navigation $settingsnav, navigation_node $studyplannode = null)
{
    global $CFG, $PAGE;
    if ($studyplannode == null) {
        return;
    }
    if (!has_capability('mod/studyplan:review', context_module::instance($PAGE->cm->id))) {
        return;
    }
    $str = "Review";
    if (has_capability('mod/studyplan:assign', context_module::instance($PAGE->cm->id))) {
        $str = "Review and Assign";
    }
    $url = new moodle_url('/mod/studyplan/review.php', array('id' => $PAGE->cm->id));
    $node = navigation_node::create($str, $url, navigation_node::NODETYPE_LEAF, 'studyplan', 'studyplan');
    if ($PAGE->url->compare($url, URL_MATCH_BASE)) {
        $node->make_active();
    }
    $studyplannode->add_node($node);
}
Ejemplo n.º 9
0
/**
 * This function extends the settings navigation block for the site.
 *
 * It is safe to rely on PAGE here as we will only ever be within the module
 * context when this is called
 *
 * @param settings_navigation $settings
 * @param navigation_node $quiznode
 */
function quiz_extend_settings_navigation($settings, $quiznode) {
    global $PAGE, $CFG;

    // Require {@link questionlib.php}
    // Included here as we only ever want to include this file if we really need to.
    require_once($CFG->libdir . '/questionlib.php');

    // We want to add these new nodes after the Edit settings node, and before the
    // Locally assigned roles node. Of course, both of those are controlled by capabilities.
    $keys = $quiznode->get_children_key_list();
    $beforekey = null;
    $i = array_search('modedit', $keys);
    if ($i === false and array_key_exists(0, $keys)) {
        $beforekey = $keys[0];
    } else if (array_key_exists($i + 1, $keys)) {
        $beforekey = $keys[$i + 1];
    }

    if (has_capability('mod/quiz:manageoverrides', $PAGE->cm->context)) {
        $url = new moodle_url('/mod/quiz/overrides.php', array('cmid'=>$PAGE->cm->id));
        $node = navigation_node::create(get_string('groupoverrides', 'quiz'),
                new moodle_url($url, array('mode'=>'group')),
                navigation_node::TYPE_SETTING, null, 'mod_quiz_groupoverrides');
        $quiznode->add_node($node, $beforekey);

        $node = navigation_node::create(get_string('useroverrides', 'quiz'),
                new moodle_url($url, array('mode'=>'user')),
                navigation_node::TYPE_SETTING, null, 'mod_quiz_useroverrides');
        $quiznode->add_node($node, $beforekey);
    }

    if (has_capability('mod/quiz:manage', $PAGE->cm->context)) {
        $node = navigation_node::create(get_string('editquiz', 'quiz'),
                new moodle_url('/mod/quiz/edit.php', array('cmid'=>$PAGE->cm->id)),
                navigation_node::TYPE_SETTING, null, 'mod_quiz_edit',
                new pix_icon('t/edit', ''));
        $quiznode->add_node($node, $beforekey);
    }

    if (has_capability('mod/quiz:preview', $PAGE->cm->context)) {
        $url = new moodle_url('/mod/quiz/startattempt.php',
                array('cmid'=>$PAGE->cm->id, 'sesskey'=>sesskey()));
        $node = navigation_node::create(get_string('preview', 'quiz'), $url,
                navigation_node::TYPE_SETTING, null, 'mod_quiz_preview',
                new pix_icon('t/preview', ''));
        $quiznode->add_node($node, $beforekey);
    }

    question_extend_settings_navigation($quiznode, $PAGE->cm->context)->trim_if_empty();
}
Ejemplo n.º 10
0
function vpl_extend_settings_navigation(settings_navigation $settings, navigation_node $vplnode)
{
    global $CFG, $PAGE, $USER;
    if (!isset($PAGE->cm->id)) {
        return;
    }
    $cmid = $PAGE->cm->id;
    $context = context_module::instance($cmid);
    $manager = has_capability(VPL_MANAGE_CAPABILITY, $context);
    $setjails = has_capability(VPL_SETJAILS_CAPABILITY, $context);
    if ($manager) {
        $userid = optional_param('userid', NULL, PARAM_INT);
        $strbasic = get_string('basic', VPL);
        $strtestcases = get_string('testcases', VPL);
        $strexecutionoptions = get_string('executionoptions', VPL);
        $menustrexecutionoptions = get_string('menuexecutionoptions', VPL);
        $strrequestedfiles = get_string('requestedfiles', VPL);
        $strexecution = get_string('execution', VPL);
        $vplindex = get_string('modulenameplural', VPL);
        $klist = $vplnode->get_children_key_list();
        if (count($klist) > 1) {
            $fkn = $klist[1];
        } else {
            $fkn = null;
        }
        $parms = array('id' => $PAGE->cm->id);
        $node = $vplnode->create($strtestcases, new moodle_url('/mod/vpl/forms/testcasesfile.php', array('id' => $PAGE->cm->id, 'edit' => 3)), navigation_node::TYPE_SETTING);
        $vplnode->add_node($node, $fkn);
        $node = $vplnode->create($strexecutionoptions, new moodle_url('/mod/vpl/forms/executionoptions.php', $parms), navigation_node::TYPE_SETTING);
        $vplnode->add_node($node, $fkn);
        $node = $vplnode->create($strrequestedfiles, new moodle_url('/mod/vpl/forms/requiredfiles.php', $parms), navigation_node::TYPE_SETTING);
        $vplnode->add_node($node, $fkn);
        $advance = $vplnode->create(get_string('advancedsettings'), null, navigation_node::TYPE_CONTAINER);
        $vplnode->add_node($advance, $fkn);
        $strexecutionlimits = get_string('maxresourcelimits', VPL);
        $strexecutionfiles = get_string('executionfiles', VPL);
        $menustrexecutionfiles = get_string('menuexecutionfiles', VPL);
        $menustrexecutionlimits = get_string('menuresourcelimits', VPL);
        $strvariations = get_string('variations', VPL);
        $strexecutionkeepfiles = get_string('keepfiles', VPL);
        $strexecutionlimits = get_string('maxresourcelimits', VPL);
        $strcheckjails = get_string('check_jail_servers', VPL);
        $strsetjails = get_string('local_jail_servers', VPL);
        $menustrexecutionkeepfiles = get_string('menukeepfiles', VPL);
        $menustrcheckjails = get_string('menucheck_jail_servers', VPL);
        $menustrsetjails = get_string('menulocal_jail_servers', VPL);
        $advance->add($strexecutionfiles, new moodle_url('/mod/vpl/forms/executionfiles.php', $parms), navigation_node::TYPE_SETTING);
        $advance->add($strexecutionlimits, new moodle_url('/mod/vpl/forms/executionlimits.php', $parms), navigation_node::TYPE_SETTING);
        $advance->add($strexecutionkeepfiles, new moodle_url('/mod/vpl/forms/executionkeepfiles.php', $parms), navigation_node::TYPE_SETTING);
        $advance->add($strvariations, new moodle_url('/mod/vpl/forms/variations.php', $parms), navigation_node::TYPE_SETTING);
        $advance->add($strcheckjails, new moodle_url('/mod/vpl/views/checkjailservers.php', $parms), navigation_node::TYPE_SETTING);
        if ($setjails) {
            $advance->add($strsetjails, new moodle_url('/mod/vpl/forms/local_jail_servers.php', $parms), navigation_node::TYPE_SETTING);
        }
        $testact = $vplnode->create(get_string('test', VPL), null, navigation_node::TYPE_CONTAINER);
        $vplnode->add_node($testact, $fkn);
        $strdescription = get_string('description', VPL);
        $strsubmission = get_string('submission', VPL);
        $stredit = get_string('edit', VPL);
        $parmsuser = array('id' => $PAGE->cm->id, 'userid' => $USER->id);
        $strsubmissionview = get_string('submissionview', VPL);
        $testact->add($strsubmission, new moodle_url('/mod/vpl/forms/submission.php', $parms), navigation_node::TYPE_SETTING);
        $testact->add($stredit, new moodle_url('/mod/vpl/forms/edit.php', $parms), navigation_node::TYPE_SETTING);
        $testact->add($strsubmissionview, new moodle_url('/mod/vpl/forms/submissionview.php', $parms), navigation_node::TYPE_SETTING);
        $testact->add(get_string('grade'), new moodle_url('/mod/vpl/forms/gradesubmission.php', $parmsuser), navigation_node::TYPE_SETTING);
        $testact->add(get_string('previoussubmissionslist', VPL), new moodle_url('/mod/vpl/views/previoussubmissionslist.php', $parmsuser), navigation_node::TYPE_SETTING);
        $nodeindex = $vplnode->create($vplindex, new moodle_url('/mod/vpl/index.php', array('id' => $PAGE->cm->course)), navigation_node::TYPE_SETTING);
        $vplnode->add_node($nodeindex, $fkn);
    }
}
Ejemplo n.º 11
0
/**
 * Adds a recycle bin link to the course admin menu.
 *
 * @param navigation_node $navigation The navigation node to extend
 * @param context $context The context of the course
 * @return void|null return null if we don't want to display the node.
 */
function tool_recyclebin_extend_navigation_category_settings($navigation, $context)
{
    global $PAGE;
    // Check if it is enabled.
    if (!\tool_recyclebin\category_bin::is_enabled()) {
        return null;
    }
    $categorybin = new \tool_recyclebin\category_bin($context->instanceid);
    // Check we can view the recycle bin.
    if (!$categorybin->can_view()) {
        return null;
    }
    $url = null;
    $settingnode = null;
    // Add a link to the category recyclebin.
    $url = new moodle_url('/admin/tool/recyclebin/index.php', array('contextid' => $context->id));
    // If we are set to auto-hide, check the number of items.
    $autohide = get_config('tool_recyclebin', 'autohide');
    if ($autohide) {
        $items = $categorybin->get_items();
        if (empty($items)) {
            return null;
        }
    }
    // Add the recyclebin link.
    $pluginname = get_string('pluginname', 'tool_recyclebin');
    $node = navigation_node::create($pluginname, $url, navigation_node::NODETYPE_LEAF, 'tool_recyclebin', 'tool_recyclebin', new pix_icon('trash', $pluginname, 'tool_recyclebin'));
    if ($PAGE->url->compare($url, URL_MATCH_BASE)) {
        $node->make_active();
    }
    $navigation->add_node($node);
}
Ejemplo n.º 12
0
/**
 * This function extends the settings navigation block for the site.
 *
 * It is safe to rely on PAGE here as we will only ever be within the module
 * context when this is called
 *
 * @param settings_navigation $settings
 * @param navigation_node $offlinequiznode
 */
function offlinequiz_extend_settings_navigation($settings, $offlinequiznode)
{
    global $PAGE, $CFG;
    // Included here as we only ever want to include this file if we really need to.
    require_once $CFG->libdir . '/questionlib.php';
    // We want to add these new nodes after the Edit settings node, and before the
    // Locally assigned roles node. Of course, both of those are controlled by capabilities.
    $keys = $offlinequiznode->get_children_key_list();
    $beforekey = null;
    $i = array_search('modedit', $keys);
    if ($i === false and array_key_exists(0, $keys)) {
        $beforekey = $keys[0];
    } else {
        if (array_key_exists($i + 1, $keys)) {
            $beforekey = $keys[$i + 1];
        }
    }
    if (has_capability('mod/offlinequiz:manage', $PAGE->cm->context)) {
        $node = navigation_node::create(get_string('groupquestions', 'offlinequiz'), new moodle_url('/mod/offlinequiz/edit.php', array('cmid' => $PAGE->cm->id)), navigation_node::TYPE_SETTING, null, 'mod_offlinequiz_edit', new pix_icon('i/questions', ''));
        $offlinequiznode->add_node($node, $beforekey);
        $node = navigation_node::create(get_string('createofflinequiz', 'offlinequiz'), new moodle_url('/mod/offlinequiz/createquiz.php', array('id' => $PAGE->cm->id)), navigation_node::TYPE_SETTING, null, 'mod_offlinequiz_createpdfs', new pix_icon('f/text', ''));
        $offlinequiznode->add_node($node, $beforekey);
        $node = navigation_node::create(get_string('participantslists', 'offlinequiz'), new moodle_url('/mod/offlinequiz/participants.php', array('id' => $PAGE->cm->id)), navigation_node::TYPE_SETTING, null, 'mod_offlinequiz_participants', new pix_icon('i/group', ''));
        $offlinequiznode->add_node($node, $beforekey);
        $node = navigation_node::create(get_string('results', 'offlinequiz'), new moodle_url('/mod/offlinequiz/report.php', array('id' => $PAGE->cm->id, 'mode' => 'overview')), navigation_node::TYPE_SETTING, null, 'mod_offlinequiz_results', new pix_icon('i/grades', ''));
        $offlinequiznode->add_node($node, $beforekey);
    }
    question_extend_settings_navigation($offlinequiznode, $PAGE->cm->context)->trim_if_empty();
}
Ejemplo n.º 13
0
/**
 * Extends the settings navigation with the treasurehunt settings
 *
 * This function is called when the context for the page is a treasurehunt module. This is not called by AJAX
 * so it is safe to rely on the $PAGE.
 *
 * @param settings_navigation $settingsnav complete settings navigation tree
 * @param navigation_node $treasurehuntnode treasurehunt administration node
 */
function treasurehunt_extend_settings_navigation(settings_navigation $settingsnav, navigation_node $treasurehuntnode = null)
{
    global $PAGE;
    // We want to add these new nodes after the Edit settings node, and before the
    // Locally assigned roles node. Of course, both of those are controlled by capabilities.
    $keys = $treasurehuntnode->get_children_key_list();
    $beforekey = null;
    $i = array_search('modedit', $keys);
    if ($i === false and array_key_exists(0, $keys)) {
        $beforekey = $keys[0];
    } else {
        if (array_key_exists($i + 1, $keys)) {
            $beforekey = $keys[$i + 1];
        }
    }
    if (has_capability('mod/treasurehunt:managetreasurehunt', $PAGE->cm->context)) {
        $node = navigation_node::create(get_string('edittreasurehunt', 'treasurehunt'), new moodle_url('/mod/treasurehunt/edit.php', array('id' => $PAGE->cm->id)), navigation_node::TYPE_SETTING, null, 'mod_treasurehunt_edit', new pix_icon('t/edit', ''));
        $treasurehuntnode->add_node($node, $beforekey);
    }
}
Ejemplo n.º 14
0
/**
 * This function extends the settings navigation block for the site.
 *
 * It is safe to rely on PAGE here as we will only ever be within the module
 * context when this is called
 *
 * @param settings_navigation $settings
 * @param navigation_node $node
 * @return void
 */
function rcontent_extend_settings_navigation($settings, $node)
{
    global $CFG, $PAGE, $DB;
    // We want to add these new nodes after the Edit settings node, and before the
    // Locally assigned roles node. Of course, both of those are controlled by capabilities.
    $keys = $node->get_children_key_list();
    $beforekey = null;
    $i = array_search('modedit', $keys);
    if ($i === false and array_key_exists(0, $keys)) {
        $beforekey = $keys[0];
    } else {
        if (array_key_exists($i + 1, $keys)) {
            $beforekey = $keys[$i + 1];
        }
    }
    if (has_any_capability(array('mod/rcontent:viewreport'), $PAGE->cm->context)) {
        require_once $CFG->dirroot . '/mod/rcontent/report/reportlib.php';
        $url = new moodle_url('/mod/rcontent/report.php', array('id' => $PAGE->cm->id));
        $reportnode = $node->add_node(navigation_node::create(get_string('results', 'rcontent'), $url, navigation_node::TYPE_SETTING, null, null, new pix_icon('i/report', '')), $beforekey);
        $reportlist = rcontent_report_list();
        if (!empty($reportlist)) {
            foreach ($reportlist as $report) {
                $url = new moodle_url('/mod/rcontent/report/' . $report . '/index.php', array('id' => $PAGE->cm->id));
                $reportnode->add_node(navigation_node::create(get_string($report, 'rcontent_' . $report), $url, navigation_node::TYPE_SETTING, null, 'rcontent_report_' . $report, new pix_icon('i/item', '')));
            }
        } else {
            if (file_exists($CFG->dirroot . '/blocks/rgrade/rgrade_table.php')) {
                $rcontent = $DB->get_record('rcontent', array('id' => $PAGE->cm->instance));
                if ($rcontent->bookid) {
                    $reportnode->add_node(navigation_node::create(get_string('rgrade', 'block_rgrade'), new moodle_url('/blocks/rgrade/rgrade_table.php', array('courseid' => $PAGE->course->id, 'bookid' => $rcontent->bookid)), navigation_node::TYPE_SETTING, null, 'rcontent_report_rgrade', new pix_icon('i/item', '')));
                }
            }
        }
    }
}
Ejemplo n.º 15
0
/**
 * Extends the settings navigation with the geogebra settings
 *
 * This function is called when the context for the page is a geogebra module. This is not called by AJAX
 * so it is safe to rely on the $PAGE.
 *
 * @param settings_navigation $settingsnav {@link settings_navigation}
 * @param navigation_node $geogebranode {@link navigation_node}
 */
function geogebra_extend_settings_navigation(settings_navigation $settingsnav, navigation_node $geogebranode = null)
{
    global $PAGE;
    $keys = $geogebranode->get_children_key_list();
    $beforekey = null;
    $i = array_search('modedit', $keys);
    if ($i === false and array_key_exists(0, $keys)) {
        $beforekey = $keys[0];
    } else {
        if (array_key_exists($i + 1, $keys)) {
            $beforekey = $keys[$i + 1];
        }
    }
    //if (has_capability('moodle/grade:viewall', $PAGE->context)) {
    $node = navigation_node::create(get_string('preview_geogebra', 'geogebra'), new moodle_url('/mod/geogebra/view.php', array('id' => $PAGE->cm->id, 'action' => 'preview')), navigation_node::TYPE_SETTING, null, 'mod_preview_geogebra_preview', new pix_icon('i/preview', ''));
    $geogebranode->add_node($node, $beforekey);
    $url = new moodle_url('/mod/geogebra/report.php', array('id' => $PAGE->cm->id));
    $reportnode = $geogebranode->add_node(navigation_node::create(get_string('results', 'geogebra'), $url, navigation_node::TYPE_SETTING, null, null, new pix_icon('i/report', '')), $beforekey);
    //}
}
Ejemplo n.º 16
0
/**
 * This function extends the settings navigation block for the site.
 *
 * It is safe to rely on PAGE here as we will only ever be within the module
 * context when this is called
 *
 * @param settings_navigation $settings
 * @param navigation_node $lessonnode
 */
function lesson_extend_settings_navigation($settings, $lessonnode)
{
    global $PAGE, $DB;
    // We want to add these new nodes after the Edit settings node, and before the
    // Locally assigned roles node. Of course, both of those are controlled by capabilities.
    $keys = $lessonnode->get_children_key_list();
    $beforekey = null;
    $i = array_search('modedit', $keys);
    if ($i === false and array_key_exists(0, $keys)) {
        $beforekey = $keys[0];
    } else {
        if (array_key_exists($i + 1, $keys)) {
            $beforekey = $keys[$i + 1];
        }
    }
    if (has_capability('mod/lesson:manageoverrides', $PAGE->cm->context)) {
        $url = new moodle_url('/mod/lesson/overrides.php', array('cmid' => $PAGE->cm->id));
        $node = navigation_node::create(get_string('groupoverrides', 'lesson'), new moodle_url($url, array('mode' => 'group')), navigation_node::TYPE_SETTING, null, 'mod_lesson_groupoverrides');
        $lessonnode->add_node($node, $beforekey);
        $node = navigation_node::create(get_string('useroverrides', 'lesson'), new moodle_url($url, array('mode' => 'user')), navigation_node::TYPE_SETTING, null, 'mod_lesson_useroverrides');
        $lessonnode->add_node($node, $beforekey);
    }
    if (has_capability('mod/lesson:edit', $PAGE->cm->context)) {
        $url = new moodle_url('/mod/lesson/view.php', array('id' => $PAGE->cm->id));
        $lessonnode->add(get_string('preview', 'lesson'), $url);
        $editnode = $lessonnode->add(get_string('edit', 'lesson'));
        $url = new moodle_url('/mod/lesson/edit.php', array('id' => $PAGE->cm->id, 'mode' => 'collapsed'));
        $editnode->add(get_string('collapsed', 'lesson'), $url);
        $url = new moodle_url('/mod/lesson/edit.php', array('id' => $PAGE->cm->id, 'mode' => 'full'));
        $editnode->add(get_string('full', 'lesson'), $url);
    }
    if (has_capability('mod/lesson:viewreports', $PAGE->cm->context)) {
        $reportsnode = $lessonnode->add(get_string('reports', 'lesson'));
        $url = new moodle_url('/mod/lesson/report.php', array('id' => $PAGE->cm->id, 'action' => 'reportoverview'));
        $reportsnode->add(get_string('overview', 'lesson'), $url);
        $url = new moodle_url('/mod/lesson/report.php', array('id' => $PAGE->cm->id, 'action' => 'reportdetail'));
        $reportsnode->add(get_string('detailedstats', 'lesson'), $url);
    }
    if (has_capability('mod/lesson:grade', $PAGE->cm->context)) {
        $url = new moodle_url('/mod/lesson/essay.php', array('id' => $PAGE->cm->id));
        $lessonnode->add(get_string('manualgrading', 'lesson'), $url);
    }
}
Ejemplo n.º 17
0
/**
 * extend an assigment navigation settings
 *
 * @param settings_navigation $settings
 * @param navigation_node $navref
 * @return void
 */
function assign_extend_settings_navigation(settings_navigation $settings, navigation_node $navref)
{
    global $PAGE, $DB;
    // We want to add these new nodes after the Edit settings node, and before the
    // Locally assigned roles node. Of course, both of those are controlled by capabilities.
    $keys = $navref->get_children_key_list();
    $beforekey = null;
    $i = array_search('modedit', $keys);
    if ($i === false and array_key_exists(0, $keys)) {
        $beforekey = $keys[0];
    } else {
        if (array_key_exists($i + 1, $keys)) {
            $beforekey = $keys[$i + 1];
        }
    }
    $cm = $PAGE->cm;
    if (!$cm) {
        return;
    }
    $context = $cm->context;
    $course = $PAGE->course;
    if (!$course) {
        return;
    }
    if (has_capability('mod/assign:manageoverrides', $PAGE->cm->context)) {
        $url = new moodle_url('/mod/assign/overrides.php', array('cmid' => $PAGE->cm->id));
        $node = navigation_node::create(get_string('groupoverrides', 'assign'), new moodle_url($url, array('mode' => 'group')), navigation_node::TYPE_SETTING, null, 'mod_assign_groupoverrides');
        $navref->add_node($node, $beforekey);
        $node = navigation_node::create(get_string('useroverrides', 'assign'), new moodle_url($url, array('mode' => 'user')), navigation_node::TYPE_SETTING, null, 'mod_assign_useroverrides');
        $navref->add_node($node, $beforekey);
    }
    // Link to gradebook.
    if (has_capability('gradereport/grader:view', $cm->context) && has_capability('moodle/grade:viewall', $cm->context)) {
        $link = new moodle_url('/grade/report/grader/index.php', array('id' => $course->id));
        $linkname = get_string('viewgradebook', 'assign');
        $node = $navref->add($linkname, $link, navigation_node::TYPE_SETTING);
    }
    // Link to download all submissions.
    if (has_any_capability(array('mod/assign:grade', 'mod/assign:viewgrades'), $context)) {
        $link = new moodle_url('/mod/assign/view.php', array('id' => $cm->id, 'action' => 'grading'));
        $node = $navref->add(get_string('viewgrading', 'assign'), $link, navigation_node::TYPE_SETTING);
        $link = new moodle_url('/mod/assign/view.php', array('id' => $cm->id, 'action' => 'downloadall'));
        $node = $navref->add(get_string('downloadall', 'assign'), $link, navigation_node::TYPE_SETTING);
    }
    if (has_capability('mod/assign:revealidentities', $context)) {
        $dbparams = array('id' => $cm->instance);
        $assignment = $DB->get_record('assign', $dbparams, 'blindmarking, revealidentities');
        if ($assignment && $assignment->blindmarking && !$assignment->revealidentities) {
            $urlparams = array('id' => $cm->id, 'action' => 'revealidentities');
            $url = new moodle_url('/mod/assign/view.php', $urlparams);
            $linkname = get_string('revealidentities', 'assign');
            $node = $navref->add($linkname, $url, navigation_node::TYPE_SETTING);
        }
    }
}
Ejemplo n.º 18
0
/**
 * This function extends the settings navigation block for the site.
 *
 * It is safe to rely on PAGE here as we will only ever be within the module
 * context when this is called.
 *
 * @param settings_navigation $settings
 * @param navigation_node $customcertnode
 */
function customcert_extend_settings_navigation(settings_navigation $settings, navigation_node $customcertnode)
{
    global $PAGE;
    $keys = $customcertnode->get_children_key_list();
    $beforekey = null;
    $i = array_search('modedit', $keys);
    if ($i === false and array_key_exists(0, $keys)) {
        $beforekey = $keys[0];
    } else {
        if (array_key_exists($i + 1, $keys)) {
            $beforekey = $keys[$i + 1];
        }
    }
    if (has_capability('mod/customcert:manage', $PAGE->cm->context)) {
        $node = navigation_node::create(get_string('editcustomcert', 'customcert'), new moodle_url('/mod/customcert/edit.php', array('cmid' => $PAGE->cm->id)), navigation_node::TYPE_SETTING, null, 'mod_customcert_edit', new pix_icon('t/edit', ''));
        $customcertnode->add_node($node, $beforekey);
    }
    return $customcertnode->trim_if_empty();
}
Ejemplo n.º 19
0
/**
 * Used to add options to the Settings menu for the subpage
 * @param unknown_type $settings Don't know what this parameter is
 * @param navigation_node $subpagenode Navigation node object for subpage
 */
function subpage_extend_settings_navigation($settings, navigation_node $subpagenode)
{
    global $PAGE;
    $url = new moodle_url('/mod/subpage/view.php', array('id' => $PAGE->cm->id));
    $url->param('sesskey', sesskey());
    if ($PAGE->user_is_editing()) {
        $url->param('edit', 'off');
        $editstring = get_string('turneditingoff');
    } else {
        $url->param('edit', 'on');
        $editstring = get_string('turneditingon');
    }
    if (has_capability('moodle/course:update', $PAGE->context)) {
        $node = navigation_node::create($editstring, $url, navigation_node::TYPE_SETTING, null, 'subpageeditingtoggle');
        $subpagenode->add_node($node, 'modedit');
    }
}
Ejemplo n.º 20
0
/**
 * Adds module specific settings to the settings block
 *
 * @param settings_navigation $settings The settings navigation object
 * @param navigation_node $questionnairenode The node to add module settings to
 */
function questionnaire_extend_settings_navigation(settings_navigation $settings, navigation_node $questionnairenode)
{
    global $PAGE, $DB, $USER, $CFG;
    $individualresponse = optional_param('individualresponse', false, PARAM_INT);
    $rid = optional_param('rid', false, PARAM_INT);
    // Response id.
    $currentgroupid = optional_param('group', 0, PARAM_INT);
    // Group id.
    require_once $CFG->dirroot . '/mod/questionnaire/questionnaire.class.php';
    $context = $PAGE->cm->context;
    $cmid = $PAGE->cm->id;
    $cm = $PAGE->cm;
    $course = $PAGE->course;
    if (!($questionnaire = $DB->get_record("questionnaire", array("id" => $cm->instance)))) {
        print_error('invalidcoursemodule');
    }
    $courseid = $course->id;
    $questionnaire = new questionnaire(0, $questionnaire, $course, $cm);
    if ($survey = $DB->get_record('questionnaire_survey', array('id' => $questionnaire->sid))) {
        $owner = trim($survey->owner) == trim($courseid);
    } else {
        $survey = false;
        $owner = true;
    }
    // We want to add these new nodes after the Edit settings node, and before the
    // Locally assigned roles node. Of course, both of those are controlled by capabilities.
    $keys = $questionnairenode->get_children_key_list();
    $beforekey = null;
    $i = array_search('modedit', $keys);
    if ($i === false and array_key_exists(0, $keys)) {
        $beforekey = $keys[0];
    } else {
        if (array_key_exists($i + 1, $keys)) {
            $beforekey = $keys[$i + 1];
        }
    }
    if (has_capability('mod/questionnaire:manage', $context) && $owner) {
        $url = '/mod/questionnaire/qsettings.php';
        $node = navigation_node::create(get_string('advancedsettings'), new moodle_url($url, array('id' => $cmid)), navigation_node::TYPE_SETTING, null, 'advancedsettings', new pix_icon('t/edit', ''));
        $questionnairenode->add_node($node, $beforekey);
    }
    if (has_capability('mod/questionnaire:editquestions', $context) && $owner) {
        $url = '/mod/questionnaire/questions.php';
        $node = navigation_node::create(get_string('questions', 'questionnaire'), new moodle_url($url, array('id' => $cmid)), navigation_node::TYPE_SETTING, null, 'questions', new pix_icon('t/edit', ''));
        $questionnairenode->add_node($node, $beforekey);
    }
    if (has_capability('mod/questionnaire:preview', $context) && $owner) {
        $url = '/mod/questionnaire/preview.php';
        $node = navigation_node::create(get_string('preview_label', 'questionnaire'), new moodle_url($url, array('id' => $cmid)), navigation_node::TYPE_SETTING, null, 'preview', new pix_icon('t/preview', ''));
        $questionnairenode->add_node($node, $beforekey);
    }
    if ($questionnaire->user_can_take($USER->id)) {
        $url = '/mod/questionnaire/complete.php';
        $node = navigation_node::create(get_string('answerquestions', 'questionnaire'), new moodle_url($url, array('id' => $cmid)), navigation_node::TYPE_SETTING, null, '', new pix_icon('i/info', 'answerquestions'));
        $questionnairenode->add_node($node, $beforekey);
    }
    $usernumresp = $questionnaire->count_submissions($USER->id);
    if ($questionnaire->capabilities->readownresponses && $usernumresp > 0) {
        $url = '/mod/questionnaire/myreport.php';
        $node = navigation_node::create(get_string('yourresponses', 'questionnaire'), new moodle_url($url, array('instance' => $questionnaire->id, 'userid' => $USER->id, 'byresponse' => 0, 'action' => 'summary')), navigation_node::TYPE_SETTING, null, 'yourresponses');
        $myreportnode = $questionnairenode->add_node($node, $beforekey);
        $summary = $myreportnode->add(get_string('summary', 'questionnaire'), new moodle_url('/mod/questionnaire/myreport.php', array('instance' => $questionnaire->id, 'userid' => $USER->id, 'byresponse' => 0, 'action' => 'summary')));
        $byresponsenode = $myreportnode->add(get_string('viewbyresponse', 'questionnaire'), new moodle_url('/mod/questionnaire/myreport.php', array('instance' => $questionnaire->id, 'userid' => $USER->id, 'byresponse' => 1, 'action' => 'vresp')));
        $allmyresponsesnode = $myreportnode->add(get_string('myresponses', 'questionnaire'), new moodle_url('/mod/questionnaire/myreport.php', array('instance' => $questionnaire->id, 'userid' => $USER->id, 'byresponse' => 0, 'action' => 'vall')));
        if ($questionnaire->capabilities->downloadresponses) {
            $downloadmyresponsesnode = $myreportnode->add(get_string('downloadtext'), new moodle_url('/mod/questionnaire/report.php', array('instance' => $questionnaire->id, 'user' => $USER->id, 'action' => 'dwnpg', 'group' => $currentgroupid)));
        }
    }
    $numresp = $questionnaire->count_submissions();
    // Number of responses in currently selected group (or all participants etc.).
    if (isset($SESSION->questionnaire->numselectedresps)) {
        $numselectedresps = $SESSION->questionnaire->numselectedresps;
    } else {
        $numselectedresps = $numresp;
    }
    // If questionnaire is set to separate groups, prevent user who is not member of any group
    // to view All responses.
    $canviewgroups = true;
    $groupmode = groups_get_activity_groupmode($cm, $course);
    if ($groupmode == 1) {
        $canviewgroups = groups_has_membership($cm, $USER->id);
    }
    if ($questionnaire->capabilities->readallresponseanytime && $numresp > 0 && $owner && $numselectedresps > 0 || $questionnaire->capabilities->readallresponses && $numresp > 0 && $canviewgroups && ($questionnaire->resp_view == QUESTIONNAIRE_STUDENTVIEWRESPONSES_ALWAYS || $questionnaire->resp_view == QUESTIONNAIRE_STUDENTVIEWRESPONSES_WHENCLOSED && $questionnaire->is_closed() || $questionnaire->resp_view == QUESTIONNAIRE_STUDENTVIEWRESPONSES_WHENANSWERED && $usernumresp > 0) && $questionnaire->is_survey_owner()) {
        $url = '/mod/questionnaire/report.php';
        $node = navigation_node::create(get_string('viewallresponses', 'questionnaire'), new moodle_url($url, array('instance' => $questionnaire->id, 'action' => 'vall')), navigation_node::TYPE_SETTING, null, 'vall');
        $reportnode = $questionnairenode->add_node($node, $beforekey);
        if ($questionnaire->capabilities->viewsingleresponse) {
            $summarynode = $reportnode->add(get_string('summary', 'questionnaire'), new moodle_url('/mod/questionnaire/report.php', array('instance' => $questionnaire->id, 'action' => 'vall')));
        } else {
            $summarynode = $reportnode;
        }
        $defaultordernode = $summarynode->add(get_string('order_default', 'questionnaire'), new moodle_url('/mod/questionnaire/report.php', array('instance' => $questionnaire->id, 'action' => 'vall', 'group' => $currentgroupid)));
        $ascendingordernode = $summarynode->add(get_string('order_ascending', 'questionnaire'), new moodle_url('/mod/questionnaire/report.php', array('instance' => $questionnaire->id, 'action' => 'vallasort', 'group' => $currentgroupid)));
        $descendingordernode = $summarynode->add(get_string('order_descending', 'questionnaire'), new moodle_url('/mod/questionnaire/report.php', array('instance' => $questionnaire->id, 'action' => 'vallarsort', 'group' => $currentgroupid)));
        if ($questionnaire->capabilities->deleteresponses) {
            $deleteallnode = $summarynode->add(get_string('deleteallresponses', 'questionnaire'), new moodle_url('/mod/questionnaire/report.php', array('instance' => $questionnaire->id, 'action' => 'delallresp', 'group' => $currentgroupid)));
        }
        if ($questionnaire->capabilities->downloadresponses) {
            $downloadresponsesnode = $summarynode->add(get_string('downloadtextformat', 'questionnaire'), new moodle_url('/mod/questionnaire/report.php', array('instance' => $questionnaire->id, 'action' => 'dwnpg', 'group' => $currentgroupid)));
        }
        if ($questionnaire->capabilities->viewsingleresponse && $questionnaire->respondenttype != 'anonymous') {
            $byresponsenode = $reportnode->add(get_string('viewbyresponse', 'questionnaire'), new moodle_url('/mod/questionnaire/report.php', array('instance' => $questionnaire->id, 'action' => 'vresp', 'byresponse' => 1, 'group' => $currentgroupid)));
            $viewindividualresponsenode = $byresponsenode->add(get_string('view', 'questionnaire'), new moodle_url('/mod/questionnaire/report.php', array('instance' => $questionnaire->id, 'action' => 'vresp', 'byresponse' => 1, 'group' => $currentgroupid)));
            if ($individualresponse) {
                $deleteindividualresponsenode = $byresponsenode->add(get_string('deleteresp', 'questionnaire'), new moodle_url('/mod/questionnaire/report.php', array('instance' => $questionnaire->id, 'action' => 'dresp', 'byresponse' => 1, 'rid' => $rid, 'group' => $currentgroupid, 'individualresponse' => 1)));
            }
        }
    }
    if ($questionnaire->capabilities->viewsingleresponse) {
        $url = '/mod/questionnaire/show_nonrespondents.php';
        $node = navigation_node::create(get_string('show_nonrespondents', 'questionnaire'), new moodle_url($url, array('id' => $cmid)), navigation_node::TYPE_SETTING, null, 'nonrespondents');
        $nonrespondentsnode = $questionnairenode->add_node($node, $beforekey);
    }
}
Ejemplo n.º 21
0
/**
 * Adds module specific settings to the settings block
 *
 * @param settings_navigation $settings The settings navigation object
 * @param navigation_node $questionnairenode The node to add module settings to
 *
 * $settings is unused, but API requires it. Suppress PHPMD warning.
 *
 * @SuppressWarnings(PHPMD.UnusedFormalParameter)
 */
function questionnaire_extend_settings_navigation(settings_navigation $settings, navigation_node $questionnairenode)
{
    global $PAGE, $DB, $USER, $CFG;
    $individualresponse = optional_param('individualresponse', false, PARAM_INT);
    $rid = optional_param('rid', false, PARAM_INT);
    // Response id.
    $currentgroupid = optional_param('group', 0, PARAM_INT);
    // Group id.
    require_once $CFG->dirroot . '/mod/questionnaire/questionnaire.class.php';
    $context = $PAGE->cm->context;
    $cmid = $PAGE->cm->id;
    $cm = $PAGE->cm;
    $course = $PAGE->course;
    if (!($questionnaire = $DB->get_record("questionnaire", array("id" => $cm->instance)))) {
        print_error('invalidcoursemodule');
    }
    $courseid = $course->id;
    $questionnaire = new questionnaire(0, $questionnaire, $course, $cm);
    if ($owner = $DB->get_field('questionnaire_survey', 'owner', array('id' => $questionnaire->sid))) {
        $owner = trim($owner) == trim($courseid);
    } else {
        $owner = true;
    }
    // On view page, currentgroupid is not yet sent as an optional_param, so get it.
    $groupmode = groups_get_activity_groupmode($cm, $course);
    if ($groupmode > 0 && $currentgroupid == 0) {
        $currentgroupid = groups_get_activity_group($questionnaire->cm);
        if (!groups_is_member($currentgroupid, $USER->id)) {
            $currentgroupid = 0;
        }
    }
    // We want to add these new nodes after the Edit settings node, and before the
    // Locally assigned roles node. Of course, both of those are controlled by capabilities.
    $keys = $questionnairenode->get_children_key_list();
    $beforekey = null;
    $i = array_search('modedit', $keys);
    if ($i === false && array_key_exists(0, $keys)) {
        $beforekey = $keys[0];
    } else {
        if (array_key_exists($i + 1, $keys)) {
            $beforekey = $keys[$i + 1];
        }
    }
    if (has_capability('mod/questionnaire:manage', $context) && $owner) {
        $url = '/mod/questionnaire/qsettings.php';
        $node = navigation_node::create(get_string('advancedsettings'), new moodle_url($url, array('id' => $cmid)), navigation_node::TYPE_SETTING, null, 'advancedsettings', new pix_icon('t/edit', ''));
        $questionnairenode->add_node($node, $beforekey);
    }
    if (has_capability('mod/questionnaire:editquestions', $context) && $owner) {
        $url = '/mod/questionnaire/questions.php';
        $node = navigation_node::create(get_string('questions', 'questionnaire'), new moodle_url($url, array('id' => $cmid)), navigation_node::TYPE_SETTING, null, 'questions', new pix_icon('t/edit', ''));
        $questionnairenode->add_node($node, $beforekey);
    }
    if (has_capability('mod/questionnaire:preview', $context)) {
        $url = '/mod/questionnaire/preview.php';
        $node = navigation_node::create(get_string('preview_label', 'questionnaire'), new moodle_url($url, array('id' => $cmid)), navigation_node::TYPE_SETTING, null, 'preview', new pix_icon('t/preview', ''));
        $questionnairenode->add_node($node, $beforekey);
    }
    if ($questionnaire->user_can_take($USER->id)) {
        $url = '/mod/questionnaire/complete.php';
        if ($questionnaire->user_has_saved_response($USER->id)) {
            $args = ['id' => $cmid, 'resume' => 1];
            $text = get_string('resumesurvey', 'questionnaire');
        } else {
            $args = ['id' => $cmid];
            $text = get_string('answerquestions', 'questionnaire');
        }
        $node = navigation_node::create($text, new moodle_url($url, $args), navigation_node::TYPE_SETTING, null, '', new pix_icon('i/info', 'answerquestions'));
        $questionnairenode->add_node($node, $beforekey);
    }
    $usernumresp = $questionnaire->count_submissions($USER->id);
    if ($questionnaire->capabilities->readownresponses && $usernumresp > 0) {
        $url = '/mod/questionnaire/myreport.php';
        if ($usernumresp > 1) {
            $urlargs = array('instance' => $questionnaire->id, 'userid' => $USER->id, 'byresponse' => 0, 'action' => 'summary', 'group' => $currentgroupid);
            $node = navigation_node::create(get_string('yourresponses', 'questionnaire'), new moodle_url($url, $urlargs), navigation_node::TYPE_SETTING, null, 'yourresponses');
            $myreportnode = $questionnairenode->add_node($node, $beforekey);
            $urlargs = array('instance' => $questionnaire->id, 'userid' => $USER->id, 'byresponse' => 0, 'action' => 'summary', 'group' => $currentgroupid);
            $myreportnode->add(get_string('summary', 'questionnaire'), new moodle_url($url, $urlargs));
            $urlargs = array('instance' => $questionnaire->id, 'userid' => $USER->id, 'byresponse' => 1, 'action' => 'vresp', 'group' => $currentgroupid);
            $byresponsenode = $myreportnode->add(get_string('viewindividualresponse', 'questionnaire'), new moodle_url($url, $urlargs));
            $urlargs = array('instance' => $questionnaire->id, 'userid' => $USER->id, 'byresponse' => 0, 'action' => 'vall', 'group' => $currentgroupid);
            $myreportnode->add(get_string('myresponses', 'questionnaire'), new moodle_url($url, $urlargs));
            if ($questionnaire->capabilities->downloadresponses) {
                $urlargs = array('instance' => $questionnaire->id, 'user' => $USER->id, 'action' => 'dwnpg', 'group' => $currentgroupid);
                $myreportnode->add(get_string('downloadtext'), new moodle_url('/mod/questionnaire/report.php', $urlargs));
            }
        } else {
            $urlargs = array('instance' => $questionnaire->id, 'userid' => $USER->id, 'byresponse' => 1, 'action' => 'vresp', 'group' => $currentgroupid);
            $node = navigation_node::create(get_string('yourresponse', 'questionnaire'), new moodle_url($url, $urlargs), navigation_node::TYPE_SETTING, null, 'yourresponse');
            $myreportnode = $questionnairenode->add_node($node, $beforekey);
        }
    }
    // If questionnaire is set to separate groups, prevent user who is not member of any group
    // and is not a non-editing teacher to view All responses.
    if ($questionnaire->can_view_all_responses($usernumresp)) {
        $url = '/mod/questionnaire/report.php';
        $node = navigation_node::create(get_string('viewallresponses', 'questionnaire'), new moodle_url($url, array('instance' => $questionnaire->id, 'action' => 'vall')), navigation_node::TYPE_SETTING, null, 'vall');
        $reportnode = $questionnairenode->add_node($node, $beforekey);
        if ($questionnaire->capabilities->viewsingleresponse) {
            $summarynode = $reportnode->add(get_string('summary', 'questionnaire'), new moodle_url('/mod/questionnaire/report.php', array('instance' => $questionnaire->id, 'action' => 'vall')));
        } else {
            $summarynode = $reportnode;
        }
        $summarynode->add(get_string('order_default', 'questionnaire'), new moodle_url('/mod/questionnaire/report.php', array('instance' => $questionnaire->id, 'action' => 'vall', 'group' => $currentgroupid)));
        $summarynode->add(get_string('order_ascending', 'questionnaire'), new moodle_url('/mod/questionnaire/report.php', array('instance' => $questionnaire->id, 'action' => 'vallasort', 'group' => $currentgroupid)));
        $summarynode->add(get_string('order_descending', 'questionnaire'), new moodle_url('/mod/questionnaire/report.php', array('instance' => $questionnaire->id, 'action' => 'vallarsort', 'group' => $currentgroupid)));
        if ($questionnaire->capabilities->deleteresponses) {
            $summarynode->add(get_string('deleteallresponses', 'questionnaire'), new moodle_url('/mod/questionnaire/report.php', array('instance' => $questionnaire->id, 'action' => 'delallresp', 'group' => $currentgroupid)));
        }
        if ($questionnaire->capabilities->downloadresponses) {
            $summarynode->add(get_string('downloadtextformat', 'questionnaire'), new moodle_url('/mod/questionnaire/report.php', array('instance' => $questionnaire->id, 'action' => 'dwnpg', 'group' => $currentgroupid)));
        }
        if ($questionnaire->capabilities->viewsingleresponse) {
            $byresponsenode = $reportnode->add(get_string('viewbyresponse', 'questionnaire'), new moodle_url('/mod/questionnaire/report.php', array('instance' => $questionnaire->id, 'action' => 'vresp', 'byresponse' => 1, 'group' => $currentgroupid)));
            $byresponsenode->add(get_string('view', 'questionnaire'), new moodle_url('/mod/questionnaire/report.php', array('instance' => $questionnaire->id, 'action' => 'vresp', 'byresponse' => 1, 'group' => $currentgroupid)));
            if ($individualresponse) {
                $byresponsenode->add(get_string('deleteresp', 'questionnaire'), new moodle_url('/mod/questionnaire/report.php', array('instance' => $questionnaire->id, 'action' => 'dresp', 'byresponse' => 1, 'rid' => $rid, 'group' => $currentgroupid, 'individualresponse' => 1)));
            }
        }
    }
    $canviewgroups = true;
    $groupmode = groups_get_activity_groupmode($cm, $course);
    if ($groupmode == 1) {
        $canviewgroups = groups_has_membership($cm, $USER->id);
    }
    $canviewallgroups = has_capability('moodle/site:accessallgroups', $context);
    if ($questionnaire->capabilities->viewsingleresponse && ($canviewallgroups || $canviewgroups)) {
        $url = '/mod/questionnaire/show_nonrespondents.php';
        $node = navigation_node::create(get_string('show_nonrespondents', 'questionnaire'), new moodle_url($url, array('id' => $cmid)), navigation_node::TYPE_SETTING, null, 'nonrespondents');
        $questionnairenode->add_node($node, $beforekey);
    }
}