|
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 Twig_Environment; |
|
16
|
|
|
use WBW\Bundle\AdminBSBBundle\Twig\Extension\AbstractTwigExtension; |
|
17
|
|
|
use WBW\Bundle\CoreBundle\Service\TranslatorTrait; |
|
18
|
|
|
use WBW\Library\Core\Argument\StringHelper; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Abstract Datetime picker Twig extension. |
|
22
|
|
|
* |
|
23
|
|
|
* @author webeweb <https://github.com/webeweb/> |
|
24
|
|
|
* @package WBW\Bundle\AdminBSBBundle\Twig\Extension\Plugin |
|
25
|
|
|
* @abstract |
|
26
|
|
|
*/ |
|
27
|
|
|
abstract class AbstractDatetimePickerTwigExtension extends AbstractTwigExtension { |
|
28
|
|
|
|
|
29
|
|
|
use TranslatorTrait; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Datetime picker. |
|
33
|
|
|
* |
|
34
|
|
|
* @var string |
|
35
|
|
|
*/ |
|
36
|
|
|
const DATETIMEPICKER = <<< EOT |
|
37
|
|
|
<script type="text/javascript"> |
|
38
|
|
|
$("%selector%").bootstrapMaterialDatePicker({ |
|
39
|
|
|
cancelText: "%cancelText%", |
|
40
|
|
|
clearButton: %clearButton%, |
|
41
|
|
|
clearText: "%clearText%", |
|
42
|
|
|
date: %date%, |
|
43
|
|
|
format: "%format%", |
|
44
|
|
|
lang: "%lang%", |
|
45
|
|
|
time: %time%, |
|
46
|
|
|
weekStart: %weekStart% |
|
47
|
|
|
}); |
|
48
|
|
|
</script> |
|
49
|
|
|
EOT; |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Default date format. |
|
53
|
|
|
* |
|
54
|
|
|
* @var string |
|
55
|
|
|
*/ |
|
56
|
|
|
const DEFAULT_DATE_FORMAT = "YYYY-MM-DD"; |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* Default datetime format. |
|
60
|
|
|
* |
|
61
|
|
|
* @var string |
|
62
|
|
|
*/ |
|
63
|
|
|
const DEFAULT_DATETIME_FORMAT = self::DEFAULT_DATE_FORMAT . " - " . self::DEFAULT_TIME_FORMAT; |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* Default time format. |
|
67
|
|
|
* |
|
68
|
|
|
* @var string |
|
69
|
|
|
*/ |
|
70
|
|
|
const DEFAULT_TIME_FORMAT = "HH:mm"; |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* Constructor. |
|
74
|
|
|
* |
|
75
|
|
|
* @param Twig_Environment $twigEnvironment The Twig environment. |
|
76
|
|
|
* @param TranslatorInterface $translator The translator. |
|
77
|
|
|
*/ |
|
78
|
|
|
protected function __construct(Twig_Environment $twigEnvironment, TranslatorInterface $translator) { |
|
79
|
|
|
parent::__construct($twigEnvironment); |
|
80
|
|
|
$this->setTranslator($translator); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* Display an AdminBSB datetime picker. |
|
85
|
|
|
* |
|
86
|
|
|
* @param string $selector The selector. |
|
87
|
|
|
* @param bool $clearButton Clear button ? |
|
88
|
|
|
* @param bool $date Date ? |
|
89
|
|
|
* @param string $format The format. |
|
90
|
|
|
* @param string $lang The lang. |
|
91
|
|
|
* @param bool $time Time ? |
|
92
|
|
|
* @param string $weekStart The week start. |
|
93
|
|
|
* @return string Returns the AdminBSB datetime picker. |
|
94
|
|
|
*/ |
|
95
|
|
|
protected function adminBSBDatetimePicker($selector, $clearButton, $date, $format, $lang, $time, $weekStart) { |
|
96
|
|
|
|
|
97
|
|
|
// Initialize the values. |
|
98
|
|
|
$weekStarts = [0, 1, 2, 3, 4, 5, 6]; |
|
99
|
|
|
|
|
100
|
|
|
// Initialize the parameters. |
|
101
|
|
|
$cancelText = $this->getTranslator()->trans("label.cancel", [], "BootstrapBundle"); |
|
102
|
|
|
$clearText = $this->getTranslator()->trans("label.delete", [], "BootstrapBundle"); |
|
103
|
|
|
$bClearButton = StringHelper::parseBoolean($clearButton); |
|
104
|
|
|
$bDate = StringHelper::parseBoolean($date); |
|
105
|
|
|
$bTime = StringHelper::parseBoolean($time); |
|
106
|
|
|
$iWeekStart = true === in_array($weekStart, $weekStarts) ? $weekStart : 0; |
|
107
|
|
|
|
|
108
|
|
|
// |
|
109
|
|
|
$searches = ["%selector%", "%cancelText%", "%clearButton%", "%clearText%", "%date%", "%format%", "%lang%", "%time%", "%weekStart%"]; |
|
110
|
|
|
$replaces = [$selector, $cancelText, $bClearButton, $clearText, $bDate, $format, $lang, $bTime, $iWeekStart]; |
|
111
|
|
|
|
|
112
|
|
|
// Return the HTML. |
|
113
|
|
|
return StringHelper::replace(self::DATETIMEPICKER, $searches, $replaces); |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
} |
|
117
|
|
|
|