本文整理汇总了PHP中core_user::get_user方法的典型用法代码示例。如果您正苦于以下问题:PHP core_user::get_user方法的具体用法?PHP core_user::get_user怎么用?PHP core_user::get_user使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类core_user
的用法示例。
在下文中一共展示了core_user::get_user方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get_popup_notifications
/**
* Get popup notifications for the specified users. Nothing is returned if notifications are disabled.
*
* @param int $useridto the user id who received the notification
* @param string $sort the column name to order by including optionally direction
* @param int $limit limit the number of result returned
* @param int $offset offset the result set by this amount
* @return array notification records
* @throws \moodle_exception
* @since 3.2
*/
public static function get_popup_notifications($useridto = 0, $sort = 'DESC', $limit = 0, $offset = 0)
{
global $DB, $USER;
$sort = strtoupper($sort);
if ($sort != 'DESC' && $sort != 'ASC') {
throw new \moodle_exception('invalid parameter: sort: must be "DESC" or "ASC"');
}
if (empty($useridto)) {
$useridto = $USER->id;
}
$params = ['useridto1' => $useridto, 'useridto2' => $useridto];
// Is notification enabled ?
if ($useridto == $USER->id) {
$disabled = $USER->emailstop;
} else {
$user = \core_user::get_user($useridto, "emailstop", MUST_EXIST);
$disabled = $user->emailstop;
}
if ($disabled) {
// Notifications are disabled, no need to run giant queries.
return array();
}
$sql = "SELECT * FROM (\n SELECT concat('r', r.id) as uniqueid, r.id, r.useridfrom, r.useridto,\n r.subject, r.fullmessage, r.fullmessageformat,\n r.fullmessagehtml, r.smallmessage, r.notification, r.contexturl,\n r.contexturlname, r.timecreated, r.timeuserfromdeleted, r.timeusertodeleted,\n r.component, r.eventtype, r.timeread\n FROM {message_read} r\n WHERE r.notification = 1\n AND r.id IN (SELECT messageid FROM {message_popup} WHERE isread = 1)\n AND r.useridto = :useridto1\n UNION ALL\n SELECT concat('u', u.id) as uniqueid, u.id, u.useridfrom, u.useridto,\n u.subject, u.fullmessage, u.fullmessageformat,\n u.fullmessagehtml, u.smallmessage, u.notification, u.contexturl,\n u.contexturlname, u.timecreated, u.timeuserfromdeleted, u.timeusertodeleted,\n u.component, u.eventtype, 0 as timeread\n FROM {message} u\n WHERE u.notification = 1\n AND u.id IN (SELECT messageid FROM {message_popup} WHERE isread = 0)\n AND u.useridto = :useridto2\n ) f ORDER BY timecreated {$sort}, timeread {$sort}, id {$sort}";
return array_values($DB->get_records_sql($sql, $params, $offset, $limit));
}
示例2: export_for_template
public function export_for_template(\renderer_base $output)
{
$data = new \stdClass();
$data->contacts = array();
$userids = array();
foreach ($this->contacts as $contact) {
$contact = new contact($contact);
$contactdata = $contact->export_for_template($output);
$userids[$contactdata->userid] = $contactdata->userid;
// Check if the contact was selected.
if ($this->contactuserid == $contactdata->userid) {
$contactdata->selected = true;
}
$data->contacts[] = $contactdata;
}
// Check if the other user is not part of the contacts. We may be sending a message to someone
// we have not had a conversation with, so we want to add a new item to the contacts array.
if ($this->contactuserid && !isset($userids[$this->contactuserid])) {
$user = \core_user::get_user($this->contactuserid);
// Set an empty message so that we know we are messaging the user, and not viewing their profile.
$user->smallmessage = '';
$user->useridfrom = $user->id;
$contact = \core_message\helper::create_contact($user);
$contact = new contact($contact);
$contactdata = $contact->export_for_template($output);
$contactdata->selected = true;
// Put the contact at the front.
array_unshift($data->contacts, $contactdata);
}
return $data;
}
示例3: generate_message
/**
* Generates the message object for a give subscription and event.
*
* @param int $subscriptionid Subscription instance
* @param \stdClass $eventobj Event data
*
* @return false|\stdClass message object
*/
protected function generate_message($subscriptionid, \stdClass $eventobj)
{
try {
$subscription = subscription_manager::get_subscription($subscriptionid);
} catch (\dml_exception $e) {
// Race condition, someone deleted the subscription.
return false;
}
$user = \core_user::get_user($subscription->userid);
$context = \context_user::instance($user->id, IGNORE_MISSING);
if ($context === false) {
// User context doesn't exist. Should never happen, nothing to do return.
return false;
}
$template = $subscription->template;
$template = $this->replace_placeholders($template, $subscription, $eventobj, $context);
$msgdata = new \stdClass();
$msgdata->component = 'tool_monitor';
// Your component name.
$msgdata->name = 'notification';
// This is the message name from messages.php.
$msgdata->userfrom = \core_user::get_noreply_user();
$msgdata->userto = $user;
$msgdata->subject = $subscription->get_name($context);
$msgdata->fullmessage = format_text($template, $subscription->templateformat, array('context' => $context));
$msgdata->fullmessageformat = $subscription->templateformat;
$msgdata->fullmessagehtml = format_text($template, $subscription->templateformat, array('context' => $context));
$msgdata->smallmessage = '';
$msgdata->notification = 1;
// This is only set to 0 for personal messages between users.
return $msgdata;
}
示例4: __construct
/**
* Constructor.
*
* @param int $currentuserid The current user we are wanting to view messages for
* @param int $otheruserid The other user we are wanting to view messages for
* @param array $messages
*/
public function __construct($currentuserid, $otheruserid, $messages)
{
$ufields = 'id, ' . get_all_user_name_fields(true) . ', lastaccess';
$this->currentuserid = $currentuserid;
if ($otheruserid) {
$this->otheruserid = $otheruserid;
$this->otheruser = \core_user::get_user($otheruserid, $ufields, MUST_EXIST);
}
$this->messages = $messages;
}
示例5: report_log_print_graph
/**
* This function is used to generate and display the log activity graph
*
* @global stdClass $CFG
* @param stdClass $course course instance
* @param int|stdClass $user id/object of the user whose logs are needed
* @param string $typeormode type of logs graph needed (usercourse.png/userday.png) or the mode (today, all).
* @param int $date timestamp in GMT (seconds since epoch)
* @param string $logreader Log reader.
* @return void
*/
function report_log_print_graph($course, $user, $typeormode, $date = 0, $logreader = '')
{
global $CFG, $OUTPUT;
if (!is_object($user)) {
$user = core_user::get_user($user);
}
$logmanager = get_log_manager();
$readers = $logmanager->get_readers();
if (empty($logreader)) {
$reader = reset($readers);
} else {
$reader = $readers[$logreader];
}
// If reader is not a sql_internal_table_reader and not legacy store then don't show graph.
if (!$reader instanceof \core\log\sql_internal_table_reader && !$reader instanceof logstore_legacy\log\store) {
return array();
}
$coursecontext = context_course::instance($course->id);
$a = new stdClass();
$a->coursename = format_string($course->shortname, true, array('context' => $coursecontext));
$a->username = fullname($user, true);
if ($typeormode == 'today' || $typeormode == 'userday.png') {
$logs = report_log_usertoday_data($course, $user, $date, $logreader);
$title = get_string("hitsoncoursetoday", "", $a);
} else {
if ($typeormode == 'all' || $typeormode == 'usercourse.png') {
$logs = report_log_userall_data($course, $user, $logreader);
$title = get_string("hitsoncourse", "", $a);
}
}
if (!empty($CFG->preferlinegraphs)) {
$chart = new \core\chart_line();
} else {
$chart = new \core\chart_bar();
}
$series = new \core\chart_series(get_string("hits"), $logs['series']);
$chart->add_series($series);
$chart->set_title($title);
$chart->set_labels($logs['labels']);
$yaxis = $chart->get_yaxis(0, true);
$yaxis->set_label(get_string("hits"));
$yaxis->set_stepsize(max(1, round(max($logs['series']) / 10)));
echo $OUTPUT->render($chart);
}
示例6: get_user_badges
/**
* Returns the list of badges awarded to a user.
*
* @param int $userid user id
* @param int $courseid course id
* @param int $page page of records to return
* @param int $perpage number of records to return per page
* @param string $search a simple string to search for
* @param bool $onlypublic whether to return only public badges
* @return array array containing warnings and the awarded badges
* @since Moodle 3.1
* @throws moodle_exception
*/
public static function get_user_badges($userid = 0, $courseid = 0, $page = 0, $perpage = 0, $search = '', $onlypublic = false)
{
global $CFG, $USER;
$warnings = array();
$params = array('userid' => $userid, 'courseid' => $courseid, 'page' => $page, 'perpage' => $perpage, 'search' => $search, 'onlypublic' => $onlypublic);
$params = self::validate_parameters(self::get_user_badges_parameters(), $params);
if (empty($CFG->enablebadges)) {
throw new moodle_exception('badgesdisabled', 'badges');
}
if (empty($CFG->badges_allowcoursebadges) && $params['courseid'] != 0) {
throw new moodle_exception('coursebadgesdisabled', 'badges');
}
// Default value for userid.
if (empty($params['userid'])) {
$params['userid'] = $USER->id;
}
// Validate the user.
$user = core_user::get_user($params['userid'], '*', MUST_EXIST);
core_user::require_active_user($user);
$usercontext = context_user::instance($user->id);
self::validate_context($usercontext);
if ($USER->id != $user->id) {
require_capability('moodle/badges:viewotherbadges', $usercontext);
// We are looking other user's badges, we must retrieve only public badges.
$params['onlypublic'] = true;
}
$userbadges = badges_get_user_badges($user->id, $params['courseid'], $params['page'], $params['perpage'], $params['search'], $params['onlypublic']);
$result = array();
$result['badges'] = array();
$result['warnings'] = $warnings;
foreach ($userbadges as $badge) {
$context = $badge->type == BADGE_TYPE_SITE ? context_system::instance() : context_course::instance($badge->courseid);
$badge->badgeurl = moodle_url::make_webservice_pluginfile_url($context->id, 'badges', 'badgeimage', $badge->id, '/', 'f1')->out(false);
// Return all the information if we are requesting our own badges.
// Or, if we have permissions for configuring badges in the badge context.
if ($USER->id == $user->id or has_capability('moodle/badges:configuredetails', $context)) {
$result['badges'][] = (array) $badge;
} else {
$result['badges'][] = array('name' => $badge->name, 'description' => $badge->description, 'badgeurl' => $badge->badgeurl, 'issuername' => $badge->issuername, 'issuerurl' => $badge->issuerurl, 'issuercontact' => $badge->issuercontact, 'uniquehash' => $badge->uniquehash, 'dateissued' => $badge->dateissued, 'dateexpire' => $badge->dateexpire);
}
}
return $result;
}
示例7: test_get_user
public function test_get_user()
{
global $CFG;
$this->resetAfterTest(true);
// Create user and try fetach it with api.
$user = $this->getDataGenerator()->create_user();
$this->assertEquals($user, core_user::get_user($user->id, '*', MUST_EXIST));
// Test noreply user.
$CFG->noreplyuserid = null;
$noreplyuser = core_user::get_noreply_user();
$this->assertEquals(1, $noreplyuser->emailstop);
$this->assertFalse(core_user::is_real_user($noreplyuser->id));
$this->assertEquals($CFG->noreplyaddress, $noreplyuser->email);
$this->assertEquals(get_string('noreplyname'), $noreplyuser->firstname);
// Set user as noreply user and make sure noreply propery is set.
core_user::reset_internal_users();
$CFG->noreplyuserid = $user->id;
$noreplyuser = core_user::get_noreply_user();
$this->assertEquals(1, $noreplyuser->emailstop);
$this->assertTrue(core_user::is_real_user($noreplyuser->id));
// Test support user.
core_user::reset_internal_users();
$CFG->supportemail = null;
$CFG->noreplyuserid = null;
$supportuser = core_user::get_support_user();
$adminuser = get_admin();
$this->assertEquals($adminuser, $supportuser);
$this->assertTrue(core_user::is_real_user($supportuser->id));
// When supportemail is set.
core_user::reset_internal_users();
$CFG->supportemail = 'test@support.moodle.test';
$supportuser = core_user::get_support_user();
$this->assertEquals(core_user::SUPPORT_USER, $supportuser->id);
$this->assertFalse(core_user::is_real_user($supportuser->id));
// Set user as support user and make sure noreply propery is set.
core_user::reset_internal_users();
$CFG->supportuserid = $user->id;
$supportuser = core_user::get_support_user();
$this->assertEquals($user, $supportuser);
$this->assertTrue(core_user::is_real_user($supportuser->id));
}
示例8: execute
/**
* Run the deletion task.
*
* @throws \coding_exception if the module could not be removed.
*/
public function execute()
{
global $CFG;
require_once $CFG->dirroot . '/course/lib.php';
// Set the proper user.
if ($this->get_custom_data()->userid !== $this->get_custom_data()->realuserid) {
$realuser = \core_user::get_user($this->get_custom_data()->realuserid, '*', MUST_EXIST);
cron_setup_user($realuser);
\core\session\manager::loginas($this->get_custom_data()->userid, \context_system::instance(), false);
} else {
$user = \core_user::get_user($this->get_custom_data()->userid, '*', MUST_EXIST);
cron_setup_user($user);
}
$cms = $this->get_custom_data()->cms;
foreach ($cms as $cm) {
try {
course_delete_module($cm->id);
} catch (\Exception $e) {
throw new \coding_exception("The course module {$cm->id} could not be deleted. {$e->getTraceAsString()}");
}
}
}
示例9: check_access
/**
* Whether the user can access the document or not.
*
* @param int $id The message instance id.
* @return int
*/
public function check_access($id)
{
global $CFG, $DB, $USER;
if (!$CFG->messaging) {
return \core_search\manager::ACCESS_DENIED;
}
$message = $DB->get_record('message_read', array('id' => $id));
if (!$message) {
return \core_search\manager::ACCESS_DELETED;
}
$userfrom = \core_user::get_user($message->useridfrom, 'id, deleted');
$userto = \core_user::get_user($message->useridto, 'id, deleted');
if (!$userfrom || !$userto || $userfrom->deleted || $userto->deleted) {
return \core_search\manager::ACCESS_DELETED;
}
if ($USER->id != $userto->id) {
return \core_search\manager::ACCESS_DENIED;
}
if ($message->timeusertodeleted != 0) {
return \core_search\manager::ACCESS_DELETED;
}
return \core_search\manager::ACCESS_GRANTED;
}
示例10: get_submission_status
/**
* Returns information about an assignment submission status for a given user.
*
* @param int $assignid assignment instance id
* @param int $userid user id (empty for current user)
* @return array of warnings and grading, status, feedback and previous attempts information
* @since Moodle 3.1
* @throws required_capability_exception
*/
public static function get_submission_status($assignid, $userid = 0)
{
global $USER;
$warnings = array();
$params = array('assignid' => $assignid, 'userid' => $userid);
$params = self::validate_parameters(self::get_submission_status_parameters(), $params);
list($assign, $course, $cm, $context) = self::validate_assign($params['assignid']);
// Default value for userid.
if (empty($params['userid'])) {
$params['userid'] = $USER->id;
}
$user = core_user::get_user($params['userid'], '*', MUST_EXIST);
core_user::require_active_user($user);
if (!$assign->can_view_submission($user->id)) {
throw new required_capability_exception($context, 'mod/assign:viewgrades', 'nopermission', '');
}
$gradingsummary = $lastattempt = $feedback = $previousattempts = null;
// Get the renderable since it contais all the info we need.
if ($assign->can_view_grades()) {
$gradingsummary = $assign->get_assign_grading_summary_renderable();
}
// Retrieve the rest of the renderable objects.
if (has_capability('mod/assign:submit', $assign->get_context(), $user)) {
$lastattempt = $assign->get_assign_submission_status_renderable($user, true);
}
$feedback = $assign->get_assign_feedback_status_renderable($user);
$previousattempts = $assign->get_assign_attempt_history_renderable($user);
// Now, build the result.
$result = array();
// First of all, grading summary, this is suitable for teachers/managers.
if ($gradingsummary) {
$result['gradingsummary'] = $gradingsummary;
}
// Did we submit anything?
if ($lastattempt) {
$submissionplugins = $assign->get_submission_plugins();
if (empty($lastattempt->submission)) {
unset($lastattempt->submission);
} else {
$lastattempt->submission->plugins = self::get_plugins_data($assign, $submissionplugins, $lastattempt->submission);
}
if (empty($lastattempt->teamsubmission)) {
unset($lastattempt->teamsubmission);
} else {
$lastattempt->teamsubmission->plugins = self::get_plugins_data($assign, $submissionplugins, $lastattempt->teamsubmission);
}
// We need to change the type of some of the structures retrieved from the renderable.
if (!empty($lastattempt->submissiongroup)) {
$lastattempt->submissiongroup = $lastattempt->submissiongroup->id;
} else {
unset($lastattempt->submissiongroup);
}
if (!empty($lastattempt->usergroups)) {
$lastattempt->usergroups = array_keys($lastattempt->usergroups);
}
// We cannot use array_keys here.
if (!empty($lastattempt->submissiongroupmemberswhoneedtosubmit)) {
$lastattempt->submissiongroupmemberswhoneedtosubmit = array_map(function ($e) {
return $e->id;
}, $lastattempt->submissiongroupmemberswhoneedtosubmit);
}
$result['lastattempt'] = $lastattempt;
}
// The feedback for our latest submission.
if ($feedback) {
if ($feedback->grade) {
$feedbackplugins = $assign->get_feedback_plugins();
$feedback->plugins = self::get_plugins_data($assign, $feedbackplugins, $feedback->grade);
} else {
unset($feedback->plugins);
unset($feedback->grade);
}
$result['feedback'] = $feedback;
}
// Retrieve only previous attempts.
if ($previousattempts and count($previousattempts->submissions) > 1) {
// Don't show the last one because it is the current submission.
array_pop($previousattempts->submissions);
// Show newest to oldest.
$previousattempts->submissions = array_reverse($previousattempts->submissions);
foreach ($previousattempts->submissions as $i => $submission) {
$attempt = array();
$grade = null;
foreach ($previousattempts->grades as $onegrade) {
if ($onegrade->attemptnumber == $submission->attemptnumber) {
$grade = $onegrade;
break;
}
}
$attempt['attemptnumber'] = $submission->attemptnumber;
if ($submission) {
//.........这里部分代码省略.........
示例11: view_grade_report
/**
* Trigger the user report events, do the same that the web interface view of the report
*
* @param int $courseid id of course
* @param int $userid id of the user the report belongs to
* @return array of warnings and status result
* @since Moodle 2.9
* @throws moodle_exception
*/
public static function view_grade_report($courseid, $userid = 0)
{
global $CFG, $USER;
require_once $CFG->dirroot . "/grade/lib.php";
require_once $CFG->dirroot . "/grade/report/user/lib.php";
$params = self::validate_parameters(self::view_grade_report_parameters(), array('courseid' => $courseid, 'userid' => $userid));
$warnings = array();
$course = get_course($params['courseid']);
$context = context_course::instance($course->id);
self::validate_context($context);
$userid = $params['userid'];
if (empty($userid)) {
$userid = $USER->id;
} else {
$user = core_user::get_user($userid, '*', MUST_EXIST);
core_user::require_active_user($user);
}
$access = false;
if (has_capability('moodle/grade:viewall', $context)) {
// Can view all course grades (any user).
$access = true;
} else {
if ($userid == $USER->id and has_capability('moodle/grade:view', $context) and $course->showgrades) {
// View own grades.
$access = true;
}
}
if (!$access) {
throw new moodle_exception('nopermissiontoviewgrades', 'error');
}
// Create a report instance. We don't need the gpr second parameter.
$report = new grade_report_user($course->id, null, $context, $userid);
$report->viewed();
$result = array();
$result['status'] = true;
$result['warnings'] = $warnings;
return $result;
}
示例12: message_send
/**
* Called when a message provider wants to send a message.
* This functions checks the message recipient's message processor configuration then
* sends the message to the configured processors
*
* Required parameters of the $eventdata object:
* component string component name. must exist in message_providers
* name string message type name. must exist in message_providers
* userfrom object|int the user sending the message
* userto object|int the message recipient
* subject string the message subject
* fullmessage string the full message in a given format
* fullmessageformat int the format if the full message (FORMAT_MOODLE, FORMAT_HTML, ..)
* fullmessagehtml string the full version (the message processor will choose with one to use)
* smallmessage string the small version of the message
*
* Optional parameters of the $eventdata object:
* notification bool should the message be considered as a notification rather than a personal message
* contexturl string if this is a notification then you can specify a url to view the event. For example the forum post the user is being notified of.
* contexturlname string the display text for contexturl
*
* @category message
* @param object $eventdata information about the message (component, userfrom, userto, ...)
* @return mixed the integer ID of the new message or false if there was a problem with a processor
*/
function message_send($eventdata)
{
global $CFG, $DB;
//new message ID to return
$messageid = false;
// Fetch default (site) preferences
$defaultpreferences = get_message_output_default_preferences();
$preferencebase = $eventdata->component . '_' . $eventdata->name;
// If message provider is disabled then don't do any processing.
if (!empty($defaultpreferences->{$preferencebase . '_disable'})) {
return $messageid;
}
//TODO: we need to solve problems with database transactions here somehow, for now we just prevent transactions - sorry
$DB->transactions_forbidden();
// By default a message is a notification. Only personal/private messages aren't notifications.
if (!isset($eventdata->notification)) {
$eventdata->notification = 1;
}
if (is_number($eventdata->userto)) {
$eventdata->userto = core_user::get_user($eventdata->userto);
}
if (is_int($eventdata->userfrom)) {
$eventdata->userfrom = core_user::get_user($eventdata->userfrom);
}
$usertoisrealuser = core_user::is_real_user($eventdata->userto->id) != false;
// If recipient is internal user (noreply user), and emailstop is set then don't send any msg.
if (!$usertoisrealuser && !empty($eventdata->userto->emailstop)) {
debugging('Attempt to send msg to internal (noreply) user', DEBUG_NORMAL);
return false;
}
if (!isset($eventdata->userto->auth) or !isset($eventdata->userto->suspended) or !isset($eventdata->userto->deleted)) {
$eventdata->userto = core_user::get_user($eventdata->userto->id);
}
//after how long inactive should the user be considered logged off?
if (isset($CFG->block_online_users_timetosee)) {
$timetoshowusers = $CFG->block_online_users_timetosee * 60;
} else {
$timetoshowusers = 300;
//5 minutes
}
// Work out if the user is logged in or not
if (!empty($eventdata->userto->lastaccess) && time() - $timetoshowusers < $eventdata->userto->lastaccess) {
$userstate = 'loggedin';
} else {
$userstate = 'loggedoff';
}
// Create the message object
$savemessage = new stdClass();
$savemessage->useridfrom = $eventdata->userfrom->id;
$savemessage->useridto = $eventdata->userto->id;
$savemessage->subject = $eventdata->subject;
$savemessage->fullmessage = $eventdata->fullmessage;
$savemessage->fullmessageformat = $eventdata->fullmessageformat;
$savemessage->fullmessagehtml = $eventdata->fullmessagehtml;
$savemessage->smallmessage = $eventdata->smallmessage;
$savemessage->notification = $eventdata->notification;
if (!empty($eventdata->contexturl)) {
$savemessage->contexturl = $eventdata->contexturl;
} else {
$savemessage->contexturl = null;
}
if (!empty($eventdata->contexturlname)) {
$savemessage->contexturlname = $eventdata->contexturlname;
} else {
$savemessage->contexturlname = null;
}
$savemessage->timecreated = time();
if (PHPUNIT_TEST and class_exists('phpunit_util')) {
// Add some more tests to make sure the normal code can actually work.
$componentdir = core_component::get_component_directory($eventdata->component);
if (!$componentdir or !is_dir($componentdir)) {
throw new coding_exception('Invalid component specified in message-send(): ' . $eventdata->component);
}
if (!file_exists("{$componentdir}/db/messages.php")) {
throw new coding_exception("{$eventdata->component} does not contain db/messages.php necessary for message_send()");
//.........这里部分代码省略.........
示例13: get_course_completion_status
/**
* Get Course completion status
*
* @param int $courseid ID of the Course
* @param int $userid ID of the User
* @return array of course completion status and warnings
* @since Moodle 2.9
* @throws moodle_exception
*/
public static function get_course_completion_status($courseid, $userid)
{
global $CFG, $USER;
require_once $CFG->libdir . '/grouplib.php';
$warnings = array();
$arrayparams = array('courseid' => $courseid, 'userid' => $userid);
$params = self::validate_parameters(self::get_course_completion_status_parameters(), $arrayparams);
$course = get_course($params['courseid']);
$user = core_user::get_user($params['userid'], 'id', MUST_EXIST);
$context = context_course::instance($course->id);
self::validate_context($context);
// Can current user see user's course completion status?
// This check verifies if completion is enabled because $course is mandatory.
if (!completion_can_view_data($user->id, $course)) {
throw new moodle_exception('cannotviewreport');
}
// The previous function doesn't check groups.
if ($user->id != $USER->id) {
if (!groups_user_groups_visible($course, $user->id)) {
// We are not in the same group!
throw new moodle_exception('accessdenied', 'admin');
}
}
$info = new completion_info($course);
// Check this user is enroled.
if (!$info->is_tracked_user($user->id)) {
if ($USER->id == $user->id) {
throw new moodle_exception('notenroled', 'completion');
} else {
throw new moodle_exception('usernotenroled', 'completion');
}
}
$completions = $info->get_completions($user->id);
if (empty($completions)) {
throw new moodle_exception('nocriteriaset', 'completion');
}
// Load course completion.
$completionparams = array('userid' => $user->id, 'course' => $course->id);
$ccompletion = new completion_completion($completionparams);
$completionrows = array();
// Loop through course criteria.
foreach ($completions as $completion) {
$criteria = $completion->get_criteria();
$completionrow = array();
$completionrow['type'] = $criteria->criteriatype;
$completionrow['title'] = $criteria->get_title();
$completionrow['status'] = $completion->get_status();
$completionrow['complete'] = $completion->is_complete();
$completionrow['timecompleted'] = $completion->timecompleted;
$completionrow['details'] = $criteria->get_details($completion);
$completionrows[] = $completionrow;
}
$result = array('completed' => $info->is_course_complete($user->id), 'aggregation' => $info->get_aggregation_method(), 'completions' => $completionrows);
$results = array('completionstatus' => $result, 'warnings' => $warnings);
return $results;
}
示例14: get_scorm_sco_tracks
/**
* Retrieves SCO tracking data for the given user id and attempt number
*
* @param int $scoid the sco id
* @param int $userid the user id
* @param int $attempt the attempt number
* @return array warnings and the scoes data
* @since Moodle 3.0
*/
public static function get_scorm_sco_tracks($scoid, $userid, $attempt = 0)
{
global $USER, $DB;
$params = self::validate_parameters(self::get_scorm_sco_tracks_parameters(), array('scoid' => $scoid, 'userid' => $userid, 'attempt' => $attempt));
$tracks = array();
$warnings = array();
$sco = scorm_get_sco($params['scoid'], SCO_ONLY);
if (!$sco) {
throw new moodle_exception('cannotfindsco', 'scorm');
}
$scorm = $DB->get_record('scorm', array('id' => $sco->scorm), '*', MUST_EXIST);
$cm = get_coursemodule_from_instance('scorm', $scorm->id);
$context = context_module::instance($cm->id);
self::validate_context($context);
$user = core_user::get_user($params['userid'], '*', MUST_EXIST);
core_user::require_active_user($user);
// Extra checks so only users with permissions can view other users attempts.
if ($USER->id != $user->id) {
require_capability('mod/scorm:viewreport', $context);
}
scorm_require_available($scorm, true, $context);
if (empty($params['attempt'])) {
$params['attempt'] = scorm_get_last_attempt($scorm->id, $user->id);
}
$attempted = false;
if ($scormtracks = scorm_get_tracks($sco->id, $params['userid'], $params['attempt'])) {
// Check if attempted.
if ($scormtracks->status != '') {
$attempted = true;
foreach ($scormtracks as $element => $value) {
$tracks[] = array('element' => $element, 'value' => $value);
}
}
}
if (!$attempted) {
$warnings[] = array('item' => 'attempt', 'itemid' => $params['attempt'], 'warningcode' => 'notattempted', 'message' => get_string('notattempted', 'scorm'));
}
$result = array();
$result['data']['attempt'] = $params['attempt'];
$result['data']['tracks'] = $tracks;
$result['warnings'] = $warnings;
return $result;
}
示例15: get_selected_user_fullname
/**
* Return selected user fullname.
*
* @return string user fullname.
*/
public function get_selected_user_fullname()
{
$user = core_user::get_user($this->userid);
return fullname($user);
}