From 5d11460abdac65ab9887c54cafeaf9566eee2780 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Sat, 26 Jun 2021 14:38:08 +0200 Subject: [PATCH] fix phpstan/phpcs --- Admin/Routes/Web/Api.php | 11 ++++++ Controller/ApiController.php | 19 ++++----- Models/CommentVoteMapper.php | 22 +++++++++++ Theme/Backend/Components/Comment/list.tpl.php | 39 ++++++++++--------- Theme/Backend/Lang/en.lang.php | 6 +++ composer.json | 2 +- 6 files changed, 70 insertions(+), 29 deletions(-) diff --git a/Admin/Routes/Web/Api.php b/Admin/Routes/Web/Api.php index ffe14d5..46ad358 100755 --- a/Admin/Routes/Web/Api.php +++ b/Admin/Routes/Web/Api.php @@ -26,6 +26,17 @@ return [ ], ], ], + '^.*/comment/list(\?.*|$)' => [ + [ + 'dest' => '\Modules\Comments\Controller\ApiController:apiCommentListUpdate', + 'verb' => RouteVerb::SET, + 'permission' => [ + 'module' => ApiController::MODULE_NAME, + 'type' => PermissionType::CREATE, + 'state' => PermissionState::LIST, + ], + ], + ], '^.*/comment/vote(\?.*|$)' => [ [ 'dest' => '\Modules\Comments\Controller\ApiController:apiChangeCommentVote', diff --git a/Controller/ApiController.php b/Controller/ApiController.php index 2f823c3..3be94a1 100755 --- a/Controller/ApiController.php +++ b/Controller/ApiController.php @@ -91,7 +91,7 @@ final class ApiController extends Controller { $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->updateModel($request->header->account, $old, $new, CommentListMapper::class, 'comment_list', $request->getOrigin()); $this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Comment List', 'Comment list successfully updated', $new); } @@ -100,16 +100,16 @@ final class ApiController extends Controller * * @param RequestAbstract $request Request * - * @return Comment + * @return CommentList * * @since 1.0.0 */ - private function updateCommentListFromRequest(RequestAbstract $request) : Comment + private function updateCommentListFromRequest(RequestAbstract $request) : CommentList { $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->allowEdit = (bool) ($request->getData('allow_edit') ?? false); + $list->allowVoting = (bool) ($request->getData('allow_voting') ?? false); + $list->allowFiles = (bool) ($request->getData('allow_upload') ?? false); $list->status = (int) ($request->getData('commentlist_status') ?? $list->status); return $list; @@ -280,19 +280,20 @@ final class ApiController extends Controller */ private function apiChangeCommentVote(RequestAbstract $request, ResponseAbstract $response, $data = null) : void { - if (!empty($val = $this->validateAnswerVote($request))) { + if (!empty($val = $this->validateCommentVote($request))) { $response->set('qa_answer_vote', new FormValidation($val)); $response->header->status = RequestStatusCode::R_400; return; } - $vote = CommentVoteMapper::findVote((int) $reqeust->getData('id'), $request->header->account); + $vote = CommentVoteMapper::findVote((int) $request->getData('id'), $request->header->account); if ($vote instanceof NullCommentVote) { $new = new CommentVote(); $new->score = (int) $request->getData('type'); - $new->createdBy = $request->header->account; + $new->comment = (int) $request->getData('id'); + $new->createdBy = new NullAccount($request->header->account); $this->createModel($request->header->account, $new, CommentVoteMapper::class, 'comment_vote', $request->getOrigin()); $this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Vote', 'Sucessfully voted.', $new); diff --git a/Models/CommentVoteMapper.php b/Models/CommentVoteMapper.php index c927513..5ebf4bc 100644 --- a/Models/CommentVoteMapper.php +++ b/Models/CommentVoteMapper.php @@ -63,4 +63,26 @@ final class CommentVoteMapper extends DataMapperAbstract * @since 1.0.0 */ protected static string $primaryField = 'comments_comment_vote_id'; + + /** + * Find vote for comment from user + * + * @param int $comment Comment id + * @param int $account Account id + * + * @return CommentVote + * + * @since 1.0.0 + */ + public static function findVote(int $comment, int $account) : CommentVote + { + $depth = 3; + $query = self::getQuery(); + $query->where(self::$table . '_d' . $depth . '.comments_comment_vote_created_by', '=', $account) + ->andWhere(self::$table . '_d' . $depth . '.comments_comment_vote_comment', '=', $comment); + + $results = self::getAllByQuery($query); + + return \reset($results); + } } diff --git a/Theme/Backend/Components/Comment/list.tpl.php b/Theme/Backend/Components/Comment/list.tpl.php index d0de39f..db63edd 100755 --- a/Theme/Backend/Components/Comment/list.tpl.php +++ b/Theme/Backend/Components/Comment/list.tpl.php @@ -1,6 +1,7 @@ commentList->getComments(); @@ -10,32 +11,32 @@ $comments = $this->commentList->getComments();
-
+
-
-
-