-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathReservationPlanHelper.php
More file actions
277 lines (258 loc) · 8.65 KB
/
ReservationPlanHelper.php
File metadata and controls
277 lines (258 loc) · 8.65 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
<?php
/**
* Reservation Plan Helper
*
* @author Allcreator Co., Ltd. <info@allcreator.net>
* @link http://www.netcommons.org NetCommons Project
* @license http://www.netcommons.org/license.txt NetCommons License
* @copyright Copyright 2014, NetCommons Project
*/
App::uses('AppHelper', 'View/Helper');
App::uses('ReservationPermissiveRooms', 'Reservations.Utility');
/**
* Reservation plan Helper
*
* @author Allcreator Co., Ltd. <info@allcreator.net>
* @package NetCommons\Reservations\View\Helper
*/
class ReservationPlanHelper extends AppHelper {
/**
* Other helpers used by FormHelper
*
* @var array
*/
public $helpers = array(
'Html',
'Form',
'NetCommons.NetCommonsForm',
'NetCommons.NetCommonsHtml',
'NetCommons.Button',
'Reservations.ReservationMonthly',
'Reservations.ReservationCommon',
'Reservations.ReservationUrl',
);
/**
* makeDatetimeWithUserSiteTz
*
* サーバ系日付時刻、タイムゾーン、言語より、言語別ユーザ系日付時刻曜日文字列を生成
* ユーザーTZ or サイトTZ を暗黙裡に使う。登録時の現地TZは、ここではつかわない。
*
* @param string $YmdHis "YYYYMMDDhhmmss"形式のシステム系日付時刻
* @param bool $isAllday 終日フラグ
* @return string HTML
*/
public function makeDatetimeWithUserSiteTz($YmdHis, $isAllday) {
$nctm = new NetCommonsTime();
$serverDatetime = ReservationTime::addDashColonAndSp($YmdHis);
//toUserDatetime()が内部でユーザTZorサイトTZを使う.
$userDatetime = $nctm->toUserDatetime($serverDatetime);
$tma = ReservationTime::transFromYmdHisToArray($userDatetime);
$unixtm = mktime(intval($tma['hour']), intval($tma['min']), intval($tma['sec']),
intval($tma['month']), intval($tma['day']), intval($tma['year']));
$html = sprintf(__d('reservations', '%s/%s/%s'), $tma['year'], $tma['month'], $tma['day']);
$wdayArray = $this->ReservationCommon->getWdayArray();
$dateInfo = getdate($unixtm);
$html .= '(' . $wdayArray[$dateInfo['wday']] . ')';
if (!$isAllday) {
$html .= ' ' . sprintf(__d('reservations', '%s:%s'), $tma['hour'], $tma['min']);
}
return $html;
}
/**
* makeDateWithUserSiteTz
*
* サーバ系日付時刻、タイムゾーン、言語より、言語別ユーザ系日付文字列を生成
* ユーザーTZ or サイトTZ を暗黙裡に使う。登録時の現地TZは、ここではつかわない。
*
* @param string $YmdHis "YYYYMMDDhhmmss"形式のシステム系日付時刻
* @param bool $isAllday 終日フラグ
* @return string HTML
*/
public function makeDateWithUserSiteTz($YmdHis, $isAllday) {
$nctm = new NetCommonsTime();
$serverDatetime = ReservationTime::addDashColonAndSp($YmdHis);
//toUserDatetime()が内部でユーザTZorサイトTZを使う.
$userDatetime = $nctm->toUserDatetime($serverDatetime);
$tma = ReservationTime::transFromYmdHisToArray($userDatetime);
//$unixtm = mktime(intval($tma['hour']), intval($tma['min']), intval($tma['sec']),
// intval($tma['month']), intval($tma['day']), intval($tma['year']));
$html = sprintf(__d('reservations', '%s/%s/%s'), $tma['year'], $tma['month'], $tma['day']);
return $html;
}
/**
* isLinePlan
*
* 日跨ぎ(日跨ぎLine)判定
*
* @param array $plan 予定
* @return bool
*/
public function isLinePlan($plan) {
$startUserDate = $this->makeDateWithUserSiteTz(
$plan['ReservationEvent']['dtstart'], $plan['ReservationEvent']['is_allday']);
$endUserDate = $this->makeDateWithUserSiteTz(
$plan['ReservationEvent']['dtend'], $plan['ReservationEvent']['is_allday']);
//日跨ぎ(ユーザー時刻で同一日ではない)
if ($startUserDate != $endUserDate && $plan['ReservationEvent']['is_allday'] == false) {
return true;
}
return false;
}
/**
* makeEditButtonHtml
*
* 編集画面のボタンHTML生成
*
* @param string $statusFieldName 承認ステータス項目名
* @param array $vars 施設予約情報
* @param array $event 予約
* @return string HTML
*/
public function makeEditButtonHtml($statusFieldName, $vars, $event) {
//save,tempsaveのoptionsでpath指定するため、Workflowヘルパーのbuttons()を参考に実装した。
//$status = Hash::get($this->_View->data, $statusFieldName);
$options = array(
'controller' => 'reservations',
'action' => 'index',
'frame_id' => Current::read('Frame.id'),
'?' => array(
'year' => $vars['year'],
'month' => $vars['month'],
)
);
$ret = '';
// キャンセルボタン
if (isset($vars['returnUrl'])) {
$cancelUrl = $vars['returnUrl'];
} else {
$cancelUrl = $this->ReservationUrl->getReservationUrl($options);
}
$cancelOptions = array(
'ng-click' => 'sending=true',
'ng-class' => '{disabled: sending}',
);
$ret .= $this->Button->cancel( __d('net_commons', 'Cancel'), $cancelUrl, $cancelOptions);
// 一時保存 差し戻しボタン非表示なら表示
$saveTempOptions = array(
'label' => __d('net_commons', 'Save temporally'),
'class' => 'btn btn-info' . $this->Button->getButtonSize() . ' btn-workflow',
'name' => 'save_' . WorkflowComponent::STATUS_IN_DRAFT,
'ng-class' => '{disabled: sending}',
'ng-show' => 'buttons.draft'
);
$ret .= $this->Button->button(__d('net_commons', 'Save temporally'), $saveTempOptions);
// 差し戻し 承認者でステータスが公開待ちなら 差し戻しボタン表示
$saveTempOptions = array(
'label' => __d('net_commons', 'Disapproval'),
'class' => 'btn btn-warning' . $this->Button->getButtonSize() . ' btn-workflow',
'name' => 'save_' . WorkflowComponent::STATUS_DISAPPROVED,
'ng-class' => '{disabled: sending}',
'ng-show' => 'buttons.disapproved',
);
$ret .= $this->Button->button(__d('net_commons', 'Disapproval'), $saveTempOptions);
// 公開申請 承認者でなければ公開申請表示
$saveOptions = array(
'class' => 'btn btn-primary' . $this->Button->getButtonSize() . ' btn-workflow',
'name' => 'save_' . WorkflowComponent::STATUS_APPROVAL_WAITING,
'ng-class' => '{disabled: sending}',
'ng-show' => 'buttons.approvalWaiting'
);
// デバッグ時は 'OK' を'承認申請'とかにかえとくとわかりやすい
$ret .= $this->Button->button(__d('net_commons', 'OK'), $saveOptions);
// 公開 承認者なら公開ボタンを表示
$saveOptions = array(
'label' => __d('net_commons', 'OK'),
'class' => 'btn btn-primary' . $this->Button->getButtonSize() . ' btn-workflow',
'name' => 'save_' . WorkflowComponent::STATUS_PUBLISHED,
'ng-class' => '{disabled: sending}',
'ng-show' => 'buttons.published'
);
$ret .= $this->Button->button(__d('net_commons', 'OK'), $saveOptions);
return $ret;
}
/**
* makeOptionsOfWdayInNthWeek
*
* 第N週M曜日のオプション配列生成
*
* @param string $firstValue 最初の値
* @param string $firstLabel 最初の文字列
* @return array 配列
*/
public function makeOptionsOfWdayInNthWeek($firstValue, $firstLabel) {
$options = array();
$options[$firstValue] = $firstLabel;
$weeks = array (1, 2, 3, 4, -1);
$wdays = explode('|', ReservationsComponent::CALENDAR_REPEAT_WDAY);
foreach ($weeks as $week) {
foreach ($wdays as $idx => $wday) {
$key = $week . $wday;
$weekLabel = $this->__getOrdSuffix($week);
if ($week > 0) {
//改行の位置調整のため、半角スペースが必要
$options[$key] = $weekLabel . ' ' . $this->getWdayString($idx);
} else {
$options[$key] = $weekLabel . $this->getWdayString($idx);
}
}
}
return $options;
}
/**
* __getOrdSuffix
*
* 第N週のための序数文字列を取得する
*
* @param int $num 週数
* @return string 序数文字列
*/
private function __getOrdSuffix($num) {
switch($num) {
case 1:
return __d('reservations', '1st week');
case 2:
return __d('reservations', '2nd week');
case 3:
return __d('reservations', '3rd week');
case 4:
return __d('reservations', '4th week');
case -1:
return __d('reservations', 'last week');
}
}
/**
* getWdayString
*
* n曜日の文字列取得
*
* @param int $index 曜日のindex 0=日曜日,1=月曜日, ... , 6=土曜日
* @return string 曜日の文字列
*/
public function getWdayString($index) {
$string = '';
switch ($index) {
case 0:
$string = __d('reservations', 'Sunday');
break;
case 1:
$string = __d('reservations', 'Monday');
break;
case 2:
$string = __d('reservations', 'Tuesday');
break;
case 3:
$string = __d('reservations', 'Wednesday');
break;
case 4:
$string = __d('reservations', 'Thursday');
break;
case 5:
$string = __d('reservations', 'Friday');
break;
default: /* 6 */
$string = __d('reservations', 'Saturday');
break;
}
return $string;
}
}