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\Utility\GeneralUtility; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* TimeRestrictionEvaluator |
19
|
|
|
*/ |
20
|
|
|
class TimeRestrictionEvaluator |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* Checks if $value can be intepreted with strtotime() |
24
|
|
|
* |
25
|
|
|
* @param string $value The value that has to be checked |
26
|
|
|
* @param string $is_in Is-In String |
27
|
|
|
* @param bool $set Determines if the field can be set (value correct) or not |
28
|
|
|
* |
29
|
|
|
* @return string The new value of the field |
30
|
|
|
*/ |
31
|
|
|
public function evaluateFieldValue(string $value, string $is_in, bool &$set): string |
|
|
|
|
32
|
|
|
{ |
33
|
|
|
$timestamp = strtotime($value); |
34
|
|
|
$set = empty($value) || $timestamp !== false; |
35
|
|
|
|
36
|
|
|
if (!empty($value)) { |
37
|
|
|
$languageService = $this->getLanguageService(); |
38
|
|
|
|
39
|
|
|
if ($set) { |
40
|
|
|
$severity = FlashMessage::INFO; |
41
|
|
|
$message = sprintf( |
42
|
|
|
$languageService->sL('LLL:EXT:sf_event_mgt/Resources/Private/Language/locallang_be.xlf:evaluation.timeRestriction.info'), |
43
|
|
|
$value, |
44
|
|
|
date($languageService->sL('LLL:EXT:sf_event_mgt/Resources/Private/Language/locallang_be.xlf:evaluation.timeRestriction.format'), $timestamp) |
45
|
|
|
); |
46
|
|
|
} else { |
47
|
|
|
$severity = FlashMessage::ERROR; |
48
|
|
|
$message = sprintf( |
49
|
|
|
$languageService->sL('LLL:EXT:sf_event_mgt/Resources/Private/Language/locallang_be.xlf:evaluation.timeRestriction.error'), |
50
|
|
|
$value |
51
|
|
|
); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** @var FlashMessage $message */ |
55
|
|
|
$message = GeneralUtility::makeInstance( |
56
|
|
|
FlashMessage::class, |
57
|
|
|
$message, |
58
|
|
|
$languageService->sL('LLL:EXT:sf_event_mgt/Resources/Private/Language/locallang_be.xlf:evaluation.timeRestriction.header'), |
59
|
|
|
$severity, |
60
|
|
|
false |
61
|
|
|
); |
62
|
|
|
|
63
|
|
|
/** @var FlashMessageService $flashMessageService */ |
64
|
|
|
$flashMessageService = GeneralUtility::makeInstance(FlashMessageService::class); |
65
|
|
|
$flashMessageService->getMessageQueueByIdentifier()->enqueue($message); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
return $value; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @return LanguageService |
73
|
|
|
*/ |
74
|
|
|
protected function getLanguageService(): ?LanguageService |
75
|
|
|
{ |
76
|
|
|
return $GLOBALS['LANG']; |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.