From b9297c8617e511bae6b7fd7517471dfb302e5e51 Mon Sep 17 00:00:00 2001 From: leosw Date: Sun, 12 Apr 2026 12:51:12 +0200 Subject: [PATCH] =?UTF-8?q?GEstion=20de=20l'ajout=20et=20de=20l'afichage?= =?UTF-8?q?=20des=20photos=20pour=20les=20commentaires=20!!=20SQL=20modifi?= =?UTF-8?q?=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/views/d.poi.view.html | 11 ++++- src/Controllers/d.poi.php | 12 +++++ src/Models/d.comments.php | 93 ++++++++++++++++++++---------------- 3 files changed, 75 insertions(+), 41 deletions(-) diff --git a/public/views/d.poi.view.html b/public/views/d.poi.view.html index f1f931f..3ef95a4 100644 --- a/public/views/d.poi.view.html +++ b/public/views/d.poi.view.html @@ -181,7 +181,7 @@
-
+
>

Impossible de commenter un point non publiƩ

@@ -194,6 +194,9 @@
+ + +
@@ -242,6 +245,12 @@
comment_html?> + + photo)) { ?> +
+ Photo du commentaire +
+
diff --git a/src/Controllers/d.poi.php b/src/Controllers/d.poi.php index 43447fd..92e09c1 100755 --- a/src/Controllers/d.poi.php +++ b/src/Controllers/d.poi.php @@ -233,6 +233,18 @@ switch ($controller->splitted_url[1]) { $Comment->author = $user->id; $Comment->content = $poi->content_id; $Comment->comment = $_POST['comment']; + + if (!empty($_FILES['photo']['tmp_name'])) { + $tmp = $_FILES['photo']['tmp_name']; + $filename = uniqid('comment_').'.jpg'; // ou extension dynamique + $destination = $config['medias_folder'].'comment_photos/'.$filename; + + move_uploaded_file($tmp, $destination); + + // URL publique + $Comment->photo = $filename; + } + $Comment->insert(); } } diff --git a/src/Models/d.comments.php b/src/Models/d.comments.php index c0f477e..8d9863d 100644 --- a/src/Models/d.comments.php +++ b/src/Models/d.comments.php @@ -28,34 +28,31 @@ class Comment public $locale = NULL; public $comment_html = NULL; public $author_obj = NULL; + public $photo = NULL; - - /***** - ** Connect to correct account using ID and stores its ID - *****/ public function checkID($id) { - global $config; - + global $config; + // Chargement du commentaire par ID. - $con = sql_connect(); + $con = sql_connect(); - $query = "SELECT * FROM content_comments WHERE id=$1"; + $query = "SELECT c.*, p.url AS photo_url FROM content_comments c + LEFT JOIN content_comment_photos p ON p.comment_id = c.id WHERE c.id = $1"; - pg_prepare($con, "prepare1", $query) - or die ("Cannot prepare statement\n"); - $result = pg_execute($con, "prepare1", array($id)) - or die ("Cannot execute statement\n"); + pg_prepare($con, "prepare_comment_join", $query) + or die("Cannot prepare statement\n"); - pg_close($con); + $result = pg_execute($con, "prepare_comment_join", array($id)) + or die("Cannot execute statement\n"); - if(pg_num_rows($result) == 1) { - $row = pg_fetch_assoc($result); - $this->populate($row); - return 1; - } - else { - return 0; - } + pg_close($con); + + if (pg_num_rows($result) == 1) { + $row = pg_fetch_assoc($result); + $this->populate($row); + return 1; + } + return 0; } /***** @@ -97,6 +94,9 @@ class Comment if (array_key_exists('locale', $row)) { $this->locale = $row['locale']; } + if (array_key_exists('photo_url', $row)) { + $this->photo = $row['photo_url']; + } } /***** @@ -118,6 +118,15 @@ class Comment $this->id = pg_fetch_assoc($result)['id']; + if(isset($this->photo) && $this->photo != NULL) { + $query = "INSERT INTO content_comment_photos (comment_id, url) VALUES + ($1, $2)"; + + pg_prepare($con, "prepare2", $query) + or die ("Cannot prepare statement\n"); + pg_execute($con, "prepare2", array($this->id, $this->photo)); + } + pg_close($con); } @@ -208,29 +217,33 @@ class Comments /***** ** Return the list of different articles *****/ - public function listComments($id, $archive=0) { - global $config; + public function listComments($id, $archive = 0) { + global $config; - $con = sql_connect(); + $con = sql_connect(); - $query = "SELECT * FROM content_comments WHERE content = $1 "; - if ($archive == 0) - $query .= "AND is_archive IS FALSE AND is_public IS TRUE "; - $query .= "ORDER BY update_date DESC"; + $query = "SELECT c.*, p.url AS photo_url FROM content_comments c + LEFT JOIN content_comment_photos p ON p.comment_id = c.id WHERE c.content = $1 "; - pg_prepare($con, "prepare1", $query) - or die ("Cannot prepare statement\n"); - $result = pg_execute($con, "prepare1", array($id)) - or die ("Cannot execute statement\n"); - - pg_close($con); + if ($archive == 0) + $query .= "AND c.is_archive IS FALSE AND c.is_public IS TRUE "; - $this->number = pg_num_rows($result); + $query .= "ORDER BY c.update_date DESC"; - for($i = 0; $i < pg_num_rows($result); $i++) { - $row = pg_fetch_assoc($result, $i); - $this->objs[$i] = new Comment; - $this->objs[$i]->populate($row); - } + pg_prepare($con, "prepare_comment_list", $query) + or die("Cannot prepare statement\n"); + + $result = pg_execute($con, "prepare_comment_list", array($id)) + or die("Cannot execute statement\n"); + + pg_close($con); + + $this->number = pg_num_rows($result); + + for ($i = 0; $i < $this->number; $i++) { + $row = pg_fetch_assoc($result, $i); + $this->objs[$i] = new Comment; + $this->objs[$i]->populate($row); + } } }