Upgraded comment creation

This commit is contained in:
Pierre 2018-04-22 13:51:22 +02:00
parent c3af9124b6
commit ddfe2f4e8e
2 changed files with 14 additions and 15 deletions

View File

@ -33,13 +33,15 @@ class CommentsController {
else else
$content = $this->get_comment_content("content", true); $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 //Try to create the comment
$commentID = components()->comments->create( $commentID = components()->comments->create($comment);
$postID,
userID,
$content,
isset($image_path) ? $image_path : ""
);
//Check for errors //Check for errors
if($commentID < 1) if($commentID < 1)

View File

@ -15,21 +15,18 @@ class Comments {
/** /**
* Create a comment * Create a comment
* *
* @param int $postID The ID of the associated post * @param Comment $comment Information about the comment to create
* @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)
* @return int The ID of the created comment or 0 in case of failure * @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 //Generate data set
$data = array( $data = array(
"ID_texte" => $postID, "ID_texte" => $comment->get_postID(),
"ID_personne" => $userID, "ID_personne" => $comment->get_userID(),
"date_envoi" => mysql_date(), "date_envoi" => mysql_date(),
"commentaire" => $content, "commentaire" => $comment->has_content() ? $comment->get_content() : "",
"image_commentaire" => $image == "" ? "" : "file:".$image "image_commentaire" => $comment->has_img_path() ? "file:".$comment->get_img_path() : ""
); );
//Insert it in the database //Insert it in the database