本文整理汇总了PHP中get_archetype_roles函数的典型用法代码示例。如果您正苦于以下问题:PHP get_archetype_roles函数的具体用法?PHP get_archetype_roles怎么用?PHP get_archetype_roles使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_archetype_roles函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get_course_risks
/**
* get_course_risks
*
* @param int $courseid courseid of the course
* @param int $startdate start of range in seconds
* @param int $enddate end of range in seconds
* @access public
* @return array list of risk values, key'd on userid
*/
public function get_course_risks($startdate = null, $enddate = null)
{
global $DB;
// TODO: Move the user list building somewhere static, otherwise its done for every indicator.
$pluginconfig = get_config('engagement');
if (!isset($pluginconfig->roles)) {
$roleids = array_keys(get_archetype_roles('student'));
} else {
$roles = $pluginconfig->roles;
$roleids = explode(',', $roles);
}
list($esql, $eparams) = get_enrolled_sql($this->context, '', 0, true);
// Only active users.
list($rsql, $rparams) = $DB->get_in_or_equal($roleids, SQL_PARAMS_NAMED, 'roles');
$sql = "SELECT " . $DB->sql_concat_join("'_'", array('je.id', 'ra.id')) . ", je.id as jeid\n FROM ({$esql}) je\n JOIN {role_assignments} ra ON (ra.userid = je.id)\n WHERE ra.contextid = :contextid AND ra.roleid {$rsql}";
$params = array_merge($eparams, $rparams);
$params['contextid'] = $this->context->id;
$result = $DB->get_records_sql($sql, $params);
$users = array();
foreach ($result as $key => $row) {
if (!isset($users[$row->jeid])) {
$users[$row->jeid] = true;
}
}
$users = array_keys($users);
return self::get_risk_for_users($users, $startdate, $enddate);
}
示例2: xmldb_enrol_self_upgrade
function xmldb_enrol_self_upgrade($oldversion)
{
global $CFG;
// Moodle v2.8.0 release upgrade line.
// Put any upgrade step following this.
// Moodle v2.9.0 release upgrade line.
// Put any upgrade step following this.
// Moodle v3.0.0 release upgrade line.
// Put any upgrade step following this.
// Moodle v3.1.0 release upgrade line.
// Put any upgrade step following this.
if ($oldversion < 2016052301) {
global $DB;
// Get roles with manager archetype.
$managerroles = get_archetype_roles('manager');
if (!empty($managerroles)) {
// Remove wrong CAP_PROHIBIT from self:holdkey.
foreach ($managerroles as $role) {
$DB->execute("DELETE\n FROM {role_capabilities}\n WHERE roleid = ? AND capability = ? AND permission = ?", array($role->id, 'enrol/self:holdkey', CAP_PROHIBIT));
}
}
upgrade_plugin_savepoint(true, 2016052301, 'enrol', 'self');
}
return true;
}
示例3: xmldb_enrol_category_install
function xmldb_enrol_category_install()
{
global $CFG, $DB;
if (!$DB->record_exists_select('role_assignments', "contextid IN (SELECT id FROM {context} WHERE contextlevel = ?)", array(CONTEXT_COURSECAT))) {
// fresh install or nobody used category enrol
return;
}
// existing sites need a way to keep category role enrols, but we do not want to encourage that on new sites
// extremely ugly hack, the sync depends on the capabilities so we unfortunately force update of caps here
// note: this is not officially supported and should not be copied elsewhere! :-(
update_capabilities('enrol_category');
$syscontext = get_context_instance(CONTEXT_SYSTEM);
$archetypes = array('student', 'teacher', 'editingteacher');
$enableplugin = false;
foreach ($archetypes as $archetype) {
$roles = get_archetype_roles($archetype);
foreach ($roles as $role) {
if (!$DB->record_exists_select('role_assignments', "roleid = ? AND contextid IN (SELECT id FROM {context} WHERE contextlevel = ?)", array($role->id, CONTEXT_COURSECAT))) {
continue;
}
assign_capability('enrol/category:synchronised', CAP_ALLOW, $role->id, $syscontext->id, true);
$levels = get_role_contextlevels($role->id);
$levels[] = CONTEXT_COURSECAT;
set_role_contextlevels($role->id, $levels);
$enableplugin = true;
}
}
if (!$enableplugin) {
return;
}
// enable this plugin
$enabledplugins = explode(',', $CFG->enrol_plugins_enabled);
$enabledplugins[] = 'category';
$enabledplugins = array_unique($enabledplugins);
set_config('enrol_plugins_enabled', implode(',', $enabledplugins));
// brute force course resync, this may take a while
require_once "{$CFG->dirroot}/enrol/category/locallib.php";
enrol_category_sync_full();
}
示例4: get_potential_students
/**
* This function calculates all unassigned students for a particular grouping.
* We enforce a rule that students can only be a member of one group in the
* grouping.
*
* @return array {IDs => names) of potential members.
*
*/
public function get_potential_students()
{
$student = get_archetype_roles('student');
$student = reset($student);
$allmembers = groups_get_potential_members($this->courseid, $student->id);
$allocatedmembers = $this->get_all_grouped_students();
$potentialmemberids = array();
foreach ($allmembers as $allmember) {
if (array_search($allmember->id, $allocatedmembers) === false) {
$potentialmemberids[] = $allmember->id;
}
}
sort($potentialmemberids);
$potentialmembernames = block_skills_group_retrieve_names($potentialmemberids);
// Note: array_combine() will not work with empty arrays.
if (count($potentialmemberids) > 0) {
return array_combine($potentialmemberids, $potentialmembernames);
} else {
return array();
}
}
示例5: get_defaultsetting
/**
* Return the default setting for this control
*
* @return array Array of default settings
*/
public function get_defaultsetting()
{
global $CFG;
if (during_initial_install()) {
return null;
}
$result = array();
foreach ($this->types as $archetype) {
if ($caproles = get_archetype_roles($archetype)) {
foreach ($caproles as $caprole) {
$result[$caprole->id] = 1;
}
}
}
return $result;
}
示例6: definition
function definition()
{
global $CFG, $USER;
$mform = $this->_form;
$columns = $this->_customdata['columns'];
$data = $this->_customdata['data'];
// I am the template user, why should it be the administrator? we have roles now, other ppl may use this script ;-)
$templateuser = $USER;
// upload settings and file
$mform->addElement('header', 'settingsheader', get_string('settings'));
$choices = array(UU_USER_ADDNEW => get_string('uuoptype_addnew', 'tool_uploaduser'), UU_USER_ADDINC => get_string('uuoptype_addinc', 'tool_uploaduser'), UU_USER_ADD_UPDATE => get_string('uuoptype_addupdate', 'tool_uploaduser'), UU_USER_UPDATE => get_string('uuoptype_update', 'tool_uploaduser'));
$mform->addElement('select', 'uutype', get_string('uuoptype', 'tool_uploaduser'), $choices);
$choices = array(0 => get_string('infilefield', 'auth'), 1 => get_string('createpasswordifneeded', 'auth'));
$mform->addElement('select', 'uupasswordnew', get_string('uupasswordnew', 'tool_uploaduser'), $choices);
$mform->setDefault('uupasswordnew', 1);
$mform->disabledIf('uupasswordnew', 'uutype', 'eq', UU_USER_UPDATE);
$choices = array(UU_UPDATE_NOCHANGES => get_string('nochanges', 'tool_uploaduser'), UU_UPDATE_FILEOVERRIDE => get_string('uuupdatefromfile', 'tool_uploaduser'), UU_UPDATE_ALLOVERRIDE => get_string('uuupdateall', 'tool_uploaduser'), UU_UPDATE_MISSING => get_string('uuupdatemissing', 'tool_uploaduser'));
$mform->addElement('select', 'uuupdatetype', get_string('uuupdatetype', 'tool_uploaduser'), $choices);
$mform->setDefault('uuupdatetype', UU_UPDATE_NOCHANGES);
$mform->disabledIf('uuupdatetype', 'uutype', 'eq', UU_USER_ADDNEW);
$mform->disabledIf('uuupdatetype', 'uutype', 'eq', UU_USER_ADDINC);
$choices = array(0 => get_string('nochanges', 'tool_uploaduser'), 1 => get_string('update'));
$mform->addElement('select', 'uupasswordold', get_string('uupasswordold', 'tool_uploaduser'), $choices);
$mform->setDefault('uupasswordold', 0);
$mform->disabledIf('uupasswordold', 'uutype', 'eq', UU_USER_ADDNEW);
$mform->disabledIf('uupasswordold', 'uutype', 'eq', UU_USER_ADDINC);
$mform->disabledIf('uupasswordold', 'uuupdatetype', 'eq', 0);
$mform->disabledIf('uupasswordold', 'uuupdatetype', 'eq', 3);
$choices = array(UU_PWRESET_WEAK => get_string('usersweakpassword', 'tool_uploaduser'), UU_PWRESET_NONE => get_string('none'), UU_PWRESET_ALL => get_string('all'));
if (empty($CFG->passwordpolicy)) {
unset($choices[UU_PWRESET_WEAK]);
}
$mform->addElement('select', 'uuforcepasswordchange', get_string('forcepasswordchange', 'core'), $choices);
$mform->addElement('selectyesno', 'uuallowrenames', get_string('allowrenames', 'tool_uploaduser'));
$mform->setDefault('uuallowrenames', 0);
$mform->disabledIf('uuallowrenames', 'uutype', 'eq', UU_USER_ADDNEW);
$mform->disabledIf('uuallowrenames', 'uutype', 'eq', UU_USER_ADDINC);
$mform->addElement('selectyesno', 'uuallowdeletes', get_string('allowdeletes', 'tool_uploaduser'));
$mform->setDefault('uuallowdeletes', 0);
$mform->disabledIf('uuallowdeletes', 'uutype', 'eq', UU_USER_ADDNEW);
$mform->disabledIf('uuallowdeletes', 'uutype', 'eq', UU_USER_ADDINC);
$mform->addElement('selectyesno', 'uuallowsuspends', get_string('allowsuspends', 'tool_uploaduser'));
$mform->setDefault('uuallowsuspends', 1);
$mform->disabledIf('uuallowsuspends', 'uutype', 'eq', UU_USER_ADDNEW);
$mform->disabledIf('uuallowsuspends', 'uutype', 'eq', UU_USER_ADDINC);
if (!empty($CFG->allowaccountssameemail)) {
$mform->addElement('selectyesno', 'uunoemailduplicates', get_string('uunoemailduplicates', 'tool_uploaduser'));
$mform->setDefault('uunoemailduplicates', 1);
} else {
$mform->addElement('hidden', 'uunoemailduplicates', 1);
}
$mform->setType('uunoemailduplicates', PARAM_BOOL);
$mform->addElement('selectyesno', 'uustandardusernames', get_string('uustandardusernames', 'tool_uploaduser'));
$mform->setDefault('uustandardusernames', 1);
$choices = array(UU_BULK_NONE => get_string('no'), UU_BULK_NEW => get_string('uubulknew', 'tool_uploaduser'), UU_BULK_UPDATED => get_string('uubulkupdated', 'tool_uploaduser'), UU_BULK_ALL => get_string('uubulkall', 'tool_uploaduser'));
$mform->addElement('select', 'uubulk', get_string('uubulk', 'tool_uploaduser'), $choices);
$mform->setDefault('uubulk', 0);
// roles selection
$showroles = false;
foreach ($columns as $column) {
if (preg_match('/^type\\d+$/', $column)) {
$showroles = true;
break;
}
}
if ($showroles) {
$mform->addElement('header', 'rolesheader', get_string('roles'));
$choices = uu_allowed_roles(true);
$mform->addElement('select', 'uulegacy1', get_string('uulegacy1role', 'tool_uploaduser'), $choices);
if ($studentroles = get_archetype_roles('student')) {
foreach ($studentroles as $role) {
if (isset($choices[$role->id])) {
$mform->setDefault('uulegacy1', $role->id);
break;
}
}
unset($studentroles);
}
$mform->addElement('select', 'uulegacy2', get_string('uulegacy2role', 'tool_uploaduser'), $choices);
if ($editteacherroles = get_archetype_roles('editingteacher')) {
foreach ($editteacherroles as $role) {
if (isset($choices[$role->id])) {
$mform->setDefault('uulegacy2', $role->id);
break;
}
}
unset($editteacherroles);
}
$mform->addElement('select', 'uulegacy3', get_string('uulegacy3role', 'tool_uploaduser'), $choices);
if ($teacherroles = get_archetype_roles('teacher')) {
foreach ($teacherroles as $role) {
if (isset($choices[$role->id])) {
$mform->setDefault('uulegacy3', $role->id);
break;
}
}
unset($teacherroles);
}
}
// default values
//.........这里部分代码省略.........
示例7: defined
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Cohort enrolment plugin settings and default values
*
* @package enrol_mnet
* @copyright 2010 David Mudrak <david@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die;
if ($ADMIN->fulltree) {
//--- general settings -----------------------------------------------------------------------------------
$settings->add(new admin_setting_heading('enrol_mnet_settings', '', get_string('pluginname_desc', 'enrol_mnet')));
//--- enrol instance defaults ----------------------------------------------------------------------------
if (!during_initial_install()) {
$options = get_default_enrol_roles(context_system::instance());
$student = get_archetype_roles('student');
$student = reset($student);
$settings->add(new admin_setting_configselect_with_advanced('enrol_mnet/roleid', get_string('defaultrole', 'role'), '', array('value' => $student->id, 'adv' => true), $options));
}
}
示例8: sync_roles
/**
* Sync roles for this user
*
* @param $user object user object (without system magic quotes)
*/
function sync_roles($user)
{
$iscreator = $this->iscreator($user->username);
if ($iscreator === null) {
return;
// Nothing to sync - creators not configured
}
if ($roles = get_archetype_roles('coursecreator')) {
$creatorrole = array_shift($roles);
// We can only use one, let's use the first one
$systemcontext = context_system::instance();
if ($iscreator) {
// Following calls will not create duplicates
role_assign($creatorrole->id, $user->id, $systemcontext->id, $this->roleauth);
} else {
// Unassign only if previously assigned by this plugin!
role_unassign($creatorrole->id, $user->id, $systemcontext->id, $this->roleauth);
}
}
}
示例9: test_view_glossary_without_permission
/**
* @expectedException require_login_exception
* @expectedExceptionMessage Activity is hidden
*/
public function test_view_glossary_without_permission()
{
$this->resetAfterTest(true);
// Generate all the things.
$c1 = $this->getDataGenerator()->create_course();
$g1 = $this->getDataGenerator()->create_module('glossary', array('course' => $c1->id));
$u1 = $this->getDataGenerator()->create_user();
$this->getDataGenerator()->enrol_user($u1->id, $c1->id);
$ctx = context_module::instance($g1->cmid);
// Revoke permission.
$roles = get_archetype_roles('user');
$role = array_shift($roles);
assign_capability('mod/glossary:view', CAP_PROHIBIT, $role->id, $ctx, true);
accesslib_clear_all_caches_for_unit_testing();
// Assertion.
$this->setUser($u1);
mod_glossary_external::view_glossary($g1->id, 'letter');
}
示例10: push_registrations
/**
* push in grouptool registered users to moodle-groups
*
* @param int $groupid optional only for this group
* @param int $groupingid optional only for this grouping
* @param bool $previewonly optional get only the preview
* @return array($error, $message)
*/
public function push_registrations($groupid = 0, $groupingid = 0, $previewonly = false)
{
global $DB, $CFG;
// Trigger the event!
\mod_grouptool\event\registration_push_started::create_from_object($this->cm)->trigger();
$userinfo = get_enrolled_users($this->context);
$return = array();
// Get active groups filtered by groupid, grouping_id, grouptoolid!
$agrps = $this->get_active_groups(true, false, 0, $groupid, $groupingid);
foreach ($agrps as $groupid => $agrp) {
foreach ($agrp->registered as $reg) {
$info = new stdClass();
if (!key_exists($reg->userid, $userinfo)) {
$userinfo[$reg->userid] = $DB->get_record('user', array('id' => $reg->userid));
}
$info->username = fullname($userinfo[$reg->userid]);
$info->groupname = $agrp->name;
if (!groups_is_member($groupid, $reg->userid)) {
// Add to group if is not already!
if (!$previewonly) {
if (!is_enrolled($this->context, $reg->userid)) {
/*
* if user's not enrolled already we force manual enrollment in course,
* so we can add the user to the group
*/
require_once $CFG->dirroot . '/enrol/manual/locallib.php';
require_once $CFG->libdir . '/accesslib.php';
if (!($enrolmanual = enrol_get_plugin('manual'))) {
throw new coding_exception('Can not instantiate enrol_manual');
}
if (!($instance = $DB->get_record('enrol', array('courseid' => $this->course->id, 'enrol' => 'manual'), '*', IGNORE_MISSING))) {
if ($instanceid = $enrolmanual->add_default_instance($this->course)) {
$instance = $DB->get_record('enrol', array('courseid' => $this->course->id, 'enrol' => 'manual'), '*', MUST_EXIST);
}
}
if ($instance != false) {
$archroles = get_archetype_roles('student');
$archrole = array_shift($archroles);
$enrolmanual->enrol_user($instance, $reg->userid, $archrole->id, time());
} else {
$message .= html_writer::tag('div', $OUTPUT->notification(get_string('cant_enrol', 'grouptool'), 'notifyproblem'));
}
}
if (groups_add_member($groupid, $reg->userid)) {
$return[] = html_writer::tag('div', get_string('added_member', 'grouptool', $info), array('class' => 'notifysuccess'));
} else {
$return[] = html_writer::tag('div', get_string('could_not_add', 'grouptool', $info), array('class' => 'notifyproblem'));
}
} else {
$return[] = html_writer::tag('div', get_string('add_member', 'grouptool', $info), array('class' => 'notifysuccess'));
}
} else {
$return[] = html_writer::tag('div', get_string('already_member', 'grouptool', $info), array('class' => 'ignored'));
}
}
}
switch (count($return)) {
default:
return array(false, implode("<br />\n", $return));
break;
case 1:
return array(false, current($return));
break;
case 0:
return array(true, get_string('nothing_to_push', 'grouptool'));
break;
}
}
示例11: load_defaults
function load_defaults()
{
global $CFG, $COURSE, $DB;
$mform =& $this->_form;
$defaults = array('reset_events' => 1, 'reset_roles_local' => 1, 'reset_gradebook_grades' => 1, 'reset_notes' => 1);
// Set student as default in unenrol user list, if role with student archetype exist.
if ($studentrole = get_archetype_roles('student')) {
$defaults['unenrol_users'] = array_keys($studentrole);
}
if ($allmods = $DB->get_records('modules')) {
foreach ($allmods as $mod) {
$modname = $mod->name;
$modfile = $CFG->dirroot . "/mod/{$modname}/lib.php";
$mod_reset_course_form_defaults = $modname . '_reset_course_form_defaults';
if (file_exists($modfile)) {
@(include_once $modfile);
if (function_exists($mod_reset_course_form_defaults)) {
if ($moddefs = $mod_reset_course_form_defaults($COURSE)) {
$defaults = $defaults + $moddefs;
}
}
}
}
}
foreach ($defaults as $element => $default) {
$mform->setDefault($element, $default);
}
}
示例12: 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();
$category = $this->getDataGenerator()->create_category();
$othercategory = $this->getDataGenerator()->create_category();
$catcreator = $this->getDataGenerator()->create_user();
$syscontext = context_system::instance();
$catcontext = context_coursecat::instance($category->id);
$othercatcontext = context_coursecat::instance($othercategory->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', 'creatorrole', 'learning plan creator role description');
$this->userrole = create_role('User role', 'userrole', '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:competencyview', CAP_ALLOW, $this->userrole, $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: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;
$this->getDataGenerator()->create_scale(array("id" => "1", "scale" => "value1, value2"));
$this->getDataGenerator()->create_scale(array("id" => "2", "scale" => "value3, value4"));
$this->getDataGenerator()->create_scale(array("id" => "3", "scale" => "value5, value6"));
$this->getDataGenerator()->create_scale(array("id" => "4", "scale" => "value7, value8"));
$this->scaleconfiguration1 = '[{"scaleid":"1"},{"name":"value1","id":1,"scaledefault":1,"proficient":0},' . '{"name":"value2","id":2,"scaledefault":0,"proficient":1}]';
$this->scaleconfiguration2 = '[{"scaleid":"2"},{"name":"value3","id":1,"scaledefault":1,"proficient":0},' . '{"name":"value4","id":2,"scaledefault":0,"proficient":1}]';
$this->scaleconfiguration3 = '[{"scaleid":"3"},{"name":"value5","id":1,"scaledefault":1,"proficient":0},' . '{"name":"value6","id":2,"scaledefault":0,"proficient":1}]';
$this->scaleconfiguration4 = '[{"scaleid":"4"},{"name":"value8","id":1,"scaledefault":1,"proficient":0},' . '{"name":"value8","id":2,"scaledefault":0,"proficient":1}]';
accesslib_clear_all_caches_for_unit_testing();
}
示例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();
}
示例14: definition
function definition (){
global $CFG, $USER;
$mform =& $this->_form;
$columns =& $this->_customdata;
// I am the template user, why should it be the administrator? we have roles now, other ppl may use this script ;-)
$templateuser = $USER;
// upload settings and file
$mform->addElement('header', 'settingsheader', get_string('settings'));
$mform->addElement('static', 'uutypelabel', get_string('uuoptype', 'admin') );
$choices = array(0 => get_string('infilefield', 'auth'), 1 => get_string('createpasswordifneeded', 'auth'));
$mform->addElement('select', 'uupasswordnew', get_string('uupasswordnew', 'admin'), $choices);
$mform->setDefault('uupasswordnew', 1);
$mform->disabledIf('uupasswordnew', 'uutype', 'eq', UU_UPDATE);
$choices = array(0 => get_string('nochanges', 'admin'),
1 => get_string('uuupdatefromfile', 'admin'),
2 => get_string('uuupdateall', 'admin'),
3 => get_string('uuupdatemissing', 'admin'));
$mform->addElement('select', 'uuupdatetype', get_string('uuupdatetype', 'admin'), $choices);
$mform->setDefault('uuupdatetype', 0);
$mform->disabledIf('uuupdatetype', 'uutype', 'eq', UU_ADDNEW);
$mform->disabledIf('uuupdatetype', 'uutype', 'eq', UU_ADDINC);
$choices = array(0 => get_string('nochanges', 'admin'), 1 => get_string('update'));
$mform->addElement('select', 'uupasswordold', get_string('uupasswordold', 'admin'), $choices);
$mform->setDefault('uupasswordold', 0);
$mform->disabledIf('uupasswordold', 'uutype', 'eq', UU_ADDNEW);
$mform->disabledIf('uupasswordold', 'uutype', 'eq', UU_ADDINC);
$mform->disabledIf('uupasswordold', 'uuupdatetype', 'eq', 0);
$mform->disabledIf('uupasswordold', 'uuupdatetype', 'eq', 3);
$mform->addElement('selectyesno', 'uuallowrenames', get_string('allowrenames', 'admin'));
$mform->setDefault('uuallowrenames', 0);
$mform->disabledIf('uuallowrenames', 'uutype', 'eq', UU_ADDNEW);
$mform->disabledIf('uuallowrenames', 'uutype', 'eq', UU_ADDINC);
$mform->addElement('selectyesno', 'uuallowdeletes', get_string('allowdeletes', 'admin'));
$mform->setDefault('uuallowdeletes', 0);
$mform->disabledIf('uuallowdeletes', 'uutype', 'eq', UU_ADDNEW);
$mform->disabledIf('uuallowdeletes', 'uutype', 'eq', UU_ADDINC);
$mform->addElement('selectyesno', 'uunoemailduplicates', get_string('uunoemailduplicates', 'admin'));
$mform->setDefault('uunoemailduplicates', 1);
$choices = array(0 => get_string('no'),
1 => get_string('uubulknew', 'admin'),
2 => get_string('uubulkupdated', 'admin'),
3 => get_string('uubulkall', 'admin'));
$mform->addElement('select', 'uubulk', get_string('uubulk', 'admin'), $choices);
$mform->setDefault('uubulk', 0);
// roles selection
$showroles = false;
foreach ($columns as $column) {
if (preg_match('/^type\d+$/', $column)) {
$showroles = true;
break;
}
}
if ($showroles) {
$mform->addElement('header', 'rolesheader', get_string('roles'));
$choices = uu_allowed_roles(true);
$mform->addElement('select', 'uulegacy1', get_string('uulegacy1role', 'admin'), $choices);
if ($studentroles = get_archetype_roles('student')) {
foreach ($studentroles as $role) {
if (isset($choices[$role->id])) {
$mform->setDefault('uulegacy1', $role->id);
break;
}
}
unset($studentroles);
}
$mform->addElement('select', 'uulegacy2', get_string('uulegacy2role', 'admin'), $choices);
if ($editteacherroles = get_archetype_roles('editingteacher')) {
foreach ($editteacherroles as $role) {
if (isset($choices[$role->id])) {
$mform->setDefault('uulegacy2', $role->id);
break;
}
}
unset($editteacherroles);
}
$mform->addElement('select', 'uulegacy3', get_string('uulegacy3role', 'admin'), $choices);
if ($teacherroles = get_archetype_roles('teacher')) {
foreach ($teacherroles as $role) {
if (isset($choices[$role->id])) {
$mform->setDefault('uulegacy3', $role->id);
break;
}
}
unset($teacherroles);
}
//.........这里部分代码省略.........
示例15: local_ent_installer_sync_users
//.........这里部分代码省略.........
}
/****************************** User Updates - time-consuming (optional). ***************************/
// This might be an OBSOLETE code, regarding the updat ecapability of the create process.
if (!empty($options['doupdates'])) {
// Narrow down what fields we need to update.
$all_keys = array_keys(get_object_vars($ldapauth->config));
$updatekeys = array();
foreach ($all_keys as $key) {
if (preg_match('/^field_updatelocal_(.+)$/', $key, $match)) {
/*
* If we have a field to update it from
* and it must be updated 'onlogin' we
* update it on cron
*/
if (!empty($ldapauth->config->{'field_map_' . $match[1]}) && $ldapauth->config->{$match[0]} === 'onlogin') {
// The actual key name.
array_push($updatekeys, $match[1]);
}
}
}
unset($all_keys);
unset($key);
} else {
mtrace(get_string('noupdatestobedone', 'auth_ldap'));
}
if (@$options['doupdates'] and !empty($updatekeys)) {
// Run updates only if relevant.
$users = $DB->get_records_sql('SELECT u.username, u.id
FROM {user} u
WHERE u.deleted = 0 AND u.auth = ? AND u.mnethostid = ?', array($ldapauth->authtype, $CFG->mnet_localhost_id));
if (!empty($users)) {
mtrace(get_string('userentriestoupdate', 'auth_ldap', count($users)));
$sitecontext = context_system::instance();
if (!empty($ldapauth->config->creators) and !empty($ldapauth->config->memberattribute) && ($roles = get_archetype_roles('coursecreator'))) {
// We can only use one, let's use the first one.
$creatorrole = array_shift($roles);
} else {
$creatorrole = false;
}
$transaction = $DB->start_delegated_transaction();
$xcount = 0;
$maxxcount = 100;
foreach ($users as $user) {
echo "\t";
$tracestr = get_string('auth_dbupdatinguser', 'auth_db', array('name' => $user->username, 'id' => $user->id));
if (!$ldapauth->update_user_record($user->username, $updatekeys)) {
$tracestr .= ' - ' . get_string('skipped');
}
mtrace($tracestr);
$xcount++;
// Update course creators if needed.
if ($creatorrole !== false) {
if ($ldapauth->iscreator($user->username)) {
role_assign($creatorrole->id, $user->id, $sitecontext->id, $ldapauth->roleauth);
} else {
role_unassign($creatorrole->id, $user->id, $sitecontext->id, $ldapauth->roleauth);
}
}
}
$transaction->allow_commit();
unset($users);
// free mem
}
} else {
// End do updates.
mtrace(get_string('noupdatestobedone', 'auth_ldap'));