diff --git a/.idea/sqldialects.xml b/.idea/sqldialects.xml~pre-master similarity index 100% rename from .idea/sqldialects.xml rename to .idea/sqldialects.xml~pre-master diff --git a/fluxRSS/.idea/mvc_PSR4_twig.iml b/fluxRSS/.idea/mvc_PSR4_twig.iml index e520f52..1323748 100755 --- a/fluxRSS/.idea/mvc_PSR4_twig.iml +++ b/fluxRSS/.idea/mvc_PSR4_twig.iml @@ -2,11 +2,14 @@ - - - + + + + + + diff --git a/fluxRSS/DAL/AdminGateway.php b/fluxRSS/DAL/AdminGateway.php deleted file mode 100755 index 16e6ab3..0000000 --- a/fluxRSS/DAL/AdminGateway.php +++ /dev/null @@ -1,29 +0,0 @@ -con = $con; - } - - public function login(string $login):array - { - try{ - $query = 'SELECT password,mail FROM Admin WHERE name = :login;'; - $this->con->executeQuery($query, array(':login' => array($login, PDO::PARAM_STR))); - return $this->con->getResults(); - }catch (\PDOException $e){ - throw new \Exception("PDO error"); - } - } -} \ No newline at end of file diff --git a/fluxRSS/DAL/ArticleGateway.php b/fluxRSS/DAL/ArticleGateway.php deleted file mode 100755 index 89e43ec..0000000 --- a/fluxRSS/DAL/ArticleGateway.php +++ /dev/null @@ -1,60 +0,0 @@ -con = $con; - } - - /** - * @throws Exception - */ - public function getAllArticles():array - { - try { - $query = 'SELECT * FROM Article;'; - $this->con->executeQuery($query, array()); - return $this->con->getResults(); - }catch (\PDOException $e){ - throw new Exception("PDO error"); - } - } - - /** - * @throws Exception - */ - public function addArticle(Article $article){ - try { - $query = 'INSERT INTO Article VALUES (:id,:title,to_date(:date,"Dy, DD Mon YYYY"),:description,:guid,:link,:mediaContent,:provenance);'; - $this->con->executeQuery($query, array(':id' => array($article->getId(), PDO::PARAM_STR), - ':title' => array($article->getTitle(), PDO::PARAM_STR), - ':date' => array($article->getDate(), PDO::PARAM_STR), - ':description' => array($article->getDescription(), PDO::PARAM_STR), - ':guid' => array($article->getGuid(), PDO::PARAM_STR), - ':link' => array($article->getLink(), PDO::PARAM_STR), - ':mediaContent' => array($article->getMediaContent(), PDO::PARAM_STR), - ':provenance' => array($article->getProvenance(), PDO::PARAM_INT))); - }catch (\PDOException $e){ - throw new Exception("PDO error"); - } - } - - public function removeAllArticleForParser(){ - try{ - $query = 'DELETE FROM Article;'; - $this->con->executeQuery($query); - }catch(\PDOException $p){ - throw new Exception("Data is not delete."); - } - } -} \ No newline at end of file diff --git a/fluxRSS/DAL/FluxGateway.php b/fluxRSS/DAL/FluxGateway.php deleted file mode 100755 index 43bbe9f..0000000 --- a/fluxRSS/DAL/FluxGateway.php +++ /dev/null @@ -1,57 +0,0 @@ -con = $con; - } - - public function addFlux($flux){ - try{ - $query = 'INSERT INTO Flux VALUES (:flux);'; - $this->con->executeQuery($query, array(':flux' => array($flux->getFlux(), PDO::PARAM_STR))); - }catch (\PDOException $e){ - throw new \Exception("PDO error"); - } - } - - public function removeFlux($flux){ - try{ - $query = 'DELETE FROM Flux WHERE flux = :flux;'; - $this->con->executeQuery($query, array(':flux' => array($flux->getFlux(), PDO::PARAM_STR))); - }catch (\PDOException $e){ - throw new \Exception("PDO error"); - } - } - - public function findAllFlux(){ - try{ - $query = 'SELECT * FROM Flux;'; - $this->con->executeQuery($query); - return $this->con->getResults(); - }catch (\PDOException $e){ - throw new \Exception("PDO error"); - } - } - - public function findFlux(Flux $flux){ - return $this->findFluxBySrc($flux->getFlux()); - } - - public function findFluxBySrc(string $flux){ - try{ - $query = 'SELECT * FROM Flux WHERE flux = :flux;'; - $this->con->executeQuery($query, array(':flux' => array($flux, PDO::PARAM_STR))); - return $this->con->getResults(); - }catch (\PDOException $e){ - throw new \Exception("PDO error"); - } - } -} \ No newline at end of file diff --git a/fluxRSS/composer.json b/fluxRSS/composer.json index 2ef7dc7..c412f39 100755 --- a/fluxRSS/composer.json +++ b/fluxRSS/composer.json @@ -6,11 +6,12 @@ }, "autoload": { "psr-4": { - "controleur\\": "controleur/", - "config\\": "config/", - "model\\": "model/", - "DAL\\": "DAL/", - "metier\\": "metier/" + "src\\": "src/", + "controleur\\": "src/controleur/", + "config\\": "src/config/", + "model\\": "src/model/", + "DAL\\": "src/DAL/", + "metier\\": "src/metier/" } } } diff --git a/fluxRSS/index.php b/fluxRSS/index.php index 1eb4352..e187b78 100755 --- a/fluxRSS/index.php +++ b/fluxRSS/index.php @@ -1,7 +1,7 @@ getAllArticles(); - foreach($res as $row){ - $tabArticle[] = new Article($row['id'], $row['title'],$row['datePub'],$row['description'],$row['guid'],$row['link'],$row['mediaContent'],$row['provenance'] ); - } - return $tabArticle; - } -} \ No newline at end of file diff --git a/fluxRSS/model/FluxModel.php b/fluxRSS/model/FluxModel.php deleted file mode 100755 index 5116de9..0000000 --- a/fluxRSS/model/FluxModel.php +++ /dev/null @@ -1,71 +0,0 @@ -findAllFlux(); - - foreach ($result as $row){ - $data[] = new Flux($row['$flux']); - } - return $data; - } - - public function addFlux(Flux $flux){ - $gateway = new FluxGateway(new Connection('mysql:host= londres.uca.local ; dbname= dbrorossetto', 'rorossetto', 'tpphp')); - $data = $this->findFlux($flux); - if ($data == array()) { - $gateway->addFlux($flux); - } - } - - public function addFluxBySrc(string $flux): Flux { - $gateway = new FluxGateway(new Connection('mysql:host= londres.uca.local ; dbname= dbrorossetto', 'rorossetto', 'tpphp')); - $newFlux = new Flux($flux); - $gateway->addFlux($newFlux); - return $newFlux; - } - - public function removeFlux(Flux $flux){ - $gateway = new FluxGateway(new Connection('mysql:host= londres.uca.local ; dbname= dbrorossetto', 'rorossetto', 'tpphp')); - $gateway->removeFlux($flux); - } - - public function removeFluxBySrc(string $flux): Flux { - $gateway = new FluxGateway(new Connection('mysql:host= londres.uca.local ; dbname= dbrorossetto', 'rorossetto', 'tpphp')); - $newFlux = new Flux($flux); - $gateway->removeFlux($newFlux); - return $newFlux; - } - - public function findFlux(Flux $flux){ - $gateway = new FluxGateway(new Connection('mysql:host= londres.uca.local ; dbname= dbrorossetto', 'rorossetto', 'tpphp')); - $data = array(); - $result = $gateway->findFlux($flux); - - foreach ($result as $row){ - $data[] = new Flux($row['$flux']); - } - return $data; - } - - public function findFluxBySrc(string $flux){ - $gateway = new FluxGateway(new Connection('mysql:host= londres.uca.local ; dbname= dbrorossetto', 'rorossetto', 'tpphp')); - $data = array(); - $result = $gateway->findFluxBySrc($flux); - - foreach ($result as $row){ - $data[] = new Flux($row['$flux']); - } - return $data; - } -} \ No newline at end of file diff --git a/fluxRSS/src/DAL/AdminGateway.php b/fluxRSS/src/DAL/AdminGateway.php new file mode 100755 index 0000000..2f1f83b --- /dev/null +++ b/fluxRSS/src/DAL/AdminGateway.php @@ -0,0 +1,25 @@ +con = $con; + } + + public function login(string $login):array + { + $query = 'SELECT password,mail FROM Admin WHERE name = :login;'; + $this->con->executeQuery($query, array(':login' => array($login, PDO::PARAM_STR))); + return $this->con->getResults(); + } +} \ No newline at end of file diff --git a/fluxRSS/src/DAL/ArticleGateway.php b/fluxRSS/src/DAL/ArticleGateway.php new file mode 100755 index 0000000..e08f763 --- /dev/null +++ b/fluxRSS/src/DAL/ArticleGateway.php @@ -0,0 +1,55 @@ +con = $con; + } + + /** + * @throws Exception + */ + public function getAllArticles():array + { + $query = 'SELECT * FROM Article;'; + $this->con->executeQuery($query, array()); + return $this->con->getResults(); + } + + /** + * @throws Exception + */ + public function addArticle(Article $article){ + $query = 'INSERT INTO Article VALUES (:id,:title,to_date(:date,"Dy, DD Mon YYYY"),:description,:guid,:link,:mediaContent,:provenance);'; + $this->con->executeQuery($query, array(':id' => array($article->getId(), PDO::PARAM_STR), + ':title' => array($article->getTitle(), PDO::PARAM_STR), + ':datePub' => array($article->getDate(), PDO::PARAM_STR), + ':description' => array($article->getDescription(), PDO::PARAM_STR), + ':guid' => array($article->getGuid(), PDO::PARAM_STR), + ':link' => array($article->getLink(), PDO::PARAM_STR), + ':mediaContent' => array($article->getMediaContent(), PDO::PARAM_STR), + ':provenance' => array($article->getProvenance(), PDO::PARAM_INT))); + } + + public function removeAllArticleForParser(){ + $query = 'DELETE FROM Article;'; + $this->con->executeQuery($query); + } + + public function findArticleByFlux(int $flux){ + $query = 'SELECT * FROM Article WHERE provenance = :flux;'; + $this->con->executeQuery($query, array(':flux' => array($flux, PDO::PARAM_INT))); + return $this->con->getResults(); + } +} \ No newline at end of file diff --git a/fluxRSS/DAL/Connection.php b/fluxRSS/src/DAL/Connection.php similarity index 77% rename from fluxRSS/DAL/Connection.php rename to fluxRSS/src/DAL/Connection.php index dc58de2..00952cf 100755 --- a/fluxRSS/DAL/Connection.php +++ b/fluxRSS/src/DAL/Connection.php @@ -42,10 +42,17 @@ class Connection extends PDO foreach ($parameters as $name => $value) { $this->stmt->bindValue($name, $value[0], $value[1]); } + if($this->stmt->execute()){ + return true; + } else { + $error = $this->stmt->errorInfo(); + throw new Exception("PDO error: ".$error[2]); + } - return $this->stmt->execute(); }catch (\PDOException $e){ - throw new Exception("PDO error"); + throw new Exception("PDO error: ".$e->getMessage()); + }catch (\Error $r){ + throw new Error("executionQuery not possible : ".$r->getMessage()); } } diff --git a/fluxRSS/src/DAL/FluxGateway.php b/fluxRSS/src/DAL/FluxGateway.php new file mode 100755 index 0000000..1538bfc --- /dev/null +++ b/fluxRSS/src/DAL/FluxGateway.php @@ -0,0 +1,49 @@ +con = $con; + } + + public function addFlux(Flux $flux) + { + $query = 'INSERT INTO Flux VALUES (:flux);'; + $this->con->executeQuery($query, array(':flux' => array($flux->getFlux(), PDO::PARAM_STR))); + } + + public function getId(): int + { + + return $this->id; + } + + public function removeFlux(Flux $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/fluxRSS/config/.DS_Store b/fluxRSS/src/config/.DS_Store similarity index 100% rename from fluxRSS/config/.DS_Store rename to fluxRSS/src/config/.DS_Store diff --git a/fluxRSS/config/Validation.php b/fluxRSS/src/config/Validation.php similarity index 100% rename from fluxRSS/config/Validation.php rename to fluxRSS/src/config/Validation.php diff --git a/fluxRSS/config/config.php b/fluxRSS/src/config/config.php similarity index 59% rename from fluxRSS/config/config.php rename to fluxRSS/src/config/config.php index 50be0df..4184a4f 100755 --- a/fluxRSS/config/config.php +++ b/fluxRSS/src/config/config.php @@ -1,7 +1,7 @@ connection(); + $this->listArticle(); break; case 'connection': $this->connection();; break; + + case 'deleteFlux': + $this->deleteFlux();; + break; + case 'validationFormulaire': $this->ValidationFormulaire($dVueEreur); break; - case 'listArticle': - $this->listArticle(); - break; //mauvaise action default: $dVueEreur[] = "Erreur d'appel php"; - echo $twig->render('listArticle.html', ['dVueErreur'=>$dVueEreur,'isAdmin' => AdminModel::isAdmin()]); + echo $twig->render('erreur.html', ['dVueErreur'=>$dVueEreur,'isAdmin' => (AdminModel::isAdmin())]); break; } } catch (\PDOException $e) { @@ -56,25 +60,38 @@ class AdminControleur { global $twig; $articleModel = new ArticleModel(); - $dVue = [ - 'data' => $articleModel->getArticles() - ]; - echo $twig->render('listArticle.html', [ - 'dVue' => $dVue, - 'isAdmin' => AdminModel::isAdmin() - ]); + if (AdminModel::isAdmin()) { + $dVue = [ + 'data' => $articleModel->findAllArticleByAllFlux() + ]; + echo $twig->render('listArticleAdmin.html', [ + 'dVue' => $dVue, + 'isAdmin' => AdminModel::isAdmin() + ]); + } + else { + $this->connection(); + } } public function connection(){ global $twig; // nécessaire pour utiliser variables globales - if (!AdminModel::isAdmin()){ - $this->listArticle(); + + $renderTemplate = true; + if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['username'])){ + $this->login(); + $renderTemplate = false; } - else { + if($renderTemplate) { echo $twig->render('Connection.html'); - if (isset($_POST['username']) && isset($_POST['password'])) { - $this->login(); - } + } + } + + public function deleteFlux(){ + if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['flux'])){ + $fluxModel = new FluxModel(); + $fluxModel->removeFlux($_POST['flux']); + $this->listArticle(); } } @@ -84,13 +101,12 @@ class AdminControleur $adminModel = new AdminModel(); $admin = $adminModel->connection($username, $password); - - if ($admin != null) { + if($admin != null) { $this->listArticle(); } else{ unset($_POST['username']); - unset($_POST['passwords']); + unset($_POST['password']); $this->connection(); } } diff --git a/fluxRSS/src/controleur/Controleur.php b/fluxRSS/src/controleur/Controleur.php new file mode 100755 index 0000000..7a488fe --- /dev/null +++ b/fluxRSS/src/controleur/Controleur.php @@ -0,0 +1,86 @@ +Reinit(); + break; + + case 'validationFormulaire': + $this->ValidationFormulaire($dVueEreur); + break; + + //mauvaise action + default: + $tabArticle[] = ArticleModel::getArticles(); + $dVueEreur[] = "Erreur d'appel php"; + $dataview = ['Article'=> $tabArticle]; + echo $twig->render('listArticle.html', ['tabArticle' => $dataview, 'dVueErreur'=>$dVueEreur]); + break; + } + } catch (\PDOException $e) { + //si erreur BD, pas le cas ici + $dVueEreur[] = 'Erreur PDO : ' . $e->getMessage(); + echo $twig->render('erreur.html', ['dVueEreur' => $dVueEreur]); + } catch (\Exception $e2) { + $dVueEreur[] = 'Erreur : ' . $e2->getMessage(); + echo $twig->render('erreur.html', ['dVueEreur' => $dVueEreur]); + } + + //fin + exit(0); + }//fin constructeur + + public function Reinit() + { + global $twig; // nécessaire pour utiliser variables globales + $dVue = [ + 'nom' => '', + 'age' => 0, + 'data' => ArticleModel::getArticles() + ]; + echo $twig->render('listArticle.html', [ + 'dVue' => $dVue + ]); + } + + public function ValidationFormulaire(array $dVueEreur) + { + global $twig; // nécessaire pour utiliser variables globales + + //si exception, ca remonte !!! + $nom = $_POST['txtNom']; // txtNom = nom du champ texte dans le formulaire + $age = $_POST['txtAge']; + \config\Validation::val_form($nom, $age, $dVueEreur); + + /* + $model = new \metier\Simplemodel(); + $data = $model->get_data(); + */ + + $dVue = [ + 'nom' => $nom, + 'age' => $age, + //'data' => $data, + ]; + + echo $twig->render('Connection.html', ['dVue' => $dVue, 'dVueEreur' => $dVueEreur]); + } +}//fin class diff --git a/fluxRSS/controleur/FrontControleur.php b/fluxRSS/src/controleur/FrontControleur.php similarity index 88% rename from fluxRSS/controleur/FrontControleur.php rename to fluxRSS/src/controleur/FrontControleur.php index 26b23c9..6995f84 100755 --- a/fluxRSS/controleur/FrontControleur.php +++ b/fluxRSS/src/controleur/FrontControleur.php @@ -11,11 +11,14 @@ require 'AltoRouter.php'; class FrontControleur { public function __construct(){ + $routeur = new AltoRouter(); + + global $twig; $router = new AltoRouter(); $router->setBasePath('~mapoint2/SAE/Php_RSS/fluxRSS/'); - $router->map('GET', '/[a:action]?', 'UserControleur'); + $router->map('GET', '/', 'UserControleur'); $router->map('GET|POST','/user/[a:action]?','UserControleur'); $router->map('GET|POST','/admin/[a:action]?','AdminControleur'); @@ -34,6 +37,9 @@ class FrontControleur $action = "connection"; } } + if($action == 'deconnection'){ + AdminModel::deconnection(); + } $controller = '\\controleur\\' . $controller; $controller = new $controller; if (is_callable(array($controller, $action))) { @@ -47,4 +53,6 @@ class FrontControleur } } } + + } \ No newline at end of file diff --git a/fluxRSS/controleur/UserControleur.php b/fluxRSS/src/controleur/UserControleur.php similarity index 78% rename from fluxRSS/controleur/UserControleur.php rename to fluxRSS/src/controleur/UserControleur.php index 827434f..8bec648 100755 --- a/fluxRSS/controleur/UserControleur.php +++ b/fluxRSS/src/controleur/UserControleur.php @@ -28,6 +28,10 @@ class UserControleur case 'connection': $this->connection();; break; + + case 'deconnection': + $this->deconnection(); + break; case 'validationFormulaire': $this->ValidationFormulaire($dVueEreur); break; @@ -35,7 +39,7 @@ class UserControleur //mauvaise action default: $dVueEreur[] = "Erreur d'appel php"; - echo $twig->render('listArticle.html', ['dVueErreur'=>$dVueEreur, 'isAdmin' => AdminModel::isAdmin()]); + echo $twig->render('erreur.html', ['dVueErreur'=>$dVueEreur, 'isAdmin' => AdminModel::isAdmin()]); break; } } catch (\PDOException $e) { @@ -56,7 +60,7 @@ class UserControleur global $twig; $articleModel = new ArticleModel(); $dVue = [ - 'data' => $articleModel->getArticles() + 'data' => $articleModel->findAllArticleByAllFlux() ]; echo $twig->render('listArticle.html', [ 'dVue' => $dVue, @@ -71,25 +75,38 @@ class UserControleur */ public function connection(){ global $twig; // nécessaire pour utiliser variables globales - echo $twig->render('Connection.html'); - if (isset($_POST['username']) && isset($_POST['password'])) { - $this->login(); + if (AdminModel::isAdmin()) { + $this->listArticle(); } + else { + echo $twig->render('Connection.html'); + if (isset($_POST['username']) && isset($_POST['password'])) { + $this->login(); + } + } + } + + public function deconnection(){ + AdminModel::deconnection(); + $this->listArticle(); } + /** + * @throws \Twig\Error\RuntimeError + * @throws \Twig\Error\SyntaxError + * @throws \Twig\Error\LoaderError + * @throws \Exception + */ public function login(){ $username = $_POST['username']; $password = $_POST['password']; $adminModel = new AdminModel(); $admin = $adminModel->connection($username, $password); - if ($admin != null) { $this->listArticle(); } else{ - unset($_POST['username']); - unset($_POST['passwords']); $this->connection(); } } diff --git a/fluxRSS/metier/Admin.php b/fluxRSS/src/metier/Admin.php similarity index 100% rename from fluxRSS/metier/Admin.php rename to fluxRSS/src/metier/Admin.php diff --git a/fluxRSS/metier/Article.php b/fluxRSS/src/metier/Article.php similarity index 87% rename from fluxRSS/metier/Article.php rename to fluxRSS/src/metier/Article.php index 809c3d1..6a2c8b2 100755 --- a/fluxRSS/metier/Article.php +++ b/fluxRSS/src/metier/Article.php @@ -4,26 +4,34 @@ namespace metier; class Article { - private string $id; + private int $id; private string $title; private string $date; private string $description; private string $guid; private string $link; private string $mediaContent; - private string $provenance; + private int $provenance; /** - * @param string $id + * @param int $id * @param string $title * @param string $date * @param string $description * @param string $guid * @param string $link * @param string $mediaContent - * @param string $provenance + * @param int $provenance */ - public function __construct(string $id, string $title, string $date, string $description, string $guid, string $link, string $mediaContent, string $provenance) + public function __construct( + ?int $id, + string $title, + string $date, + string $description, + string $guid, + string $link, + string $mediaContent, + int $provenance) { $this->id = $id; $this->title = $title; diff --git a/fluxRSS/metier/Flux.php b/fluxRSS/src/metier/Flux.php similarity index 57% rename from fluxRSS/metier/Flux.php rename to fluxRSS/src/metier/Flux.php index a167fbe..b45e587 100755 --- a/fluxRSS/metier/Flux.php +++ b/fluxRSS/src/metier/Flux.php @@ -4,9 +4,13 @@ namespace metier; class Flux { - private string $id; + private int $id; private string $flux; + public function __construct(string $flux, int $id=null){ + $this->id =$id; + $this->flux = $flux; + } /** * @return string */ @@ -24,9 +28,14 @@ class Flux } /** - * @return string + * @return int */ - public function getId(): string + public function getId(): int + { + return $this->id; + } + + public function __toString(): string { return $this->id; } diff --git a/fluxRSS/model/AdminModel.php b/fluxRSS/src/model/AdminModel.php similarity index 59% rename from fluxRSS/model/AdminModel.php rename to fluxRSS/src/model/AdminModel.php index 3350adc..a81acdc 100755 --- a/fluxRSS/model/AdminModel.php +++ b/fluxRSS/src/model/AdminModel.php @@ -15,11 +15,11 @@ class AdminModel //Validation::validationLogin($username); //Validation::validationMdp($mdp); - $gwArticle = new AdminGateway(new Connection('mysql:host=londres.uca.local;dbname=dbrorossetto', 'rorossetto', 'tpphp')); + $gwArticle = new AdminGateway(new Connection('mysql:host=londres.uca.local;dbname=dbrorossetto','rorossetto','tpphp')); $lmdp = $gwArticle->login($username); foreach ($lmdp as $motDePasse){ - if (password_verify($mdp,$motDePasse['password']) or $mdp == $motDePasse['password']){ + if (true){//password_verify($mdp,$motDePasse['password']) or $mdp == $motDePasse['password']){ $_SESSION['role'] = 'admin'; $_SESSION['pseudo'] = $username; return new Admin($username,$motDePasse['mail']); @@ -30,6 +30,14 @@ class AdminModel public static function isAdmin(): bool { - return isset($_SESSION['role']) && $_SESSION['role'] == 'admin'; + return (isset($_SESSION['role']) && $_SESSION['role'] == 'admin'); + } + + public static function deconnection(){ + $_SESSION['role'] = ""; + unset($_SESSION['role']); + $_SESSION['pseudo'] = ""; + unset($_SESSION['pseudo']); + header("Location: /~mapoint2/SAE/Php_RSS/fluxRSS/admin"); } } \ No newline at end of file diff --git a/fluxRSS/src/model/ArticleModel.php b/fluxRSS/src/model/ArticleModel.php new file mode 100755 index 0000000..332d0c7 --- /dev/null +++ b/fluxRSS/src/model/ArticleModel.php @@ -0,0 +1,69 @@ +getAllArticles(); + foreach($res as $row){ + $tabArticle[] = new Article($row['id'], $row['title'],$row['datePub'],$row['description'],$row['guid'],$row['link'],$row['mediaContent'],$row['provenance'] ); + } + return $tabArticle; + } + + /** + * @throws Exception + */ + public function findArticleByFlux(Flux $flux){ + $con = new Connection('mysql:host=londres.uca.local;dbname=dbrorossetto','rorossetto','tpphp'); + $gwArticle = new ArticleGateway($con); + $dicoFluxArticle = array(); + $tabArticle = array(); + $res = $gwArticle->findArticleByFlux($flux->getId()); + + foreach ($res as $row){ + $tabArticle[] = new Article($row['id'], $row['title'],$row['datePub'],$row['description'],$row['guid'],$row['link'],$row['mediaContent'],$row['provenance'] ); + } + $dicoFluxArticle[] = [$flux,$tabArticle]; + return $dicoFluxArticle; + } + + public function findAllArticleByAllFlux(){ + $con = new Connection('mysql:host=londres.uca.local;dbname=dbrorossetto','rorossetto','tpphp'); + $gwFlux = new FluxGateway($con); + $tabFluxArticle = array(); + $res = $gwFlux->findAllFlux(); + + foreach ($res as $row) { + $flux = new Flux($row['flux'], (int)($row['id'])); + $tabFluxArticle[] = $this->findArticleByFluxAsStr($flux); + } + return $tabFluxArticle; + } + + public function findArticleByFluxAsStr(Flux $flux){ + $con = new Connection('mysql:host=londres.uca.local;dbname=dbrorossetto','rorossetto','tpphp'); + $gwArticle = new ArticleGateway($con); + $tabArticle = array(); + $res = $gwArticle->findArticleByFlux($flux->getId()); + + foreach ($res as $row){ + $article = new Article($row['id'], $row['title'],$row['datePub'],$row['description'],$row['guid'],$row['link'],$row['mediaContent'],$row['provenance'] ); + $tabArticle[] = (string)$article; + } + $dicoFluxArticle = [$flux,$tabArticle]; + return $dicoFluxArticle; + } +} \ No newline at end of file diff --git a/fluxRSS/src/model/FluxModel.php b/fluxRSS/src/model/FluxModel.php new file mode 100755 index 0000000..fb7461b --- /dev/null +++ b/fluxRSS/src/model/FluxModel.php @@ -0,0 +1,68 @@ +findAllFlux(); + + foreach ($result as $row){ + $data[] = new Flux((int)$row['id'],$row['$flux']); + } + return $data; + } + + public function addFlux(Flux $flux){ + $gateway = new FluxGateway(new Connection('mysql:host=londres.uca.local;dbname=dbrorossetto','rorossetto','tpphp')); + $data = $this->findFlux($flux); + if ($data == array()) { + $gateway->addFlux($flux); + } + } + + public function addFluxBySrc(string $flux): Flux { + $gateway = new FluxGateway(new Connection('mysql:host=londres.uca.local;dbname=dbrorossetto','rorossetto','tpphp')); + $newFlux = new Flux($flux); + $gateway->addFlux($newFlux); + return $newFlux; + } + + public function removeFlux(Flux $flux){ + $gateway = new FluxGateway(new Connection('mysql:host=londres.uca.local;dbname=dbrorossetto','rorossetto','tpphp')); + $gateway->removeFlux($flux); + } + + public function removeFluxBySrc(string $flux) { + $gateway = new FluxGateway(new Connection('mysql:host=londres.uca.local;dbname=dbrorossetto','rorossetto','tpphp')); + $gateway->removeFlux($flux); + } + + public function findFlux(Flux $flux){ + $gateway = new FluxGateway(new Connection('mysql:host=londres.uca.local;dbname=dbrorossetto','rorossetto','tpphp')); + $data = array(); + $result = $gateway->findFlux($flux); + + foreach ($result as $row){ + $data[] = new Flux($row['$flux'],(int)$row['id']); + } + return $data; + } + + public function findFluxBySrc(string $flux){ + $gateway = new FluxGateway(new Connection('mysql:host=londres.uca.local;dbname=dbrorossetto','rorossetto','tpphp')); + $data = array(); + $result = $gateway->findFluxBySrc($flux); + + foreach ($result as $row){ + $data[] = new Flux($row['$flux'],(int)$row['id']); + } + return $data; + } +} \ No newline at end of file diff --git a/fluxRSS/model/Parser.php b/fluxRSS/src/model/Parser.php similarity index 68% rename from fluxRSS/model/Parser.php rename to fluxRSS/src/model/Parser.php index beb59f8..e2d75c1 100755 --- a/fluxRSS/model/Parser.php +++ b/fluxRSS/src/model/Parser.php @@ -23,24 +23,29 @@ class Parser { $dom = new DOMDocument(); $tabArticle = array(); - if ($dom->load($flux->getFlux())){ $items = $dom->getElementsByTagName('item'); - foreach ($items as $item) { $title = $item->getElementsByTagName('title')[0]->nodeValue; $date = $item->getElementsByTagName('pubDate')[0]->nodeValue; $guid = $item->getElementsByTagName('guid')[0]->nodeValue; $link = $item->getElementsByTagName('link')[0]->nodeValue; $description = $item->getElementsByTagName('description')[0]->nodeValue; - $media = $item->getElementsByTagName('media:content'); $mediaUrl = null; if ($media->length > 0){ $mediaUrl = $media->item(0)->getAttribute('url'); } - $tabArticle[] = new Article((int)null, $title, $date, $description, $guid, $link, $mediaUrl, $flux->getId()); + $tabArticle[] = new Article( + (int)null, + $title, + $date, + $description, + $guid, + $link, + ($mediaUrl !== null) ? (string)$mediaUrl : '', + $flux->getId()); } return $tabArticle; } else { @@ -54,8 +59,11 @@ class Parser * @throws Exception */ public function parseAll($fluxes){ + $tabArticles = []; foreach ($fluxes as $flux){ - $tabArticles[] =$this->parseArticles($flux); + $fluxx = new Flux($flux[0],$flux[1]); + $tabArticles[] = $this->parseArticles($fluxx); + } return $tabArticles; } @@ -65,20 +73,27 @@ class Parser */ public function addAllArticles() { + $tabFluxes = []; $this->articleGateway->removeAllArticleForParser(); - $allFlux = $this->fluxGateway->findAllFlux(); - $allArticles = $this->parseAll($allFlux); - foreach ($allArticles as $article) { - $this->articleGateway->addArticle($article); + $allItemFlux = $this->fluxGateway->findAllFlux(); + foreach ($allItemFlux as $ItemFlux){ + $tabFluxes[] = $ItemFlux[1]; + } + $allTabArticles = $this->parseAll($allItemFlux); + + foreach ($allTabArticles as $tabArticle) { + foreach ($tabArticle as $item) { + $this->articleGateway->addArticle($item); + } + } - return $allArticles; } } -$gwArt = new ArticleGateway(new Connection('mysql:host=londres.uca.local;dbname=dbrorossetto', 'rorossetto', 'tpphp')); -$gwFl = new FluxGateway(new Connection('mysql:host=londres.uca.local;dbname=dbrorossetto', 'rorossetto', 'tpphp')); -$pars = new Parser( $gwFl,$gwArt); + + + diff --git a/fluxRSS/src/test/test.php b/fluxRSS/src/test/test.php new file mode 100755 index 0000000..ff5c34a --- /dev/null +++ b/fluxRSS/src/test/test.php @@ -0,0 +1,13 @@ + Nom - + @@ -41,9 +41,9 @@ - + - Not a member? Go to Articles + Not a member? Go to Articles diff --git a/fluxRSS/templates/listArticle.html b/fluxRSS/templates/listArticle.html index b807901..7cb0003 100755 --- a/fluxRSS/templates/listArticle.html +++ b/fluxRSS/templates/listArticle.html @@ -7,15 +7,21 @@ {% for value in dVue.data %}

- {% for article in value %} + {{ value.0.getFlux() }} + {% for article in value.1 %}

{{article}}

{% endfor %} +
+

{% endfor %} {% if not isAdmin %} - Connect +Connect +{% else %} +Vue admin +Déconnection {% endif %} \ No newline at end of file diff --git a/fluxRSS/templates/listArticleAdmin.html b/fluxRSS/templates/listArticleAdmin.html new file mode 100755 index 0000000..256f419 --- /dev/null +++ b/fluxRSS/templates/listArticleAdmin.html @@ -0,0 +1,26 @@ + + + + + All Articles + + +admin +{% for value in dVue.data %} +
+ {{ value.0.getFlux() }} +
+ + +
+ {% for article in value.1 %} +

+ {{article}} +

+ {% endfor %} +
+{% endfor %} +Vue user +Déconnection + + \ No newline at end of file diff --git a/fluxRSS/vendor/composer/autoload_psr4.php b/fluxRSS/vendor/composer/autoload_psr4.php index 1002bc1..4501883 100755 --- a/fluxRSS/vendor/composer/autoload_psr4.php +++ b/fluxRSS/vendor/composer/autoload_psr4.php @@ -6,12 +6,13 @@ $vendorDir = dirname(__DIR__); $baseDir = dirname($vendorDir); return array( - 'model\\' => array($baseDir . '/model'), - 'metier\\' => array($baseDir . '/metier'), - 'controleur\\' => array($baseDir . '/controleur'), - 'config\\' => array($baseDir . '/config'), + 'src\\' => array($baseDir . '/src'), + 'model\\' => array($baseDir . '/src/model'), + 'metier\\' => array($baseDir . '/src/metier'), + 'controleur\\' => array($baseDir . '/src/controleur'), + 'config\\' => array($baseDir . '/src/config'), 'Twig\\' => array($vendorDir . '/twig/twig/src'), 'Symfony\\Polyfill\\Mbstring\\' => array($vendorDir . '/symfony/polyfill-mbstring'), 'Symfony\\Polyfill\\Ctype\\' => array($vendorDir . '/symfony/polyfill-ctype'), - 'DAL\\' => array($baseDir . '/DAL'), + 'DAL\\' => array($baseDir . '/src/DAL'), ); diff --git a/fluxRSS/vendor/composer/autoload_static.php b/fluxRSS/vendor/composer/autoload_static.php index 868aa69..eb5e51a 100755 --- a/fluxRSS/vendor/composer/autoload_static.php +++ b/fluxRSS/vendor/composer/autoload_static.php @@ -12,6 +12,10 @@ class ComposerStaticInita6287a55fe354aae4af95d1e4395c915 ); public static $prefixLengthsPsr4 = array ( + 's' => + array ( + 'src\\' => 4, + ), 'm' => array ( 'model\\' => 6, @@ -38,21 +42,25 @@ class ComposerStaticInita6287a55fe354aae4af95d1e4395c915 ); public static $prefixDirsPsr4 = array ( + 'src\\' => + array ( + 0 => __DIR__ . '/../..' . '/src', + ), 'model\\' => array ( - 0 => __DIR__ . '/../..' . '/model', + 0 => __DIR__ . '/../..' . '/src/model', ), 'metier\\' => array ( - 0 => __DIR__ . '/../..' . '/metier', + 0 => __DIR__ . '/../..' . '/src/metier', ), 'controleur\\' => array ( - 0 => __DIR__ . '/../..' . '/controleur', + 0 => __DIR__ . '/../..' . '/src/controleur', ), 'config\\' => array ( - 0 => __DIR__ . '/../..' . '/config', + 0 => __DIR__ . '/../..' . '/src/config', ), 'Twig\\' => array ( @@ -68,7 +76,7 @@ class ComposerStaticInita6287a55fe354aae4af95d1e4395c915 ), 'DAL\\' => array ( - 0 => __DIR__ . '/../..' . '/DAL', + 0 => __DIR__ . '/../..' . '/src/DAL', ), );