You are here

public function ScaleQuestion::deleteCollectionIfNotUsed 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::deleteCollectionIfNotUsed()
  2. 8.5 question_types/quiz_scale/src/Plugin/quiz/QuizQuestion/ScaleQuestion.php \ScaleQuestion::deleteCollectionIfNotUsed()
  3. 6.4 question_types/scale/scale.classes.inc \ScaleQuestion::deleteCollectionIfNotUsed()
  4. 7.6 question_types/scale/scale.classes.inc \ScaleQuestion::deleteCollectionIfNotUsed()
  5. 7 question_types/scale/scale.classes.inc \ScaleQuestion::deleteCollectionIfNotUsed()
  6. 7.4 question_types/scale/scale.classes.inc \ScaleQuestion::deleteCollectionIfNotUsed()
  7. 7.5 question_types/scale/scale.classes.inc \ScaleQuestion::deleteCollectionIfNotUsed()

Deletes an answer collection if it isn't beeing used.

Parameters

$answer_collection_id :

$accept - if collection is used more than this many times we keep it.:

Return value

true if deleted, false if not deleted.

2 calls to ScaleQuestion::deleteCollectionIfNotUsed()
ScaleQuestion::delete in question_types/scale/scale.classes.inc
Implementation of delete
ScaleQuestion::saveAnswerCollection in question_types/scale/scale.classes.inc
Stores the answer collection to the database, or reuses an excisting collection.

File

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

Class

ScaleQuestion
Implementation of QuizQuestion.

Code

public function deleteCollectionIfNotUsed($answer_collection_id, $accept = 0) {
  $sql = 'SELECT COUNT(*)
    		FROM {quiz_scale_user}
    		WHERE answer_collection_id = %d';
  $results = db_fetch_array(db_query($sql, $answer_collection_id));
  if ($results['COUNT(*)'] > 0) {
    return;
  }
  $sql = 'SELECT for_all
    		FROM {quiz_scale_answer_collection}
    		WHERE id = %d';
  $results = db_fetch_object(db_query($sql, $answer_collection_id));
  if ($results->for_all == 1) {
    return;
  }
  $sql = 'SELECT COUNT(*)
    		FROM {quiz_scale_node_properties}
    		WHERE answer_collection_id = %d';
  $results = db_fetch_array(db_query($sql, $answer_collection_id));
  if ($results['COUNT(*)'] <= $accept) {
    $sql = 'DELETE FROM {quiz_scale_answer_collection}
      		  WHERE id = %d';
    db_query($sql, $answer_collection_id);
    $sql = 'DELETE FROM {quiz_scale_answer}
      		  WHERE answer_collection_id = %d';
    db_query($sql, $answer_collection_id);
    return TRUE;
  }
  return FALSE;
}