-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCalendarButtonHelper.php
More file actions
214 lines (205 loc) · 5.82 KB
/
CalendarButtonHelper.php
File metadata and controls
214 lines (205 loc) · 5.82 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
<?php
/**
* Calendar Many kind Button 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('CalendarPermissiveRooms', 'Calendars.Utility');
/**
* Calendar Many kind Button Helper
*
* @author Allcreator Co., Ltd. <info@allcreator.net>
* @package NetCommons\Calendars\View\Helper
*/
class CalendarButtonHelper extends AppHelper {
/**
* Creatable status
*
* @var mixed
*/
protected $_isCreatable = array();
/**
* Other helpers used by FormHelper
*
* @var array
*/
public $helpers = array(
'Html',
'Form',
'NetCommons.NetCommonsForm',
'NetCommons.NetCommonsHtml',
'NetCommons.Button',
'NetCommons.LinkButton',
'Calendars.CalendarCommon',
'Calendars.CalendarUrl',
);
/**
* Default Constructor
*
* @param View $View The View this helper is being attached to.
* @param array $settings Configuration settings for the helper.
*/
public function __construct(View $View, $settings = array()) {
parent::__construct($View, $settings);
}
/**
* makeGlyphiconPlusWithUrl
*
* Url付き追加アイコン生成
*
* @param int $year 年
* @param int $month 月
* @param int $day 日
* @param arrya $vars カレンダー情報
* @return string HTML
*/
public function makeGlyphiconPlusWithUrl($year, $month, $day, $vars) {
$url = $this->_makeAddUrl($vars, $year, $month, $day);
$options = array(
'url' => $url,
'button' => 'plus-link'
);
$html = $this->getAddButton($vars, $options);
return $html;
}
/**
* makeGlyphiconPlusWithTimeUrl
*
* Time指定Url付き追加アイコン生成
*
* @param int $year 年
* @param int $month 月
* @param int $day 日
* @param int $hour 時
* @param arrya $vars カレンダー情報
* @return string HTML
*/
public function makeGlyphiconPlusWithTimeUrl($year, $month, $day, $hour, $vars) {
$url = $this->_makeAddUrl($vars, $year, $month, $day, $hour);
$options = array(
'url' => $url,
'button' => 'plus-link'
);
$html = $this->getAddButton($vars, $options);
return $html;
}
/**
* getAddButton
*
* 予定登録のための「追加」ボタン表示
* どこか一部屋でも予定登録できる対象の空間があればボタンは表示されます
*
* @param array $vars カレンダー情報
* @param array $options オプション情報
* @return string
*
* 速度改善の修正に伴って発生したため抑制
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
public function getAddButton($vars, $options = null) {
// まだ作成可能かどうかの判断フラグが設定されていない場合
// まず設定する
$frameId = Current::read('Frame.id');
if ($frameId === null) {
$frameId = 0;
}
if (! isset($this->_isCreatable[$frameId]) ||
$this->_isCreatable[$frameId] === null) {
$rooms = CalendarPermissiveRooms::getCreatableRoomIdList();
if (empty($rooms)) {
$this->_isCreatable[$frameId] = false;
} else {
$intersectRoom = array_intersect_key($rooms, $vars['exposeRoomOptions']);
if (empty($intersectRoom)) {
$this->_isCreatable[$frameId] = false;
} else {
$this->_isCreatable[$frameId] = true;
}
}
}
// 判断フラグがOFFの場合から文字列を返す
if ($this->_isCreatable[$frameId] === false) {
return '';
}
// どこかに書きこみ可能なルームが一つでもあれば追加ボタンを出す
// 追加画面へのURL指定がある場合(時間とか日付とか)
if (isset($options['url'])) {
$url = $options['url'];
} else {
$url = $this->_makeAddUrl($vars, $vars['year'], $vars['month'], $vars['day']);
}
// ボタンで出すか、+マークリンクで出すか
if (isset($options['button']) && $options['button'] == 'plus-link') {
$html = $this->NetCommonsHtml->link('+', $url, array(
'class' => 'pull-right calendar-edit-plus-icon',
'escape' => false
));
} else {
$html = $this->LinkButton->add('', $url);
}
return $html;
}
/**
* _makeAddUrl
*
* @param array $vars カレンダー情報
* @param int $year 年
* @param int $mon 月
* @param int $day 日
* @param int $hour 時間
* @return string url
*/
protected function _makeAddUrl($vars, $year, $mon, $day, $hour = null) {
if ($hour !== null) {
$url = $this->CalendarUrl->makeEditUrlWithTime($year, $mon, $day, $hour, $vars);
} else {
$url = $this->CalendarUrl->makeEditUrl($year, $mon, $day, $vars);
}
//$url = str_replace('calendar_plans/edit', 'calendar_plans/add', $url);
$url['action'] = 'add';
return $url;
}
/**
* getEditButton
*
* view.ctpから呼び出されることを想定
* $eventの予定が閲覧者にとって編集可能なものであるかどうかを判断する
*
* @param array $vars カレンダー情報
* @param array $event カレンダー予定
* @return string 編集ボタンHTML
*/
public function getEditButton($vars, $event) {
$roomId = $event['CalendarEvent']['room_id'];
// それ以外の時
$canEdit = CalendarPermissiveRooms::isEditable($roomId);
$canCreate = CalendarPermissiveRooms::isCreatable($roomId);
// 表示ルームにおける自分の権限がeditable以上なら無条件に編集可能
// creatbleのとき=自分が作ったデータならOK
if (!$canCreate) {
return '';
}
if (!$canEdit) {
if ($event['CalendarEvent']['created_user'] != Current::read('User.id')) {
return '';
}
}
$html = $this->Button->editLink('', array(
'controller' => 'calendar_plans',
'action' => 'edit',
'key' => $event['CalendarEvent']['key'],
'frame_id' => Current::read('Frame.id'),
'block_id' => '',
'?' => array(
'year' => $vars['year'],
'month' => $vars['month'],
'day' => $vars['day'],
)
));
return $html;
}
}