resolution conflicts

pull/16/head
Roxane ROSSETTO 1 year ago
commit ecd2f52662

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="SqlDialectMappings">
<file url="file://$PROJECT_DIR$/fluxRSS/DAL/ArticleGateway.php" dialect="PostgreSQL" />
</component>
</project>

@ -2,11 +2,14 @@
<module type="WEB_MODULE" version="4"> <module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager"> <component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$"> <content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/config" isTestSource="false" packagePrefix="config\" />
<sourceFolder url="file://$MODULE_DIR$/controleur" isTestSource="false" packagePrefix="controleur\" />
<sourceFolder url="file://$MODULE_DIR$/metier" isTestSource="false" packagePrefix="modeles\" />
<sourceFolder url="file://$MODULE_DIR$/spec" isTestSource="true" /> <sourceFolder url="file://$MODULE_DIR$/spec" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/tests" isTestSource="true" /> <sourceFolder url="file://$MODULE_DIR$/tests" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/DAL" isTestSource="false" packagePrefix="DAL\" />
<sourceFolder url="file://$MODULE_DIR$/src/config" isTestSource="false" packagePrefix="config\" />
<sourceFolder url="file://$MODULE_DIR$/src/controleur" isTestSource="false" packagePrefix="controleur\" />
<sourceFolder url="file://$MODULE_DIR$/src/metier" isTestSource="false" packagePrefix="metier\" />
<sourceFolder url="file://$MODULE_DIR$/src/model" isTestSource="false" packagePrefix="model\" />
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" packagePrefix="src\" />
<excludeFolder url="file://$MODULE_DIR$/vendor/composer" /> <excludeFolder url="file://$MODULE_DIR$/vendor/composer" />
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/polyfill-ctype" /> <excludeFolder url="file://$MODULE_DIR$/vendor/symfony/polyfill-ctype" />
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/polyfill-mbstring" /> <excludeFolder url="file://$MODULE_DIR$/vendor/symfony/polyfill-mbstring" />

@ -6,11 +6,12 @@
}, },
"autoload": { "autoload": {
"psr-4": { "psr-4": {
"controleur\\": "controleur/", "src\\": "src/",
"config\\": "config/", "controleur\\": "src/controleur/",
"model\\": "model/", "config\\": "src/config/",
"DAL\\": "DAL/", "model\\": "src/model/",
"metier\\": "metier/" "DAL\\": "src/DAL/",
"metier\\": "src/metier/"
} }
} }
} }

@ -1,7 +1,7 @@
<?php <?php
//chargement config //chargement config
require_once __DIR__ . '/config/config.php'; require_once __DIR__ . '/src/config/config.php';
require __DIR__ . '/vendor/autoload.php'; require __DIR__ . '/vendor/autoload.php';

@ -35,10 +35,10 @@ class ArticleGateway
*/ */
public function addArticle(Article $article){ public function addArticle(Article $article){
try { try {
$query = 'INSERT INTO Article VALUES (:id,:title,to_date(:date,"Dy, DD Mon YYYY"),:description,:guid,:link,:mediaContent,:provenance);'; $query = 'INSERT INTO Article VALUES (:id,:title,:datePub,:description,:guid,:link,:mediaContent,:provenance);';
$this->con->executeQuery($query, array(':id' => array($article->getId(), PDO::PARAM_STR), $this->con->executeQuery($query, array(':id' => array($article->getId(), PDO::PARAM_INT),
':title' => array($article->getTitle(), PDO::PARAM_STR), ':title' => array($article->getTitle(), PDO::PARAM_STR),
':date' => array($article->getDate(), PDO::PARAM_STR), ':datePub' => array($article->getDate(), PDO::PARAM_STR),
':description' => array($article->getDescription(), PDO::PARAM_STR), ':description' => array($article->getDescription(), PDO::PARAM_STR),
':guid' => array($article->getGuid(), PDO::PARAM_STR), ':guid' => array($article->getGuid(), PDO::PARAM_STR),
':link' => array($article->getLink(), PDO::PARAM_STR), ':link' => array($article->getLink(), PDO::PARAM_STR),
@ -54,7 +54,7 @@ class ArticleGateway
$query = 'DELETE FROM Article;'; $query = 'DELETE FROM Article;';
$this->con->executeQuery($query); $this->con->executeQuery($query);
}catch(\PDOException $p){ }catch(\PDOException $p){
throw new Exception("Data is not delete."); throw new Exception("Data is not deleted.");
} }
} }
} }

@ -42,10 +42,17 @@ class Connection extends PDO
foreach ($parameters as $name => $value) { foreach ($parameters as $name => $value) {
$this->stmt->bindValue($name, $value[0], $value[1]); $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){ }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());
} }
} }

@ -13,6 +13,12 @@ class FluxGateway
$this->con = $con; $this->con = $con;
} }
public function getId(): int
{
return $this->id;
}
public function addFlux($flux){ public function addFlux($flux){
try{ try{
$query = 'INSERT INTO Flux VALUES (:flux);'; $query = 'INSERT INTO Flux VALUES (:flux);';
@ -35,7 +41,8 @@ class FluxGateway
try{ try{
$query = 'SELECT * FROM Flux;'; $query = 'SELECT * FROM Flux;';
$this->con->executeQuery($query); $this->con->executeQuery($query);
return $this->con->getResults(); $results = $this->con->getResults();
return $results;
}catch (\PDOException $e){ }catch (\PDOException $e){
throw new \Exception("PDO error"); throw new \Exception("PDO error");
} }

@ -1,7 +1,7 @@
<?php <?php
//gen //gen
$rep = __DIR__ . '/../'; $rep = __DIR__ . '/fluxRSS/';
// liste des modules à inclure // liste des modules à inclure

@ -0,0 +1,86 @@
<?php
namespace controleur;
use model\ArticleModel;
class UserControleur
{
public function __construct()
{
global $twig; // nécessaire pour utiliser variables globales
session_start();
//debut
//on initialise un tableau d'erreur
$dVueEreur = [];
try {
$action = $_REQUEST['action'] ?? null;
switch($action) {
//pas d'action, on réinitialise 1er appel
case null:
$this->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

@ -11,6 +11,9 @@ require 'AltoRouter.php';
class FrontControleur class FrontControleur
{ {
public function __construct(){ public function __construct(){
$routeur = new AltoRouter();
global $twig; global $twig;
$router = new AltoRouter(); $router = new AltoRouter();
@ -50,4 +53,6 @@ class FrontControleur
} }
} }
} }
} }

@ -4,26 +4,34 @@ namespace metier;
class Article class Article
{ {
private string $id; private int $id;
private string $title; private string $title;
private string $date; private string $date;
private string $description; private string $description;
private string $guid; private string $guid;
private string $link; private string $link;
private string $mediaContent; private string $mediaContent;
private string $provenance; private int $provenance;
/** /**
* @param string $id * @param int $id
* @param string $title * @param string $title
* @param string $date * @param string $date
* @param string $description * @param string $description
* @param string $guid * @param string $guid
* @param string $link * @param string $link
* @param string $mediaContent * @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->id = $id;
$this->title = $title; $this->title = $title;

@ -4,9 +4,19 @@ namespace metier;
class Flux class Flux
{ {
private string $id; private int $id;
private string $flux; private string $flux;
/**
* @param int $id
* @param string $flux
*/
public function __construct(int $id, string $flux)
{
$this->id = $id;
$this->flux = $flux;
}
/** /**
* @return string * @return string
*/ */
@ -24,9 +34,9 @@ class Flux
} }
/** /**
* @return string * @return int
*/ */
public function getId(): string public function getId(): int
{ {
return $this->id; return $this->id;
} }

@ -23,24 +23,29 @@ class Parser
{ {
$dom = new DOMDocument(); $dom = new DOMDocument();
$tabArticle = array(); $tabArticle = array();
if ($dom->load($flux->getFlux())){ if ($dom->load($flux->getFlux())){
$items = $dom->getElementsByTagName('item'); $items = $dom->getElementsByTagName('item');
foreach ($items as $item) { foreach ($items as $item) {
$title = $item->getElementsByTagName('title')[0]->nodeValue; $title = $item->getElementsByTagName('title')[0]->nodeValue;
$date = $item->getElementsByTagName('pubDate')[0]->nodeValue; $date = $item->getElementsByTagName('pubDate')[0]->nodeValue;
$guid = $item->getElementsByTagName('guid')[0]->nodeValue; $guid = $item->getElementsByTagName('guid')[0]->nodeValue;
$link = $item->getElementsByTagName('link')[0]->nodeValue; $link = $item->getElementsByTagName('link')[0]->nodeValue;
$description = $item->getElementsByTagName('description')[0]->nodeValue; $description = $item->getElementsByTagName('description')[0]->nodeValue;
$media = $item->getElementsByTagName('media:content'); $media = $item->getElementsByTagName('media:content');
$mediaUrl = null; $mediaUrl = null;
if ($media->length > 0){ if ($media->length > 0){
$mediaUrl = $media->item(0)->getAttribute('url'); $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; return $tabArticle;
} else { } else {
@ -54,8 +59,11 @@ class Parser
* @throws Exception * @throws Exception
*/ */
public function parseAll($fluxes){ public function parseAll($fluxes){
$tabArticles = [];
foreach ($fluxes as $flux){ foreach ($fluxes as $flux){
$tabArticles[] =$this->parseArticles($flux); $fluxx = new Flux($flux[0],$flux[1]);
$tabArticles[] = $this->parseArticles($fluxx);
} }
return $tabArticles; return $tabArticles;
} }
@ -65,20 +73,27 @@ class Parser
*/ */
public function addAllArticles() public function addAllArticles()
{ {
$tabFluxes = [];
$this->articleGateway->removeAllArticleForParser(); $this->articleGateway->removeAllArticleForParser();
$allFlux = $this->fluxGateway->findAllFlux(); $allItemFlux = $this->fluxGateway->findAllFlux();
$allArticles = $this->parseAll($allFlux); foreach ($allItemFlux as $ItemFlux){
foreach ($allArticles as $article) { $tabFluxes[] = $ItemFlux[1];
$this->articleGateway->addArticle($article);
} }
return $allArticles; $allTabArticles = $this->parseAll($allItemFlux);
foreach ($allTabArticles as $tabArticle) {
foreach ($tabArticle as $item) {
$this->articleGateway->addArticle($item);
} }
} }
$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); }

@ -0,0 +1,13 @@
<?php
namespace test;
use DAL\ArticleGateway;
use DAL\Connection;
use DAL\FluxGateway;
use model\Parser;
require '../../vendor/autoload.php';
$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);

@ -6,12 +6,13 @@ $vendorDir = dirname(__DIR__);
$baseDir = dirname($vendorDir); $baseDir = dirname($vendorDir);
return array( return array(
'model\\' => array($baseDir . '/model'), 'src\\' => array($baseDir . '/src'),
'metier\\' => array($baseDir . '/metier'), 'model\\' => array($baseDir . '/src/model'),
'controleur\\' => array($baseDir . '/controleur'), 'metier\\' => array($baseDir . '/src/metier'),
'config\\' => array($baseDir . '/config'), 'controleur\\' => array($baseDir . '/src/controleur'),
'config\\' => array($baseDir . '/src/config'),
'Twig\\' => array($vendorDir . '/twig/twig/src'), 'Twig\\' => array($vendorDir . '/twig/twig/src'),
'Symfony\\Polyfill\\Mbstring\\' => array($vendorDir . '/symfony/polyfill-mbstring'), 'Symfony\\Polyfill\\Mbstring\\' => array($vendorDir . '/symfony/polyfill-mbstring'),
'Symfony\\Polyfill\\Ctype\\' => array($vendorDir . '/symfony/polyfill-ctype'), 'Symfony\\Polyfill\\Ctype\\' => array($vendorDir . '/symfony/polyfill-ctype'),
'DAL\\' => array($baseDir . '/DAL'), 'DAL\\' => array($baseDir . '/src/DAL'),
); );

@ -12,6 +12,10 @@ class ComposerStaticInita6287a55fe354aae4af95d1e4395c915
); );
public static $prefixLengthsPsr4 = array ( public static $prefixLengthsPsr4 = array (
's' =>
array (
'src\\' => 4,
),
'm' => 'm' =>
array ( array (
'model\\' => 6, 'model\\' => 6,
@ -38,21 +42,25 @@ class ComposerStaticInita6287a55fe354aae4af95d1e4395c915
); );
public static $prefixDirsPsr4 = array ( public static $prefixDirsPsr4 = array (
'src\\' =>
array (
0 => __DIR__ . '/../..' . '/src',
),
'model\\' => 'model\\' =>
array ( array (
0 => __DIR__ . '/../..' . '/model', 0 => __DIR__ . '/../..' . '/src/model',
), ),
'metier\\' => 'metier\\' =>
array ( array (
0 => __DIR__ . '/../..' . '/metier', 0 => __DIR__ . '/../..' . '/src/metier',
), ),
'controleur\\' => 'controleur\\' =>
array ( array (
0 => __DIR__ . '/../..' . '/controleur', 0 => __DIR__ . '/../..' . '/src/controleur',
), ),
'config\\' => 'config\\' =>
array ( array (
0 => __DIR__ . '/../..' . '/config', 0 => __DIR__ . '/../..' . '/src/config',
), ),
'Twig\\' => 'Twig\\' =>
array ( array (
@ -68,7 +76,7 @@ class ComposerStaticInita6287a55fe354aae4af95d1e4395c915
), ),
'DAL\\' => 'DAL\\' =>
array ( array (
0 => __DIR__ . '/../..' . '/DAL', 0 => __DIR__ . '/../..' . '/src/DAL',
), ),
); );

@ -3,7 +3,7 @@
'name' => '__root__', 'name' => '__root__',
'pretty_version' => 'dev-master', 'pretty_version' => 'dev-master',
'version' => 'dev-master', 'version' => 'dev-master',
'reference' => '74b55bc18906a4639884ce8f33bd06d1657149b3', 'reference' => 'c00c0a1c491c44a1666572f040f9b9df34933d25',
'type' => 'library', 'type' => 'library',
'install_path' => __DIR__ . '/../../', 'install_path' => __DIR__ . '/../../',
'aliases' => array(), 'aliases' => array(),
@ -13,7 +13,7 @@
'__root__' => array( '__root__' => array(
'pretty_version' => 'dev-master', 'pretty_version' => 'dev-master',
'version' => 'dev-master', 'version' => 'dev-master',
'reference' => '74b55bc18906a4639884ce8f33bd06d1657149b3', 'reference' => 'c00c0a1c491c44a1666572f040f9b9df34933d25',
'type' => 'library', 'type' => 'library',
'install_path' => __DIR__ . '/../../', 'install_path' => __DIR__ . '/../../',
'aliases' => array(), 'aliases' => array(),

Loading…
Cancel
Save