From d07e31635a8937620d7b4e02582754ca19ea5a05 Mon Sep 17 00:00:00 2001 From: xharpenParksuhyeon Date: Tue, 21 Dec 2021 17:49:57 +0000 Subject: [PATCH] #328 BoardService Class - getBoardMoreItem formatting --- src/Services/BoardService.php | 37 ++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/src/Services/BoardService.php b/src/Services/BoardService.php index ae26221e..88286674 100644 --- a/src/Services/BoardService.php +++ b/src/Services/BoardService.php @@ -201,25 +201,34 @@ public function getItems(Request $request, ConfigEntity $config, $id = null) */ public function getBoardMoreItems(ConfigEntity $config, $currentItemId) { - /** @var Board $model */ - $model = Board::division($config->get('boardId')); - $query = $model->where('instance_id', $config->get('boardId')) - ->where('id', '<>', $currentItemId)->visible(); + $boardInstanceId = $config->get('boardId'); - if ($config->get('category') === true) { - $query->leftJoin( - 'board_category', - sprintf('%s.%s', $query->getQuery()->from, 'id'), - '=', - sprintf('%s.%s', 'board_category', 'target_id') - ); - } + $query = Board::division($boardInstanceId) + ->newQuery() + ->visible() + ->orderBy('head', 'desc') + ->with(['slug']) + ->where([ + ['instance_id', '=', $boardInstanceId], + ['id', '<>', $currentItemId], + ]) + ->when( + $config->has('category') === true, + function ($query) { + $fromTable =$query->getQuery()->from; - $query->with(['slug']); + $query->leftJoin( + 'board_category', + sprintf('%s.%s', $fromTable, 'id'), + '=', + sprintf('%s.%s', '', 'target_id') + ); + } + ); Event::fire('xe.plugin.board.moreItems', [$query, $config]); - return $query->take(8)->orderByDesc('head')->get(); + return $query->take(8)->get(); } /**