|
|
|
@ -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);
|
|
|
|
|