Finition gateway Athlete Coach et Activite a tester mais normalement fonctionnel
continuous-integration/drone/push Build is failing Details

WORK-KMO-Gateway
Kevin MONTEIRO 12 months ago
parent aba0924f64
commit fe12112ce6

@ -1,38 +1,39 @@
<?php
namespace Database;
use \PDO;
class ActiviteGateway {
private $connection;
class ActivityGateway {
private Connexion $connection;
public function __construct(Connection $connection) {
public function __construct(Connexion $connection) {
$this->connection = $connection;
}
public function getActivite() {
public function getActivity() {
$query = "SELECT * FROM Activite";
return $this->connection->executeWithErrorHandling($query);
}
public function getActiviteById(int $activiteId) {
public function getActivityById(int $activityId) {
$query = "SELECT * FROM Activite WHERE idActivite = :id";
$params = [':id' => [$activiteId, PDO::PARAM_INT]];
$params = [':id' => [$activityId, PDO::PARAM_INT]];
return $this->connection->executeWithErrorHandling($query, $params);
}
public function getActiviteByType(string $type) {
public function getActivityByType(string $type) {
$query = "SELECT * FROM Activite WHERE type = :type";
$params = [':type' => [$type, PDO::PARAM_STR]];
return $this->connection->executeWithErrorHandling($query, $params);
}
public function getActiviteByDate(string $date) {
public function getActivityByDate(string $date) {
$query = "SELECT * FROM Activite WHERE date = :date";
$params = [':date' => [$date, PDO::PARAM_STR]];
return $this->connection->executeWithErrorHandling($query, $params);
}
public function getActiviteByTimeRange(string $startTime, string $endTime) {
public function getActivityByTimeRange(string $startTime, string $endTime) {
$query = "SELECT * FROM Activite WHERE heureDebut >= :startTime AND heureFin <= :endTime";
$params = [
':startTime' => [$startTime, PDO::PARAM_STR],
@ -41,76 +42,76 @@ class ActiviteGateway {
return $this->connection->executeWithErrorHandling($query, $params);
}
public function getActiviteByEffort(int $effortRessenti) {
public function getActivityByEffort(int $effortRessenti) {
$query = "SELECT * FROM Activite WHERE effortRessenti = :effort";
$params = [':effort' => [$effortRessenti, PDO::PARAM_INT]];
return $this->connection->executeWithErrorHandling($query, $params);
}
public function getActiviteByVariability(int $variabilite) {
public function getActivityByVariability(int $variabilite) {
$query = "SELECT * FROM Activite WHERE variabilite = :variability";
$params = [':variability' => [$variabilite, PDO::PARAM_INT]];
return $this->connection->executeWithErrorHandling($query, $params);
}
public function getActiviteByTemperature(int $temperatureMoyenne) {
public function getActivityByTemperature(int $temperatureMoyenne) {
$query = "SELECT * FROM Activite WHERE temperatureMoyenne = :temperature";
$params = [':temperature' => [$temperatureMoyenne, PDO::PARAM_INT]];
return $this->connection->executeWithErrorHandling($query, $params);
}
public function addActivite(ActiviteEntity $activite) {
public function addActivity(ActivityEntity $activity) {
$query = "INSERT INTO Activite (type, date, heureDebut, heureDeFin, effortRessenti, variabilite, variance, ecartType, moyenne, maximum, minimum, temperatureMoyenne)
VALUES (:type, :date, :heureDebut, :heureDeFin, :effortRessenti, :variabilite, :variance, :ecartType, :moyenne, :maximum, :minimum, :temperatureMoyenne)";
$params = [
':type' => $activite->getType(),
':date' => $activite->getDate()->format('Y-m-d'), // Format date pour SQL
':heureDebut' => $activite->getHeureDebut()->format('H:i:s'), // Format heure pour SQL
':heureDeFin' => $activite->getHeureFin()->format('H:i:s'), // Format heure pour SQL
':effortRessenti' => $activite->getEffortRessenti(),
':variabilite' => $activite->getVariabilite(),
':variance' => $activite->getVariance(),
':ecartType' => $activite->getEcartType(),
':moyenne' => $activite->getMoyenne(),
':maximum' => $activite->getMaximum(),
':minimum' => $activite->getMinimum(),
':temperatureMoyenne' => $activite->getTemperatureMoyenne(),
':type' => $activity->getType(),
':date' => $activity->getDate()->format('Y-m-d'), // Format date pour SQL
':heureDebut' => $activity->getHeureDebut()->format('H:i:s'), // Format heure pour SQL
':heureDeFin' => $activity->getHeureFin()->format('H:i:s'), // Format heure pour SQL
':effortRessenti' => $activity->getEffortRessenti(),
':variabilite' => $activity->getVariabilite(),
':variance' => $activity->getVariance(),
':ecartType' => $activity->getEcartType(),
':moyenne' => $activity->getMoyenne(),
':maximum' => $activity->getMaximum(),
':minimum' => $activity->getMinimum(),
':temperatureMoyenne' => $activity->getTemperatureMoyenne(),
];
return $this->connection->executeWithErrorHandling($query, $params);
}
public function updateActivite(ActiviteEntity $oldActivite, ActiviteEntity $newActivite) {
public function updateActivity(ActivityEntity $oldActivity, ActivityEntity $newActivity) {
$query = "UPDATE Activite
SET type = :type, date = :date, heureDebut = :heureDebut, heureDeFin = :heureDeFin,
effortRessenti = :effortRessenti, variabilite = :variabilite, variance = :variance, ecartType = :ecartType, moyenne = :moyenne, maximum = :maximum, minimum = :minimum, temperatureMoyenne = :temperatureMoyenne
WHERE idActivite = :idActivite";
$params = [
':idActivite' => $oldActivite->getIdActivite(),
':type' => $newActivite->getType(),
':date' => $newActivite->getDate()->format('Y-m-d'), // Format date pour SQL
':heureDebut' => $newActivite->getHeureDebut()->format('H:i:s'), // Format heure pour SQL
':heureDeFin' => $newActivite->getHeureFin()->format('H:i:s'), // Format heure pour SQL
':effortRessenti' => $newActivite->getEffortRessenti(),
':variabilite' => $newActivite->getVariabilite(),
':variance' => $newActivite->getVariance(),
':ecartType' => $newActivite->getEcartType(),
':moyenne' => $newActivite->getMoyenne(),
':maximum' => $newActivite->getMaximum(),
':minimum' => $newActivite->getMinimum(),
':temperatureMoyenne' => $newActivite->getTemperatureMoyenne(),
':idActivite' => $oldActivity->getIdActivity(),
':type' => $newActivity->getType(),
':date' => $newActivity->getDate()->format('Y-m-d'), // Format date pour SQL
':heureDebut' => $newActivity->getHeureDebut()->format('H:i:s'), // Format heure pour SQL
':heureDeFin' => $newActivity->getHeureFin()->format('H:i:s'), // Format heure pour SQL
':effortRessenti' => $newActivity->getEffortRessenti(),
':variabilite' => $newActivity->getVariabilite(),
':variance' => $newActivity->getVariance(),
':ecartType' => $newActivity->getEcartType(),
':moyenne' => $newActivity->getMoyenne(),
':maximum' => $newActivity->getMaximum(),
':minimum' => $newActivity->getMinimum(),
':temperatureMoyenne' => $newActivity->getTemperatureMoyenne(),
];
return $this->connection->executeWithErrorHandling($query, $params);
}
public function deleteActivite(int $idActivite) {
$query = "DELETE FROM Activite WHERE idActivite = :idActivite";
public function deleteActivity(int $idActivity) {
$query = "DELETE FROM Activite WHERE idActivite = :idActivity";
$params = [
':idActivite' => $idActivite,
':idActivity' => $idActivity,
];
return $this->connection->executeWithErrorHandling($query, $params);

@ -1,34 +1,81 @@
<?php
namespace Database;
use Model\Activite;
class ActiviteMapper {
public function map(array $data):ActiviteEntity {
$activite = new ActiviteEntity();
$activite->setIdActivite($data['idActivite']);
$activite->setType($data['type']);
$activite->setDate($data['date']);
$activite->setHeureDebut($data['heureDebut']);
$activite->setHeureFin($data['heureFin']);
$activite->setEffortRessenti($data['effortRessenti']);
$activite->setVariabilite($data['variabilite']);
$activite->setVariance($data['variance']);
$activite->setEcartType($data['ecartType']);
$activite->setMoyenne($data['moyenne']);
$activite->setMaximum($data['maximum']);
$activite->setMinimum($data['minimum']);
$activite->setTemperatureMoyenne($data['temperatureMoyenne']);
return $activite;
}
use Model\Activity;
class ActivityMapper {
public function activitySqlToEntity(array $data):array
{
$activityEntities = [];
foreach ($data as $activityData) {
$activity = new ActivityEntity();
if (isset($activityData['idActivity'])) {
$activity->setIdActivity($data['idActivity']);
}
if (isset($activityData['type'])) {
$activity->setType($data['type']);
}
if (isset($activityData['date'])) {
$activity->setDate($data['date']);
}
if (isset($activityData['heureDebut'])) {
$activity->setHeureDebut($data['heureDebut']);
}
if (isset($activityData['heureFin'])) {
$activity->setHeureFin($data['heureFin']);
}
if (isset($activityData['effortRessenti'])) {
$activity->setEffortRessenti($data['effortRessenti']);
}
if (isset($activityData['variabilite'])) {
$activity->setVariabilite($data['variabilite']);
}
if (isset($activityData['variance'])) {
$activity->setVariance($data['variance']);
}
if (isset($activityData['ecartType'])) {
$activity->setEcartType($data['ecartType']);
}
//public function ActiviteEntityToModel(ActiviteEntity entity): Activite;
if (isset($activityData['moyenne'])) {
$activity->setMoyenne($data['moyenne']);
}
public function ActiviteEntityToModel(ActiviteEntity $activiteEntity):Activite{
if (isset($activityData['maximum'])) {
$activity->setMaximum($data['maximum']);
}
$act = new Activite(
$activiteEntity->getIdActivite(),
if (isset($activityData['minimum'])) {
$activity->setMinimum($data['minimum']);
}
if (isset($activityData['temperatureMoyenne'])) {
$activity->setTemperatureMoyenne($data['temperatureMoyenne']);
}
$activityEntities[] = $activity;
}
return $activityEntities;
}
/**
* @throws \Exception
*/
public function ActivityEntityToModel(ActivityEntity $activiteEntity):Activity{
$act = new Activity(
$activiteEntity->getIdActivity(),
$activiteEntity->getType(),
$activiteEntity->getDate(),
$activiteEntity->getHeureDebut(),
@ -45,7 +92,27 @@ class ActiviteMapper {
return $act;
}
//public function ActiviteToEntity(Activite model): ActiviteEntity;
//public function ActivityToEntity(Activity model): ActivityEntity;
public function activityToEntity(Activity $act):ActivityEntity{
$act = new ActivityEntity();
$act->setIdActivity($act->getIdActivity()());
$act->setType($act->getType());
$act->setDate($act->getDate());
$act->setHeureDebut($act->getHeureDebut());
$act->setHeureFin($act->getHeureFin());
$act->setEffortRessenti($act->getEffortRessenti());
$act->setVariabilite($act->getVariabilite());
$act->setVariance($act->getVariance());
$act->setEcartType($act->getEcartType());
$act->setMoyenne($act->getMoyenne());
$act->setMaximum($act->getMaximum());
$act->setMinimum($act->getMinimum());
$act->setTemperatureMoyenne($act->getTemperatureMoyenne());
return $act;
}
}
?>

@ -2,8 +2,8 @@
namespace Database;
class ActiviteEntity {
private $idActivite;
class ActivityEntity {
private $idActivity;
private $type;
private $date;
private $heureDebut;
@ -18,7 +18,7 @@ class ActiviteEntity {
private $temperatureMoyenne;
// Getters
public function getIdActivite() {
public function getIdActivity() {
return $this->idActivity;
}
@ -71,7 +71,7 @@ class ActiviteEntity {
}
// Setters
public function setIdActivite($idActivity) {
public function setIdActivity($idActivity) {
$this->idActivity = $idActivity;
}

@ -4,7 +4,7 @@ namespace Database;
use \PDO;
class AthleteGateway {
private $connection;
private Connexion $connection;
public function __construct(Connexion $connection) {
$this->connection = $connection;

Loading…
Cancel
Save