-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCalendarUrlHelper.php
More file actions
230 lines (218 loc) · 5.36 KB
/
CalendarUrlHelper.php
File metadata and controls
230 lines (218 loc) · 5.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
<?php
/**
* Calendar Url 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('WorkflowComponent', 'Workflow.Controller/Component');
App::uses('CalendarFrameSetting', 'Calendars.Model');
/**
* Calendar url Helper
*
* @author Allcreator Co., Ltd. <info@allcreator.net>
* @package NetCommons\Calendars\View\Helper
*/
class CalendarUrlHelper extends AppHelper {
/**
* Other helpers used by FormHelper
*
* @var array
*/
public $helpers = array(
'NetCommons.NetCommonsForm',
'NetCommons.NetCommonsHtml',
'NetCommons.BackTo',
'Calendars.CalendarCommon',
);
/**
* @var string daily へのリンクから年月日クエリを除いたURL
*/
private $__dailyBaseUrl;
/**
* beforeRender
*
* @param string $viewFile view file
* @return void
*/
public function beforeRender($viewFile) {
$this->__setupDailyBaseUrl();
parent::beforeRender($viewFile);
}
/**
* setupDailyBaseUrl
*
* @return void
*/
private function __setupDailyBaseUrl() {
$this->__dailyBaseUrl = $this->getCalendarUrl(array(
'plugin' => 'calendars',
'controller' => 'calendars',
'action' => 'index',
'block_id' => '',
'frame_id' => Current::read('Frame.id'),
'?' => array(
'style' => 'daily',
'tab' => 'list',
)
));
}
/**
* makePlanShowUrl
*
* 予定表示Url生成
*
* @param int $year 年
* @param int $month 月
* @param int $day 日
* @param array $plan 予定
* @param bool $isArray 配列での戻り値を求めているか
* @return string url
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
*/
public function makePlanShowUrl($year, $month, $day, $plan, $isArray = false) {
if ($isArray) {
$url = $this->getCalendarUrlAsArray(array(
'plugin' => 'calendars',
'controller' => 'calendar_plans',
'action' => 'view',
'key' => $plan['CalendarEvent']['key'],
'frame_id' => Current::read('Frame.id'),
));
} else {
$url = $this->getCalendarUrl(array(
'plugin' => 'calendars',
'controller' => 'calendar_plans',
'action' => 'view',
'key' => $plan['CalendarEvent']['key'],
'frame_id' => Current::read('Frame.id'),
));
}
return $url;
}
/**
* makeEditUrl
*
* 編集画面URL生成
*
* @param int $year 年
* @param int $month 月
* @param int $day 日
* @param array $vars カレンダー情報
* @return string Url
*/
public function makeEditUrl($year, $month, $day, $vars) {
$options = array(
'plugin' => 'calendars',
'controller' => 'calendar_plans',
'action' => 'edit',
'frame_id' => Current::read('Frame.id'),
'?' => array(
'year' => $year,
'month' => $month,
'day' => $day,
)
);
$url = $this->getCalendarUrlAsArray($options);
return $url;
}
/**
* makeEditUrlWithTime
*
* 編集画面URL生成
*
* @param int $year 年
* @param int $month 月
* @param int $day 日
* @param int $hour 時
* @param array $vars カレンダー情報
* @return string Url
*/
public function makeEditUrlWithTime($year, $month, $day, $hour, $vars) {
$options = array(
'plugin' => 'calendars',
'controller' => 'calendar_plans',
'action' => 'edit',
'frame_id' => Current::read('Frame.id'),
'?' => array(
'year' => $year,
'month' => $month,
'day' => $day,
'hour' => $hour,
)
);
$url = $this->getCalendarUrlAsArray($options);
return $url;
}
/**
* getCalendarDailyUrl
*
* カレンダー日次URL取得
*
* @param int $year 年
* @param int $month 月
* @param int $day 日
* @return string URL
*/
public function getCalendarDailyUrl($year, $month, $day) {
return $this->__dailyBaseUrl . '&' . http_build_query(
[
'year' => $year,
'month' => $month,
'day' => $day,
]
);
}
/**
* getBackFirstButton
*
* 最初の画面に戻るUrlリンクボタンの取得
*
* @param array $vars カレンダー情報
* @return string URL
*/
public function getBackFirstButton($vars) {
// urlパラメタにstyleがなくて、表示画面がデフォルトの画面と一緒ならこのボタンは不要
// 本当は共通関数[getQueryParam]を使いたかったが、
// AppControllerに作っちゃったためHelperから呼びづらく、似たコードを書いてしまった
// 許してほしい
$isNotMain = isset($this->request->params['requested'])
? $this->request->params['requested']
: null;
$frameId = isset($this->request->query['frame_id'])
? $this->request->query['frame_id']
: null;
if ($frameId === null || $frameId != Current::read('Frame.id') || $isNotMain) {
return '';
}
//return $this->BackTo->indexLinkButton(__d('calendars', 'Back to First view'));
return $this->BackTo->pageLinkButton(__d('calendars', 'Back'));
}
/**
* getCalendarUrl
*
* URL取得汎用関数
*
* @param array $arr URL作成のためのパラメータ配列
* @return string URL文字列
*/
public function getCalendarUrl($arr) {
return Router::url(NetCommonsUrl::actionUrlAsArray($arr));
}
/**
* getCalendarUrlAsArray
*
* URL取得汎用関数
*
* @param array $arr URL作成のためのパラメータ配列
* @return array URL配列
*/
public function getCalendarUrlAsArray($arr) {
$ret = NetCommonsUrl::actionUrlAsArray($arr);
$ret['block_id'] = '';
return $ret;
}
}