From e26e820fd0b245b65a8f2484ed0ca06f97e65190 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Wed, 29 Jul 2020 20:55:12 +0200 Subject: [PATCH] load comments if applicabe --- Controller/ApiController.php | 10 ++++++++++ Controller/BackendController.php | 12 ++++++++++++ Models/NewsArticle.php | 14 ++++++++++++++ Theme/Backend/Lang/de.lang.php | 1 + Theme/Backend/Lang/en.lang.php | 1 + Theme/Backend/news-create.tpl.php | 8 ++++++++ Theme/Backend/news-single.tpl.php | 10 ++++++++++ 7 files changed, 56 insertions(+) diff --git a/Controller/ApiController.php b/Controller/ApiController.php index 7d98f39..8d20871 100755 --- a/Controller/ApiController.php +++ b/Controller/ApiController.php @@ -28,6 +28,7 @@ use phpOMS\Message\NotificationLevel; use phpOMS\Message\RequestAbstract; use phpOMS\Message\ResponseAbstract; use phpOMS\Model\Message\FormValidation; +use phpOMS\Module\NullModule; use phpOMS\Utils\Parser\Markdown\Markdown; /** @@ -166,6 +167,15 @@ final class ApiController extends Controller $newsArticle->setStatus((int) ($request->getData('status') ?? NewsStatus::VISIBLE)); $newsArticle->setFeatured((bool) ($request->getData('featured') ?? true)); + // allow comments + if (!empty($request->getData('allow_comments')) + && !($commentApi = $this->app->moduleManager->get('Comments') instanceof NullModule) + ) { + /** @var \Modules\Comments\Controller\ApiController $commentApi */ + $commnetList = $commentApi->createCommentList(); + $newsArticle->setCommentList($commnetList); + } + if (!empty($tags = $request->getDataJson('tags'))) { foreach ($tags as $tag) { if (!isset($tag['id'])) { diff --git a/Controller/BackendController.php b/Controller/BackendController.php index 47d499f..7fb4d88 100755 --- a/Controller/BackendController.php +++ b/Controller/BackendController.php @@ -26,6 +26,7 @@ use phpOMS\Message\Http\RequestStatusCode; use phpOMS\Message\RequestAbstract; use phpOMS\Message\ResponseAbstract; use phpOMS\Views\View; +use phpOMS\Module\NullModule; /** * News controller class. @@ -134,6 +135,17 @@ final class BackendController extends Controller implements DashboardElementInte PermissionType::MODIFY, $this->app->orgId, $this->app->appName, self::MODULE_NAME, PermissionState::NEWS, $article->getId()) ); + // allow comments + if (!$article->getComments() !== null + && !($this->app->moduleManager->get('Comments') instanceof NullModule) + ) { + $commentCreateView = new \Modules\Comments\Theme\Backend\Components\Comment\CreateView($this->app->l11nManager, $request, $response); + $commentListView = new \Modules\Comments\Theme\Backend\Components\Comment\ListView($this->app->l11nManager, $request, $response); + + $view->addData('commentCreate', $commentCreateView); + $view->addData('commentList', $commentListView); + } + return $view; } diff --git a/Models/NewsArticle.php b/Models/NewsArticle.php index dab88f7..a694cf8 100755 --- a/Models/NewsArticle.php +++ b/Models/NewsArticle.php @@ -199,6 +199,20 @@ class NewsArticle implements ArrayableInterface, \JsonSerializable return $this->plain; } + /** + * Set comment list + * + * @param CommentList $comments + * + * @return void + * + * @since 1.0.0 + */ + public function setCommentList($comments) : void + { + $this->comments = $comments; + } + /** * Get comments * diff --git a/Theme/Backend/Lang/de.lang.php b/Theme/Backend/Lang/de.lang.php index 01c3c25..7671655 100755 --- a/Theme/Backend/Lang/de.lang.php +++ b/Theme/Backend/Lang/de.lang.php @@ -15,6 +15,7 @@ declare(strict_types=1); return ['News' => [ 'Accounts/Groups' => 'Benutyer/Gruppen', 'Additional' => 'Zusätzlich', + 'AllowComments' => 'Kommentare erlauben', 'Archive' => 'Archiv', 'Author' => 'Autor', 'Date' => 'Datum', diff --git a/Theme/Backend/Lang/en.lang.php b/Theme/Backend/Lang/en.lang.php index 428bd08..e034fe2 100755 --- a/Theme/Backend/Lang/en.lang.php +++ b/Theme/Backend/Lang/en.lang.php @@ -15,6 +15,7 @@ declare(strict_types=1); return ['News' => [ 'Accounts/Groups' => 'Accounts/Groups', 'Additional' => 'Additional', + 'AllowComments' => 'Allow comments', 'Archive' => 'Archive', 'Author' => 'Author', 'Date' => 'Date', diff --git a/Theme/Backend/news-create.tpl.php b/Theme/Backend/news-create.tpl.php index 939b5bb..4db8c07 100755 --- a/Theme/Backend/news-create.tpl.php +++ b/Theme/Backend/news-create.tpl.php @@ -68,6 +68,14 @@ echo $this->getData('nav')->render(); ?>