load comments if applicabe

This commit is contained in:
Dennis Eichhorn 2020-07-29 20:55:12 +02:00
parent a3c367cde6
commit e26e820fd0
7 changed files with 56 additions and 0 deletions

View File

@ -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'])) {

View File

@ -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;
}

View File

@ -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
*

View File

@ -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',

View File

@ -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',

View File

@ -68,6 +68,14 @@ echo $this->getData('nav')->render(); ?>
<option value="<?= $this->printHtml($code); ?>"<?= $this->printHtml($code === $news->getLanguage() ? ' selected' : ''); ?>><?= $this->printHtml($language); ?>
<?php endforeach; ?>
</select>
<tr><td>
<label for="iComment"><?= $this->getHtml('AllowComments'); ?></label>
<tr><td>
<label class="checkbox" for="iComment">
<input id="iComment" type="checkbox" name="allow_comments" value="1">
<span class="checkmark"></span>
<?= $this->getHtml('AllowComments'); ?>
</label>
</table>
</div>
<div class="portlet-foot">

View File

@ -52,3 +52,13 @@ echo $this->getData('nav')->render(); ?>
</section>
</div>
</div>
<?php
$commentList = $news->getComments();
if (!empty($commentList) && $commentList->isActive()) :
/* @todo: check if user has permission to create a comment here, maybe he is only allowed to read comments */
/* @todo: instead of creating a custom news list or news textarea I should create a component which simply gets loaded on the pages by passing the commentList id and the comments to show */
$this->getData('commentCreate')->render(1);
$this->getData('commentList')->render(1);
endif; ?>