Created comment object

This commit is contained in:
Pierre 2018-04-21 14:48:02 +02:00
parent 217c6c4213
commit e20403e8ab
3 changed files with 138 additions and 19 deletions

View File

@ -0,0 +1,31 @@
<?php
/**
* Base object for any unique object
*
* @author Pierre HUBERT
*/
abstract class BaseUniqueObject {
//Private fields
private $id = 0;
//Set and get object ID
public function set_id(int $id){
$this->id = $id;
}
public function get_id() : int {
return $this->id;
}
/**
* Check wether this object is valid or not
*
* @return bool TRUE if this object is valid / FALSE else
*/
public function isValid() : bool {
return $this->id > 0;
}
}

View File

@ -6,26 +6,11 @@
* @author Pierre HUBERT * @author Pierre HUBERT
*/ */
class BaseUserModel { //Need the BaseUniqueObject class
require_once __DIR__."/BaseUniqueObject.php";
//Private fields abstract class BaseUserModel extends BaseUniqueObject {
private $userID = 0;
//Set and get user ID //Nothing yet
public function set_id(int $id){
$this->id = $id;
}
public function get_id() : int {
return $this->id;
}
/**
* Check wether this object is valid or not
*
* @return bool TRUE if this object is valid / FALSE else
*/
public function isValid() : bool {
return $this->id > 0;
}
} }

103
classes/models/Comment.php Normal file
View File

@ -0,0 +1,103 @@
<?php
/**
* Comments model
*
* @author Pierre HUBERT
*/
class Comment extends BaseUniqueObject {
//Private fields
private $userID;
private $postID;
private $time_sent;
private $content;
private $image_path;
private $image_url;
private $likes;
private $userLike;
//Set and get user ID
public function set_userID(int $userID){
$this->userID = $userID;
}
public function get_userID() : int {
return $this->userID;
}
//Set and get post ID
public function set_postID(int $postID){
$this->postID = $postID;
}
public function get_postID() : int {
return $this->postID;
}
//Set and get creation time
public function set_time_sent(int $time_sent){
$this->time_sent = $time_sent;
}
public function get_time_sent() : int {
return $this->time_sent;
}
//Set and get content
public function set_content(string $content){
$this->content = $content == "" ? null : $content;
}
public function has_content() : bool {
return $this->content != null;
}
public function get_content() : string {
return $this->content != null ? $this->content : "null";
}
//Set and get image path
public function set_img_path(string $img_path){
$this->img_path = $img_path == "" ? null : $img_path;
}
public function has_img_path() : bool {
return $this->img_path != null;
}
public function get_img_path() : string {
return $this->img_path != null ? $this->img_path : "null";
}
//Set and get image url
public function set_img_url(string $img_url){
$this->img_url = $img_url == "" ? null : $img_url;
}
public function has_img_url() : bool {
return $this->img_url != null;
}
public function get_img_url() : string {
return $this->img_url != null ? $this->img_url : "null";
}
//Set and get the number of likes over the comment
public function set_likes(int $likes){
$this->likes = $likes;
}
public function get_likes() : int {
return $this->likes;
}
//Set and get user like status
public function set_userLike(bool $userLike){
$this->userLike = $userLike;
}
public function get_userLike() : bool {
return $this->userLike;
}
}