mirror of
https://github.com/Karaka-Management/oms-Comments.git
synced 2026-02-07 21:18:41 +00:00
Implement comment models
This commit is contained in:
parent
3c95a5b51e
commit
2265004217
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -0,0 +1,106 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.1
|
||||
*
|
||||
* @category TBD
|
||||
* @package TBD
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link http://orange-management.com
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
namespace Modules\Comments\Models;
|
||||
|
||||
/**
|
||||
* Task class.
|
||||
*
|
||||
* @category Comments
|
||||
* @package Modules
|
||||
* @license OMS License 1.0
|
||||
* @link http://orange-management.com
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Comment
|
||||
{
|
||||
private $id = 0;
|
||||
|
||||
private $createdBy = 0;
|
||||
|
||||
private $createdAt = null;
|
||||
|
||||
private $list = null;
|
||||
|
||||
private $title = '';
|
||||
|
||||
private $content = '';
|
||||
|
||||
private $ref = null;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->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;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.1
|
||||
*
|
||||
* @category TBD
|
||||
* @package TBD
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link http://orange-management.com
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
namespace Modules\Comments\Models;
|
||||
|
||||
/**
|
||||
* Task class.
|
||||
*
|
||||
* @category Comments
|
||||
* @package Modules
|
||||
* @license OMS License 1.0
|
||||
* @link http://orange-management.com
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class CommentList
|
||||
{
|
||||
private $id = 0;
|
||||
|
||||
private $comments = [];
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
public function getId() : int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getComments() : array
|
||||
{
|
||||
return $this->comments;
|
||||
}
|
||||
|
||||
public function addComment($comment)
|
||||
{
|
||||
$this->comments[] = $comment;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,102 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.1
|
||||
*
|
||||
* @category TBD
|
||||
* @package TBD
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link http://orange-management.com
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
namespace Modules\Comments\Models;
|
||||
|
||||
use Modules\Comments\Models\CommentMapper;
|
||||
use phpOMS\DataStorage\Database\DataMapperAbstract;
|
||||
use phpOMS\DataStorage\Database\Query\Builder;
|
||||
use phpOMS\DataStorage\Database\Query\Column;
|
||||
use phpOMS\DataStorage\Database\RelationType;
|
||||
|
||||
/**
|
||||
* Mapper class.
|
||||
*
|
||||
* @category Tasks
|
||||
* @package Modules
|
||||
* @license OMS License 1.0
|
||||
* @link http://orange-management.com
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class CommentListMapper extends DataMapperAbstract
|
||||
{
|
||||
|
||||
/**
|
||||
* Columns.
|
||||
*
|
||||
* @var array
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static $columns = [
|
||||
'comments_list_id' => ['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;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,100 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.1
|
||||
*
|
||||
* @category TBD
|
||||
* @package TBD
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link http://orange-management.com
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
namespace Modules\Comments\Models;
|
||||
|
||||
use phpOMS\DataStorage\Database\DataMapperAbstract;
|
||||
use phpOMS\DataStorage\Database\Query\Builder;
|
||||
use phpOMS\DataStorage\Database\Query\Column;
|
||||
use phpOMS\DataStorage\Database\RelationType;
|
||||
|
||||
/**
|
||||
* Mapper class.
|
||||
*
|
||||
* @category Tasks
|
||||
* @package Modules
|
||||
* @license OMS License 1.0
|
||||
* @link http://orange-management.com
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class CommentMapper extends DataMapperAbstract
|
||||
{
|
||||
|
||||
/**
|
||||
* Columns.
|
||||
*
|
||||
* @var array
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static $columns = [
|
||||
'comments_comment_id' => ['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;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user