Can create comments.

This commit is contained in:
Pierre
2018-01-31 06:47:25 +01:00
parent 6f792886e4
commit 8611d3fa1e
2 changed files with 76 additions and 2 deletions

View File

@ -12,6 +12,34 @@ class Comments {
*/
const COMMENTS_TABLE = "commentaires";
/**
* 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)
* @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 {
//Generate data set
$data = array(
"ID_texte" => $postID,
"ID_personne" => $userID,
"date_envoi" => mysql_date(),
"commentaire" => $content,
"image_commentaire" => $image == "" ? "" : "file:".$image
);
//Insert it in the database
if(!CS::get()->db->addLine($this::COMMENTS_TABLE, $data))
return 0;
//Get the ID of the last inserted comment and return it
return CS::get()->db->getLastInsertedID();
}
/**
* Fetch the comments of a post
*