diff --git a/mvc_PSR4_twig/modeles/Flux.php b/mvc_PSR4_twig/modeles/Flux.php index e99d929..e621e83 100644 --- a/mvc_PSR4_twig/modeles/Flux.php +++ b/mvc_PSR4_twig/modeles/Flux.php @@ -4,5 +4,21 @@ namespace modeles; class Flux { + private string $flux; + /** + * @return string + */ + public function getFlux(): string + { + return $this->flux; + } + + /** + * @param string $flux + */ + public function setFlux(string $flux): void + { + $this->flux = $flux; + } } \ No newline at end of file diff --git a/mvc_PSR4_twig/modeles/FluxGateway.php b/mvc_PSR4_twig/modeles/FluxGateway.php index 2ea0b83..d7eeef0 100644 --- a/mvc_PSR4_twig/modeles/FluxGateway.php +++ b/mvc_PSR4_twig/modeles/FluxGateway.php @@ -2,7 +2,39 @@ namespace modeles; +use PDO; + class FluxGateway { + private Connection $con; + + public function __construct(Connection $con){ + $this->con = $con; + } + + public function addFlux($flux){ + $query = 'INSERT INTO Flux VALUES (:flux);'; + $this->con->executeQuery($query, array(':flux' => array($flux->getFlux(), PDO::PARAM_STR))); + } + + public function removeFlux($flux){ + $query = 'DELETE FROM Flux WHERE flux = :flux;'; + $this->con->executeQuery($query, array(':flux' => array($flux->getFlux(), PDO::PARAM_STR))); + } + + public function findAllFlux(){ + $query = 'SELECT * FROM Flux;'; + $this->con->executeQuery($query); + return $this->con->getResults(); + } + + public function findFlux(Flux $flux){ + return $this->findFluxBySrc($flux->getFlux()); + } + public function findFluxBySrc(string $flux){ + $query = 'SELECT * FROM Flux WHERE flux = :flux;'; + $this->con->executeQuery($query, array(':flux' => array($flux, PDO::PARAM_STR))); + return $this->con->getResults(); + } } \ No newline at end of file diff --git a/mvc_PSR4_twig/modeles/FluxModel.php b/mvc_PSR4_twig/modeles/FluxModel.php index fac3177..5b45b51 100644 --- a/mvc_PSR4_twig/modeles/FluxModel.php +++ b/mvc_PSR4_twig/modeles/FluxModel.php @@ -4,5 +4,58 @@ namespace modeles; class FluxModel { + private FluxGateway $gateway; + public function FindAllFlux(){ + $data = array(); + $result = $this->gateway->findAllFlux(); + foreach ($result as $row){ + $data[] = new Flux($row['$flux']); + } + return $data; + } + + public function addFlux(Flux $flux) + { + $data = findFlux($flux); + if ($data == array()) { + $this->gateway->addFlux($flux); + } + } + + public function addFluxBySrc(string $flux): Flux { + $newFlux = new Flux($flux); + $this->gateway->addFlux($newFlux); + return $newFlux; + } + + public function removeFlux(Flux $flux){ + $this->gateway->removeFlux($flux); + } + + public function removeFluxBySrc(string $flux): Flux { + $newFlux = new Flux($flux); + $this->gateway->removeFlux($newFlux); + return $newFlux; + } + + public function findFlux(Flux $flux){ + $data = array(); + $result = $this->gateway->findFlux($flux); + + foreach ($result as $row){ + $data[] = new Flux($row['$flux']); + } + return $data; + } + + public function findFluxBySrc(string $flux){ + $data = array(); + $result = $this->gateway->findFluxBySrc($flux); + + foreach ($result as $row){ + $data[] = new Flux($row['$flux']); + } + return $data; + } } \ No newline at end of file