Skip to content

Commit

Permalink
#311 QnA 위젯 리스트에 '최근 몇 일'을 설정할 수 있게 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
xharpenParksuhyeon committed Aug 22, 2021
1 parent a4e5318 commit 48932b2
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
20 changes: 18 additions & 2 deletions components/Widgets/QnaList/QnaListWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Xpressengine\Plugins\Board\Components\Widgets\QnaList;

use Carbon\Carbon;
use View;
use Illuminate\Support\Arr;
use Xpressengine\Config\ConfigEntity;
Expand All @@ -24,22 +25,37 @@ class QnaListWidget extends AbstractWidget
*/
public function render(): string
{
/** @var UrlHandler $urlHandler */
$urlHandler = app(UrlHandler::class);
$widgetConfig = $this->setting();
$boardId = Arr::get($widgetConfig, 'board_id');
$boardMenuItem = MenuItem::where('type', 'board@board')->findOrFail($boardId);

$boardRequest = $this->getBoardRequest($widgetConfig);
$boardConfig = $this->getBoardConfig($boardMenuItem, Arr::get($widgetConfig, 'take'));

$recentDate = Arr::get($widgetConfig, 'recent_date', 0);

if ($recentDate !== 0) {
$current = Carbon::now();

$boardRequest->merge([
'created_at' => [
'start' => $current->copy()->addDay(-1 * $recentDate)->startOfDay()->toString(),
'end' => $current->copy()->addDay($recentDate)->endOfDay()->toString()
]
]);
}

$boards = app(BoardService::class)->getItems($boardRequest, $boardConfig)->getCollection();
$moreUrl = Arr::get($widgetConfig, 'using_more') !== 'true' ? null : app(UrlHandler::class)->get('index', $boardRequest->all(), $boardId);
$moreUrl = Arr::get($widgetConfig, 'using_more') !== 'true' ? null : $urlHandler->get('index', $boardRequest->all(), $boardId);

return $this->renderSkin([
'boardConfig' => $boardConfig,
'widgetConfig' => $widgetConfig,
'boards' => $boards,
'moreUrl' => $moreUrl,
'urlHandler' => app(UrlHandler::class),
'urlHandler' => $urlHandler,
]);
}

Expand Down
5 changes: 5 additions & 0 deletions components/Widgets/QnaList/views/settings.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
<input type="number" placeholder="출력할 게시물의 수를 입력해주세요." name="take" class="form-control" value="{{ array_get($args, 'take', 5) }}" />
</div>

<div class="form-group">
<label>최근 몇일</label>
<input type="number" name="recent_date" class="form-control" value="{{ array_get($args, 'recent_date') }}" />
</div>

<div class="form-group">
<label>채택 여부에 따른 필터링</label>
<select name="adopt_filter" class="form-control">
Expand Down
16 changes: 16 additions & 0 deletions src/Plugin/Intercepts/ReplyIntercepts.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,23 @@ public static function listenReplyArticles()
}

$replyConfig = ReplyConfigHandler::make()->getActivated($instanceId);

// 최근에 작성된 게시물
$query->when($request->get('created_at'), function ($query, $createdAt) {
if (is_array($createdAt) === false) {
return false;
}

$query->when(Arr::get($createdAt, 'start'), function($query, $startRangeAt) {
$query->where('created_at', '>=', $startRangeAt);
});

$query->when(Arr::get($createdAt, 'end'), function($query, $endRangeAt) {
$query->where('created_at', '<=', $endRangeAt);
});
});

// 답변여부에 따른 분류
$query->when($replyConfig, function($query) use($request) {
$query->where('parent_id', '')->with('replies');

Expand Down

0 comments on commit 48932b2

Please sign in to comment.