class CourseReport in Course 6
Same name and namespace in other branches
- 7.2 includes/CourseReport.inc \CourseReport
- 7 includes/CourseReport.inc \CourseReport
Holds a user's total progress through a course and functionality to check for completion of required objects.
Hierarchy
- class \CourseHandler
- class \CourseReport
Expanded class hierarchy of CourseReport
File
- includes/
course.core.inc, line 266 - course.core.inc File for main Course class.
View source
class CourseReport extends CourseHandler {
private $course;
/**
* @param Course $course
*/
public function __construct($course) {
$this->primaryKey = 'crid';
$this->handlerType = 'course_report';
$this->serializedField = 'data';
$this->table = 'course_report';
$this->course = $course;
$sql = "SELECT * FROM {course_report} WHERE nid = %d AND uid = %d";
$result = db_query($sql, $this->course
->getNode()->nid, $this->course
->getUser()->uid);
if ($config = db_fetch_array($result)) {
parent::__construct($config);
}
else {
parent::__construct(array(
'nid' => $this->course
->getNode()->nid,
'uid' => $this->course
->getUser()->uid,
));
}
}
/**
* Get the course of this tracker.
*
* @return Course
*/
public function getCourse() {
return $this->course;
}
/**
* Track the course (scan required objects, update progress, completion, etc).
*/
public function track() {
$required = 0;
$required_complete = 0;
$prev = NULL;
foreach ($this->course
->getObjects() as $courseObject) {
if (!$courseObject
->getOption('enabled')) {
continue;
}
if (!$prev) {
$this
->setOption('section_name', $courseObject
->getTitle());
}
// Count required objects.
$required += $courseObject
->getOption('required');
// Count completed required objects.
$required_complete += $courseObject
->getOption('required') && $courseObject
->getFulfillment()
->isComplete();
// Log last grade.
if ($courseObject
->isGraded() && $courseObject
->getOption('grade_include')) {
$this
->setOption('grade_result', $courseObject
->getFulfillment()
->getOption('grade_result'));
}
if (!$courseObject
->getFulfillment()
->isComplete() && $prev && $prev
->getFulfillment()
->isComplete()) {
$this
->setOption('section_name', $courseObject
->getTitle());
}
$prev = clone $courseObject;
}
if ($required_complete >= $required) {
// Course requirements have been met.
$this
->setOption('section', 'complete');
$this
->setOption('section_name', 'Complete');
$this
->setOption('complete', 1);
if (!$this
->getOption('date_completed')) {
$this
->setOption('date_completed', time());
}
}
$this
->setOption('nid', $this->course
->getNode()->nid);
$this
->setOption('uid', $this->course
->getUser()->uid);
module_invoke_all('course_report_presave', $this);
$op = $this
->getOption($this->primaryKey) ? 'update' : 'insert';
$this
->save();
module_invoke_all("course_report_{$op}", $this);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CourseHandler:: |
private | property | ||
CourseHandler:: |
protected | property | ||
CourseHandler:: |
public | property | ||
CourseHandler:: |
public | property | ||
CourseHandler:: |
public | property | ||
CourseHandler:: |
public | property | ||
CourseHandler:: |
final public | function | Merge an array of options onto the existing options. | |
CourseHandler:: |
public | function | Get an array of access messages. | |
CourseHandler:: |
protected | function | Return an array of database fields. This determines what fields should be serialized instead of stored. | |
CourseHandler:: |
function | |||
CourseHandler:: |
final public | function | Get an option stored in this CourseObject. | |
CourseHandler:: |
public | function | Get an object's configuration. | 1 |
CourseHandler:: |
public | function | Stub. Get the summary of an object's options. | 1 |
CourseHandler:: |
public | function | Return a list of warning strings about this handler. | 1 |
CourseHandler:: |
protected | function | Handlers need to declare their defaults if they have a configuration form. | 4 |
CourseHandler:: |
public | function | Handlers can declare a form. | 4 |
CourseHandler:: |
private | function | Merge arrays with replace, not append. | |
CourseHandler:: |
public | function | Save data somewhere. | 1 |
CourseHandler:: |
public | function | Validate? | 3 |
CourseHandler:: |
public | function | 2 | |
CourseHandler:: |
public | function | Set an access message to be displayed along with the course object when it is in the outline. For example, "This activity will open on XYZ" or "Please complete Step 1 to take this activity." | |
CourseHandler:: |
final public | function | Set an option for this handler. | |
CourseHandler:: |
final public | function | Set this entire handler's options. | |
CourseReport:: |
private | property | ||
CourseReport:: |
public | function | Get the course of this tracker. | |
CourseReport:: |
public | function | Track the course (scan required objects, update progress, completion, etc). | |
CourseReport:: |
public | function |
Overrides CourseHandler:: |