|
|
|
@ -21,6 +21,8 @@ use Twig\Error\RuntimeError;
|
|
|
|
|
use Twig\Error\SyntaxError;
|
|
|
|
|
use Verification\Verification;
|
|
|
|
|
use Enum\TypeSourceEnum;
|
|
|
|
|
use Model\ImageModel;
|
|
|
|
|
use Gateway\ImageGateway;
|
|
|
|
|
|
|
|
|
|
class UserControler {
|
|
|
|
|
|
|
|
|
@ -30,6 +32,7 @@ class UserControler {
|
|
|
|
|
private CharacterModel $caMod;
|
|
|
|
|
private SourceModel $srcMod;
|
|
|
|
|
private QuestionModel $questMod;
|
|
|
|
|
private ImageModel $iMod;
|
|
|
|
|
|
|
|
|
|
public function __construct() {
|
|
|
|
|
global $co;
|
|
|
|
@ -39,6 +42,7 @@ class UserControler {
|
|
|
|
|
$this -> questMod = new QuestionModel(new QuestionGateway($co));
|
|
|
|
|
$this -> caMod = new CharacterModel(new CharacterGateway($co));
|
|
|
|
|
$this->srcMod = new SourceModel(new SourceGateway($co));
|
|
|
|
|
$this->iMod = new ImageModel(new ImageGateway($co));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function profil() {
|
|
|
|
@ -337,47 +341,23 @@ class UserControler {
|
|
|
|
|
* @throws RuntimeError
|
|
|
|
|
* @throws LoaderError
|
|
|
|
|
*/
|
|
|
|
|
public function toSubmit() : ?array
|
|
|
|
|
public function toSubmit(string $content,string $character, string $source)
|
|
|
|
|
{
|
|
|
|
|
global $co;
|
|
|
|
|
if ($_POST)
|
|
|
|
|
{
|
|
|
|
|
$content = $_POST['content'] ?? null;
|
|
|
|
|
$character = $_POST['character'] ?? null;
|
|
|
|
|
$source = $_POST['src'] ?? null;
|
|
|
|
|
//$img = $_POST['img'] ?? null;
|
|
|
|
|
|
|
|
|
|
$errors = [null, null];
|
|
|
|
|
|
|
|
|
|
$gw = new CharacterGateway($co);
|
|
|
|
|
$mdl = new CharacterModel($gw);
|
|
|
|
|
|
|
|
|
|
$character = $mdl -> getCharacterById($character);
|
|
|
|
|
|
|
|
|
|
$gw = new SourceGateway($co);
|
|
|
|
|
$mdl = new SourceModel($gw);
|
|
|
|
|
|
|
|
|
|
$source = $mdl -> getSourceById($source);
|
|
|
|
|
$nameSrc = $this->srcMod->getSourceById($source)->getTitle();
|
|
|
|
|
$nameChar = $this->caMod->getCharacterById($character)->getName();
|
|
|
|
|
|
|
|
|
|
if (!$character)
|
|
|
|
|
$errors[0] = "Personnage inexistant";
|
|
|
|
|
if (!$source)
|
|
|
|
|
$errors[1] = "Source inexistante";
|
|
|
|
|
if ($errors[0] || $errors[1])
|
|
|
|
|
{
|
|
|
|
|
global $twig;
|
|
|
|
|
$this->submit();
|
|
|
|
|
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['src']];
|
|
|
|
|
$this -> qMod -> addQuote($content,'fr',$character,$source,$this->uMod->getIdByUsername(Verification::VerifChar($_SESSION['user'])));
|
|
|
|
|
$this -> recapSubmitQuote(array('content' => $content, 'src' => $nameSrc, 'character' => $nameChar));
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -391,6 +371,8 @@ class UserControler {
|
|
|
|
|
global $vues;
|
|
|
|
|
$src = true;
|
|
|
|
|
$char = true;
|
|
|
|
|
$srcId = null;
|
|
|
|
|
$charId = null;
|
|
|
|
|
require_once $vues['create'];
|
|
|
|
|
exit();
|
|
|
|
|
}
|
|
|
|
@ -398,6 +380,8 @@ class UserControler {
|
|
|
|
|
global $vues;
|
|
|
|
|
$src = true;
|
|
|
|
|
$char = false;
|
|
|
|
|
$srcId = null;
|
|
|
|
|
$charId = $_POST['character'];
|
|
|
|
|
require_once $vues['create'];
|
|
|
|
|
exit();
|
|
|
|
|
}
|
|
|
|
@ -405,32 +389,23 @@ class UserControler {
|
|
|
|
|
global $vues;
|
|
|
|
|
$src = false;
|
|
|
|
|
$char = true;
|
|
|
|
|
$srcId = $_POST['src'];
|
|
|
|
|
$charId = null;
|
|
|
|
|
require_once $vues['create'];
|
|
|
|
|
exit();
|
|
|
|
|
}
|
|
|
|
|
if($_POST)
|
|
|
|
|
$recap = $this -> toSubmit();
|
|
|
|
|
if ($recap)
|
|
|
|
|
{
|
|
|
|
|
$this -> recapSubmitQuote($recap);
|
|
|
|
|
}
|
|
|
|
|
$recap = $this -> toSubmit($_POST['content'],$_POST['character'],$_POST['src']);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function recapSubmitQuote(array $recap){
|
|
|
|
|
global $vues;
|
|
|
|
|
require_once($vues["recap"]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ===================== SUBMIT QUOTE FUNCTION =====================
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @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']))
|
|
|
|
@ -445,15 +420,17 @@ class UserControler {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function add(){
|
|
|
|
|
global $vues;
|
|
|
|
|
global $vues, $repImg;
|
|
|
|
|
$error = [];
|
|
|
|
|
$src = false;
|
|
|
|
|
$char = false;
|
|
|
|
|
var_dump($_FILES);
|
|
|
|
|
if($_POST['req'] == "both"){
|
|
|
|
|
$src = true;
|
|
|
|
|
$char = true;
|
|
|
|
|
}
|
|
|
|
|
elseif($_POST['req'] == "src" or $src == true){
|
|
|
|
|
$src = true;
|
|
|
|
|
$char = false;
|
|
|
|
|
|
|
|
|
|
if($_POST['req'] == "src" or $src == true){
|
|
|
|
|
$type = array("movie","serie","video-game","anime");
|
|
|
|
|
if(Verification::verifNotNull($_POST["titre"])){
|
|
|
|
|
$_POST["titre"] = Verification::verifChar($_POST["titre"]);
|
|
|
|
@ -465,8 +442,6 @@ class UserControler {
|
|
|
|
|
$error[] = "Le titre doit être définit";
|
|
|
|
|
}
|
|
|
|
|
if(Verification::verifNotNull($_POST["date"])){
|
|
|
|
|
$src = true;
|
|
|
|
|
$char = false;
|
|
|
|
|
$_POST["date"] = Verification::verifChar($_POST["date"]);
|
|
|
|
|
if(intval($_POST["date"],10) < 1850 or intval($_POST["date"],10) > date( "Y", time() )){
|
|
|
|
|
$error[] = "La date est invalide";
|
|
|
|
@ -485,24 +460,57 @@ class UserControler {
|
|
|
|
|
$error[] = "Le type doit être définit";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
elseif($_POST['req'] == "char" or $char == true){
|
|
|
|
|
$src = false;
|
|
|
|
|
$char = true;
|
|
|
|
|
if(Verification::verifNotNull($_POST[""])){
|
|
|
|
|
|
|
|
|
|
if($_POST['req'] == "char" or $char == true){
|
|
|
|
|
if(Verification::verifNotNull($_POST["name"])){
|
|
|
|
|
$_POST["name"] = Verification::verifChar($_POST["name"]);
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
$error[] = "Le nom doit être définit";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// upload de la photo
|
|
|
|
|
if (isset($_FILES['avatar'])) {
|
|
|
|
|
|
|
|
|
|
$tabExtension = explode('.', $_FILES['avatar']['name']);
|
|
|
|
|
$extension = strtolower(end($tabExtension));
|
|
|
|
|
$extensions = ['jpg', 'png', 'jpeg'];
|
|
|
|
|
if(in_array($extension, $extensions)){
|
|
|
|
|
move_uploaded_file($_FILES['avatar']['tmp_name'], $repImg.$_FILES['avatar']['name']);
|
|
|
|
|
$filePath = $repImg.$_FILES['avatar']['name'];
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
$error[] = "Mauvaise extension";
|
|
|
|
|
exit();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
$error[] = "Aucune photo";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if($error == []){
|
|
|
|
|
$recap['content'] = $_POST['content'];
|
|
|
|
|
if($_POST['req'] == "both"){
|
|
|
|
|
|
|
|
|
|
$this->srcMod->createSource($_POST["titre"], $_POST["date"], TypeSourceEnum::from($_POST["type"]));
|
|
|
|
|
$idImg = $this->iMod->createImgModelWithoutId($filePath);
|
|
|
|
|
$this->caMod->createCharacterWithoutId($_POST["name"], $idImg);
|
|
|
|
|
$idC = $this-> caMod -> getCharacterByName($_POST["name"])->getIdCharacter();
|
|
|
|
|
$idS = $this -> srcMod -> getSourceByTitle($_POST["titre"])->getIdSource();
|
|
|
|
|
}
|
|
|
|
|
elseif($_POST['req'] == "src"){
|
|
|
|
|
$this->srcMod->createSource($_POST["titre"], $_POST["date"], TypeSourceEnum::from($_POST["type"]));
|
|
|
|
|
$idC = Verification::VerifChar($_POST["character"]);
|
|
|
|
|
$idS = $this -> srcMod -> getSourceByTitle($_POST["titre"])->getIdSource();
|
|
|
|
|
}
|
|
|
|
|
elseif($_POST['req'] == "char"){
|
|
|
|
|
|
|
|
|
|
$idImg = $this->iMod->createImgModelWithoutId($filePath);
|
|
|
|
|
$this->caMod->createCharacterWithoutId($_POST["name"], $idImg);
|
|
|
|
|
$idC = $this-> caMod -> getCharacterByName($_POST["name"])->getIdCharacter();
|
|
|
|
|
$idS = Verification::VerifChar($_POST["src"]);
|
|
|
|
|
}
|
|
|
|
|
require_once($vues["recap"]); //A changer pour recapSubmitQuote
|
|
|
|
|
$this -> toSubmit(Verification::VerifChar($_POST["content"]),$idC,$idS);
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
require_once($vues["create"]);
|
|
|
|
|