|
|
|
@ -2,13 +2,24 @@
|
|
|
|
|
|
|
|
|
|
namespace controleur;
|
|
|
|
|
|
|
|
|
|
use DAL\ArticleGateway;
|
|
|
|
|
use DAL\Connection;
|
|
|
|
|
use DAL\FluxGateway;
|
|
|
|
|
use http\Exception;
|
|
|
|
|
use metier\Flux;
|
|
|
|
|
use model\AdminModel;
|
|
|
|
|
use model\ArticleModel;
|
|
|
|
|
use model\FluxModel;
|
|
|
|
|
use model\Parser;
|
|
|
|
|
|
|
|
|
|
class AdminControleur
|
|
|
|
|
{
|
|
|
|
|
public function __construct(){
|
|
|
|
|
/*public function __construct()
|
|
|
|
|
{
|
|
|
|
|
$this->init();
|
|
|
|
|
}*/
|
|
|
|
|
|
|
|
|
|
public function init(){
|
|
|
|
|
global $twig; // nécessaire pour utiliser variables globales
|
|
|
|
|
//debut
|
|
|
|
|
|
|
|
|
@ -37,6 +48,18 @@ class AdminControleur
|
|
|
|
|
$this->ValidationFormulaire($dVueEreur);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'listFlux':
|
|
|
|
|
$this->listFlux();
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'ajoutFlux':
|
|
|
|
|
$this->ajoutFlux();
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'changeNbArticle':
|
|
|
|
|
$this->changeNbArticle();
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
//mauvaise action
|
|
|
|
|
default:
|
|
|
|
|
$dVueEreur[] = "Erreur d'appel php";
|
|
|
|
@ -60,10 +83,12 @@ class AdminControleur
|
|
|
|
|
{
|
|
|
|
|
global $twig;
|
|
|
|
|
$articleModel = new ArticleModel();
|
|
|
|
|
$nbArticle = isset($_SESSION['nbArticle']) ? intval($_SESSION['nbArticle']) : 5;
|
|
|
|
|
$allArticles = $articleModel->getArticles();
|
|
|
|
|
$articles = array_slice($allArticles, 0, $nbArticle);
|
|
|
|
|
if (AdminModel::isAdmin()) {
|
|
|
|
|
$data = $articleModel->getArticles();
|
|
|
|
|
$dVue = [
|
|
|
|
|
'data' => $data
|
|
|
|
|
'data' => $articles
|
|
|
|
|
];
|
|
|
|
|
echo $twig->render('listArticleAdmin.html', [
|
|
|
|
|
'dVue' => $dVue,
|
|
|
|
@ -75,11 +100,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,9 +133,35 @@ class AdminControleur
|
|
|
|
|
|
|
|
|
|
public function deleteFlux(){
|
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['flux'])){
|
|
|
|
|
$articleModel = new ArticleModel();
|
|
|
|
|
$fluxModel = new FluxModel();
|
|
|
|
|
$fluxModel->removeFlux($_POST['flux']);
|
|
|
|
|
$this->listArticle();
|
|
|
|
|
$articleModel->removeArticleIdFlux(intval($_POST['flux']));
|
|
|
|
|
$fluxModel->removeFluxById(intval($_POST['flux']));
|
|
|
|
|
$_REQUEST['action'] = 'listFlux';
|
|
|
|
|
$this->init();
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
$_REQUEST['action'] = 'listFlux';
|
|
|
|
|
$this->init();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function ajoutFlux(){
|
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['fluxAdd'])){
|
|
|
|
|
$con = new Connection('mysql:host=londres.uca.local;dbname=dbrorossetto','rorossetto','tpphp');
|
|
|
|
|
$gwArticle = new ArticleGateway($con);
|
|
|
|
|
$gwFlux = new FluxGateway($con);
|
|
|
|
|
$parser = new Parser($gwFlux,$gwArticle);
|
|
|
|
|
$fluxModel = new FluxModel();
|
|
|
|
|
$fluxModel->addFluxBySrc($_POST['fluxAdd']);
|
|
|
|
|
$parser->addAllArticles();
|
|
|
|
|
$_REQUEST['action'] = 'listFlux';
|
|
|
|
|
unset($_POST['fluxAdd']);
|
|
|
|
|
$this->init();
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
$_REQUEST['action'] = 'listFlux';
|
|
|
|
|
$this->init();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -103,7 +172,7 @@ class AdminControleur
|
|
|
|
|
$adminModel = new AdminModel();
|
|
|
|
|
$admin = $adminModel->connection($username, $password);
|
|
|
|
|
if($admin != null) {
|
|
|
|
|
$this->listArticle();
|
|
|
|
|
$this->init();
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
unset($_POST['username']);
|
|
|
|
@ -111,4 +180,13 @@ class AdminControleur
|
|
|
|
|
$this->connection();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function changeNbArticle()
|
|
|
|
|
{
|
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['nbArticle'])) {
|
|
|
|
|
$_SESSION['nbArticle'] = $_POST['nbArticle'];
|
|
|
|
|
unset($_POST['action']);
|
|
|
|
|
}
|
|
|
|
|
$this->init();
|
|
|
|
|
}
|
|
|
|
|
}
|