mirror of
https://github.com/pierre42100/ComunicAPI
synced 2024-11-23 22:09:29 +00:00
Upgraded comment creation
This commit is contained in:
parent
c3af9124b6
commit
ddfe2f4e8e
@ -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)
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user