You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
1.7 KiB
50 lines
1.7 KiB
<?php
|
|
|
|
namespace Model;
|
|
|
|
use Entity\QuestionEntity;
|
|
use Entity\QuizEntity;
|
|
use Entity\QuizQuestionEntity;
|
|
use Gateway\Connection;
|
|
use Gateway\QuestionGateway;
|
|
use Gateway\QuizGateway;
|
|
use Gateway\QuizQuestionGateway;
|
|
use Gateway\Gateway;
|
|
|
|
class QuizQuestionModel extends Model
|
|
{
|
|
|
|
/**
|
|
* Retrieves all questions associated with a specific quiz.
|
|
*
|
|
* @param int $id The unique identifier of the quiz.
|
|
* @param Connection $co The database connection to be used for querying.
|
|
*
|
|
* @return QuestionEntity[] Returns an array of QuestionEntity objects representing all the questions in the quiz.
|
|
*/
|
|
public function getAllQuestionByQuiz(int $id, Connection $co): array{
|
|
// Fetch all questions related to the given quiz ID using the gateway's findQuestionsFromQuiz method.
|
|
$q = $this->gateway->findQuestionsFromQuiz($id);
|
|
|
|
// Initialize an empty array to store the QuestionEntity objects.
|
|
$questions = [];
|
|
|
|
// Create a new QuestionGateway instance using the provided database connection.
|
|
$gateway = new QuestionGateway($co);
|
|
|
|
// Create a new QuestionModel instance, passing the QuestionGateway for data operations.
|
|
$qmdl = new QuestionModel($gateway);
|
|
|
|
// Loop through each question in the result and retrieve its full details using the QuestionModel.
|
|
foreach ($q as $question) {
|
|
// Add the full QuestionEntity object for each question to the questions array.
|
|
$questions[] = $qmdl->getQuestion($question[1]);
|
|
}
|
|
|
|
// Return the array of QuestionEntity objects.
|
|
return $questions;
|
|
}
|
|
|
|
}
|
|
|
|
?>
|