Skip to content

Commit

Permalink
#311 답글이랑 관련된 코드를 service 파일에서 event 쪽으로 옮겨 작성해줍니다.
Browse files Browse the repository at this point in the history
  • Loading branch information
xharpenParksuhyeon committed Aug 18, 2021
1 parent f8f5dd8 commit 90b5424
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
20 changes: 20 additions & 0 deletions src/Plugin/Intercepts/ReplyIntercepts.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

namespace Xpressengine\Plugins\Board\Plugin\Intercepts;

use Event;
use Xpressengine\Config\ConfigEntity;
use Xpressengine\Document\Models\Document;
use Xpressengine\Http\Request;
use Xpressengine\Plugins\Board\Models\Board;
use Xpressengine\Routing\InstanceConfig;
use Xpressengine\User\UserInterface;
use Xpressengine\Plugins\Board\Exceptions\{
CanNotDeleteHasReplyException,
Expand All @@ -15,6 +17,7 @@
};
use Xpressengine\Plugins\Board\{
BoardPermissionHandler,
ConfigHandler,
Handler as BoardHandler,
Plugin as BoardPlugin,
IdentifyManager,
Expand All @@ -24,6 +27,23 @@

abstract class ReplyIntercepts
{
/**
* listen reply articles
*/
public static function listenReplyArticles()
{
Event::listen('xe.plugin.board.articles', function ($query) {
$instanceConfig = InstanceConfig::instance();
$instanceId = $instanceConfig->getInstanceId();

$boardConfig = app(ConfigHandler::class)->get($instanceId);

$query->when($boardConfig && $boardConfig->get('replyPost', false) === true, function($query) {
$query->where('parent_id', '')->with('replies');
});
});
}

/**
* intercept validate stored
*/
Expand Down
1 change: 1 addition & 0 deletions src/Plugin/Resources.php
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,7 @@ function ($deleteCategory, $item, $force = true) {
*/
public static function interceptReply()
{
Plugin\Intercepts\ReplyIntercepts::listenReplyArticles();
Plugin\Intercepts\ReplyIntercepts::interceptValidateStored();
Plugin\Intercepts\ReplyIntercepts::interceptValidateUpdated();
Plugin\Intercepts\ReplyIntercepts::interceptProtectDeleted();
Expand Down
3 changes: 1 addition & 2 deletions src/Services/BoardService.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,7 @@ public function getItems(Request $request, ConfigEntity $config, $id = null)
{
/** @var Board $model */
$model = Board::division($config->get('boardId'));
$query = $model->where('instance_id', $config->get('boardId'))
->where('parent_id', '');
$query = $model->where('instance_id', $config->get('boardId'));

if ($config->get('noticeInList') === true) {
$query->visibleWithNotice();
Expand Down

0 comments on commit 90b5424

Please sign in to comment.