From f7c6dcce70c421b4a825b306c33af5d0bb5b62d4 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Sun, 4 Apr 2021 17:10:52 +0200 Subject: [PATCH] many fixes and expands and module expansions --- Admin/Install/db.json | 71 +++++++++++++++++-- Controller/ApiController.php | 41 +++++++++++ Models/Comment.php | 35 +++++++++ Models/CommentList.php | 52 ++++---------- Models/CommentListMapper.php | 4 +- Models/CommentListStatus.php | 34 +++++++++ Models/CommentMapper.php | 16 +++++ Models/NullCommentList.php | 3 +- Theme/Backend/Components/Comment/list.tpl.php | 48 +++++++++++-- 9 files changed, 251 insertions(+), 53 deletions(-) create mode 100644 Models/CommentListStatus.php diff --git a/Admin/Install/db.json b/Admin/Install/db.json index 4a6f64c..94ef849 100755 --- a/Admin/Install/db.json +++ b/Admin/Install/db.json @@ -9,13 +9,8 @@ "primary": true, "autoincrement": true }, - "comments_list_active": { - "name": "comments_list_active", - "type": "TINYINT", - "null": false - }, - "comments_list_allow_comment": { - "name": "comments_list_allow_comment", + "comments_list_status": { + "name": "comments_list_status", "type": "TINYINT", "null": false }, @@ -28,6 +23,11 @@ "name": "comments_list_allow_edit", "type": "TINYINT", "null": false + }, + "comments_list_allow_files": { + "name": "comments_list_allow_files", + "type": "TINYINT", + "null": false } } }, @@ -89,5 +89,62 @@ "null": false } } + }, + "comments_comment_media": { + "name": "comments_comment_media", + "fields": { + "comments_comment_media_id": { + "name": "comments_comment_media_id", + "type": "INT", + "null": false, + "primary": true, + "autoincrement": true + }, + "comments_comment_media_src": { + "name": "comments_comment_media_src", + "type": "INT", + "null": false, + "foreignTable": "comments_comment", + "foreignKey": "comments_comment_id" + }, + "comments_comment_media_dst": { + "name": "comments_comment_media_dst", + "type": "INT", + "null": false, + "foreignTable": "media", + "foreignKey": "media_id" + } + } + }, + "comments_comment_vote": { + "name": "comments_comment_vote", + "fields": { + "comments_comment_vote_id": { + "name": "comments_comment_vote_id", + "type": "INT", + "null": false, + "primary": true, + "autoincrement": true + }, + "comments_comment_vote_src": { + "name": "comments_comment_vote_src", + "type": "INT", + "null": false, + "foreignTable": "comments_comment", + "foreignKey": "comments_comment_id" + }, + "comments_comment_vote_dst": { + "name": "comments_comment_vote_dst", + "type": "INT", + "null": false, + "foreignTable": "account", + "foreignKey": "account_id" + }, + "comments_comment_vote_score": { + "name": "comments_comment_vote_score", + "type": "TINYINT", + "null": false + } + } } } \ No newline at end of file diff --git a/Controller/ApiController.php b/Controller/ApiController.php index 2b969ac..c953627 100755 --- a/Controller/ApiController.php +++ b/Controller/ApiController.php @@ -71,6 +71,47 @@ final class ApiController extends Controller return $list; } + /** + * Api method to update comment list + * + * @param RequestAbstract $request Request + * @param ResponseAbstract $response Response + * @param mixed $data Generic data + * + * @return void + * + * @api + * + * @since 1.0.0 + */ + public function apiCommentListUpdate(RequestAbstract $request, ResponseAbstract $response, $data = null) : void + { + $old = clone CommentListMapper::get((int) $request->getData('id')); + $new = $this->updateCommentListFromRequest($request); + $this->updateModel($request->header->account, $old, $new, CommentMapper::class, 'comment_list', $request->getOrigin()); + $this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Comment List', 'Comment list successfully updated', $new); + } + + /** + * Method to update comment from request. + * + * @param RequestAbstract $request Request + * + * @return Comment + * + * @since 1.0.0 + */ + private function updateCommentListFromRequest(RequestAbstract $request) : Comment + { + $list = CommentListMapper::get((int) $request->getData('id')); + $list->allowEdit = (bool) ($request->getData('allow_edit') ?? $list->allowEdit); + $list->allowVoting = (bool) ($request->getData('allow_voting') ?? $list->allowVoting); + $list->allowFiles = (bool) ($request->getData('allow_upload') ?? $list->allowFiles); + $list->status = (int) ($request->getData('commentlist_status') ?? $list->status); + + return $list; + } + /** * Api method to create comment * diff --git a/Models/Comment.php b/Models/Comment.php index e99f74d..801a9c4 100755 --- a/Models/Comment.php +++ b/Models/Comment.php @@ -15,6 +15,7 @@ declare(strict_types=1); namespace Modules\Comments\Models; use Modules\Admin\Models\Account; +use Modules\Media\Models\Media; use Modules\Admin\Models\NullAccount; /** @@ -99,6 +100,14 @@ class Comment */ private $ref = null; + /** + * Media files + * + * @var Media[] + * @since 1.0.0 + */ + protected array $media = []; + /** * Constructor. * @@ -207,4 +216,30 @@ class Comment { return []; } + + /** + * Get all media + * + * @return Media[] + * + * @since 1.0.0 + */ + public function getMedia() : array + { + return $this->media; + } + + /** + * Add media + * + * @param Media $media Media to add + * + * @return void + * + * @since 1.0.0 + */ + public function addMedia(Media $media) : void + { + $this->media[] = $media; + } } diff --git a/Models/CommentList.php b/Models/CommentList.php index 9e0ffe9..92f164a 100755 --- a/Models/CommentList.php +++ b/Models/CommentList.php @@ -14,6 +14,8 @@ declare(strict_types=1); namespace Modules\Comments\Models; +use Modules\Media\Models\Media; + /** * Task class. * @@ -43,21 +45,13 @@ class CommentList /** * Is active * - * @var bool + * @var int * @since 1.0.0 */ - public bool $isActive = true; + public int $status = CommentListStatus::ACTIVE; /** - * Is active - * - * @var bool - * @since 1.0.0 - */ - public bool $allowComment = true; - - /** - * Is active + * Allow voting * * @var bool * @since 1.0.0 @@ -65,13 +59,21 @@ class CommentList public bool $allowVoting = true; /** - * Is active + * Allow editing * * @var bool * @since 1.0.0 */ public bool $allowEdit = true; + /** + * Allow files + * + * @var bool + * @since 1.0.0 + */ + public bool $allowFiles = true; + /** * Get id. * @@ -109,30 +111,4 @@ class CommentList { $this->comments[] = $comment; } - - /** - * Is active - * - * @return bool - * - * @since 1.0.0 - */ - public function isActive() : bool - { - return $this->isActive; - } - - /** - * Set list activity - * - * @param bool $active Is active - * - * @return void - * - * @since 1.0.0 - */ - public function setActive(bool $active) : void - { - $this->isActive = $active; - } } diff --git a/Models/CommentListMapper.php b/Models/CommentListMapper.php index fc6772f..4b74035 100755 --- a/Models/CommentListMapper.php +++ b/Models/CommentListMapper.php @@ -34,10 +34,10 @@ final class CommentListMapper extends DataMapperAbstract */ protected static array $columns = [ 'comments_list_id' => ['name' => 'comments_list_id', 'type' => 'int', 'internal' => 'id'], - 'comments_list_active' => ['name' => 'comments_list_active', 'type' => 'bool', 'internal' => 'isActive'], - 'comments_list_allow_comment' => ['name' => 'comments_list_allow_comment', 'type' => 'bool', 'internal' => 'allowComment'], + 'comments_list_status' => ['name' => 'comments_list_status', 'type' => 'bool', 'internal' => 'status'], 'comments_list_allow_voting' => ['name' => 'comments_list_allow_voting', 'type' => 'bool', 'internal' => 'allowVoting'], 'comments_list_allow_edit' => ['name' => 'comments_list_allow_edit', 'type' => 'bool', 'internal' => 'allowEdit'], + 'comments_list_allow_files' => ['name' => 'comments_list_allow_files', 'type' => 'bool', 'internal' => 'allowFiles'], ]; /** diff --git a/Models/CommentListStatus.php b/Models/CommentListStatus.php new file mode 100644 index 0000000..5f7ae14 --- /dev/null +++ b/Models/CommentListStatus.php @@ -0,0 +1,34 @@ + + * @since 1.0.0 + */ + protected static array $hasMany = [ + 'media' => [ + 'mapper' => MediaMapper::class, + 'table' => 'comments_comment_media', + 'external' => 'comments_comment_media_dst', + 'self' => 'comments_comment_media_src', + ], + ]; + /** * Primary table. * diff --git a/Models/NullCommentList.php b/Models/NullCommentList.php index 7009ddb..4aa8c77 100755 --- a/Models/NullCommentList.php +++ b/Models/NullCommentList.php @@ -33,7 +33,6 @@ final class NullCommentList extends CommentList */ public function __construct(int $id = 0) { - $this->id = $id; - $this->isActive = false; + $this->id = $id; } } diff --git a/Theme/Backend/Components/Comment/list.tpl.php b/Theme/Backend/Components/Comment/list.tpl.php index d047829..0711efe 100755 --- a/Theme/Backend/Components/Comment/list.tpl.php +++ b/Theme/Backend/Components/Comment/list.tpl.php @@ -1,14 +1,54 @@ commentList->getComments(); +?> + +
+ + + + + + + +
+ +
-
- content; ?> -
+
+
+ content; ?> +
+
+
+ printHtml( + \sprintf('%3$s %2$s %1$s', $comment->createdBy->name1, $comment->createdBy->name2, $comment->createdBy->name3) + ); ?> + createdAt->format('Y-m-d H:i:s'); ?> +
- \ No newline at end of file +