本文整理汇总了PHP中get_users_by_capability函数的典型用法代码示例。如果您正苦于以下问题:PHP get_users_by_capability函数的具体用法?PHP get_users_by_capability怎么用?PHP get_users_by_capability使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_users_by_capability函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get_users_by_capability
/**
* Gets users on course who have the specified capability. Returns an array
* of user objects which only contain the 'id' field. If the same capability
* has already been checked (e.g. by another condition) then a cached
* result will be used.
*
* More fields are not necessary because this code is only used to filter
* users from an existing list.
*
* @param string $capability Required capability
* @return array Associative array of user id => objects containing only id
*/
public function get_users_by_capability($capability)
{
if (!array_key_exists($capability, $this->cache)) {
$this->cache[$capability] = get_users_by_capability($this->context, $capability, 'u.id');
}
return $this->cache[$capability];
}
示例2: print_filter
function print_filter(&$mform)
{
global $remotedb, $COURSE;
//$filter_user = optional_param('filter_user',0,PARAM_INT);
$reportclassname = 'report_' . $this->report->type;
$reportclass = new $reportclassname($this->report);
if ($this->report->type != 'sql') {
$components = cr_unserialize($this->report->components);
$conditions = $components['conditions'];
$userlist = $reportclass->elements_by_conditions($conditions);
} else {
$coursecontext = context_course::instance($COURSE->id);
$userlist = array_keys(get_users_by_capability($coursecontext, 'moodle/user:viewdetails'));
}
$useroptions = array();
$useroptions[0] = get_string('filter_all', 'block_configurable_reports');
if (!empty($userlist)) {
list($usql, $params) = $remotedb->get_in_or_equal($userlist);
$users = $remotedb->get_records_select('user', "id {$usql}", $params);
foreach ($users as $c) {
$useroptions[$c->id] = format_string($c->lastname . ' ' . $c->firstname);
}
}
$mform->addElement('select', 'filter_user', get_string('user'), $useroptions);
$mform->setType('filter_user', PARAM_INT);
}
示例3: get_admins
/**
* Returns list of all admins
*
* @uses $CFG
* @return object
*/
function get_admins()
{
global $CFG;
$context = get_context_instance(CONTEXT_SYSTEM, SITEID);
return get_users_by_capability($context, 'moodle/site:doanything', 'u.*, ra.id as adminid', 'ra.id ASC');
// only need first one
}
示例4: choice_get_response_data
function choice_get_response_data($choice, $cm, $groupmode)
{
global $CFG, $USER;
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
/// Get the current group
if ($groupmode > 0) {
$currentgroup = groups_get_activity_group($cm);
} else {
$currentgroup = 0;
}
/// Initialise the returned array, which is a matrix: $allresponses[responseid][userid] = responseobject
$allresponses = array();
/// First get all the users who have access here
/// To start with we assume they are all "unanswered" then move them later
$allresponses[0] = get_users_by_capability($context, 'mod/choice:choose', 'u.id, u.picture, u.firstname, u.lastname, u.idnumber', 'u.firstname ASC', '', '', $currentgroup, '', false, true);
/// Get all the recorded responses for this choice
$rawresponses = get_records('choice_answers', 'choiceid', $choice->id);
/// Use the responses to move users into the correct column
if ($rawresponses) {
foreach ($rawresponses as $response) {
if (isset($allresponses[0][$response->userid])) {
// This person is enrolled and in correct group
$allresponses[0][$response->userid]->timemodified = $response->timemodified;
$allresponses[$response->optionid][$response->userid] = clone $allresponses[0][$response->userid];
unset($allresponses[0][$response->userid]);
// Remove from unanswered column
}
}
}
return $allresponses;
}
示例5: get_professor
function get_professor($course_id)
{
$context = get_context_instance(CONTEXT_COURSE, $course_id);
$users = get_users_by_capability($context, 'moodle/course:managegroups', 'u.id, u.firstname, u.lastname, u.email, u.mailformat, u.phone2', 'lastname ASC, firstname DESC');
$advanced_users = get_users_by_capability($context, 'moodle/course:create', 'u.id', 'lastname ASC, firstname DESC');
foreach ($advanced_users as $key => $value) {
unset($users[$key]);
}
return current($users);
}
示例6: virtualclass_course_teacher_list
function virtualclass_course_teacher_list()
{
global $COURSE;
$courseid = $COURSE->id;
$context = context_course::instance($courseid);
$heads = get_users_by_capability($context, 'moodle/course:update');
$teachers = array();
foreach ($heads as $head) {
$teachers[$head->id] = fullname($head);
}
return $teachers;
}
示例7: definition
/**
* Sets up form for display to user
* @global object $CFG Moodle global config
* @version 2015062901
* @since 2011042601
*/
public function definition()
{
global $CFG;
global $PAGE;
$accountDAO = new TxttoolsAccountDAO();
$accountCount = $accountDAO->countTxttoolsRecords();
$PAGE->requires->jquery();
$PAGE->requires->yui_module('moodle-block_moodletxt-admin', 'M.block_moodletxt.admin.init');
$installForm =& $this->_form;
// We need a list of users that can be default inboxes,
// for the user to choose from for this initial account
$defaultInboxUsers = get_users_by_capability(context_system::instance(), 'block/moodletxt:defaultinbox');
$admins = get_admins();
foreach ($admins as $admin) {
$defaultInboxUsers[$admin->id] = $admin;
}
$defaultInboxList = array();
foreach ($defaultInboxUsers as $defaultInboxUser) {
$defaultInboxList[$defaultInboxUser->id] = MoodletxtStringHelper::formatNameForDisplay($defaultInboxUser->firstname, $defaultInboxUser->lastname, $defaultInboxUser->username);
}
$ctxtInstances = array();
$ctxtInstances[TxttoolsAccount::$UK_LOCATION] = TxttoolsAccount::$UK_LOCATION . ' - ' . TxttoolsAccount::$UK_URL;
$ctxtInstances[TxttoolsAccount::$US_LOCATION] = TxttoolsAccount::$US_LOCATION . ' - ' . TxttoolsAccount::$US_URL;
$ctxtInstances['URL'] = 'Custom';
// Txttools account
$installForm->addElement('header', 'addAccount', get_string('adminlabeladdaccount', 'block_moodletxt'));
if ($accountCount < 1) {
$installForm->addElement('select', 'accountCtxtInstance', get_string('adminaccountctxtinstance', 'block_moodletxt'), $ctxtInstances);
$installForm->setType('accountCtxtInstance', PARAM_STRINGID);
$installForm->addElement('text', 'accountUrl', get_string('adminaccounturl', 'block_moodletxt'));
$installForm->setType('accountUrl', PARAM_URL);
}
$installForm->addElement('text', 'accountName', get_string('adminlabelaccusername', 'block_moodletxt'), array('maxlength' => 20));
$installForm->setType('accountName', PARAM_ALPHANUMEXT);
$installForm->addRule('accountName', get_string('errornousername', 'block_moodletxt'), 'required');
$installForm->addElement('password', 'accountPassword1', get_string('adminlabelaccpassword', 'block_moodletxt'));
$installForm->setType('accountPassword1', PARAM_ALPHANUMEXT);
$installForm->addRule('accountPassword1', get_string('errornopassword', 'block_moodletxt'), 'required');
$installForm->addRule('accountPassword1', get_string('errorpasswordtooshort', 'block_moodletxt'), 'minlength', 8);
$installForm->addElement('password', 'accountPassword2', get_string('adminlabelaccpassword2', 'block_moodletxt'));
$installForm->setType('accountPassword2', PARAM_ALPHANUMEXT);
$installForm->addRule('accountPassword2', get_string('errornopassword', 'block_moodletxt'), 'required');
$installForm->addRule('accountPassword2', get_string('errorpasswordtooshort', 'block_moodletxt'), 'minlength', 8);
$installForm->addElement('text', 'accountDescription', get_string('adminlabelaccdesc', 'block_moodletxt'));
$installForm->setType('accountDescription', PARAM_TEXT);
$installForm->addElement('select', 'accountDefaultInbox', get_string('adminlabelaccinbox', 'block_moodletxt'), $defaultInboxList);
$installForm->setType('accountDefaultInbox', PARAM_INT);
// Buttons
$buttonarray = array();
$buttonarray[] =& $installForm->createElement('submit', 'submitButton', get_string('adminbutaddaccount', 'block_moodletxt'));
$installForm->addGroup($buttonarray, 'buttonar', '', array(' '), false);
$installForm->closeHeaderBefore('buttonar');
}
示例8: definition
public function definition()
{
global $USER, $OUTPUT, $CFG;
$mform = $this->_form;
$instance = $this->_customdata;
$this->instance = $instance;
$plugin = enrol_get_plugin('boleto');
$heading = $plugin->get_instance_name($instance);
$mform->addElement('header', 'boletoheader', $heading);
if ($instance->password) {
// Change the id of boleto enrolment key input as there can be multiple boleto enrolment methods.
$mform->addElement('passwordunmask', 'enrolpassword', get_string('password', 'enrol_boleto'), array('id' => 'enrolpassword_' . $instance->id));
$context = context_course::instance($this->instance->courseid);
$keyholders = get_users_by_capability($context, 'enrol/boleto:holdkey', user_picture::fields('u'));
$keyholdercount = 0;
foreach ($keyholders as $keyholder) {
$keyholdercount++;
if ($keyholdercount === 1) {
$mform->addElement('static', 'keyholder', '', get_string('keyholder', 'enrol_boleto'));
}
$keyholdercontext = context_user::instance($keyholder->id);
if ($USER->id == $keyholder->id || has_capability('moodle/user:viewdetails', context_system::instance()) || has_coursecontact_role($keyholder->id)) {
$profilelink = '<a href="' . $CFG->wwwroot . '/user/view.php?id=' . $keyholder->id . '&course=' . $this->instance->courseid . '">' . fullname($keyholder) . '</a>';
} else {
$profilelink = fullname($keyholder);
}
$profilepic = $OUTPUT->user_picture($keyholder, array('size' => 35, 'courseid' => $this->instance->courseid));
$mform->addElement('static', 'keyholder' . $keyholdercount, '', $profilepic . $profilelink);
}
}
$boletourl = new moodle_url('/enrol/boleto/boleto.php', array('instanceid' => $this->instance->id));
$mform->addElement('static', 'info', '', get_string('boletoprintandpayinfo', 'enrol_boleto'));
// customint8 == avista.
if ($this->instance->customint8) {
$mform->addElement('static', 'info', '', get_string('boletoprintandpayinfodirectlinks', 'enrol_boleto', $boletourl->out(false)));
} else {
$mform->addElement('static', 'info', '', get_string('boletoprintandpayinfoparceladolink0', 'enrol_boleto', $boletourl->out(false)));
$boletourl->param('parcela', 1);
$mform->addElement('static', 'info', '', get_string('boletoprintandpayinfoparceladolink1', 'enrol_boleto', $boletourl->out(false)));
$boletourl->param('parcela', 2);
$mform->addElement('static', 'info', '', get_string('boletoprintandpayinfoparceladolink2', 'enrol_boleto', $boletourl->out(false)));
}
$this->add_action_buttons(false, get_string('enrolme', 'enrol_boleto'));
$mform->addElement('hidden', 'id');
$mform->setType('id', PARAM_INT);
$mform->setDefault('id', $instance->courseid);
$mform->addElement('hidden', 'instance');
$mform->setType('instance', PARAM_INT);
$mform->setDefault('instance', $instance->id);
}
示例9: getallhiddenrecipients
function getallhiddenrecipients($cid, $bid)
{
global $sid;
$debug = false;
if ($cid == 1) {
$blockcontext = get_context_instance(CONTEXT_SYSTEM, $sid);
} else {
$blockcontext = get_context_instance(CONTEXT_BLOCK, $bid);
}
$hiddenrecipients = get_users_by_capability($blockcontext, 'block/contact_form:hiddenrecipient', 'u.id, u.firstname, u.lastname, u.email, u.mailformat', 'u.lastname ASC', '', '', '', '', false);
if ($debug) {
echo '****** Written from line ' . __LINE__ . ' of ' . __FILE__ . ' ********<br />';
echo '<hr />';
echo 'hiddencollector (block/contact_form:hiddenrecipients)<br />';
print_object($hiddenrecipients);
}
return $hiddenrecipients;
}
示例10: load_relevant_students
/**
* Get information about which students to show in the report.
* @param object $cm the coures module.
* @return an array with four elements:
* 0 => integer the current group id (0 for none).
* 1 => array ids of all the students in this course.
* 2 => array ids of all the students in the current group.
* 3 => array ids of all the students to show in the report. Will be the
* same as either element 1 or 2.
*/
protected function load_relevant_students($cm)
{
$currentgroup = groups_get_activity_group($cm, true);
if (!($students = get_users_by_capability($this->context, array('mod/quiz:reviewmyattempts', 'mod/quiz:attempt'), 'u.id, 1', '', '', '', '', '', false))) {
$students = array();
} else {
$students = array_keys($students);
}
if (empty($currentgroup)) {
return array($currentgroup, $students, array(), $students);
}
// We have a currently selected group.
if (!($groupstudents = get_users_by_capability($this->context, array('mod/quiz:reviewmyattempts', 'mod/quiz:attempt'), 'u.id, 1', '', '', '', $currentgroup, '', false))) {
$groupstudents = array();
} else {
$groupstudents = array_keys($groupstudents);
}
return array($currentgroup, $students, $groupstudents, $groupstudents);
}
示例11: fetch_course_users
function fetch_course_users($courseid)
{
global $CFG, $DB;
//get course and require requester is logged in
if (!($course = $DB->get_record('course', array('id' => $courseid)))) {
print_error('invalidcourseid');
}
require_course_login($course);
//fetch course context
$coursecontext = \context_course::instance($courseid);
//fetch user objects for all users in course
//'u.id, u.username, u.firstname, u.lastname, u.picture'
$users = get_users_by_capability($coursecontext, 'moodle/user:viewdetails');
//usersummary variable
$usersummary = "";
//set up xml to return
$xml_output = "<pairsets>\n";
$pairstreamname = rand(1000000, 9999999);
$xml_output .= "\t<pair name='{$pairstreamname}' dirty='false'>\n";
//fill with user "pairelements"
foreach ($users as $user) {
$xml_output .= "\t\t<pairelement username='" . $user->username . "' showname='" . fullname($user) . "' pictureurl='" . fetch_user_picture($user, 120) . "' />\n";
if ($usersummary == "") {
$usersummary .= $user->username;
} else {
$usersummary .= ";" . $user->username;
}
}
//close our list of users in the pairset
$xml_output .= "\t</pair>\n";
//We also provide a summary of all the users in this course
//so that the laszlo client doesn't need to xml divine it
$xml_output .= "\t<usersummary>\n";
$xml_output .= $usersummary;
$xml_output .= "\t</usersummary>\n";
$xml_output .= "</pairsets>";
//Return the data
return $xml_output;
}
示例12: feedback_get_receivemail_users
/**
* get users which have the receivemail-capability
*
* @uses CONTEXT_MODULE
* @param int $cmid
* @param mixed $groups single groupid or array of groupids - group(s) user is in
* @return object the userrecords
*/
function feedback_get_receivemail_users($cmid, $groups = false) {
if (!$context = get_context_instance(CONTEXT_MODULE, $cmid)) {
print_error('badcontext');
}
//description of the call below:
//get_users_by_capability($context, $capability, $fields='', $sort='', $limitfrom='',
// $limitnum='', $groups='', $exceptions='', $doanything=true)
return get_users_by_capability($context,
'mod/feedback:receivemail',
'',
'lastname',
'',
'',
$groups,
'',
false);
}
示例13: load_choices
/**
* Load all of the uses who have the capability into choice array
*
* @return bool Always returns true
*/
function load_choices()
{
if (is_array($this->choices)) {
return true;
}
$users = get_users_by_capability(get_context_instance(CONTEXT_SYSTEM), $this->capability, 'u.id,u.username,u.firstname,u.lastname', 'u.lastname,u.firstname');
$this->choices = array('$@NONE@$' => get_string('nobody'), '$@ALL@$' => get_string('everyonewhocan', 'admin', get_capability_string($this->capability)));
if ($this->includeadmins) {
$admins = get_admins();
foreach ($admins as $user) {
$this->choices[$user->id] = fullname($user);
}
}
if (is_array($users)) {
foreach ($users as $user) {
$this->choices[$user->id] = fullname($user);
}
}
return true;
}
示例14: add_grade_form_elements
//.........这里部分代码省略.........
$mform->addElement('static', 'outcome_' . $index . '[' . $userid . ']', $outcome->name . ':', $options[$outcome->grades[$userid]->grade]);
} else {
$options[''] = get_string('nooutcome', 'grades');
$attributes = array('id' => 'menuoutcome_' . $index);
$mform->addElement('select', 'outcome_' . $index . '[' . $userid . ']', $outcome->name . ':', $options, $attributes);
$mform->setType('outcome_' . $index . '[' . $userid . ']', PARAM_INT);
$mform->setDefault('outcome_' . $index . '[' . $userid . ']', $outcome->grades[$userid]->grade);
}
}
}
$capabilitylist = array('gradereport/grader:view', 'moodle/grade:viewall');
if (has_all_capabilities($capabilitylist, $this->get_course_context())) {
$urlparams = array('id' => $this->get_course()->id);
$url = new moodle_url('/grade/report/grader/index.php', $urlparams);
$usergrade = '-';
if (isset($gradinginfo->items[0]->grades[$userid]->str_grade)) {
$usergrade = $gradinginfo->items[0]->grades[$userid]->str_grade;
}
$gradestring = $this->get_renderer()->action_link($url, $usergrade);
} else {
$usergrade = '-';
if (isset($gradinginfo->items[0]->grades[$userid]) && !$gradinginfo->items[0]->grades[$userid]->hidden) {
$usergrade = $gradinginfo->items[0]->grades[$userid]->str_grade;
}
$gradestring = $usergrade;
}
if ($this->get_instance()->markingworkflow) {
$states = $this->get_marking_workflow_states_for_current_user();
$options = array('' => get_string('markingworkflowstatenotmarked', 'assign')) + $states;
$mform->addElement('select', 'workflowstate', get_string('markingworkflowstate', 'assign'), $options);
$mform->addHelpButton('workflowstate', 'markingworkflowstate', 'assign');
}
if ($this->get_instance()->markingallocation && has_capability('mod/assign:manageallocations', $this->context)) {
$markers = get_users_by_capability($this->context, 'mod/assign:grade');
$markerlist = array('' => get_string('choosemarker', 'assign'));
foreach ($markers as $marker) {
$markerlist[$marker->id] = fullname($marker);
}
$mform->addElement('select', 'allocatedmarker', get_string('allocatedmarker', 'assign'), $markerlist);
$mform->addHelpButton('allocatedmarker', 'allocatedmarker', 'assign');
$mform->disabledIf('allocatedmarker', 'workflowstate', 'eq', ASSIGN_MARKING_WORKFLOW_STATE_READYFORREVIEW);
$mform->disabledIf('allocatedmarker', 'workflowstate', 'eq', ASSIGN_MARKING_WORKFLOW_STATE_INREVIEW);
$mform->disabledIf('allocatedmarker', 'workflowstate', 'eq', ASSIGN_MARKING_WORKFLOW_STATE_READYFORRELEASE);
$mform->disabledIf('allocatedmarker', 'workflowstate', 'eq', ASSIGN_MARKING_WORKFLOW_STATE_RELEASED);
}
$mform->addElement('static', 'currentgrade', get_string('currentgrade', 'assign'), $gradestring);
if (count($useridlist) > 1) {
$strparams = array('current' => $rownum + 1, 'total' => count($useridlist));
$name = get_string('outof', 'assign', $strparams);
$mform->addElement('static', 'gradingstudent', get_string('gradingstudent', 'assign'), $name);
}
// Let feedback plugins add elements to the grading form.
$this->add_plugin_grade_elements($grade, $mform, $data, $userid);
// Hidden params.
$mform->addElement('hidden', 'id', $this->get_course_module()->id);
$mform->setType('id', PARAM_INT);
$mform->addElement('hidden', 'rownum', $rownum);
$mform->setType('rownum', PARAM_INT);
$mform->setConstant('rownum', $rownum);
$mform->addElement('hidden', 'useridlistid', $useridlistid);
$mform->setType('useridlistid', PARAM_INT);
$mform->addElement('hidden', 'attemptnumber', $attemptnumber);
$mform->setType('attemptnumber', PARAM_INT);
$mform->addElement('hidden', 'ajax', optional_param('ajax', 0, PARAM_INT));
$mform->setType('ajax', PARAM_INT);
if ($this->get_instance()->teamsubmission) {
示例15: get_graders
/**
* Returns a list of teachers that should be grading given submission
*
* @param object $user
* @return array
*/
function get_graders($user) {
//potential graders
$potgraders = get_users_by_capability($this->context, 'mod/assignment:grade', '', '', '', '', '', '', false, false);
$graders = array();
if (groups_get_activity_groupmode($this->cm) == SEPARATEGROUPS) { // Separate groups are being used
if ($groups = groups_get_all_groups($this->course->id, $user->id)) { // Try to find all groups
foreach ($groups as $group) {
foreach ($potgraders as $t) {
if ($t->id == $user->id) {
continue; // do not send self
}
if (groups_is_member($group->id, $t->id)) {
$graders[$t->id] = $t;
}
}
}
} else {
// user not in group, try to find graders without group
foreach ($potgraders as $t) {
if ($t->id == $user->id) {
continue; // do not send self
}
if (!groups_get_all_groups($this->course->id, $t->id)) { //ugly hack
$graders[$t->id] = $t;
}
}
}
} else {
foreach ($potgraders as $t) {
if ($t->id == $user->id) {
continue; // do not send self
}
$graders[$t->id] = $t;
}
}
return $graders;
}