/** * 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')); }
/** * 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; }
/** * 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(); }
/** * 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; }
/** * 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); }
/** * 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); }
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') ); $content .= html_writer::empty_tag('input', $attributes); $attributes = array('type' => 'image', 'name' => "remove_all", 'src' => $this->output->pix_url('t/delete'), 'alt' => get_string('remove')); $content .= html_writer::empty_tag('input', $attributes); $content .= html_writer::end_tag('span'); $content .= html_writer::end_tag('div'); $content .= html_writer::end_tag('div'); $content .= html_writer::tag('div', '', array('id' => 'local_mail_recipients_list', 'class' => 'mail_form_recipients')); $content .= html_writer::start_tag('div', array('class' => 'mail_recipients_loading')); $content .= $this->output->pix_icon('i/loading', get_string('actions'), 'moodle', array('class' => 'loading_icon')); $content .= html_writer::end_tag('div'); $content .= html_writer::end_tag('div'); return $content; }
/** * 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); }
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; }
/** * 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)); }
function definition() { global $CFG, $DB; $mform =& $this->_form; $mform->addElement('hidden', 'id', $this->_customdata['id']); $mform->addElement('hidden', 'f', $this->_customdata['f']); $mform->addElement('hidden', 's', $this->_customdata['s']); $mform->addElement('hidden', 'c', $this->_customdata['c']); $mform->setType('id', PARAM_INT); $mform->setType('f', PARAM_INT); $mform->setType('s', PARAM_INT); $mform->setType('c', PARAM_INT); $mform->addElement('header', 'general', get_string('general', 'form')); $editoroptions = $this->_customdata['editoroptions']; // Show all custom fields $customfields = $this->_customdata['customfields']; facetoface_add_customfields_to_form($mform, $customfields); $formarray = array(); $formarray[] = $mform->createElement('selectyesno', 'datetimeknown', get_string('sessiondatetimeknown', 'facetoface')); $formarray[] = $mform->createElement('static', 'datetimeknownhint', '', html_writer::tag('span', get_string('datetimeknownhinttext','facetoface'), array('class' => 'hint-text'))); $mform->addGroup($formarray,'datetimeknown_group', get_string('sessiondatetimeknown','facetoface'), array(' '),false); $mform->addGroupRule('datetimeknown_group', null, 'required', null, 'client'); $mform->setDefault('datetimeknown', false); $mform->addHelpButton('datetimeknown_group', 'sessiondatetimeknown', 'facetoface'); $repeatarray = array(); $timezones = get_clean_timezone_list(true); $timezones[get_string('sessiontimezoneunknown', 'facetoface')] = get_string('sessiontimezoneunknown', 'facetoface'); $repeatarray[] = &$mform->createElement('hidden', 'sessiondateid', 0); $repeatarray[] = $mform->createElement('select', 'sessiontimezone', get_string('sessiontimezone', 'facetoface'), $timezones); $repeatarray[] = &$mform->createElement('date_time_selector', 'timestart', get_string('timestart', 'facetoface')); $repeatarray[] = &$mform->createElement('date_time_selector', 'timefinish', get_string('timefinish', 'facetoface')); $checkboxelement = &$mform->createElement('checkbox', 'datedelete', '', get_string('dateremove', 'facetoface')); unset($checkboxelement->_attributes['id']); // necessary until MDL-20441 is fixed $repeatarray[] = $checkboxelement; $repeatarray[] = &$mform->createElement('html', html_writer::empty_tag('br')); // spacer $repeatcount = $this->_customdata['nbdays']; $repeatoptions = array(); $repeatoptions['timestart']['disabledif'] = array('datetimeknown', 'eq', 0); $repeatoptions['timefinish']['disabledif'] = array('datetimeknown', 'eq', 0); $repeatoptions['sessiontimezone']['disabledif'] = array('datetimeknown', 'eq', 0); $repeatoptions['sessiontimezone']['default'] = $this->_customdata['defaulttimezone']; $mform->setType('timestart', PARAM_INT); $mform->setType('timefinish', PARAM_INT); $mform->setType('sessiontimezone', PARAM_TEXT); $mform->setType('sessiondateid', PARAM_INT); $this->repeat_elements($repeatarray, $repeatcount, $repeatoptions, 'date_repeats', 'date_add_fields', 1, get_string('dateadd', 'facetoface'), true); // Rooms form $pdroom = ''; $roomnote = ''; if (!empty($this->_customdata['s'])) { $sql = "SELECT r.* FROM {facetoface_sessions} s INNER JOIN {facetoface_room} r ON s.roomid = r.id WHERE s.id = ? AND r.custom = 0"; $params = array($this->_customdata['s']); if ($room = $DB->get_record_sql($sql, $params)) { $pdroom = $room->name.', '.$room->building.', '.$room->address.', '.$room->description." (".get_string('capacity', 'facetoface').": ".$room->capacity.")"; $pdroom = format_string($pdroom); if ($room->type == 'external') { $roomnote = '<br><em>'.get_string('roommustbebookedtoexternalcalendar', 'facetoface').'</em>'; } } } $mform->addElement('static', 'predefinedroom', get_string('room', 'facetoface'), '<span id="pdroom">'.$pdroom.'</span><span id="roomnote">'.$roomnote.'</span>'); $mform->addElement('static', 'addpdroom', '', '<input type="button" value="'.get_string('choosepredefinedroom', 'facetoface').'" name="show-addpdroom-dialog" id="show-addpdroom-dialog" />'); $mform->addElement('hidden', 'pdroomid', 0); $mform->setType('pdroomid', PARAM_INT); $mform->addElement('hidden', 'pdroomcapacity', 0); $mform->setType('pdroomcapacity', PARAM_INT); $mform->addElement('checkbox', 'customroom', '', get_string('otherroom', 'facetoface')); $mform->setType('customroom', PARAM_INT); $mform->disabledIf('customroom', 'datetimeknown', 'eq', 0); $mform->addElement('html', '<div class="fitem"><div class="fitemtitle"></div><table><tr><td>'); $mform->addElement('static', '', '', get_string('roomname', 'facetoface')); $mform->addElement('html', '</td><td>'); $mform->addElement('static', '', '', get_string('building', 'facetoface')); $mform->addElement('html', '</td><td>'); $mform->addElement('static', '', '', get_string('address', 'facetoface')); $mform->addElement('html', '</td><td>'); $mform->addElement('static', '', '', get_string('capacity', 'facetoface')); $mform->addElement('html', '</td></tr><td>'); $mform->addElement('text', 'croomname', array(), array('class' => 'cellwidth', 'maxlength' => '90')); $mform->setType('croomname', PARAM_TEXT); $mform->disabledIf('croomname', 'customroom', 'notchecked'); $mform->addElement('html', '</td><td>'); $mform->addElement('text', 'croombuilding', array(), array('class' => 'cellwidth', 'maxlength' => '90')); $mform->setType('croombuilding', PARAM_TEXT); $mform->disabledIf('croombuilding', 'customroom', 'notchecked'); $mform->addElement('html', '</td><td>'); $mform->addElement('text', 'croomaddress', array(), array('class' => 'cellwidth', 'maxlength' => '230')); $mform->setType('croomaddress', PARAM_TEXT); $mform->disabledIf('croomaddress', 'customroom', 'notchecked'); $mform->addElement('html', '</td><td>'); $mform->addElement('text', 'croomcapacity', array(), array('class' => 'cellwidth', 'maxlength' => '10')); $mform->disabledIf('croomcapacity', 'customroom', 'notchecked'); $mform->setType('croomcapacity', PARAM_INT); $mform->addElement('html', '</td><tr></table></div>'); $mform->addElement('text', 'capacity', get_string('capacity', 'facetoface'), 'size="5"'); $mform->addRule('capacity', null, 'required', null, 'client'); $mform->setType('capacity', PARAM_INT); $mform->setDefault('capacity', 10); $mform->addRule('capacity', null, 'numeric', null, 'client'); $mform->addHelpButton('capacity', 'capacity', 'facetoface'); $mform->addElement('checkbox', 'allowoverbook', get_string('allowoverbook', 'facetoface')); $mform->addHelpButton('allowoverbook', 'allowoverbook', 'facetoface'); $mform->addElement('text', 'duration', get_string('duration', 'facetoface'), 'size="5"'); $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 { $roledisplay = ''; } $mform->addElement('advcheckbox', 'trainerrole['.$role->id.']['.$cid.']', $roledisplay, $choice, null, array('', $cid)); $mform->setType('trainerrole['.$role->id.']['.$cid.']', PARAM_INT); } } else { $mform->addElement('select', 'trainerrole['.$role->id.']', $rolename, $choices, array('multiple' => 'multiple')); $mform->setType('trainerrole['.$role->id.']', PARAM_SEQUENCE); } // Select current trainers if ($current_trainers) { foreach ($current_trainers as $roleid => $trainers) { $t = array(); foreach ($trainers as $trainer) { $t[] = $trainer->id; $mform->setDefault('trainerrole['.$roleid.']['.$trainer->id.']', $trainer->id); } $mform->setDefault('trainerrole['.$roleid.']', implode(',', $t)); } } } } // If conflicts are disabled if (!empty($CFG->facetoface_allowschedulingconflicts)) { $mform->addElement('selectyesno', 'allowconflicts', get_string('allowschedulingconflicts', 'facetoface')); $mform->setDefault('allowconflicts', 0); // defaults to 'no' $mform->addHelpButton('allowconflicts', 'allowschedulingconflicts', 'facetoface'); $mform->setType('allowconflicts', PARAM_BOOL); } $this->add_action_buttons(); }
} 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;
/** * */ protected function get_context_roles_menu() { $context = $this->_field->df->context; return role_get_names($context, ROLENAME_ALIAS, true); }
/** * 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); } } }