Implement ical feed for contingents
This commit is contained in:
@@ -27,10 +27,13 @@ namespace EP\EpProducts\Controller;
|
||||
* 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\Product;
|
||||
use EP\EpProducts\Domain\Repository\ContingentRepository;
|
||||
use EP\EpProducts\Service\ContingentDataService;
|
||||
use Kigkonsult\Icalcreator\Vcalendar;
|
||||
use League\Period\Period;
|
||||
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
|
||||
|
||||
class AjaxContingentController extends ActionController
|
||||
@@ -100,4 +103,52 @@ class AjaxContingentController extends ActionController
|
||||
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 = 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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -128,6 +128,7 @@ tx_epproducts_ajax_json {
|
||||
AjaxContingent {
|
||||
1 = list
|
||||
2 = rooms
|
||||
3 = ical
|
||||
}
|
||||
AjaxWatchlist {
|
||||
1 = list
|
||||
@@ -144,6 +145,37 @@ tx_epproducts_ajax_html < tx_epproducts_ajax_json
|
||||
tx_epproducts_ajax_html.typeNum = 1702
|
||||
tx_epproducts_ajax_html.config.additionalHeaders.10.header = Content-type:text/html
|
||||
|
||||
tx_epproducts_ical = PAGE
|
||||
tx_epproducts_ical {
|
||||
typeNum = 1710
|
||||
config {
|
||||
disableAllHeaderCode = 1
|
||||
disablePrefixComment = 1
|
||||
additionalHeaders.1.header = Cache-Control: no-cache, no-store, must-revalidate
|
||||
additionalHeaders.10.header = Content-type: text/calendar
|
||||
additionalHeaders.20.header = Content-disposition: attachment; filename=ep-reisen.ical
|
||||
xhtml_cleaning = 0
|
||||
admPanel = 0
|
||||
debug = 0
|
||||
no_cache = 1
|
||||
}
|
||||
|
||||
10 = USER_INT
|
||||
10 {
|
||||
userFunc = TYPO3\CMS\Extbase\Core\Bootstrap->run
|
||||
extensionName = EpProducts
|
||||
pluginName = ical
|
||||
vendorName = EP
|
||||
controller = AjaxContingent
|
||||
action = ical
|
||||
switchableControllerActions {
|
||||
AjaxContingent {
|
||||
1 = ical
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
lib.bookingWidget = USER
|
||||
lib.bookingWidget {
|
||||
userFunc = TYPO3\CMS\Extbase\Core\Bootstrap->run
|
||||
|
||||
@@ -358,6 +358,17 @@ $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['scheduler']['tasks'][\EP\EpProducts\T
|
||||
]
|
||||
);
|
||||
|
||||
\TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin(
|
||||
'EP.' . $_EXTKEY,
|
||||
'ical',
|
||||
[
|
||||
'AjaxContingent' => 'ical',
|
||||
],
|
||||
[
|
||||
'AjaxContingent' => 'ical',
|
||||
]
|
||||
);
|
||||
|
||||
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/class.tx_cms_layout.php']['tt_content_drawItem']['ep_products'] =
|
||||
\EP\EpProducts\Hook\PageLayoutView::class;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user