public function CourseReport::track in Course 7
Same name and namespace in other branches
- 6 includes/course.core.inc \CourseReport::track()
- 7.2 includes/CourseReport.inc \CourseReport::track()
Track the course (scan required objects, update progress, completion, etc).
File
- includes/
CourseReport.inc, line 21
Class
- CourseReport
- Holds a user's total progress through a course and functionality to check for completion of required objects.
Code
public function track() {
$required = 0;
$required_complete = 0;
$prev = NULL;
$account = user_load($this->uid);
foreach ($this
->getCourse()
->getObjects() as $courseObject) {
if (!$courseObject
->getOption('enabled')) {
continue;
}
if (!$prev) {
$this
->setOption('section_name', $courseObject
->getTitle());
$this
->setOption('coid', $courseObject
->getId());
}
// Count required objects.
$required += $courseObject
->getOption('required');
// Count completed required objects.
$required_complete += $courseObject
->getOption('required') && $courseObject
->getFulfillment($account)
->isComplete();
// Log last grade.
if ($courseObject
->isGraded() && $courseObject
->getOption('grade_include')) {
$this
->setOption('grade_result', $courseObject
->getFulfillment($account)
->getOption('grade_result'));
}
if (!$courseObject
->getFulfillment($account)
->isComplete() && $prev && $prev
->getFulfillment($account)
->isComplete()) {
$this
->setOption('section_name', $courseObject
->getTitle());
$this
->setOption('coid', $courseObject
->getId());
}
$prev = clone $courseObject;
}
if ($required_complete >= $required) {
// Course requirements have been met.
$this
->setOption('section', 'complete');
$this
->setOption('section_name', t('Complete'));
$this
->setOption('complete', 1);
if (!$this
->getOption('date_completed')) {
$this
->setOption('date_completed', REQUEST_TIME);
}
}
$this
->save();
}