本文整理汇总了PHP中role_get_names函数的典型用法代码示例。如果您正苦于以下问题:PHP role_get_names函数的具体用法?PHP role_get_names怎么用?PHP role_get_names使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了role_get_names函数的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: definition
/**
* Form definition.
*/
public function definition()
{
global $PAGE;
$mform = $this->_form;
$roles = get_roles_for_contextlevels(CONTEXT_USER);
if (empty($roles)) {
$output = $PAGE->get_renderer('tool_cohortroles');
$warning = $output->notify_problem(get_string('noassignableroles', 'tool_cohortroles'));
$mform->addElement('html', $warning);
return;
}
$options = array('ajax' => 'tool_lp/form-user-selector', 'multiple' => true);
$mform->addElement('autocomplete', 'userids', get_string('selectusers', 'tool_cohortroles'), array(), $options);
$mform->addRule('userids', null, 'required');
$names = role_get_names();
$options = array();
foreach ($roles as $idx => $roleid) {
$options[$roleid] = $names[$roleid]->localname;
}
$mform->addElement('select', 'roleid', get_string('selectrole', 'tool_cohortroles'), $options);
$mform->addRule('roleid', null, 'required');
$context = context_system::instance();
$options = array('ajax' => 'tool_lp/form-cohort-selector', 'multiple' => true, 'data-contextid' => $context->id, 'data-includes' => 'all');
$mform->addElement('autocomplete', 'cohortids', get_string('selectcohorts', 'tool_cohortroles'), array(), $options);
$mform->addRule('cohortids', null, 'required');
$mform->addElement('submit', 'submit', get_string('assign', 'tool_cohortroles'));
}
示例2: get_course_detail_array
/**
* Returns course details in an array ready to be printed.
*
* @global \moodle_database $DB
* @param \course_in_list $course
* @return array
*/
public static function get_course_detail_array(\course_in_list $course)
{
global $DB;
$canaccess = $course->can_access();
$format = \course_get_format($course->id);
$modinfo = \get_fast_modinfo($course->id);
$modules = $modinfo->get_used_module_names();
$sections = array();
if ($format->uses_sections()) {
foreach ($modinfo->get_section_info_all() as $section) {
if ($section->uservisible) {
$sections[] = $format->get_section_name($section);
}
}
}
$category = \coursecat::get($course->category);
$categoryurl = new \moodle_url('/course/management.php', array('categoryid' => $course->category));
$categoryname = $category->get_formatted_name();
$details = array('fullname' => array('key' => \get_string('fullname'), 'value' => $course->get_formatted_fullname()), 'shortname' => array('key' => \get_string('shortname'), 'value' => $course->get_formatted_shortname()), 'idnumber' => array('key' => \get_string('idnumber'), 'value' => s($course->idnumber)), 'category' => array('key' => \get_string('category'), 'value' => \html_writer::link($categoryurl, $categoryname)));
if (has_capability('moodle/site:accessallgroups', $course->get_context())) {
$groups = \groups_get_course_data($course->id);
$details += array('groupings' => array('key' => \get_string('groupings', 'group'), 'value' => count($groups->groupings)), 'groups' => array('key' => \get_string('groups'), 'value' => count($groups->groups)));
}
if ($canaccess) {
$names = \role_get_names($course->get_context());
$sql = 'SELECT ra.roleid, COUNT(ra.id) AS rolecount
FROM {role_assignments} ra
WHERE ra.contextid = :contextid
GROUP BY ra.roleid';
$rolecounts = $DB->get_records_sql($sql, array('contextid' => $course->get_context()->id));
$roledetails = array();
foreach ($rolecounts as $result) {
$a = new \stdClass();
$a->role = $names[$result->roleid]->localname;
$a->count = $result->rolecount;
$roledetails[] = \get_string('assignedrolecount', 'moodle', $a);
}
$details['roleassignments'] = array('key' => \get_string('roleassignments'), 'value' => join('<br />', $roledetails));
}
if ($course->can_review_enrolments()) {
$enrolmentlines = array();
$instances = \enrol_get_instances($course->id, true);
$plugins = \enrol_get_plugins(true);
foreach ($instances as $instance) {
if (!isset($plugins[$instance->enrol])) {
// Weird.
continue;
}
$plugin = $plugins[$instance->enrol];
$enrolmentlines[] = $plugin->get_instance_name($instance);
}
$details['enrolmentmethods'] = array('key' => \get_string('enrolmentmethods'), 'value' => join('<br />', $enrolmentlines));
}
if ($canaccess) {
$details['format'] = array('key' => \get_string('format'), 'value' => \course_get_format($course)->get_format_name());
$details['sections'] = array('key' => \get_string('sections'), 'value' => join('<br />', $sections));
$details['modulesused'] = array('key' => \get_string('modulesused'), 'value' => join('<br />', $modules));
}
return $details;
}
示例3: __construct
/**
* Sets up the table.
*
* @param string $uniqueid Unique id of table.
* @param moodle_url $url The base URL.
*/
public function __construct($uniqueid, $url)
{
global $CFG;
parent::__construct($uniqueid);
$context = context_system::instance();
$this->context = $context;
$this->rolenames = role_get_names();
// This object should not be used without the right permissions.
require_capability('moodle/role:manage', $context);
$this->useridfield = 'userid';
// Define columns in the table.
$this->define_table_columns();
$this->define_baseurl($url);
// Define configs.
$this->define_table_configs();
}
示例4: get_filter_options
/**
* Retrieve the list of available filter options.
*
* @return array An array whose keys are the valid options
* And whose values are the values to display
*/
public static function get_filter_options()
{
$allroles = role_get_names(null, ROLENAME_ALIAS);
$roles = [];
foreach ($allroles as $role) {
if ($role->archetype === 'guest') {
// No point in including the 'guest' role as it isn't possible to show tours to a guest.
continue;
}
$roles[$role->shortname] = $role->localname;
}
// Add the Site Administrator pseudo-role.
$roles[self::ROLE_SITEADMIN] = get_string('administrator', 'core');
// Sort alphabetically too.
\core_collator::asort($roles);
return $roles;
}
示例5: definition
/**
* Definition of this form.
*/
protected function definition()
{
$mform = $this->_form;
$data = $this->_customdata;
$options = array();
$group = get_string('other');
$options[$group] = array();
$options[$group][0] = get_string('norole', 'core_role');
$group = get_string('role', 'core');
$options[$group] = array();
foreach (role_get_names(null, ROLENAME_BOTH) as $role) {
// Allow reset to self too, it may be useful when importing incomplete XML preset.
$options[$group][$role->id] = $role->localname;
}
$group = get_string('archetype', 'core_role');
$options[$group] = array();
foreach (get_role_archetypes() as $type) {
$options[$group][$type] = get_string('archetype' . $type, 'core_role');
}
$mform->addElement('header', 'presetheader', get_string('roleresetdefaults', 'core_role'));
$mform->addElement('selectgroups', 'resettype', get_string('roleresetrole', 'core_role'), $options);
$mform->addElement('filepicker', 'rolepreset', get_string('rolerepreset', 'core_role'));
if ($data['roleid']) {
$mform->addElement('header', 'resetheader', get_string('resetrole', 'core_role'));
$mform->addElement('advcheckbox', 'shortname', get_string('roleshortname', 'core_role'));
$mform->addElement('advcheckbox', 'name', get_string('customrolename', 'core_role'));
$mform->addElement('advcheckbox', 'description', get_string('customroledescription', 'core_role'));
$mform->addElement('advcheckbox', 'archetype', get_string('archetype', 'core_role'));
$mform->addElement('advcheckbox', 'contextlevels', get_string('maybeassignedin', 'core_role'));
$mform->addElement('advcheckbox', 'allowassign', get_string('allowassign', 'core_role'));
$mform->addElement('advcheckbox', 'allowoverride', get_string('allowoverride', 'core_role'));
$mform->addElement('advcheckbox', 'allowswitch', get_string('allowswitch', 'core_role'));
$mform->addElement('advcheckbox', 'permissions', get_string('permissions', 'core_role'));
}
$mform->addElement('hidden', 'roleid');
$mform->setType('roleid', PARAM_INT);
$mform->addElement('hidden', 'action');
$mform->setType('action', PARAM_ALPHA);
$mform->addElement('hidden', 'return');
$mform->setType('return', PARAM_ALPHA);
$this->add_action_buttons(true, get_string('continue', 'core'));
$this->set_data($data);
}
示例6: facetoface_get_session_involvement
/**
* Get session info and role description from get_sessions_within output
*
* @access public
* @param object $user User this $info relates to
* @param object $info Single result from facetoface_get_sessions_within()
* @return string
*/
function facetoface_get_session_involvement($user, $info) {
global $USER;
// Data to pass to lang string
$data = new object();
// Session time data
$data->timestart = userdate($info->timestart, get_string('strftimetime'));
$data->timefinish = userdate($info->timefinish, get_string('strftimetime'));
$data->datestart = userdate($info->timestart, get_string('strftimedate'));
$data->datefinish = userdate($info->timefinish, get_string('strftimedate'));
$data->datetimestart = userdate($info->timestart, get_string('strftimedatetime'));
$data->datetimefinish = userdate($info->timefinish, get_string('strftimedatetime'));
// Session name/link
$data->session = html_writer::link(new moodle_url('/mod/facetoface/view.php', array('f' => $info->f2fid)), format_string($info->name));
// User's participation
if (!empty($info->roleid)) {
// Load roles (and cache)
static $roles;
if (!isset($roles)) {
$context = context_course::instance($info->courseid);
$roles = role_get_names($context);
}
// Check if role exists
if (!isset($roles[$info->roleid])) {
print_error('error:rolenotfound');
}
$data->participation = format_string($roles[$info->roleid]->localname);
$strkey = "error:userassigned";
} else {
$strkey = "error:userbooked";
}
// Check if start/finish on the same day
$strkey .= "sessionconflict";
if ($data->datestart == $data->datefinish) {
$strkey .= "sameday";
} else {
$strkey .= "multiday";
}
if ($user->id == $USER->id) {
$strkey .= "selfsignup";
}
$data->fullname = fullname($user);
return get_string($strkey, 'facetoface', $data);
}
示例7: recipientsform
public function recipientsform($courseid, $userid) {
global $COURSE, $DB;
$options = array();
$owngroups = groups_get_user_groups($courseid, $userid);
$content = html_writer::start_tag('div', array('id' => 'local_mail_recipients_form', 'class' => 'local_mail_form mail_hidden'));
if ($COURSE->groupmode == SEPARATEGROUPS and empty($owngroups[0])) {
return '';
}
$content .= html_writer::start_tag('div', array('class' => 'mail_recipients_toolbar'));
// Roles
$context = context_course::instance($courseid);
$roles = role_get_names($context);
$userroles = local_mail_get_user_roleids($userid, $context);
$mailsamerole = has_capability('local/mail:mailsamerole', $context);
foreach ($roles as $key => $role) {
$count = $DB->count_records_select('role_assignments', "contextid = :contextid AND roleid = :roleid AND userid <> :userid",
array('contextid' => $context->id, 'roleid' => $role->id, 'userid' => $userid));
if (($count && $mailsamerole)
|| ($count && !$mailsamerole && !in_array($role->id, $userroles))) {
$options[$key] = $role->localname;
}
}
$text = get_string('role', 'moodle');
$content .= html_writer::start_tag('span', array('class' => 'roleselector'));
$content .= html_writer::label($text, 'local_mail_roles');
$text = get_string('all', 'local_mail');
$content .= html_writer::select($options, 'local_mail_roles', '', array('' => $text), array('id' => 'local_mail_recipients_roles', 'class' => ''));
$content .= html_writer::end_tag('span');
// Groups
$groups = groups_get_all_groups($courseid);
if ($COURSE->groupmode == NOGROUPS or ($COURSE->groupmode == VISIBLEGROUPS and empty($groups))) {
$content .= html_writer::tag('span', get_string('allparticipants', 'moodle'), array('class' => 'groupselector groupname'));
} else {
if ($COURSE->groupmode == VISIBLEGROUPS or has_capability('moodle/site:accessallgroups', $context)) {
unset($options);
foreach ($groups as $key => $group) {
$options[$key] = $group->name;
}
$text = get_string('group', 'moodle');
$content .= html_writer::start_tag('span', array('class' => 'groupselector'));
$content .= html_writer::label($text, 'local_mail_recipients_groups');
$text = get_string('allparticipants', 'moodle');
$content .= html_writer::select($options, 'local_mail_recipients_groups', '', array('' => $text), array('id' => 'local_mail_recipients_groups', 'class' => ''));
$content .= html_writer::end_tag('span');
} else if (count($owngroups[0]) == 1) {// SEPARATEGROUPS and user in only one group
$text = get_string('group', 'moodle');
$content .= html_writer::start_tag('span', array('class' => 'groupselector'));
$content .= html_writer::label("$text: ", null);
$content .= html_writer::tag('span', groups_get_group_name($owngroups[0][0]), array('class' => 'groupname'));
$content .= html_writer::end_tag('span');
} else if (count($owngroups[0]) > 1) {// SEPARATEGROUPS and user in several groups
unset($options);
foreach ($owngroups[0] as $key => $group) {
$options[$group] = groups_get_group_name($group);
}
$text = get_string('group', 'moodle');
$content .= html_writer::start_tag('span', array('class' => 'groupselector'));
$content .= html_writer::label($text, 'local_mail_recipients_groups');
$text = get_string('allparticipants', 'moodle');
$content .= html_writer::select($options, 'local_mail_recipients_groups', '',
array(key($options) => current($options)), array('id' => 'local_mail_recipients_groups', 'class' => ''));
$content .= html_writer::end_tag('span');
}
}
$content .= html_writer::tag('div', '', array('class' => 'mail_separator'));
// Search
$content .= html_writer::start_tag('div', array('class' => 'mail_recipients_search'));
$attributes = array(
'type' => 'text',
'name' => 'recipients_search',
'value' => '',
'maxlength' => '100',
'class' => 'mail_search'
);
$text = get_string('search', 'local_mail');
$content .= html_writer::label($text, 'recipients_search');
$content .= html_writer::empty_tag('input', $attributes);
// Select all recipients
$content .= html_writer::start_tag('span', array('class' => 'mail_all_recipients_actions'));
$attributes = array(
'type' => 'button',
'name' => "to_all",
'value' => get_string('to', 'local_mail')
);
$content .= html_writer::empty_tag('input', $attributes);
$attributes = array(
'type' => 'button',
'name' => "cc_all",
'value' => get_string('cc', 'local_mail')
);
$content .= html_writer::empty_tag('input', $attributes);
$attributes = array(
'type' => 'button',
'name' => "bcc_all",
'value' => get_string('bcc', 'local_mail')
);
//.........这里部分代码省略.........
示例8: get_filter_options
/**
* Retrieve the list of available filter options.
*
* @return array An array whose keys are the valid options
* And whose values are the values to display
*/
public static function get_filter_options()
{
return role_get_names(null, ROLENAME_ALIAS, true);
}
示例9: getVcrRoleByContext
public function getVcrRoleByContext($userId, $context)
{
$listRole = get_user_roles($context, $userId, false);
//Student-Teacher-POVH
$listRoleDetail = role_get_names($context);
$roleString = "";
foreach ($listRole as $item) {
$archetype = $listRoleDetail[$item->roleid]->archetype;
if ($archetype == "manager" || $archetype == "coursecreator") {
$roleString = 'povh';
break;
} else {
if ($archetype == "teacher" || $archetype == "editingteacher") {
$roleString = 'teacher';
break;
} else {
$roleString = 'student';
}
}
}
return $roleString;
}
示例10: get_allow_role_control
/**
* Returns an array of roles with the allowed type.
*
* @param string $type Must be one of: assign, switch, or override.
* @return array Am array of role names with the allowed type
*/
protected function get_allow_role_control($type)
{
if ($type !== 'assign' and $type !== 'switch' and $type !== 'override') {
debugging('Invalid role allowed type specified', DEBUG_DEVELOPER);
return '';
}
$property = 'allow' . $type;
$selected = $this->{$property};
$options = array();
foreach (role_get_names(null, ROLENAME_ALIAS) as $role) {
$options[$role->id] = $role->localname;
}
if ($this->roleid == 0) {
$options[-1] = get_string('thisnewrole', 'core_role');
}
return html_writer::select($options, 'allow' . $type . '[]', $selected, false, array('multiple' => 'multiple', 'size' => 10));
}
示例11: definition
//.........这里部分代码省略.........
$mform->setType('duration', PARAM_TEXT);
$mform->addHelpButton('duration', 'duration', 'facetoface');
if (!get_config(NULL, 'facetoface_hidecost')) {
$formarray = array();
$formarray[] = $mform->createElement('text', 'normalcost', get_string('normalcost', 'facetoface'), 'size="5"');
$formarray[] = $mform->createElement('static', 'normalcosthint', '', html_writer::tag('span', get_string('normalcosthinttext','facetoface'), array('class' => 'hint-text')));
$mform->addGroup($formarray,'normalcost_group', get_string('normalcost','facetoface'), array(' '),false);
$mform->setType('normalcost', PARAM_TEXT);
$mform->addHelpButton('normalcost_group', 'normalcost', 'facetoface');
if (!get_config(NULL, 'facetoface_hidediscount')) {
$formarray = array();
$formarray[] = $mform->createElement('text', 'discountcost', get_string('discountcost', 'facetoface'), 'size="5"');
$formarray[] = $mform->createElement('static', 'discountcosthint', '', html_writer::tag('span', get_string('discountcosthinttext','facetoface'), array('class' => 'hint-text')));
$mform->addGroup($formarray,'discountcost_group', get_string('discountcost','facetoface'), array(' '),false);
$mform->setType('discountcost', PARAM_TEXT);
$mform->addHelpButton('discountcost_group', 'discountcost', 'facetoface');
}
}
$mform->addElement('editor', 'details_editor', get_string('details', 'facetoface'), null, $editoroptions);
$mform->setType('details_editor', PARAM_RAW);
$mform->addHelpButton('details_editor', 'details', 'facetoface');
// Choose users for trainer roles
$context = context_course::instance($this->_customdata['course']->id);
$roles = facetoface_get_trainer_roles($context);
if ($roles) {
// Get current trainers
$current_trainers = facetoface_get_trainers($this->_customdata['s']);
// Get course context and roles
$rolenames = role_get_names($context);
// Loop through all selected roles
$header_shown = false;
foreach ($roles as $role) {
$rolename = format_string($rolenames[$role->id]->localname);
// Attempt to load users with this role in this context.
$rs = get_role_users($role->id, $context, true, 'u.id, u.firstname, u.lastname', 'u.id ASC');
if (!$rs) {
continue;
}
$choices = array();
foreach ($rs as $roleuser) {
$choices[$roleuser->id] = fullname($roleuser);
}
// Show header (if haven't already)
if ($choices && !$header_shown) {
$mform->addElement('header', 'trainerroles', get_string('sessionroles', 'facetoface'));
$header_shown = true;
}
// If only a few, use checkboxes
if (count($choices) < 4) {
$role_shown = false;
foreach ($choices as $cid => $choice) {
// Only display the role title for the first checkbox for each role
if (!$role_shown) {
$roledisplay = $rolename;
$role_shown = true;
} else {
示例12: get_user_roles_with_special
}
break;
case CONTEXT_MODULE:
$PAGE->set_heading($context->get_context_name(false));
$PAGE->set_cacheable(false);
break;
case CONTEXT_BLOCK:
$PAGE->set_heading($PAGE->course->fullname);
break;
}
// Get the list of the reported-on user's role assignments - must be after
// the page setup code above, or the language might be wrong.
$reportuser = $userselector->get_selected_user();
if (!is_null($reportuser)) {
$roleassignments = get_user_roles_with_special($context, $reportuser->id);
$rolenames = role_get_names($context);
}
echo $OUTPUT->header();
// Print heading.
echo $OUTPUT->heading($title);
// If a user has been chosen, show all the permissions for this user.
if (!is_null($reportuser)) {
echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide');
if (!empty($roleassignments)) {
echo $OUTPUT->heading(get_string('rolesforuser', 'core_role', fullname($reportuser)), 3);
echo html_writer::start_tag('ul');
$systemcontext = context_system::instance();
foreach ($roleassignments as $ra) {
$racontext = context::instance_by_id($ra->contextid);
$link = html_writer::link($racontext->get_url(), $racontext->get_context_name());
$rolename = $rolenames[$ra->roleid]->localname;
示例13: get_context_roles_menu
/**
*
*/
protected function get_context_roles_menu()
{
$context = $this->_field->df->context;
return role_get_names($context, ROLENAME_ALIAS, true);
}
示例14: test_get_filter_options_no_guest_roles
/**
* Test that the get_filter_options function does not include the guest roles.
*/
public function test_get_filter_options_no_guest_roles()
{
create_role('Test Role', 'testrole', 'This is a test role', 'guest');
$allroles = role_get_names(null, ROLENAME_ALIAS);
$options = \tool_usertours\local\filter\role::get_filter_options();
foreach ($allroles as $role) {
$hasrole = isset($options[$role->shortname]);
if ($role->archetype === 'guest') {
$this->assertFalse($hasrole);
} else {
$this->assertTrue($hasrole);
}
}
}