function Quiz::getQuestions in Quiz 8.6
Same name and namespace in other branches
- 8.5 src/Entity/Quiz.php \Drupal\quiz\Entity\Quiz::getQuestions()
- 6.x src/Entity/Quiz.php \Drupal\quiz\Entity\Quiz::getQuestions()
Retrieve list of published questions assigned to quiz.
This function should be used for question browsers and similiar... It should not be used to decide what questions a user should answer when taking a quiz. quiz_build_question_list is written for that purpose.
Return value
An array of questions.
1 call to Quiz::getQuestions()
- Quiz::getNumberOfQuestions in src/
Entity/ Quiz.php - Finds out the number of configured questions for the quiz, taking into account random questions pulled from a pool
File
- src/
Entity/ Quiz.php, line 764
Class
- Quiz
- Defines the Quiz entity class.
Namespace
Drupal\quiz\EntityCode
function getQuestions() {
$relationships = Drupal::entityTypeManager()
->getStorage('quiz_question_relationship')
->loadByProperties([
'quiz_id' => $this
->id(),
'quiz_vid' => $this
->getRevisionId(),
]);
return $relationships;
$questions = array();
$query = db_select('quiz_question', 'n');
$query
->fields('n', array(
'qqid',
'type',
));
$query
->fields('nr', array(
'vid',
'title',
));
$query
->fields('qnr', array(
'question_status',
'weight',
'max_score',
'auto_update_max_score',
'qnr_id',
'qqr_pid',
'question_id',
'question_vid',
));
$query
->addField('n', 'vid', 'latest_vid');
$query
->join('quiz_question_revision', 'nr', 'n.qid = nr.qid');
$query
->leftJoin('quiz_question_relationship', 'qnr', 'nr.vid = qnr.child_vid');
$query
->condition('n.status', 1);
$query
->condition('qnr.quiz_id', $quiz_nid);
if ($quiz_vid) {
$query
->condition('qnr.quiz_vid', $quiz_vid);
}
$query
->condition('qqr_pid', NULL, 'IS');
$query
->orderBy('qnr.weight');
$result = $query
->execute();
foreach ($result as $question) {
$questions[] = $question;
quiz_get_sub_questions($question->qnr_id, $questions);
}
return $questions;
}