Refactor ical action to dedicated controller, add route enhancer
This commit is contained in:
@@ -168,6 +168,22 @@ routeEnhancers:
|
|||||||
defaultController: 'Search::staticresult'
|
defaultController: 'Search::staticresult'
|
||||||
requirements:
|
requirements:
|
||||||
filter_settings: '[A-Z\d%\-]+'
|
filter_settings: '[A-Z\d%\-]+'
|
||||||
|
ContingentsIcalPlugin:
|
||||||
|
type: Extbase
|
||||||
|
extension: EpProducts
|
||||||
|
plugin: ical
|
||||||
|
routes:
|
||||||
|
-
|
||||||
|
routePath: '/contingents/{hotel}'
|
||||||
|
_controller: 'Ical::contingents'
|
||||||
|
_arguments:
|
||||||
|
hotel: hotel
|
||||||
|
defaultController: 'Ical::contingents'
|
||||||
|
aspects:
|
||||||
|
hotel:
|
||||||
|
type: PersistedAliasMapper
|
||||||
|
tableName: tx_epproducts_domain_model_hotel
|
||||||
|
routeFieldName: path_segment
|
||||||
ResellerPlugin:
|
ResellerPlugin:
|
||||||
type: Extbase
|
type: Extbase
|
||||||
extension: EpProducts
|
extension: EpProducts
|
||||||
@@ -220,5 +236,6 @@ routeEnhancers:
|
|||||||
'/json': 1701
|
'/json': 1701
|
||||||
'/html': 1702
|
'/html': 1702
|
||||||
'.json': 1803
|
'.json': 1803
|
||||||
|
'.ical': 1710
|
||||||
'sitemap.xml': 1533906435
|
'sitemap.xml': 1533906435
|
||||||
'yoast-snippetpreview.json': 1480321830
|
'yoast-snippetpreview.json': 1480321830
|
||||||
|
|||||||
@@ -27,13 +27,10 @@ namespace EP\EpProducts\Controller;
|
|||||||
* This copyright notice MUST APPEAR in all copies of the script!
|
* This copyright notice MUST APPEAR in all copies of the script!
|
||||||
***************************************************************/
|
***************************************************************/
|
||||||
|
|
||||||
use EP\EpProducts\Domain\Model\Contingent;
|
|
||||||
use EP\EpProducts\Domain\Model\Hotel;
|
use EP\EpProducts\Domain\Model\Hotel;
|
||||||
use EP\EpProducts\Domain\Model\Product;
|
use EP\EpProducts\Domain\Model\Product;
|
||||||
use EP\EpProducts\Domain\Repository\ContingentRepository;
|
use EP\EpProducts\Domain\Repository\ContingentRepository;
|
||||||
use EP\EpProducts\Service\ContingentDataService;
|
use EP\EpProducts\Service\ContingentDataService;
|
||||||
use Kigkonsult\Icalcreator\Vcalendar;
|
|
||||||
use League\Period\Period;
|
|
||||||
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
|
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
|
||||||
|
|
||||||
class AjaxContingentController extends ActionController
|
class AjaxContingentController extends ActionController
|
||||||
@@ -103,52 +100,4 @@ class AjaxContingentController extends ActionController
|
|||||||
return \json_encode($rooms);
|
return \json_encode($rooms);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param Hotel $hotel
|
|
||||||
* @param string $year
|
|
||||||
* @param string $month
|
|
||||||
* @param int $months
|
|
||||||
*/
|
|
||||||
public function icalAction(Hotel $hotel)
|
|
||||||
{
|
|
||||||
$range = Period::after(new \DateTime('now'), '1 year');
|
|
||||||
|
|
||||||
$events = $this->contingentRepository->getEvents(
|
|
||||||
\DateTime::createFromImmutable($range->getStartDate()),
|
|
||||||
\DateTime::createFromImmutable($range->getEndDate()),
|
|
||||||
['hotel' => $hotel]
|
|
||||||
);
|
|
||||||
|
|
||||||
$vcalendar = Vcalendar::factory([ Vcalendar::UNIQUE_ID => 'www.ep-reisen.de' ]);
|
|
||||||
|
|
||||||
foreach ($events as $event) {
|
|
||||||
/** @var Contingent $event */
|
|
||||||
$paxTotal = $event->getPax();
|
|
||||||
$paxAvaiable = $event->getAvailable();
|
|
||||||
|
|
||||||
if ($paxTotal > 0) {
|
|
||||||
$percentageBooked = 100 - round($paxAvaiable / $paxTotal * 100);
|
|
||||||
} else {
|
|
||||||
$percentageBooked = 100;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($percentageBooked >= 75) {
|
|
||||||
$dtStart = $event->getBegin();
|
|
||||||
$dtEnd = clone $event->getBegin();
|
|
||||||
$dtEnd->modify('+1 day');
|
|
||||||
$vcalendar
|
|
||||||
->newVevent()
|
|
||||||
->setDtstart($dtStart)
|
|
||||||
->setDtend($dtEnd)
|
|
||||||
->setSummary('Unavailable')
|
|
||||||
->setDescription(sprintf('Unavailable on %s', $dtStart->format('d M Y')))
|
|
||||||
;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return $vcalendar->vtimezonePopulate()->createCalendar();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,102 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace EP\EpProducts\Controller;
|
||||||
|
|
||||||
|
/***************************************************************
|
||||||
|
*
|
||||||
|
* Copyright notice
|
||||||
|
*
|
||||||
|
* (c) 2016 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!
|
||||||
|
***************************************************************/
|
||||||
|
|
||||||
|
use EP\EpProducts\Domain\Model\Contingent;
|
||||||
|
use EP\EpProducts\Domain\Model\Hotel;
|
||||||
|
use EP\EpProducts\Domain\Repository\ContingentRepository;
|
||||||
|
use Kigkonsult\Icalcreator\Vcalendar;
|
||||||
|
use League\Period\Period;
|
||||||
|
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
|
||||||
|
|
||||||
|
class IcalController extends ActionController
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var \EP\EpProducts\Domain\Repository\ContingentRepository
|
||||||
|
*/
|
||||||
|
protected $contingentRepository;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param ContingentRepository $contingentRepository
|
||||||
|
*/
|
||||||
|
public function __construct(ContingentRepository $contingentRepository)
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
|
||||||
|
$this->contingentRepository = $contingentRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Hotel $hotel
|
||||||
|
* @param string $year
|
||||||
|
* @param string $month
|
||||||
|
* @param int $months
|
||||||
|
*/
|
||||||
|
public function contingentsAction(Hotel $hotel)
|
||||||
|
{
|
||||||
|
$range = Period::after(new \DateTime('now'), '1 year');
|
||||||
|
|
||||||
|
$events = $this->contingentRepository->getEvents(
|
||||||
|
\DateTime::createFromImmutable($range->getStartDate()),
|
||||||
|
\DateTime::createFromImmutable($range->getEndDate()),
|
||||||
|
['hotel' => $hotel]
|
||||||
|
);
|
||||||
|
|
||||||
|
$vcalendar = Vcalendar::factory([ Vcalendar::UNIQUE_ID => 'www.ep-reisen.de' ]);
|
||||||
|
|
||||||
|
foreach ($events as $event) {
|
||||||
|
/** @var Contingent $event */
|
||||||
|
$paxTotal = $event->getPax();
|
||||||
|
$paxAvaiable = $event->getAvailable();
|
||||||
|
|
||||||
|
if ($paxTotal > 0) {
|
||||||
|
$percentageBooked = 100 - round($paxAvaiable / $paxTotal * 100);
|
||||||
|
} else {
|
||||||
|
$percentageBooked = 100;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($percentageBooked >= 75) {
|
||||||
|
$dtStart = $event->getBegin();
|
||||||
|
$dtEnd = clone $event->getBegin();
|
||||||
|
$dtEnd->modify('+1 day');
|
||||||
|
$vcalendar
|
||||||
|
->newVevent()
|
||||||
|
->setDtstart($dtStart)
|
||||||
|
->setDtend($dtEnd)
|
||||||
|
->setSummary('Unavailable')
|
||||||
|
->setDescription(sprintf('Unavailable on %s', $dtStart->format('d M Y')))
|
||||||
|
;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
header(sprintf('Content-disposition: attachment; filename=%s.ical', $hotel->getPathSegment()));
|
||||||
|
|
||||||
|
return $vcalendar->vtimezonePopulate()->createCalendar();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -241,6 +241,11 @@ class Hotel extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity implements Te
|
|||||||
*/
|
*/
|
||||||
protected $externalLink;
|
protected $externalLink;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $pathSegment;
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->initStorageObjects();
|
$this->initStorageObjects();
|
||||||
@@ -923,6 +928,14 @@ class Hotel extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity implements Te
|
|||||||
return $this->externalLink;
|
return $this->externalLink;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getPathSegment()
|
||||||
|
{
|
||||||
|
return $this->pathSegment;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $externalLink
|
* @param string $externalLink
|
||||||
*/
|
*/
|
||||||
|
|||||||
+18
-2
@@ -28,7 +28,7 @@ return [
|
|||||||
address, longitude, latitude, headline, teaser, description, features, room_types, additional_information,
|
address, longitude, latitude, headline, teaser, description, features, room_types, additional_information,
|
||||||
teaser_images, header_images, images, reseller_images, code, type, category, country, region, city, facts,
|
teaser_images, header_images, images, reseller_images, code, type, category, country, region, city, facts,
|
||||||
teamer, products, header_title,header_subtitle, earlybird, new, low_contingent, show_as_teaser,
|
teamer, products, header_title,header_subtitle, earlybird, new, low_contingent, show_as_teaser,
|
||||||
external_link',
|
external_link, path_segment',
|
||||||
],
|
],
|
||||||
'types' => [
|
'types' => [
|
||||||
'1' => [
|
'1' => [
|
||||||
@@ -41,7 +41,7 @@ return [
|
|||||||
],
|
],
|
||||||
'palettes' => [
|
'palettes' => [
|
||||||
'top' => ['showitem' => 'hidden,earlybird,new,low_contingent,show_as_teaser,
|
'top' => ['showitem' => 'hidden,earlybird,new,low_contingent,show_as_teaser,
|
||||||
--linebreak--,code,groupsch_id,detail_page,--linebreak--,external_link'],
|
--linebreak--,code,groupsch_id,detail_page,--linebreak--,external_link,path_segment'],
|
||||||
'geolocation' => ['showitem' => 'address, longitude, latitude'],
|
'geolocation' => ['showitem' => 'address, longitude, latitude'],
|
||||||
'destinations' => ['showitem' => 'country,region,city'],
|
'destinations' => ['showitem' => 'country,region,city'],
|
||||||
'name' => ['showitem' => 'name,short_name,--linebreak--,header_title,header_subtitle,--linebreak--,headline'],
|
'name' => ['showitem' => 'name,short_name,--linebreak--,header_title,header_subtitle,--linebreak--,headline'],
|
||||||
@@ -638,5 +638,21 @@ return [
|
|||||||
'eval' => 'trim',
|
'eval' => 'trim',
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
|
'path_segment' => [
|
||||||
|
'exclude' => 0,
|
||||||
|
'label' => 'URL Segment',
|
||||||
|
'config' => [
|
||||||
|
'type' => 'slug',
|
||||||
|
'generatorOptions' => [
|
||||||
|
'fields' => ['name'],
|
||||||
|
'prefixParentPageSlug' => false,
|
||||||
|
'replacements' => [
|
||||||
|
'/' => '-',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
'fallbackCharacter' => '-',
|
||||||
|
'eval' => 'uniqueInSite',
|
||||||
|
],
|
||||||
|
],
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -153,7 +153,6 @@ tx_epproducts_ical {
|
|||||||
disablePrefixComment = 1
|
disablePrefixComment = 1
|
||||||
additionalHeaders.1.header = Cache-Control: no-cache, no-store, must-revalidate
|
additionalHeaders.1.header = Cache-Control: no-cache, no-store, must-revalidate
|
||||||
additionalHeaders.10.header = Content-type: text/calendar
|
additionalHeaders.10.header = Content-type: text/calendar
|
||||||
additionalHeaders.20.header = Content-disposition: attachment; filename=ep-reisen.ical
|
|
||||||
xhtml_cleaning = 0
|
xhtml_cleaning = 0
|
||||||
admPanel = 0
|
admPanel = 0
|
||||||
debug = 0
|
debug = 0
|
||||||
@@ -166,11 +165,11 @@ tx_epproducts_ical {
|
|||||||
extensionName = EpProducts
|
extensionName = EpProducts
|
||||||
pluginName = ical
|
pluginName = ical
|
||||||
vendorName = EP
|
vendorName = EP
|
||||||
controller = AjaxContingent
|
controller = Ical
|
||||||
action = ical
|
action = contingents
|
||||||
switchableControllerActions {
|
switchableControllerActions {
|
||||||
AjaxContingent {
|
Ical {
|
||||||
1 = ical
|
1 = contingents
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -362,10 +362,10 @@ $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['scheduler']['tasks'][\EP\EpProducts\T
|
|||||||
'EP.' . $_EXTKEY,
|
'EP.' . $_EXTKEY,
|
||||||
'ical',
|
'ical',
|
||||||
[
|
[
|
||||||
'AjaxContingent' => 'ical',
|
'Ical' => 'contingents',
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'AjaxContingent' => 'ical',
|
'Ical' => 'contingents',
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -224,6 +224,7 @@ CREATE TABLE tx_epproducts_domain_model_hotel
|
|||||||
code varchar(255) DEFAULT '' NOT NULL,
|
code varchar(255) DEFAULT '' NOT NULL,
|
||||||
groupsch_id varchar(8) DEFAULT '' NOT NULL,
|
groupsch_id varchar(8) DEFAULT '' NOT NULL,
|
||||||
external_link varchar(255) DEFAULT '' NOT NULL,
|
external_link varchar(255) DEFAULT '' NOT NULL,
|
||||||
|
path_segment varchar(255) DEFAULT '' NOT NULL,
|
||||||
type varchar(255) DEFAULT '' NOT NULL,
|
type varchar(255) DEFAULT '' NOT NULL,
|
||||||
category int(11) DEFAULT '0' NOT NULL,
|
category int(11) DEFAULT '0' NOT NULL,
|
||||||
country int(11) unsigned DEFAULT '0',
|
country int(11) unsigned DEFAULT '0',
|
||||||
|
|||||||
Reference in New Issue
Block a user