diff --git a/.DS_Store b/.DS_Store index 754d560..91512b4 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9f11b75 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.idea/ diff --git a/composer.json b/composer.json index 5174d0b..40799b2 100644 --- a/composer.json +++ b/composer.json @@ -9,7 +9,9 @@ "Controleur\\": "src/Controleur/", "Model\\": "src/Model/", "Gateway\\": "src/Gateway/", - "Entity\\": "src/Entity/" + "Entity\\": "src/Entity/", + "Verification\\": "src/Verification/", + "Enum\\": "src/Enum" } } } diff --git a/config/config.php b/config/config.php index 2c604be..322a129 100644 --- a/config/config.php +++ b/config/config.php @@ -12,7 +12,7 @@ $base = ''; $login = ''; $mdp = ''; -$racine='/~kemondejar/WF-Website'; +$racine='/~lebeaulato/WF-Website'; // /~kekentin/WF/WF-Website //Vues @@ -27,6 +27,7 @@ $vues['favorite'] = 'vue/favorits.php'; $vues['quiz'] = 'vue/quiz.php'; $vues['endQuiz'] = 'vue/endQuiz.php'; +$vues['submitQuote'] = 'vue/submitQuote.php'; //Style css diff --git a/index.php b/index.php index a0bc58c..cdbd6fb 100644 --- a/index.php +++ b/index.php @@ -13,10 +13,9 @@ if(!isset($_SESSION['theme'])){ //chargement config require_once __DIR__ . '/config/config.php'; - require __DIR__ . '/vendor/autoload.php'; -$co = new \Gateway\Connection('pgsql:host=localhost;dbname=dbkekentin;', 'kekentin', 'passwd'); +$co = new \Gateway\Connection('pgsql:host=localhost;dbname=dbkekentin;', 'kekentin', 'passwd');// ('pgsql:host=localhost;dbname=dbkekentin;', 'kekentin', 'passwd') //twig $loader = new \Twig\Loader\FilesystemLoader('vue/templates'); diff --git a/public/script/changeData.js b/public/script/changeData.js index e76bb9f..b270748 100644 --- a/public/script/changeData.js +++ b/public/script/changeData.js @@ -1,97 +1,70 @@ +var racine = '/~lebeaulato/WF-Website'; //Mettre votre chemin à vous + +//=============================== USERNAME =============================== function editFieldUsername(id) { - var pElement = document.getElementById(id);// Récupérer l'élément
via son identifiant - - var currentValue = pElement.textContent.trim();// Obtenir le texte actuel du
+ var pElement = document.getElementById(id); // Récupérer l'élément
via son identifiant + var currentValue = pElement.textContent.trim(); // Obtenir le texte actuel du
// Créer un champ de saisie avec la valeur actuelle var input = document.createElement('input'); input.type = 'text'; - input.value = currentValue - input.class = 'changeValue'; - - input.setAttribute('onblur', 'saveFieldUsername("' + id + '", this.value)'); // Sauvegarde lors de la perte de focus + input.value = currentValue; + input.class ='changeValue'; + input.name='pseudo'; + - // Remplacer le
par le champ + // Créer un bouton de validation + var button = document.createElement('button'); + button.textContent = 'Valider'; + button.classList.add('saveButtonPasswd'); + button.type ="submit"; + + // Remplacer le contenu du
par le champ et le bouton pElement.innerHTML = ''; pElement.appendChild(input); - - input.focus(); // Mettre le focus sur le champ de saisie -} + pElement.appendChild(button); -//Sauvegarder les changements sur la vue pour le username -function saveFieldUsername(id, newValue) { - if (id === 'username') { - if (newValue.trim() === "") { - alert('Le nom d\'utilisateur ne peut pas être vide.'); - document.getElementById(id).querySelector('input').focus(); - return; // Ne pas sauvegarder si le nom d'utilisateur est vide - } - } - - var pElement = document.getElementById(id);// Récupérer l'élément
via son identifiant
-
- // Mettre à jour la valeur avec la nouvelle saisie
- pElement.innerHTML = '' + newValue + ' ';
+ input.focus(); // Mettre le focus sur le champ de saisie
}
+//=============================== EMAIL ===============================
function editFieldEmail(id) {
- var pElement = document.getElementById(id);// Récupérer l'élément
via son identifiant - var currentValue = pElement.textContent.trim();// Obtenir le texte actuel du
+ var pElement = document.getElementById(id); // Récupérer l'élément
via son identifiant + var currentValue = pElement.textContent.trim(); // Obtenir le texte actuel du
// Créer un champ de saisie avec la valeur actuelle var input = document.createElement('input'); input.type = 'email'; - input.value = currentValue - input.class = 'changeValue'; - - input.setAttribute('onblur', 'saveFieldEmail("' + id + '", this.value)'); // Sauvegarde lors de la perte de focus - - // Remplacer le
par le champ - pElement.innerHTML = ''; - pElement.appendChild(input); - - input.focus(); // Mettre le focus sur le champ de saisie -} - -//Sauvegarder les changements sur la vue pour l'email -function saveFieldEmail(id, newValue) { - if (id === 'email') { - if (!validateEmail(newValue)) { - alert('Adresse email invalide. Veuillez entrer un email valide.'); - document.getElementById(id).querySelector('input').focus(); - return; // Ne pas sauvegarder si l'email n'est pas valide - } - } - + input.value = currentValue; + input.class= 'changeValue'; // Correction de l'attribut 'class' + input.name='email'; - var pElement = document.getElementById(id); // Récupérer l'élément
via son identifiant
-
- // Mettre à jour la valeur avec la nouvelle saisie
- pElement.innerHTML = '' + newValue + ' ';
-}
+ // Créer un bouton de validation
+ var button = document.createElement('button');
+ button.textContent = 'Valider';
+ button.classList.add('saveButtonPasswd');
+ button.type ="submit";
+ // Remplacer le contenu du
par le champ et le bouton + pElement.innerHTML = ''; + pElement.appendChild(input); + pElement.appendChild(button); -//Email valide -function validateEmail(email) { - var re = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;// Regex pour vérifier le format de l'email - return re.test(String(email).toLowerCase()); + input.focus(); // Mettre le focus sur le champ de saisie } - - - +//=============================== PASSWORD =============================== function editFieldPassWd(id) { var pElement = document.getElementById(id);// Récupérer l'élément
via son identifiant - pElement.innerHTML = '';// Effacer le contenu actuel de
pour insérer les inputs // Créer le champ de saisie pour le nouveau mot de passe @@ -101,7 +74,8 @@ function editFieldPassWd(id) { inputNewPass.classList.add('changeValue'); // Ajouter une classe CSS pour styliser l'input inputNewPass.setAttribute('id', 'newPassword'); // Ajouter un ID pour la gestion inputNewPass.classList.add('inputPasswd'); // Ajouter une classe au input - + inputNewPass.name='passwdFirst'; + // Créer le champ de saisie pour la confirmation du mot de passe var inputConfirmPass = document.createElement('input'); @@ -110,16 +84,13 @@ function editFieldPassWd(id) { inputConfirmPass.classList.add('changeValue'); // Ajouter une classe CSS pour styliser l'input inputConfirmPass.setAttribute('id', 'confirmPassword'); // Ajouter un ID pour la gestion inputConfirmPass.classList.add('inputPasswd'); // Ajouter une classe au input - + inputConfirmPass.name='passwdSecond'; + // Ajouter un bouton de sauvegarde var saveButton = document.createElement('button'); saveButton.textContent = 'Sauvegarder le mot de passe'; saveButton.classList.add('saveButtonPasswd'); // Ajouter une classe au bouton - - saveButton.onclick = function() { - savePasswordFields(id, inputNewPass.value, inputConfirmPass.value); - - }; + saveButton.type="submit"; // Ajouter les deux champs de saisie et le bouton dans l'élément
pElement.appendChild(inputNewPass); @@ -129,30 +100,4 @@ function editFieldPassWd(id) { pElement.appendChild(saveButton); inputNewPass.focus();// Mettre le focus sur le premier champ de saisie -} - - - -function savePasswordFields(id, newPassword, confirmPassword) { - // Vérification si les champs sont vides - if (newPassword.trim() === "" || confirmPassword.trim() === ""){ - alert("Le mot de passe n'a pas changé"); - } - - // Vérification de la correspondance des deux mots de passe - if (newPassword === confirmPassword) { - - var pElement = document.getElementById(id);// Récupérer l'élément
via son identifiant
-
-
-
- // Remplacer les champs input par le texte masqué
- pElement.innerHTML ='Votre mot de passe';
- alert('Mot de passe mis à jour avec succès');
-
- // fonction pour envoyer les nouveaux mots de passe au serveur
-
- } else {
- alert('Les mots de passe ne correspondent pas.');
- }
-}
+}
\ No newline at end of file
diff --git a/public/styles/styleSubmitQuote.css b/public/styles/styleSubmitQuote.css
new file mode 100644
index 0000000..98ee5cd
--- /dev/null
+++ b/public/styles/styleSubmitQuote.css
@@ -0,0 +1,57 @@
+@import url(./style.css);
+
+@import url('https://fonts.googleapis.com/css2?family=Lemon&display=swap');
+
+body, html {
+ height: 100%;
+ overflow: hidden;
+}
+
+/* ====== DARK MODE ====== */
+body.dark-mode h1, body.dark-mode h2, body.dark-mode p {
+ color: white;
+ font-family: "Lemon", serif;
+ text-align: center;
+}
+
+
+/* ====== LIGHT MODE ====== */
+body.light-mode h1, body.light-mode h2, body.light-mode p {
+ color: black;
+ font-family: "Lemon", serif;
+ text-align: center;
+}
+
+
+/* ====== OTHER ====== */
+
+
+
+
+#form {
+ width: 80%;
+ height: 83%;
+ display: flex;
+ justify-content: center;
+ align-items: center;
+}
+
+body.dark-mode #box {
+ background-color: #1b0048;
+ padding: 20px;
+ width: 50%;
+ margin: auto;
+ border-radius: 15px;
+ border: 1px solid #6100ff;
+}
+
+
+/* ====== DIVERS ====== */
+#contentField, #characterField, #sourceField, #imageField {
+}
+
+#contentField p, #characterField p, #sourceField p, #imageField p {
+}
+
+#confirm {
+}
\ No newline at end of file
diff --git a/src/Controleur/FrontControler.php b/src/Controleur/FrontControler.php
index 42fae8d..ab3cb62 100644
--- a/src/Controleur/FrontControler.php
+++ b/src/Controleur/FrontControler.php
@@ -9,11 +9,14 @@ Class FrontControler{
private Connection $co;
+ /**
+ * @throws \Exception
+ */
public function __construct($co){
global $twig,$racine;
$this->listAction = ['visitor' => array('accueil','search','quote','login','signin','validlogin','validsignin'),
- 'user' => array('quiz','commentary','logout','addComment','favorite','profil','addFav','supFav'),
+ 'user' => array('quiz','commentary','logout','addComment','favorite','profil','addFav','supFav','changedata', 'submit', 'validsubmit'),
'admin' => array('null')];
$dVueEreur = [];
@@ -44,9 +47,12 @@ Class FrontControler{
$router->map('GET|POST', '/unlog', 'UserControler','unlog');
$router->map('GET|POST', '/signin', 'VisitorControler','signin');
$router->map('GET|POST', '/validlogin', 'VisitorControler','validlogin');
- $router->map('GET|POST', '/validsignin', 'VisitorControler','validsignin');
+ $router->map('GET|POST', '/validsignin', 'VisitorControler','validsignin');
$router->map('GET|POST', '/addFav/[i:id]', 'UserControler','addFav');
$router->map('GET|POST', '/supFav/[i:id]', 'UserControler','supFav');
+ $router->map('GET|POST', '/changedata', 'UserControler','changedata');
+ $router->map('GET|POST', '/submit', 'UserControler', 'submit');
+ $router->map('GET|POST', '/validsubmit', 'UserControler', 'validsubmit');
$match = $router->match();
diff --git a/src/Controleur/UserControler.php b/src/Controleur/UserControler.php
index e2c09b5..9a1ad92 100644
--- a/src/Controleur/UserControler.php
+++ b/src/Controleur/UserControler.php
@@ -1,26 +1,26 @@
cMod->createComment($_POST['content'],$_POST['idQuote'],$this->uMod->getIdByUsername($_SESSION['user']));
+ $this->cMod->createComment(Verification::verifChar($_POST['content']),
+ Verification::verifChar($_POST['idQuote']),
+ $this->uMod->getIdByUsername(Verification::verifChar($_SESSION['user'])));
header("Location:".$racine."/quote/$id");
}
@@ -81,7 +83,7 @@ class UserControler {
switch ($action) {
case 'canswer':
if ($this->CorrectAnswer())
- $_SESSION['score'] = isset($_SESSION['score']) ? ($_SESSION['score'] + 1) : 1;
+ $_SESSION['score'] = Verification::verifChar( isset( $_SESSION['score']) ? ($_SESSION['score'] + 1) : 1 ) ;
$this->continueQuiz($id, $nb_questions);
break;
default:
@@ -91,8 +93,8 @@ class UserControler {
// page erreur
break;
default:
- $_SESSION['score'] = $_SESSION['score'] ?? 0;
- $this->showQuestion($id, $_SESSION['no_question'] ?? 0);
+ $_SESSION['score'] = Verification::verifChar($_SESSION['score'] ?? 0);
+ $this->showQuestion($id, Verification::verifChar($_SESSION['no_question'] ?? 0));
break;
}
}
@@ -107,9 +109,8 @@ class UserControler {
{
global $racine;
$score = $_SESSION['score'];
- $_SESSION['no_question'] = isset($_SESSION['no_question']) ? ($_SESSION['no_question'] + 1) : 1;
+ $_SESSION['no_question'] = Verification::verifChar( isset($_SESSION['no_question']) ? ($_SESSION['no_question'] + 1) : 1);
if ($_SESSION['no_question'] >= $total_questions) {
- // session_destroy();
$_SESSION['no_question'] = 0;
$this->endQuiz($id_quiz, $score);
}
@@ -137,10 +138,10 @@ class UserControler {
public function CorrectAnswer() : bool
{
- $answera = $_POST['answera'] ?? null;
- $answerb = $_POST['answerb'] ?? null;
- $answerc = $_POST['answerc'] ?? null;
- $answerd = $_POST['answerd'] ?? null;
+ $answera = Verification::verifChar($_POST['answera'] ?? null);
+ $answerb = Verification::verifChar($_POST['answerb'] ?? null);
+ $answerc = Verification::verifChar($_POST['answerc'] ?? null);
+ $answerd = Verification::verifChar($_POST['answerd'] ?? null);
$id= null;
$answer = null;
@@ -178,7 +179,7 @@ class UserControler {
*/
public function showQuestion(int $id, int $num) : void
{
- global $vues;
+ global $vues,$twig;
$q = $this->GetQuestion($id);
$question = $q[$num] ?? $q[0];
$idquestion = $question->getIdQuestion();
@@ -199,7 +200,7 @@ class UserControler {
public function addFav(array $arg){
global $racine;
$id= $arg['id'] ?? 1;
- $this->uMod->addFavorite($_SESSION["user"],$id);
+ $this->uMod->addFavorite(Verification::verifChar($_SESSION["user"]),$id);
header("Location:" . $racine . "/quote/$id");
}
@@ -207,7 +208,145 @@ class UserControler {
public function supFav(array $arg){
global $racine;
$id= $arg['id'] ?? 1;
- $this->uMod->supFavorite($_SESSION["user"],$id);
+ $this->uMod->supFavorite(Verification::verifChar($_SESSION["user"]),$id);
header("Location:". $racine ."/quote/$id");
}
+
+ public function changedata() : void
+ {
+ global $vues, $racine;
+ if ($_POST)
+ {
+ $newImage = $_POST['image'] ?? null;
+ $newPseudo = $_POST['pseudo'] ?? null;
+ $newEmail = $_POST['email'] ?? null;
+ $newMdpFirst = $_POST['passwdFirst'] ?? null;
+ $newMdpSecond = $_POST['passwdSecond'] ?? null;
+
+ //Modif le pseudo
+ if($newPseudo){
+ $user = $this-> uMod->setUsername($_SESSION['user'], $newPseudo);
+ if($user == $newPseudo){ //Si le pseudo existe déjà
+ $_SESSION['user'] = $newPseudo;
+ }
+ }
+
+ else if($newEmail){
+ $user = $this-> uMod->setEmail($_SESSION['user'], $newEmail);
+ }
+
+ else if($newMdpFirst && $newMdpSecond){
+
+ if($newMdpFirst == $newMdpSecond){
+
+ $option = ['cost' => 12];
+ $newPassWd = password_hash($newMdpFirst, PASSWORD_BCRYPT, $option);
+ $user = $this-> uMod->setPassWd($_SESSION['user'], $newPassWd);
+ }
+ }
+
+ else if($newImage){
+ $user = $this->uMod->setImage($_SESSION['user']);
+ }
+ }
+ header("Location: ". $racine."/profil");
+
+ }
+
+ /**
+ * @throws SyntaxError
+ * @throws RuntimeError
+ * @throws LoaderError
+ */
+ public function submit() : void
+ {
+ global $vues;
+ require_once $vues['submitQuote'];
+ }
+
+ /**
+ * @throws SyntaxError
+ * @throws RuntimeError
+ * @throws LoaderError
+ */
+ public function toSubmit() : ?array
+ {
+ global $co;
+ if ($_POST)
+ {
+ $content = $_POST['content'] ?? null;
+ $character = $_POST['character'] ?? null;
+ $source = $_POST['source'] ?? null;
+ //$img = $_POST['img'] ?? null;
+
+ $errors = [null, null];
+
+ $gw = new CharacterGateway($co);
+ $mdl = new CharacterModel($gw);
+
+ $character = $mdl -> getCharacterByName($character);
+
+ $gw = new SourceGateway($co);
+ $mdl = new SourceModel($gw);
+
+ $source = $mdl -> getSourceByTitle($source);
+
+ if (!$character)
+ $errors[0] = "Personnage inexistant";
+ if (!$source)
+ $errors[1] = "Source inexistante";
+ if ($errors[0] || $errors[1])
+ {
+ global $twig;
+ echo $twig->render("submitQuote.html.twig", ['errors' => $errors]);
+ exit();
+ }
+
+ $gw = new QuoteGateway($co);
+ $mdl = new QuoteModel($gw);
+
+ $mdl -> insert4User($content, '/imgPath', 'fr', $this -> getIdOfUser(), $source->getIdSource(), $character->getIdCharacter());
+
+ return [$content, $_POST['character'], $_POST['source']];
+ }
+ return null;
+ }
+
+ /**
+ * @throws SyntaxError
+ * @throws RuntimeError
+ * @throws LoaderError
+ */
+ public function validsubmit() : void
+ {
+ $recap = $this -> toSubmit();
+ if ($recap)
+ {
+ $this -> recapSubmitQuote($recap);
+ }
+ }
+
+ /**
+ * @throws RuntimeError
+ * @throws SyntaxError
+ * @throws LoaderError
+ */
+ public function recapSubmitQuote(?array $recap) : void
+ {
+ global $twig;
+ echo $twig -> render("recapSubmitQuote.html.twig", ['content' => $recap[0], 'character' => $recap[1], 'source' => $recap[2]]);
+ }
+
+ public function getIdOfUser() : ?int
+ {
+ if (isset($_SESSION['user']))
+ {
+ global $co;
+ $gw = new UserGateway($co);
+ $mdl = new UserModel($gw);
+
+ return $mdl -> getUsername($_SESSION['user']) -> getId();
+ }
+ return null;
+ }
}
diff --git a/src/Controleur/VisitorControler.php b/src/Controleur/VisitorControler.php
index a3f8350..99589af 100644
--- a/src/Controleur/VisitorControler.php
+++ b/src/Controleur/VisitorControler.php
@@ -13,6 +13,7 @@ use Twig\Error\LoaderError;
use Twig\Error\RuntimeError;
use Twig\Error\SyntaxError;
+use Verification\Verification;
Class VisitorControler {
@@ -27,6 +28,7 @@ Class VisitorControler {
private array $errors;
+
/**
* @throws SyntaxError
* @throws RuntimeError
@@ -68,9 +70,9 @@ Class VisitorControler {
public function search(array $arg){
global $vues;
- $type = ($_POST['type'] ?? "");
- $search = ( $_POST['search'] ?? NULL);
- $filtre = ($arg['filtre'] ?? []);
+ $type = ( Verification::verifChar( $_POST['type'] ?? ""));
+ $search = ( Verification::verifChar( $_POST['search'] ?? NULL));
+ $filtre = ( Verification::verifArrayChar( $arg['filtre'] ?? []));
$tq=$this->sMod->searchQuote($type,$search,$filtre);
@@ -88,9 +90,9 @@ Class VisitorControler {
global $vues;
require_once $vues['login'];
- // global $twig;
+ //global $twig;
- // echo $twig->render("login.html.twig");
+ //echo $twig->render("login.html.twig");
//$this -> toLogIn();
}
@@ -103,11 +105,14 @@ Class VisitorControler {
public function signin(): void
{
global $vues;
- require_once $vues['signin'];
- }
+ require_once $vues['signin'];
+ //global $twig;
+ //echo $twig->render("login.html.twig");
+ //$this -> signin();
+ }
public function validlogin() : void
@@ -115,8 +120,8 @@ Class VisitorControler {
global $vues,$racine;
if ($_POST)
{
- $pseudo = $_POST['pseudo'] ?? null;
- $mdp = $_POST['mdp'] ?? null;
+ $pseudo = Verification::verifChar($_POST['pseudo'] ?? null);
+ $mdp = Verification::verifChar($_POST['mdp'] ?? null);
$user = $this -> uMod -> getUsername($pseudo);
@@ -124,9 +129,9 @@ Class VisitorControler {
{
if (password_verify($mdp, $user->getPassword()))
{
- $_SESSION['user'] = $pseudo;
+ $_SESSION['user'] = Verification::verifChar($pseudo);
$_SESSION['role'] = 'user';
- header("Location: ". $racine); ///~kekentin/WF/WF-Website/
+ header("Location: ". $racine);
exit();
}else
{
@@ -156,10 +161,10 @@ Class VisitorControler {
global $vues,$racine;
if ($_POST) {
- $pseudo = $_POST['pseudo'] ?? null;
- $email = $_POST['email'] ?? null;
- $mdp = $_POST['mdp'] ?? null;
- $cmdp = $_POST['cmdp'] ?? null;
+ $pseudo = Verification::verifChar($_POST['pseudo'] ?? null);
+ $email = Verification::verifChar($_POST['email'] ?? null);
+ $mdp = Verification::verifChar($_POST['mdp'] ?? null);
+ $cmdp = Verification::verifChar($_POST['cmdp'] ?? null);
if ($mdp != $cmdp) {
$errors[2] = "Mots de passe incorrects";
@@ -191,8 +196,8 @@ Class VisitorControler {
}
else echo $this->uMod->insertUser($pseudo, $email, $hmdp);
- $_SESSION["role"] = 'user';
- $_SESSION["user"] = $pseudo;
+ $_SESSION["role"] = Verification::verifChar('user');
+ $_SESSION["user"] = Verification::verifChar($pseudo);
header("Location: ". $racine);
}
diff --git a/src/Entity/sourceEntity.php b/src/Entity/SourceEntity.php
similarity index 74%
rename from src/Entity/sourceEntity.php
rename to src/Entity/SourceEntity.php
index 8a41c86..48f6ea0 100644
--- a/src/Entity/sourceEntity.php
+++ b/src/Entity/SourceEntity.php
@@ -1,6 +1,8 @@
id_source = $id_source;
$this->title = $title;
$this->date = $date;
+ //$this->type = $type;
}
/**
@@ -69,9 +74,17 @@ class SourceEntity
$this->date = $date;
}
+
+ public function getType(): TypeSourceEnum
+ {
+ return $this->type;
+ }
-
-
+ public function setType(TypeSourceEnum $type): void
+ {
+ $this->type = $type;
+ }
+
}
diff --git a/src/Enum/TypeSourceEnum.php b/src/Enum/TypeSourceEnum.php
new file mode 100644
index 0000000..dbc5bfa
--- /dev/null
+++ b/src/Enum/TypeSourceEnum.php
@@ -0,0 +1,9 @@
+ co -> executeQuery($query, [
- 'id_char' => array($id_character, PDO::PARAM_INT),
- 'name' => array($name, PDO::PARAM_STR),
- 'img_char' => array($img_char, PDO::PARAM_STR)
+ 'id_caracter' => array($id_character, PDO::PARAM_INT),
+ 'caracter' => array($name, PDO::PARAM_STR),
+ 'id_img' => array($img_char, PDO::PARAM_STR)
]);
}
public function findById(int $id) : array
{
- $query = "SELECT * FROM Characters WHERE id_char = :id_c";
+ $query = "SELECT * FROM caracter WHERE id_caracter = :id_c";
$this -> co -> executeQuery($query, ["id_c" => array($id, PDO::PARAM_INT)]);
return $this -> co -> getResults();
}
public function findByName(string $name) : array
{
- $query = "SELECT * FROM Characters WHERE name = :n";
+ $query = "SELECT * FROM caracter WHERE caracter = :n";
$this -> co -> executeQuery($query, ["n" => array($name, PDO::PARAM_STR)]);
return $this -> co -> getResults();
}
public function findAll() : array
{
- $query = "SELECT * FROM Characters";
+ $query = "SELECT * FROM caracter";
$this -> co -> executeQuery($query);
return $this -> co -> getResults();
}
public function delete(int $id) : bool
{
- $query = "DELETE FROM Characters WHERE id_char = :id_c";
+ $query = "DELETE FROM caracter WHERE id_caracter = :id_c";
return $this -> co -> executeQuery($query, ["id_c" => array($id, PDO::PARAM_INT)]);
}
public function update(int $id_char, string $name, string $img_char) : bool
{
$query = "
- UPDATE Characters
- SET name = :n, img_char = :i
- WHERE id_char = :id_c
+ UPDATE caracter
+ SET caracter = :n, id_img = :i
+ WHERE id_caracter = :id_c
";
return $this -> co -> executeQuery($query, [
"id_c" => array($id_char, PDO::PARAM_INT),
- "name" => array($name, PDO::PARAM_STR),
+ "caracter" => array($name, PDO::PARAM_STR),
"i" => array($img_char, PDO::PARAM_STR)
]);
}
diff --git a/src/Gateway/QuoteGateway.php b/src/Gateway/QuoteGateway.php
index c6bdc91..d5ace1f 100644
--- a/src/Gateway/QuoteGateway.php
+++ b/src/Gateway/QuoteGateway.php
@@ -1,22 +1,30 @@
co->executeQuery($query,array(':quote' => array($quote,PDO::PARAM_STR),':page' => array($numpage,PDO::PARAM_INT),':language' => array($language,PDO::PARAM_STR)));
- $result=$this->co->getResults();
- return $result;
+ $query="SELECT q.id_quote, q.content, q.id_caracter, c.img_char, s.title, s.date, q.likes, q.langue
+ FROM Quote q
+ JOIN Source s ON s.id_source = q.id_source
+ WHERE content LIKE '%:quote%' AND is_valid = true AND langue = :langue
+ LIMIT 20 OFFSET :page*20;";
+ $this->co->executeQuery($query,array(':quote' => array($quote,PDO::PARAM_STR),':page' => array($numpage,PDO::PARAM_INT),':langue' => array($language,PDO::PARAM_STR)));
+ return $this->co->getResults();
}
public function searchSource(string $source,int $numpage,string $language):array{
//recherche par source
- $query="SELECT q.id_quote, q.content, c.caracter, c.img_path, s.title, s.date, q.like, q.language FROM Quote q JOIN Caracter c ON c.id_caracter = q.id_caracter JOIN Source s ON s.id_source = q.id_source WHERE s.title LIKE '%:source%' AND q.isValid = true AND language = :language LIMIT 20 OFFSET :page*20;";
- $this->co->executeQuery($query,array(':source' => array($source,PDO::PARAM_STR),':page' => array($numpage,PDO::PARAM_INT),':language' => array($language,PDO::PARAM_STR)));
+ $query="SELECT q.id_quote, q.content, c.character, c.img_path, s.title, s.date, q.likes, q.langue
+ FROM Quote q
+ JOIN Caracter c ON c.id_caracter = q.character
+ JOIN Source s ON s.id_source = q.id_source
+ WHERE s.title LIKE '%:source%' AND q.is_valid = true AND langue = :langue
+ LIMIT 20 OFFSET :page*20;";
+ $this->co->executeQuery($query,array(':source' => array($source,PDO::PARAM_STR),':page' => array($numpage,PDO::PARAM_INT),':langue' => array($language,PDO::PARAM_STR)));
$result=$this->co->getResults();
return $result;
}
@@ -24,8 +32,13 @@ Class QuoteGateway extends Gateway{
public function searchPers(string $Carac,int $numpage,string $language):array{
//recherche par personnage
- $query="SELECT q.id_quote, q.content, c.caracter, c.img_path, s.title, s.date, q.like, q.language FROM Quote q JOIN Caracter c ON c.id_caracter = q.id_caracter JOIN Source s ON s.id_source = q.id_source WHERE c.caracter LIKE '%:pers%' AND q.isValid = true AND language = :language LIMIT 20 OFFSET :page*20;";
- $this->co->executeQuery($query,array(':pers' => array($Pers,PDO::PARAM_STR),':page' => array($numpage,PDO::PARAM_INT),':language' => array($language,PDO::PARAM_STR)));
+ $query="SELECT q.id_quote, q.content, c.character, c.img_path, s.title, s.date, q.likes, q.langue
+ FROM Quote q
+ JOIN Caracter c ON c.id_caracter = q.character
+ JOIN Source s ON s.id_source = q.id_source
+ WHERE c.character LIKE '%:pers%' AND q.is_valid = true AND langue = :langue
+ LIMIT 20 OFFSET :page*20;";
+ $this->co->executeQuery($query,array(':pers' => array($Pers,PDO::PARAM_STR),':page' => array($numpage,PDO::PARAM_INT),':langue' => array($language,PDO::PARAM_STR)));
$result=$this->co->getResults();
return $result;
}
@@ -33,7 +46,12 @@ Class QuoteGateway extends Gateway{
public function searchId(string $id):array{
//recherche par id
- $query="SELECT q.id_quote, q.content, c.caracter, i.imgPath, s.title, s.dates, q.likes, q.langue FROM Quote q JOIN Caracter c ON c.id_caracter = q.id_caracter JOIN Source s ON s.id_source = q.id_source JOIN Image i ON c.id_img = i.id_img WHERE q.id_quote = :id AND q.isvalide = true;";
+ $query="SELECT q.id_quote, q.content, c.caracter, i.imgPath, s.title, s.dates, q.likes, q.langue
+ FROM Quote q
+ JOIN Caracter c ON c.id_caracter = q.id_caracter
+ JOIN Source s ON s.id_source = q.id_source
+ JOIN Image i ON c.id_img = i.id_img
+ WHERE q.id_quote = :id AND q.isvalide = true;";
$this->co->executeQuery($query,array(':id' => array($id,PDO::PARAM_STR)));
$result=$this->co->getResults();
return $result;
@@ -46,7 +64,7 @@ Class QuoteGateway extends Gateway{
JOIN Source s ON s.id_source = q.id_source
JOIN Image i ON c.id_img = i.id_img
WHERE lower(";
-
+
if($type=='personnage'){
$query = $query . "c.caracter) LIKE lower('%" . $search . "%')";
}
@@ -62,21 +80,21 @@ Class QuoteGateway extends Gateway{
}*/
$this->co->executeQuery($query,array());
-
+
$result=$this->co->getResults();
return $result;
}
public function getQuoteOfTheDay(string $language): array {
$query = "SELECT q.id_quote, q.content, c.caracter, i.imgPath, s.title, s.dateS, q.likes, q.langue
- FROM DailyQuote dq
- JOIN Quote q ON dq.citation_id = q.id_quote
- JOIN Caracter c ON c.id_caracter = q.id_caracter
- JOIN Source s ON s.id_source = q.id_source
- JOIN Image i ON c.id_img = i.id_img
- WHERE q.isValide = true AND q.langue = :language
- ORDER BY q.id_quote DESC
- LIMIT 1;";
+ FROM DailyQuote dq
+ JOIN Quote q ON dq.citation_id = q.id_quote
+ JOIN Caracter c ON c.id_caracter = q.id_caracter
+ JOIN Source s ON s.id_source = q.id_source
+ JOIN Image i ON c.id_img = i.id_img
+ WHERE q.isValide = true AND q.langue = :language
+ ORDER BY q.id_quote DESC
+ LIMIT 1;";
try {
$this->co->executeQuery($query, [':language' => [$language, PDO::PARAM_STR]]);
$result = $this->co->getResults();
@@ -85,9 +103,9 @@ Class QuoteGateway extends Gateway{
echo "Erreur dans getQuoteOfTheDay: " . $e->getMessage();
return [];
}
- }
+ }
+
-
public function getSuggestions(int $numpage, string $language): array {
$query = "SELECT q.id_quote, q.content, c.caracter, i.imgPath, s.title, s.dateS, q.likes, q.langue
@@ -126,6 +144,32 @@ Class QuoteGateway extends Gateway{
}
}
+ public function autoincrement() : int
+ {
+ $query = "SELECT Max(id_quote) + 1 as id FROM Quote;";
+ $this->co->executeQuery($query);
+ return ($this -> co ->getResults())[0]['id'];
+ }
+
+ public function insert4User(string $content, string $img_path, string $langage, int $user, int $source, int $character) : bool
+ {
+ $query = "
+ INSERT INTO Quote (id_quote, content, langue, reason, id_source, id_caracter, id_user_verif, img_path)
+ VALUES (:id, :content, :langage, :reason, :source, :character, :user, :img_path)
+ ";
+
+ return $this->co->executeQuery($query, [
+ ':id' => array($this->autoincrement(), PDO::PARAM_INT),
+ ':content' => array($content, PDO::PARAM_STR),
+ ':img_path' => array($img_path, PDO::PARAM_STR),
+ ':langage' => array($langage, PDO::PARAM_STR),
+ ':user' => array($user, PDO::PARAM_INT),
+ ':reason' => array('À vérifier', PDO::PARAM_STR),
+ ':source' => array($source, PDO::PARAM_STR),
+ ':character' => array($character, PDO::PARAM_STR)
+ ]);
+ }
+
//======================== PARTI ADMIN ========================
//Probablement à déplacer dans un autre fichier
@@ -133,8 +177,7 @@ Class QuoteGateway extends Gateway{
//obtenir les quotes en attentes de validation par l'admin
$query = 'SELECT * FROM Quote WHERE isValid=:bool';
$this->co->executeQuery($query,array(':bool' => array(false, PDO::PARAM_BOOL)));
- $result=$this->co->getResults();
- return $result;
+ return $this->co->getResults();
}
public function validQuote(int $id){
@@ -152,61 +195,56 @@ Class QuoteGateway extends Gateway{
public function updateContent(int $id, string $newContent):array{
//Update le contexte de quote passé en paramètre
$queryUpdate = 'UPDATE Quote SET content=:newContent WHERE id_quote=:idQuote';
- $con->executeQuery($queryUpdate, array(':idQuote'=>array($id, PDO::PARAM_STR), ':newContent'=> array($newContent, PDO::PARAM_STR)));
+ $this->co->executeQuery($queryUpdate, array(':idQuote'=>array($id, PDO::PARAM_STR), ':newContent'=> array($newContent, PDO::PARAM_STR)));
//Renvoie le nouveau contexte de quote
- $queryReponse = 'SELECT content FROM Quote WHERE id_quote=:idQuote';
- $con->executeQuery($queryReponse, array(':idQuote'=>array($id, PDO::PARAM_STR)));
- $result = $con->getResults();
- return $result;
+ $queryReponse = 'SELECT content FROM Quote WHERE id_quote=:idQuote';
+ $this->co->executeQuery($queryReponse, array(':idQuote'=>array($id, PDO::PARAM_STR)));
+ return $this->co->getResults();
}
public function updateTimeCode(int $id, string $newTimeCode):array{
//Update le time code de quote passé en paramètre
$queryUpdate = 'UPDATE Quote SET timecode=:newTimeCode WHERE id_quote=:idQuote';
- $con->executeQuery($queryUpdate, array(':idQuote'=>array($id, PDO::PARAM_STR), ':newTimeCode'=> array($newTimeCode, PDO::PARAM_STR)));
+ $this->co->executeQuery($queryUpdate, array(':idQuote'=>array($id, PDO::PARAM_STR), ':newTimeCode'=> array($newTimeCode, PDO::PARAM_STR)));
//Renvoie le nouveau contexte de quote
- $queryReponse = 'SELECT timecode FROM Quote WHERE id_quote=:idQuote';
- $con->executeQuery($queryReponse, array(':idQuote'=>array($id, PDO::PARAM_STR)));
- $result = $con->getResults();
- return $result;
+ $queryReponse = 'SELECT timecode FROM Quote WHERE id_quote=:idQuote';
+ $this->co->executeQuery($queryReponse, array(':idQuote'=>array($id, PDO::PARAM_STR)));
+ return $this->co->getResults();
}
public function updateDate(int $id, int $newDate):array{
//Update la date de quote passé en paramètre
$queryUpdate = 'UPDATE Source SET dateSource =:newdate WHERE idSource = (SELECT idSource FROM Quote WHERE idQuote =:idQuote)';
- $con->executeQuery($queryUpdate, array(':idQuote'=>array($id, PDO::PARAM_STR), ':newDate'=> array($newDate, PDO::PARAM_INT)));
+ $this->co->executeQuery($queryUpdate, array(':idQuote'=>array($id, PDO::PARAM_STR), ':newDate'=> array($newDate, PDO::PARAM_INT)));
//Renvoie la nouvelle date de quote
- $queryReponse = 'SELECT s.dateSource FROM Source s, Quote q WHERE id_quote=:idQuote AND s.idSource = q.idSource';
- $con->executeQuery($queryReponse, array(':idQuote'=>array($id, PDO::PARAM_STR)));
- $result = $con->getResults();
- return $result;
+ $queryReponse = 'SELECT s.dateSource FROM Source s, Quote q WHERE id_quote=:idQuote AND s.idSource = q.idSource';
+ $this->co->executeQuery($queryReponse, array(':idQuote'=>array($id, PDO::PARAM_STR)));
+ return $this->co->getResults();
}
public function updateTitle(int $id, string $newTitle):array{
//Update le titre de l'oeuvre de quote passé en paramètre
$queryUpdate = 'UPDATE Source SET title =:newTitle WHERE idSource = (SELECT idSource FROM Quote WHERE idQuote =:idQuote)';
- $con->executeQuery($queryUpdate, array(':idQuote'=>array($id, PDO::PARAM_STR), ':newTitle'=> array($newTitle, PDO::PARAM_STR)));
+ $this->co->executeQuery($queryUpdate, array(':idQuote'=>array($id, PDO::PARAM_STR), ':newTitle'=> array($newTitle, PDO::PARAM_STR)));
//Renvoie le nouveau titre de quote
- $queryReponse = 'SELECT s.title FROM Source s, Quote q WHERE id_quote=:idQuote AND s.idSource = q.idSource';
- $con->executeQuery($queryReponse, array(':idQuote'=>array($id, PDO::PARAM_STR)));
- $result = $con->getResults();
- return $result;
+ $queryReponse = 'SELECT s.title FROM Source s, Quote q WHERE id_quote=:idQuote AND s.idSource = q.idSource';
+ $this->co->executeQuery($queryReponse, array(':idQuote'=>array($id, PDO::PARAM_STR)));
+ return $this->co->getResults();
}
public function updateNameCharacter(int $id, string $newNameCharacter):array{
//Update le personnage de l'oeuvre de quote passé en paramètre
$queryUpdate = 'UPDATE Character SET name =:newNameCharacter WHERE idCharacter = (SELECT idCharacter FROM Quote WHERE idQuote =:idQuote)';
- $con->executeQuery($queryUpdate, array(':idQuote'=>array($id, PDO::PARAM_STR), ':newNameCharacter'=> array($newNameCharacter, PDO::PARAM_STR)));
+ $this->co->executeQuery($queryUpdate, array(':idQuote'=>array($id, PDO::PARAM_STR), ':newNameCharacter'=> array($newNameCharacter, PDO::PARAM_STR)));
//Renvoie le nouveau personnage de quote
- $queryReponse = 'SELECT c.title FROM Character c, Quote q WHERE id_quote=:idQuote AND c.idCharacter = q.idCharacter';
- $con->executeQuery($queryReponse, array(':idQuote'=>array($id, PDO::PARAM_STR)));
- $result = $con->getResults();
- return $result;
+ $queryReponse = 'SELECT c.title FROM Character c, Quote q WHERE id_quote=:idQuote AND c.idCharacter = q.idCharacter';
+ $this->co->executeQuery($queryReponse, array(':idQuote'=>array($id, PDO::PARAM_STR)));
+ return $this->co->getResults();
}
}
diff --git a/src/Gateway/sourceGateway.php b/src/Gateway/SourceGateway.php
similarity index 68%
rename from src/Gateway/sourceGateway.php
rename to src/Gateway/SourceGateway.php
index a746ec8..ed540b3 100644
--- a/src/Gateway/sourceGateway.php
+++ b/src/Gateway/SourceGateway.php
@@ -1,20 +1,22 @@
co -> executeQuery($query, [
- "id_source" => array($s->getIdSource(), PDO::PARAM_INT),
"title" => array($s->getTitle(), PDO::PARAM_STR),
- "date" => array($s->getDate(), PDO::PARAM_STR)
+ "date" => array($s->getDate(), PDO::PARAM_STR),
+ "type" => array($s->getType(), PDO::PARAM_STR)
]);
}
@@ -30,7 +32,7 @@ class SourceGateway extends Gateway{
{
$query = "SELECT * FROM Source WHERE title = :t";
- $this -> co -> executeQuery($query, ["title" => array($t, PDO::PARAM_STR)]);
+ $this -> co -> executeQuery($query, ["t" => array($t, PDO::PARAM_STR)]);
return $res = $this -> co -> getResults();
// if ($res)
@@ -44,19 +46,21 @@ class SourceGateway extends Gateway{
public function findByDate(string $d) : array
{
- $query = "SELECT * FROM Source WHERE date = :d";
+ $query = "SELECT * FROM Source WHERE dates = :d";
- $this -> co -> executeQuery($query, ["date" => array($d, PDO::PARAM_STR)]);
- $res = $this -> co -> getResults();
+ $this -> co -> executeQuery($query, ["d" => array($d, PDO::PARAM_STR)]);
+ return $this -> co -> getResults();
+ }
+
+ /*
+ public function findByType(TypeSourceEnum $type) : array
+ {
+ $query = "SELECT * FROM Source WHERE type = :t";
- if ($res)
- return new sourceEntity(
- $res["id_source"],
- $res["title"],
- $res["date"]
- );
- return null;
+ $this -> co -> executeQuery($query, ["t" => array($type, PDO::PARAM_STR)]);
+ return $this -> co -> getResults();
}
+ */
public function findAll() : array
{
@@ -71,7 +75,8 @@ class SourceGateway extends Gateway{
$sources[] = new sourceEntity(
$source["id_source"],
$source["title"],
- $source["date"]
+ $source["date"],
+ TypeSourceEnum::Movie//$res["source"]
);
}
return $sources;
diff --git a/src/Gateway/UserGateway.php b/src/Gateway/UserGateway.php
index a211518..450feb0 100644
--- a/src/Gateway/UserGateway.php
+++ b/src/Gateway/UserGateway.php
@@ -70,7 +70,7 @@ Class UserGateway extends Gateway{
//obtenir les information d'un user
public function findDataUser(int $id):array{
- $query = 'SELECT * FROM Users WHERE id_user=:idUser';
+ $query = 'SELECT u.id_user , u.username , u.email , u.password , i.imgPath , u.creation FROM Users WHERE id_user=:idUser';
$this->co->executeQuery($query, array(':idUser'=>array($id, PDO::PARAM_STR)));
$result = $this->co->getResults();
return $result;
@@ -78,7 +78,7 @@ Class UserGateway extends Gateway{
// obtenir les informations d'un user selon son pseudo
public function findUsername(string $username):array{
- $query = 'SELECT u.id_user , u.username , u.email , u.password , i.imgPath , u.creation FROM Users u Join Image i on i.id_img=u.img WHERE username= :username';
+ $query = 'SELECT * FROM Users u Join Image i on i.id_img=u.img WHERE username= :username';
$this->co->executeQuery($query, array(':username'=>array($username, PDO::PARAM_STR)));
return $this->co->getResults();
}
@@ -89,47 +89,76 @@ Class UserGateway extends Gateway{
return $this->co->getResults();
}
+ public function IsExisteUsername(string $username): bool {
+ $query = 'SELECT COUNT(*) as count FROM Users WHERE username = :username';
+ $this->co->executeQuery($query, array(':username' => array($username, PDO::PARAM_STR)));
+ $results = $this->co->getResults();
+
+ return $results[0]['count'] > 0; // retourne true si "count" > 0)
+ }
+
+ public function IsExisteEmail(string $email): bool {
+ $query = 'SELECT COUNT(*) as count FROM Users WHERE email = :email';
+ $this->co->executeQuery($query, array(':email' => array($email, PDO::PARAM_STR)));
+ $results = $this->co->getResults();
+
+ return $results[0]['count'] > 0; // retourne true si "count" > 0)
+ }
+
// ===================== UPDATE FUNCTION =====================
- public function updateUsername(int $id, string $newUsername):bool{
+ //Update Username
+ public function updateUsername(string $username, string $newUsername):array{
//Update le nom du user passé en paramètre
- $queryUpdate = 'UPDATE Users SET username=:newUsername WHERE id_user=:idUser';
- $this->co->executeQuery($queryUpdate, array(':idUser'=>array($id, PDO::PARAM_STR), ':newUsername'=> array($newUsername, PDO::PARAM_STR)));
+ $queryUpdate = 'UPDATE Users SET username=:newUsername WHERE username=:username';
+ $this->co->executeQuery($queryUpdate, array(':username'=>array($username, PDO::PARAM_STR), ':newUsername'=> array($newUsername, PDO::PARAM_STR)));
//Renvoie le nouveau nom du user
- $queryReponse = 'SELECT username FROM Users WHERE id_user=:idUser';
+ $queryReponse = 'SELECT username FROM Users WHERE username=:idUser';
- return $this->co->executeQuery($queryReponse, array($id=>array($newUsername, PDO::PARAM_STR)));
+ $this->co->executeQuery($queryReponse, array(':idUser'=>array($newUsername, PDO::PARAM_STR)));
+ return $this->co->getResults();
}
- public function updateEmail(int $id, string $newEmail):bool{
+
+ //Update Email
+ public function updateEmail(string $username, string $newEmail):array{
//Update le email du user passé en paramètre
- $queryUpdate = 'UPDATE Users SET email=:newEmail WHERE id_user=:idUser';
- $this->co->executeQuery($queryUpdate, array(':idUser'=>array($id, PDO::PARAM_STR), ':newEmail'=> array($newEmail, PDO::PARAM_STR)));
+ $queryUpdate = 'UPDATE Users SET email=:newEmail WHERE username=:username';
+ $this->co->executeQuery($queryUpdate, array(':username'=>array($username, PDO::PARAM_STR), ':newEmail'=> array($newEmail, PDO::PARAM_STR)));
//Renvoie le nouveau email du user
- $queryReponse = 'SELECT email FROM Users WHERE id_user=:idUser';
- return $this->co->executeQuery($queryReponse, array(':idUser'=>array($id, PDO::PARAM_STR)));
+ $queryReponse = 'SELECT email FROM Users WHERE username=:username';
+
+ $this->co->executeQuery($queryReponse, array(':username'=>array($username, PDO::PARAM_STR)));
+ return $this->co->getResults();
}
- public function updateImg(int $id, int $newImg):array{
+
+
+ public function updateImg(string $username):array{
+ $id_image = $this->randomImg();
//Update l'image du user passé en paramètre
- $query = 'UPDATE Users SET img_prfl=:newImg WHERE id_user=:idUser';
- $this->co->executeQuery($query, array(':idUser'=>array($id, PDO::PARAM_STR), ':newImg'=> array($newImg, PDO::PARAM_STR)));
+ $query = 'UPDATE Users SET img=:id_image WHERE username=:username';
+ $this->co->executeQuery($query, array(':username'=>array($username, PDO::PARAM_STR), ':id_image'=> array($id_image, PDO::PARAM_INT)));
//Renvoie la nouvelle image du user
- $queryReponse = 'SELECT img_prfl FROM Users WHERE id_user=:idUser';
- $this->co->executeQuery($queryReponse, array(':idUser'=>array($id, PDO::PARAM_STR)));
- $result = $this->co->getResults();
- return $result;
+ $queryReponse = 'SELECT img FROM Users WHERE username=:username';
+ $this->co->executeQuery($queryReponse, array(':username'=>array($username, PDO::PARAM_STR)));
+ return $this->co->getResults();
}
- public function updatePasswd(int $id, string $newPassWd):array{
+
+ public function updatePasswd(string $username, string $newPassWd):void{
//Update le passwd du user passé en paramètre
- $query = 'UPDATE Users SET pssword=:newPassWd WHERE id_user=:idUser';
- $this->co->executeQuery($query, array(':idUser'=>array($id, PDO::PARAM_STR), ':newPassWd'=> array($newPassWd, PDO::PARAM_STR)));
+ $query = 'UPDATE Users SET password=:newPassWd WHERE username=:username';
+ $this->co->executeQuery($query, array(':username'=>array($username, PDO::PARAM_STR), ':newPassWd'=> array($newPassWd, PDO::PARAM_STR)));
}
+
+
+
+
public function getIdUser(string $username):array{
$query = 'SELECT id_user FROM Users WHERE username=:username';
$this->co->executeQuery($query, array(':username'=>array($username, PDO::PARAM_STR)));
diff --git a/src/Model/CharacterModel.php b/src/Model/CharacterModel.php
index 53eb21c..fa1e074 100644
--- a/src/Model/CharacterModel.php
+++ b/src/Model/CharacterModel.php
@@ -19,9 +19,9 @@ class CharacterModel extends Model
$c = $this -> gateway -> findById($id_character);
if ($c)
return new CharacterEntity(
- $c['id_character'],
- $c['name'],
- $c['img_path']
+ $c['id_caracter'],
+ $c['caracter'],
+ $c['id_img']
);
return null;
}
@@ -31,9 +31,9 @@ class CharacterModel extends Model
$c = $this -> gateway -> findByName($name);
if ($c)
return new CharacterEntity(
- $c[0]['id_character'],
- $c[0]['name'],
- $c[0]['img_path']
+ $c[0]['id_caracter'],
+ $c[0]['caracter'],
+ $c[0]['id_img']
);
return null;
}
@@ -47,9 +47,9 @@ class CharacterModel extends Model
foreach ($c as $character)
{
$characters[] = new CharacterEntity(
- $character['id_character'],
- $character['name'],
- $character['img_path']
+ $character['id_caracter'],
+ $character['caracter'],
+ $character['id_img']
);
}
return $characters;
diff --git a/src/Model/QuoteModel.php b/src/Model/QuoteModel.php
index 7d1af63..b0bcff3 100644
--- a/src/Model/QuoteModel.php
+++ b/src/Model/QuoteModel.php
@@ -45,6 +45,12 @@
}
return $tabQ;
}
+
+ public function insert4User(string $content, string $img_path, string $langage, int $user, int $source, int $character) : bool
+ {
+ return $this->gateway->insert4User($content, $img_path, $langage, $user, $source, $character);
+ }
+
}
?>
diff --git a/src/Model/UserModel.php b/src/Model/UserModel.php
index 41cffc0..5f2a99d 100644
--- a/src/Model/UserModel.php
+++ b/src/Model/UserModel.php
@@ -76,39 +76,60 @@
return null;
}
- public function setUsername(int $id, string $newUsername){
- $res = $this->gateway->updateUsername($id,$newUsername);
- $src[] = $res[0]['username'];
+ public function IsExisteUsername(string $username):bool{
+ return $this->gateway->IsExisteUsername($username);
+ }
- return $src;
+ public function IsExisteEmail(string $email):bool{
+ return $this->gateway->IsExisteEmail($email);
}
- public function setEmail(int $id, string $newEmail){
- $res = $this->gateway->updateEmail($id,$newEmail);
- $src[] = $res[0]['email'];
- return $src;
+ public function setUsername(string $username, string $newUsername): string {
+
+ if ($this->IsExisteUsername($newUsername)) {// Vérifier si le nouveau nom d'utilisateur existe déjà
+ return $username;// Retourne l'ancien nom d'utilisateur sans modification
+ }
+
+ $res = $this->gateway->updateUsername($username, $newUsername);// Sinon, mettre à jour le nom d'utilisateur
+
+ // Retourner le nouveau nom d'utilisateur après modification
+ if (!empty($res) && isset($res[0]['username'])) {
+ return $res[0]['username'];
+ }
+
+ // En cas d'échec, retourne l'ancien nom d'utilisateur
+ return $username;
}
+
- public function setImg(int $id, int $newImg){
- $res = $this->gateway->updateImg($id,$newImg);
- $src[] = $res[0]['img'];
+ public function setEmail(string $username, string $newEmail){
+ if ($this->IsExisteEmail($newEmail)) {
+ return $email;
+ }
- return $src;
+ $res = $this->gateway->updateEmail($username,$newEmail);
+
+ if (!empty($res) && isset($res[0]['email'])) {
+ return $res[0]['email'];
+ }
+
+ return $username;// En cas d'échec, retourne l'ancien email
}
- public function setPassWd(int $id, string $newPassWd){
- $res = $this->gateway->updatePasswd($id,$newPassWd);
- $src[] = $res[0]['pssword'];
+ public function setImage(string $username){
+ $res = $this->gateway->updateImg($username);
+ $src[] = $res[0]['img'];
return $src;
}
- public function getIdByUsername(string $username){
- $res = $this->gateway->getIdUser($username);
- return $res[0]['id_user'];
+ public function setPassWd(string $username, string $newPassWd):void{
+ $res = $this->gateway->updatePasswd($username,$newPassWd);
}
+
+
public function isFavorite(?string $username, int $idq): bool {
if($_SESSION["user"] == NULL){
return false;
@@ -119,6 +140,7 @@
}
}
+
public function addFavorite(string $username, int $id){
$this->gateway->addFavorite($username,$id);
}
@@ -126,6 +148,11 @@
public function supFavorite(string $username, int $id){
$this->gateway->supFavorite($username,$id);
}
+
+ public function getIdByUsername(string $username){
+ $res = $this->gateway->getIdUser($username);
+ return $res[0]['id_user'];
+ }
}
?>
diff --git a/src/Model/sourceModel.php b/src/Model/sourceModel.php
index 9430baa..baf1c37 100644
--- a/src/Model/sourceModel.php
+++ b/src/Model/sourceModel.php
@@ -1,17 +1,17 @@
gateway -> create($q);
+
}
public function getSourceById(int $id_source) : ?SourceEntity
@@ -22,40 +22,68 @@ class SourceModel extends Model
return new sourceEntity(
$res[0]["id_source"],
$res[0]["title"],
- $res[0]["date"]
+ $res[0]["dates"],
+ TypeSourceEnum::Movie//from($res[0]["type"])
);
return null;
}
- public function getSourceByTitle(string $title) : array
+ public function getSourceByTitle(string $title) : ?SourceEntity
{
$res = $this->gateway->findByTitle($title);
+ if ($res)
+ return new sourceEntity(
+ $res[0]["id_source"],
+ $res[0]["title"],
+ $res[0]["dates"],
+ TypeSourceEnum::Movie//from($res[0]["type"])
+ );
+ return null;
+ }
+
+ public function getSourceByDate(string $date) : array
+ {
+ $res = $this->gateway->findByDate($date);
+ $src = [];
foreach ($res as $sources) {
$src[] = new sourceEntity(
- $sources["id_source"],
- $sources["title"],
- $sources["date"]
- );
+ $sources["id_source"],
+ $sources["title"],
+ $sources["dates"],
+ TypeSourceEnum::from($sources["type"])
+ );
}
return $src;
}
- public function getSourceByDate(string $date) : array
+ public function getSourceByType(TypeSourceEnum $type) : array
{
- $res = $this->gateway->findByDate($date);
+ $res = $this->gateway->findByType($type);
+ $src = [];
foreach ($res as $sources) {
$src[] = new sourceEntity(
- $sources["id_source"],
- $sources["title"],
- $sources["date"]
- );
+ $sources["id_source"],
+ $sources["title"],
+ $sources["dates"],
+ TypeSourceEnum::from($sources["type"])
+ );
}
return $src;
}
- public function getSources() : array
+ public function getAllSources() : array
{
- return $this -> gateway -> findAll();
+ $res = $this -> gateway -> findAll();
+ $src = [];
+ foreach ($res as $sources) {
+ $src[] = new sourceEntity(
+ $sources["id_source"],
+ $sources["title"],
+ $sources["dates"],
+ TypeSourceEnum::from($sources["type"])
+ );
+ }
+ return $src;
}
public function deleteSource(int $id_source) : bool
diff --git a/src/Verification/Verification.php b/src/Verification/Verification.php
index a607afa..a849265 100644
--- a/src/Verification/Verification.php
+++ b/src/Verification/Verification.php
@@ -1,18 +1,44 @@
','(',')'];
+ $chaineInterdi=["AND","OR","WHERE","FROM","SELECT"];
+ $textVerif="";
+
+ foreach( str_split($text,1) as $char){
+ if( !in_array($char,$charInterdi) ){
+ $textVerif=$textVerif.$char;
+ }
+ }
+
+ $text=$textVerif;
+ $textVerif="";
+ $tabText=explode(" ",$text);
+ for( $i=0 ; $i
▶ Profil ◀
+
+
+
+
-
+
Contenu *
+Personnage *
+Source *
+diff --git a/vue/templates/recapSubmitQuote.html.twig b/vue/templates/recapSubmitQuote.html.twig new file mode 100644 index 0000000..d542dd3 --- /dev/null +++ b/vue/templates/recapSubmitQuote.html.twig @@ -0,0 +1,51 @@ + + +
+ + +
+ + + + + +
+