diff --git a/RestControllers/CommentsController.php b/RestControllers/CommentsController.php index 7f860b8..a26966b 100644 --- a/RestControllers/CommentsController.php +++ b/RestControllers/CommentsController.php @@ -33,13 +33,15 @@ class CommentsController { else $content = $this->get_comment_content("content", true); + //Create comment object with new information + $comment = new Comment(); + $comment->set_postID($postID); + $comment->set_userID(userID); + $comment->set_content($content); + $comment->set_img_path(isset($image_path) ? $image_path : ""); + //Try to create the comment - $commentID = components()->comments->create( - $postID, - userID, - $content, - isset($image_path) ? $image_path : "" - ); + $commentID = components()->comments->create($comment); //Check for errors if($commentID < 1) diff --git a/classes/components/comments.php b/classes/components/comments.php index bffcb98..5c6580d 100644 --- a/classes/components/comments.php +++ b/classes/components/comments.php @@ -15,21 +15,18 @@ class Comments { /** * Create a comment * - * @param int $postID The ID of the associated post - * @param int $userID The ID of the associated user - * @param string $content The content of the comment - * @param string $image The path of an associated image (if any) + * @param Comment $comment Information about the comment to create * @return int The ID of the created comment or 0 in case of failure */ - public function create(int $postID, int $userID, string $content, string $image = "") : int { + public function create(Comment $comment) : int { //Generate data set $data = array( - "ID_texte" => $postID, - "ID_personne" => $userID, + "ID_texte" => $comment->get_postID(), + "ID_personne" => $comment->get_userID(), "date_envoi" => mysql_date(), - "commentaire" => $content, - "image_commentaire" => $image == "" ? "" : "file:".$image + "commentaire" => $comment->has_content() ? $comment->get_content() : "", + "image_commentaire" => $comment->has_img_path() ? "file:".$comment->get_img_path() : "" ); //Insert it in the database