class CourseObjectQuiz in Course 6
Same name and namespace in other branches
- 7.2 modules/course_quiz/course_quiz.classes.inc \CourseObjectQuiz
 - 7 modules/course_quiz/course_quiz.classes.inc \CourseObjectQuiz
 
Hierarchy
- class \CourseHandler
- class \CourseObject
- class \CourseObjectNode
- class \CourseObjectQuiz
 
 
 - class \CourseObjectNode
 
 - class \CourseObject
 
Expanded class hierarchy of CourseObjectQuiz
1 string reference to 'CourseObjectQuiz'
- course_quiz_course_handlers in modules/
course_quiz/ course_quiz.module  - Implements hook_course_handlers().
 
File
- modules/
course_quiz/ course_quiz.classes.inc, line 3  
View source
class CourseObjectQuiz extends CourseObjectNode {
  /**
   * Create the quiz node and set it as this object's instance.
   */
  function create() {
    $quiz = new stdClass();
    $quiz->auto_created = TRUE;
    $quiz->type = 'quiz';
    $quiz->title = $this
      ->getTitle();
    $quiz->uid = $this->user->uid;
    $quiz->quiz_always = TRUE;
    $quiz->quiz_open = $quiz->quiz_close = array(
      'month' => date('m'),
      'day' => date('d'),
      'year' => date('Y'),
    );
    $quiz = (object) array_merge(_quiz_get_node_defaults(), (array) $quiz);
    node_save($quiz);
    $this
      ->setNode($quiz);
  }
  /**
   * The take URL of the quiz is /take.
   */
  function getTakeUrl() {
    return url("node/{$this->node->nid}/take");
  }
  /**
   * Marks a user's fulfillment record for this object complete if the user
   * passed the quiz.
   */
  function grade($user, $rid) {
    $nid = (int) $this
      ->getInstanceId();
    $fulfillment = $this
      ->getFulfillment();
    $result_ids = (array) $fulfillment
      ->getOption('quiz_result_ids');
    $result_ids[] = $rid;
    $fulfillment
      ->setOption('quiz_result_ids', $result_ids);
    $result = reset(quiz_get_score_data(array(
      $nid,
    ), $user->uid));
    if ($result && $result->percent_score >= $this
      ->getOption('passing_grade')) {
      $fulfillment
        ->setGrade($result->percent_score)
        ->setComplete()
        ->save();
    }
    else {
      $fulfillment
        ->setGrade($result->percent_score)
        ->save();
    }
  }
  /**
   * Course quiz options.
   */
  public function optionsDefinition() {
    $options = parent::optionsDefinition();
    $options['passing_grade'] = 75;
    return $options;
  }
  /**
   * Add an option only pertinent to quiz?
   */
  public function optionsForm(&$form, &$form_state) {
    parent::optionsForm($form, $form_state);
    $defaults = $this
      ->getOptions();
    $form['grading']['passing_grade'] = array(
      '#title' => t('Passing grade'),
      '#type' => 'textfield',
      '#size' => 4,
      '#default_value' => $defaults['passing_grade'],
      '#description' => t('The user will not be able to proceed past this object unless this grade is met.'),
    );
  }
  /**
   * Let the user know if they have a Quiz without questions.
   */
  public function getWarnings() {
    $warnings = parent::getWarnings();
    if ($this
      ->getInstanceId()) {
      if (!quiz_get_number_of_questions($this->node->vid)) {
        $warnings[] = t('This Quiz does not have any questions. Please !link.', array(
          '!link' => l('add questions', "node/{$this->getInstanceId()}/questions"),
        ));
      }
    }
    return $warnings;
  }
  public function getReports() {
    return array(
      'results' => array(
        'title' => 'Results',
      ),
    );
  }
  public function getReport($key) {
    module_load_include('inc', 'quiz', 'quiz.admin');
    switch ($key) {
      case 'results':
        return array(
          'title' => t('Quiz results'),
          'content' => drupal_get_form('quiz_results_manage_results_form', $this->node),
        );
    }
  }
  /**
   * Remove all quiz attempts associated with this fulfillment.
   */
  public function unenroll() {
    parent::unenroll();
    $fulfillment = $this
      ->getFulfillment();
    quiz_delete_results((array) $fulfillment
      ->getOption('quiz_result_ids'));
  }
  function getNodeTypes() {
    return array(
      'quiz',
    );
  }
  function isGraded() {
    return TRUE;
  }
  function getCloneAbility() {
    return t('%object can only be partially cloned. It will be created with the same settings, but the without the questions', array(
      '%object' => $this
        ->getTitle(),
    ));
  }
  /**
   * Exception for quiz: we need to set auto_created.
   */
  function thaw($ice) {
    $this->node = $ice->node;
    unset($this->node->nid);
    $this->node->auto_created = TRUE;
    node_save($this->node);
    return $this->node->nid;
  }
  function getOptionsSummary() {
    $summary = parent::getOptionsSummary();
    if ($this
      ->getInstanceId()) {
      $summary['questions'] = l('Edit questions', "node/{$this->getInstanceId()}/questions");
    }
    return $summary;
  }
}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:: | 
                  private | function | Merge arrays with replace, not append. | |
| 
            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. | |
| 
            CourseObject:: | 
                  private | property | ||
| 
            CourseObject:: | 
                  private | property | ||
| 
            CourseObject:: | 
                  protected | property | ||
| 
            CourseObject:: | 
                  public | function | Access functionality for course objects. | |
| 
            CourseObject:: | 
                  function | Get the object component for this course object. | ||
| 
            CourseObject:: | 
                  function | Get the Course that contains this CourseObject. | ||
| 
            CourseObject:: | 
                  function | Get the course node ID this CourseObject belongs to. | ||
| 
            CourseObject:: | 
                  public | function | Get this course object's fulfillment object. | |
| 
            CourseObject:: | 
                  function | Get the instance ID. This could be the external component ID, a Node ID... | ||
| 
            CourseObject:: | 
                  public static | function | Return the number of occurances that can be in a course at the same time. For example, the design of the Certificate module can only have 1 set of mappings per node. The same goes for Course Credit. We may also want a course object that can only be… | 2 | 
| 
            CourseObject:: | 
                  function | Get the module that provides this course object. | ||
| 
            CourseObject:: | 
                  public | function | 
            Get options, with session options having precedence. Overrides CourseHandler:: | 
                  |
| 
            CourseObject:: | 
                  public | function | Get the user's status in this course object. | 1 | 
| 
            CourseObject:: | 
                  function | |||
| 
            CourseObject:: | 
                  public | function | Return the URL to the course object router. | |
| 
            CourseObject:: | 
                  public | function | Specify whether fulfillment uses asynchronous polling. | 2 | 
| 
            CourseObject:: | 
                  public | function | ||
| 
            CourseObject:: | 
                  public | function | Is this course object required for course completion? | |
| 
            CourseObject:: | 
                  function | Checks the temporary status of a course object. | ||
| 
            CourseObject:: | 
                  private | function | ||
| 
            CourseObject:: | 
                  public | function | Override navigation links. | 1 | 
| 
            CourseObject:: | 
                  public | function | Overrides a course outline list item. | 1 | 
| 
            CourseObject:: | 
                  function | Give the course object a chance do asynchronous polling and set completion on demand. | ||
| 
            CourseObject:: | 
                  public | function | Get all course object implementations of getOptionsSummary(). | |
| 
            CourseObject:: | 
                  function | Set the object component for this course object. | ||
| 
            CourseObject:: | 
                  public | function | Set the Course for this CourseObject. | |
| 
            CourseObject:: | 
                  function | Set the internal course object ID. | ||
| 
            CourseObject:: | 
                  function | Set this object's instance ID. | ||
| 
            CourseObject:: | 
                  function | Set the module that provides this course object. | ||
| 
            CourseObject:: | 
                  function | Set the user fulfilling/creating this course object. | ||
| 
            CourseObject:: | 
                  public | function | 5 | |
| 
            CourseObject:: | 
                  final public | function | Take a course object. | |
| 
            CourseObject:: | 
                  function | Remove any records associated with this course object for the user. | 1 | |
| 
            CourseObjectNode:: | 
                  protected | property | ||
| 
            CourseObjectNode:: | 
                  public | function | 
            Destroy the node instance. Overrides CourseObject:: | 
                  |
| 
            CourseObjectNode:: | 
                  function | 
            Freeze data to persist over cloning/exporting. Overrides CourseObject:: | 
                  ||
| 
            CourseObjectNode:: | 
                  public | function | 
            Get the URL to edit this course object, if any. Overrides CourseObject:: | 
                  |
| 
            CourseObjectNode:: | 
                  public | function | 
            Simple node course object behavior is to just redirect to the node. Overrides CourseObject:: | 
                  3 | 
| 
            CourseObjectNode:: | 
                  function | 
            Grant access to course content before going to it. Overrides CourseObject:: | 
                  ||
| 
            CourseObjectNode:: | 
                  public | function | ||
| 
            CourseObjectNode:: | 
                  public | function | 
            Save object configs to cache. Overrides CourseObject:: | 
                  2 | 
| 
            CourseObjectNode:: | 
                  public | function | 
            Validate the options form. Check the node type. Overrides CourseObject:: | 
                  |
| 
            CourseObjectNode:: | 
                  function | 
            Duration expired (or something) - CourseObject is telling us so. Overrides CourseObject:: | 
                  ||
| 
            CourseObjectNode:: | 
                  function | 
            On object write, set privacy on this node. Overrides CourseObject:: | 
                  ||
| 
            CourseObjectNode:: | 
                  public | function | Set the node and instance ID (node ID) of this CourseObjectNode. | |
| 
            CourseObjectNode:: | 
                  public | function | 
            Construct a course object from a database record. Overrides CourseObject:: | 
                  |
| 
            CourseObjectQuiz:: | 
                  function | 
            Create the quiz node and set it as this object's instance. Overrides CourseObjectNode:: | 
                  ||
| 
            CourseObjectQuiz:: | 
                  function | 
            Returns an translated error message if this object has issues with cloning. Overrides CourseObjectNode:: | 
                  ||
| 
            CourseObjectQuiz:: | 
                  function | 
            Return a list of valid node types. Overrides CourseObjectNode:: | 
                  ||
| 
            CourseObjectQuiz:: | 
                  function | 
            Get core options summary. Overrides CourseObject:: | 
                  ||
| 
            CourseObjectQuiz:: | 
                  public | function | 
            Let the course object provide its own reports. Overrides CourseObject:: | 
                  |
| 
            CourseObjectQuiz:: | 
                  public | function | 
            Let the course object provide its own reports. Overrides CourseObject:: | 
                  |
| 
            CourseObjectQuiz:: | 
                  function | 
            The take URL of the quiz is /take. Overrides CourseObjectNode:: | 
                  ||
| 
            CourseObjectQuiz:: | 
                  public | function | 
            Let the user know if they have a Quiz without questions. Overrides CourseObjectNode:: | 
                  |
| 
            CourseObjectQuiz:: | 
                  function | Marks a user's fulfillment record for this object complete if the user passed the quiz. | ||
| 
            CourseObjectQuiz:: | 
                  function | 
            Is this object graded? Overrides CourseObject:: | 
                  ||
| 
            CourseObjectQuiz:: | 
                  public | function | 
            Course quiz options. Overrides CourseObjectNode:: | 
                  |
| 
            CourseObjectQuiz:: | 
                  public | function | 
            Add an option only pertinent to quiz? Overrides CourseObjectNode:: | 
                  |
| 
            CourseObjectQuiz:: | 
                  function | 
            Exception for quiz: we need to set auto_created. Overrides CourseObjectNode:: | 
                  ||
| 
            CourseObjectQuiz:: | 
                  public | function | Remove all quiz attempts associated with this fulfillment. |