Ejemplo n.º 1
0
/**
 * Add a "Compile" menu link to the Course Admin block as the top link.
 *
 * @author Gerald Albion
 * date 2014-10-31
 * @copyright 2014 Royal Roads University
 * @param object $settingsnav Main navigation object.
 * @param object $context Course context.
 */
function local_compile_extends_settings_navigation($settingsnav, $context)
{
    // Context must be course.
    if ($context->contextlevel != CONTEXT_COURSE) {
        return;
    }
    // Must be in a valid course: Cannot be course id 0.
    if ($context->instanceid == 0) {
        return;
    }
    // Must be in a valid course: Course must be retrievable.
    if (!($course = get_course($context->instanceid))) {
        return;
    }
    // Must be enrolled or otherwise allowed to view the course.
    if (!(is_enrolled($context) || is_viewing($context))) {
        return;
    }
    // Must have a course admin menu in which to add link.
    if (!($coursenode = $settingsnav->find('courseadmin', navigation_node::TYPE_COURSE))) {
        return;
    }
    // Good to go.  Build the menu item.
    $url = new moodle_url('/local/compile/list_modules.php', array('id' => $course->id));
    $newnode = navigation_node::create(get_string('menucaption', 'local_compile'), $url, navigation_node::NODETYPE_LEAF, 'compile', 'compile', new pix_icon('i/settings', ''));
    // We want to put this link at the top: find the existing top (first) node.
    $firstnode = $coursenode->get_children_key_list()[0];
    // Add the menu item to the menu, before the first node.
    $coursenode->add_node($newnode, $firstnode);
}
Ejemplo n.º 2
0
 /**
  * Adds the item in course settings navigation to toggle modchooser
  *
  * Theme can overwrite as an empty function to exclude it (for example if theme does not
  * use modchooser at all)
  */
 protected function add_modchoosertoggle()
 {
     global $CFG;
     static $modchoosertoggleadded = false;
     // Add the module chooser toggle to the course page
     if ($modchoosertoggleadded || $this->page->state > moodle_page::STATE_PRINTING_HEADER || $this->page->course->id == SITEID || !$this->page->user_is_editing() || !($context = context_course::instance($this->page->course->id)) || !has_capability('moodle/course:update', $context) || !course_ajax_enabled($this->page->course) || !($coursenode = $this->page->settingsnav->find('courseadmin', navigation_node::TYPE_COURSE)) || !$coursenode->get('editsettings')) {
         // too late or we are on site page or we could not find the course settings node
         // or we are not allowed to edit
         return;
     }
     $modchoosertoggleadded = true;
     if ($this->page->url->compare(new moodle_url('/course/view.php'), URL_MATCH_BASE)) {
         // We are on the course page, retain the current page params e.g. section.
         $modchoosertoggleurl = clone $this->page->url;
     } else {
         // Edit on the main course page.
         $modchoosertoggleurl = new moodle_url('/course/view.php', array('id' => $this->page->course->id, 'return' => $this->page->url->out_as_local_url(false)));
     }
     $modchoosertoggleurl->param('sesskey', sesskey());
     if ($usemodchooser = get_user_preferences('usemodchooser', $CFG->modchooserdefault)) {
         $modchoosertogglestring = get_string('modchooserdisable', 'moodle');
         $modchoosertoggleurl->param('modchooser', 'off');
     } else {
         $modchoosertogglestring = get_string('modchooserenable', 'moodle');
         $modchoosertoggleurl->param('modchooser', 'on');
     }
     $modchoosertoggle = navigation_node::create($modchoosertogglestring, $modchoosertoggleurl, navigation_node::TYPE_SETTING);
     $coursenode->add_node($modchoosertoggle, 'editsettings');
     $modchoosertoggle->add_class('modchoosertoggle');
     $modchoosertoggle->add_class('visibleifjs');
     user_preference_allow_ajax_update('usemodchooser', PARAM_BOOL);
 }
Ejemplo n.º 3
0
/**
* Sets up the main navigation
* @param settingsnav $settingsnav navigation settings object
* @param context $context Context of the form
*/
function local_metadata_extends_settings_navigation($settingsnav, $context)
{
    global $CFG, $PAGE, $USER;
    // Setup navigation for Admin metadata
    if (is_null($PAGE->course)) {
        //return;
    } else {
        if ($categorynode = $settingsnav->find('categorysettings', null)) {
            $url = new moodle_url('/local/metadata/admview_knowledge.php', array('categoryid' => $PAGE->category->id));
            $foonode = navigation_node::create(get_string('manage_pluginname', 'local_metadata'), $url, navigation_node::NODETYPE_LEAF, 'metadata', 'metadata', new pix_icon('i/report', ''));
            if ($PAGE->url->compare($url, URL_MATCH_BASE)) {
                $foonode->make_active();
            }
            $categorynode->add_node($foonode);
            //$categorynode->add(get_string('manage_pluginname', 'local_metadata'), $url, self::TYPE_SETTING, null, 'permissions', new pix_icon('i/permissions', ''));
        }
    }
    // Only add this settings item on non-site course pages.
    if (!$PAGE->course or $PAGE->course->id == 1) {
        return;
    }
    // TODO: Only let users with the appropriate capability see this settings item.
    //if (!has_capability('local/metadata:ins_view', context_course::instance($PAGE->course->id))) {
    //    return;
    //}
    if ($settingnode = $settingsnav->find('courseadmin', navigation_node::TYPE_COURSE)) {
        $url = new moodle_url('/local/metadata/insview_general.php', array('id' => $PAGE->course->id));
        // TODO: Should change the name to something more descriptive
        $foonode = navigation_node::create(get_string('ins_pluginname', 'local_metadata'), $url, navigation_node::NODETYPE_LEAF, 'metadata', 'metadata', new pix_icon('i/report', ''));
        if ($PAGE->url->compare($url, URL_MATCH_BASE)) {
            $foonode->make_active();
        }
        $settingnode->add_node($foonode);
    }
}
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_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.º 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;
    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.º 6
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.º 7
0
function local_forum2pdf_extends_settings_navigation(settings_navigation $nav, context $context)
{
    global $PAGE;
    // 教師にのみPDF出力を許可
    if (!has_capability('moodle/course:manageactivities', $context)) {
        return;
    }
    //echo "<pre>"; var_dump($PAGE->cm->instance); echo "</pre>";
    if ($PAGE->context->contextlevel == CONTEXT_MODULE && $PAGE->cm->modname === 'forum') {
        $pdflink = navigation_node::create(get_string('pdflink', 'local_forum2pdf'));
        $pdflink->key = 'forum2pdf';
        $pdflink->action = new moodle_url('/local/forum2pdf/export.php', array('f' => $PAGE->cm->instance));
        $modulesettings = $nav->get('modulesettings');
        $modulesettings->add_node($pdflink);
    }
}
Ejemplo n.º 8
0
function local_saml_site_extend_settings_navigation($settingsnav, $context)
{
    global $CFG, $PAGE;
    if (has_capability('local/saml_site:addrules', context_course::instance($PAGE->course->id))) {
        $settingnode = $settingsnav->find('root', navigation_node::TYPE_SITE_ADMIN);
        if ($settingnode) {
            $setMotdMenuLbl = get_string('adminmenutitle', 'local_saml_site');
            $setMotdUrl = new moodle_url('/local/saml_site/samlsitepermissions.php');
            $setMotdnode = navigation_node::create($setMotdMenuLbl, $setMotdUrl, navigation_node::NODETYPE_LEAF, 'saml_site', 'saml_site', new pix_icon('i/settings', $setMotdMenuLbl));
            if ($PAGE->url->compare($setMotdUrl, URL_MATCH_BASE)) {
                $setMotdnode->make_active();
            }
            $settingnode->add_node($setMotdnode);
        }
    }
}
Ejemplo n.º 9
0
function local_saml_siteenrol_extend_settings_navigation($settingsnav, $context)
{
    global $CFG, $PAGE;
    // Only let users with the appropriate capability see this settings item.
    if (has_capability('local/saml_siteenrol:addorremoveusers', context_course::instance($PAGE->course->id))) {
        if ($settingnode = $settingsnav->find('users', navigation_node::TYPE_CONTAINER)) {
            $url = new moodle_url('/local/saml_siteenrol/usermanager.php', array('id' => $PAGE->course->id));
            $strfoo = get_string('menuname', 'local_saml_siteenrol');
            $foonode = navigation_node::create($strfoo, $url, navigation_node::NODETYPE_LEAF, 'saml_siteenrol', 'saml_siteenrol', new pix_icon('i/enrolusers', $strfoo));
            if ($PAGE->url->compare($url, URL_MATCH_BASE)) {
                $foonode->make_active();
            }
            $settingnode->add_node($foonode);
        }
    }
}
Ejemplo n.º 10
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.º 11
0
function local_enrolmentreminder_extends_settings_navigation($settingsnav)
{
    global $PAGE;
    global $DB;
    global $USER;
    global $SITE;
    if (has_capability('moodle/site:config', context_system::instance())) {
        if ($PAGE->context->contextlevel == CONTEXT_COURSE && $PAGE->course->id != $SITE->id) {
            if ($settingnode = $settingsnav->find('courseadmin', navigation_node::TYPE_COURSE)) {
                $url = new moodle_url('/local/enrolmentreminder/index.php', array('courseid' => $PAGE->course->id));
                $mynode = navigation_node::create(get_string('enrolmentreminder', 'local_enrolmentreminder'), $url, navigation_node::NODETYPE_LEAF, 'local_enrolmentreminder', 'local_enrolmentreminder', new pix_icon('enrolmentreminder-16', get_string('enrolmentreminder', 'local_enrolmentreminder'), 'local_enrolmentreminder'));
                if ($PAGE->url->compare($url, URL_MATCH_BASE)) {
                    $mynode->make_active();
                }
                $settingnode->add_node($mynode);
            }
        }
    }
}
Ejemplo n.º 12
0
function local_syncgroups_extends_settings_navigation(settings_navigation $nav, context $context = null)
{
    global $PAGE;
    // Only add this settings item on non-site course pages.
    if (!$PAGE->course or $PAGE->course->id == 1) {
        return;
    }
    if ($coursenode = $nav->get('courseadmin')) {
        if ($usersnode = $coursenode->get('users')) {
            $str = get_string('pluginname', 'local_syncgroups');
            $url = new moodle_url('/local/syncgroups/index.php', array('courseid' => $context->instanceid));
            $node = navigation_node::create($str, $url, navigation_node::NODETYPE_LEAF, 'local_syncgroups', 'local_syncgroups');
            if ($PAGE->url->compare($url, URL_MATCH_BASE)) {
                $node->make_active();
            }
            $usersnode->add_node($node, 'override');
        }
    }
}
Ejemplo n.º 13
0
 /**
  * Get the list of categories leading to this course.
  *
  * This function is used by {@link navbar::get_items()} to add back the "courses"
  * node and category chain leading to the current course.  Note that this is only ever
  * called for the current course, so we don't need to bother taking in any parameters.
  *
  * @return array
  */
 private function get_course_categories()
 {
     global $CFG;
     require_once $CFG->dirroot . '/course/lib.php';
     $categories = array();
     $cap = 'moodle/category:viewhiddencategories';
     foreach ($this->page->categories as $category) {
         if (!$category->visible && !has_capability($cap, get_category_or_system_context($category->parent))) {
             continue;
         }
         $url = new moodle_url('/course/index.php', array('categoryid' => $category->id));
         $name = format_string($category->name, true, array('context' => context_coursecat::instance($category->id)));
         $categorynode = navigation_node::create($name, $url, self::TYPE_CATEGORY, null, $category->id);
         if (!$category->visible) {
             $categorynode->hidden = true;
         }
         $categories[] = $categorynode;
     }
     if (is_enrolled(context_course::instance($this->page->course->id))) {
         $courses = $this->page->navigation->get('mycourses');
     } else {
         $courses = $this->page->navigation->get('courses');
     }
     if (!$courses) {
         // Courses node may not be present.
         $courses = navigation_node::create(get_string('courses'), new moodle_url('/course/index.php'), self::TYPE_CONTAINER);
     }
     $categories[] = $courses;
     return $categories;
 }
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 $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.º 15
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.º 16
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.º 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 gets called by {@link settings_navigation::load_user_settings()} and actually works out
  * what can be shown/done
  *
  * @param int $courseid The current course' id
  * @param int $userid The user id to load for
  * @param string $gstitle The string to pass to get_string for the branch title
  * @return navigation_node|false
  */
 protected function generate_user_settings($courseid, $userid, $gstitle = 'usercurrentsettings')
 {
     global $DB, $CFG, $USER, $SITE;
     if ($courseid != $SITE->id) {
         if (!empty($this->page->course->id) && $this->page->course->id == $courseid) {
             $course = $this->page->course;
         } else {
             $select = context_helper::get_preload_record_columns_sql('ctx');
             $sql = "SELECT c.*, {$select}\n                          FROM {course} c\n                          JOIN {context} ctx ON c.id = ctx.instanceid\n                         WHERE c.id = :courseid AND ctx.contextlevel = :contextlevel";
             $params = array('courseid' => $courseid, 'contextlevel' => CONTEXT_COURSE);
             $course = $DB->get_record_sql($sql, $params, MUST_EXIST);
             context_helper::preload_from_record($course);
         }
     } else {
         $course = $SITE;
     }
     $coursecontext = context_course::instance($course->id);
     // Course context
     $systemcontext = context_system::instance();
     $currentuser = $USER->id == $userid;
     if ($currentuser) {
         $user = $USER;
         $usercontext = context_user::instance($user->id);
         // User context
     } else {
         $select = context_helper::get_preload_record_columns_sql('ctx');
         $sql = "SELECT u.*, {$select}\n                      FROM {user} u\n                      JOIN {context} ctx ON u.id = ctx.instanceid\n                     WHERE u.id = :userid AND ctx.contextlevel = :contextlevel";
         $params = array('userid' => $userid, 'contextlevel' => CONTEXT_USER);
         $user = $DB->get_record_sql($sql, $params, IGNORE_MISSING);
         if (!$user) {
             return false;
         }
         context_helper::preload_from_record($user);
         // Check that the user can view the profile
         $usercontext = context_user::instance($user->id);
         // User context
         $canviewuser = has_capability('moodle/user:viewdetails', $usercontext);
         if ($course->id == $SITE->id) {
             if ($CFG->forceloginforprofiles && !has_coursecontact_role($user->id) && !$canviewuser) {
                 // Reduce possibility of "browsing" userbase at site level
                 // Teachers can browse and be browsed at site level. If not forceloginforprofiles, allow access (bug #4366)
                 return false;
             }
         } else {
             $canviewusercourse = has_capability('moodle/user:viewdetails', $coursecontext);
             $userisenrolled = is_enrolled($coursecontext, $user->id, '', true);
             if (!$canviewusercourse && !$canviewuser || !$userisenrolled) {
                 return false;
             }
             $canaccessallgroups = has_capability('moodle/site:accessallgroups', $coursecontext);
             if (!$canaccessallgroups && groups_get_course_groupmode($course) == SEPARATEGROUPS && !$canviewuser) {
                 // If groups are in use, make sure we can see that group (MDL-45874). That does not apply to parents.
                 if ($courseid == $this->page->course->id) {
                     $mygroups = get_fast_modinfo($this->page->course)->groups;
                 } else {
                     $mygroups = groups_get_user_groups($courseid);
                 }
                 $usergroups = groups_get_user_groups($courseid, $userid);
                 if (!array_intersect_key($mygroups[0], $usergroups[0])) {
                     return false;
                 }
             }
         }
     }
     $fullname = fullname($user, has_capability('moodle/site:viewfullnames', $this->page->context));
     $key = $gstitle;
     $prefurl = new moodle_url('/user/preferences.php');
     if ($gstitle != 'usercurrentsettings') {
         $key .= $userid;
         $prefurl->param('userid', $userid);
     }
     // Add a user setting branch.
     if ($gstitle == 'usercurrentsettings') {
         $dashboard = $this->add(get_string('myhome'), new moodle_url('/my/'), self::TYPE_CONTAINER, null, 'dashboard');
         // This should be set to false as we don't want to show this to the user. It's only for generating the correct
         // breadcrumb.
         $dashboard->display = false;
         if (get_home_page() == HOMEPAGE_MY) {
             $dashboard->mainnavonly = true;
         }
         $iscurrentuser = $user->id == $USER->id;
         $baseargs = array('id' => $user->id);
         if ($course->id != $SITE->id && !$iscurrentuser) {
             $baseargs['course'] = $course->id;
             $issitecourse = false;
         } else {
             // Load all categories and get the context for the system.
             $issitecourse = true;
         }
         // Add the user profile to the dashboard.
         $profilenode = $dashboard->add(get_string('profile'), new moodle_url('/user/profile.php', array('id' => $user->id)), self::TYPE_SETTING, null, 'myprofile');
         if (!empty($CFG->navadduserpostslinks)) {
             // Add nodes for forum posts and discussions if the user can view either or both
             // There are no capability checks here as the content of the page is based
             // purely on the forums the current user has access too.
             $forumtab = $profilenode->add(get_string('forumposts', 'forum'));
             $forumtab->add(get_string('posts', 'forum'), new moodle_url('/mod/forum/user.php', $baseargs), null, 'myposts');
             $forumtab->add(get_string('discussions', 'forum'), new moodle_url('/mod/forum/user.php', array_merge($baseargs, array('mode' => 'discussions'))), null, 'mydiscussions');
         }
         // Add blog nodes.
         if (!empty($CFG->enableblogs)) {
             if (!$this->cache->cached('userblogoptions' . $user->id)) {
                 require_once $CFG->dirroot . '/blog/lib.php';
                 // Get all options for the user.
                 $options = blog_get_options_for_user($user);
                 $this->cache->set('userblogoptions' . $user->id, $options);
             } else {
                 $options = $this->cache->{'userblogoptions' . $user->id};
             }
             if (count($options) > 0) {
                 $blogs = $profilenode->add(get_string('blogs', 'blog'), null, navigation_node::TYPE_CONTAINER);
                 foreach ($options as $type => $option) {
                     if ($type == "rss") {
                         $blogs->add($option['string'], $option['link'], self::TYPE_SETTING, null, null, new pix_icon('i/rss', ''));
                     } else {
                         $blogs->add($option['string'], $option['link'], self::TYPE_SETTING, null, 'blog' . $type);
                     }
                 }
             }
         }
         // Add the messages link.
         // It is context based so can appear in the user's profile and in course participants information.
         if (!empty($CFG->messaging)) {
             $messageargs = array('user1' => $USER->id);
             if ($USER->id != $user->id) {
                 $messageargs['user2'] = $user->id;
             }
             if ($course->id != $SITE->id) {
                 $messageargs['viewing'] = MESSAGE_VIEW_COURSE . $course->id;
             }
             $url = new moodle_url('/message/index.php', $messageargs);
             $dashboard->add(get_string('messages', 'message'), $url, self::TYPE_SETTING, null, 'messages');
         }
         // Add the "My private files" link.
         // This link doesn't have a unique display for course context so only display it under the user's profile.
         if ($issitecourse && $iscurrentuser && has_capability('moodle/user:manageownfiles', $usercontext)) {
             $url = new moodle_url('/user/files.php');
             $dashboard->add(get_string('privatefiles'), $url, self::TYPE_SETTING);
         }
         // Add a node to view the users notes if permitted.
         if (!empty($CFG->enablenotes) && has_any_capability(array('moodle/notes:manage', 'moodle/notes:view'), $coursecontext)) {
             $url = new moodle_url('/notes/index.php', array('user' => $user->id));
             if ($coursecontext->instanceid != SITEID) {
                 $url->param('course', $coursecontext->instanceid);
             }
             $profilenode->add(get_string('notes', 'notes'), $url);
         }
         // Show the grades node.
         if ($issitecourse && $iscurrentuser || has_capability('moodle/user:viewdetails', $usercontext)) {
             require_once $CFG->dirroot . '/user/lib.php';
             // Set the grades node to link to the "Grades" page.
             if ($course->id == SITEID) {
                 $url = user_mygrades_url($user->id, $course->id);
             } else {
                 // Otherwise we are in a course and should redirect to the user grade report (Activity report version).
                 $url = new moodle_url('/course/user.php', array('mode' => 'grade', 'id' => $course->id, 'user' => $user->id));
             }
             $dashboard->add(get_string('grades', 'grades'), $url, self::TYPE_SETTING, null, 'mygrades');
         }
         // Let plugins hook into user navigation.
         $pluginsfunction = get_plugins_with_function('extend_navigation_user', 'lib.php');
         foreach ($pluginsfunction as $plugintype => $plugins) {
             if ($plugintype != 'report') {
                 foreach ($plugins as $pluginfunction) {
                     $pluginfunction($profilenode, $user, $usercontext, $course, $coursecontext);
                 }
             }
         }
         $usersetting = navigation_node::create(get_string('preferences', 'moodle'), $prefurl, self::TYPE_CONTAINER, null, $key);
         $dashboard->add_node($usersetting);
     } else {
         $usersetting = $this->add(get_string('preferences', 'moodle'), $prefurl, self::TYPE_CONTAINER, null, $key);
         $usersetting->display = false;
     }
     $usersetting->id = 'usersettings';
     // Check if the user has been deleted.
     if ($user->deleted) {
         if (!has_capability('moodle/user:update', $coursecontext)) {
             // We can't edit the user so just show the user deleted message.
             $usersetting->add(get_string('userdeleted'), null, self::TYPE_SETTING);
         } else {
             // We can edit the user so show the user deleted message and link it to the profile.
             if ($course->id == $SITE->id) {
                 $profileurl = new moodle_url('/user/profile.php', array('id' => $user->id));
             } else {
                 $profileurl = new moodle_url('/user/view.php', array('id' => $user->id, 'course' => $course->id));
             }
             $usersetting->add(get_string('userdeleted'), $profileurl, self::TYPE_SETTING);
         }
         return true;
     }
     $userauthplugin = false;
     if (!empty($user->auth)) {
         $userauthplugin = get_auth_plugin($user->auth);
     }
     $useraccount = $usersetting->add(get_string('useraccount'), null, self::TYPE_CONTAINER, null, 'useraccount');
     // Add the profile edit link.
     if (isloggedin() && !isguestuser($user) && !is_mnet_remote_user($user)) {
         if (($currentuser || is_siteadmin($USER) || !is_siteadmin($user)) && has_capability('moodle/user:update', $systemcontext)) {
             $url = new moodle_url('/user/editadvanced.php', array('id' => $user->id, 'course' => $course->id));
             $useraccount->add(get_string('editmyprofile'), $url, self::TYPE_SETTING);
         } else {
             if (has_capability('moodle/user:editprofile', $usercontext) && !is_siteadmin($user) || $currentuser && has_capability('moodle/user:editownprofile', $systemcontext)) {
                 if ($userauthplugin && $userauthplugin->can_edit_profile()) {
                     $url = $userauthplugin->edit_profile_url();
                     if (empty($url)) {
                         $url = new moodle_url('/user/edit.php', array('id' => $user->id, 'course' => $course->id));
                     }
                     $useraccount->add(get_string('editmyprofile'), $url, self::TYPE_SETTING);
                 }
             }
         }
     }
     // Change password link.
     if ($userauthplugin && $currentuser && !\core\session\manager::is_loggedinas() && !isguestuser() && has_capability('moodle/user:changeownpassword', $systemcontext) && $userauthplugin->can_change_password()) {
         $passwordchangeurl = $userauthplugin->change_password_url();
         if (empty($passwordchangeurl)) {
             $passwordchangeurl = new moodle_url('/login/change_password.php', array('id' => $course->id));
         }
         $useraccount->add(get_string("changepassword"), $passwordchangeurl, self::TYPE_SETTING, null, 'changepassword');
     }
     if (isloggedin() && !isguestuser($user) && !is_mnet_remote_user($user)) {
         if ($currentuser && has_capability('moodle/user:editownprofile', $systemcontext) || has_capability('moodle/user:editprofile', $usercontext)) {
             $url = new moodle_url('/user/language.php', array('id' => $user->id, 'course' => $course->id));
             $useraccount->add(get_string('preferredlanguage'), $url, self::TYPE_SETTING, null, 'preferredlanguage');
         }
     }
     $pluginmanager = core_plugin_manager::instance();
     $enabled = $pluginmanager->get_enabled_plugins('mod');
     if (isset($enabled['forum']) && isloggedin() && !isguestuser($user) && !is_mnet_remote_user($user)) {
         if ($currentuser && has_capability('moodle/user:editownprofile', $systemcontext) || has_capability('moodle/user:editprofile', $usercontext)) {
             $url = new moodle_url('/user/forum.php', array('id' => $user->id, 'course' => $course->id));
             $useraccount->add(get_string('forumpreferences'), $url, self::TYPE_SETTING);
         }
     }
     $editors = editors_get_enabled();
     if (count($editors) > 1) {
         if (isloggedin() && !isguestuser($user) && !is_mnet_remote_user($user)) {
             if ($currentuser && has_capability('moodle/user:editownprofile', $systemcontext) || has_capability('moodle/user:editprofile', $usercontext)) {
                 $url = new moodle_url('/user/editor.php', array('id' => $user->id, 'course' => $course->id));
                 $useraccount->add(get_string('editorpreferences'), $url, self::TYPE_SETTING);
             }
         }
     }
     // Add "Course preferences" link.
     if (isloggedin() && !isguestuser($user)) {
         if ($currentuser && has_capability('moodle/user:editownprofile', $systemcontext) || has_capability('moodle/user:editprofile', $usercontext)) {
             $url = new moodle_url('/user/course.php', array('id' => $user->id, 'course' => $course->id));
             $useraccount->add(get_string('coursepreferences'), $url, self::TYPE_SETTING, null, 'coursepreferences');
         }
     }
     // View the roles settings.
     if (has_any_capability(array('moodle/role:assign', 'moodle/role:safeoverride', 'moodle/role:override', 'moodle/role:manage'), $usercontext)) {
         $roles = $usersetting->add(get_string('roles'), null, self::TYPE_SETTING);
         $url = new moodle_url('/admin/roles/usersroles.php', array('userid' => $user->id, 'courseid' => $course->id));
         $roles->add(get_string('thisusersroles', 'role'), $url, self::TYPE_SETTING);
         $assignableroles = get_assignable_roles($usercontext, ROLENAME_BOTH);
         if (!empty($assignableroles)) {
             $url = new moodle_url('/admin/roles/assign.php', array('contextid' => $usercontext->id, 'userid' => $user->id, 'courseid' => $course->id));
             $roles->add(get_string('assignrolesrelativetothisuser', 'role'), $url, self::TYPE_SETTING);
         }
         if (has_capability('moodle/role:review', $usercontext) || count(get_overridable_roles($usercontext, ROLENAME_BOTH)) > 0) {
             $url = new moodle_url('/admin/roles/permissions.php', array('contextid' => $usercontext->id, 'userid' => $user->id, 'courseid' => $course->id));
             $roles->add(get_string('permissions', 'role'), $url, self::TYPE_SETTING);
         }
         $url = new moodle_url('/admin/roles/check.php', array('contextid' => $usercontext->id, 'userid' => $user->id, 'courseid' => $course->id));
         $roles->add(get_string('checkpermissions', 'role'), $url, self::TYPE_SETTING);
     }
     // Repositories.
     if (!$this->cache->cached('contexthasrepos' . $usercontext->id)) {
         require_once $CFG->dirroot . '/repository/lib.php';
         $editabletypes = repository::get_editable_types($usercontext);
         $haseditabletypes = !empty($editabletypes);
         unset($editabletypes);
         $this->cache->set('contexthasrepos' . $usercontext->id, $haseditabletypes);
     } else {
         $haseditabletypes = $this->cache->{'contexthasrepos' . $usercontext->id};
     }
     if ($haseditabletypes) {
         $repositories = $usersetting->add(get_string('repositories', 'repository'), null, self::TYPE_SETTING);
         $repositories->add(get_string('manageinstances', 'repository'), new moodle_url('/repository/manage_instances.php', array('contextid' => $usercontext->id)));
     }
     // Portfolio.
     if ($currentuser && !empty($CFG->enableportfolios) && has_capability('moodle/portfolio:export', $systemcontext)) {
         require_once $CFG->libdir . '/portfoliolib.php';
         if (portfolio_has_visible_instances()) {
             $portfolio = $usersetting->add(get_string('portfolios', 'portfolio'), null, self::TYPE_SETTING);
             $url = new moodle_url('/user/portfolio.php', array('courseid' => $course->id));
             $portfolio->add(get_string('configure', 'portfolio'), $url, self::TYPE_SETTING);
             $url = new moodle_url('/user/portfoliologs.php', array('courseid' => $course->id));
             $portfolio->add(get_string('logs', 'portfolio'), $url, self::TYPE_SETTING);
         }
     }
     $enablemanagetokens = false;
     if (!empty($CFG->enablerssfeeds)) {
         $enablemanagetokens = true;
     } else {
         if (!is_siteadmin($USER->id) && !empty($CFG->enablewebservices) && has_capability('moodle/webservice:createtoken', context_system::instance())) {
             $enablemanagetokens = true;
         }
     }
     // Security keys.
     if ($currentuser && $enablemanagetokens) {
         $url = new moodle_url('/user/managetoken.php', array('sesskey' => sesskey()));
         $useraccount->add(get_string('securitykeys', 'webservice'), $url, self::TYPE_SETTING);
     }
     // Messaging.
     if ($currentuser && has_capability('moodle/user:editownmessageprofile', $systemcontext) || !isguestuser($user) && has_capability('moodle/user:editmessageprofile', $usercontext) && !is_primary_admin($user->id)) {
         $url = new moodle_url('/message/edit.php', array('id' => $user->id));
         $useraccount->add(get_string('messaging', 'message'), $url, self::TYPE_SETTING);
     }
     // Blogs.
     if ($currentuser && !empty($CFG->enableblogs)) {
         $blog = $usersetting->add(get_string('blogs', 'blog'), null, navigation_node::TYPE_CONTAINER, null, 'blogs');
         if (has_capability('moodle/blog:view', $systemcontext)) {
             $blog->add(get_string('preferences', 'blog'), new moodle_url('/blog/preferences.php'), navigation_node::TYPE_SETTING);
         }
         if (!empty($CFG->useexternalblogs) && $CFG->maxexternalblogsperuser > 0 && has_capability('moodle/blog:manageexternal', $systemcontext)) {
             $blog->add(get_string('externalblogs', 'blog'), new moodle_url('/blog/external_blogs.php'), navigation_node::TYPE_SETTING);
             $blog->add(get_string('addnewexternalblog', 'blog'), new moodle_url('/blog/external_blog_edit.php'), navigation_node::TYPE_SETTING);
         }
         // Remove the blog node if empty.
         $blog->trim_if_empty();
     }
     // Badges.
     if ($currentuser && !empty($CFG->enablebadges)) {
         $badges = $usersetting->add(get_string('badges'), null, navigation_node::TYPE_CONTAINER, null, 'badges');
         if (has_capability('moodle/badges:manageownbadges', $usercontext)) {
             $url = new moodle_url('/badges/mybadges.php');
             $badges->add(get_string('managebadges', 'badges'), $url, self::TYPE_SETTING);
         }
         $badges->add(get_string('preferences', 'badges'), new moodle_url('/badges/preferences.php'), navigation_node::TYPE_SETTING);
         if (!empty($CFG->badges_allowexternalbackpack)) {
             $badges->add(get_string('backpackdetails', 'badges'), new moodle_url('/badges/mybackpack.php'), navigation_node::TYPE_SETTING);
         }
     }
     // Let plugins hook into user settings navigation.
     $pluginsfunction = get_plugins_with_function('extend_navigation_user_settings', 'lib.php');
     foreach ($pluginsfunction as $plugintype => $plugins) {
         foreach ($plugins as $pluginfunction) {
             $pluginfunction($usersetting, $user, $usercontext, $course, $coursecontext);
         }
     }
     return $usersetting;
 }
Ejemplo n.º 19
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.º 20
0
 /**
  * Adds the item in course settings navigation to toggle modchooser
  *
  * Theme can overwrite as an empty function to exclude it (for example if theme does not
  * use modchooser at all)
  */
 protected function add_modchoosertoggle()
 {
     global $CFG;
     // Only needs to be done once per page.
     if (!$this->page->requires->should_create_one_time_item_now('core_course_modchoosertoggle')) {
         return;
     }
     if ($this->page->state > moodle_page::STATE_PRINTING_HEADER || $this->page->course->id == SITEID || !$this->page->user_is_editing() || !($context = context_course::instance($this->page->course->id)) || !has_capability('moodle/course:manageactivities', $context) || !course_ajax_enabled($this->page->course) || !($coursenode = $this->page->settingsnav->find('courseadmin', navigation_node::TYPE_COURSE)) || !($turneditingnode = $coursenode->get('turneditingonoff'))) {
         // Too late, or we are on site page, or we could not find the
         // adjacent nodes in course settings menu, or we are not allowed to edit.
         return;
     }
     if ($this->page->url->compare(new moodle_url('/course/view.php'), URL_MATCH_BASE)) {
         // We are on the course page, retain the current page params e.g. section.
         $modchoosertoggleurl = clone $this->page->url;
     } else {
         // Edit on the main course page.
         $modchoosertoggleurl = new moodle_url('/course/view.php', array('id' => $this->page->course->id, 'return' => $this->page->url->out_as_local_url(false)));
     }
     $modchoosertoggleurl->param('sesskey', sesskey());
     if ($usemodchooser = get_user_preferences('usemodchooser', $CFG->modchooserdefault)) {
         $modchoosertogglestring = get_string('modchooserdisable', 'moodle');
         $modchoosertoggleurl->param('modchooser', 'off');
     } else {
         $modchoosertogglestring = get_string('modchooserenable', 'moodle');
         $modchoosertoggleurl->param('modchooser', 'on');
     }
     $modchoosertoggle = navigation_node::create($modchoosertogglestring, $modchoosertoggleurl, navigation_node::TYPE_SETTING, null, 'modchoosertoggle');
     // Insert the modchoosertoggle after the settings node 'turneditingonoff' (navigation_node only has function to insert before, so we insert before and then swap).
     $coursenode->add_node($modchoosertoggle, 'turneditingonoff');
     $turneditingnode->remove();
     $coursenode->add_node($turneditingnode, 'modchoosertoggle');
     $modchoosertoggle->add_class('modchoosertoggle');
     $modchoosertoggle->add_class('visibleifjs');
     user_preference_allow_ajax_update('usemodchooser', PARAM_BOOL);
 }
Ejemplo n.º 21
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.º 22
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.º 23
0
function local_mail_extend_navigation($root) {
    global $CFG, $COURSE, $PAGE, $SESSION, $SITE, $USER;

    if (!get_config('local_mail', 'version')) {
        return;
    }

    $courses = local_mail_get_my_courses();

    $count = local_mail_message::count_menu($USER->id);

    // My mail

    $text = get_string('mymail', 'local_mail');
    if (!empty($count->inbox)) {
        $text .= ' (' . $count->inbox . ')';
    }
    $node = navigation_node::create($text, null, navigation_node::TYPE_ROOTNODE);
    if (!empty($count->inbox)) {
        $node->add_class('local_mail_new_messages');
    }
    $child = $root->add_node($node, 'mycourses');
    $child->add_class('mail_root');

    // Compose

    $text = get_string('compose', 'local_mail');
    $url = new moodle_url('/local/mail/compose.php');
    $urlrecipients = new moodle_url('/local/mail/recipients.php');

    if ($PAGE->url->compare($url, URL_MATCH_BASE) or
        $PAGE->url->compare($urlrecipients, URL_MATCH_BASE)) {
        $url->param('m', $PAGE->url->param('m'));
    } else {
        $url = new moodle_url('/local/mail/create.php');
        if ($COURSE->id != $SITE->id) {
            $url->param('c', $COURSE->id);
            $url->param('sesskey', sesskey());
        }
    }

    $node->add(s($text), $url);

    // Inbox

    $text = get_string('inbox', 'local_mail');
    if (!empty($count->inbox)) {
        $text .= ' (' . $count->inbox . ')';
    }
    $url = new moodle_url('/local/mail/view.php', array('t' => 'inbox'));
    $child = $node->add(s($text), $url);
    $child->add_class('mail_inbox');

    // Starred

    $text = get_string('starredmail', 'local_mail');
    $url = new moodle_url('/local/mail/view.php', array('t' => 'starred'));
    $node->add(s($text), $url);

    // Drafts

    $text = get_string('drafts', 'local_mail');
    if (!empty($count->drafts)) {
        $text .= ' (' . $count->drafts . ')';
    }
    $url = new moodle_url('/local/mail/view.php', array('t' => 'drafts'));
    $child = $node->add(s($text), $url);
    $child->add_class('mail_drafts');

    // Sent

    $text = get_string('sentmail', 'local_mail');
    $url = new moodle_url('/local/mail/view.php', array('t' => 'sent'));
    $node->add(s($text), $url);

    // Courses

    if ($courses) {
        $text = get_string('courses', 'local_mail');
        $nodecourses = $node->add($text, null, navigation_node::TYPE_CONTAINER);
        foreach ($courses as $course) {
            $text = $course->shortname;
            if (!empty($count->courses[$course->id])) {
                $text .= ' (' . $count->courses[$course->id] . ')';
            }
            $params = array('t' => 'course', 'c' => $course->id);
            $url = new moodle_url('/local/mail/view.php', $params);
            $child = $nodecourses->add(s($text), $url);
            $child->hidden = !$course->visible;
            $child->add_class('mail_course_'.$course->id);
        }
    }

    // Labels

    $labels = local_mail_label::fetch_user($USER->id);
    if ($labels) {
        $text = get_string('labels', 'local_mail');
        $nodelabels = $node->add($text, null, navigation_node::TYPE_CONTAINER);
        foreach ($labels as $label) {
            $text = $label->name();
            if (!empty($count->labels[$label->id()])) {
                $text .= ' (' . $count->labels[$label->id()] . ')';
            }
            $params = array('t' => 'label', 'l' => $label->id());
            $url = new moodle_url('/local/mail/view.php', $params);
            $child = $nodelabels->add(s($text), $url);
            $child->add_class('mail_label_'.$label->id());
        }
    }

    // Trash

    $text = get_string('trash', 'local_mail');
    $url = new moodle_url('/local/mail/view.php', array('t' => 'trash'));
    $node->add(s($text), $url);

    // Preferences

    $text = get_string('preferences');
    $url = new moodle_url('/local/mail/preferences.php');
    $node->add(s($text), $url);

    // User profile

    if (empty($CFG->messaging) and
        $PAGE->url->compare(new moodle_url('/user/view.php'), URL_MATCH_BASE)) {
        $userid = optional_param('id', false, PARAM_INT);
        if (local_mail_valid_recipient($userid)) {
            $vars = array('course' => $COURSE->id, 'recipient' => $userid);
            $PAGE->requires->string_for_js('sendmessage', 'local_mail');
            $PAGE->requires->js_init_code('M.local_mail = ' . json_encode($vars));
            $PAGE->requires->js('/local/mail/user.js');
        }
    }

    // Users list

    if (empty($CFG->messaging) and
        $PAGE->url->compare(new moodle_url('/user/index.php'), URL_MATCH_BASE)) {
        $userid = optional_param('id', false, PARAM_INT);
        $vars = array('course' => $COURSE->id);
        $PAGE->requires->string_for_js('choosedots', 'moodle');
        $PAGE->requires->strings_for_js(array(
                'bulkmessage',
                'to',
                'cc',
                'bcc',
                ), 'local_mail');
        $PAGE->requires->js_init_code('M.local_mail = ' . json_encode($vars));
        $PAGE->requires->js('/local/mail/users.js');
    }

    // Block progress

    if ($PAGE->url->compare(new moodle_url('/blocks/progress/overview.php'), URL_MATCH_BASE)) {
        $userid = optional_param('id', false, PARAM_INT);
        $vars = array('course' => $COURSE->id);
        $PAGE->requires->string_for_js('choosedots', 'moodle');
        $PAGE->requires->strings_for_js(array(
                'bulkmessage',
                'to',
                'cc',
                'bcc',
                ), 'local_mail');
        $PAGE->requires->js_init_code('M.local_mail = ' . json_encode($vars));
        $PAGE->requires->js('/local/mail/users.js');
    }
}
Ejemplo n.º 24
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.º 25
0
 public function get_content()
 {
     global $DB, $USER, $CFG, $COURSE, $PAGE;
     if ($this->content !== null) {
         //si el contenido ya esta generado, no se genera una 2da vez
         return $this->content;
     }
     block_settings::$navcount++;
     $this->content = new stdClass();
     if (!isloggedin()) {
         // si no esta conectado, el bloque no se muestra
         $this->content->text = '';
         return $this->content;
     }
     $root = navigation_node::create("UAI", null, navigation_node::TYPE_ROOTNODE, null, null);
     if ($nodereservasalas = $this->reserva_salas()) {
         $root->add_node($nodereservasalas);
     }
     if ($nodeasistencias = $this->asistencias()) {
         $root->add_node($nodeasistencias);
     }
     if ($nodeprintorders = $this->print_orders()) {
         $root->add_node($nodeprintorders);
     }
     if ($nodeemarking = $this->emarking()) {
         $root->add_node($nodeemarking);
     }
     if ($nodefacebook = $this->facebook()) {
         $root->add_node($nodefacebook);
     }
     if ($nodereportes = $this->reportes()) {
         $root->add_node($nodereportes);
     }
     if ($nodetoolbox = $this->toolbox()) {
         $root->add_node($nodetoolbox);
     }
     if ($nodepaperattendance = $this->paperattendance()) {
         $root->add_node($nodepaperattendance);
     }
     $renderer = $this->page->get_renderer('block_uai');
     $this->content->text = $renderer->uai_tree($root);
     $this->content->footer = '';
     return $this->content;
 }
Ejemplo n.º 26
0
 /**
  * Get the list of categories leading to this course.
  *
  * This function is used by {@link navbar::get_items()} to add back the "courses"
  * node and category chain leading to the current course.  Note that this is only ever
  * called for the current course, so we don't need to bother taking in any parameters.
  *
  * @return array
  */
 private function get_course_categories()
 {
     $categories = array();
     foreach ($this->page->categories as $category) {
         $url = new moodle_url('/course/index.php', array('categoryid' => $category->id));
         $name = format_string($category->name, true, array('context' => context_coursecat::instance($category->id)));
         $categories[] = navigation_node::create($name, $url, self::TYPE_CATEGORY, null, $category->id);
         $id = $category->parent;
     }
     if (is_enrolled(context_course::instance($this->page->course->id))) {
         $courses = $this->page->navigation->get('mycourses');
     } else {
         $courses = $this->page->navigation->get('courses');
     }
     if (!$courses) {
         // Courses node may not be present.
         $courses = navigation_node::create(get_string('courses'), new moodle_url('/course/index.php'), self::TYPE_CONTAINER);
     }
     $categories[] = $courses;
     return $categories;
 }
Ejemplo n.º 27
0
function lti_extend_settings_navigation($settings, $parentnode)
{
    global $PAGE;
    if (has_capability('mod/lti:manage', context_module::instance($PAGE->cm->id))) {
        $keys = $parentnode->get_children_key_list();
        $node = navigation_node::create('Submissions', new moodle_url('/mod/lti/grade.php', array('id' => $PAGE->cm->id)), navigation_node::TYPE_SETTING, null, 'mod_lti_submissions');
        $parentnode->add_node($node, $keys[1]);
    }
}
Ejemplo n.º 28
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.º 29
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.º 30
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);
}