Commit 237f420c authored by Tino Goratsch's avatar Tino Goratsch

use the comments model for the comments module some more

parent 98575e91
......@@ -48,27 +48,27 @@ abstract class AbstractModel
}
/**
* @param array $data
* @param array $columnData
* @param null|int $entryId
* @return bool|int
*/
protected function save(array $data, $entryId = null)
public function save(array $columnData, $entryId = null)
{
$data = $this->prepareData($data);
$columnData = $this->prepareData($columnData);
$this->dispatchBeforeSaveEvent($this->repository, $data, $entryId);
$this->dispatchBeforeSaveEvent($this->repository, $columnData, $entryId);
if ($entryId === null) {
$result = $this->repository->insert($data);
$result = $this->repository->insert($columnData);
if ($result !== false) {
$entryId = $result;
}
} else {
$result = $this->repository->update($data, $entryId);
$result = $this->repository->update($columnData, $entryId);
}
$this->dispatchAfterSaveEvent($this->repository, $data, $entryId);
$this->dispatchAfterSaveEvent($this->repository, $columnData, $entryId);
return $result;
}
......
......@@ -53,18 +53,18 @@ abstract class AbstractNestedSetModel extends AbstractModel
}
/**
* @param array $data
* @param array $columnData
* @param int|null $entryId
* @return bool|int
*/
protected function save(array $data, $entryId = null)
public function save(array $columnData, $entryId = null)
{
$data = $this->prepareData($data);
$columnData = $this->prepareData($columnData);
$this->dispatchBeforeSaveEvent($this->repository, $data, $entryId);
$this->dispatchBeforeSaveEvent($this->repository, $columnData, $entryId);
if ($entryId === null) {
$result = $this->insertOperation->execute($data, $data['parent_id']);
$result = $this->insertOperation->execute($columnData, $columnData['parent_id']);
if ($result !== false) {
$entryId = $result;
......@@ -72,13 +72,13 @@ abstract class AbstractNestedSetModel extends AbstractModel
} else {
$result = $this->editOperation->execute(
$entryId,
$data['parent_id'],
isset($data['block_id']) ? $data['block_id'] : 0,
$data
$columnData['parent_id'],
isset($columnData['block_id']) ? $columnData['block_id'] : 0,
$columnData
);
}
$this->dispatchAfterSaveEvent($this->repository, $data, $entryId);
$this->dispatchAfterSaveEvent($this->repository, $columnData, $entryId);
return $result;
}
......
......@@ -59,17 +59,15 @@ class Delete extends Core\Controller\AbstractAdminAction
// If there are no comments for the given module, redirect to the general comments admin panel page
if ($this->commentRepository->countAll($id) == 0) {
return $this->redirectMessages()->setMessage(
$result,
$this->translator->t('system', $result !== false ? 'delete_success' : 'delete_error'),
'acp/comments'
);
$redirectUrl = 'acp/comments';
} else {
$redirectUrl = 'acp/comments/details/index/id_' . $id;
}
return $this->redirectMessages()->setMessage(
$result,
$this->translator->t('system', $result !== false ? 'delete_success' : 'delete_error'),
'acp/comments/details/index/id_' . $id
$redirectUrl
);
},
'acp/comments/details/delete/id_' . $id,
......
......@@ -17,10 +17,6 @@ use ACP3\Modules\ACP3\System;
*/
class Edit extends Core\Controller\AbstractAdminAction
{
/**
* @var \ACP3\Modules\ACP3\Comments\Model\Repository\CommentRepository
*/
protected $commentRepository;
/**
* @var \ACP3\Modules\ACP3\Comments\Validation\AdminFormValidation
*/
......@@ -29,26 +25,30 @@ class Edit extends Core\Controller\AbstractAdminAction
* @var \ACP3\Core\Helpers\FormToken
*/
protected $formTokenHelper;
/**
* @var Comments\Model\CommentsModel
*/
protected $commentsModel;
/**
* Details constructor.
*
* @param \ACP3\Core\Controller\Context\AdminContext $context
* @param \ACP3\Modules\ACP3\Comments\Model\Repository\CommentRepository $commentRepository
* @param \ACP3\Core\Controller\Context\AdminContext $context
* @param Comments\Model\CommentsModel $commentsModel
* @param \ACP3\Modules\ACP3\Comments\Validation\AdminFormValidation $adminFormValidation
* @param \ACP3\Core\Helpers\FormToken $formTokenHelper
* @param \ACP3\Core\Helpers\FormToken $formTokenHelper
*/
public function __construct(
Core\Controller\Context\AdminContext $context,
Comments\Model\Repository\CommentRepository $commentRepository,
Comments\Model\CommentsModel $commentsModel,
Comments\Validation\AdminFormValidation $adminFormValidation,
Core\Helpers\FormToken $formTokenHelper)
{
parent::__construct($context);
$this->commentRepository = $commentRepository;
$this->adminFormValidation = $adminFormValidation;
$this->formTokenHelper = $formTokenHelper;
$this->commentsModel = $commentsModel;
}
/**
......@@ -59,7 +59,7 @@ class Edit extends Core\Controller\AbstractAdminAction
*/
public function execute($id)
{
$comment = $this->commentRepository->getOneById($id);
$comment = $this->commentsModel->getOneById($id);
if (empty($comment) === false) {
$this->breadcrumb
......@@ -105,19 +105,15 @@ class Edit extends Core\Controller\AbstractAdminAction
$this->adminFormValidation->validate($formData);
$updateValues = [
'message' => $this->get('core.helpers.secure')->strEncode($formData['message'])
'message' => $formData['message']
];
if ((empty($comment['user_id']) || $this->validator->is(IntegerValidationRule::class, $comment['user_id']) === false) &&
!empty($formData['name'])
) {
$updateValues['name'] = $this->get('core.helpers.secure')->strEncode($formData['name']);
$updateValues['name'] = $formData['name'];
}
$bool = $this->commentRepository->update($updateValues, $commentId);
Core\Cache\Purge::doPurge($this->appPath->getCacheDir() . 'http');
return $bool;
return $this->commentsModel->save($updateValues, $commentId);
},
'acp/comments/details/index/id_' . $moduleId
);
......
......@@ -14,43 +14,36 @@ use ACP3\Modules\ACP3\Comments;
*/
class Create extends AbstractFrontendAction
{
/**
* @var \ACP3\Core\Date
*/
protected $date;
/**
* @var \ACP3\Core\Helpers\FormToken
*/
protected $formTokenHelper;
/**
* @var \ACP3\Modules\ACP3\Comments\Model\Repository\CommentRepository
*/
protected $commentRepository;
/**
* @var \ACP3\Modules\ACP3\Comments\Validation\FormValidation
*/
protected $formValidation;
/**
* @var Comments\Model\CommentsModel
*/
protected $commentsModel;
/**
* @param \ACP3\Core\Controller\Context\FrontendContext $context
* @param \ACP3\Core\Date $date
* @param \ACP3\Modules\ACP3\Comments\Model\Repository\CommentRepository $commentRepository
* @param \ACP3\Core\Controller\Context\FrontendContext $context
* @param Comments\Model\CommentsModel $commentsModel
* @param \ACP3\Modules\ACP3\Comments\Validation\FormValidation $formValidation
* @param \ACP3\Core\Helpers\FormToken $formTokenHelper
* @param \ACP3\Core\Helpers\FormToken $formTokenHelper
*/
public function __construct(
Core\Controller\Context\FrontendContext $context,
Core\Date $date,
Comments\Model\Repository\CommentRepository $commentRepository,
Comments\Model\CommentsModel $commentsModel,
Comments\Validation\FormValidation $formValidation,
Core\Helpers\FormToken $formTokenHelper)
{
parent::__construct($context);
$this->date = $date;
$this->commentRepository = $commentRepository;
$this->formValidation = $formValidation;
$this->formTokenHelper = $formTokenHelper;
$this->commentsModel = $commentsModel;
}
/**
......@@ -89,20 +82,17 @@ class Create extends AbstractFrontendAction
->setIpAddress($ipAddress)
->validate($formData);
$insertValues = [
'id' => '',
'date' => $this->date->toSQL(),
$columnData = [
'date' => 'now',
'ip' => $ipAddress,
'name' => $this->get('core.helpers.secure')->strEncode($formData['name']),
'name' => $formData['name'],
'user_id' => $this->user->isAuthenticated() === true ? $this->user->getUserId() : null,
'message' => $this->get('core.helpers.secure')->strEncode($formData['message']),
'message' => $formData['message'],
'module_id' => $this->modules->getModuleId($module),
'entry_id' => $entryId,
];
$bool = $this->commentRepository->insert($insertValues);
Core\Cache\Purge::doPurge($this->appPath->getCacheDir() . 'http');
$bool = $this->commentsModel->save($columnData);
return $this->redirectMessages()->setMessage(
$bool,
......
......@@ -10,7 +10,7 @@ services:
class: ACP3\Modules\ACP3\Comments\Controller\Admin\Details\Edit
arguments:
- '@core.context.admin'
- '@comments.model.commentrepository'
- '@comments.model.comments_model'
- '@comments.validation.admin_form_validation'
- '@core.helpers.formToken'
......@@ -45,8 +45,7 @@ services:
class: ACP3\Modules\ACP3\Comments\Controller\Frontend\Index\Create
arguments:
- '@core.context.frontend'
- '@core.date'
- '@comments.model.commentrepository'
- '@comments.model.comments_model'
- '@comments.validator'
- '@core.helpers.formToken'
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment