本文整理汇总了PHP中get_role_users函数的典型用法代码示例。如果您正苦于以下问题:PHP get_role_users函数的具体用法?PHP get_role_users怎么用?PHP get_role_users使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_role_users函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: init
/**
* Initialise this screen
*
* @param bool $selfitemisempty Has an item been selected (will be false)
*/
public function init($selfitemisempty = false)
{
global $DB;
$roleids = explode(',', get_config('moodle', 'gradebookroles'));
$this->items = get_role_users($roleids, $this->context, false, '', 'u.id, u.lastname, u.firstname', null, $this->groupid, $this->perpage * $this->page, $this->perpage);
$this->item = $DB->get_record('course', array('id' => $this->courseid));
}
示例2: blended_get_users_by_type
/**
* Find the list of users and get a list with the ids of students and a list of non-students
* @param type $context_course
* @return array(array($studentIds), array($non_studentIds), array($activeids), array($user_records))
*/
function blended_get_users_by_type($context_course)
{
// Get users with gradable roles
global $CFG;
$gradable_roles = $CFG->gradebookroles;
$roles = explode(',', $gradable_roles);
$students = array();
foreach ($roles as $roleid) {
$users_in_role = get_role_users($roleid, $context_course);
$ids = array_keys($users_in_role);
$students = array_merge($students, $ids);
$students = array_unique($students);
}
// get enrolled users
$user_records = get_enrolled_users($context_course, '', 0, '*');
$users = array_keys($user_records);
$non_students = array_diff($users, $students);
// select active userids
$activeids = array();
global $DB;
list($select, $params) = $DB->get_in_or_equal($students);
$select = "userid {$select}";
$select .= " AND courseid = ?";
$params[] = (int) $context_course->instanceid;
$last_accesses = $DB->get_records_select('user_lastaccess', $select, $params);
foreach ($last_accesses as $record) {
$activeids[] = $record->userid;
}
return array($students, $non_students, $activeids, $user_records);
}
示例3: course_info_box
/**
* Renders course info box.
*
* @param stdClass $course
* @return string
*/
public function course_info_box(stdClass $course)
{
global $CFG;
$context = context_course::instance($course->id);
$content = '';
$content .= $this->output->box_start('generalbox info');
$summary = file_rewrite_pluginfile_urls($course->summary, 'pluginfile.php', $context->id, 'course', 'summary', null);
$content .= format_text($summary, $course->summaryformat, array('overflowdiv' => true), $course->id);
if (!empty($CFG->coursecontact)) {
$coursecontactroles = explode(',', $CFG->coursecontact);
foreach ($coursecontactroles as $roleid) {
if ($users = get_role_users($roleid, $context, true)) {
foreach ($users as $teacher) {
$role = new stdClass();
$role->id = $teacher->roleid;
$role->name = $teacher->rolename;
$role->shortname = $teacher->roleshortname;
$role->coursealias = $teacher->rolecoursealias;
$fullname = fullname($teacher, has_capability('moodle/site:viewfullnames', $context));
$namesarray[] = role_get_name($role, $context) . ': <a href="' . $CFG->wwwroot . '/user/view.php?id=' . $teacher->id . '&course=' . SITEID . '">' . $fullname . '</a>';
}
}
}
if (!empty($namesarray)) {
$content .= "<ul class=\"teachers\">\n<li>";
$content .= implode('</li><li>', $namesarray);
$content .= "</li></ul>";
}
}
$content .= $this->output->box_end();
return $content;
}
示例4: execute
function execute($data, $user, $courseid)
{
$context = get_context_instance(CONTEXT_COURSE, $courseid);
if ($users = get_role_users($data->roles, $context, false, 'u.id')) {
return array_keys($users);
}
return array();
}
示例5: execute
function execute($data, $user, $courseid)
{
global $DB;
$context = cr_get_context(CONTEXT_COURSE, $courseid);
if ($users = get_role_users($data->roles, $context, false, 'u.id', 'u.id')) {
return array_keys($users);
}
return array();
}
示例6: getStudentsByCourse
function getStudentsByCourse($courseId)
{
$courses = get_courses();
$context = context_course::instance($courseId);//course id
$students = get_role_users(5, $context); //student context
return $students ;
}
示例7: _wwassignment_get_course_students
/**
* @desc Finds all of the users in the course
* @param $courseid -- the course id
* @return record containing user information ( username, userid)
*/
function _wwassignment_get_course_students($courseid)
{
debugLog("Begin get_course_students({$courseid} )");
debugLog("courseID is " . print_r($courseid, true));
$context = get_context_instance(CONTEXT_COURSE, $courseid);
debugLog("context is " . print_r($context, true));
$users = array();
$roles_used_in_context = get_roles_used_in_context($context);
//debugLog("roles used ". print_r($roles_used_in_context, true));
foreach ($roles_used_in_context as $role) {
$roleid = $role->id;
debugLog("roleid should be 5 for a student {$roleid}");
//debugLog(get_role_users($roleid, $context, true) );
if ($new_users = get_role_users($roleid, $context, true)) {
$users = array_merge($users, $new_users);
//FIXME a user could be liseted twice
}
debugLog("display users " . print_r($users, true));
}
debugLog("display users in course--on");
debugLog("users again" . print_r($users, true));
debugLog("End get_course_students({$courseid} )");
return $users;
}
示例8: getKnownUsers
/**
* Retrieve all known users for the current Moodle user
* @return array Array of objects featuring name and Moodle id
*/
function getKnownUsers()
{
global $course;
$context = get_context_instance(CONTEXT_COURSE, $course->id);
$students = get_role_users(5, $context);
$tmp = (array) null;
foreach ($students as $student) {
$knownUser = (object) null;
$knownUser->id = $student->id;
if ($student->maildisplay) {
$knownUser->email = $student->email;
}
$fullname = $student->firstname . ' ' . $student->lastname;
if (strlen(trim($fullname)) == 0) {
$fullname = $student->username;
}
$knownUser->name = $fullname;
if ($account_link = get_record("studynotes_account_links", "system", "moodle", "external_id", $student->id)) {
$knownUser->mb_id = $account_link->internal_id;
}
$tmp[] = $knownUser;
}
return $tmp;
}
示例9: get_course_absenties
function get_course_absenties($cid){
$context = context_course::instance($cid);
$enrolledStudents = get_role_users(5 , $context);//getting all the students from a course level
$loggedinusers=get_all_loggedin_users('All');
$logstuarr=array();$cnt=0;
foreach($loggedinusers as $logstudent){
$logstuarr[$cnt++]=array('stid'=>$logstudent->userid);
}
$lgss=array_column($logstuarr, 'stid');
//print_r($lgss);
$absented_Students=array();$stcnt=0;
foreach($enrolledStudents as $student){
if(in_array($student->id, $lgss)){}
else{
$absented_Students[$stcnt++]=array('stid'=>$student->id);
}
}
$absented_Students=array_column($absented_Students,'stid');
return $absented_Students;
}
示例10: email_welcome_message
/**
* Send welcome email to specified user.
*
* @param stdClass $instance
* @param stdClass $user user record
* @return void
*/
protected function email_welcome_message($instance, $user)
{
global $CFG, $DB;
$course = $DB->get_record('course', array('id' => $instance->courseid), '*', MUST_EXIST);
$context = context_course::instance($course->id);
$a = new stdClass();
$a->coursename = format_string($course->fullname, true, array('context' => $context));
$a->profileurl = "{$CFG->wwwroot}/user/view.php?id={$user->id}&course={$course->id}";
if (trim($instance->customtext1) !== '') {
$message = $instance->customtext1;
$key = array('{$a->coursename}', '{$a->profileurl}', '{$a->fullname}', '{$a->email}');
$value = array($a->coursename, $a->profileurl, fullname($user), $user->email);
$message = str_replace($key, $value, $message);
if (strpos($message, '<') === false) {
// Plain text only.
$messagetext = $message;
$messagehtml = text_to_html($messagetext, null, false, true);
} else {
// This is most probably the tag/newline soup known as FORMAT_MOODLE.
$messagehtml = format_text($message, FORMAT_MOODLE, array('context' => $context, 'para' => false, 'newlines' => true, 'filter' => true));
$messagetext = html_to_text($messagehtml);
}
} else {
$messagetext = get_string('welcometocoursetext', 'enrol_self', $a);
$messagehtml = text_to_html($messagetext, null, false, true);
}
$subject = get_string('welcometocourse', 'enrol_self', format_string($course->fullname, true, array('context' => $context)));
$rusers = array();
if (!empty($CFG->coursecontact)) {
$croles = explode(',', $CFG->coursecontact);
list($sort, $sortparams) = users_order_by_sql('u');
// We only use the first user.
$i = 0;
do {
$rusers = get_role_users($croles[$i], $context, true, '', 'r.sortorder ASC, ' . $sort, null, '', '', '', '', $sortparams);
$i++;
} while (empty($rusers) && !empty($croles[$i]));
}
if ($rusers) {
$contact = reset($rusers);
} else {
$contact = core_user::get_support_user();
}
// Directly emailing welcome message rather than using messaging.
email_to_user($user, $contact, $subject, $messagetext, $messagehtml);
}
示例11: definition
function definition()
{
global $USER, $CFG, $DB;
$courseconfig = get_config('moodlecourse');
$mform =& $this->_form;
$course = $this->_customdata['course'];
$category = $this->_customdata['category'];
$systemcontext = get_context_instance(CONTEXT_SYSTEM);
$categorycontext = get_context_instance(CONTEXT_COURSECAT, $category->id);
$disable_meta = false;
// basic meta course state protection; server-side security checks not needed
if (!empty($course)) {
$coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
$context = $coursecontext;
if (course_in_meta($course)) {
$disable_meta = get_string('metaalreadyinmeta');
} else {
if ($course->metacourse) {
if ($DB->count_records('course_meta', array('parent_course' => $course->id)) > 0) {
$disable_meta = get_string('metaalreadyhascourses');
}
} else {
// if users already enrolled directly into coures, do not allow switching to meta,
// users with metacourse manage permission are exception
// please note that we do not need exact results - anything unexpected here prevents metacourse
$managers = get_users_by_capability($coursecontext, 'moodle/course:managemetacourse', 'u.id');
$enrolroles = get_roles_with_capability('moodle/course:view', CAP_ALLOW, $coursecontext);
if ($users = get_role_users(array_keys($enrolroles), $coursecontext, false, 'u.id', 'u.id ASC')) {
foreach ($users as $user) {
if (!isset($managers[$user->id])) {
$disable_meta = get_string('metaalreadyhasenrolments');
break;
}
}
}
unset($managers);
unset($users);
unset($enrolroles);
}
}
} else {
$coursecontext = null;
$context = $categorycontext;
}
/// form definition with new course defaults
//--------------------------------------------------------------------------------
$mform->addElement('header', 'general', get_string('general', 'form'));
// Must have create course capability in both categories in order to move course
if (has_capability('moodle/course:create', $categorycontext)) {
$displaylist = array();
$parentlist = array();
make_categories_list($displaylist, $parentlist, 'moodle/course:create');
$mform->addElement('select', 'category', get_string('category'), $displaylist);
} else {
$mform->addElement('hidden', 'category', null);
}
$mform->setHelpButton('category', array('coursecategory', get_string('category')));
$mform->setDefault('category', $category->id);
$mform->setType('category', PARAM_INT);
$fullname = get_string('defaultcoursefullname');
$shortname = get_string('defaultcourseshortname');
while ($DB->record_exists('course', array('fullname' => $fullname)) or $DB->record_exists('course', array('fullname' => $fullname))) {
$fullname++;
$shortname++;
}
$mform->addElement('text', 'fullname', get_string('fullnamecourse'), 'maxlength="254" size="50"');
$mform->setHelpButton('fullname', array('coursefullname', get_string('fullnamecourse')), true);
$mform->addRule('fullname', get_string('missingfullname'), 'required', null, 'client');
$mform->setType('fullname', PARAM_MULTILANG);
if ($course and !has_capability('moodle/course:changefullname', $coursecontext)) {
$mform->hardFreeze('fullname');
$mform->setConstant('fullname', $course->fullname);
}
$mform->setDefault('fullname', $fullname);
$mform->addElement('text', 'shortname', get_string('shortnamecourse'), 'maxlength="100" size="20"');
$mform->setHelpButton('shortname', array('courseshortname', get_string('shortnamecourse')), true);
$mform->addRule('shortname', get_string('missingshortname'), 'required', null, 'client');
$mform->setType('shortname', PARAM_MULTILANG);
if ($course and !has_capability('moodle/course:changeshortname', $coursecontext)) {
$mform->hardFreeze('shortname');
$mform->setConstant('shortname', $course->shortname);
}
$mform->setDefault('shortname', $shortname);
$mform->addElement('text', 'idnumber', get_string('idnumbercourse'), 'maxlength="100" size="10"');
$mform->setHelpButton('idnumber', array('courseidnumber', get_string('idnumbercourse')), true);
$mform->setType('idnumber', PARAM_RAW);
if ($course and !has_capability('moodle/course:changeidnumber', $coursecontext)) {
$mform->hardFreeze('idnumber');
$mform->setConstants('idnumber', $course->idnumber);
}
$mform->addElement('htmleditor', 'summary', get_string('summary'), array('rows' => '10', 'cols' => '65'));
$mform->setHelpButton('summary', array('text2', get_string('helptext')), true);
$mform->setType('summary', PARAM_RAW);
$courseformats = get_list_of_plugins('course/format');
$formcourseformats = array();
foreach ($courseformats as $courseformat) {
$formcourseformats["{$courseformat}"] = get_string("format{$courseformat}", "format_{$courseformat}");
if ($formcourseformats["{$courseformat}"] == "[[format{$courseformat}]]") {
$formcourseformats["{$courseformat}"] = get_string("format{$courseformat}");
}
//.........这里部分代码省略.........
示例12: bigbluebuttonbn_get_users
function bigbluebuttonbn_get_users($context)
{
$roles = bigbluebuttonbn_get_db_moodle_roles();
$users_array = array();
foreach ($roles as $role) {
$users = get_role_users($role->id, $context);
foreach ($users as $user) {
array_push($users_array, array("id" => $user->id, "name" => $user->firstname . ' ' . $user->lastname));
}
}
return $users_array;
}
示例13: foreach
}
foreach ($completion->get_criteria() as $criterion) {
if (!in_array($criterion->criteriatype, array(COMPLETION_CRITERIA_TYPE_COURSE, COMPLETION_CRITERIA_TYPE_ACTIVITY))) {
$criteria[] = $criterion;
}
}
// Can logged in user mark users as complete?
// (if the logged in user has a role defined in the role criteria)
$allow_marking = false;
$allow_marking_criteria = null;
if (!$csv) {
// Get role criteria
$rcriteria = $completion->get_criteria(COMPLETION_CRITERIA_TYPE_ROLE);
if (!empty($rcriteria)) {
foreach ($rcriteria as $rcriterion) {
$users = get_role_users($rcriterion->role, $context, true);
// If logged in user has this role, allow marking complete
if ($users && in_array($USER->id, array_keys($users))) {
$allow_marking = true;
$allow_marking_criteria = $rcriterion->id;
break;
}
}
}
}
/**
* Setup page header
*/
if ($csv) {
header('Content-Disposition: attachment; filename=progress.' . preg_replace('/[^a-z0-9-]/', '_', strtolower($course->shortname)) . '.csv');
// Unicode byte-order mark for Excel
示例14: array
<?php
$role = $DB->get_record('role', array('shortname' => 'student'));
$table = 'jcode_files';
$context = context_course::instance($course->id);
$students = get_role_users($role->id, $context);
$save = optional_param('savequickgrades', '', PARAM_TEXT);
require_once $CFG->libdir . '/gradelib.php';
if (!empty($save)) {
foreach ($_POST as $name => $value) {
if (strstr($name, 'quickgrade_') && !strstr($name, 'comments_')) {
$name = str_replace('quickgrade_', '', $name);
$nota = new stdClass();
$nota->grade = $value;
$grading_info = grade_get_grades($course->id, 'mod', 'jcode', $jcode->id, 0);
grade_update_outcomes('mod/jcode', $course->id, 'mod', 'jcode', $jcode->id, $name, array('0' => $value));
if (is_numeric($nota->grade)) {
$feedback = $_POST['quickgrade_comments_' . $name];
$nota->feedback = $feedback;
if ($n = $DB->get_record($table, array('jcode_id' => $jcode->id, 'user_id' => $name))) {
$nota->id = $n->id;
$DB->update_record($table, $nota);
} else {
$DB->insert($table, $nota);
}
}
}
}
}
$t = new html_table();
jcode_add_table_row_cells($t, array('Aluno', 'Nota', 'Feedback', 'Data de Entrega', 'Arquivo', 'Resultado'));
示例15: tao_message_get_recipients_by_target
function tao_message_get_recipients_by_target($target, $course, $user = null)
{
$user = tao_user_parameter($user);
$context = get_context_instance(CONTEXT_COURSE, $course->id);
if (!empty($target->recipientrole) || !empty($target->recipientroles)) {
if (!empty($target->recipientcontext)) {
$context = get_context_instance_by_id($target->recipientcontext);
}
if (!empty($target->recipientrole)) {
$roleid = get_field('role', 'id', 'shortname', $target->recipientrole);
} else {
$rolesql = " IN ( '" . implode("','", $target->recipientroles) . "' ) ";
$roleid = array_keys(get_records_select('role', 'shortname ' . $rolesql, '', 'id, id'));
}
return get_role_users($roleid, $context);
} else {
if (is_array($target->recipientfunction)) {
// recipientfunction
$function = $target->recipientfunction['users'];
$users = $function($user, $course);
if (empty($target->recipienttransform)) {
return $users;
}
switch ($target->recipienttransform) {
case 'nested':
// these are the grandchild ones
$newu = array();
foreach ($users as $key => $children) {
$newu = array_merge($newu, $children);
}
return $newu;
}
}
}
}