-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathReservationLocationOpenText.php
More file actions
81 lines (75 loc) · 2.54 KB
/
ReservationLocationOpenText.php
File metadata and controls
81 lines (75 loc) · 2.54 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php
/**
* ReservationLocationOpenText.php
*
* @author Ryuji AMANO <ryuji@ryus.co.jp>
* @link http://www.netcommons.org NetCommons Project
* @license http://www.netcommons.org/license.txt NetCommons License
*/
/**
* Class ReservationLocationOpenText
*/
class ReservationLocationOpenText {
/**
* openTextを返す
*
* @param array $reservationLocation 施設データ
* @return string
*/
public function openText($reservationLocation) {
$ret = '';
$weekDaysOptions = [
'Sun' => __d('holidays', 'Sunday'),
'Mon' => __d('holidays', 'Monday'),
'Tue' => __d('holidays', 'Tuesday'),
'Wed' => __d('holidays', 'Wednesday'),
'Thu' => __d('holidays', 'Thursday'),
'Fri' => __d('holidays', 'Friday'),
'Sat' => __d('holidays', 'Saturday'),
];
$timeTable = $reservationLocation['ReservationLocation']['time_table'];
if ($timeTable === 'Sun|Mon|Tue|Wed|Thu|Fri|Sat') {
//毎日
$ret = __d('reservations', '毎日');
} elseif ($timeTable === 'Mon|Tue|Wed|Thu|Fri') {
// 平日
$ret = __d('reservations', '平日');
} else {
$timeTable = explode('|', $timeTable);
$weekList = [];
foreach ($timeTable as $weekday) {
if ($weekday) {
$weekList[] = $weekDaysOptions[$weekday];
}
}
$ret = implode(', ', $weekList);
}
//時間
$startTime = $reservationLocation['ReservationLocation']['start_time'];
$locationTimeZone = new DateTimeZone($reservationLocation['ReservationLocation']['timezone']);
$startDate = new DateTime($startTime, new DateTimeZone('UTC'));
$startDate->setTimezone($locationTimeZone);
$reservationLocation['ReservationLocation']['start_time'] = $startDate->format('H:i');
$endTime = $reservationLocation['ReservationLocation']['end_time'];
$endDate = new DateTime($endTime, new DateTimeZone('UTC'));
$endDate->setTimezone($locationTimeZone);
$reservationLocation['ReservationLocation']['end_time'] = $endDate->format('H:i');
// endで00:00は24:00あつかい
if ($reservationLocation['ReservationLocation']['end_time'] == '00:00') {
$reservationLocation['ReservationLocation']['end_time'] = '24:00';
}
$ret = sprintf('%s %s - %s',
$ret,
$reservationLocation['ReservationLocation']['start_time'],
$reservationLocation['ReservationLocation']['end_time']
);
if (Current::read('User.timezone') !=
$reservationLocation['ReservationLocation']['timezone']) {
$SiteSetting = new SiteSetting();
$SiteSetting->prepare();
$ret .= ' ';
$ret .= $SiteSetting->defaultTimezones[$reservationLocation['ReservationLocation']['timezone']];
}
return $ret;
}
}