You are here

class QuizfileuploadQuestion in Quiz File Upload 7

Same name and namespace in other branches
  1. 6 quizfileupload.classes.inc \QuizfileuploadQuestion
  2. 7.5 quizfileupload.classes.inc \QuizfileuploadQuestion
  3. 7.4 quizfileupload.classes.inc \QuizfileuploadQuestion

Extension of QuizQuestion.

Hierarchy

Expanded class hierarchy of QuizfileuploadQuestion

1 string reference to 'QuizfileuploadQuestion'
quizfileupload_quiz_question_info in ./quizfileupload.module
Implementation of hook_quiz_question_info().

File

./quizfileupload.classes.inc, line 22
The main classes for the multichoice question type.

View source
class QuizfileuploadQuestion extends QuizQuestion {

  /**
   * Implementation of save
   *
   * Stores the question in the database.
   *
   * @param is_new if - if the node is a new node...
   * (non-PHPdoc)
   * @see sites/all/modules/quiz-HEAD/question_types/quiz_question/QuizQuestion#save()
   */
  public function saveNodeProperties($is_new = FALSE) {
    $is_new = $is_new || $this->node->revision == 1;
    if ($is_new) {
      db_insert('quiz_fileupload_node_properties')
        ->fields(array(
        'nid' => $this->node->nid,
        'vid' => $this->node->vid,
        'filetypes' => $this->node->filetypes,
      ))
        ->execute();
    }
    else {
      db_update('quiz_fileupload_node_properties')
        ->fields(array(
        'filetypes' => $this->node->filetypes,
      ))
        ->condition('nid', $this->node->nid)
        ->condition('vid', $this->node->vid)
        ->execute();
    }
  }

  /**
   * Implementation of validate
   *
   * QuizQuestion#validate()
   */
  public function validateNode(array &$form) {

    //no validation required
  }

  /**
   * Implementation of delete
   *
   * @see QuizQuestion#delete()
   */
  public function delete($only_this_version = FALSE) {
    if ($only_this_version) {
      db_delete('quiz_fileupload_node_properties')
        ->condition('question_nid', $this->node->nid)
        ->condition('question_vid', $this->node->vid)
        ->execute();
      db_delete('quiz_fileupload_user_answers')
        ->condition('nid', $this->node->nid)
        ->condition('vid', $this->node->vid)
        ->execute();
    }
    else {
      db_delete('quiz_fileupload_node_properties')
        ->condition('nid', $this->node->nid)
        ->execute();
      db_delete('quiz_fileupload_user_answers')
        ->condition('question_nid', $this->node->nid)
        ->execute();
    }
    parent::delete($only_this_version);
  }

  /**
   * Implementation of getNodeProperties
   *
   * @see QuizQuestion#getNodeProperties()
   */
  public function getNodeProperties() {
    if (isset($this->nodeProperties)) {
      return $this->nodeProperties;
    }
    $props = parent::getNodeProperties();

    // Load the properties
    $res_a = db_query('SELECT filetypes FROM {quiz_fileupload_node_properties} WHERE nid = :nid AND vid = :vid', array(
      ':nid' => $this->node->nid,
      ':vid' => $this->node->vid,
    ))
      ->fetchAssoc();
    if (is_array($res_a)) {
      $props = array_merge($props, $res_a);
    }
    $this->nodeProperties = $props;
    return $props;
  }

  /**
   * Implementation of getNodeView
   *
   * @see QuizQuestion#getNodeView()
   */
  public function getNodeView() {
    $content = parent::getNodeView();
    $content['filetypes'] = array(
      '#type' => 'markup',
      '#value' => '<pre>' . check_plain($this->node->filetypes) . '</pre>',
    );
    return $content;
  }

  /**
   * Generates the question form.
   *
   * This is called whenever a question is rendered, either
   * to an administrator or to a quiz taker.
   */
  public function getAnsweringForm(array $form_state = NULL, $rid) {
    $form = parent::getAnsweringForm($form_state, $rid);
    $fid = db_query('SELECT qf.fid
      FROM {quiz_fileupload_user_answers} qf
      WHERE question_nid = :nid AND question_vid = :vid AND result_id = :result_id', array(
      ':nid' => $this->node->nid,
      ':vid' => $this->node->vid,
      ':result_id' => $rid,
    ))
      ->fetchField();
    if (is_numeric($fid)) {
      $form['previous_upload'] = array(
        '#title' => t('Previous upload'),
        '#type' => 'item',
        '#markup' => quiz_file_markup($fid),
        '#description' => t('<strong>Upload a new file to replace previous upload.</strong>'),
      );
    }
    $form['tries'] = array(
      '#type' => 'file',
      '#title' => t('Upload'),
      '#description' => t('Allowed extensions !ext', array(
        '!ext' => $this->node->filetypes,
      )),
    );
    return $form;
  }

  /**
   * Implementation of getCreationForm
   *
   * @see QuizQuestion#getCreationForm()
   */
  public function getCreationForm(array &$form_state = NULL) {
    $allowed = variable_get('quizfileupload_default_extensions', QUIZFILEUPLOAD_DEFAULT_EXTENSIONS);
    $form['filetypes'] = array(
      '#type' => 'textfield',
      '#title' => t('Allowed extension'),
      '#description' => t('Enter the allowed file extensions one per line.'),
      '#default_value' => isset($this->node->filetypes) ? $this->node->filetypes : $allowed,
      '#required' => TRUE,
    );
    return $form;
  }

  /**
   * Implementation of getMaximumScore
   *
   * @see QuizQuestion#getMaximumScore()
   */
  public function getMaximumScore() {
    return variable_get('quizfileupload_default_score', 1);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
QuizfileuploadQuestion::delete public function Implementation of delete
QuizfileuploadQuestion::getAnsweringForm public function Generates the question form.
QuizfileuploadQuestion::getCreationForm public function Implementation of getCreationForm
QuizfileuploadQuestion::getMaximumScore public function Implementation of getMaximumScore
QuizfileuploadQuestion::getNodeProperties public function Implementation of getNodeProperties
QuizfileuploadQuestion::getNodeView public function Implementation of getNodeView
QuizfileuploadQuestion::saveNodeProperties public function Implementation of save
QuizfileuploadQuestion::validateNode public function Implementation of validate