本文整理汇总了PHP中get_users_by_capability函数的典型用法代码示例。如果您正苦于以下问题:PHP get_users_by_capability函数的具体用法?PHP get_users_by_capability怎么用?PHP get_users_by_capability使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_users_by_capability函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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];
}
开发者ID:pzhu2004,项目名称:moodle,代码行数:19,代码来源:capability_checker.php
示例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);
}
开发者ID:adonm,项目名称:learning,代码行数:26,代码来源:plugin.class.php
示例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
}
开发者ID:BackupTheBerlios,项目名称:samouk-svn,代码行数:13,代码来源:datalib.php
示例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;
}
开发者ID:nagyistoce,项目名称:moodle-Teach-Pilot,代码行数:31,代码来源:linker.php
示例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);
}
开发者ID:nadavkav,项目名称:Moodle2-Hebrew-plugins,代码行数:10,代码来源:User.php
示例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;
}
开发者ID:apmgrouptc,项目名称:moodle-mod_virtualclass,代码行数:12,代码来源:locallib.php
示例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');
}
开发者ID:educacionbe,项目名称:campus,代码行数:59,代码来源:NewTxttoolsAccountForm.php
示例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);
}
开发者ID:josenorberto,项目名称:moodle-enrol_boleto,代码行数:50,代码来源:locallib.php
示例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;
}
开发者ID:NextEinstein,项目名称:riverhills,代码行数:18,代码来源:lib.php
示例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);
}
开发者ID:sebastiansanio,项目名称:tallerdeprogramacion2fiuba,代码行数:29,代码来源:attemptsreport.php
示例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;
}
开发者ID:gabrielrosset,项目名称:moodle-filter_poodll,代码行数:39,代码来源:dataset_manager.php
示例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);
}
开发者ID:numbas,项目名称:moodle,代码行数:27,代码来源:lib.php
示例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;
}
开发者ID:raymondAntonio,项目名称:moodle,代码行数:25,代码来源:adminlib.php
示例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) {
开发者ID:covex-nn,项目名称:moodle,代码行数:67,代码来源:locallib.php
示例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;
}
开发者ID:nuckey,项目名称:moodle,代码行数:44,代码来源:lib.php
示例16: get_users_by_capability
/**
* Who has this capability in this context?
*
* This can be a very expensive call - use sparingly and keep
* the results if you are going to need them again soon.
*
* Note if $fields is empty this function attempts to get u.*
* which can get rather large - and has a serious perf impact
* on some DBs.
*
* @param context $context
* @param string|array $capability - capability name(s)
* @param string $fields - fields to be pulled. The user table is aliased to 'u'. u.id MUST be included.
* @param string $sort - the sort order. Default is lastaccess time.
* @param mixed $limitfrom - number of records to skip (offset)
* @param mixed $limitnum - number of records to fetch
* @param string|array $groups - single group or array of groups - only return
* users who are in one of these group(s).
* @param string|array $exceptions - list of users to exclude, comma separated or array
* @param bool $doanything_ignored not used any more, admin accounts are never returned
* @param bool $view_ignored - use get_enrolled_sql() instead
* @param bool $useviewallgroups if $groups is set the return users who
* have capability both $capability and moodle/site:accessallgroups
* in this context, as well as users who have $capability and who are
* in $groups.
* @return mixed
*/
function get_users_by_capability(context $context, $capability, $fields = '', $sort = '', $limitfrom = '', $limitnum = '', $groups = '', $exceptions = '', $doanything_ignored = null, $view_ignored = null, $useviewallgroups = false)
{
global $CFG, $DB;
$defaultuserroleid = isset($CFG->defaultuserroleid) ? $CFG->defaultuserroleid : 0;
$defaultfrontpageroleid = isset($CFG->defaultfrontpageroleid) ? $CFG->defaultfrontpageroleid : 0;
$ctxids = trim($context->path, '/');
$ctxids = str_replace('/', ',', $ctxids);
// Context is the frontpage
$iscoursepage = false;
// coursepage other than fp
$isfrontpage = false;
if ($context->contextlevel == CONTEXT_COURSE) {
if ($context->instanceid == SITEID) {
$isfrontpage = true;
} else {
$iscoursepage = true;
}
}
$isfrontpage = $isfrontpage || is_inside_frontpage($context);
$caps = (array) $capability;
// construct list of context paths bottom-->top
list($contextids, $paths) = get_context_info_list($context);
// we need to find out all roles that have these capabilities either in definition or in overrides
$defs = array();
list($incontexts, $params) = $DB->get_in_or_equal($contextids, SQL_PARAMS_NAMED, 'con');
list($incaps, $params2) = $DB->get_in_or_equal($caps, SQL_PARAMS_NAMED, 'cap');
$params = array_merge($params, $params2);
$sql = "SELECT rc.id, rc.roleid, rc.permission, rc.capability, ctx.path\n FROM {role_capabilities} rc\n JOIN {context} ctx on rc.contextid = ctx.id\n WHERE rc.contextid {$incontexts} AND rc.capability {$incaps}";
$rcs = $DB->get_records_sql($sql, $params);
foreach ($rcs as $rc) {
$defs[$rc->capability][$rc->path][$rc->roleid] = $rc->permission;
}
// go through the permissions bottom-->top direction to evaluate the current permission,
// first one wins (prohibit is an exception that always wins)
$access = array();
foreach ($caps as $cap) {
foreach ($paths as $path) {
if (empty($defs[$cap][$path])) {
continue;
}
foreach ($defs[$cap][$path] as $roleid => $perm) {
if ($perm == CAP_PROHIBIT) {
$access[$cap][$roleid] = CAP_PROHIBIT;
continue;
}
if (!isset($access[$cap][$roleid])) {
$access[$cap][$roleid] = (int) $perm;
}
}
}
}
// make lists of roles that are needed and prohibited in this context
$needed = array();
// one of these is enough
$prohibited = array();
// must not have any of these
foreach ($caps as $cap) {
if (empty($access[$cap])) {
continue;
}
foreach ($access[$cap] as $roleid => $perm) {
if ($perm == CAP_PROHIBIT) {
unset($needed[$cap][$roleid]);
$prohibited[$cap][$roleid] = true;
} else {
if ($perm == CAP_ALLOW and empty($prohibited[$cap][$roleid])) {
$needed[$cap][$roleid] = true;
}
}
}
if (empty($needed[$cap]) or !empty($prohibited[$cap][$defaultuserroleid])) {
// easy, nobody has the permission
unset($needed[$cap]);
//.........这里部分代码省略.........
开发者ID:rolandovanegas,项目名称:moodle,代码行数:101,代码来源:accesslib.php
示例17: find_users
/**
* Find our users who could be enrolled into the remote course
*
* Our users must have 'moodle/site:mnetlogintoremote' capability assigned.
* Remote users, guests, deleted and not confirmed users are not returned.
*
* @param string $search
* @return array
*/
public function find_users($search)
{
global $CFG, $DB;
$systemcontext = context_system::instance();
$userids = get_users_by_capability($systemcontext, 'moodle/site:mnetlogintoremote', 'u.id');
if (empty($userids)) {
return array();
}
list($usql, $uparams) = $DB->get_in_or_equal(array_keys($userids), SQL_PARAMS_NAMED, 'uid');
list($wherecondition, $params) = $this->search_sql($search, 'u');
$params = array_merge($params, $uparams);
$params['hostid'] = $this->hostid;
$params['remotecourseid'] = $this->remotecourseid;
$params['mnetlocalhostid'] = $CFG->mnet_localhost_id;
$fields = "SELECT " . $this->required_fields_sql("u");
$countfields = "SELECT COUNT(1)";
$sql = " FROM {user} u\n WHERE {$wherecondition}\n AND u.mnethostid = :mnetlocalhostid\n AND u.id {$usql}\n AND u.id NOT IN (SELECT e.userid\n FROM {mnetservice_enrol_enrolments} e\n WHERE (e.hostid = :hostid AND e.remotecourseid = :remotecourseid))";
list($sort, $sortparams) = users_order_by_sql('u');
$order = " ORDER BY {$sort}";
if (!$this->is_validating()) {
$potentialmemberscount = $DB->count_records_sql($countfields . $sql, $params);
if ($potentialmemberscount > 100) {
return $this->too_many_results($search, $potentialmemberscount);
}
}
$availableusers = $DB->get_records_sql($fields . $sql . $order, array_merge($params, $sortparams));
if (empty($availableusers)) {
return array();
}
if ($search) {
$groupname = get_string('enrolcandidatesmatching', 'enrol', $search);
} else {
$groupname = get_string('enrolcandidates', 'enrol');
}
return array($groupname => $availableusers);
}
开发者ID:evltuma,项目名称:moodle,代码行数:45,代码来源:locallib.php
示例18: print_enrolmentkeyfrom
/**
* Prints the message telling you were to get the enrolment key
* appropriate for the prevailing circumstances
* A bit clunky because I didn't want to change the standard strings
*/
function print_enrolmentkeyfrom($course)
{
global $CFG;
global $USER;
$context = get_context_instance(CONTEXT_SYSTEM);
$guest = has_capability('moodle/legacy:guest', $context, $USER->id, false);
// if a keyholder role is defined we list teachers in that role (if any exist)
$contactslisted = false;
$canseehidden = has_capability('moodle/role:viewhiddenassigns', $context);
if (!empty($CFG->enrol_manual_keyholderrole)) {
if ($contacts = get_role_users($CFG->enrol_manual_keyholderrole, get_context_instance(CONTEXT_COURSE, $course->id), true, '', 'u.lastname ASC', $canseehidden)) {
// guest user has a slightly different message
if ($guest) {
print_string('enrolmentkeyfromguest', '', ':<br />');
} else {
print_string('enrolmentkeyfrom', '', ':<br />');
}
foreach ($contacts as $contact) {
$contactname = "<a href=\"../user/view.php?id={$contact->id}&course=" . SITEID . "\">" . fullname($contact) . "</a>.";
echo "{$contactname}<br />";
}
$contactslisted = true;
}
}
// if no keyholder role is defined OR nobody is in that role we do this the 'old' way
// (show the first person with update rights)
if (!$contactslisted) {
if ($teachers = get_users_by_capability(get_context_instance(CONTEXT_COURSE, $course->id), 'moodle/course:update', 'u.*', 'u.id ASC', 0, 1, '', '', false, true)) {
$teacher = array_shift($teachers);
}
if (!empty($teacher)) {
$teachername = "<a href=\"../user/view.php?id={$teacher->id}&course=" . SITEID . "\">" . fullname($teacher) . "</a>.";
} else {
$teachername = strtolower(get_string('defaultcourseteacher'));
//get_string('yourteacher', '', $course->teacher);
}
// guest user has a slightly different message
if ($guest) {
print_string('enrolmentkeyfromguest', '', $teachername);
} else {
print_string('enrolmentkeyfrom', '', $teachername);
}
}
}
开发者ID:kai707,项目名称:ITSA-backup,代码行数:49,代码来源:enrol.php
示例19: quiz_send_notification_emails
/**
* Takes a bunch of information to format into an email and send
* to the specified recipient.
*
* @param object $course the course
* @param object $quiz the quiz
* @param object $attempt this attempt just finished
* @param object $context the quiz context
* @param object $cm the coursemodule for this quiz
*
* @return int number of emails sent
*/
function quiz_send_notification_emails($course, $quiz, $attempt, $context, $cm)
{
global $CFG, $USER;
// we will count goods and bads for error logging
$emailresult = array('good' => 0, 'block' => 0, 'fail' => 0);
// do nothing if required objects not present
if (empty($course) or empty($quiz) or empty($attempt) or empty($context)) {
debugging('quiz_send_notification_emails: Email(s) not sent due to program error.', DEBUG_DEVELOPER);
return $emailresult['fail'];
}
// check for confirmation required
$sendconfirm = false;
$notifyexcludeusers = '';
if (has_capability('mod/quiz:emailconfirmsubmission', $context, NULL, false)) {
// exclude from notify emails later
$notifyexcludeusers = $USER->id;
// send the email
$sendconfirm = true;
}
// check for notifications required
$notifyfields = 'u.id, u.username, u.firstname, u.lastname, u.email, u.emailstop, u.lang, u.timezone, u.mailformat, u.maildisplay';
$groups = groups_get_all_groups($course->id, $USER->id);
if (is_array($groups) && count($groups) > 0) {
$groups = array_keys($groups);
} else {
if (groups_get_activity_groupmode($cm, $course) != NOGROUPS) {
// If the user is not in a group, and the quiz is set to group mode,
// then set $gropus to a non-existant id so that only users with
// 'moodle/site:accessallgroups' get notified.
$groups = -1;
} else {
$groups = '';
}
}
$userstonotify = get_users_by_capability($context, 'mod/quiz:emailnotifysubmission', $notifyfields, '', '', '', $groups, $notifyexcludeusers, false, false, true);
// if something to send, then build $a
if (!empty($userstonotify) or $sendconfirm) {
$a = new stdClass();
// course info
$a->coursename = $course->fullname;
$a->courseshortname = $course->shortname;
// quiz info
$a->quizname = $quiz->name;
$a->quizreporturl = $CFG->wwwroot . '/mod/quiz/report.php?q=' . $quiz->id;
$a->quizreportlink = '<a href="' . $a->quizreporturl . '">' . format_string($quiz->name) . ' report</a>';
$a->quizreviewurl = $CFG->wwwroot . '/mod/quiz/review.php?attempt=' . $attempt->id;
$a->quizreviewlink = '<a href="' . $a->quizreviewurl . '">' . format_string($quiz->name) . ' review</a>';
$a->quizurl = $CFG->wwwroot . '/mod/quiz/view.php?q=' . $quiz->id;
$a->quizlink = '<a href="' . $a->quizurl . '">' . format_string($quiz->name) . '</a>';
// attempt info
$a->submissiontime = userdate($attempt->timefinish);
$a->timetaken = format_time($attempt->timefinish - $attempt->timestart);
// student who sat the quiz info
$a->studentidnumber = $USER->idnumber;
$a->studentname = fullname($USER);
$a->studentusername = $USER->username;
}
// send confirmation if required
if ($sendconfirm) {
// send the email and update stats
switch (quiz_send_confirmation($a)) {
case true:
$emailresult['good']++;
break;
case false:
$emailresult['fail']++;
break;
case 'emailstop':
$emailresult['block']++;
break;
}
}
// send notifications if required
if (!empty($userstonotify)) {
// loop through recipients and send an email to each and update stats
foreach ($userstono
|
请发表评论