-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #82 from jweiland-net/featureApi
Add public API
- Loading branch information
Showing
13 changed files
with
492 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the package jweiland/reserve. | ||
* | ||
* For the full copyright and license information, please read the | ||
* LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
namespace JWeiland\Reserve\Service; | ||
|
||
use JWeiland\Reserve\Domain\Repository\PeriodRepository; | ||
|
||
/** | ||
* Official public API class for ext:reserve | ||
* | ||
* @api | ||
*/ | ||
class ReserveService | ||
{ | ||
/** | ||
* @var PeriodRepository | ||
*/ | ||
protected $periodRepository; | ||
|
||
public function __construct(PeriodRepository $periodRepository) | ||
{ | ||
$this->periodRepository = $periodRepository; | ||
} | ||
|
||
/** | ||
* @param int $facilityUid | ||
* @param \DateTime $dateTime DateTime that contains the date of field "date" and time of field "begin" | ||
* @return array | ||
*/ | ||
public function findPeriodsByDateAndBegin(int $facilityUid, \DateTime $dateTime): array | ||
{ | ||
return $this->periodRepository->findByDateAndBegin($dateTime, $facilityUid)->toArray(); | ||
} | ||
|
||
/** | ||
* @param int $facilityUid | ||
* @param \DateTime $dateTimeOfPeriod DateTime that contains the date of field "date" and time of field "begin" | ||
* @return int|null | ||
*/ | ||
public function getRemainingParticipants(int $facilityUid, \DateTime $dateTimeOfPeriod): ?int | ||
{ | ||
$periods = $this->findPeriodsByDateAndBegin($facilityUid, $dateTimeOfPeriod); | ||
$remainingParticipants = null; | ||
if ($periods) { | ||
$remainingParticipants = reset($periods)->getRemainingParticipants(); | ||
} | ||
return $remainingParticipants; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
.. include:: ../Includes.txt | ||
|
||
.. _extend-reserve: | ||
|
||
============== | ||
Extend reserve | ||
============== | ||
|
||
The class `JWeiland\Reserve\Service\ReserveService` is the official public API for ext:reserve. | ||
You can use this class in your own extension to get some information like remaining participants of a period. | ||
|
||
If you want even more, then you can use the other Service classes, Repositories and so on too but make sure that some | ||
functionality can change in upcoming versions. We try to keep compatibility but sometimes breaking changes are required. | ||
|
||
|
||
.. toctree:: | ||
:maxdepth: 2 | ||
|
||
ReserveService/Index | ||
UpdateTemplates/Index |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
.. include:: ../Includes.txt | ||
|
||
.. reserve-service: | ||
=============== | ||
Reserve service | ||
=============== | ||
|
||
The class `JWeiland\Reserve\Service\ReserveService` is the official public API for ext:reserve. | ||
You can use this class in your own extension to get some information like remaining participants of a period. | ||
|
||
The following example shows a controller that uses FlexForms or TypoScript for Facility and DateTime selection. This selection will be used | ||
to get the remaining participants of a matching period. | ||
|
||
.. code-block:: php | ||
<?php | ||
declare(strict_types=1); | ||
/* | ||
* This file is part of the package my/example. | ||
* | ||
* For the full copyright and license information, please read the | ||
* LICENSE file that was distributed with this source code. | ||
*/ | ||
namespace My\Example\Controller; | ||
use JWeiland\Reserve\Service\ReserveService; | ||
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController; | ||
class ExampleController extends ActionController | ||
{ | ||
/** | ||
* @var ReserveService | ||
*/ | ||
protected $reserveService; | ||
public function __construct(ReserveService $reserveService) | ||
{ | ||
$this->reserveService = $reserveService; | ||
} | ||
public function showAction(): void | ||
{ | ||
$dateTime = new \DateTime(); | ||
$dateTime->setTimestamp((int)$this->settings['dateTimeOfEvent']); | ||
$this->view->assign( | ||
'remainingParticipants', | ||
$this->reserveService->getRemainingParticipants((int)$this->settings['facility'], $dateTime) | ||
); | ||
} | ||
} | ||
The FlexForms.xml may look like this. | ||
|
||
.. code-block:: xml | ||
<?xml version="1.0" encoding="utf-8" standalone="yes" ?> | ||
<T3DataStructure> | ||
<sheets> | ||
<sDEF> | ||
<ROOT> | ||
<TCEforms> | ||
<sheetTitle>Main</sheetTitle> | ||
</TCEforms> | ||
<type>array</type> | ||
<el> | ||
<settings.dateTimeOfEvent> | ||
<label>Date of the event</label> | ||
<config> | ||
<type>input</type> | ||
<size>10</size> | ||
<renderType>inputDateTime</renderType> | ||
<eval>datetime</eval> | ||
<default>0</default> | ||
</config> | ||
</settings.dateTimeOfEvent> | ||
<settings.facility> | ||
<TCEforms> | ||
<label>Choose a Facility</label> | ||
<config> | ||
<type>group</type> | ||
<internal_type>db</internal_type> | ||
<allowed>tx_reserve_domain_model_facility</allowed> | ||
<maxitems>1</maxitems> | ||
<minitems>1</minitems> | ||
<size>1</size> | ||
<default>0</default> | ||
</config> | ||
</TCEforms> | ||
</settings.facility> | ||
</el> | ||
</ROOT> | ||
</sDEF> | ||
</sheets> | ||
</T3DataStructure> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
.. include:: ../Includes.txt | ||
|
||
.. _update-templates: | ||
|
||
================ | ||
Update templates | ||
================ | ||
|
||
This extension uses fluid templates so you are able to override them like in most other TYPO3 extensions. | ||
|
||
Override template using TypoScript | ||
---------------------------------- | ||
|
||
Do you have a site package? Put the templates into your site package extension. Otherwise you can put them into fileadmin if you really want. | ||
|
||
.. code-block:: typoscript | ||
plugin.tx_reserve { | ||
view { | ||
templateRootPaths > | ||
templateRootPaths { | ||
0 = EXT:reserve/Resources/Private/Templates/ | ||
1 = EXT:site_package/Resources/Private/Extensions/reserve/Templates/ | ||
} | ||
partialRootPaths > | ||
partialRootPaths { | ||
0 = EXT:reserve/Resources/Private/Partials/ | ||
1 = EXT:site_package/Resources/Private/Extensions/reserve/Partials/ | ||
} | ||
layoutRootPaths > | ||
layoutRootPaths { | ||
0 = EXT:reserve/Resources/Private/Layouts/ | ||
1 = EXT:site_package/Resources/Private/Extensions/reserve/Layouts/ | ||
} | ||
} | ||
} | ||
Override template using constant editor | ||
--------------------------------------- | ||
|
||
TYPO3 Backend > Templates > Constant Editor | ||
|
||
.. figure:: ../../Images/TemplatesConstantEditor.png | ||
:class: with-shadow | ||
:alt: Constant editor | ||
:width: 500px |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.