10namespace ComusParty\Models;
13use ComusParty\App\Exceptions\NotFoundException;
14use DateMalformedStringException;
68 $stmt = $this->pdo->prepare(
71 JOIN ' .
DB_PREFIX .
'player p ON i.player_uuid = p.uuid
72 WHERE i.id = :id AND p.uuid = :uuid');
73 $stmt->bindParam(
':id', $invoiceId);
74 $stmt->bindParam(
':uuid', $_SESSION[
'uuid']);
76 $stmt->setFetchMode(PDO::FETCH_ASSOC);
77 $invoice = $stmt->fetch();
78 if ($invoice ===
false) {
82 $stmt = $this->pdo->prepare(
85 JOIN ' .
DB_PREFIX .
'invoice_row ir ON a.id = ir.article_id
86 WHERE ir.invoice_id = :invoice_id');
87 $stmt->bindParam(
':invoice_id', $invoiceId);
89 $stmt->setFetchMode(PDO::FETCH_ASSOC);
90 $articles = $stmt->fetchAll();
91 if ($articles ===
false) {
107 foreach ($data as $article) {
108 $articles[] = $this->
hydrate($article);
122 $article->setId($data[
'id']);
123 $article->setName($data[
'name']);
125 if ($data[
'type'] ==
'pfp') {
126 $type = ArticleType::ProfilePicture;
127 } elseif ($data[
'type'] ==
'banner') {
131 $article->setType($type);
132 $article->setDescription($data[
'description']);
133 $article->setPricePoint($data[
'price_point']);
134 $article->setPriceEuro($data[
'price_euro']);
136 $article->setCreatedAt(
new DateTime($data[
'created_at']));
137 $article->setUpdatedAt(
new DateTime($data[
'updated_at']));
138 $article->setFilePath($data[
'file_path']);
151 $stmt = $this->pdo->prepare(
154 JOIN ' .
DB_PREFIX .
'invoice_row ir ON a.id = ir.article_id
155 JOIN ' .
DB_PREFIX .
'invoice i ON ir.invoice_id = i.id
156 WHERE i.player_uuid = :uuid AND type = "pfp" ');
157 $stmt->bindParam(
':uuid', $uuid);
159 $stmt->setFetchMode(PDO::FETCH_ASSOC);
160 $articles = $stmt->fetchAll();
172 $stmt = $this->pdo->prepare(
175 JOIN ' .
DB_PREFIX .
'invoice_row ir ON a.id = ir.article_id
176 JOIN ' .
DB_PREFIX .
'invoice i ON ir.invoice_id = i.id
177 WHERE i.player_uuid = :uuid AND type = "banner" ');
178 $stmt->bindParam(
':uuid', $uuid);
180 $stmt->setFetchMode(PDO::FETCH_ASSOC);
181 $articles = $stmt->fetchAll();
195 $stmt = $this->pdo->query(
198 $stmt->setFetchMode(PDO::FETCH_ASSOC);
199 $tabArticles = $stmt->fetchAll();
200 if ($tabArticles ===
false) {
217 $idsString = implode(
',', $ids);
219 $stmt = $this->pdo->query(
'SELECT * FROM ' .
DB_PREFIX .
'article WHERE id IN (' . $idsString .
')');
220 $stmt->setFetchMode(PDO::FETCH_ASSOC);
222 $tabArticles = $stmt->fetchAll();
224 if ($tabArticles ===
false) {
241 $stmt = $this->pdo->query(
"SELECT *
243 WHERE type = 'pfp'");
245 $stmt->setFetchMode(PDO::FETCH_ASSOC);
246 $tabPfps = $stmt->fetchAll();
248 if ($tabPfps ===
false) {
262 $stmt = $this->pdo->query(
"SELECT *
264 WHERE type = 'banner'");
265 $stmt->setFetchMode(PDO::FETCH_ASSOC);
266 $tabBanners = $stmt->fetchAll();
267 if ($tabBanners ===
false) {
284 if ($typeArticle ==
"ProfilePicture") {
287 if ($pfpActive !=
null) {
288 $idPfpActive = $pfpActive->getId();
289 $stmt = $this->pdo->prepare(
291 JOIN ' .
DB_PREFIX .
'invoice i ON ir.invoice_id = i.id
292 JOIN ' .
DB_PREFIX .
'article a ON ir.article_id = a.id
294 WHERE i.player_uuid = :uuid AND ir.article_id = :idArticleActif');
295 $stmt->bindParam(
':uuid', $uuid);
296 $stmt->bindParam(
':idArticleActif', $idPfpActive);
302 $stmt = $this->pdo->prepare(
304 JOIN ' .
DB_PREFIX .
'invoice i ON ir.invoice_id = i.id
305 JOIN ' .
DB_PREFIX .
'article a ON ir.article_id = a.id
307 WHERE i.player_uuid = :uuid AND ir.article_id = :idArticle'
309 $stmt->bindParam(
':uuid', $uuid);
310 $stmt->bindParam(
':idArticle', $idArticle);
311 $ok = $stmt->execute();
314 $_SESSION[
'pfpPath'] = $pfp->getFilePath();
319 if ($typeArticle ==
"Banner") {
323 if ($bannerActive !=
null) {
324 $idBannerActive = $bannerActive->getId();
325 $stmt = $this->pdo->prepare(
327 JOIN ' .
DB_PREFIX .
'invoice i ON ir.invoice_id = i.id
328 JOIN ' .
DB_PREFIX .
'article a ON ir.article_id = a.id
330 WHERE i.player_uuid = :uuid AND ir.article_id = :idArticleActif');
331 $stmt->bindParam(
':uuid', $uuid);
332 $stmt->bindParam(
':idArticleActif', $idBannerActive);
333 $ok = $stmt->execute();
338 $stmt = $this->pdo->prepare(
340 JOIN ' .
DB_PREFIX .
'invoice i ON ir.invoice_id = i.id
341 JOIN ' .
DB_PREFIX .
'article a ON ir.article_id = a.id
343 WHERE i.player_uuid = :uuid AND ir.article_id = :idArticle'
345 $stmt->bindParam(
':uuid', $uuid);
346 $stmt->bindParam(
':idArticle', $idArticle);
347 $ok = $stmt->execute();
348 $banner = $this->
findById($idArticle);
349 if ($banner !=
null) {
350 $_SESSION[
'bannerPath'] = $banner->getFilePath();
365 $stmt = $this->pdo->prepare(
368 JOIN ' .
DB_PREFIX .
'invoice_row ir ON a.id = ir.article_id
369 JOIN ' .
DB_PREFIX .
'invoice i ON ir.invoice_id = i.id
370 WHERE i.player_uuid = :uuid AND a.type = "pfp" AND ir.active = 1');
371 $stmt->bindParam(
':uuid', $uuid);
373 $stmt->setFetchMode(PDO::FETCH_ASSOC);
374 $pfp = $stmt->fetch();
375 if ($pfp ===
false) {
389 $stmt = $this->pdo->prepare(
393 $stmt->bindParam(
':id', $id);
395 $stmt->setFetchMode(PDO::FETCH_ASSOC);
396 $article = $stmt->fetch();
397 if ($article ===
false) {
400 return $this->
hydrate($article);
411 $stmt = $this->pdo->prepare(
414 JOIN ' .
DB_PREFIX .
'invoice_row ir ON a.id = ir.article_id
415 JOIN ' .
DB_PREFIX .
'invoice i ON ir.invoice_id = i.id
416 WHERE i.player_uuid = :uuid AND a.type = "banner" AND ir.active = 1');
417 $stmt->bindParam(
':uuid', $uuid);
419 $stmt->setFetchMode(PDO::FETCH_ASSOC);
420 $banner = $stmt->fetch();
421 if ($banner ===
false) {
424 return $this->
hydrate($banner);
434 $stmt = $this->pdo->prepare(
437 WHERE p.uuid = :uuid');
438 $stmt->bindParam(
':uuid', $uuid);
440 if ($stmt->rowCount() === 0) {
444 $stmt = $this->pdo->prepare(
446 JOIN ' .
DB_PREFIX .
'invoice i ON ir.invoice_id = i.id
447 JOIN ' .
DB_PREFIX .
'article a ON ir.article_id = a.id
449 WHERE i.player_uuid = :uuid AND a.type = "pfp"');
450 $stmt->bindParam(
':uuid', $uuid);
463 $stmt = $this->pdo->prepare(
465 JOIN ' .
DB_PREFIX .
'invoice i ON ir.invoice_id = i.id
466 JOIN ' .
DB_PREFIX .
'article a ON ir.article_id = a.id
468 WHERE i.player_uuid = :uuid AND a.type = "banner"');
469 $stmt->bindParam(
':uuid', $uuid);
Classe NotFoundException.
findActivePfpByPlayerUuid(string $uuid)
Retourne la photo de profile active que le joueur possède sous forme d'objet Article.
findActiveBannerByPlayerUuid(string $uuid)
Retourne la bannière active que le joueur possède sous forme d'objet Article.
deleteActiveArticleForPfp(string $uuid)
Supprime toutes les pfps pour les mettre à 0 en active.
findAllPfpsOwnedByPlayer(string $uuid)
Retourne un tableau d'objets Article (ou null) à partir de l'UUID du joueur correspondant à l'ensembl...
hydrate(array $data)
Hydrate un objet Article avec les valeurs du tableau associatif passé en paramètre.
findArticlesWithIds(array $ids)
Retourne un tableau d'objets Article recensant l'ensemble des articles correspondant aux id "ids".
deleteActiveArticleForBanner(string $uuid)
Supprime toutes les bannières pour les mettre à 0 en active.
updateActiveArticle(string $uuid, string $idArticle, string $typeArticle)
Met à jour l'article en active dans la base de données.
getPdo()
Retourne la connexion à la base de données.
findAll()
Retourne un tableau d'objets Article recensant l'ensemble des articles enregistrés dans la base de do...
findArticlesByInvoiceId(?int $invoiceId)
Retourne un tableau d'objets Article (ou null) à partir de l'ID de la facture passé en paramètre.
findAllBannersOwnedByPlayer(string $uuid)
Retourne un tableau d'objets Article (ou null) à partir de l'UUID du joueur correspondant à l'ensembl...
findAllPfps()
Retourne un tableau d'objets Article qui ont le type profile_picture dans la base de données.
setPdo(?PDO $pdo)
Modifie la connexion à la base de données.
findAllBanners()
Retourne un tableau d'objets Article qui ont le type banner dans la base de données.
__construct(?PDO $pdo)
Le constructeur de la classe ArticleDAO.
findById(string $id)
Retourne un objet Article (ou null) à partir de l'ID passé en paramètre.
hydrateMany(array $data)
Hydrate un tableau d'objets Article avec les valeurs des tableaux associatifs du tableau passé en par...
const DB_PREFIX
Préfixe des tables de la base de données.