本文整理汇总了PHP中enrol_get_all_users_courses函数的典型用法代码示例。如果您正苦于以下问题:PHP enrol_get_all_users_courses函数的具体用法?PHP enrol_get_all_users_courses怎么用?PHP enrol_get_all_users_courses使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了enrol_get_all_users_courses函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: definition
public function definition()
{
global $DB, $USER;
$form = $this->_form;
$selectdata = enrol_get_all_users_courses($USER->id, true, ['id', 'fullname']);
$coursearray = null;
$coursearray[null] = '-- SELECT --';
foreach ($selectdata as $val) {
$coursearray[$val->id] = $val->fullname;
}
$form->addElement('select', 'courseid', get_string('courseselect', 'local_note'), $coursearray);
$form->setType('courseid', PARAM_RAW);
$form->addRule('courseid', get_string('err_courseselect', 'local_note'), 'required', null, 'server', false, false);
$form->addElement('text', 'title', get_string('title', 'local_note'));
$form->setType('title', PARAM_RAW);
$form->addElement('htmleditor', 'content', get_string("content", "local_note"), 'wrap="virtual" rows="3" cols="20"');
$form->setType('content', PARAM_RAW);
$form->addElement('filemanager', 'attachment', get_string('attachment', 'local_note'), null, array('maxbytes' => '2097152', 'accepted_types' => '*'));
$form->addElement('text', 'label', get_string('label', 'local_note'));
$form->setType('label', PARAM_RAW);
$form->addElement('select', 'status', get_string("status", "local_note"), array('1' => 'Active', '0' => 'In-active'));
$form->setType('status', PARAM_RAW);
$form->addElement('hidden', 'id', $this->noteid);
$form->setType('id', PARAM_RAW);
$this->add_action_buttons();
}
示例2: get_enrolled_course_ids
/**
* Obtain enrolled courses for the specified user.
*
* @param integer $userid
*
* @return integer[]
*/
protected static function get_enrolled_course_ids($userid)
{
$courses = enrol_get_all_users_courses($userid, false);
$courseids = array_reduce($courses, function ($courseids, $course) {
$courseids[] = $course->id;
return $courseids;
}, array());
return $courseids;
}
示例3: test_mergeenrolments
/**
* Enrol two users on one unique course each and one shared course
* then merge them.
*/
public function test_mergeenrolments()
{
global $DB;
// Setup two users to merge.
$user_remove = $this->getDataGenerator()->create_user();
$user_keep = $this->getDataGenerator()->create_user();
// Create three courses.
$course1 = $this->getDataGenerator()->create_course();
$course2 = $this->getDataGenerator()->create_course();
$course3 = $this->getDataGenerator()->create_course();
$maninstance1 = $DB->get_record('enrol', array('courseid' => $course1->id, 'enrol' => 'manual'), '*', MUST_EXIST);
$maninstance2 = $DB->get_record('enrol', array('courseid' => $course2->id, 'enrol' => 'manual'), '*', MUST_EXIST);
$maninstance3 = $DB->get_record('enrol', array('courseid' => $course3->id, 'enrol' => 'manual'), '*', MUST_EXIST);
$manual = enrol_get_plugin('manual');
$studentrole = $DB->get_record('role', array('shortname' => 'student'));
// Enrol $user_remove on course 1 + 2 and $user_keep on course 2 + 3.
$manual->enrol_user($maninstance1, $user_remove->id, $studentrole->id);
$manual->enrol_user($maninstance2, $user_remove->id, $studentrole->id);
$manual->enrol_user($maninstance2, $user_keep->id, $studentrole->id);
$manual->enrol_user($maninstance3, $user_keep->id, $studentrole->id);
// Check initial state of enrolments for $user_remove.
$courses = enrol_get_all_users_courses($user_remove->id);
ksort($courses);
$this->assertCount(2, $courses);
$this->assertEquals(array($course1->id, $course2->id), array_keys($courses));
// Check initial state of enrolments for $user_keep.
$courses = enrol_get_all_users_courses($user_keep->id);
ksort($courses);
$this->assertCount(2, $courses);
$this->assertEquals(array($course2->id, $course3->id), array_keys($courses));
$mut = new MergeUserTool();
list($success, $log, $logid) = $mut->merge($user_keep->id, $user_remove->id);
// Check $user_remove is suspended.
$user_remove = $DB->get_record('user', array('id' => $user_remove->id));
$this->assertEquals(1, $user_remove->suspended);
// Check $user_keep is now enrolled on all three courses.
$courses = enrol_get_all_users_courses($user_keep->id);
ksort($courses);
$this->assertCount(3, $courses);
$this->assertEquals(array($course1->id, $course2->id, $course3->id), array_keys($courses));
}
示例4: print_row
}
print_row(get_string('skypeid') . ':', '<a href="skype:' . urlencode($user->skype) . '?call">' . s($user->skype) . $statusicon . '</a>');
}
if ($user->yahoo && !isset($hiddenfields['yahooid'])) {
print_row(get_string('yahooid') . ':', '<a href="http://edit.yahoo.com/config/send_webmesg?.target=' . urlencode($user->yahoo) . '&.src=pg">' . s($user->yahoo) . " <img src=\"http://opi.yahoo.com/online?u=" . urlencode($user->yahoo) . "&m=g&t=0\" alt=\"\"></a>");
}
if ($user->aim && !isset($hiddenfields['aimid'])) {
print_row(get_string('aimid') . ':', '<a href="aim:goim?screenname=' . urlencode($user->aim) . '">' . s($user->aim) . '</a>');
}
if ($user->msn && !isset($hiddenfields['msnid'])) {
print_row(get_string('msnid') . ':', s($user->msn));
}
/// Print the Custom User Fields
profile_display_fields($user->id);
if (!isset($hiddenfields['mycourses'])) {
if ($mycourses = enrol_get_all_users_courses($user->id, true, NULL, 'visible DESC,sortorder ASC')) {
$shown = 0;
$courselisting = '';
foreach ($mycourses as $mycourse) {
if ($mycourse->category) {
context_helper::preload_from_record($mycourse);
$ccontext = context_course::instance($mycourse->id);
$class = '';
if ($mycourse->visible == 0) {
if (!has_capability('moodle/course:viewhiddencourses', $ccontext)) {
continue;
}
$class = 'class="dimmed"';
}
$courselisting .= "<a href=\"{$CFG->wwwroot}/user/view.php?id={$user->id}&course={$mycourse->id}\" {$class} >" . $ccontext->get_context_name(false) . "</a>, ";
}
示例5: promoted_courses
public function promoted_courses($type)
{
global $CFG, $OUTPUT, $DB, $PAGE, $USER;
if ($type == '') {
return false;
}
$featuredcontent = '';
$featuredids = '';
/* Get Featured courses id from DB */
if ($type == 'tags') {
$sql = "SELECT DISTINCT itemid FROM {tag_instance} WHERE itemtype = 'course' AND tagid IN(SELECT tagid FROM {tag_instance} WHERE itemtype = 'user' AND itemid = " . $USER->id . ")";
$featuredidsarray = $DB->get_records_sql($sql, array());
$featuredids = '';
$promotedtitle = theme_pioneer_get_setting('promotedtagtitle', 'format_text');
$promotedlinktext = theme_pioneer_get_setting('promotedtaglinktext', 'format_text');
$promotedlink = theme_pioneer_get_setting('promotedtaglink', 'format_text');
$personaltextbox = theme_pioneer_get_setting('promotedtagtextbox', 'format_html');
foreach ($featuredidsarray as $fid) {
$featuredids .= $fid->itemid . ',';
}
}
if ($type == 'setting') {
$featuredids = theme_pioneer_get_setting('promotedcourses');
$promotedtitle = theme_pioneer_get_setting('promotedtitle', 'format_text');
$promotedlinktext = theme_pioneer_get_setting('promotedlinktext', 'format_text');
$promotedlink = theme_pioneer_get_setting('promotedlink', 'format_text');
$personaltextbox = '';
}
if ($type == 'my') {
$promotedtitle = theme_pioneer_get_setting('promotedmytitle', 'format_text');
$promotedlinktext = theme_pioneer_get_setting('promotedmylinktext', 'format_text');
$promotedlink = theme_pioneer_get_setting('promotedmylink', 'format_text');
$personaltextbox = theme_pioneer_get_setting('promotedmytextbox', 'format_html');
$courses = enrol_get_all_users_courses($USER->id);
foreach ($courses as $fid) {
$featuredids .= $fid->id . ',';
}
}
/* Get Featured courses id from DB */
$rcourseids = !empty($featuredids) ? explode(",", $featuredids, 30) : array();
if (empty($rcourseids)) {
return false;
}
$hcourseids = theme_pioneer_hidden_courses_ids();
if (!empty($hcourseids)) {
foreach ($rcourseids as $key => $val) {
if (in_array($val, $hcourseids)) {
unset($rcourseids[$key]);
}
}
}
foreach ($rcourseids as $key => $val) {
$ccourse = $DB->get_record('course', array('id' => $val));
if (empty($ccourse)) {
unset($rcourseids[$key]);
continue;
}
}
if (empty($rcourseids)) {
return false;
}
$fcourseids = array_chunk($rcourseids, 30);
$totalfcourse = count($fcourseids);
$featuredheader = '<div class="custom-courses-list" id="Promoted-Courses">
<div class="container-fluid">
<div class="titlebar with-felements">
<h2>' . $promotedtitle . '</h2>
<div class="clearfix"></div>
</div>
<div class="promoted_courses" data-crow="' . $totalfcourse . '">';
$featuredfooter = ' <p style="float:right;"> <a href="' . $promotedlink . '">' . $promotedlinktext . '</a></p>
<div class="clearfix"></div>
</div>
</div>
</div>';
if (!empty($fcourseids)) {
foreach ($fcourseids as $courseids) {
$rowcontent = '<p>' . $personaltextbox . '</p><div><div class="row-fluid carousel">';
foreach ($courseids as $courseid) {
$course = get_course($courseid);
$no = get_config('theme_pioneer', 'patternselect');
$nimgp = empty($no) || $no == "default" ? 'no-image' : 'cs0' . $no . '/no-image';
$noimgurl = $OUTPUT->pix_url($nimgp, 'theme');
$courseurl = new moodle_url('/course/view.php', array('id' => $courseid));
if ($course instanceof stdClass) {
require_once $CFG->libdir . '/coursecatlib.php';
$course = new course_in_list($course);
}
$imgurl = '';
$summary = theme_pioneer_strip_html_tags($course->summary);
$summary = theme_pioneer_course_trim_char($summary, 110);
$trimtitle = theme_pioneer_course_trim_char($course->fullname, 25);
$context = context_course::instance($course->id);
$nostudents = count_role_users(5, $context);
foreach ($course->get_course_overviewfiles() as $file) {
$isimage = $file->is_valid_image();
$imgurl = file_encode_url("{$CFG->wwwroot}/pluginfile.php", '/' . $file->get_contextid() . '/' . $file->get_component() . '/' . $file->get_filearea() . $file->get_filepath() . $file->get_filename(), !$isimage);
if (!$isimage) {
$imgurl = $noimgurl;
}
//.........这里部分代码省略.........
示例6: all_ungraded
public static function all_ungraded($userid)
{
$courses = enrol_get_all_users_courses($userid);
$capability = 'gradereport/grader:view';
foreach ($courses as $course) {
if (has_capability($capability, \context_course::instance($course->id), $userid)) {
$courseids[] = $course->id;
}
}
if (empty($courseids)) {
return array();
}
$mods = \core_plugin_manager::instance()->get_installed_plugins('mod');
$mods = array_keys($mods);
$grading = [];
foreach ($mods as $mod) {
$class = '\\theme_snap\\activity';
$method = $mod . '_ungraded';
if (method_exists($class, $method)) {
$grading = array_merge($grading, call_user_func([$class, $method], $courseids));
}
}
usort($grading, array('self', 'sort_graded'));
return $grading;
}
示例7: enrol_user_sees_own_courses
/**
* Can user access at least one enrolled course?
*
* Cheat if necessary, but find out as fast as possible!
*
* @param int|stdClass $user null means use current user
* @return bool
*/
function enrol_user_sees_own_courses($user = null)
{
global $USER;
if ($user === null) {
$user = $USER;
}
$userid = is_object($user) ? $user->id : $user;
// Guest account does not have any courses
if (isguestuser($userid) or empty($userid)) {
return false;
}
// Let's cheat here if this is the current user,
// if user accessed any course recently, then most probably
// we do not need to query the database at all.
if ($USER->id == $userid) {
if (!empty($USER->enrol['enrolled'])) {
foreach ($USER->enrol['enrolled'] as $until) {
if ($until > time()) {
return true;
}
}
}
}
// Now the slow way.
$courses = enrol_get_all_users_courses($userid, true);
foreach ($courses as $course) {
if ($course->visible) {
return true;
}
context_helper::preload_from_record($course);
$context = context_course::instance($course->id);
if (has_capability('moodle/course:viewhiddencourses', $context, $user)) {
return true;
}
}
return false;
}
示例8: test_enrol_get_all_users_courses
public function test_enrol_get_all_users_courses()
{
global $DB, $CFG;
$this->resetAfterTest();
$studentrole = $DB->get_record('role', array('shortname' => 'student'));
$this->assertNotEmpty($studentrole);
$teacherrole = $DB->get_record('role', array('shortname' => 'teacher'));
$this->assertNotEmpty($teacherrole);
$admin = get_admin();
$user1 = $this->getDataGenerator()->create_user();
$user2 = $this->getDataGenerator()->create_user();
$user3 = $this->getDataGenerator()->create_user();
$user4 = $this->getDataGenerator()->create_user();
$user5 = $this->getDataGenerator()->create_user();
$category1 = $this->getDataGenerator()->create_category(array('visible' => 0));
$category2 = $this->getDataGenerator()->create_category();
$course1 = $this->getDataGenerator()->create_course(array('category' => $category1->id));
$course2 = $this->getDataGenerator()->create_course(array('category' => $category2->id));
$course3 = $this->getDataGenerator()->create_course(array('category' => $category2->id, 'visible' => 0));
$course4 = $this->getDataGenerator()->create_course(array('category' => $category2->id));
$maninstance1 = $DB->get_record('enrol', array('courseid' => $course1->id, 'enrol' => 'manual'), '*', MUST_EXIST);
$DB->set_field('enrol', 'status', ENROL_INSTANCE_DISABLED, array('id' => $maninstance1->id));
$maninstance1 = $DB->get_record('enrol', array('courseid' => $course1->id, 'enrol' => 'manual'), '*', MUST_EXIST);
$maninstance2 = $DB->get_record('enrol', array('courseid' => $course2->id, 'enrol' => 'manual'), '*', MUST_EXIST);
$maninstance3 = $DB->get_record('enrol', array('courseid' => $course3->id, 'enrol' => 'manual'), '*', MUST_EXIST);
$maninstance4 = $DB->get_record('enrol', array('courseid' => $course4->id, 'enrol' => 'manual'), '*', MUST_EXIST);
$manual = enrol_get_plugin('manual');
$this->assertNotEmpty($manual);
$manual->enrol_user($maninstance1, $user1->id, $teacherrole->id);
$manual->enrol_user($maninstance1, $user2->id, $studentrole->id);
$manual->enrol_user($maninstance1, $user4->id, $teacherrole->id, 0, 0, ENROL_USER_SUSPENDED);
$manual->enrol_user($maninstance1, $admin->id, $studentrole->id);
$manual->enrol_user($maninstance2, $user1->id);
$manual->enrol_user($maninstance2, $user2->id);
$manual->enrol_user($maninstance2, $user3->id, 0, 1, time() + 60 * 60);
$manual->enrol_user($maninstance3, $user1->id);
$manual->enrol_user($maninstance3, $user2->id);
$manual->enrol_user($maninstance3, $user3->id, 0, 1, time() - 60 * 60);
$manual->enrol_user($maninstance3, $user4->id, 0, 0, 0, ENROL_USER_SUSPENDED);
$courses = enrol_get_all_users_courses($CFG->siteguest);
$this->assertSame(array(), $courses);
$courses = enrol_get_all_users_courses(0);
$this->assertSame(array(), $courses);
// Results are sorted by visibility, sortorder by default (in our case order of creation)
$courses = enrol_get_all_users_courses($admin->id);
$this->assertCount(1, $courses);
$this->assertEquals(array($course1->id), array_keys($courses));
$courses = enrol_get_all_users_courses($admin->id, true);
$this->assertCount(0, $courses);
$this->assertEquals(array(), array_keys($courses));
$courses = enrol_get_all_users_courses($user1->id);
$this->assertCount(3, $courses);
$this->assertEquals(array($course2->id, $course1->id, $course3->id), array_keys($courses));
$courses = enrol_get_all_users_courses($user1->id, true);
$this->assertCount(2, $courses);
$this->assertEquals(array($course2->id, $course3->id), array_keys($courses));
$courses = enrol_get_all_users_courses($user2->id);
$this->assertCount(3, $courses);
$this->assertEquals(array($course2->id, $course1->id, $course3->id), array_keys($courses));
$courses = enrol_get_all_users_courses($user2->id, true);
$this->assertCount(2, $courses);
$this->assertEquals(array($course2->id, $course3->id), array_keys($courses));
$courses = enrol_get_all_users_courses($user3->id);
$this->assertCount(2, $courses);
$this->assertEquals(array($course2->id, $course3->id), array_keys($courses));
$courses = enrol_get_all_users_courses($user3->id, true);
$this->assertCount(1, $courses);
$this->assertEquals(array($course2->id), array_keys($courses));
$courses = enrol_get_all_users_courses($user4->id);
$this->assertCount(2, $courses);
$this->assertEquals(array($course1->id, $course3->id), array_keys($courses));
$courses = enrol_get_all_users_courses($user4->id, true);
$this->assertCount(0, $courses);
$this->assertEquals(array(), array_keys($courses));
// Make sure sorting and columns work.
$basefields = array('id', 'category', 'sortorder', 'shortname', 'fullname', 'idnumber', 'startdate', 'visible', 'groupmode', 'groupmodeforce');
$courses = enrol_get_all_users_courses($user2->id, true);
$course = reset($courses);
context_helper::preload_from_record($course);
$course = (array) $course;
$this->assertEquals($basefields, array_keys($course), '', 0, 10, true);
$courses = enrol_get_all_users_courses($user2->id, false, 'modinfo');
$course = reset($courses);
$this->assertTrue(property_exists($course, 'modinfo'));
$courses = enrol_get_all_users_courses($user2->id, false, null, 'id DESC');
$this->assertEquals(array($course3->id, $course2->id, $course1->id), array_keys($courses));
}
示例9: core_myprofile_navigation
//.........这里部分代码省略.........
$node = new core_user\output\myprofile\node('contact', 'phone2', get_string('phone2'), null, null, $user->phone2);
$tree->add_node($node);
}
if (isset($identityfields['institution']) && $user->institution) {
$node = new core_user\output\myprofile\node('contact', 'institution', get_string('institution'), null, null, $user->institution);
$tree->add_node($node);
}
if (isset($identityfields['department']) && $user->department) {
$node = new core_user\output\myprofile\node('contact', 'department', get_string('department'), null, null, $user->institution);
$tree->add_node($node);
}
if (isset($identityfields['idnumber']) && $user->idnumber) {
$node = new core_user\output\myprofile\node('contact', 'idnumber', get_string('idnumber'), null, null, $user->institution);
$tree->add_node($node);
}
if ($user->url && !isset($hiddenfields['webpage'])) {
$url = $user->url;
if (strpos($user->url, '://') === false) {
$url = 'http://' . $url;
}
$webpageurl = new moodle_url($url);
$node = new core_user\output\myprofile\node('contact', 'webpage', get_string('webpage'), null, null, html_writer::link($url, $webpageurl));
$tree->add_node($node);
}
// Printing tagged interests. We want this only for full profile.
if (!empty($CFG->usetags) && empty($course)) {
if ($interests = tag_get_tags_csv('user', $user->id)) {
$node = new core_user\output\myprofile\node('contact', 'interests', get_string('interests'), null, null, $interests);
$tree->add_node($node);
}
}
if (!isset($hiddenfields['mycourses'])) {
$showallcourses = optional_param('showallcourses', 0, PARAM_INT);
if ($mycourses = enrol_get_all_users_courses($user->id, true, null, 'visible DESC, sortorder ASC')) {
$shown = 0;
$courselisting = html_writer::start_tag('ul');
foreach ($mycourses as $mycourse) {
if ($mycourse->category) {
context_helper::preload_from_record($mycourse);
$ccontext = context_course::instance($mycourse->id);
if (!isset($course) || $mycourse->id != $course->id) {
$linkattributes = null;
if ($mycourse->visible == 0) {
if (!has_capability('moodle/course:viewhiddencourses', $ccontext)) {
continue;
}
$linkattributes['class'] = 'dimmed';
}
$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));
}
示例10: die
}
}
if ($availableRecord == Null) {
// Add one button for return
die("No Valid Record!");
}
}
}
// When user is staff and doing update
if (in_array("staff", $identity) && (array_key_exists("submitType", $_POST) && $_POST['submitType'] == "update")) {
// register_id not null
$userId = $availableRecord['register_id'];
} else {
$userId = $USER->id;
}
$selectedCourses = enrol_get_all_users_courses($userId);
$courseTeacherMap = obtainCourseTeacherMap($userId, $selectedCourses);
$courseTeacherMapJson = json_encode($courseTeacherMap);
echo $OUTPUT->header();
?>
<link rel="stylesheet" type="text/css"
href="<?php
echo $CFG->wwwroot;
?>
/lib/jquery/ui-1.10.4/css/base/jquery-ui.min.css">
<link rel="stylesheet" type="text/css"
href="<?php
echo $CFG->wwwroot;
?>
/testreservation/css/testReservationForm.css">
示例11: required_param
$teacherroleid = 3;
$logged = false;
$PAGE->set_context(context_system::instance());
// Id of the exam to be deleted.
$activityid = required_param('id', PARAM_INT);
$check = optional_param('create', 0, PARAM_INT);
$forkingUrl = new moodle_url($CFG->wwwroot . '/mod/emarking/activities/forking.php', array('id' => $activityid));
$editUrl = new moodle_url($CFG->wwwroot . '/mod/emarking/activities/edit.php', array('id' => $activityid));
$pdfUrl = new moodle_url($CFG->wwwroot . '/mod/emarking/activities/pdfcreator.php', array('id' => $activityid));
if (isset($check) && $check == 1) {
$message = "eMarking creado exitosamente.";
echo "<script type='text/javascript'>alert('{$message}');</script>";
}
if (isloggedin()) {
$logged = true;
$courses = enrol_get_all_users_courses($USER->id);
$countcourses = count($courses);
foreach ($courses as $course) {
$context = context_course::instance($course->id);
$roles = get_user_roles($context, $USER->id, true);
foreach ($roles as $rol) {
if ($rol->roleid == $teacherroleid) {
$asteachercourses[$course->id] = $course->fullname;
}
}
}
}
$activity = $DB->get_record('emarking_activities', array('id' => $activityid));
$user_object = $DB->get_record('user', array('id' => $activity->userid));
$rubric = $DB->get_records_sql("SELECT grl.id,\n\t\t\t\t\t\t\t\t\t gd.description as des,\n\t\t\t\t\t\t\t\t\t grc.id as grcid,\n\t\t\t\t\t\t\t\t\t grl.score,\n\t\t\t\t\t\t\t\t\t grl.definition, \n\t\t\t\t\t\t\t\t\t grc.description, \n\t\t\t\t\t\t\t\t\t grc.sortorder, \n\t\t\t\t\t\t\t\t\t gd.name as name\n\t\t\t\t\t\t\t FROM {gradingform_rubric_levels} as grl,\n\t \t\t\t\t\t\t\t {gradingform_rubric_criteria} as grc,\n \t\t\t\t\t\t\t {grading_definitions} as gd\n\t\t\t\t\t\t\t WHERE gd.id=? AND grc.definitionid=gd.id AND grc.id=grl.criterionid\n\t\t\t\t\t\t\t ORDER BY grcid, grl.id", array($activity->rubricid));
foreach ($rubric as $data) {
示例12: getCoursesOwnedByUser
/**
* In moodle a course is owned by an INTUITEL user if he has the permission block/intuitel:externallyedit
* @see \intuitel\IntuitelAdaptor::getCoursesOwnedByUser()
* @global type $CFG
* @param \intuitel\UserId $user_id
* @return array
*/
public function getCoursesOwnedByUser(UserId $user_id)
{
global $CFG;
require_once $CFG->libdir . '/accesslib.php';
$user = $this->getNativeUserFromUId($user_id);
//Get courses enrolled
$mycourses = enrol_get_all_users_courses($user->id, true, NULL, 'visible DESC,sortorder ASC');
$editable_courses = array();
foreach ($mycourses as $mycourse) {
\context_helper::preload_from_record($mycourse);
$ccontext = \context_course::instance($mycourse->id);
if (has_capability('block/intuitel:externallyedit', $ccontext, $user)) {
$course_info = get_fast_modinfo($mycourse->id, $user->id);
$editable_courses[] = $this->createLOFromNative($course_info, 'course');
}
}
return $editable_courses;
}
示例13: coursesas
/**
* returns the list of courses related to a user with id of $id
*
* @global type $DB
* @param type $id
* @param type $role = {"student" , "teacher"}
* @param type $cyear
* @param type $csem
* @return type
*/
function coursesas($id, $role)
{
global $DB;
$allcourses = enrol_get_all_users_courses($id);
$courses = array();
$i = 0;
$cohortids = getcohortids();
$cohortcourses = array();
if (count($cohortids) > 0) {
$query = "select distinct e.courseid from {enrol} e, {cohort} co where " . "e.customint1 = co.id and (co.idnumber like '" . current($cohortids)->term_id . "%'";
for ($i = 1; $i < count($cohortids); $i++) {
$query .= " or co.idnumber like '" . next($cohortids)->term_id . "%'";
}
$query .= ")";
$cohortcourses = $DB->get_records_sql($query);
}
foreach ($allcourses as $course) {
$isin = false;
foreach ($cohortcourses as $cohortcourse) {
if ($cohortcourse->courseid == $course->id) {
$isin = true;
}
}
if (!$isin) {
continue;
}
if ($role == 'student') {
if (isstudentincourse($id, $course->id)) {
array_push($courses, $course);
}
}
if ($role == 'teacher') {
if (isteacherincourse($id, $course->id)) {
array_push($courses, $course);
}
}
}
return $courses;
}
示例14: enrol_get_users_courses
/**
* Returns list of courses user is enrolled into.
* (Note: use enrol_get_all_users_courses if you want to use the list wihtout any cap checks )
*
* - $fields is an array of fieldnames to ADD
* so name the fields you really need, which will
* be added and uniq'd
*
* @param int $userid
* @param bool $onlyactive return only active enrolments in courses user may see
* @param string|array $fields
* @param string $sort
* @return array
*/
function enrol_get_users_courses($userid, $onlyactive = false, $fields = NULL, $sort = 'visible DESC,sortorder ASC')
{
global $DB;
$courses = enrol_get_all_users_courses($userid, $onlyactive, $fields, $sort);
// preload contexts and check visibility
if ($onlyactive) {
foreach ($courses as $id => $course) {
context_instance_preload($course);
if (!$course->visible) {
if (!($context = context_course::instance($id))) {
unset($courses[$id]);
continue;
}
if (!has_capability('moodle/course:viewhiddencourses', $context, $userid)) {
unset($courses[$id]);
continue;
}
}
}
}
return $courses;
}
示例15: gradeable_courseids
/**
* Get courses where user has the ability to view the gradebook.
*
* @param int $userid
* @return array
* @throws \coding_exception
*/
public static function gradeable_courseids($userid)
{
$courses = enrol_get_all_users_courses($userid);
$courseids = [];
$capability = 'gradereport/grader:view';
foreach ($courses as $course) {
if (has_capability($capability, \context_course::instance($course->id), $userid)) {
$courseids[] = $course->id;
}
}
return $courseids;
}