Commit 6833fce3 authored by Tino Goratsch's avatar Tino Goratsch

use the GuestbookModel class in the guestbook module some more

parent b1081fdf
......@@ -82,17 +82,13 @@ class Create extends AbstractFrontendAction
->setIpAddress($ipAddress)
->validate($formData);
$columnData = [
'date' => 'now',
'ip' => $ipAddress,
'name' => $formData['name'],
'user_id' => $this->user->isAuthenticated() === true ? $this->user->getUserId() : null,
'message' => $formData['message'],
'module_id' => $this->modules->getModuleId($module),
'entry_id' => $entryId,
];
$formData['date'] = 'now';
$formData['ip'] = $ipAddress;
$formData['user_id'] = $this->user->isAuthenticated() === true ? $this->user->getUserId() : null;
$formData['module_id'] = $this->modules->getModuleId($module);
$formData['entry_id'] = $entryId;
$bool = $this->commentsModel->save($columnData);
$bool = $this->commentsModel->save($formData);
return $this->redirectMessages()->setMessage(
$bool,
......
......@@ -19,10 +19,6 @@ class Edit extends Core\Controller\AbstractAdminAction
* @var \ACP3\Core\Helpers\FormToken
*/
protected $formTokenHelper;
/**
* @var \ACP3\Modules\ACP3\Guestbook\Model\Repository\GuestbookRepository
*/
protected $guestbookRepository;
/**
* @var \ACP3\Modules\ACP3\Guestbook\Validation\AdminFormValidation
*/
......@@ -31,29 +27,33 @@ class Edit extends Core\Controller\AbstractAdminAction
* @var \ACP3\Core\Helpers\Forms
*/
protected $formsHelper;
/**
* @var Guestbook\Model\GuestbookModel
*/
private $guestbookModel;
/**
* Edit constructor.
*
* @param \ACP3\Core\Controller\Context\AdminContext $context
* @param \ACP3\Core\Helpers\Forms $formsHelper
* @param \ACP3\Core\Helpers\FormToken $formTokenHelper
* @param \ACP3\Modules\ACP3\Guestbook\Model\Repository\GuestbookRepository $guestbookRepository
* @param \ACP3\Core\Controller\Context\AdminContext $context
* @param \ACP3\Core\Helpers\Forms $formsHelper
* @param \ACP3\Core\Helpers\FormToken $formTokenHelper
* @param Guestbook\Model\GuestbookModel $guestbookModel
* @param \ACP3\Modules\ACP3\Guestbook\Validation\AdminFormValidation $adminFormValidation
*/
public function __construct(
Core\Controller\Context\AdminContext $context,
Core\Helpers\Forms $formsHelper,
Core\Helpers\FormToken $formTokenHelper,
Guestbook\Model\Repository\GuestbookRepository $guestbookRepository,
Guestbook\Model\GuestbookModel $guestbookModel,
Guestbook\Validation\AdminFormValidation $adminFormValidation
) {
parent::__construct($context);
$this->formsHelper = $formsHelper;
$this->formTokenHelper = $formTokenHelper;
$this->guestbookRepository = $guestbookRepository;
$this->adminFormValidation = $adminFormValidation;
$this->guestbookModel = $guestbookModel;
}
/**
......@@ -64,7 +64,7 @@ class Edit extends Core\Controller\AbstractAdminAction
*/
public function execute($id)
{
$guestbook = $this->guestbookRepository->getOneById($id);
$guestbook = $this->guestbookModel->getOneById($id);
if (empty($guestbook) === false) {
$settings = $this->config->getSettings(Guestbook\Installer\Schema::MODULE_NAME);
......@@ -90,7 +90,7 @@ class Edit extends Core\Controller\AbstractAdminAction
/**
* @param array $formData
* @param array $settings
* @param int $guestbookId
* @param int $guestbookId
*
* @return \Symfony\Component\HttpFoundation\RedirectResponse
*/
......@@ -101,14 +101,9 @@ class Edit extends Core\Controller\AbstractAdminAction
->setSettings($settings)
->validate($formData);
$updateValues = [
'message' => $this->get('core.helpers.secure')->strEncode($formData['message']),
'active' => $settings['notify'] == 2 ? $formData['active'] : 1,
];
$bool = $this->guestbookRepository->update($updateValues, $guestbookId);
$formData['active'] = $settings['notify'] == 2 ? $formData['active'] : 1;
Core\Cache\Purge::doPurge($this->appPath->getCacheDir() . 'http');
$bool = $this->guestbookModel->save($formData, $guestbookId);
return $bool;
});
......
......@@ -16,18 +16,10 @@ use ACP3\Modules\ACP3\Seo\Installer\Schema;
*/
class Create extends AbstractAction
{
/**
* @var \ACP3\Core\Date
*/
protected $date;
/**
* @var \ACP3\Core\Helpers\FormToken
*/
protected $formTokenHelper;
/**
* @var \ACP3\Modules\ACP3\Guestbook\Model\Repository\GuestbookRepository
*/
protected $guestbookRepository;
/**
* @var \ACP3\Modules\ACP3\Guestbook\Validation\FormValidation
*/
......@@ -40,6 +32,10 @@ class Create extends AbstractAction
* @var \ACP3\Core\Helpers\Forms
*/
protected $formsHelper;
/**
* @var Guestbook\Model\GuestbookModel
*/
protected $guestbookModel;
/**
* @var bool
*/
......@@ -49,27 +45,24 @@ class Create extends AbstractAction
* Create constructor.
*
* @param \ACP3\Core\Controller\Context\FrontendContext $context
* @param \ACP3\Core\Date $date
* @param \ACP3\Core\Helpers\Forms $formsHelper
* @param \ACP3\Core\Helpers\FormToken $formTokenHelper
* @param \ACP3\Modules\ACP3\Guestbook\Model\Repository\GuestbookRepository $guestbookRepository
* @param Guestbook\Model\GuestbookModel $guestbookModel
* @param \ACP3\Modules\ACP3\Guestbook\Validation\FormValidation $formValidation
*/
public function __construct(
Core\Controller\Context\FrontendContext $context,
Core\Date $date,
Core\Helpers\Forms $formsHelper,
Core\Helpers\FormToken $formTokenHelper,
Guestbook\Model\Repository\GuestbookRepository $guestbookRepository,
Guestbook\Model\GuestbookModel $guestbookModel,
Guestbook\Validation\FormValidation $formValidation
) {
parent::__construct($context);
$this->date = $date;
$this->formsHelper = $formsHelper;
$this->formTokenHelper = $formTokenHelper;
$this->guestbookRepository = $guestbookRepository;
$this->formValidation = $formValidation;
$this->guestbookModel = $guestbookModel;
}
public function preDispatch()
......@@ -137,19 +130,12 @@ class Create extends AbstractAction
->setNewsletterAccess($this->newsletterActive)
->validate($formData);
$insertValues = [
'id' => '',
'date' => $this->date->toSQL(),
'ip' => $ipAddress,
'name' => $this->get('core.helpers.secure')->strEncode($formData['name']),
'user_id' => $this->user->isAuthenticated() ? $this->user->getUserId() : null,
'message' => $this->get('core.helpers.secure')->strEncode($formData['message']),
'website' => $this->get('core.helpers.secure')->strEncode($formData['website']),
'mail' => $formData['mail'],
'active' => $this->guestbookSettings['notify'] == 2 ? 0 : 1,
];
$formData['date'] = 'now';
$formData['ip'] = $ipAddress;
$formData['user_id'] = $this->user->isAuthenticated() ? $this->user->getUserId() : null;
$formData['active'] = $this->guestbookSettings['notify'] == 2 ? 0 : 1;
$lastId = $this->guestbookRepository->insert($insertValues);
$lastId = $this->guestbookModel->save($formData);
if ($this->guestbookSettings['notify'] == 1 || $this->guestbookSettings['notify'] == 2) {
$this->sendNotificationEmail($lastId);
......@@ -164,8 +150,6 @@ class Create extends AbstractAction
$this->newsletterSubscribeHelper->subscribeToNewsletter($formData['mail']);
}
Core\Cache\Purge::doPurge($this->appPath->getCacheDir() . 'http');
return $this->redirectMessages()->setMessage(
$lastId,
$this->translator->t('system', $lastId !== false ? 'create_success' : 'create_error')
......
......@@ -11,7 +11,7 @@ services:
- '@core.context.admin'
- '@core.helpers.forms'
- '@core.helpers.formToken'
- '@guestbook.model.guestbookrepository'
- '@guestbook.model.guestbook_model'
- '@guestbook.validation.admin_form_validation'
guestbook.controller.admin.index.index:
......@@ -32,10 +32,9 @@ services:
class: ACP3\Modules\ACP3\Guestbook\Controller\Frontend\Index\Create
arguments:
- '@core.context.frontend'
- '@core.date'
- '@core.helpers.forms'
- '@core.helpers.formToken'
- '@guestbook.model.guestbookrepository'
- '@guestbook.model.guestbook_model'
- '@guestbook.validator'
calls:
- ['setNewsletterSubscribeHelper', ['@?newsletter.helper.subscribe']]
......
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