diff --git a/fluxRSS/src/DAL/FluxGateway.php b/fluxRSS/src/DAL/FluxGateway.php index 1538bfc..bcdbcec 100755 --- a/fluxRSS/src/DAL/FluxGateway.php +++ b/fluxRSS/src/DAL/FluxGateway.php @@ -15,23 +15,25 @@ class FluxGateway public function addFlux(Flux $flux) { - $query = 'INSERT INTO Flux VALUES (:flux);'; - $this->con->executeQuery($query, array(':flux' => array($flux->getFlux(), PDO::PARAM_STR))); + $this->addFluxBySrc($flux->getFlux()); } - public function getId(): int + public function addFluxBySrc(string $flux) { - - return $this->id; + $query = 'INSERT INTO Flux VALUES (null,:flux);'; + var_dump($this->con->executeQuery($query, array(':flux' => array($flux, PDO::PARAM_STR)))); } public function removeFlux(Flux $flux){ + $this->removeFluxBySrc($flux->getFlux()); + } + + public function removeFluxBySrc(string $flux){ $query = 'DELETE FROM Flux WHERE flux = :flux;'; - $this->con->executeQuery($query, array(':flux' => array($flux->getFlux(), PDO::PARAM_STR))); + $this->con->executeQuery($query, array(':flux' => array($flux, PDO::PARAM_STR))); } public function findAllFlux(){ - $query = 'SELECT * FROM Flux;'; $this->con->executeQuery($query); return $this->con->getResults(); diff --git a/fluxRSS/src/controleur/AdminControleur.php b/fluxRSS/src/controleur/AdminControleur.php index 1f261a8..6166e7c 100755 --- a/fluxRSS/src/controleur/AdminControleur.php +++ b/fluxRSS/src/controleur/AdminControleur.php @@ -2,13 +2,20 @@ namespace controleur; +use http\Exception; +use metier\Flux; use model\AdminModel; use model\ArticleModel; use model\FluxModel; class AdminControleur { - public function __construct(){ + /*public function __construct() + { + $this->init(); + }*/ + + public function init(){ global $twig; // nécessaire pour utiliser variables globales //debut @@ -37,6 +44,14 @@ class AdminControleur $this->ValidationFormulaire($dVueEreur); break; + case 'listFlux': + $this->listFlux(); + break; + + case 'ajoutFlux': + $this->ajoutFlux(); + break; + //mauvaise action default: $dVueEreur[] = "Erreur d'appel php"; @@ -74,11 +89,29 @@ class AdminControleur } } + public function listFlux(){ + global $twig; + $fluxModel = new FluxModel(); + if (AdminModel::isAdmin()) { + $dVue = [ + 'data' => $fluxModel->findAllFlux() + ]; + echo $twig->render('listFlux.html', [ + 'dVue' => $dVue, + 'isAdmin' => AdminModel::isAdmin() + ]); + } + else { + $this->connection(); + } + } + public function connection(){ global $twig; // nécessaire pour utiliser variables globales $renderTemplate = true; if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['username'])){ + $_REQUEST['action'] = null; $this->login(); $renderTemplate = false; } @@ -90,8 +123,27 @@ class AdminControleur public function deleteFlux(){ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['flux'])){ $fluxModel = new FluxModel(); - $fluxModel->removeFlux($_POST['flux']); - $this->listArticle(); + $fluxModel->removeFluxBySrc($_POST['flux']); + $_REQUEST['action'] = 'listFlux'; + $this->init(); + } + else{ + $_REQUEST['action'] = 'listFlux'; + $this->init(); + } + } + + public function ajoutFlux(){ + if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['fluxAdd'])){ + $fluxModel = new FluxModel(); + $fluxModel->addFluxBySrc($_POST['fluxAdd']); + $_REQUEST['action'] = 'listFlux'; + unset($_POST['fluxAdd']); + $this->init(); + } + else{ + $_REQUEST['action'] = 'listFlux'; + $this->init(); } } @@ -102,7 +154,7 @@ class AdminControleur $adminModel = new AdminModel(); $admin = $adminModel->connection($username, $password); if($admin != null) { - $this->listArticle(); + $this->init(); } else{ unset($_POST['username']); diff --git a/fluxRSS/src/controleur/FrontControleur.php b/fluxRSS/src/controleur/FrontControleur.php index 6995f84..96af8ab 100755 --- a/fluxRSS/src/controleur/FrontControleur.php +++ b/fluxRSS/src/controleur/FrontControleur.php @@ -30,7 +30,7 @@ class FrontControleur else { session_start(); $controller=$match['target'] ?? null; - $action=$match['params']['action'] ?? null; + $action=$match['params']['action'] ?? "init"; try { if($controller == "AdminControleur"){ if (!AdminModel::isAdmin()){ diff --git a/fluxRSS/src/controleur/UserControleur.php b/fluxRSS/src/controleur/UserControleur.php index 8bec648..247ab39 100755 --- a/fluxRSS/src/controleur/UserControleur.php +++ b/fluxRSS/src/controleur/UserControleur.php @@ -7,7 +7,7 @@ use model\Parser; class UserControleur { - public function __construct() + public function init() { global $twig; // nécessaire pour utiliser variables globales //debut diff --git a/fluxRSS/src/metier/Flux.php b/fluxRSS/src/metier/Flux.php index b45e587..c7ea937 100755 --- a/fluxRSS/src/metier/Flux.php +++ b/fluxRSS/src/metier/Flux.php @@ -4,10 +4,10 @@ namespace metier; class Flux { - private int $id; + private ?int $id; private string $flux; - public function __construct(string $flux, int $id=null){ + public function __construct(?int $id, string $flux){ $this->id =$id; $this->flux = $flux; } diff --git a/fluxRSS/src/model/ArticleModel.php b/fluxRSS/src/model/ArticleModel.php index 332d0c7..0da42c6 100755 --- a/fluxRSS/src/model/ArticleModel.php +++ b/fluxRSS/src/model/ArticleModel.php @@ -47,7 +47,7 @@ class ArticleModel $res = $gwFlux->findAllFlux(); foreach ($res as $row) { - $flux = new Flux($row['flux'], (int)($row['id'])); + $flux = new Flux((int)($row['id']),$row['flux']); $tabFluxArticle[] = $this->findArticleByFluxAsStr($flux); } return $tabFluxArticle; diff --git a/fluxRSS/src/model/FluxModel.php b/fluxRSS/src/model/FluxModel.php index fb7461b..a79eedb 100755 --- a/fluxRSS/src/model/FluxModel.php +++ b/fluxRSS/src/model/FluxModel.php @@ -8,13 +8,13 @@ use metier\Flux; class FluxModel { - public function FindAllFlux(){ + public function findAllFlux(){ $gateway = new FluxGateway(new Connection('mysql:host=londres.uca.local;dbname=dbrorossetto','rorossetto','tpphp')); $data = array(); $result = $gateway->findAllFlux(); foreach ($result as $row){ - $data[] = new Flux((int)$row['id'],$row['$flux']); + $data[] = new Flux((int)$row['id'],$row['flux']); } return $data; } @@ -29,7 +29,7 @@ class FluxModel public function addFluxBySrc(string $flux): Flux { $gateway = new FluxGateway(new Connection('mysql:host=londres.uca.local;dbname=dbrorossetto','rorossetto','tpphp')); - $newFlux = new Flux($flux); + $newFlux = new Flux(null,$flux); $gateway->addFlux($newFlux); return $newFlux; } @@ -41,7 +41,7 @@ class FluxModel public function removeFluxBySrc(string $flux) { $gateway = new FluxGateway(new Connection('mysql:host=londres.uca.local;dbname=dbrorossetto','rorossetto','tpphp')); - $gateway->removeFlux($flux); + $gateway->removeFluxBySrc($flux); } public function findFlux(Flux $flux){ @@ -50,7 +50,7 @@ class FluxModel $result = $gateway->findFlux($flux); foreach ($result as $row){ - $data[] = new Flux($row['$flux'],(int)$row['id']); + $data[] = new Flux((int)$row['id'],$row['$flux']); } return $data; } @@ -61,7 +61,7 @@ class FluxModel $result = $gateway->findFluxBySrc($flux); foreach ($result as $row){ - $data[] = new Flux($row['$flux'],(int)$row['id']); + $data[] = new Flux((int)$row['id'],$row['$flux']); } return $data; } diff --git a/fluxRSS/templates/listArticleAdmin.html b/fluxRSS/templates/listArticleAdmin.html index 256f419..2643f24 100755 --- a/fluxRSS/templates/listArticleAdmin.html +++ b/fluxRSS/templates/listArticleAdmin.html @@ -21,6 +21,7 @@ admin {% endfor %} Vue user +Vue flux Déconnection \ No newline at end of file diff --git a/fluxRSS/templates/listFlux.html b/fluxRSS/templates/listFlux.html new file mode 100755 index 0000000..14d182e --- /dev/null +++ b/fluxRSS/templates/listFlux.html @@ -0,0 +1,23 @@ + + + + + All Flux + + + {% for value in dVue.data %} +
+ {{ value.getFlux() }} +
+ + +
+
+ {% endfor %} +
+ + +
+ Vue article + + \ No newline at end of file