function Quiz::getNumberOfQuestions in Quiz 6.x
Same name and namespace in other branches
- 8.6 src/Entity/Quiz.php \Drupal\quiz\Entity\Quiz::getNumberOfQuestions()
- 8.5 src/Entity/Quiz.php \Drupal\quiz\Entity\Quiz::getNumberOfQuestions()
Finds out the number of configured questions for the quiz, taking into account random questions pulled from a pool
Return value
int The number of quiz questions.
File
- src/
Entity/ Quiz.php, line 696
Class
- Quiz
- Defines the Quiz entity class.
Namespace
Drupal\quiz\EntityCode
function getNumberOfQuestions() {
$count = 0;
$relationships = $this
->getQuestions();
$random = $this
->get('randomization')
->getString();
switch ($random) {
case 2:
case 3:
$count = $this
->getNumberOfRequiredQuestions() + $this
->get('number_of_random_questions')->value;
break;
case 0:
case 1:
default:
foreach ($relationships as $relationship) {
if ($quizQuestion = $relationship
->getQuestion()) {
if ($quizQuestion
->isGraded()) {
$count++;
}
}
}
}
return intval($count);
}