You are here

class CourseReport in Course 6

Same name and namespace in other branches
  1. 7.2 includes/CourseReport.inc \CourseReport
  2. 7 includes/CourseReport.inc \CourseReport

Holds a user's total progress through a course and functionality to check for completion of required objects.

Hierarchy

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

Namesort descending Modifiers Type Description Overrides
CourseHandler::$accessMessages private property
CourseHandler::$config protected property
CourseHandler::$handlerType public property
CourseHandler::$primaryKey public property
CourseHandler::$serializedField public property
CourseHandler::$table public property
CourseHandler::addOptions final public function Merge an array of options onto the existing options.
CourseHandler::getAccessMessages public function Get an array of access messages.
CourseHandler::getDatabaseFields protected function Return an array of database fields. This determines what fields should be serialized instead of stored.
CourseHandler::getId function
CourseHandler::getOption final public function Get an option stored in this CourseObject.
CourseHandler::getOptions public function Get an object's configuration. 1
CourseHandler::getOptionsSummary public function Stub. Get the summary of an object's options. 1
CourseHandler::getWarnings public function Return a list of warning strings about this handler. 1
CourseHandler::optionsDefinition protected function Handlers need to declare their defaults if they have a configuration form. 4
CourseHandler::optionsForm public function Handlers can declare a form. 4
CourseHandler::optionsMerge private function Merge arrays with replace, not append.
CourseHandler::optionsSubmit public function Save data somewhere. 1
CourseHandler::optionsValidate public function Validate? 3
CourseHandler::save public function 2
CourseHandler::setAccessMessage 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::setOption final public function Set an option for this handler.
CourseHandler::setOptions final public function Set this entire handler's options.
CourseReport::$course private property
CourseReport::getCourse public function Get the course of this tracker.
CourseReport::track public function Track the course (scan required objects, update progress, completion, etc).
CourseReport::__construct public function Overrides CourseHandler::__construct