-
Notifications
You must be signed in to change notification settings - Fork 5
/
DatePickerConfig.php
54 lines (48 loc) · 1.63 KB
/
DatePickerConfig.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
namespace omnilight\datetime;
use yii\base\InvalidParamException;
use yii\base\Model;
use yii\helpers\ArrayHelper;
use yii\helpers\FormatConverter;
/**
* Class DatePickerConfig
*/
class DatePickerConfig
{
use DateTimeAttributeFinder;
/**
* @param Model $model
* @param $attribute
* @param array $options
* @param string $datePickerClass
* @return array
*/
public static function get(Model $model, $attribute, $options = [], $datePickerClass = 'yii\jui\DatePicker')
{
try {
$attribute = self::findAttribute($model, $attribute);
$format = DateTimeBehavior::normalizeIcuFormat($attribute->targetFormat, $attribute->behavior->formatter);
switch ($datePickerClass) {
case 'yii\jui\DatePicker':
$defaults = [
'language' => \Yii::$app->language,
'clientOptions' => [
'dateFormat' => 'php:' . FormatConverter::convertDateIcuToJui($format[1], $format[0]),
]
];
break;
case 'omnilight\widgets\DatePicker':
$defaults = [
'language' => \Yii::$app->language,
'dateFormat' => 'php:' . FormatConverter::convertDateIcuToPhp($format[1], $format[0]),
];
break;
default:
return $options;
}
} catch (InvalidParamException $e) {
$defaults = [];
}
return ArrayHelper::merge($defaults, $options);
}
}