本文整理汇总了PHP中get_overridable_roles函数的典型用法代码示例。如果您正苦于以下问题:PHP get_overridable_roles函数的具体用法?PHP get_overridable_roles怎么用?PHP get_overridable_roles使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_overridable_roles函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: load_category_settings
/**
* Loads category specific settings in the navigation
*
* @return navigation_node
*/
protected function load_category_settings()
{
global $CFG;
$categorynode = $this->add(print_context_name($this->context), null, null, null, 'categorysettings');
$categorynode->force_open();
if (has_any_capability(array('moodle/category:manage', 'moodle/course:create'), $this->context)) {
$url = new moodle_url('/course/category.php', array('id' => $this->context->instanceid, 'sesskey' => sesskey()));
if ($this->page->user_is_editing()) {
$url->param('categoryedit', '0');
$editstring = get_string('turneditingoff');
} else {
$url->param('categoryedit', '1');
$editstring = get_string('turneditingon');
}
$categorynode->add($editstring, $url, self::TYPE_SETTING, null, null, new pix_icon('i/edit', ''));
}
if ($this->page->user_is_editing() && has_capability('moodle/category:manage', $this->context)) {
$editurl = new moodle_url('/course/editcategory.php', array('id' => $this->context->instanceid));
$categorynode->add(get_string('editcategorythis'), $editurl, self::TYPE_SETTING, null, 'edit', new pix_icon('i/edit', ''));
$addsubcaturl = new moodle_url('/course/editcategory.php', array('parent' => $this->context->instanceid));
$categorynode->add(get_string('addsubcategory'), $addsubcaturl, self::TYPE_SETTING, null, 'addsubcat', new pix_icon('i/withsubcat', ''));
}
// Assign local roles
if (has_capability('moodle/role:assign', $this->context)) {
$assignurl = new moodle_url('/' . $CFG->admin . '/roles/assign.php', array('contextid' => $this->context->id));
$categorynode->add(get_string('assignroles', 'role'), $assignurl, self::TYPE_SETTING, null, 'roles', new pix_icon('i/roles', ''));
}
// Override roles
if (has_capability('moodle/role:review', $this->context) or count(get_overridable_roles($this->context)) > 0) {
$url = new moodle_url('/' . $CFG->admin . '/roles/permissions.php', array('contextid' => $this->context->id));
$categorynode->add(get_string('permissions', 'role'), $url, self::TYPE_SETTING, null, 'permissions', new pix_icon('i/permissions', ''));
}
// Check role permissions
if (has_any_capability(array('moodle/role:assign', 'moodle/role:safeoverride', 'moodle/role:override', 'moodle/role:assign'), $this->context)) {
$url = new moodle_url('/' . $CFG->admin . '/roles/check.php', array('contextid' => $this->context->id));
$categorynode->add(get_string('checkpermissions', 'role'), $url, self::TYPE_SETTING, null, 'checkpermissions', new pix_icon('i/checkpermissions', ''));
}
// Cohorts
if (has_capability('moodle/cohort:manage', $this->context) or has_capability('moodle/cohort:view', $this->context)) {
$categorynode->add(get_string('cohorts', 'cohort'), new moodle_url('/cohort/index.php', array('contextid' => $this->context->id)), self::TYPE_SETTING, null, 'cohort', new pix_icon('i/cohort', ''));
}
// Manage filters
if (has_capability('moodle/filter:manage', $this->context) && count(filter_get_available_in_context($this->context)) > 0) {
$url = new moodle_url('/filter/manage.php', array('contextid' => $this->context->id));
$categorynode->add(get_string('filters', 'admin'), $url, self::TYPE_SETTING, null, 'filters', new pix_icon('i/filter', ''));
}
return $categorynode;
}
示例2: load_category_settings
/**
* Loads category specific settings in the navigation
*
* @return navigation_node
*/
protected function load_category_settings()
{
global $CFG;
// We can land here while being in the context of a block, in which case we
// should get the parent context which should be the category one. See self::initialise().
if ($this->context->contextlevel == CONTEXT_BLOCK) {
$catcontext = $this->context->get_parent_context();
} else {
$catcontext = $this->context;
}
// Let's make sure that we always have the right context when getting here.
if ($catcontext->contextlevel != CONTEXT_COURSECAT) {
throw new coding_exception('Unexpected context while loading category settings.');
}
$categorynode = $this->add($catcontext->get_context_name(), null, null, null, 'categorysettings');
$categorynode->nodetype = navigation_node::NODETYPE_BRANCH;
$categorynode->force_open();
if (can_edit_in_category($catcontext->instanceid)) {
$url = new moodle_url('/course/management.php', array('categoryid' => $catcontext->instanceid));
$editstring = get_string('managecategorythis');
$categorynode->add($editstring, $url, self::TYPE_SETTING, null, null, new pix_icon('i/edit', ''));
}
if (has_capability('moodle/category:manage', $catcontext)) {
$editurl = new moodle_url('/course/editcategory.php', array('id' => $catcontext->instanceid));
$categorynode->add(get_string('editcategorythis'), $editurl, self::TYPE_SETTING, null, 'edit', new pix_icon('i/edit', ''));
$addsubcaturl = new moodle_url('/course/editcategory.php', array('parent' => $catcontext->instanceid));
$categorynode->add(get_string('addsubcategory'), $addsubcaturl, self::TYPE_SETTING, null, 'addsubcat', new pix_icon('i/withsubcat', ''));
}
// Assign local roles
$assignableroles = get_assignable_roles($catcontext);
if (!empty($assignableroles)) {
$assignurl = new moodle_url('/' . $CFG->admin . '/roles/assign.php', array('contextid' => $catcontext->id));
$categorynode->add(get_string('assignroles', 'role'), $assignurl, self::TYPE_SETTING, null, 'roles', new pix_icon('i/assignroles', ''));
}
// Override roles
if (has_capability('moodle/role:review', $catcontext) or count(get_overridable_roles($catcontext)) > 0) {
$url = new moodle_url('/' . $CFG->admin . '/roles/permissions.php', array('contextid' => $catcontext->id));
$categorynode->add(get_string('permissions', 'role'), $url, self::TYPE_SETTING, null, 'permissions', new pix_icon('i/permissions', ''));
}
// Check role permissions
if (has_any_capability(array('moodle/role:assign', 'moodle/role:safeoverride', 'moodle/role:override', 'moodle/role:assign'), $catcontext)) {
$url = new moodle_url('/' . $CFG->admin . '/roles/check.php', array('contextid' => $catcontext->id));
$categorynode->add(get_string('checkpermissions', 'role'), $url, self::TYPE_SETTING, null, 'checkpermissions', new pix_icon('i/checkpermissions', ''));
}
// Cohorts
if (has_any_capability(array('moodle/cohort:view', 'moodle/cohort:manage'), $catcontext)) {
$categorynode->add(get_string('cohorts', 'cohort'), new moodle_url('/cohort/index.php', array('contextid' => $catcontext->id)), self::TYPE_SETTING, null, 'cohort', new pix_icon('i/cohort', ''));
}
// Manage filters
if (has_capability('moodle/filter:manage', $catcontext) && count(filter_get_available_in_context($catcontext)) > 0) {
$url = new moodle_url('/filter/manage.php', array('contextid' => $catcontext->id));
$categorynode->add(get_string('filters', 'admin'), $url, self::TYPE_SETTING, null, 'filters', new pix_icon('i/filter', ''));
}
// Restore.
if (has_capability('moodle/restore:restorecourse', $catcontext)) {
$url = new moodle_url('/backup/restorefile.php', array('contextid' => $catcontext->id));
$categorynode->add(get_string('restorecourse', 'admin'), $url, self::TYPE_SETTING, null, 'restorecourse', new pix_icon('i/restore', ''));
}
// Let plugins hook into category settings navigation.
$pluginsfunction = get_plugins_with_function('extend_navigation_category_settings', 'lib.php');
foreach ($pluginsfunction as $plugintype => $plugins) {
foreach ($plugins as $pluginfunction) {
$pluginfunction($categorynode, $catcontext);
}
}
return $categorynode;
}
示例3: error
}
} else {
if (!empty($courseid)) {
// we need this for user tabs in user context
if (!($course = get_record('course', 'id', $courseid))) {
error('Invalid course id');
}
} else {
$courseid = SITEID;
$course = clone $SITE;
}
}
require_login($course);
require_capability('moodle/role:assign', $context);
/// needed for tabs.php
$overridableroles = get_overridable_roles($context, 'name', ROLENAME_BOTH);
$assignableroles = get_assignable_roles($context, 'name', ROLENAME_BOTH);
/// Get some language strings
$strpotentialusers = get_string('potentialusers', 'role');
$strexistingusers = get_string('existingusers', 'role');
$straction = get_string('assignroles', 'role');
$strroletoassign = get_string('roletoassign', 'role');
$strsearch = get_string('search');
$strshowall = get_string('showall');
$strparticipants = get_string('participants');
$strsearchresults = get_string('searchresults');
$unlimitedperiod = get_string('unlimited');
$defaultperiod = $course->enrolperiod;
for ($i = 1; $i <= 365; $i++) {
$seconds = $i * 86400;
$periodmenu[$seconds] = get_string('numdays', '', $i);
示例4: require_login
$courseid = SITEID;
$coursecontext = $context;
}
require_login($course);
$baseurl = 'override.php?contextid=' . $context->id;
if (!empty($userid)) {
$baseurl .= '&userid=' . $userid;
}
if ($courseid != SITEID) {
$baseurl .= '&courseid=' . $courseid;
}
if ($cancel) {
redirect($baseurl);
}
/// needed for tabs.php
$overridableroles = get_overridable_roles($context);
$assignableroles = get_assignable_roles($context);
/// Get some language strings
$strroletooverride = get_string('roletooverride', 'role');
$straction = get_string('overrideroles', 'role');
$strcurrentrole = get_string('currentrole', 'role');
$strparticipants = get_string('participants');
/// Make sure this user can override that role
if ($roleid) {
if (!user_can_override($context, $roleid)) {
error('you can not override this role in this context');
}
}
if ($userid) {
$user = get_record('user', 'id', $userid);
$fullname = fullname($user, has_capability('moodle/site:viewfullnames', $context));
示例5: require_capability
if ($safeoverridesonly) {
require_capability('moodle/role:safeoverride', $context);
}
/// Handle the cancel button.
if (optional_param('cancel', false, PARAM_BOOL)) {
redirect($baseurl);
}
/// Handle the toggle advanced mode button.
$showadvanced = get_user_preferences('overridepermissions_showadvanced', false);
if (optional_param('toggleadvanced', false, PARAM_BOOL)) {
$showadvanced = !$showadvanced;
set_user_preference('overridepermissions_showadvanced', $showadvanced);
}
/// These are needed early because of tabs.php
$assignableroles = get_assignable_roles($context, ROLENAME_BOTH);
list($overridableroles, $overridecounts, $nameswithcounts) = get_overridable_roles($context, ROLENAME_BOTH, true);
/// Make sure this user can override that role
if ($roleid && !isset($overridableroles[$roleid])) {
$a = new stdClass();
$a->roleid = $roleid;
$a->context = $contextname;
print_error('cannotoverriderolehere', '', get_context_url($context), $a);
}
/// If we are actually overriding a role, create the table object, and save changes if appropriate.
if ($roleid) {
if ($showadvanced) {
$overridestable = new override_permissions_table_advanced($context, $roleid, $safeoverridesonly);
} else {
$overridestable = new override_permissions_table_basic($context, $roleid, $safeoverridesonly);
}
$overridestable->read_submitted_permissions();
示例6: array
$contexts[$conid]->roleassignments = array();
}
/// Put the contexts into a tree structure.
foreach ($contexts as $conid => $con) {
$context = context::instance_by_id($conid);
$parentcontextid = get_parent_contextid($context);
if ($parentcontextid) {
$contexts[$parentcontextid]->children[] = $conid;
}
}
/// Put the role capabilities into the context tree.
foreach ($roleassignments as $ra) {
$contexts[$ra->contextid]->roleassignments[$ra->roleid] = $ra;
}
$assignableroles = get_assignable_roles($usercontext, ROLENAME_BOTH);
$overridableroles = get_overridable_roles($usercontext, ROLENAME_BOTH);
/// Print the header
$fullname = fullname($user, has_capability('moodle/site:viewfullnames', $coursecontext));
$straction = get_string('thisusersroles', 'role');
$title = get_string('xroleassignments', 'role', $fullname);
/// Course header
$PAGE->set_title($title);
if ($courseid != SITEID) {
$PAGE->set_heading($fullname);
} else {
$PAGE->set_heading($course->fullname);
}
echo $OUTPUT->header();
echo $OUTPUT->heading($title, 3);
echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthnormal');
// Display them.
示例7: test_get_overridable_roles
/**
* Test getting of all overridable roles.
*/
public function test_get_overridable_roles()
{
global $DB;
$this->resetAfterTest();
$course = $this->getDataGenerator()->create_course();
$coursecontext = context_course::instance($course->id);
$teacherrole = $DB->get_record('role', array('shortname' => 'editingteacher'), '*', MUST_EXIST);
$teacher = $this->getDataGenerator()->create_user();
role_assign($teacherrole->id, $teacher->id, $coursecontext);
$teacherename = (object) array('roleid' => $teacherrole->id, 'name' => 'Učitel', 'contextid' => $coursecontext->id);
$DB->insert_record('role_names', $teacherename);
$this->assertTrue($DB->record_exists('capabilities', array('name' => 'moodle/backup:backupcourse')));
// Any capability is ok.
assign_capability('moodle/backup:backupcourse', CAP_PROHIBIT, $teacherrole->id, $coursecontext->id);
$studentrole = $DB->get_record('role', array('shortname' => 'student'), '*', MUST_EXIST);
$student = $this->getDataGenerator()->create_user();
role_assign($studentrole->id, $student->id, $coursecontext);
$contexts = $DB->get_records('context');
$users = $DB->get_records('user');
$allroles = $DB->get_records('role');
// Evaluate all results for all users in all contexts.
foreach ($users as $user) {
$this->setUser($user);
foreach ($contexts as $contextid => $unused) {
$context = context_helper::instance_by_id($contextid);
$roles = get_overridable_roles($context, ROLENAME_SHORT);
foreach ($allroles as $roleid => $role) {
$hascap = has_any_capability(array('moodle/role:safeoverride', 'moodle/role:override'), $context);
if (is_siteadmin()) {
$this->assertTrue(isset($roles[$roleid]));
} else {
$parents = $context->get_parent_context_ids(true);
$pcontexts = implode(',', $parents);
$allowed = $DB->record_exists_sql("SELECT r.id\n FROM {role} r\n JOIN {role_allow_override} rao ON r.id = rao.allowoverride\n JOIN {role_assignments} ra ON rao.roleid = ra.roleid\n WHERE ra.userid = :userid AND ra.contextid IN ({$pcontexts}) AND r.id = :roleid\n ", array('userid' => $user->id, 'roleid' => $roleid));
if (isset($roles[$roleid])) {
$this->assertTrue($hascap);
$this->assertTrue($allowed);
} else {
$this->assertFalse($hascap and $allowed);
}
}
if (isset($roles[$roleid])) {
$this->assertEquals($role->shortname, $roles[$roleid]);
}
}
}
}
// Test parameter defaults.
$this->setAdminUser();
$roles1 = get_overridable_roles($coursecontext);
$roles2 = get_overridable_roles($coursecontext, ROLENAME_ALIAS, false);
$this->assertEquals($roles2, $roles1);
$alltypes = array(ROLENAME_ALIAS, ROLENAME_ALIAS_RAW, ROLENAME_BOTH, ROLENAME_ORIGINAL, ROLENAME_ORIGINALANDSHORT, ROLENAME_SHORT);
foreach ($alltypes as $type) {
$rolenames = role_fix_names($allroles, $coursecontext, $type);
$roles = get_overridable_roles($coursecontext, $type, false);
foreach ($roles as $roleid => $rolename) {
$this->assertSame($rolenames[$roleid]->localname, $rolename);
}
}
// Verify counts.
$roles = get_overridable_roles($coursecontext, ROLENAME_ALIAS, false);
list($rolenames, $rolecounts, $nameswithcounts) = get_overridable_roles($coursecontext, ROLENAME_ALIAS, true);
$this->assertEquals($roles, $rolenames);
foreach ($rolenames as $roleid => $name) {
if ($roleid == $teacherrole->id) {
$this->assertEquals(1, $rolecounts[$roleid]);
} else {
$this->assertEquals(0, $rolecounts[$roleid]);
}
$this->assertSame("{$name} ({$rolecounts[$roleid]})", $nameswithcounts[$roleid]);
}
}
示例8: edit_controls
/**
* Get the appropriate list of editing icons for a block. This is used
* to set {@link block_contents::$controls} in {@link block_base::get_contents_for_output()}.
*
* @param $output The core_renderer to use when generating the output. (Need to get icon paths.)
* @return an array in the format for {@link block_contents::$controls}
*/
public function edit_controls($block)
{
global $CFG;
$controls = array();
$actionurl = $this->page->url->out(false, array('sesskey' => sesskey()));
$blocktitle = $block->title;
if (empty($blocktitle)) {
$blocktitle = $block->arialabel;
}
if ($this->page->user_can_edit_blocks()) {
// Move icon.
$str = new lang_string('moveblock', 'block', $blocktitle);
$controls[] = new action_menu_link_primary(new moodle_url($actionurl, array('bui_moveid' => $block->instance->id)), new pix_icon('t/move', $str, 'moodle', array('class' => 'iconsmall', 'title' => '')), $str, array('class' => 'editing_move'));
}
if ($this->page->user_can_edit_blocks() || $block->user_can_edit()) {
// Edit config icon - always show - needed for positioning UI.
$str = new lang_string('configureblock', 'block', $blocktitle);
$controls[] = new action_menu_link_secondary(new moodle_url($actionurl, array('bui_editid' => $block->instance->id)), new pix_icon('t/edit', $str, 'moodle', array('class' => 'iconsmall', 'title' => '')), $str, array('class' => 'editing_edit'));
}
if ($this->page->user_can_edit_blocks() && $block->instance_can_be_hidden()) {
// Show/hide icon.
if ($block->instance->visible) {
$str = new lang_string('hideblock', 'block', $blocktitle);
$url = new moodle_url($actionurl, array('bui_hideid' => $block->instance->id));
$icon = new pix_icon('t/hide', $str, 'moodle', array('class' => 'iconsmall', 'title' => ''));
$attributes = array('class' => 'editing_hide');
} else {
$str = new lang_string('showblock', 'block', $blocktitle);
$url = new moodle_url($actionurl, array('bui_showid' => $block->instance->id));
$icon = new pix_icon('t/show', $str, 'moodle', array('class' => 'iconsmall', 'title' => ''));
$attributes = array('class' => 'editing_show');
}
$controls[] = new action_menu_link_secondary($url, $icon, $str, $attributes);
}
// Display either "Assign roles" or "Permissions" or "Change permissions" icon (whichever first is available).
$rolesurl = null;
if (get_assignable_roles($block->context, ROLENAME_SHORT)) {
$rolesurl = new moodle_url('/admin/roles/assign.php', array('contextid' => $block->context->id));
$str = new lang_string('assignrolesinblock', 'block', $blocktitle);
$icon = 'i/assignroles';
} else {
if (has_capability('moodle/role:review', $block->context) or get_overridable_roles($block->context)) {
$rolesurl = new moodle_url('/admin/roles/permissions.php', array('contextid' => $block->context->id));
$str = get_string('permissions', 'role');
$icon = 'i/permissions';
} else {
if (has_any_capability(array('moodle/role:safeoverride', 'moodle/role:override', 'moodle/role:assign'), $block->context)) {
$rolesurl = new moodle_url('/admin/roles/check.php', array('contextid' => $block->context->id));
$str = get_string('checkpermissions', 'role');
$icon = 'i/checkpermissions';
}
}
}
if ($rolesurl) {
// TODO: please note it is sloppy to pass urls through page parameters!!
// it is shortened because some web servers (e.g. IIS by default) give
// a 'security' error if you try to pass a full URL as a GET parameter in another URL.
$return = $this->page->url->out(false);
$return = str_replace($CFG->wwwroot . '/', '', $return);
$rolesurl->param('returnurl', $return);
$controls[] = new action_menu_link_secondary($rolesurl, new pix_icon($icon, $str, 'moodle', array('class' => 'iconsmall', 'title' => '')), $str, array('class' => 'editing_roles'));
}
if ($this->user_can_delete_block($block)) {
// Delete icon.
$str = new lang_string('deleteblock', 'block', $blocktitle);
$controls[] = new action_menu_link_secondary(new moodle_url($actionurl, array('bui_deleteid' => $block->instance->id)), new pix_icon('t/delete', $str, 'moodle', array('class' => 'iconsmall', 'title' => '')), $str, array('class' => 'editing_delete'));
}
return $controls;
}
示例9: get_content
function get_content()
{
global $CFG, $USER, $SITE, $COURSE;
if ($this->content !== NULL) {
return $this->content;
}
$this->content = new stdClass();
$this->content->items = array();
$this->content->icons = array();
$this->content->footer = '';
if (empty($this->instance->pageid)) {
// sticky
if (!empty($COURSE)) {
$this->instance->pageid = $COURSE->id;
}
}
if (empty($this->instance)) {
return $this->content = '';
} else {
if ($this->instance->pageid == SITEID) {
// return $this->content = '';
}
}
if (!empty($this->instance->pageid)) {
$context = get_context_instance(CONTEXT_COURSE, $this->instance->pageid);
if ($COURSE->id == $this->instance->pageid) {
$course = $COURSE;
} else {
$course = get_record('course', 'id', $this->instance->pageid);
}
} else {
$context = get_context_instance(CONTEXT_SYSTEM);
$course = $SITE;
}
if (!has_capability('moodle/course:view', $context)) {
// Just return
return $this->content;
}
if (empty($CFG->loginhttps)) {
$securewwwroot = $CFG->wwwroot;
} else {
$securewwwroot = str_replace('http:', 'https:', $CFG->wwwroot);
}
/// Course editing on/off
if ($course->id !== SITEID and has_capability('moodle/course:update', $context)) {
$this->content->icons[] = '<img src="' . $CFG->pixpath . '/i/edit.gif" class="icon" alt="" />';
if (isediting($this->instance->pageid)) {
$this->content->items[] = '<a href="view.php?id=' . $this->instance->pageid . '&edit=off&sesskey=' . sesskey() . '">' . get_string('turneditingoff') . '</a>';
} else {
$this->content->items[] = '<a href="view.php?id=' . $this->instance->pageid . '&edit=on&sesskey=' . sesskey() . '">' . get_string('turneditingon') . '</a>';
}
$this->content->items[] = '<a href="' . $CFG->wwwroot . '/course/edit.php?id=' . $this->instance->pageid . '">' . get_string('settings') . '</a>';
$this->content->icons[] = '<img src="' . $CFG->pixpath . '/i/settings.gif" class="icon" alt="" />';
}
/// Assign roles to the course
if ($course->id != SITEID) {
if (has_capability('moodle/role:assign', $context)) {
$this->content->items[] = '<a href="' . $CFG->wwwroot . '/' . $CFG->admin . '/roles/assign.php?contextid=' . $context->id . '">' . get_string('assignroles', 'role') . '</a>';
$this->content->icons[] = '<img src="' . $CFG->pixpath . '/i/roles.gif" class="icon" alt="" />';
} else {
if (get_overridable_roles($context, 'name', ROLENAME_ORIGINAL)) {
$this->content->items[] = '<a href="' . $CFG->wwwroot . '/' . $CFG->admin . '/roles/override.php?contextid=' . $context->id . '">' . get_string('overridepermissions', 'role') . '</a>';
$this->content->icons[] = '<img src="' . $CFG->pixpath . '/i/roles.gif" class="icon" alt="" />';
}
}
}
/// View course grades (or just your own grades, same link)
/// find all accessible reports
if ($course->id !== SITEID) {
$reportavailable = false;
if (has_capability('moodle/grade:viewall', $context)) {
$reportavailable = true;
} else {
if (!empty($course->showgrades)) {
if ($reports = get_list_of_plugins('grade/report')) {
// Get all installed reports
arsort($reports);
// user is last, we want to test it first
foreach ($reports as $plugin) {
if (has_capability('gradereport/' . $plugin . ':view', $context)) {
//stop when the first visible plugin is found
$reportavailable = true;
break;
}
}
}
}
}
if ($reportavailable) {
$this->content->items[] = '<a href="' . $CFG->wwwroot . '/grade/report/index.php?id=' . $this->instance->pageid . '">' . get_string('grades') . '</a>';
$this->content->icons[] = '<img src="' . $CFG->pixpath . '/i/grades.gif" class="icon" alt="" />';
}
}
/// Course outcomes (to help give it more prominence because it's important)
if (!empty($CFG->enableoutcomes)) {
if ($course->id !== SITEID and has_capability('moodle/course:update', $context)) {
$this->content->items[] = '<a href="' . $CFG->wwwroot . '/grade/edit/outcome/course.php?id=' . $this->instance->pageid . '">' . get_string('outcomes', 'grades') . '</a>';
$this->content->icons[] = '<img src="' . $CFG->pixpath . '/i/outcomes.gif" class="icon" alt="" />';
}
}
//.........这里部分代码省略.........
示例10: edit_controls
/**
* Get the appropriate list of editing icons for a block. This is used
* to set {@link block_contents::$controls} in {@link block_base::get_contents_for_output()}.
*
* @param $output The core_renderer to use when generating the output. (Need to get icon paths.)
* @return an array in the format for {@link block_contents::$controls}
*/
public function edit_controls($block)
{
global $CFG;
$controls = array();
$actionurl = $this->page->url->out(false, array('sesskey' => sesskey()));
$blocktitle = $block->title;
if (empty($blocktitle)) {
$blocktitle = $block->arialabel;
}
if ($this->page->user_can_edit_blocks()) {
// Move icon.
$str = new lang_string('moveblock', 'block', $blocktitle);
$controls[] = new action_menu_link_primary(new moodle_url($actionurl, array('bui_moveid' => $block->instance->id)), new pix_icon('t/move', $str, 'moodle', array('class' => 'iconsmall', 'title' => '')), $str, array('class' => 'editing_move'));
}
if ($this->page->user_can_edit_blocks() || $block->user_can_edit()) {
// Edit config icon - always show - needed for positioning UI.
$str = new lang_string('configureblock', 'block', $blocktitle);
$controls[] = new action_menu_link_secondary(new moodle_url($actionurl, array('bui_editid' => $block->instance->id)), new pix_icon('t/edit', $str, 'moodle', array('class' => 'iconsmall', 'title' => '')), $str, array('class' => 'editing_edit'));
}
if ($this->page->user_can_edit_blocks() && $block->instance_can_be_hidden()) {
// Show/hide icon.
if ($block->instance->visible) {
$str = new lang_string('hideblock', 'block', $blocktitle);
$url = new moodle_url($actionurl, array('bui_hideid' => $block->instance->id));
$icon = new pix_icon('t/hide', $str, 'moodle', array('class' => 'iconsmall', 'title' => ''));
$attributes = array('class' => 'editing_hide');
} else {
$str = new lang_string('showblock', 'block', $blocktitle);
$url = new moodle_url($actionurl, array('bui_showid' => $block->instance->id));
$icon = new pix_icon('t/show', $str, 'moodle', array('class' => 'iconsmall', 'title' => ''));
$attributes = array('class' => 'editing_show');
}
$controls[] = new action_menu_link_secondary($url, $icon, $str, $attributes);
}
// Assign roles.
if (get_assignable_roles($block->context, ROLENAME_SHORT)) {
$rolesurl = new moodle_url('/admin/roles/assign.php', array('contextid' => $block->context->id, 'returnurl' => $this->page->url->out_as_local_url()));
$str = new lang_string('assignrolesinblock', 'block', $blocktitle);
$controls[] = new action_menu_link_secondary($rolesurl, new pix_icon('i/assignroles', $str, 'moodle', array('class' => 'iconsmall', 'title' => '')), $str, array('class' => 'editing_assignroles'));
}
// Permissions.
if (has_capability('moodle/role:review', $block->context) or get_overridable_roles($block->context)) {
$rolesurl = new moodle_url('/admin/roles/permissions.php', array('contextid' => $block->context->id, 'returnurl' => $this->page->url->out_as_local_url()));
$str = get_string('permissions', 'role');
$controls[] = new action_menu_link_secondary($rolesurl, new pix_icon('i/permissions', $str, 'moodle', array('class' => 'iconsmall', 'title' => '')), $str, array('class' => 'editing_permissions'));
}
// Change permissions.
if (has_any_capability(array('moodle/role:safeoverride', 'moodle/role:override', 'moodle/role:assign'), $block->context)) {
$rolesurl = new moodle_url('/admin/roles/check.php', array('contextid' => $block->context->id, 'returnurl' => $this->page->url->out_as_local_url()));
$str = get_string('checkpermissions', 'role');
$controls[] = new action_menu_link_secondary($rolesurl, new pix_icon('i/checkpermissions', $str, 'moodle', array('class' => 'iconsmall', 'title' => '')), $str, array('class' => 'editing_checkroles'));
}
if ($this->user_can_delete_block($block)) {
// Delete icon.
$str = new lang_string('deleteblock', 'block', $blocktitle);
$controls[] = new action_menu_link_secondary(new moodle_url($actionurl, array('bui_deleteid' => $block->instance->id)), new pix_icon('t/delete', $str, 'moodle', array('class' => 'iconsmall', 'title' => '')), $str, array('class' => 'editing_delete'));
}
return $controls;
}