Skip to content

Commit

Permalink
#328 BoardService Class - getBoardMoreItem formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
xharpenParksuhyeon committed Dec 21, 2021
1 parent b5ec2af commit d07e316
Showing 1 changed file with 23 additions and 14 deletions.
37 changes: 23 additions & 14 deletions src/Services/BoardService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

/**
Expand Down

0 comments on commit d07e316

Please sign in to comment.