Improve code by implementing dto class
This commit is contained in:
@@ -26,12 +26,13 @@ namespace EP\EpProducts\Controller;
|
||||
* This copyright notice MUST APPEAR in all copies of the script!
|
||||
***************************************************************/
|
||||
|
||||
use EP\EpProducts\Domain\Model\Dto\GroupsPriceInquiry;
|
||||
use EP\EpProducts\Domain\Model\GroupsPriceBoard;
|
||||
use EP\EpProducts\Domain\Model\Hotel;
|
||||
use EP\EpProducts\Domain\Repository\GroupsPriceOptionRepository;
|
||||
use EP\EpProducts\Service\EmailService;
|
||||
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
|
||||
use TYPO3\CMS\Extbase\Annotation as Extbase;
|
||||
use TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException;
|
||||
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
|
||||
|
||||
class AjaxGroupsPriceController extends ActionController
|
||||
@@ -56,47 +57,47 @@ class AjaxGroupsPriceController extends ActionController
|
||||
|
||||
public function initializeProcessFormAction()
|
||||
{
|
||||
if ($this->request->hasArgument('options')) {
|
||||
$optionUids = $this->request->getArgument('options');
|
||||
$options = $this->groupsPriceOptionRepository->findByUids($optionUids)->toArray();
|
||||
$this->request->setArgument('options', $options);
|
||||
if ($this->request->hasArgument('groupsPriceInquiry')) {
|
||||
$this->arguments->getArgument('groupsPriceInquiry')
|
||||
->getPropertyMappingConfiguration()->allowAllProperties();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Hotel $hotel
|
||||
* @param string $name
|
||||
* @param string $email
|
||||
* @param string $dateFrom
|
||||
* @param string $dateTo
|
||||
* @param int $pax
|
||||
* @param array $options
|
||||
* @param GroupsPriceBoard $board
|
||||
*
|
||||
* @Extbase\Validate("NotEmpty", param="name")
|
||||
* @Extbase\Validate("NotEmpty", param="email")
|
||||
* @Extbase\Validate("EmailAddress", param="email")
|
||||
* @param GroupsPriceInquiry $groupsPriceInquiry
|
||||
* @return string
|
||||
*/
|
||||
public function processFormAction(Hotel $hotel, $name, $email, $dateFrom, $dateTo, $pax = 30, array $options = [], GroupsPriceBoard $board = null)
|
||||
public function processFormAction(Hotel $hotel, GroupsPriceInquiry $groupsPriceInquiry)
|
||||
{
|
||||
$emailOptions = [
|
||||
'toEmail' => $this->settings['groupsPriceToEmail'],
|
||||
'toName' => $this->settings['groupsPriceToName'],
|
||||
'fromEmail' => $this->settings['groupsPriceToEmail'],
|
||||
'fromName' => $this->settings['groupsPriceToName'],
|
||||
'subject' => 'Gruppenhaus Preiskalkulator/Anfrage',
|
||||
'subject' => 'Gruppenhaus Preisberechnung/Anfrage',
|
||||
'templateName' => 'GroupsPrice',
|
||||
];
|
||||
|
||||
try {
|
||||
$selectedOptions = $this->groupsPriceOptionRepository->findByUids($groupsPriceInquiry->getOptions());
|
||||
}
|
||||
catch (InvalidQueryException $e) {
|
||||
$selectedOptions = [];
|
||||
}
|
||||
|
||||
$variables = [
|
||||
'hotel' => $hotel,
|
||||
'name' => $name,
|
||||
'email' => $email,
|
||||
'dateFrom' => $dateFrom,
|
||||
'dateTo' => $dateTo,
|
||||
'pax' => $pax,
|
||||
'options' => $this->groupsPriceOptionRepository->findByUids($options)->toArray(),
|
||||
'board' => $board,
|
||||
'name' => $groupsPriceInquiry->getName(),
|
||||
'email' => $groupsPriceInquiry->getEmail(),
|
||||
'phone' => $groupsPriceInquiry->getPhone(),
|
||||
'remarks' => $groupsPriceInquiry->getRemarks(),
|
||||
'dateFrom' => $groupsPriceInquiry->getDateFrom(),
|
||||
'dateTo' => $groupsPriceInquiry->getDateTo(),
|
||||
'pax' => $groupsPriceInquiry->getPax(),
|
||||
'options' => $selectedOptions,
|
||||
'board' => $groupsPriceInquiry->getBoard(),
|
||||
'summary' => $groupsPriceInquiry->getSummary(),
|
||||
];
|
||||
|
||||
$this->emailService->send($emailOptions, $variables);
|
||||
|
||||
@@ -0,0 +1,247 @@
|
||||
<?php
|
||||
namespace EP\EpProducts\Domain\Model\Dto;
|
||||
|
||||
/***************************************************************
|
||||
*
|
||||
* Copyright notice
|
||||
*
|
||||
* (c) 2020 Björn Fromme <[email protected]>, dreipunktnull
|
||||
*
|
||||
* All rights reserved
|
||||
*
|
||||
* This script is part of the TYPO3 project. The TYPO3 project is
|
||||
* free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* The GNU General Public License can be found at
|
||||
* http://www.gnu.org/copyleft/gpl.html.
|
||||
*
|
||||
* This script is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* This copyright notice MUST APPEAR in all copies of the script!
|
||||
***************************************************************/
|
||||
|
||||
class GroupsPriceInquiry
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
* @TYPO3\CMS\Extbase\Annotation\Validate("NotEmpty")
|
||||
*/
|
||||
protected $name;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
* @TYPO3\CMS\Extbase\Annotation\Validate("NotEmpty")
|
||||
* @TYPO3\CMS\Extbase\Annotation\Validate("EmailAddress")
|
||||
*/
|
||||
protected $email;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
* @TYPO3\CMS\Extbase\Annotation\Validate("NotEmpty")
|
||||
*/
|
||||
protected $phone;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $remarks;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
* @TYPO3\CMS\Extbase\Annotation\Validate("NotEmpty")
|
||||
*/
|
||||
protected $dateFrom;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
* @TYPO3\CMS\Extbase\Annotation\Validate("NotEmpty")
|
||||
*/
|
||||
protected $dateTo;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
* @TYPO3\CMS\Extbase\Annotation\Validate("NotEmpty")
|
||||
*/
|
||||
protected $pax;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $options = [];
|
||||
|
||||
/**
|
||||
* @var \EP\EpProducts\Domain\Model\GroupsPriceBoard
|
||||
*/
|
||||
protected $board;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $summary;
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
*/
|
||||
public function setName($name)
|
||||
{
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getEmail()
|
||||
{
|
||||
return $this->email;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $email
|
||||
*/
|
||||
public function setEmail($email)
|
||||
{
|
||||
$this->email = $email;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getPhone()
|
||||
{
|
||||
return $this->phone;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $phone
|
||||
*/
|
||||
public function setPhone($phone)
|
||||
{
|
||||
$this->phone = $phone;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getRemarks()
|
||||
{
|
||||
return $this->remarks;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $remarks
|
||||
*/
|
||||
public function setRemarks($remarks)
|
||||
{
|
||||
$this->remarks = $remarks;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getDateFrom()
|
||||
{
|
||||
return $this->dateFrom;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $dateFrom
|
||||
*/
|
||||
public function setDateFrom($dateFrom)
|
||||
{
|
||||
$this->dateFrom = $dateFrom;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getDateTo()
|
||||
{
|
||||
return $this->dateTo;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $dateTo
|
||||
*/
|
||||
public function setDateTo($dateTo)
|
||||
{
|
||||
$this->dateTo = $dateTo;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getPax()
|
||||
{
|
||||
return $this->pax;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $pax
|
||||
*/
|
||||
public function setPax($pax)
|
||||
{
|
||||
$this->pax = $pax;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getOptions()
|
||||
{
|
||||
return $this->options;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $options
|
||||
*/
|
||||
public function setOptions(array $options = [])
|
||||
{
|
||||
$this->options = $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \EP\EpProducts\Domain\Model\GroupsPriceBoard
|
||||
*/
|
||||
public function getBoard()
|
||||
{
|
||||
return $this->board;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \EP\EpProducts\Domain\Model\GroupsPriceBoard $board
|
||||
*/
|
||||
public function setBoard(\EP\EpProducts\Domain\Model\GroupsPriceBoard $board = null)
|
||||
{
|
||||
$this->board = $board;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getSummary()
|
||||
{
|
||||
return $this->summary;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $summary
|
||||
*/
|
||||
public function setSummary(array $summary)
|
||||
{
|
||||
$this->summary = $summary;
|
||||
}
|
||||
}
|
||||
+10
-1
@@ -32,8 +32,17 @@ use TYPO3\CMS\Extbase\Persistence\Repository;
|
||||
|
||||
class GroupsPriceOptionRepository extends Repository
|
||||
{
|
||||
/**
|
||||
* @param array $uids
|
||||
* @return array
|
||||
* @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException
|
||||
*/
|
||||
public function findByUids(array $uids)
|
||||
{
|
||||
if (0 === count($uids)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
/** @var Typo3QuerySettings $querySettings */
|
||||
$querySettings = $this->objectManager->get(Typo3QuerySettings::class);
|
||||
$querySettings->setRespectStoragePage(false);
|
||||
@@ -42,6 +51,6 @@ class GroupsPriceOptionRepository extends Repository
|
||||
$query = $this->createQuery();
|
||||
$query->matching($query->in('uid', $uids));
|
||||
|
||||
return $query->execute();
|
||||
return $query->execute()->toArray();
|
||||
}
|
||||
}
|
||||
|
||||
+10
-10
@@ -208,16 +208,16 @@
|
||||
options.push(option.uid);
|
||||
}
|
||||
let formData = {
|
||||
'tx_epproducts_ajax[name]': this.name,
|
||||
'tx_epproducts_ajax[email]': this.email,
|
||||
'tx_epproducts_ajax[phone]': this.phone,
|
||||
'tx_epproducts_ajax[remarks]': this.remarks,
|
||||
'tx_epproducts_ajax[dateFrom]': this.selectedFrom.format('DD.MM.YYYY'),
|
||||
'tx_epproducts_ajax[dateTo]': this.selectedTo.format('DD.MM.YYYY'),
|
||||
'tx_epproducts_ajax[pax]': this.selectedPax,
|
||||
'tx_epproducts_ajax[board]': this.selectedBoard ? this.selectedBoard.uid : null,
|
||||
'tx_epproducts_ajax[options]': options,
|
||||
'tx_epproducts_ajax[summary]': this.priceSummary
|
||||
'tx_epproducts_ajax[groupsPriceInquiry][name]': this.name,
|
||||
'tx_epproducts_ajax[groupsPriceInquiry][email]': this.email,
|
||||
'tx_epproducts_ajax[groupsPriceInquiry][phone]': this.phone,
|
||||
'tx_epproducts_ajax[groupsPriceInquiry][remarks]': this.remarks,
|
||||
'tx_epproducts_ajax[groupsPriceInquiry][dateFrom]': this.selectedFrom.format('DD.MM.YYYY'),
|
||||
'tx_epproducts_ajax[groupsPriceInquiry][dateTo]': this.selectedTo.format('DD.MM.YYYY'),
|
||||
'tx_epproducts_ajax[groupsPriceInquiry][pax]': this.selectedPax,
|
||||
'tx_epproducts_ajax[groupsPriceInquiry][board]': this.selectedBoard ? this.selectedBoard.uid : null,
|
||||
'tx_epproducts_ajax[groupsPriceInquiry][options]': options,
|
||||
'tx_epproducts_ajax[groupsPriceInquiry][summary]': this.priceSummary
|
||||
};
|
||||
this.processing = true;
|
||||
this.submitted = false;
|
||||
|
||||
Reference in New Issue
Block a user