parent
8473b52a96
commit
6e935ce864
@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace Database;
|
||||
|
||||
use Shared\Log;
|
||||
|
||||
class NotificationEntity
|
||||
{
|
||||
private $idNotif;
|
||||
private $message;
|
||||
private $date;
|
||||
private $statut;
|
||||
private $urgence;
|
||||
private $idAthlete;
|
||||
public function getIdNotif(): int
|
||||
{
|
||||
return $this->idNotif;
|
||||
}
|
||||
public function getMessage()
|
||||
{
|
||||
return $this->message;
|
||||
}
|
||||
public function getDate()
|
||||
{
|
||||
return $this->date;
|
||||
}
|
||||
public function getStatut()
|
||||
{
|
||||
return $this->statut;
|
||||
}
|
||||
public function getUrgence()
|
||||
{
|
||||
return $this->urgence;
|
||||
}
|
||||
public function getIdAthlete()
|
||||
{
|
||||
return $this->idAthlete;
|
||||
}
|
||||
public function setIdNotif($idNotif)
|
||||
{
|
||||
$this->idNotif = $idNotif;
|
||||
}
|
||||
public function setMessage($message)
|
||||
{
|
||||
$this->message = $message;
|
||||
}
|
||||
public function setDate($date)
|
||||
{
|
||||
$this->date = $date;
|
||||
}
|
||||
public function setStatut($statut)
|
||||
{
|
||||
$this->statut = $statut;
|
||||
}
|
||||
public function setUrgence($urgence)
|
||||
{
|
||||
$this->urgence = $urgence;
|
||||
}
|
||||
public function setIdAthlete($idAthlete)
|
||||
{
|
||||
$this->idAthlete = $idAthlete;
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace Database;
|
||||
|
||||
class NotificationGateway
|
||||
{
|
||||
private Connexion $connection;
|
||||
|
||||
public function __construct(Connexion $connection) {
|
||||
$this->connection = $connection;
|
||||
}
|
||||
|
||||
public function getNotifications(): array
|
||||
{
|
||||
$query = "SELECT * FROM Notification";
|
||||
$res = $this->connection->executeWithErrorHandling($query);
|
||||
return $res;
|
||||
}
|
||||
}
|
@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
namespace Database;
|
||||
|
||||
use DateTime;
|
||||
use Model\Notification;
|
||||
use Model\Training;
|
||||
use Shared\Log;
|
||||
|
||||
class NotificationMapper
|
||||
{
|
||||
public function notificationSqlToEntity(array $data): array
|
||||
{
|
||||
$notificationEntities = [];
|
||||
|
||||
foreach ($data as $notificationData) {
|
||||
$notification = new NotificationEntity();
|
||||
|
||||
if (isset($notificationData['idnotif'])) {
|
||||
$notification->setIdNotif($notificationData['idnotif']);
|
||||
}
|
||||
|
||||
if (isset($notificationData['message'])) {
|
||||
$notification->setMessage($notificationData['message']);
|
||||
}
|
||||
|
||||
if (isset($notificationData['date'])) {
|
||||
$notification->setDate($notificationData['date']);
|
||||
}
|
||||
|
||||
if (isset($notificationData['statut'])) {
|
||||
$notification->setStatut($notificationData['statut']);
|
||||
}
|
||||
|
||||
if (isset($notificationData['urgence'])) {
|
||||
$notification->setUrgence($notificationData['urgence']);
|
||||
}
|
||||
|
||||
if (isset($notificationData['athleteid'])) {
|
||||
$notification->setIdAthlete($notificationData['athleteid']);
|
||||
}
|
||||
|
||||
$notificationEntities[] = $notification;
|
||||
}
|
||||
|
||||
return $notificationEntities;
|
||||
}
|
||||
|
||||
public function notificationEntityToModel(NotificationEntity $notificationEntity): Notification
|
||||
{
|
||||
$date = new DateTime($notificationEntity->getDate());
|
||||
return new Notification(
|
||||
$notificationEntity->getIdNotif(),
|
||||
$notificationEntity->getMessage(),
|
||||
$date,
|
||||
$notificationEntity->getStatut(),
|
||||
$notificationEntity->getUrgence(),
|
||||
$notificationEntity->getIdAthlete()
|
||||
);
|
||||
}
|
||||
|
||||
public function notificationToEntity(Notification $notification): NotificationEntity
|
||||
{
|
||||
$notif = new NotificationEntity();
|
||||
$notif->setIdNotif($notification->getId());
|
||||
$notif->setMessage($notification->getMessage());
|
||||
$notif->setDate($notification->getDate());
|
||||
$notif->setStatut($notification->getStatut());
|
||||
$notif->setUrgence($notification->getUrgence());
|
||||
$notif->setIdAthlete($notification->getToUserId());
|
||||
|
||||
return $notif;
|
||||
}
|
||||
}
|
Loading…
Reference in new issue