public function ScaleQuestion::deleteCollectionIfNotUsed in Quiz 8.5
Same name and namespace in other branches
- 8.6 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.4 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 being used.
Parameters
int $answer_collection_id: Answer collection id.
int $accept: If collection is used more than this many times we keep it.
Return value
bool TRUE if deleted, FALSE if not deleted.
2 calls to ScaleQuestion::deleteCollectionIfNotUsed()
- ScaleQuestion::delete in question_types/
quiz_scale/ src/ Plugin/ quiz/ QuizQuestion/ ScaleQuestion.php - Implementation of delete().
- ScaleQuestion::saveAnswerCollection in question_types/
quiz_scale/ src/ Plugin/ quiz/ QuizQuestion/ ScaleQuestion.php - Stores|Identifies the answer collection.
File
- question_types/
quiz_scale/ src/ Plugin/ quiz/ QuizQuestion/ ScaleQuestion.php, line 192 - Scale classes.
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 isn't being 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;
}