本文整理汇总了PHP中unassign_capability函数的典型用法代码示例。如果您正苦于以下问题:PHP unassign_capability函数的具体用法?PHP unassign_capability怎么用?PHP unassign_capability使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了unassign_capability函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: xmldb_block_demostudent_install
/**
* @package block
* @subpackage demostudent
* @author Dominik Royko [email protected]
*/
function xmldb_block_demostudent_install()
{
global $DB;
$result = true;
$systemcontext = context_system::instance();
// Create DemoStudent role.
$contextlevels = array(CONTEXT_COURSE, CONTEXT_MODULE);
if (!($demostudentrole = $DB->get_record('role', array('shortname' => 'demostudent')))) {
if ($roleid = create_role(get_string('roledemostudentname', 'block_demostudent'), 'demostudent', get_string('roledemostudentdescription', 'block_demostudent'), 'student')) {
$newrole = new stdClass();
$newrole->id = $roleid;
// Set the capabilities to the archetype (student).
// Caution: new capabilities un/set here can get clobbered by 'clonepermissionsfrom',
// defined in access.php.
reset_role_capabilities($roleid);
// DemoStudent needs to see the DemoStudent block.
$result = $result && assign_capability('block/demostudent:seedemostudentblock', CAP_ALLOW, $newrole->id, $systemcontext->id);
// DemoStudent should be able to see hidden courses to facilitate testing.
$result = $result && assign_capability('moodle/course:viewhiddencourses', CAP_ALLOW, $newrole->id, $systemcontext->id);
// DemoStudent should NOT be able to add more demostudents!
$result = $result && unassign_capability('block/demostudent:addinstance', $newrole->id);
$systemcontext->mark_dirty();
set_role_contextlevels($newrole->id, $contextlevels);
} else {
$result = false;
}
}
return $result;
}
开发者ID:MoodleMetaData,项目名称:MoodleMetaData,代码行数:34,代码来源:install.php
示例2: qcreate_student_q_access_sync
/**
* Called from cron and update_instance. Not called from add_instance as the contexts are not set up yet.
*/
function qcreate_student_q_access_sync($qcreate, $cmcontext = null, $course = null, $forcesync = false)
{
//check if a check is needed
$timenow = time();
$activityopen = ($qcreate->timeopen == 0 || $qcreate->timeopen < $timenow) && ($qcreate->timeclose == 0 || $qcreate->timeclose > $timenow);
$activitywasopen = ($qcreate->timeopen == 0 || $qcreate->timeopen < $qcreate->timesync) && ($qcreate->timeclose == 0 || $qcreate->timeclose > $qcreate->timesync);
$needsync = empty($qcreate->timesync) || $activitywasopen != $activityopen;
if ($forcesync || $needsync) {
if ($cmcontext == null) {
$cm = get_coursemodule_from_instance('qcreate', $qcreate->id);
$cmcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
}
if ($course == null) {
$course = get_record('course', 'id', $qcreate->course);
}
$studentrole = get_default_course_role($course);
if ($activityopen) {
$capabilitiestoassign = array(0 => array('moodle/question:add' => 1, 'moodle/question:usemine' => -1, 'moodle/question:viewmine' => -1, 'moodle/question:editmine' => -1), 1 => array('moodle/question:add' => 1, 'moodle/question:usemine' => 1, 'moodle/question:viewmine' => -1, 'moodle/question:editmine' => -1), 2 => array('moodle/question:add' => 1, 'moodle/question:usemine' => 1, 'moodle/question:viewmine' => 1, 'moodle/question:editmine' => -1), 3 => array('moodle/question:add' => 1, 'moodle/question:usemine' => 1, 'moodle/question:viewmine' => 1, 'moodle/question:editmine' => 1));
foreach ($capabilitiestoassign[$qcreate->studentqaccess] as $capability => $permission) {
assign_capability($capability, $permission, $studentrole->id, $cmcontext->id, true);
}
} else {
$capabilitiestounassign = array('moodle/question:add', 'moodle/question:usemine', 'moodle/question:viewmine', 'moodle/question:editmine');
foreach ($capabilitiestounassign as $capability) {
unassign_capability($capability, $studentrole->id, $cmcontext->id);
}
}
set_field('qcreate', 'timesync', $timenow, 'id', $qcreate->id);
}
}
开发者ID:hmatulis,项目名称:RTL-BIDI-Hebrew-Moodle-Plugins,代码行数:33,代码来源:lib.php
示例3: unassignUserCapability
/**
* Unassign a capability to $USER
*
* @param string $capability capability name
* @param int $contextid
* @param int $roleid
*/
public static function unassignUserCapability($capability, $contextid, $roleid) {
global $USER;
unassign_capability($capability, $roleid, $contextid);
accesslib_clear_all_caches_for_unit_testing();
}
开发者ID:JP-Git,项目名称:moodle,代码行数:14,代码来源:helpers.php
示例4: unassignUserCapability
/**
* Unassign a capability to $USER.
*
* @param string $capability capability name.
* @param int $contextid set the context id if you used assignUserCapability.
* @param int $roleid set the role id if you used assignUserCapability.
* @param int $courseid set the course id if you used getDataGenerator->enrol_users.
* @param string $enrol set the enrol plugin name if you used getDataGenerator->enrol_users with a different plugin than 'manual'.
*/
public static function unassignUserCapability($capability, $contextid = null, $roleid = null, $courseid = null, $enrol = 'manual')
{
global $DB;
if (!empty($courseid)) {
// Retrieve the role id.
$instances = $DB->get_records('enrol', array('courseid' => $courseid, 'enrol' => $enrol));
if (count($instances) != 1) {
throw new coding_exception('No found enrol instance for courseid: ' . $courseid . ' and enrol: ' . $enrol);
}
$instance = reset($instances);
if (is_null($roleid) and $instance->roleid) {
$roleid = $instance->roleid;
}
} else {
if (empty($contextid) or empty($roleid)) {
throw new coding_exception('unassignUserCapaibility requires contextid/roleid or courseid');
}
}
unassign_capability($capability, $roleid, $contextid);
accesslib_clear_all_caches_for_unit_testing();
}
开发者ID:evltuma,项目名称:moodle,代码行数:30,代码来源:helpers.php
示例5: setUp
public function setUp()
{
global $DB;
$this->resetAfterTest();
$this->course = self::getDataGenerator()->create_course();
$this->student1 = $this->getDataGenerator()->create_user();
$this->student2 = $this->getDataGenerator()->create_user();
$this->teacher1 = $this->getDataGenerator()->create_user();
$this->teacher2 = $this->getDataGenerator()->create_user();
$this->teacher3 = $this->getDataGenerator()->create_user();
$this->studentrole = $DB->get_record('role', array('shortname' => 'student'));
$this->teacherrole = $DB->get_record('role', array('shortname' => 'teacher'));
unassign_capability('moodle/site:accessallgroups', $this->teacherrole->id);
$this->getDataGenerator()->enrol_user($this->student1->id, $this->course->id, $this->studentrole->id);
$this->getDataGenerator()->enrol_user($this->student2->id, $this->course->id, $this->studentrole->id);
$this->getDataGenerator()->enrol_user($this->teacher1->id, $this->course->id, $this->teacherrole->id);
$this->getDataGenerator()->enrol_user($this->teacher2->id, $this->course->id, $this->teacherrole->id);
$this->getDataGenerator()->enrol_user($this->teacher3->id, $this->course->id, $this->teacherrole->id);
// Create the forum.
$record = new stdClass();
$record->introformat = FORMAT_HTML;
$record->course = $this->course->id;
// Set Aggregate type = Average of ratings.
$record->assessed = RATING_AGGREGATE_AVERAGE;
$record->scale = 100;
$this->forum = self::getDataGenerator()->create_module('forum', $record);
$this->contextid = context_module::instance($this->forum->cmid)->id;
// Add discussion to the forums.
$record = new stdClass();
$record->course = $this->course->id;
$record->userid = $this->student1->id;
$record->forum = $this->forum->id;
$this->discussion = self::getDataGenerator()->get_plugin_generator('mod_forum')->create_discussion($record);
// Retrieve the first post.
$this->post = $DB->get_record('forum_posts', array('discussion' => $this->discussion->id));
}
开发者ID:janeklb,项目名称:moodle,代码行数:36,代码来源:externallib_test.php
示例6: error
}
if (empty($errors)) {
// update normal role settings
$role->id = $roleid;
$role->name = $name;
$role->shortname = $shortname;
$role->description = $description;
if (!update_record('role', $role)) {
error('Could not update role!');
}
// set proper legacy type
foreach ($legacyroles as $ltype => $lcap) {
if ($ltype == $legacytype) {
assign_capability($lcap, CAP_ALLOW, $roleid, $sitecontext->id);
} else {
unassign_capability($lcap, $roleid);
}
}
// edited a role sitewide...
mark_context_dirty($sitecontext->path);
add_to_log(SITEID, 'role', 'edit', 'admin/roles/manage.php?action=edit&roleid=' . $role->id, $role->name, '', $USER->id);
redirect('manage.php');
}
// edited a role sitewide - with errors, but still...
mark_context_dirty($sitecontext->path);
}
break;
case 'delete':
if (in_array($roleid, $defaultroles)) {
error('This role is used as one of the default system roles, it can not be deleted');
}
开发者ID:r007,项目名称:PMoodle,代码行数:31,代码来源:manage.php
示例7: fn_sg_set_user_capability
/**
* Called from the settings form. Assigns or unassigns capabilities from Group Manager role.
* Assumes that this role exists, and that capabilities have numeric values 1 and 2 from form.
*
* @param $settingname
* @return unknown_type
*/
function fn_sg_set_user_capability($settingname)
{
global $CFG;
$context = get_system_context();
$role = get_record('role', 'shortname', FNGRPMANROLESNAME);
if ($settingname == 's__block_fn_site_groups_users') {
$capsset = explode(',', $CFG->block_fn_site_groups_users);
if (in_array(1, $capsset)) {
assign_capability('block/fn_site_groups:assignowngroupusers', CAP_ALLOW, $role->id, $context->id);
} else {
unassign_capability('block/fn_site_groups:assignowngroupusers', $role->id, $context->id);
}
if (in_array(2, $capsset)) {
assign_capability('block/fn_site_groups:assignallusers', CAP_ALLOW, $role->id, $context->id);
} else {
unassign_capability('block/fn_site_groups:assignallusers', $role->id, $context->id);
}
} else {
if ($settingname == 's__block_fn_site_groups_creategroups') {
if (!empty($CFG->block_fn_site_groups_creategroups)) {
assign_capability('block/fn_site_groups:createnewgroups', CAP_ALLOW, $role->id, $context->id);
} else {
unassign_capability('block/fn_site_groups:createnewgroups', $role->id, $context->id);
}
}
}
return true;
}
开发者ID:hmatulis,项目名称:RTL-BIDI-Hebrew-Moodle-Plugins,代码行数:35,代码来源:lib.php
示例8: xmldb_oublog_upgrade
function xmldb_oublog_upgrade($oldversion = 0)
{
global $CFG, $THEME, $db;
$result = true;
if ($result && $oldversion < 2008022600) {
/// Define field views to be added to oublog_instances
$table = new XMLDBTable('oublog_instances');
$field = new XMLDBField('views');
$field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'accesstoken');
/// Launch add field views
$result = $result && add_field($table, $field);
$table = new XMLDBTable('oublog');
$field = new XMLDBField('views');
$field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'global');
/// Launch add field views
$result = $result && add_field($table, $field);
}
if ($result && $oldversion < 2008022700) {
/// Define field oublogid to be added to oublog_links
$table = new XMLDBTable('oublog_links');
$field = new XMLDBField('oublogid');
$field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null, 'id');
/// Launch add field oublogid
$result = $result && add_field($table, $field);
/// Define key oublog_links_oublog_fk (foreign) to be added to oublog_links
$table = new XMLDBTable('oublog_links');
$key = new XMLDBKey('oublog_links_oublog_fk');
$key->setAttributes(XMLDB_KEY_FOREIGN, array('oublogid'), 'oublog', array('id'));
/// Launch add key oublog_links_oublog_fk
$result = $result && add_key($table, $key);
/// Changing nullability of field oubloginstancesid on table oublog_links to null
$table = new XMLDBTable('oublog_links');
$field = new XMLDBField('oubloginstancesid');
$field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null, 'oublogid');
/// Launch change of nullability for field oubloginstancesid
$result = $result && change_field_notnull($table, $field);
}
if ($result && $oldversion < 2008022701) {
/// Define field sortorder to be added to oublog_links
$table = new XMLDBTable('oublog_links');
$field = new XMLDBField('sortorder');
$field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null, 'url');
/// Launch add field sortorder
$result = $result && add_field($table, $field);
}
if ($result && $oldversion < 2008030704) {
/// Add search data
require_once dirname(__FILE__) . '/../locallib.php';
require_once dirname(__FILE__) . '/../lib.php';
if (oublog_search_installed()) {
global $db;
$olddebug = $db->debug;
$db->debug = false;
print '<ul>';
oublog_ousearch_update_all(true);
print '</ul>';
$db->debug = $olddebug;
}
}
if ($result && $oldversion < 2008030707) {
/// Define field lasteditedby to be added to oublog_posts
$table = new XMLDBTable('oublog_posts');
$field = new XMLDBField('lasteditedby');
$field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null, 'visibility');
/// Launch add field lasteditedby
$result = $result && add_field($table, $field);
/// Transfer edit data to lasteditedby
$result = $result && execute_sql("\r\nUPDATE {$CFG->prefix}oublog_posts SET lasteditedby=(\r\n SELECT userid FROM {$CFG->prefix}oublog_edits WHERE {$CFG->prefix}oublog_posts.id=postid ORDER BY id DESC LIMIT 1 \r\n) WHERE editsummary IS NOT NULL\r\n ");
/// Define field editsummary to be dropped from oublog_posts
$table = new XMLDBTable('oublog_posts');
$field = new XMLDBField('editsummary');
/// Launch drop field editsummary
$result = $result && drop_field($table, $field);
}
if ($result && $oldversion < 2008073000) {
/// Define field completionposts to be added to oublog
$table = new XMLDBTable('oublog');
$field = new XMLDBField('completionposts');
$field->setAttributes(XMLDB_TYPE_INTEGER, '9', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'views');
/// Launch add field completionposts
$result = $result && add_field($table, $field);
/// Define field completioncomments to be added to oublog
$field = new XMLDBField('completioncomments');
$field->setAttributes(XMLDB_TYPE_INTEGER, '9', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'completionposts');
/// Launch add field completioncomments
$result = $result && add_field($table, $field);
}
if ($result && $oldversion < 2008121100) {
// remove oublog:view from legacy:user roles
$roles = get_roles_with_capability('moodle/legacy:user', CAP_ALLOW);
foreach ($roles as $role) {
$result = $result && unassign_capability('mod/oublog:view', $role->id);
}
}
if ($result && $oldversion < 2009012600) {
// Remove oublog:post and oublog:comment from legacy:user roles (if present)
$roles = get_roles_with_capability('moodle/legacy:user', CAP_ALLOW);
// Also from default user role if not already included
if (!array_key_exists($CFG->defaultuserroleid, $roles)) {
$roles[] = get_record('role', 'id', $CFG->defaultuserroleid);
//.........这里部分代码省略.........
开发者ID:hmatulis,项目名称:RTL-BIDI-Hebrew-Moodle-Plugins,代码行数:101,代码来源:upgrade.php
示例9: test_everything_in_accesslib
//.........这里部分代码省略.........
$firstrecord = (array)$firstrecord;
$this->assertSame(array_keys($firstrecord), array_values($columns));
context_helper::reset_caches();
foreach ($records as $record) {
context_helper::preload_from_record($record);
$this->assertEquals($record, new stdClass());
}
$this->assertEquals(context_inspection::test_context_cache_size(), count($records));
unset($records);
unset($columns);
context_helper::reset_caches();
context_helper::preload_course($SITE->id);
$this->assertEquals(7, context_inspection::test_context_cache_size()); // depends on number of default blocks
// ====== assign_capability(), unassign_capability() ====================
$rc = $DB->get_record('role_capabilities', array('contextid'=>$frontpagecontext->id, 'roleid'=>$allroles['teacher'], 'capability'=>'moodle/site:accessallgroups'));
$this->assertFalse($rc);
assign_capability('moodle/site:accessallgroups', CAP_ALLOW, $allroles['teacher'], $frontpagecontext->id);
$rc = $DB->get_record('role_capabilities', array('contextid'=>$frontpagecontext->id, 'roleid'=>$allroles['teacher'], 'capability'=>'moodle/site:accessallgroups'));
$this->assertEquals($rc->permission, CAP_ALLOW);
assign_capability('moodle/site:accessallgroups', CAP_PREVENT, $allroles['teacher'], $frontpagecontext->id);
$rc = $DB->get_record('role_capabilities', array('contextid'=>$frontpagecontext->id, 'roleid'=>$allroles['teacher'], 'capability'=>'moodle/site:accessallgroups'));
$this->assertEquals($rc->permission, CAP_ALLOW);
assign_capability('moodle/site:accessallgroups', CAP_PREVENT, $allroles['teacher'], $frontpagecontext, true);
$rc = $DB->get_record('role_capabilities', array('contextid'=>$frontpagecontext->id, 'roleid'=>$allroles['teacher'], 'capability'=>'moodle/site:accessallgroups'));
$this->assertEquals($rc->permission, CAP_PREVENT);
assign_capability('moodle/site:accessallgroups', CAP_INHERIT, $allroles['teacher'], $frontpagecontext);
$rc = $DB->get_record('role_capabilities', array('contextid'=>$frontpagecontext->id, 'roleid'=>$allroles['teacher'], 'capability'=>'moodle/site:accessallgroups'));
$this->assertFalse($rc);
assign_capability('moodle/site:accessallgroups', CAP_ALLOW, $allroles['teacher'], $frontpagecontext);
unassign_capability('moodle/site:accessallgroups', $allroles['teacher'], $frontpagecontext, true);
$rc = $DB->get_record('role_capabilities', array('contextid'=>$frontpagecontext->id, 'roleid'=>$allroles['teacher'], 'capability'=>'moodle/site:accessallgroups'));
$this->assertFalse($rc);
unassign_capability('moodle/site:accessallgroups', $allroles['teacher'], $frontpagecontext->id, true);
unset($rc);
accesslib_clear_all_caches(false); // must be done after assign_capability()
// ======= role_assign(), role_unassign(), role_unassign_all() ==============
$context = context_course::instance($testcourses[1]);
$this->assertEquals($DB->count_records('role_assignments', array('contextid'=>$context->id)), 0);
role_assign($allroles['teacher'], $testusers[1], $context->id);
role_assign($allroles['teacher'], $testusers[2], $context->id);
role_assign($allroles['manager'], $testusers[1], $context->id);
$this->assertEquals($DB->count_records('role_assignments', array('contextid'=>$context->id)), 3);
role_unassign($allroles['teacher'], $testusers[1], $context->id);
$this->assertEquals($DB->count_records('role_assignments', array('contextid'=>$context->id)), 2);
role_unassign_all(array('contextid'=>$context->id));
$this->assertEquals($DB->count_records('role_assignments', array('contextid'=>$context->id)), 0);
unset($context);
accesslib_clear_all_caches(false); // just in case
// ====== has_capability(), get_users_by_capability(), role_switch(), reload_all_capabilities() and friends ========================
$adminid = get_admin()->id;
$guestid = $CFG->siteguest;
// Enrol some users into some courses
$course1 = $DB->get_record('course', array('id'=>$testcourses[22]), '*', MUST_EXIST);
开发者ID:numbas,项目名称:moodle,代码行数:67,代码来源:accesslib_test.php
示例10: capabilities_cleanup
/**
* Deletes cached capabilities that are no longer needed by the component.
* Also unassigns these capabilities from any roles that have them.
* @param $component - examples: 'moodle', 'mod/forum', 'block/quiz_results'
* @param $newcapdef - array of the new capability definitions that will be
* compared with the cached capabilities
* @return int - number of deprecated capabilities that have been removed
*/
function capabilities_cleanup($component, $newcapdef = NULL)
{
global $DB;
$removedcount = 0;
if ($cachedcaps = get_cached_capabilities($component)) {
foreach ($cachedcaps as $cachedcap) {
if (empty($newcapdef) || array_key_exists($cachedcap->name, $newcapdef) === false) {
// Remove from capabilities cache.
if (!$DB->delete_records('capabilities', array('name' => $cachedcap->name))) {
print_error('cannotdeletecap', '', '', $cachedcap->name);
} else {
$removedcount++;
}
// Delete from roles.
if ($roles = get_roles_with_capability($cachedcap->name)) {
foreach ($roles as $role) {
if (!unassign_capability($cachedcap->name, $role->id)) {
print_error('cannotunassigncap', 'error', '', (object) array('cap' => $cachedcap->name, 'role' => $role->name));
}
}
}
}
// End if.
}
}
return $removedcount;
}
开发者ID:nicolasconnault,项目名称:moodle2.0,代码行数:35,代码来源:accesslib.php
示例11: test_check_group_membership
/**
* Test workshop::check_group_membership() functionality.
*/
public function test_check_group_membership()
{
global $DB, $CFG;
$this->resetAfterTest();
$courseid = $this->course->id;
$generator = $this->getDataGenerator();
// Make test groups.
$group1 = $generator->create_group(array('courseid' => $courseid));
$group2 = $generator->create_group(array('courseid' => $courseid));
$group3 = $generator->create_group(array('courseid' => $courseid));
// Revoke the accessallgroups from non-editing teachers (tutors).
$roleids = $DB->get_records_menu('role', null, '', 'shortname, id');
unassign_capability('moodle/site:accessallgroups', $roleids['teacher']);
// Create test use accounts.
$teacher1 = $generator->create_user();
$tutor1 = $generator->create_user();
$tutor2 = $generator->create_user();
$student1 = $generator->create_user();
$student2 = $generator->create_user();
$student3 = $generator->create_user();
// Enrol the teacher (has the access all groups permission).
$generator->enrol_user($teacher1->id, $courseid, $roleids['editingteacher']);
// Enrol tutors (can not access all groups).
$generator->enrol_user($tutor1->id, $courseid, $roleids['teacher']);
$generator->enrol_user($tutor2->id, $courseid, $roleids['teacher']);
// Enrol students.
$generator->enrol_user($student1->id, $courseid, $roleids['student']);
$generator->enrol_user($student2->id, $courseid, $roleids['student']);
$generator->enrol_user($student3->id, $courseid, $roleids['student']);
// Add users in groups.
groups_add_member($group1, $tutor1);
groups_add_member($group2, $tutor2);
groups_add_member($group1, $student1);
groups_add_member($group2, $student2);
groups_add_member($group3, $student3);
// Workshop with no groups.
$workshopitem1 = $this->getDataGenerator()->create_module('workshop', ['course' => $courseid, 'groupmode' => NOGROUPS]);
$cm = get_coursemodule_from_instance('workshop', $workshopitem1->id, $courseid, false, MUST_EXIST);
$workshop1 = new testable_workshop($workshopitem1, $cm, $this->course);
$this->setUser($teacher1);
$this->assertTrue($workshop1->check_group_membership($student1->id));
$this->assertTrue($workshop1->check_group_membership($student2->id));
$this->assertTrue($workshop1->check_group_membership($student3->id));
$this->setUser($tutor1);
$this->assertTrue($workshop1->check_group_membership($student1->id));
$this->assertTrue($workshop1->check_group_membership($student2->id));
$this->assertTrue($workshop1->check_group_membership($student3->id));
// Workshop in visible groups mode.
$workshopitem2 = $this->getDataGenerator()->create_module('workshop', ['course' => $courseid, 'groupmode' => VISIBLEGROUPS]);
$cm = get_coursemodule_from_instance('workshop', $workshopitem2->id, $courseid, false, MUST_EXIST);
$workshop2 = new testable_workshop($workshopitem2, $cm, $this->course);
$this->setUser($teacher1);
$this->assertTrue($workshop2->check_group_membership($student1->id));
$this->assertTrue($workshop2->check_group_membership($student2->id));
$this->assertTrue($workshop2->check_group_membership($student3->id));
$this->setUser($tutor1);
$this->assertTrue($workshop2->check_group_membership($student1->id));
$this->assertTrue($workshop2->check_group_membership($student2->id));
$this->assertTrue($workshop2->check_group_membership($student3->id));
// Workshop in separate groups mode.
$workshopitem3 = $this->getDataGenerator()->create_module('workshop', ['course' => $courseid, 'groupmode' => SEPARATEGROUPS]);
$cm = get_coursemodule_from_instance('workshop', $workshopitem3->id, $courseid, false, MUST_EXIST);
$workshop3 = new testable_workshop($workshopitem3, $cm, $this->course);
$this->setUser($teacher1);
$this->assertTrue($workshop3->check_group_membership($student1->id));
$this->assertTrue($workshop3->check_group_membership($student2->id));
$this->assertTrue($workshop3->check_group_membership($student3->id));
$this->setUser($tutor1);
$this->assertTrue($workshop3->check_group_membership($student1->id));
$this->assertFalse($workshop3->check_group_membership($student2->id));
$this->assertFalse($workshop3->check_group_membership($student3->id));
$this->setUser($tutor2);
$this->assertFalse($workshop3->check_group_membership($student1->id));
$this->assertTrue($workshop3->check_group_membership($student2->id));
$this->assertFalse($workshop3->check_group_membership($student3->id));
}
开发者ID:dg711,项目名称:moodle,代码行数:79,代码来源:locallib_test.php
示例12: test_remove_competency_from_template
public function test_remove_competency_from_template()
{
$syscontext = context_system::instance();
$this->setUser($this->creator);
$lpg = $this->getDataGenerator()->get_plugin_generator('core_competency');
// Create a template.
$template = $this->create_template(1, true);
// Create a competency.
$framework = $lpg->create_framework();
$competency = $lpg->create_competency(array('competencyframeworkid' => $framework->get_id()));
// Add the competency.
external::add_competency_to_template($template->id, $competency->get_id());
// Check that it was added.
$this->assertEquals(1, external::count_competencies_in_template($template->id));
// Check that we can remove the competency.
external::remove_competency_from_template($template->id, $competency->get_id());
// Check that it was removed.
$this->assertEquals(0, external::count_competencies_in_template($template->id));
// Unassign capability.
unassign_capability('moodle/competency:templatemanage', $this->creatorrole, $syscontext->id);
accesslib_clear_all_caches_for_unit_testing();
// Check we can not remove the competency now.
try {
external::add_competency_to_template($template->id, $competency->get_id());
$this->fail('Exception expected due to not permissions to manage template competencies');
} catch (moodle_exception $e) {
$this->assertEquals('nopermissions', $e->errorcode);
}
}
开发者ID:reconnectmedia,项目名称:moodle,代码行数:29,代码来源:external_test.php
示例13: setUp
/**
* Setup function- we will create a course and add an assign instance to it.
*/
protected function setUp()
{
global $DB;
$this->resetAfterTest(true);
// Create some users.
$creator = $this->getDataGenerator()->create_user();
$user = $this->getDataGenerator()->create_user();
$catuser = $this->getDataGenerator()->create_user();
$catcreator = $this->getDataGenerator()->create_user();
$category = $this->getDataGenerator()->create_category();
$othercategory = $this->getDataGenerator()->create_category();
$syscontext = context_system::instance();
$catcontext = context_coursecat::instance($category->id);
// Fetching default authenticated user role.
$userroles = get_archetype_roles('user');
$this->assertCount(1, $userroles);
$authrole = array_pop($userroles);
// Reset all default authenticated users permissions.
unassign_capability('moodle/competency:competencygrade', $authrole->id);
unassign_capability('moodle/competency:competencymanage', $authrole->id);
unassign_capability('moodle/competency:competencyview', $authrole->id);
unassign_capability('moodle/competency:planmanage', $authrole->id);
unassign_capability('moodle/competency:planmanagedraft', $authrole->id);
unassign_capability('moodle/competency:planmanageown', $authrole->id);
unassign_capability('moodle/competency:planview', $authrole->id);
unassign_capability('moodle/competency:planviewdraft', $authrole->id);
unassign_capability('moodle/competency:planviewown', $authrole->id);
unassign_capability('moodle/competency:planviewowndraft', $authrole->id);
unassign_capability('moodle/competency:templatemanage', $authrole->id);
unassign_capability('moodle/competency:templateview', $authrole->id);
unassign_capability('moodle/cohort:manage', $authrole->id);
unassign_capability('moodle/competency:coursecompetencyconfigure', $authrole->id);
// Creating specific roles.
$this->creatorrole = create_role('Creator role', 'lpcreatorrole', 'learning plan creator role description');
$this->userrole = create_role('User role', 'lpuserrole', 'learning plan user role description');
assign_capability('moodle/competency:competencymanage', CAP_ALLOW, $this->creatorrole, $syscontext->id);
assign_capability('moodle/competency:competencycompetencyconfigure', CAP_ALLOW, $this->creatorrole, $syscontext->id);
assign_capability('moodle/competency:planmanage', CAP_ALLOW, $this->creatorrole, $syscontext->id);
assign_capability('moodle/competency:planmanagedraft', CAP_ALLOW, $this->creatorrole, $syscontext->id);
assign_capability('moodle/competency:planmanageown', CAP_ALLOW, $this->creatorrole, $syscontext->id);
assign_capability('moodle/competency:planview', CAP_ALLOW, $this->creatorrole, $syscontext->id);
assign_capability('moodle/competency:planviewdraft', CAP_ALLOW, $this->creatorrole, $syscontext->id);
assign_capability('moodle/competency:templatemanage', CAP_ALLOW, $this->creatorrole, $syscontext->id);
assign_capability('moodle/competency:competencygrade', CAP_ALLOW, $this->creatorrole, $syscontext->id);
assign_capability('moodle/cohort:manage', CAP_ALLOW, $this->creatorrole, $syscontext->id);
assign_capability('moodle/competency:competencyview', CAP_ALLOW, $this->userrole, $syscontext->id);
assign_capability('moodle/competency:templateview', CAP_ALLOW, $this->userrole, $syscontext->id);
assign_capability('moodle/competency:planviewown', CAP_ALLOW, $this->userrole, $syscontext->id);
assign_capability('moodle/competency:planviewowndraft', CAP_ALLOW, $this->userrole, $syscontext->id);
role_assign($this->creatorrole, $creator->id, $syscontext->id);
role_assign($this->creatorrole, $catcreator->id, $catcontext->id);
role_assign($this->userrole, $user->id, $syscontext->id);
role_assign($this->userrole, $catuser->id, $catcontext->id);
$this->creator = $creator;
$this->catcreator = $catcreator;
$this->user = $user;
$this->catuser = $catuser;
$this->category = $category;
$this->othercategory = $othercategory;
accesslib_clear_all_caches_for_unit_testing();
}
开发者ID:evltuma,项目名称:moodle,代码行数:64,代码来源:externallib_test.php
示例14: test_get_item_ratings
/**
* Test get_item_ratings
*/
public function test_get_item_ratings()
{
global $DB, $USER;
$this->resetAfterTest(true);
$course = self::getDataGenerator()->create_course();
$student = $this->getDataGenerator()->create_user();
$teacher1 = $this->getDataGenerator()->create_user();
$teacher2 = $this->getDataGenerator()->create_user();
$teacher3 = $this->getDataGenerator()->create_user();
$studentrole = $DB->get_record('role', array('shortname' => 'student'));
$teacherrole = $DB->get_record('role', array('shortname' => 'teacher'));
unassign_capability('moodle/site:accessallgroups', $teacherrole->id);
$this->getDataGenerator()->enrol_user($student->id, $course->id, $studentrole->id);
$this->getDataGenerator()->enrol_user($teacher1->id, $course->id, $teacherrole->id);
$this->getDataGenerator()->enrol_user($teacher2->id, $course->id, $teacherrole->id);
$this->getDataGenerator()->enrol_user($teacher3->id, $course->id, $teacherrole->id);
// Create the forum.
$record = new stdClass();
$record->introformat = FORMAT_HTML;
$record->course = $course->id;
// Set Aggregate type = Average of ratings.
$record->assessed = RATING_AGGREGATE_AVERAGE;
$forum = self::getDataGenerator()->create_module('forum', $record);
$contextid = context_module::instance($forum->cmid)->id;
// Add discussion to the forums.
$record = new stdClass();
$record->course = $course->id;
$record->userid = $student->id;
$record->forum = $forum->id;
$discussion = self::getDataGenerator()->get_plugin_generator('mod_forum')->create_discussion($record);
// Retrieve the first post.
$post = $DB->get_record('forum_posts', array('discussion' => $discussion->id));
// Rete the discussion as teacher1.
$rating1 = new stdClass();
$rating1->contextid = $contextid;
$rating1->component = 'mod_forum';
$rating1->ratingarea = 'post';
$rating1->itemid = $post->id;
$rating1->rating = 90;
$rating1->scaleid = 100;
$rating1->userid = $teacher1->id;
$rating1->timecreated = time();
$rating1->timemodified = time();
$rating1->id = $DB->insert_record('rating', $rating1);
// Rete the discussion as teacher2.
$rating2 = new stdClass();
$rating2->contextid = $contextid;
$rating2->component = 'mod_forum';
$rating2->ratingarea = 'post';
$rating2->itemid = $post->id;
$rating2->rating = 95;
$rating2->scaleid = 100;
$rating2->userid = $teacher2->id;
$rating2->timecreated = time() + 1;
$rating2->timemodified = time() + 1;
$rating2->id = $DB->insert_record('rating', $rating2);
// Delete teacher2, we must still receive the ratings.
delete_user($teacher2);
// Teachers can see all the ratings.
$this->setUser($teacher1);
$ratings = core_rating_external::get_item_ratings('module', $forum->cmid, 'mod_forum', 'post', $post->id, 100, '');
// We need to execute the return values cleaning process to simulate the web service server.
$ratings = external_api::clean_returnvalue(core_rating_external::get_item_ratings_returns(), $ratings);
$this->assertCount(2, $ratings['ratings']);
$indexedratings = array();
foreach ($ratings['ratings'] as $rating) {
$indexedratings[$rating['id']] = $rating;
}
$this->assertEquals($rating1->rating . ' / ' . $rating1->scaleid, $indexedratings[$rating1->id]['rating']);
$this->assertEquals($rating2->rating . ' / ' . $rating2->scaleid, $indexedratings[$rating2->id]['rating']);
$this->assertEquals($rating1->userid, $indexedratings[$rating1->id]['userid']);
$this->assertEquals($rating2->userid, $indexedratings[$rating2->id]['userid']);
// Student can see ratings.
$this->setUser($student);
$ratings = core_rating_external::get_item_ratings('module', $forum->cmid, 'mod_forum', 'post', $post->id, 100, '');
// We need to execute the return values cleaning process to simulate the web service server.
$ratings = external_api::clean_returnvalue(core_rating_external::get_item_ratings_returns(), $ratings);
$this->assertCount(2, $ratings['ratings']);
// Invalid item.
try {
$ratings = core_rating_external::get_item_ratings('module', $forum->cmid, 'mod_forum', 'post', 0, 100, '');
$this->fail('Exception expected due invalid itemid.');
} catch (moodle_exception $e) {
$this->assertEquals('invalidrecord', $e->errorcode);
}
// Invalid area.
try {
$ratings = core_rating_external::get_item_ratings('module', $forum->cmid, 'mod_forum', 'xyz', $post->id, 100, '');
$this->fail('Exception expected due invalid rating area.');
} catch (moodle_exception $e) {
$this->assertEquals('invalidratingarea', $e->errorcode);
}
// Invalid context. invalid_parameter_exception.
try {
$ratings = core_rating_external::get_item_ratings('module', 0, 'mod_forum', 'post', $post->id, 100, '');
$this->fail('Exception expected due invalid context.');
} catch (invalid_parameter_exception $e) {
//.........这里部分代码省略.........
开发者ID:evltuma,项目名称:moodle,代码行数:101,代码来源:externallib_test.php
示例15: revoke
/**
* Revokes the capability assignment.
*/
public function revoke()
{
foreach ($this->capability as $capability) {
unassign_capability($capability, $this->roleid, $this->contextid);
}
accesslib_clear_all_caches_for_unit_testing();
}
开发者ID:pzhu2004,项目名称:moodle,代码行数:10,代码来源:course_capability_assignment.php
示例16: capabilities_cleanup
/**
* Deletes cached capabilities that are no longer needed by the component.
* Also unassigns these capabilities from any roles that have them.
* @param $component - examples: 'moodle', 'mod/forum', 'block/quiz_results'
* @param $newcapdef - array of the new capability definitions that will be
* compared with the cached capabilities
* @return int - number of deprecated capabilities that have been removed
*/
function capabilities_cleanup($component, $newcapdef = NULL)
{
$removedcount = 0;
if ($cachedcaps = get_cached_capabilities($component)) {
foreach ($cachedcaps as $cachedcap) {
if (empty($newcapdef) || array_key_exists($cachedcap->name, $newcapdef) === false) {
// Remove from capabilities cache.
if (!delete_records('capabilities', 'name', $cachedcap->name)) {
error('Could not delete deprecated capability ' . $cachedcap->name);
} else {
$removedcount++;
}
// Delete from roles.
if ($roles = get_roles_with_capability($cachedcap->name)) {
foreach ($roles as $role) {
if (!unassign_capability($cachedcap->name, $role->id)) {
error('Could not unassign deprecated capability ' . $cachedcap->name . ' from role ' . $role->name);
}
}
}
}
// End if.
}
}
return $removedcount;
}
开发者ID:edwinphillips,项目名称:moodle-485cb39,代码行数:34,
|
请发表评论