diff --git a/Admin/Installer.php b/Admin/Installer.php index 22321ae..f3e386c 100644 --- a/Admin/Installer.php +++ b/Admin/Installer.php @@ -43,7 +43,7 @@ class Installer extends InstallerAbstract $dbPool->get()->con->prepare( 'CREATE TABLE if NOT EXISTS `' . $dbPool->get()->prefix . 'comments_list` ( `comments_list_id` int(11) NOT NULL AUTO_INCREMENT, - PRIMARY KEY (`comments_comment_id`) + PRIMARY KEY (`comments_list_id`) )ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;' )->execute(); @@ -52,7 +52,7 @@ class Installer extends InstallerAbstract `comments_comment_id` int(11) NOT NULL AUTO_INCREMENT, `comments_comment_title` varchar(250) NOT NULL, `comments_comment_content` text NOT NULL, - `comments_comment_list` int(11) NOT NULL, + `comments_comment_list` int(11) DEFAULT NULL, `comments_comment_ref` int(11) DEFAULT NULL, `comments_comment_created_at` datetime NOT NULL, `comments_comment_created_by` int(11) NOT NULL, diff --git a/Models/Comment.php b/Models/Comment.php index e69de29..5876503 100644 --- a/Models/Comment.php +++ b/Models/Comment.php @@ -0,0 +1,106 @@ +createdAt = new \DateTime(); + } + + public function getId() : int + { + return $this->id; + } + + public function setRef($ref) + { + $this->ref = $ref; + } + + public function getRef() + { + return $this->ref; + } + + public function setList($list) + { + $this->list = $list; + } + + public function getList() + { + return $this->list; + } + + public function getTitle() : string + { + return $this->title; + } + + public function setTitle(string $title) + { + $this->title = $title; + } + + public function getContent() : string + { + return $this->content; + } + + public function setContent(string $content) + { + $this->content = $content; + } + + public function getCreatedBy() + { + return $this->createdBy; + } + + public function setCreatedBy($createdBy) + { + $this->createdBy = $createdBy; + } + + public function getCreatedAt() : \DateTime + { + return $this->createdAt; + } +} \ No newline at end of file diff --git a/Models/CommentList.php b/Models/CommentList.php index e69de29..56eacf5 100644 --- a/Models/CommentList.php +++ b/Models/CommentList.php @@ -0,0 +1,51 @@ +id; + } + + public function getComments() : array + { + return $this->comments; + } + + public function addComment($comment) + { + $this->comments[] = $comment; + } + +} \ No newline at end of file diff --git a/Models/CommentListMapper.php b/Models/CommentListMapper.php index e69de29..668d720 100644 --- a/Models/CommentListMapper.php +++ b/Models/CommentListMapper.php @@ -0,0 +1,102 @@ + ['name' => 'comments_list_id', 'type' => 'int', 'internal' => 'id'], + ]; + + /** + * Has many relation. + * + * @var array + * @since 1.0.0 + */ + protected static $hasMany = [ + 'comments' => [ + 'mapper' => CommentMapper::class, + 'table' => 'comments_comment', + 'dst' => 'comments_comment_list', + 'src' => null, + ], + ]; + + /** + * Primary table. + * + * @var string + * @since 1.0.0 + */ + protected static $table = 'comments_list'; + + /** + * Primary field name. + * + * @var string + * @since 1.0.0 + */ + protected static $primaryField = 'comments_list_id'; + + /** + * Create object. + * + * @param mixed $obj Object + * @param int $relations Behavior for relations creation + * + * @return mixed + * + * @since 1.0.0 + */ + public static function create($obj, int $relations = RelationType::ALL) + { + try { + $objId = parent::create($obj, $relations); + + if($objId === null || !is_scalar($objId)) { + return $objId; + } + } catch (\Exception $e) { + var_dump($e->getMessage()); + + return false; + } + + return $objId; + } +} diff --git a/Models/CommentMapper.php b/Models/CommentMapper.php index e69de29..0fe1f59 100644 --- a/Models/CommentMapper.php +++ b/Models/CommentMapper.php @@ -0,0 +1,100 @@ + ['name' => 'comments_comment_id', 'type' => 'int', 'internal' => 'id'], + 'comments_comment_title' => ['name' => 'comments_comment_title', 'type' => 'string', 'internal' => 'title'], + 'comments_comment_content' => ['name' => 'comments_comment_content', 'type' => 'string', 'internal' => 'content'], + 'comments_comment_list' => ['name' => 'comments_comment_list', 'type' => 'int', 'internal' => 'list'], + 'comments_comment_ref' => ['name' => 'comments_comment_ref', 'type' => 'int', 'internal' => 'ref'], + 'comments_comment_created_by' => ['name' => 'comments_comment_created_by', 'type' => 'int', 'internal' => 'createdBy'], + 'comments_comment_created_at' => ['name' => 'comments_comment_created_at', 'type' => 'DateTime', 'internal' => 'createdAt'], + ]; + + /** + * Primary table. + * + * @var string + * @since 1.0.0 + */ + protected static $table = 'comments_comment'; + + /** + * Created at. + * + * @var string + * @since 1.0.0 + */ + protected static $createdAt = 'comments_comment_created_at'; + + /** + * Primary field name. + * + * @var string + * @since 1.0.0 + */ + protected static $primaryField = 'comments_comment_id'; + + /** + * Create object. + * + * @param mixed $obj Object + * @param int $relations Behavior for relations creation + * + * @return mixed + * + * @since 1.0.0 + */ + public static function create($obj, int $relations = RelationType::ALL) + { + try { + $objId = parent::create($obj, $relations); + + if($objId === null || !is_scalar($objId)) { + return $objId; + } + } catch (\Exception $e) { + var_dump($e->getMessage()); + + return false; + } + + return $objId; + } +}