1 | <?php |
||
9 | class Util |
||
10 | { |
||
11 | /** |
||
12 | * Convert TZ |
||
13 | * |
||
14 | * @param string $date |
||
15 | * @param string $fromTimeZone |
||
16 | * @param string $toTimeZone |
||
17 | * @param string $format |
||
18 | * @return string |
||
19 | */ |
||
20 | public static function convertTz($date, $fromTimeZone, $toTimeZone, $format = 'Y-m-d H:i:s') |
||
21 | { |
||
22 | $date = new \DateTime($date, new \DateTimeZone($fromTimeZone)); |
||
23 | $date->setTimeZone(new \DateTimeZone($toTimeZone)); |
||
24 | |||
25 | return $date->format($format); |
||
26 | } |
||
27 | |||
28 | /** |
||
29 | * Clear text |
||
30 | * Can use for meta tags |
||
31 | * |
||
32 | * @param string $text |
||
33 | * @return string |
||
34 | */ |
||
35 | public static function clearText($text) |
||
36 | { |
||
37 | $text = str_replace('"', '“', $text); |
||
38 | return Html::encode(html_entity_decode(strip_tags($text))); |
||
39 | } |
||
40 | |||
41 | /** |
||
42 | * Make page title |
||
43 | * |
||
44 | * @param string $title |
||
45 | * @param string $appendToEnd |
||
46 | * @return string |
||
47 | */ |
||
48 | public static function makePageTitle($title = '', $appendToEnd = '') |
||
49 | { |
||
50 | $title = $title ? self::clearText($title) . ' / ' : ''; |
||
51 | return $title . $appendToEnd; |
||
52 | } |
||
53 | |||
54 | /** |
||
55 | * Collect model errors |
||
56 | * |
||
57 | * @param Model $model the model to be validated |
||
58 | * @return array the error message array indexed by the attribute IDs. |
||
59 | */ |
||
60 | public static function collectModelErrors($model) |
||
72 | |||
73 | /** |
||
74 | * Create manually UploadedFile instance by file path |
||
75 | * |
||
76 | * @param string $name the original name of the file being uploaded |
||
77 | * @param string $file file path |
||
78 | * @return UploadedFile |
||
79 | */ |
||
80 | public static function makeUploadedFile($name, $file) |
||
95 | } |
||
96 |