public function ScaleQuestion::deleteCollectionIfNotUsed in Quiz 7.4
Same name and namespace in other branches
- 8.6 question_types/quiz_scale/src/Plugin/quiz/QuizQuestion/ScaleQuestion.php \ScaleQuestion::deleteCollectionIfNotUsed()
- 8.5 question_types/quiz_scale/src/Plugin/quiz/QuizQuestion/ScaleQuestion.php \ScaleQuestion::deleteCollectionIfNotUsed()
- 6.6 question_types/scale/scale.classes.inc \ScaleQuestion::deleteCollectionIfNotUsed()
- 6.4 question_types/scale/scale.classes.inc \ScaleQuestion::deleteCollectionIfNotUsed()
- 7.6 question_types/scale/scale.classes.inc \ScaleQuestion::deleteCollectionIfNotUsed()
- 7 question_types/scale/scale.classes.inc \ScaleQuestion::deleteCollectionIfNotUsed()
- 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 identifies an existing collection.
File
- question_types/
scale/ scale.classes.inc, line 181 - The main classes for the scale question type.
Class
- ScaleQuestion
- Extension of QuizQuestion.
Code
public function deleteCollectionIfNotUsed($answer_collection_id, $accept = 0) {
// Check if the collection is someones preset. If it is we can't delete it.
$count = db_query('SELECT COUNT(*) FROM {quiz_scale_user} WHERE answer_collection_id = :acid', array(
':acid' => $answer_collection_id,
))
->fetchField();
if ($count > 0) {
return FALSE;
}
// Check if the collection is a global preset. If it is we can't delete it.
$for_all = db_query('SELECT for_all FROM {quiz_scale_answer_collection} WHERE id = :id', array(
':id' => $answer_collection_id,
))
->fetchField();
if ($for_all == 1) {
return FALSE;
}
// Check if the collection is used in an existing question. If it is we can't delete it.
$count = db_query('SELECT COUNT(*) FROM {quiz_scale_node_properties} WHERE answer_collection_id = :acid', array(
':acid' => $answer_collection_id,
))
->fetchField();
// We delete the answer collection if it isnt beeing used by enough questions
if ($count <= $accept) {
db_delete('quiz_scale_answer_collection')
->condition('id', $answer_collection_id)
->execute();
db_delete('quiz_scale_answer')
->condition('answer_collection_id', $answer_collection_id)
->execute();
return TRUE;
}
return FALSE;
}