public function QuizResult::getLayout in Quiz 6.x
Same name and namespace in other branches
- 8.6 src/Entity/QuizResult.php \Drupal\quiz\Entity\QuizResult::getLayout()
- 8.5 src/Entity/QuizResult.php \Drupal\quiz\Entity\QuizResult::getLayout()
Get the layout for this quiz result.
The layout contains the questions to be delivered.
Return value
3 calls to QuizResult::getLayout()
- QuizResult::copyToQuizResult in src/
Entity/ QuizResult.php - Copy this result's answers onto another Quiz result, based on the new Quiz result's settings.
- QuizResult::finalize in src/
Entity/ QuizResult.php - Score a quiz result.
- QuizResult::score in src/
Entity/ QuizResult.php - Calculates the score user received on quiz.
File
- src/
Entity/ QuizResult.php, line 78
Class
- QuizResult
- Defines the Quiz entity class.
Namespace
Drupal\quiz\EntityCode
public function getLayout() {
if ($this
->isNew()) {
// New results do not have layouts yet.
return [];
}
$quiz_result_answers = Drupal::entityTypeManager()
->getStorage('quiz_result_answer')
->loadByProperties([
'result_id' => $this
->id(),
]);
// @todo when we load the layout we have to load the question relationships
// too because we need to know the parentage
$quiz_question_relationship = Drupal::entityTypeManager()
->getStorage('quiz_question_relationship')
->loadByProperties([
'quiz_vid' => $this
->get('vid')
->getString(),
]);
$id_qqr = [];
foreach ($quiz_question_relationship as $rel) {
$id_qqr[$rel
->get('question_id')
->getString()] = $rel;
}
$layout = [];
foreach ($quiz_result_answers as $quiz_result_answer) {
$layout[$quiz_result_answer
->get('number')
->getString()] = $quiz_result_answer;
$question_id = $quiz_result_answer
->get('question_id')
->getString();
if (isset($id_qqr[$question_id])) {
// Question is in a relationship.
// @todo better way to do this? We need to load the relationship
// hierarchy onto the result answers.
$quiz_result_answer->qqr_id = $id_qqr[$question_id]
->get('qqr_id')
->getString();
$quiz_result_answer->qqr_pid = $id_qqr[$question_id]
->get('qqr_pid')
->getString();
}
}
ksort($layout, SORT_NUMERIC);
return $layout;
}