本文整理汇总了PHP中user_can_assign函数的典型用法代码示例。如果您正苦于以下问题:PHP user_can_assign函数的具体用法?PHP user_can_assign怎么用?PHP user_can_assign使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了user_can_assign函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: print_error
print_error('invalidcourseid');
}
if (!($context = get_context_instance(CONTEXT_COURSE, $course->id))) {
print_error('invalidcontext');
}
require_login($course->id);
if ($course->metacourse) {
print_error('cantunenrollfrommetacourse', '', $CFG->wwwroot . '/course/view.php?id=' . $course->id);
}
if ($userid) {
// Unenrolling someone else
require_capability('moodle/role:assign', $context, NULL, false);
$roles = get_user_roles($context, $userid, false);
// verify user may unassign all roles at course context
foreach ($roles as $role) {
if (!user_can_assign($context, $role->roleid)) {
print_error('cannotunassignrolefrom', '', '', $role->roleid);
}
}
} else {
// Unenrol yourself
require_capability('moodle/role:unassignself', $context, NULL, false);
}
if (!empty($USER->access['rsw'][$context->path])) {
print_error('cantunenrollinthisrole', '', $CFG->wwwroot . '/course/view.php?id=' . $course->id);
}
if ($confirm and confirm_sesskey()) {
if ($userid) {
if (!role_unassign(0, $userid, 0, $context->id)) {
print_error("unenrolerror");
}
开发者ID:ajv,项目名称:Offline-Caching,代码行数:31,代码来源:unenrol.php
示例2: stdClass
}
if ($roleid > 0) {
$a = new stdClass();
$a->number = $totalcount;
$a->role = $rolenames[$roleid];
$heading = format_string(get_string('xuserswiththerole', 'role', $a));
if ($currentgroup and $group) {
$a->group = $group->name;
$heading .= ' ' . format_string(get_string('ingroup', 'role', $a));
}
if ($accesssince) {
$a->timeperiod = $timeoptions[$accesssince];
$heading .= ' ' . format_string(get_string('inactiveformorethan', 'role', $a));
}
$heading .= ": {$a->number}";
if (user_can_assign($context, $roleid)) {
$headingurl = new moodle_url($CFG->wwwroot . '/' . $CFG->admin . '/roles/assign.php', array('roleid' => $roleid, 'contextid' => $context->id));
$heading .= $OUTPUT->action_icon($headingurl, new pix_icon('t/edit', get_string('edit')));
}
echo $OUTPUT->heading($heading, 3);
} else {
if ($course->id != SITEID && has_capability('moodle/course:enrolreview', $context)) {
$editlink = $OUTPUT->action_icon(new moodle_url('/enrol/users.php', array('id' => $course->id)), new pix_icon('t/edit', get_string('edit')));
} else {
$editlink = '';
}
if ($course->id == SITEID and $roleid < 0) {
$strallparticipants = get_string('allsiteusers', 'role');
} else {
$strallparticipants = get_string('allparticipants');
}
开发者ID:educakanchay,项目名称:campus,代码行数:31,代码来源:index.php
示例3: test_get_assignable_roles
/**
* Test returning of assignable roles in context.
*/
public function test_get_assignable_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);
$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_assignable_roles($context, ROLENAME_SHORT);
foreach ($allroles as $roleid => $role) {
if (isset($roles[$roleid])) {
if (is_siteadmin()) {
$this->assertTrue($DB->record_exists('role_context_levels', array('contextlevel' => $context->contextlevel, 'roleid' => $roleid)));
} else {
$this->assertTrue(user_can_assign($context, $roleid), "u:{$user->id} r:{$roleid}");
}
$this->assertEquals($role->shortname, $roles[$roleid]);
} else {
$allowed = $DB->record_exists('role_context_levels', array('contextlevel' => $context->contextlevel, 'roleid' => $roleid));
if (is_siteadmin()) {
$this->assertFalse($allowed);
} else {
$this->assertFalse($allowed and user_can_assign($context, $roleid), "u:{$user->id}, r:{$allroles[$roleid]->name}, c:{$context->contextlevel}");
}
}
}
}
}
// Not-logged-in user.
$this->setUser(0);
foreach ($contexts as $contextid => $unused) {
$context = context_helper::instance_by_id($contextid);
$roles = get_assignable_roles($context, ROLENAME_SHORT);
$this->assertSame(array(), $roles);
}
// Test current user.
$this->setUser(0);
$admin = $DB->get_record('user', array('username' => 'admin'), '*', MUST_EXIST);
$roles1 = get_assignable_roles($coursecontext, ROLENAME_SHORT, false, $admin);
$roles2 = get_assignable_roles($coursecontext, ROLENAME_SHORT, false, $admin->id);
$this->setAdminUser();
$roles3 = get_assignable_roles($coursecontext, ROLENAME_SHORT);
$this->assertSame($roles1, $roles3);
$this->assertSame($roles2, $roles3);
// Test parameter defaults.
$this->setAdminUser();
$roles1 = get_assignable_roles($coursecontext);
$roles2 = get_assignable_roles($coursecontext, ROLENAME_ALIAS, false, $admin);
$this->assertEquals($roles2, $roles1);
// Verify returned names - let's allow all roles everywhere to simplify this a bit.
$alllevels = context_helper::get_all_levels();
$alllevels = array_keys($alllevels);
foreach ($allroles as $roleid => $role) {
set_role_contextlevels($roleid, $alllevels);
}
$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_assignable_roles($coursecontext, $type, false, $admin);
foreach ($roles as $roleid => $rolename) {
$this->assertSame($rolenames[$roleid]->localname, $rolename);
}
}
// Verify counts.
$alltypes = array(ROLENAME_ALIAS, ROLENAME_ALIAS_RAW, ROLENAME_BOTH, ROLENAME_ORIGINAL, ROLENAME_ORIGINALANDSHORT, ROLENAME_SHORT);
foreach ($alltypes as $type) {
$roles = get_assignable_roles($coursecontext, $type, false, $admin);
list($rolenames, $rolecounts, $nameswithcounts) = get_assignable_roles($coursecontext, $type, true, $admin);
$this->assertEquals($roles, $rolenames);
foreach ($rolenames as $roleid => $name) {
if ($roleid == $teacherrole->id or $roleid == $studentrole->id) {
$this->assertEquals(1, $rolecounts[$roleid]);
} else {
$this->assertEquals(0, $rolecounts[$roleid]);
}
$this->assertSame("{$name} ({$rolecounts[$roleid]})", $nameswithcounts[$roleid]);
}
}
}
开发者ID:sumitnegi933,项目名称:Moodle_lms_New,代码行数:96,代码来源:accesslib_test.php
示例4: require_capability
// to extend enrolments current user needs to be able to do role assignments
require_capability('moodle/role:assign', $context);
$today = time();
$today = make_timestamp(date('Y', $today), date('m', $today), date('d', $today), 0, 0, 0);
if (count($users) > 0 and $form = data_submitted() and confirm_sesskey()) {
if (count($form->userid) != count($form->extendperiod) || count($form->userid) != count($form->extendbase)) {
print_error('invalidformdata', '', $CFG->wwwroot . '/user/index.php?id=' . $id);
}
foreach ($form->userid as $k => $v) {
// find all roles this student have in this course
if ($students = $DB->get_records_sql("SELECT ra.id, ra.roleid, ra.timestart, ra.timeend\n FROM {role_assignments} ra\n WHERE userid = ?\n AND contextid = ?", array($v, $context->id))) {
// enrol these users again, with time extension
// not that this is not necessarily a student role
foreach ($students as $student) {
// only extend if the user can make role assignments on this role
if (user_can_assign($context, $student->roleid)) {
switch ($form->extendperiod[$k]) {
case 0:
// No change
break;
case -1:
// unlimited
$student->timeend = 0;
break;
default:
// extend
switch ($form->extendbase[$k]) {
case 0:
// course start date
$student->timeend = $course->startdate + $form->extendperiod[$k];
break;
开发者ID:nicolasconnault,项目名称:moodle2.0,代码行数:31,代码来源:extendenrol.php
示例5: process_unassignment
protected function process_unassignment($data)
{
$context = $this->get_context();
if (!user_can_assign($context, $data->role)) {
print_error('nopermissions', 'error');
}
foreach ($data->_selection as $user) {
role_unassign($data->role, cm_get_moodleuserid($user), 0, $context->id);
}
$tmppage = $this->get_basepage();
redirect($tmppage->get_url(), get_string('users_removed_from_role', 'block_curr_admin', count($data->_selection)));
}
开发者ID:remotelearner,项目名称:elis.cm,代码行数:12,代码来源:rolepage.class.php
示例6: get_assignable_roles
/**
* Gets a list of roles that this user can assign in this context
* @param object $context
* @return array
*/
function get_assignable_roles($context, $field = "name")
{
$options = array();
if ($roles = get_all_roles()) {
foreach ($roles as $role) {
if (user_can_assign($context, $role->id)) {
$options[$role->id] = strip_tags(format_string($role->{$field}, true));
}
}
}
return $options;
}
开发者ID:veritech,项目名称:pare-project,代码行数:17,代码来源:accesslib.php
示例7: notify
notify(get_string('coursegroupunknown', 'error', $addgroup[$i]));
} else {
if ($gid = groups_get_group_by_name($course[$i]->id, $addgroup[$i])) {
$groupid[$i] = $gid;
} else {
notify(get_string('groupunknown', 'error', $addgroup[$i]));
}
}
}
}
for ($i = 0; $i < 5; $i++) {
/// Enrol into courses if necessary
if ($course[$i]) {
if (isset($addrole[$i])) {
$coursecontext = get_context_instance(CONTEXT_COURSE, $course[$i]->id);
if (!user_can_assign($coursecontext, $addrole[$i])) {
notify('--> Can not assign role in course');
//TODO: localize
}
$ret = role_assign($addrole[$i], $user->id, 0, $coursecontext->id);
} else {
if (isset($addtype[$i])) {
switch ($addtype[$i]) {
case 2:
// teacher
$ret = add_teacher($user->id, $course[$i]->id, 1);
break;
case 3:
// non-editing teacher
$ret = add_teacher($user->id, $course[$i]->id, 0);
break;
开发者ID:veritech,项目名称:pare-project,代码行数:31,代码来源:uploaduser.php
注:本文中的user_can_assign函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论