本文整理汇总了PHP中completion_info::is_tracked_user方法的典型用法代码示例。如果您正苦于以下问题:PHP completion_info::is_tracked_user方法的具体用法?PHP completion_info::is_tracked_user怎么用?PHP completion_info::is_tracked_user使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类completion_info
的用法示例。
在下文中一共展示了completion_info::is_tracked_user方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get_content
public function get_content()
{
global $CFG, $USER;
// If content is cached
if ($this->content !== NULL) {
return $this->content;
}
// Create empty content
$this->content = new stdClass();
// Can edit settings?
$can_edit = has_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $this->page->course->id));
// Get course completion data
$info = new completion_info($this->page->course);
// Don't display if completion isn't enabled!
if (!completion_info::is_enabled_for_site()) {
if ($can_edit) {
$this->content->text = get_string('completionnotenabledforsite', 'completion');
}
return $this->content;
} else {
if (!$info->is_enabled()) {
if ($can_edit) {
$this->content->text = get_string('completionnotenabledforcourse', 'completion');
}
return $this->content;
}
}
// Get this user's data
$completion = $info->get_completion($USER->id, COMPLETION_CRITERIA_TYPE_SELF);
// Check if self completion is one of this course's criteria
if (empty($completion)) {
if ($can_edit) {
$this->content->text = get_string('selfcompletionnotenabled', 'block_selfcompletion');
}
return $this->content;
}
// Check this user is enroled
if (!$info->is_tracked_user($USER->id)) {
$this->content->text = get_string('notenroled', 'completion');
return $this->content;
}
// Is course complete?
if ($info->is_course_complete($USER->id)) {
$this->content->text = get_string('coursealreadycompleted', 'completion');
return $this->content;
// Check if the user has already marked themselves as complete
} else {
if ($completion->is_complete()) {
$this->content->text = get_string('alreadyselfcompleted', 'block_selfcompletion');
return $this->content;
// If user is not complete, or has not yet self completed
} else {
$this->content->text = '';
$this->content->footer = '<br /><a href="' . $CFG->wwwroot . '/course/togglecompletion.php?course=' . $this->page->course->id . '">';
$this->content->footer .= get_string('completecourse', 'block_selfcompletion') . '</a>...';
}
}
return $this->content;
}
示例2: get_content
public function get_content()
{
global $USER;
// If content is cached
if ($this->content !== NULL) {
return $this->content;
}
global $CFG;
// Create empty content
$this->content = new stdClass();
// Don't display if completion isn't enabled!
if (!$this->page->course->enablecompletion) {
$this->content->text = get_string('completionnotenabled', 'block_selfcompletion');
return $this->content;
}
// Get course completion data
$info = new completion_info($this->page->course);
$completion = $info->get_completion($USER->id, COMPLETION_CRITERIA_TYPE_SELF);
// Is course complete?
if ($info->is_course_complete($USER->id)) {
return $this->content;
}
// Check if self completion is one of this course's criteria
if (empty($completion)) {
$this->content->text = get_string('selfcompletionnotenabled', 'block_selfcompletion');
return $this->content;
}
// Check this user is enroled
if (!$info->is_tracked_user($USER->id)) {
$this->content->text = get_string('notenroled', 'completion');
return $this->content;
}
// Check if the user has already marked themselves as complete
if ($completion->is_complete()) {
return $this->content;
} else {
$this->content->text = '';
$this->content->footer = '<br /><a href="' . $CFG->wwwroot . '/course/togglecompletion.php?course=' . $this->page->course->id . '">' . get_string('completecourse', 'block_selfcompletion') . '</a>...';
}
return $this->content;
}
示例3: array
$user = $USER;
}
// Check permissions.
require_login();
if (!completion_can_view_data($user->id, $course)) {
print_error('cannotviewreport');
}
// Load completion data.
$info = new completion_info($course);
$returnurl = new moodle_url('/course/view.php', array('id' => $id));
// Don't display if completion isn't enabled.
if (!$info->is_enabled()) {
print_error('completionnotenabled', 'completion', $returnurl);
}
// Check this user is enroled.
if (!$info->is_tracked_user($user->id)) {
if ($USER->id == $user->id) {
print_error('notenroled', 'completion', $returnurl);
} else {
print_error('usernotenroled', 'completion', $returnurl);
}
}
// Display page.
$PAGE->set_context(context_course::instance($course->id));
// Print header.
$page = get_string('completionprogressdetails', 'block_completionstatus');
$title = format_string($course->fullname) . ': ' . $page;
$PAGE->navbar->add($page);
$PAGE->set_pagelayout('standard');
$PAGE->set_url('/blocks/completionstatus/details.php', array('course' => $course->id, 'user' => $user->id));
$PAGE->set_title(get_string('course') . ': ' . $course->fullname);
示例4: get_content
public function get_content()
{
global $USER, $CFG, $DB, $COURSE;
// If content is cached
if ($this->content !== NULL) {
return $this->content;
}
// Create empty content
$this->content = new stdClass();
// Can edit settings?
$can_edit = has_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $this->page->course->id));
// Get course completion data
$info = new completion_info($this->page->course);
// Don't display if completion isn't enabled!
if (!completion_info::is_enabled_for_site()) {
if ($can_edit) {
$this->content->text = get_string('completionnotenabledforsite', 'completion');
}
return $this->content;
} else {
if (!$info->is_enabled()) {
if ($can_edit) {
$this->content->text = get_string('completionnotenabledforcourse', 'completion');
}
return $this->content;
}
}
// Load criteria to display
$completions = $info->get_completions($USER->id);
// Check if this course has any criteria
if (empty($completions)) {
if ($can_edit) {
$this->content->text = get_string('nocriteriaset', 'completion');
}
return $this->content;
}
// Check this user is enroled
if (!$info->is_tracked_user($USER->id)) {
// If not enrolled, but are can view the report:
if (has_capability('report/completion:view', get_context_instance(CONTEXT_COURSE, $COURSE->id))) {
$this->content->text = '<a href="' . $CFG->wwwroot . '/report/completion/index.php?course=' . $COURSE->id . '">' . get_string('viewcoursereport', 'completion') . '</a>';
return $this->content;
}
// Otherwise, show error
$this->content->text = get_string('notenroled', 'completion');
return $this->content;
}
// Generate markup for criteria statuses
$shtml = '';
// For aggregating activity completion
$activities = array();
$activities_complete = 0;
// For aggregating course prerequisites
$prerequisites = array();
$prerequisites_complete = 0;
// Flag to set if current completion data is inconsistent with
// what is stored in the database
$pending_update = false;
// Loop through course criteria
foreach ($completions as $completion) {
$criteria = $completion->get_criteria();
$complete = $completion->is_complete();
if (!$pending_update && $criteria->is_pending($completion)) {
$pending_update = true;
}
// Activities are a special case, so cache them and leave them till last
if ($criteria->criteriatype == COMPLETION_CRITERIA_TYPE_ACTIVITY) {
$activities[$criteria->moduleinstance] = $complete;
if ($complete) {
$activities_complete++;
}
continue;
}
// Prerequisites are also a special case, so cache them and leave them till last
if ($criteria->criteriatype == COMPLETION_CRITERIA_TYPE_COURSE) {
$prerequisites[$criteria->courseinstance] = $complete;
if ($complete) {
$prerequisites_complete++;
}
continue;
}
$shtml .= '<tr><td>';
$shtml .= $criteria->get_title();
$shtml .= '</td><td style="text-align: right">';
$shtml .= $completion->get_status();
$shtml .= '</td></tr>';
}
// Aggregate activities
if (!empty($activities)) {
$shtml .= '<tr><td>';
$shtml .= get_string('activitiescompleted', 'completion');
$shtml .= '</td><td style="text-align: right">';
$a = new stdClass();
$a->first = $activities_complete;
$a->second = count($activities);
$shtml .= get_string('firstofsecond', 'block_completionstatus', $a);
$shtml .= '</td></tr>';
}
// Aggregate prerequisites
if (!empty($prerequisites)) {
//.........这里部分代码省略.........
示例5: 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;
}
示例6: get_content
public function get_content()
{
global $USER;
$rows = array();
$srows = array();
$prows = array();
// If content is cached.
if ($this->content !== null) {
return $this->content;
}
$course = $this->page->course;
$context = context_course::instance($course->id);
// Create empty content.
$this->content = new stdClass();
$this->content->text = '';
$this->content->footer = '';
// Can edit settings?
$can_edit = has_capability('moodle/course:update', $context);
// Get course completion data.
$info = new completion_info($course);
// Don't display if completion isn't enabled!
if (!completion_info::is_enabled_for_site()) {
if ($can_edit) {
$this->content->text .= get_string('completionnotenabledforsite', 'completion');
}
return $this->content;
} else {
if (!$info->is_enabled()) {
if ($can_edit) {
$this->content->text .= get_string('completionnotenabledforcourse', 'completion');
}
return $this->content;
}
}
// Load criteria to display.
$completions = $info->get_completions($USER->id);
// Check if this course has any criteria.
if (empty($completions)) {
if ($can_edit) {
$this->content->text .= get_string('nocriteriaset', 'completion');
}
return $this->content;
}
// Check this user is enroled.
if ($info->is_tracked_user($USER->id)) {
// Generate markup for criteria statuses.
$data = '';
// For aggregating activity completion.
$activities = array();
$activities_complete = 0;
// For aggregating course prerequisites.
$prerequisites = array();
$prerequisites_complete = 0;
// Flag to set if current completion data is inconsistent with what is stored in the database.
$pending_update = false;
// Loop through course criteria.
foreach ($completions as $completion) {
$criteria = $completion->get_criteria();
$complete = $completion->is_complete();
if (!$pending_update && $criteria->is_pending($completion)) {
$pending_update = true;
}
// Activities are a special case, so cache them and leave them till last.
if ($criteria->criteriatype == COMPLETION_CRITERIA_TYPE_ACTIVITY) {
$activities[$criteria->moduleinstance] = $complete;
if ($complete) {
$activities_complete++;
}
continue;
}
// Prerequisites are also a special case, so cache them and leave them till last.
if ($criteria->criteriatype == COMPLETION_CRITERIA_TYPE_COURSE) {
$prerequisites[$criteria->courseinstance] = $complete;
if ($complete) {
$prerequisites_complete++;
}
continue;
}
$row = new html_table_row();
$row->cells[0] = new html_table_cell($criteria->get_title());
$row->cells[1] = new html_table_cell($completion->get_status());
$row->cells[1]->style = 'text-align: right;';
$srows[] = $row;
}
// Aggregate activities.
if (!empty($activities)) {
$a = new stdClass();
$a->first = $activities_complete;
$a->second = count($activities);
$row = new html_table_row();
$row->cells[0] = new html_table_cell(get_string('activitiescompleted', 'completion'));
$row->cells[1] = new html_table_cell(get_string('firstofsecond', 'block_completionstatus', $a));
$row->cells[1]->style = 'text-align: right;';
$srows[] = $row;
}
// Aggregate prerequisites.
if (!empty($prerequisites)) {
$a = new stdClass();
$a->first = $prerequisites_complete;
$a->second = count($prerequisites);
//.........这里部分代码省略.........
示例7: array
if (!$cmid && !$courseid) {
print_error('invalidarguments');
}
// Process self completion
if ($courseid) {
$PAGE->set_url(new moodle_url('/course/togglecompletion.php', array('course' => $courseid)));
// Check user is logged in
$course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST);
$context = context_course::instance($course->id);
require_login($course);
$completion = new completion_info($course);
$trackeduser = $user ? $user : $USER->id;
if (!$completion->is_enabled()) {
throw new moodle_exception('completionnotenabled', 'completion');
} else {
if (!$completion->is_tracked_user($trackeduser)) {
throw new moodle_exception('nottracked', 'completion');
}
}
if ($user && $rolec) {
require_sesskey();
completion_criteria::factory(array('id' => $rolec, 'criteriatype' => COMPLETION_CRITERIA_TYPE_ROLE));
//TODO: this is dumb, because it does not fetch the data?!?!
$criteria = completion_criteria_role::fetch(array('id' => $rolec));
if ($criteria and user_has_role_assignment($USER->id, $criteria->role, $context->id)) {
$criteria_completions = $completion->get_completions($user, COMPLETION_CRITERIA_TYPE_ROLE);
foreach ($criteria_completions as $criteria_completion) {
if ($criteria_completion->criteriaid == $rolec) {
$criteria->complete($criteria_completion);
break;
}
示例8: array
$courseid = optional_param('course', 0, PARAM_INT);
$confirm = optional_param('confirm', 0, PARAM_BOOL);
if (!$cmid && !$courseid) {
print_error('invalidarguments');
}
// Process self completion
if ($courseid) {
$PAGE->set_url(new moodle_url('/course/togglecompletion.php', array('course' => $courseid)));
// Check user is logged in
$course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST);
$context = context_course::instance($course->id);
require_login($course);
$completion = new completion_info($course);
if (!$completion->is_enabled()) {
throw new moodle_exception('completionnotenabled', 'completion');
} elseif (!$completion->is_tracked_user($USER->id)) {
throw new moodle_exception('nottracked', 'completion');
}
// Check if we are marking a user complete via the completion report
$user = optional_param('user', 0, PARAM_INT);
$rolec = optional_param('rolec', 0, PARAM_INT);
if ($user && $rolec) {
require_sesskey();
completion_criteria::factory(array('id' => $rolec, 'criteriatype' => COMPLETION_CRITERIA_TYPE_ROLE));
//TODO: this is dumb, because it does not fetch the data?!?!
$criteria = completion_criteria_role::fetch(array('id' => $rolec));
if ($criteria and user_has_role_assignment($USER->id, $criteria->role, $context->id)) {
$criteria_completions = $completion->get_completions($user, COMPLETION_CRITERIA_TYPE_ROLE);
foreach ($criteria_completions as $criteria_completion) {
if ($criteria_completion->criteriaid == $rolec) {
$criteria->complete($criteria_completion);
示例9: mark_course_self_completed
/**
* Update the course completion status for the current user (if course self-completion is enabled).
*
* @param int $courseid Course id
* @return array Result and possible warnings
* @since Moodle 3.0
* @throws moodle_exception
*/
public static function mark_course_self_completed($courseid)
{
global $USER;
$warnings = array();
$params = self::validate_parameters(self::mark_course_self_completed_parameters(), array('courseid' => $courseid));
$course = get_course($params['courseid']);
$context = context_course::instance($course->id);
self::validate_context($context);
// Set up completion object and check it is enabled.
$completion = new completion_info($course);
if (!$completion->is_enabled()) {
throw new moodle_exception('completionnotenabled', 'completion');
}
if (!$completion->is_tracked_user($USER->id)) {
throw new moodle_exception('nottracked', 'completion');
}
$completion = $completion->get_completion($USER->id, COMPLETION_CRITERIA_TYPE_SELF);
// Self completion criteria not enabled.
if (!$completion) {
throw new moodle_exception('noselfcompletioncriteria', 'completion');
}
// Check if the user has already marked himself as complete.
if ($completion->is_complete()) {
throw new moodle_exception('useralreadymarkedcomplete', 'completion');
}
// Mark the course complete.
$completion->mark_complete();
$result = array();
$result['status'] = true;
$result['warnings'] = $warnings;
return $result;
}
示例10: get_content
public function get_content()
{
global $USER, $CFG, $DB, $COURSE;
if ($this->content !== null) {
return $this->content;
}
$this->content = new stdClass();
$courses1 = enrol_get_my_courses('', 'visible DESC,sortorder ASC');
//defined in lib/enrollib.php file
// Display completion status
$this->content->text .= '<table cellpadding="0" cellspacing="0" width="178" border="0">';
$this->content->text .= '<tr>';
$this->content->text .= '<td width="85" align="right"><b>Total</b>';
$this->content->text .= '</td><td align="left"><b>Over</b>';
$this->content->text .= '</td><td align="left"><b>%</b>';
$this->content->text .= '</td></tr></table>';
$this->content->text .= '<table cellpadding="0" cellspacing="0" width="178" border="0">';
foreach ($courses1 as $course1) {
if ($course1->id == SITEID) {
continue;
}
$userid = optional_param('user', 0, PARAM_INT);
// Load course
$course = $DB->get_record('course', array('id' => $course1->id));
// Load user
if ($userid) {
$user = $DB->get_record('user', array('id' => $userid), '*', MUST_EXIST);
} else {
$user = $USER;
}
$coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
$personalcontext = get_context_instance(CONTEXT_USER, $user->id);
$can_view = false;
// Can view own report
if ($USER->id == $user->id) {
$can_view = true;
} else {
if (has_capability('moodle/user:viewuseractivitiesreport', $personalcontext)) {
$can_view = true;
} else {
if (has_capability('coursereport/completion:view', $coursecontext)) {
$can_view = true;
} else {
if (has_capability('coursereport/completion:view', $personalcontext)) {
$can_view = true;
}
}
}
}
if (!$can_view) {
$this->content->text .= print_error('cannotviewreport');
}
// Load completion data
$info = new completion_info($course);
// Load criteria to display
$completions = $info->get_completions($user->id);
// Check this user is enroled
if (!$info->is_tracked_user($user->id)) {
if ($USER->id == $user->id) {
$this->content->text .= print_error('notenroled', 'completion', $returnurl);
} else {
$this->content->text .= print_error('usernotenroled', 'completion', $returnurl);
}
}
// Is course complete?
$coursecomplete = $info->is_course_complete($user->id);
// Has this user completed any criteria?
$criteriacomplete = $info->count_course_user_data($user->id);
if ($coursecomplete) {
$status = get_string('complete');
} else {
if (!$criteriacomplete) {
$status = '<i>' . get_string('notyetstarted', 'completion') . '</i>';
} else {
$status = '<i>' . get_string('inprogress', 'completion') . '</i>';
}
}
//GET TOTAL NUMBER OF TASKS ASSIGNED TO CURRENT USER
$conditions = array("course" => $course->id);
$tot_rec = $DB->count_records('course_completion_criteria', $conditions);
//GET TOTAL NUMBER OF TASKS ASSIGNED TO CURRENT USER
$result = $DB->get_records_sql('SELECT mc.coursemoduleid,mc.userid,mc.completionstate,
m.id,m.course FROM `mdl_course_modules_completion` mc
LEFT JOIN
mdl_course_modules m
ON
mc.coursemoduleid=m.id WHERE mc.userid = ? AND m.course = ?', array($user->id, $course->id));
$tot_comp = count($result);
$count1 = $tot_comp / $tot_rec;
$count2 = $count1 * 100;
$count = number_format($count2, 0);
$linkhref = new moodle_url('/course/view.php', array('id' => $course->id));
$this->content->text .= '<tr><td colspan="4"><b title="Course" style="color:#000066;">';
$this->content->text .= '<a href="' . $linkhref . '">' . $course1->fullname . '</a>';
$this->content->text .= '</b></td></tr>';
$this->content->text .= '<tr><td align="left" width="70" title="Activity completion status">';
//$this->content->text .=$course1->fullname;
$this->content->text .= $status;
$this->content->text .= '</td><td align="left" width="27" title="Total activities">' . $tot_rec;
$this->content->text .= '</td><td width="27" align="left" title="Total Activities completed">' . $tot_comp;
//.........这里部分代码省略.........