You are here

public function ScaleQuestion::saveAnswerCollection in Quiz 6.6

Same name and namespace in other branches
  1. 8.6 question_types/quiz_scale/src/Plugin/quiz/QuizQuestion/ScaleQuestion.php \ScaleQuestion::saveAnswerCollection()
  2. 8.5 question_types/quiz_scale/src/Plugin/quiz/QuizQuestion/ScaleQuestion.php \ScaleQuestion::saveAnswerCollection()
  3. 6.4 question_types/scale/scale.classes.inc \ScaleQuestion::saveAnswerCollection()
  4. 7.6 question_types/scale/scale.classes.inc \ScaleQuestion::saveAnswerCollection()
  5. 7 question_types/scale/scale.classes.inc \ScaleQuestion::saveAnswerCollection()
  6. 7.4 question_types/scale/scale.classes.inc \ScaleQuestion::saveAnswerCollection()
  7. 7.5 question_types/scale/scale.classes.inc \ScaleQuestion::saveAnswerCollection()

Stores the answer collection to the database, or reuses an excisting collection.

Parameters

$is_new_node - the question is beeing inserted(not updated):

$alt_input - the alternatives array to be saved.:

$preset - 1 | 0 = preset | not preset:

Return value

unknown_type

1 call to ScaleQuestion::saveAnswerCollection()
ScaleQuestion::save in question_types/scale/scale.classes.inc
Implementation of save

File

question_types/scale/scale.classes.inc, line 105
The main classes for the scale question type.

Class

ScaleQuestion
Implementation of QuizQuestion.

Code

public function saveAnswerCollection($is_new_node, $alt_input = NULL, $preset = NULL) {
  global $user;
  if (!isset($alt_input)) {
    $alt_input = get_object_vars($this->node);
  }
  if (!isset($preset)) {
    $preset = $this->node->save;
  }
  $alternatives = array();

  // Fetching alternatives
  for ($i = 0; $i < variable_get('scale_max_num_of_alts', 10); $i++) {
    if (strlen($alt_input['alternative' . $i]) > 0) {
      $alternatives[] = $alt_input['alternative' . $i];
    }
  }
  if ($answer_collection_id = $this
    ->excistingCollection($alternatives)) {
    if ($preset == 1) {
      $this
        ->setPreset($answer_collection_id);
    }
    if (!$is_new_node || $this->util) {
      $col_to_delete = $this->util ? $this->col_id : $this->node->{0}->answer_collection_id;
      if ($col_to_delete != $answer_collection_id) {
        $this
          ->deleteCollectionIfNotUsed($col_to_delete, 1);
      }
    }
    return $answer_collection_id;
  }
  db_query('INSERT INTO {quiz_scale_answer_collection} () VALUES ()');
  $answer_collection_id = db_last_insert_id('quiz_scale_answer_collection', 'id');
  if ($preset == 1) {
    $sql = 'INSERT INTO {quiz_scale_user}
              (uid, answer_collection_id)
              VALUES (%d, %d)';
    db_query($sql, $user->uid, $answer_collection_id);
  }
  db_lock_table('quiz_scale_answer');
  for ($i = 0; $i < count($alternatives); $i++) {
    $this
      ->saveAlternative($alternatives[$i], $answer_collection_id);
  }
  db_unlock_tables();
  return $answer_collection_id;
}