-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
713 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<?php | ||
|
||
class Answer | ||
{ | ||
private int $id; | ||
private string $title; | ||
private bool $isRight; | ||
|
||
public function __construct($array) | ||
{ | ||
$this->setTitle($array['answer_title']); | ||
$this->setId($array['answer_id']); | ||
$this->setIsRight($array['answer_isRight']); | ||
} | ||
|
||
/** | ||
* Get the value of answer | ||
*/ | ||
public function getTitle() | ||
{ | ||
return $this->title; | ||
} | ||
|
||
/** | ||
* Set the value of answer | ||
* | ||
* @return self | ||
*/ | ||
public function setTitle($title) | ||
{ | ||
$this->title = $title; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Get the value of id | ||
*/ | ||
public function getId() | ||
{ | ||
return $this->id; | ||
} | ||
|
||
/** | ||
* Set the value of id | ||
* | ||
* @return self | ||
*/ | ||
public function setId($id) | ||
{ | ||
$this->id = $id; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Get the value of isRight | ||
*/ | ||
public function getIsRight() | ||
{ | ||
return $this->isRight; | ||
} | ||
|
||
/** | ||
* Set the value of isRight | ||
* | ||
* @return self | ||
*/ | ||
public function setIsRight($isRight) | ||
{ | ||
$this->isRight = $isRight; | ||
|
||
return $this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<?php | ||
|
||
class QCM | ||
{ | ||
private int $id; | ||
private string $title; | ||
private array $questions; | ||
|
||
/** | ||
* Get the value of questions | ||
* | ||
* @return array $questions | ||
*/ | ||
public function __construct($array) | ||
{ | ||
$this->setTitle($array['qcm_title'])->setId($array['qcm_id']); | ||
} | ||
public function getQuestions() | ||
{ | ||
return $this->questions; | ||
} | ||
/** | ||
* Add a question | ||
* @param Question $question | ||
* @return Question | ||
*/ | ||
public function addQuestions(Question $question) | ||
{ | ||
$this->questions[] = $question; | ||
return $this->questions[sizeof($this->questions) - 1]; | ||
} | ||
|
||
public function show() | ||
{ | ||
include '../app/includes/show.php'; | ||
} | ||
|
||
/** | ||
* Get the value of title | ||
*/ | ||
public function getTitle() | ||
{ | ||
return $this->title; | ||
} | ||
|
||
/** | ||
* Set the value of title | ||
* | ||
* @return self | ||
*/ | ||
public function setTitle($title) | ||
{ | ||
$this->title = $title; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Get the value of id | ||
*/ | ||
public function getId() | ||
{ | ||
return $this->id; | ||
} | ||
|
||
/** | ||
* Set the value of id | ||
* | ||
* @return self | ||
*/ | ||
public function setId($id) | ||
{ | ||
$this->id = $id; | ||
|
||
return $this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<?php | ||
|
||
class Question | ||
{ | ||
private int $id; | ||
private string $title; | ||
private array $answers; | ||
|
||
public function __construct($array) | ||
{ | ||
$this->setTitle($array['question_title']); | ||
$this->setId($array['question_id']); | ||
} | ||
/** | ||
* Get the value of answers | ||
* | ||
* @return array $answers | ||
*/ | ||
|
||
public function getAnswers() | ||
{ | ||
return $this->answers; | ||
} | ||
|
||
/** | ||
* Add an Answer | ||
* @param Answer $answer | ||
* @return self | ||
*/ | ||
public function addAnswers(Answer $answer) | ||
{ | ||
$this->answers[] = $answer; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Get the value of question | ||
*/ | ||
public function getTitle() | ||
{ | ||
return $this->title; | ||
} | ||
|
||
/** | ||
* Set the value of question | ||
* | ||
* @return self | ||
*/ | ||
public function setTitle($title) | ||
{ | ||
$this->title = $title; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Get the value of id | ||
*/ | ||
public function getId() | ||
{ | ||
return $this->id; | ||
} | ||
|
||
/** | ||
* Set the value of id | ||
* | ||
* @return self | ||
*/ | ||
public function setId($id) | ||
{ | ||
$this->id = $id; | ||
|
||
return $this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php | ||
|
||
class AnswerManager | ||
{ | ||
|
||
private static $pdo; | ||
|
||
public static function getPdoInstance() | ||
{ | ||
if (self::$pdo == NULL) // Je créer un singleton de PDO ici dans le but de ne pas l'instancier à chaque appel de la méthode | ||
{ | ||
try { | ||
self::$pdo = new PDO('mysql:host=localhost;dbname=qcm', 'root', ''); | ||
} catch (PDOException $e) { | ||
print "Erreur !: " . $e->getMessage() . "<br/>"; | ||
die(); | ||
} | ||
} | ||
|
||
return self::$pdo; | ||
} | ||
|
||
public static function getAll() | ||
{ | ||
$pdo = self::getPdoInstance(); | ||
|
||
$sql = "SELECT * FROM answers"; | ||
$req = $pdo->query($sql); | ||
$products = $req->fetchAll(PDO::FETCH_ASSOC); | ||
|
||
return self::hydrateCollection($products); | ||
} | ||
|
||
public static function get(int $id) | ||
{ | ||
$pdo = self::getPdoInstance(); | ||
|
||
$sql = "SELECT * FROM answers WHERE answer_id = :id"; | ||
$req = $pdo->prepare($sql); | ||
$req->execute([ | ||
'id' => $id | ||
]); | ||
$product = $req->fetch(PDO::FETCH_ASSOC); | ||
return new Answer($product); | ||
} | ||
|
||
public static function getFromQuestion(int $id) | ||
{ | ||
$pdo = self::getPdoInstance(); | ||
|
||
$sql = "SELECT * FROM answers WHERE question_id = :id"; | ||
$req = $pdo->prepare($sql); | ||
$req->execute([ | ||
'id' => $id | ||
]); | ||
$items = $req->fetchAll(PDO::FETCH_ASSOC); | ||
return self::hydrateCollection($items); | ||
} | ||
|
||
private static function hydrateCollection(array $collection) | ||
{ | ||
foreach ($collection as $index => $productInfo) { | ||
$collection[$index] = new Answer($productInfo); | ||
} | ||
|
||
return $collection; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
class QcmManager | ||
{ | ||
|
||
private static $pdo; | ||
|
||
public static function getPdoInstance() | ||
{ | ||
if (self::$pdo == NULL) // Je créer un singleton de PDO ici dans le but de ne pas l'instancier à chaque appel de la méthode | ||
{ | ||
try { | ||
self::$pdo = new PDO('mysql:host=localhost;dbname=qcm', 'root', ''); | ||
} catch (PDOException $e) { | ||
print "Erreur !: " . $e->getMessage() . "<br/>"; | ||
die(); | ||
} | ||
} | ||
|
||
return self::$pdo; | ||
} | ||
|
||
public static function getAll() | ||
{ | ||
$pdo = self::getPdoInstance(); | ||
|
||
$sql = "SELECT * FROM qcm"; | ||
$req = $pdo->query($sql); | ||
$products = $req->fetchAll(PDO::FETCH_ASSOC); | ||
|
||
// return $products; | ||
return self::hydrateCollection($products); | ||
} | ||
|
||
public static function get(int $id) | ||
{ | ||
$pdo = self::getPdoInstance(); | ||
|
||
$sql = "SELECT * FROM qcm WHERE qcm_id = :id"; | ||
$req = $pdo->prepare($sql); | ||
$req->execute([ | ||
'id' => $id | ||
]); | ||
$product = $req->fetch(PDO::FETCH_ASSOC); | ||
return new QCM($product); | ||
} | ||
|
||
private static function hydrateCollection(array $collection) | ||
{ | ||
foreach ($collection as $index => $productInfo) { | ||
$collection[$index] = new QCM($productInfo); | ||
} | ||
|
||
return $collection; | ||
} | ||
} |
Oops, something went wrong.