From b819729df788d0c966ef5ff83711488823bdf706 Mon Sep 17 00:00:00 2001 From: "kevin.modejar" Date: Tue, 15 Oct 2024 09:50:02 +0200 Subject: [PATCH] Suite gateway --- script/comment.php | 0 script/quote.php | 16 ++++++++++++++ script/quoteGateway.php | 49 +++++++++++++++++++++++++++++++++++++++++ script/user.php | 4 ++-- script/userGateway.php | 17 +++++++------- 5 files changed, 76 insertions(+), 10 deletions(-) create mode 100644 script/comment.php create mode 100644 script/quote.php create mode 100644 script/quoteGateway.php diff --git a/script/comment.php b/script/comment.php new file mode 100644 index 0000000..e69de29 diff --git a/script/quote.php b/script/quote.php new file mode 100644 index 0000000..d3c07ac --- /dev/null +++ b/script/quote.php @@ -0,0 +1,16 @@ + \ No newline at end of file diff --git a/script/quoteGateway.php b/script/quoteGateway.php new file mode 100644 index 0000000..db85b36 --- /dev/null +++ b/script/quoteGateway.php @@ -0,0 +1,49 @@ +con=$con; + } + + public function searchQuote(string $quote,int $numpage,string $language):array{ + + //recherche par citation + $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 content LIKE '%:quote%' AND isValid = true AND language = :language LIMIT 20 OFFSET :page*20;"; + $this->con->executeQuery($query,array(':quote' => array($quote,PDO::PARAM_STR),':page' => array($numpage,PDO::PARAM_INT),':language' => array($language,PDO::PARAM_STR))); + $result=$this->con->getResults(); + return $result; + } + + 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->con->executeQuery($query,array(':source' => array($source,PDO::PARAM_STR),':page' => array($numpage,PDO::PARAM_INT),':language' => array($language,PDO::PARAM_STR))); + $result=$this->con->getResults(); + return $result; + } + + 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->con->executeQuery($query,array(':pers' => array($Pers,PDO::PARAM_STR),':page' => array($numpage,PDO::PARAM_INT),':language' => array($language,PDO::PARAM_STR))); + $result=$this->con->getResults(); + return $result; + } + + public function getComment(int $id):array{ + + //obtention des commentaire d'une citation + $query="SELECT c.id_comment u.username, u.imgPath, c.comment, c.date FROM Commentary c JOIN Quote q ON c.quote = q.id_quote JOIN User u ON u.id_user = c.user JOIN Image i ON i.id_img = u.img WHERE id_quote = :id;"; + $this->con->executeQuery($query,array(':id' => array($id,PDO::PARAM_INT))); + $result=$this->con->getResults(); + return $result; + } + +} + +?> \ No newline at end of file diff --git a/script/user.php b/script/user.php index 32aeb82..2c9fd74 100644 --- a/script/user.php +++ b/script/user.php @@ -6,9 +6,9 @@ class User{ public string $hidenPasswd; public string $img; public string $email; - public bool $admin = false; - function __construct(string $pseudo, string $password, string $image, string $mail) { + function __construct(int $id, string $pseudo, string $password, string $image, string $mail) { + $this->id = $id; $this->username = $pseudo; $this->passwd = $password; $this->hidenPasswd = hidenPassWd($password); diff --git a/script/userGateway.php b/script/userGateway.php index 08b8f37..6549956 100644 --- a/script/userGateway.php +++ b/script/userGateway.php @@ -1,6 +1,5 @@ con=$con; } - public function insert(User $u):int{ + public function insert(string $username,string $email,string $passwd):int{ // récupération id $query='SELECT id_user FROM Users WHERE id_user >= ALL (SELECT id_user FROM Users);'; @@ -30,12 +29,14 @@ Class UserGateway{ $query='DELETE FROM Users WHERE id_user = :id;'; $this->con->executeQuery($query,array(':id' => array($id,PDO::PARAM_INT))); } - - public function searchQuote(string $quote,int $numpage)//: - { - $query="Select * From Quote Where content LIKE '%:quote%' Limit 20 OFFSET :page*20;"; - $this->con->executeQuery($query,array(':quote' => array($quote,PDO::PARAM_STR),':page' => array($numpage,PDO::PARAM_INT))); - //return ; + + public function getFavorite(int $id):array{ + + //obtention favoris d'un user + $query='SELECT * FROM Quote WHERE id_quote IN (SELECT id_quote IN Favorite f JOIN User u ON u.id_user = f.user WHERE id_user = :id);'; + $this->con->executeQuery($query,array(':id' => array($id,PDO::PARAM_INT))); + $result=$this->con->getResults(); + return $result; } }