1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Extension "sf_event_mgt" for TYPO3 CMS. |
5
|
|
|
* |
6
|
|
|
* For the full copyright and license information, please read the |
7
|
|
|
* LICENSE.txt file that was distributed with this source code. |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace DERHANSEN\SfEventMgt\Evaluation; |
11
|
|
|
|
12
|
|
|
use TYPO3\CMS\Core\Localization\LanguageService; |
13
|
|
|
use TYPO3\CMS\Core\Messaging\FlashMessage; |
14
|
|
|
use TYPO3\CMS\Core\Messaging\FlashMessageService; |
15
|
|
|
use TYPO3\CMS\Core\Type\ContextualFeedbackSeverity; |
16
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
17
|
|
|
|
18
|
|
|
class TimeRestrictionEvaluator |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* Checks if $value can be interpreted with strtotime() |
22
|
|
|
*/ |
23
|
|
|
public function evaluateFieldValue(string $value, string $is_in, bool &$set): string |
|
|
|
|
24
|
|
|
{ |
25
|
|
|
$timestamp = strtotime($value); |
26
|
|
|
$set = empty($value) || $timestamp !== false; |
27
|
|
|
|
28
|
|
|
if (!empty($value) && $timestamp !== false) { |
29
|
|
|
$languageService = $this->getLanguageService(); |
30
|
|
|
|
31
|
|
|
if ($set) { |
32
|
|
|
$severity = ContextualFeedbackSeverity::INFO; |
33
|
|
|
$message = sprintf( |
34
|
|
|
$languageService->sL('LLL:EXT:sf_event_mgt/Resources/Private/Language/locallang_be.xlf:evaluation.timeRestriction.info'), |
35
|
|
|
$value, |
36
|
|
|
date($languageService->sL('LLL:EXT:sf_event_mgt/Resources/Private/Language/locallang_be.xlf:evaluation.timeRestriction.format'), $timestamp) |
37
|
|
|
); |
38
|
|
|
} else { |
39
|
|
|
$severity = ContextualFeedbackSeverity::ERROR; |
40
|
|
|
$message = sprintf( |
41
|
|
|
$languageService->sL('LLL:EXT:sf_event_mgt/Resources/Private/Language/locallang_be.xlf:evaluation.timeRestriction.error'), |
42
|
|
|
$value |
43
|
|
|
); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** @var FlashMessage $message */ |
47
|
|
|
$message = GeneralUtility::makeInstance( |
48
|
|
|
FlashMessage::class, |
49
|
|
|
$message, |
50
|
|
|
$languageService->sL('LLL:EXT:sf_event_mgt/Resources/Private/Language/locallang_be.xlf:evaluation.timeRestriction.header'), |
51
|
|
|
$severity, |
52
|
|
|
false |
53
|
|
|
); |
54
|
|
|
|
55
|
|
|
/** @var FlashMessageService $flashMessageService */ |
56
|
|
|
$flashMessageService = GeneralUtility::makeInstance(FlashMessageService::class); |
57
|
|
|
$flashMessageService->getMessageQueueByIdentifier()->enqueue($message); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
return $value; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
protected function getLanguageService(): LanguageService |
64
|
|
|
{ |
65
|
|
|
return $GLOBALS['LANG']; |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.