本文整理汇总了PHP中get_user_roles_in_course函数的典型用法代码示例。如果您正苦于以下问题:PHP get_user_roles_in_course函数的具体用法?PHP get_user_roles_in_course怎么用?PHP get_user_roles_in_course使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_user_roles_in_course函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get_evidences_for_course
/**
* returns a list of activities for a user that can be interpreted as evidences
*
* The complete list of course activities can only be loaded if you are a teacher!
*
* @return array Array of course objects
* @since Moodle 2.5
*/
public static function get_evidences_for_course($courseId)
{
global $DB, $CFG, $USER;
$userId = $USER->id;
$roles = get_user_roles_in_course($userId, $courseId);
if (strpos($roles, 'Teacher') !== FALSE || strpos($roles, 'Lehrer') !== FALSE || strpos($roles, 'Student') !== FALSE || strpos($roles, 'Trainer') !== FALSE) {
$query = 'SELECT {log}.*,firstname,lastname,email,lastaccess FROM {log} , {user} INNER JOIN {role_assignments} ra ON ra.userid = {user}.id INNER JOIN {context} ct ON ct.id = ra.contextid INNER JOIN {course} c ON c.id = ct.instanceid INNER JOIN {role} r ON r.id = ra.roleid INNER JOIN {course_categories} cc ON cc.id = c.category WHERE {log}.userid = {user}.id AND {log}.course= ? AND r.id =5 ORDER BY time DESC';
$result = $DB->get_records_sql($query, array($courseId));
$mapper = function ($arrayElement) {
return array('shortname' => $arrayElement->module . $arrayElement->info . " am " . $arrayElement->lastaccess, 'url' => $actual_link . "/mod/" . $arrayElement->module . "/" . $arrayElement->url, 'username' => $arrayElement->firstname . " " . $arrayElement->lastname, "userId" => $arrayElement->userid, 'changed' => $arrayElement->lastaccess, 'course' => $arrayElement->course, 'activityTyp' => $arrayElement->module, 'email' => $arrayElement->email);
};
$result_mapped = array_map($mapper, $result);
return $result_mapped;
} else {
return array();
}
}
示例2: userdate
}
}
echo '</div>';
// Print all the little details in a list
echo '<table class="list" summary="">';
// Show last time this user accessed this course
if (!isset($hiddenfields['lastaccess'])) {
if ($lastaccess = $DB->get_record('user_lastaccess', array('userid' => $user->id, 'courseid' => $course->id))) {
$datestring = userdate($lastaccess->timeaccess) . " (" . format_time(time() - $lastaccess->timeaccess) . ")";
} else {
$datestring = get_string("never");
}
print_row(get_string("lastaccess") . ":", $datestring);
}
// Show roles in this course
if ($rolestring = get_user_roles_in_course($id, $course->id)) {
print_row(get_string('roles') . ':', $rolestring);
}
// Show groups this user is in
if (!isset($hiddenfields['groups'])) {
$accessallgroups = has_capability('moodle/site:accessallgroups', $coursecontext);
if ($usergroups = groups_get_all_groups($course->id, $user->id)) {
$groupstr = '';
foreach ($usergroups as $group) {
if ($course->groupmode == SEPARATEGROUPS and !$accessallgroups and $user->id != $USER->id) {
if (!groups_is_member($group->id, $user->id)) {
continue;
}
}
if ($course->groupmode != NOGROUPS) {
$groupstr .= ' <a href="' . $CFG->wwwroot . '/user/index.php?id=' . $course->id . '&group=' . $group->id . '">' . format_string($group->name) . '</a>,';
示例3: test_get_user_roles_in_course
/**
* Test roles used in course.
*/
public function test_get_user_roles_in_course()
{
global $DB, $CFG;
$this->resetAfterTest();
$teacherrole = $DB->get_record('role', array('shortname' => 'editingteacher'), '*', MUST_EXIST);
$studentrole = $DB->get_record('role', array('shortname' => 'student'), '*', MUST_EXIST);
$course = $this->getDataGenerator()->create_course();
$coursecontext = context_course::instance($course->id);
$teacherrename = (object) array('roleid' => $teacherrole->id, 'name' => 'Učitel', 'contextid' => $coursecontext->id);
$DB->insert_record('role_names', $teacherrename);
$roleids = explode(',', $CFG->profileroles);
// Should include teacher and student in new installs.
$this->assertTrue(in_array($teacherrole->id, $roleids));
$this->assertTrue(in_array($studentrole->id, $roleids));
$user1 = $this->getDataGenerator()->create_user();
role_assign($teacherrole->id, $user1->id, $coursecontext->id);
role_assign($studentrole->id, $user1->id, $coursecontext->id);
$user2 = $this->getDataGenerator()->create_user();
role_assign($studentrole->id, $user2->id, $coursecontext->id);
$user3 = $this->getDataGenerator()->create_user();
$roles = get_user_roles_in_course($user1->id, $course->id);
$this->assertEquals(1, preg_match_all('/,/', $roles, $matches));
$this->assertTrue(strpos($roles, role_get_name($teacherrole, $coursecontext)) !== false);
$roles = get_user_roles_in_course($user2->id, $course->id);
$this->assertEquals(0, preg_match_all('/,/', $roles, $matches));
$this->assertTrue(strpos($roles, role_get_name($studentrole, $coursecontext)) !== false);
$roles = get_user_roles_in_course($user3->id, $course->id);
$this->assertSame('', $roles);
}
示例4: who_used_invite
/**
* Figures out who used an invite.
*
* @param object $invite Invitation record
*
* @return object Returns an object with following values:
* ['username'] - name of who used invite
* ['useremail'] - email of who used invite
* ['roles'] - roles the user has for course that
* they were invited
* ['timeused'] - formatted string of time used
* Returns false on error or if invite wasn't used.
*/
public function who_used_invite($invite)
{
global $DB;
$ret_val = new stdClass();
if (empty($invite->userid) || empty($invite->tokenused) || empty($invite->courseid) || empty($invite->timeused)) {
return false;
}
// Find user.
$user = $DB->get_record('user', array('id' => $invite->userid));
if (empty($user)) {
return false;
}
$ret_val->username = sprintf('%s %s', $user->firstname, $user->lastname);
$ret_val->useremail = $user->email;
// Find their roles for course.
$ret_val->roles = get_user_roles_in_course($invite->userid, $invite->courseid);
if (empty($ret_val->roles)) {
// If no roles, then they must have been booted out later.
return false;
}
$ret_val->roles = strip_tags($ret_val->roles);
// Format string when invite was used.
$ret_val->timeused = date('M j, Y g:ia', $invite->timeused);
return $ret_val;
}
示例5: core_myprofile_navigation
//.........这里部分代码省略.........
}
$params = array('id' => $user->id, 'course' => $mycourse->id);
if ($showallcourses) {
$params['showallcourses'] = 1;
}
$url = new moodle_url('/user/view.php', $params);
$courselisting .= html_writer::tag('li', html_writer::link($url, $ccontext->get_context_name(false), $linkattributes));
} else {
$courselisting .= html_writer::tag('li', $course->fullname);
}
}
$shown++;
if (!$showallcourses && $shown == $CFG->navcourselimit) {
$url = null;
if (isset($course)) {
$url = new moodle_url('/user/view.php', array('id' => $user->id, 'course' => $course->id, 'showallcourses' => 1));
} else {
$url = new moodle_url('/user/profile.php', array('id' => $user->id, 'showallcourses' => 1));
}
$courselisting .= html_writer::tag('li', html_writer::link($url, get_string('viewmore'), array('title' => get_string('viewmore'))));
break;
}
}
$courselisting .= html_writer::end_tag('ul');
if (!empty($mycourses)) {
// Add this node only if there are courses to display.
$node = new core_user\output\myprofile\node('coursedetails', 'courseprofiles', get_string('courseprofiles'), null, null, rtrim($courselisting, ', '));
$tree->add_node($node);
}
}
}
if (!empty($course)) {
// Show roles in this course.
if ($rolestring = get_user_roles_in_course($user->id, $course->id)) {
$node = new core_user\output\myprofile\node('coursedetails', 'roles', get_string('roles'), null, null, $rolestring);
$tree->add_node($node);
}
// Show groups this user is in.
if (!isset($hiddenfields['groups']) && !empty($course)) {
$accessallgroups = has_capability('moodle/site:accessallgroups', $context);
if ($usergroups = groups_get_all_groups($course->id, $user->id)) {
$groupstr = '';
foreach ($usergroups as $group) {
if ($course->groupmode == SEPARATEGROUPS and !$accessallgroups and $user->id != $USER->id) {
if (!groups_is_member($group->id, $user->id)) {
continue;
}
}
if ($course->groupmode != NOGROUPS) {
$groupstr .= ' <a href="' . $CFG->wwwroot . '/user/index.php?id=' . $course->id . '&group=' . $group->id . '">' . format_string($group->name) . '</a>,';
} else {
// The user/index.php shows groups only when course in group mode.
$groupstr .= ' ' . format_string($group->name);
}
}
if ($groupstr !== '') {
$node = new core_user\output\myprofile\node('coursedetails', 'groups', get_string('group'), null, null, rtrim($groupstr, ', '));
$tree->add_node($node);
}
}
}
if (!isset($hiddenfields['suspended'])) {
if ($user->suspended) {
$node = new core_user\output\myprofile\node('coursedetails', 'suspended', null, null, null, get_string('suspended', 'auth'));
$tree->add_node($node);
}
示例6: get_certificate_text
/**
* Substitutes the certificate text variables
*
* @param stdClass $issuecert The issue certificate object
* @param string $certtext The certificate text without substitutions
* @return string Return certificate text with all substutions
*/
protected function get_certificate_text($issuecert, $certtext = null)
{
global $OUTPUT, $DB, $CFG;
if (!($user = get_complete_user_data('id', $issuecert->userid))) {
print_error('nousersfound', 'moodle');
}
//If no text set get firstpage text
if (empty($certtext)) {
$certtext = $this->get_instance()->certificatetext;
}
$certtext = format_text($certtext, FORMAT_HTML, array('noclean' => true));
$a = new stdClass();
$a->username = fullname($user);
$a->idnumber = $user->idnumber;
$a->firstname = $user->firstname;
$a->lastname = $user->lastname;
$a->email = $user->email;
$a->icq = $user->icq;
$a->skype = $user->skype;
$a->yahoo = $user->yahoo;
$a->aim = $user->aim;
$a->msn = $user->msn;
$a->phone1 = $user->phone1;
$a->phone2 = $user->phone2;
$a->institution = $user->institution;
$a->department = $user->department;
$a->address = $user->address;
$a->city = $user->city;
//Add userimage url
$a->userimage = $OUTPUT->user_picture($user, array('size' => 1, 'popup' => false));
if (!empty($user->country)) {
$a->country = get_string($user->country, 'countries');
} else {
$a->country = '';
}
//Formatting URL, if needed
$url = $user->url;
if (strpos($url, '://') === false) {
$url = 'http://' . $url;
}
$a->url = $url;
//Getting user custom profiles fields
$userprofilefields = $this->get_user_profile_fields($user->id);
foreach ($userprofilefields as $key => $value) {
$key = 'profile_' . $key;
$a->{$key} = $value;
}
$a->coursename = format_string($this->get_instance()->coursename, true);
$a->grade = $this->get_grade($user->id);
$a->date = $this->get_date($issuecert, $user->id);
$a->outcome = $this->get_outcome($user->id);
$a->certificatecode = $issuecert->code;
// this code stay here only beace legacy supporte, coursehours variable was removed
//see issue 61 https://github.com/bozoh/moodle-mod_simplecertificate/issues/61
if (isset($this->get_instance()->coursehours)) {
$a->hours = format_string($this->get_instance()->coursehours . ' ' . get_string('hours', 'simplecertificate'), true);
} else {
$a->hours = '';
}
try {
if ($course = $this->get_course()) {
require_once $CFG->libdir . '/coursecatlib.php';
$courseinlist = new course_in_list($course);
if ($courseinlist->has_course_contacts()) {
$t = array();
foreach ($courseinlist->get_course_contacts() as $userid => $coursecontact) {
$t[] = $coursecontact['rolename'] . ': ' . $coursecontact['username'];
}
$a->teachers = implode("<br>", $t);
} else {
$a->teachers = '';
}
} else {
$a->teachers = '';
}
} catch (Exception $e) {
$a->teachers = '';
}
//Fetch user actitivy restuls
$a->userresults = $this->get_user_results($issuecert->userid);
//Get User role name in course
if (!($a->userrolename = get_user_roles_in_course($user->id, $course->id))) {
$a->userrolename = '';
}
// Get user enrollment start date
// see funtion enrol_get_enrolment_end($courseid, $userid), which get enddate, not start
$sql = "SELECT ue.timestart\n FROM {user_enrolments} ue\n JOIN {enrol} e ON (e.id = ue.enrolid AND e.courseid = :courseid)\n JOIN {user} u ON u.id = ue.userid\n WHERE ue.userid = :userid AND e.status = :enabled AND u.deleted = 0";
$params = array('enabled' => ENROL_INSTANCE_ENABLED, 'userid' => $user->id, 'courseid' => $course->id);
if ($timestart = $DB->get_field_sql($sql, $params)) {
$a->timestart = userdate($timestart, $this->get_instance()->timestartdatefmt);
} else {
$a->timestart = '';
}
//.........这里部分代码省略.........