-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCalendarWeeklyHelper.php
More file actions
282 lines (255 loc) · 9.36 KB
/
CalendarWeeklyHelper.php
File metadata and controls
282 lines (255 loc) · 9.36 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
278
279
280
281
282
<?php
/**
* Calendar Weekly 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('CalendarComponent', 'Calendars.Controller/Component');
/**
* Calendar weekly Helper
*
* @author Allcreator Co., Ltd. <info@allcreator.net>
* @package NetCommons\Calendars\View\Helper
*/
class CalendarWeeklyHelper extends CalendarMonthlyHelper {
/**
* Other helpers used by FormHelper
*
* @var array
*/
public $helpers = array(
'NetCommonsForm',
'NetCommonsHtml',
'Form',
'Calendars.CalendarCommon',
'Calendars.CalendarButton',
'Calendars.CalendarUrl',
'Calendars.CalendarDaily',
'Calendars.CalendarMonthly',
'Calendars.CalendarPlan',
'NetCommons.TitleIcon',
);
/**
* getPlanSummariesHtml
*
* 予定概要群html取得
*
* @param array $vars カレンダー情報
* @param int $year 年
* @param int $month 月
* @param int $day 日
* @param string $fromTime この日の1日のスタート時刻
* @param string $toTime この日の1日のエンド時刻
* @param array $plans この日の予定群
* @return string HTML
*/
public function getPlanSummariesHtml($vars, $year, $month, $day, $fromTime, $toTime, $plans) {
$html = '';
if ($this->_lineProcess == true) {
$html .= $this->getPlanSummariesLineHtml($vars, $year, $month, $day, $fromTime, $toTime,
$plans, $vars['currentRoomId']);
return $html;
}
$id = 'divline' . (string)$this->_week . '_' . (string)$this->_celCnt;
$html .= "<div style='z-index:1;' id='" . $id . "'></div>"; //縦位置調整用
foreach ($plans as $plan) {
//仕様
//予定が1件以上あるとき)
//※roomIdが一致するデータ
if ($vars['currentRoomId'] != $plan['CalendarEvent']['room_id']) {
if ($vars['currentRoomId'] == CalendarsComponent::FRIEND_PLAN_VIRTUAL_ROOM_ID
&& !empty($plan['CalendarEvent']['pseudo_friend_share_plan'])) {
//このルームは「仲間の予定」仮想ルームで、かつ、
//予定($plan['CalendarEvent])の擬似項目pseudo_friend_share_planに値(1)がセットされている「仲間の予定」
//データである。よって、room_idが一致しなくても、表示する例外ケース。
} else {
//ルームIDが予定のルームIDと一致もしないし、
//「仲間の予定」仮想ルーム時の「仲間の予定」データでもないので、
//次の予定に進む。
continue;
}
}
$isLine = $this->CalendarPlan->isLinePlan($plan);
if ($isLine == true) {
continue;
}
$html .= $this->getPlanTitleHtml($vars, $year, $month, $day, $fromTime, $toTime, $plan);
}
return $html;
}
/**
* getPlanTitleHtml
*
* 予定(タイトル)html取得
*
* @param array $vars カレンダー情報
* @param int $year 年
* @param int $month 月
* @param int $day 日
* @param string $fromTime この日の1日のスタート時刻
* @param string $toTime この日の1日のエンド時刻
* @param array $plan 予定
* @return string HTML
*/
public function getPlanTitleHtml($vars, $year, $month, $day, $fromTime, $toTime, $plan) {
$html = '';
// 大枠
$html .= '<div class="row">';
$html .= '<div class="col-xs-12">';
// スペースごとの枠
$html .= $this->getPlanTitle($vars, $year, $month, $day, $fromTime, $toTime, $plan);
$html .= '</div></div>';
return $html;
}
/**
* makeWeeklyHeaderHtml
*
* (週表示)ヘッダ部分html生成
*
* @param array $vars コントローラーからの情報
* @return array HTMLと$varsを返す
*/
public function makeWeeklyHeaderHtml($vars) {
if ($vars['week'] == 0) {
//日付から第n週を求めて設定
$nWeek = ceil(($vars['mInfo']['wdayOf1stDay'] + $vars['day']) / 7);
//第n週の日曜日の日付に更新
} else {
$nWeek = $vars['week'];
}
//n週の日曜日の日付をセットする(n日前にする)
$firstSunDay = (1 - $vars['mInfo']['wdayOf1stDay']) + (7 * ($nWeek - 1));
$firsttimestamp = mktime(0, 0, 0, $vars['month'], $firstSunDay, $vars['year']);
$firstYear = date('Y', $firsttimestamp);
$firstMonth = date('m', $firsttimestamp);
$firstDay = date('d', $firsttimestamp);
$vars['weekFirst']['firstYear'] = $firstYear;
$vars['weekFirst']['firstMonth'] = $firstMonth;
$vars['weekFirst']['firstDay'] = $firstDay;
/* 日(曜日)(指定日を開始日) */
$days = array();
$wDay = array();
/* 曜日 */
$html = '<tr><td rowspan=2 class="calendar-weekly-col-room-name-head"></td>';
for ($i = 0; $i < 7; $i++) {
$timestamp = mktime(0, 0, 0, $firstMonth, ($firstDay + $i ), $firstYear);
$years[$i] = date('Y', $timestamp);
$months[$i] = date('m', $timestamp);
$days[$i] = (int)date('d', $timestamp);
$wDay[$i] = date('w', $timestamp);
$url = $this->CalendarUrl->getCalendarDailyUrl($years[$i], $months[$i], $days[$i]);
$tdColor[$i] = '';
if ($this->CalendarCommon->isToday($vars, $years[$i], $months[$i], $days[$i])) {
$tdColor[$i] = 'calendar-weekly-tbl-td-today-head-top';
}
$textColor = $this->CalendarCommon->makeTextColor(
$years[$i], $months[$i], $days[$i], $vars['holidays'], $wDay[$i]);
$holidayTitle = $this->CalendarCommon->getHolidayTitle(
$years[$i], $months[$i], $days[$i], $vars['holidays'], $i);
$html .= "<td class='calendar-monthly-line-" . ($i + 1) .
" calendar-weekly-col-day-head " . $tdColor[$i] . "'>";
$html .= '<span class=';
$html .= '"calendar-day calendar-daily-disp ';
$html .= $textColor . '" data-url="' . $url . '">';
$html .= $days[$i] . '<small>(' . $this->CalendarCommon->getWeekName($i) . ')</small>';
$html .= '</span>';
$html .= '<small class="calendar-weekly-holiday ' . $textColor . '">';
$html .= $holidayTitle . '</small>';
$html .= '</td>';
}
$html .= '</tr>';
$html .= '<tr>';
for ($i = 0; $i < 7; $i++) {
$tdBottomColor = str_replace('top', 'bottom', $tdColor[$i]);
$html .= '<td class="calendar-weekly-col-day-head-bottom ' . $tdBottomColor . '">';
$html .= $this->CalendarButton->makeGlyphiconPlusWithUrl(
$years[$i], $months[$i], $days[$i], $vars);
$html .= '</td>';
}
$html .= '</tr>';
return [$html, $vars];
}
/**
* makeWeeklyBodyHtml
*
* (週表示)本体html生成
*
* @param array $vars コントローラーからの情報
* @return string HTML
*/
public function makeWeeklyBodyHtml($vars) {
$html = '';
$rooms = $vars['exposeRoomOptions'];
//プライベートを表示することになって入るなら「仲間の予定」仮想ルーム情報を追記
if ($vars['CalendarFrameSetting']['is_myroom']) {
$rooms[CalendarsComponent::FRIEND_PLAN_VIRTUAL_ROOM_ID] = __d('calendars', 'Schedule of fellow');
}
//ルーム数分繰り返し
$cnt = 0;
$year = $vars['year'];
$month = $vars['month'];
$day = $vars['day'];
$nctm = new NetCommonsTime();
$roomMaxNum = count($rooms);
foreach ($rooms as $room) {
$cnt++;
$roomID = array_keys($rooms, $room);
//週の行の左のルーム名の場合、具体的な予定($plan)を渡せないので、第2引数はnullにし、
//第3引数で直接roomIdを渡すようにしている。
$calendarPlanMark = $this->CalendarCommon->getPlanMarkClassName($vars, null, $roomID[0]);
$html .= '<tr><div class="row">'; //1行の開始
/**Line**/
$this->_week = $cnt - 1;
$this->_lineData[$this->_week] = array();
$this->_celCnt = 0; //左から何セル目か
$this->_linePlanCnt = 0; // この週の連続する予定数
/**Line**/
//ルーム名
$html .= '<td class="calendar-weekly-col-room-name calendar-tbl-td-pos">';
$html .= '<div class="row"><div class="col-xs-12">';
$html .= '<div class="calendar-plan-mark ' . $calendarPlanMark . '">';
$html .= $room; // ここに来る前にすでにエスケープ処理が終わっていた
$html .= '</div></div></div></td>';
$vars['currentRoomId'] = $roomID[0];//$cnt;
//予定(7日分繰り返し)
for ($nDay = 0; $nDay < 7; $nDay++) {
$tdColor = '';
if ($nDay === 0) { //前日+1日
$year = $vars['weekFirst']['firstYear'];
$month = $vars['weekFirst']['firstMonth'];
$day = $vars['weekFirst']['firstDay'];
} else {
list($year, $month, $day) = CalendarTime::getNextDay($year, $month, $day);
}
if ($tdColor = $this->CalendarCommon->isToday($vars, $year, $month, $day) == true) {
if ($cnt == $roomMaxNum) {//最終行
$tdColor = 'calendar-weekly-tbl-td-today-last';
} else {
$tdColor = 'calendar-weekly-tbl-td-today';
}
}
$html .= '<td class="';
$html .= 'calendar-weekly-col-day calendar-tbl-td-pos calendar-tbl-td-room-plan ';
$html .= $tdColor . '"><div>';
//ルームID($cnt)が一致するの当日の予定を取得 pending
//line----start
$html .= "<div class=
'calendar-col-day-line calendar-period_" . $this->_week . $this->_celCnt . "'>";
$this->_lineProcess = true; //line予定の追加
$html .= $this->_makePlanSummariesHtml($vars, $nctm, $year, $month, $day);
$html .= "</div>";
$this->_lineProcess = false; //line予定の追加
$html .= $this->_makePlanSummariesHtml($vars, $nctm, $year, $month, $day);
$this->_celCnt++;
//line test------end
$html .= "</div></td>";
}
$html .= "</div></tr>"; // 1行の終了
}
return $html;
}
}