PluginProbe ʕ •ᴥ•ʔ
VikAppointments Services Booking Calendar / 1.2.21
VikAppointments Services Booking Calendar v1.2.21
1.2.21 1.2.20 trunk 1.2.17 1.2.18 1.2.19
vikappointments / site / helpers / libraries / import / forms / columns / date.php
vikappointments / site / helpers / libraries / import / forms / columns Last commit date
city.php 3 days ago country.php 3 days ago currency.php 3 days ago date.php 3 days ago empgroup.php 3 days ago employee.php 3 days ago group.php 3 days ago index.html 3 days ago optiongroup.php 3 days ago service.php 3 days ago state.php 3 days ago user.php 3 days ago
date.php
106 lines
1 <?php
2 /**
3 * @package VikAppointments
4 * @subpackage core
5 * @author E4J s.r.l.
6 * @copyright Copyright (C) 2021 E4J s.r.l. All Rights Reserved.
7 * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
8 * @link https://vikwp.com
9 */
10
11 // No direct access
12 defined('ABSPATH') or die('No script kiddies please!');
13
14 /**
15 * Formats the given date/timestamp into a globally
16 * recognized format (military).
17 *
18 * @since 1.7
19 */
20 class ImportColumnDate extends ImportColumn
21 {
22 /**
23 * Helper method used to manipulate the given value before
24 * binding the object to save.
25 *
26 * @param mixed $value The default import value.
27 *
28 * @return string The value to bind
29 */
30 public function onImport($value)
31 {
32 if (VAPDateHelper::isNull($value))
33 {
34 // invalid date
35 return null;
36 }
37
38 // check whether the given value is not a timestamp
39 if (!is_numeric($value))
40 {
41 // look for a "Z" at the end, which stands for UTC date
42 if (preg_match("/Z$/", $value))
43 {
44 // remove T and Z from date
45 $value = trim(preg_replace("/[TZ]/", ' ', $value));
46 }
47 else
48 {
49 try
50 {
51 // no trailing "Z", assume the date was set
52 // into the local timezone of the user
53 $value = JFactory::getDate($value, JFactory::getUser()->getTimezone());
54 // now re-format in UTC
55 $value = $value->toSql();
56 }
57 catch (Exception $e)
58 {
59 // invalid date...
60 return null;
61 }
62 }
63 }
64
65 return $value;
66 }
67
68 /**
69 * Helper method used to format the values under this column.
70 *
71 * @param mixed $value The default column value.
72 *
73 * @return string The formatted value
74 */
75 public function format($value)
76 {
77 // format with parent first
78 $date = parent::format($value);
79
80 if ($value != $date)
81 {
82 // value has been manipulated by the parent,
83 // we don't need to go ahead
84 return $date;
85 }
86
87 if (VAPDateHelper::isNull($date))
88 {
89 // return an empty string in case of null date
90 return '';
91 }
92
93 if (is_numeric($date))
94 {
95 // format timestamp into military one
96 $date = date('Y-m-d H:i:s', $date);
97 }
98 else
99 {
100 $date = JHtml::fetch('date', $date, 'Y-m-d H:i:s');
101 }
102
103 return $date;
104 }
105 }
106