1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of the adminbsb-material-design-bundle package. |
5
|
|
|
* |
6
|
|
|
* (c) 2018 WEBEWEB |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace WBW\Bundle\AdminBSBBundle\Twig\Extension\Plugin; |
13
|
|
|
|
14
|
|
|
use Symfony\Component\Translation\TranslatorInterface; |
15
|
|
|
use WBW\Bundle\AdminBSBBundle\Twig\Extension\AbstractAdminBSBTwigExtension; |
16
|
|
|
use WBW\Library\Core\Helper\Argument\StringHelper; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Abstract Datetime picker Twig extension. |
20
|
|
|
* |
21
|
|
|
* @author webeweb <https://github.com/webeweb/> |
22
|
|
|
* @package WBW\Bundle\AdminBSBBundle\Twig\Extension\Plugin |
23
|
|
|
* @abstract |
24
|
|
|
*/ |
25
|
|
|
abstract class AbstractDatetimePickerTwigExtension extends AbstractAdminBSBTwigExtension { |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Datetime picker. |
29
|
|
|
* |
30
|
|
|
* @var string |
31
|
|
|
*/ |
32
|
|
|
const DATETIMEPICKER = <<< 'EOTXT' |
33
|
|
|
<script type="text/javascript"> |
34
|
|
|
$("%selector%").bootstrapMaterialDatePicker({ |
35
|
|
|
cancelText: "%cancelText%", |
36
|
|
|
clearButton: %clearButton%, |
37
|
|
|
clearText: "%clearText%", |
38
|
|
|
date: %date%, |
39
|
|
|
format: "%format%", |
40
|
|
|
lang: "%lang%", |
41
|
|
|
time: %time%, |
42
|
|
|
weekStart: %weekStart% |
43
|
|
|
}); |
44
|
|
|
</script> |
45
|
|
|
EOTXT; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Default date format. |
49
|
|
|
* |
50
|
|
|
* @var string |
51
|
|
|
*/ |
52
|
|
|
const DEFAULT_DATE_FORMAT = "YYYY-MM-DD"; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Default datetime format. |
56
|
|
|
* |
57
|
|
|
* @var string |
58
|
|
|
*/ |
59
|
|
|
const DEFAULT_DATETIME_FORMAT = self::DEFAULT_DATE_FORMAT . " - " . self::DEFAULT_TIME_FORMAT; |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Default time format. |
63
|
|
|
* |
64
|
|
|
* @var string |
65
|
|
|
*/ |
66
|
|
|
const DEFAULT_TIME_FORMAT = "HH:mm"; |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Translator. |
70
|
|
|
* |
71
|
|
|
* @var TranslatorInterface |
72
|
|
|
*/ |
73
|
|
|
private $translator; |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Constructor. |
77
|
|
|
*/ |
78
|
|
|
protected function __construct(TranslatorInterface $translator) { |
79
|
|
|
$this->setTranslator($translator); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Display an AdminBSB datetime picker. |
84
|
|
|
* |
85
|
|
|
* @param string $selector The selector. |
86
|
|
|
* @param string $clearButton Clear button ? |
87
|
|
|
* @param boolean $date Date ? |
88
|
|
|
* @param string $format The format. |
89
|
|
|
* @param string $lang The lang. |
90
|
|
|
* @param boolean $time Time ? |
91
|
|
|
* @param string $weekStart The week start. |
92
|
|
|
* @return string Returns the AdminBSB datetime picker. |
93
|
|
|
*/ |
94
|
|
|
protected function adminBSBDatetimePicker($selector, $clearButton, $date, $format, $lang, $time, $weekStart) { |
95
|
|
|
|
96
|
|
|
// Initialize the values. |
97
|
|
|
$weekStarts = [0, 1, 2, 3, 4, 5, 6]; |
98
|
|
|
|
99
|
|
|
// Initialize the parameters. |
100
|
|
|
$cancelText = $this->getTranslator()->trans("label.cancel", [], "BootstrapBundle"); |
101
|
|
|
$clearText = $this->getTranslator()->trans("label.delete", [], "BootstrapBundle"); |
102
|
|
|
$bClearButton = StringHelper::parseBoolean($clearButton); |
|
|
|
|
103
|
|
|
$bDate = StringHelper::parseBoolean($date); |
104
|
|
|
$bTime = StringHelper::parseBoolean($time); |
105
|
|
|
$iWeekStart = true === in_array($weekStart, $weekStarts) ? $weekStart : 0; |
106
|
|
|
|
107
|
|
|
// |
108
|
|
|
$searches = ["%selector%", "%cancelText%", "%clearButton%", "%clearText%", "%date%", "%format%", "%lang%", "%time%", "%weekStart%"]; |
109
|
|
|
$replaces = [$selector, $cancelText, $bClearButton, $clearText, $bDate, $format, $lang, $bTime, $iWeekStart]; |
110
|
|
|
|
111
|
|
|
// Return the HTML. |
112
|
|
|
return StringHelper::replace(self::DATETIMEPICKER, $searches, $replaces); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* Get the translator. |
117
|
|
|
* |
118
|
|
|
* @return TranslatorInterface Returns the translator. |
119
|
|
|
*/ |
120
|
|
|
public function getTranslator() { |
121
|
|
|
return $this->translator; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* Set the translator. |
126
|
|
|
* |
127
|
|
|
* @param TranslatorInterface $translator The translator. |
128
|
|
|
* @return AbstractDatetimePickerTwigExtension Returns this Datetime picker Twig extension. |
129
|
|
|
*/ |
130
|
|
|
protected function setTranslator(TranslatorInterface $translator) { |
131
|
|
|
$this->translator = $translator; |
132
|
|
|
return $this; |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
} |
136
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: