-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCalendarRoomSelectHelper.php
More file actions
218 lines (196 loc) · 6.05 KB
/
CalendarRoomSelectHelper.php
File metadata and controls
218 lines (196 loc) · 6.05 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
<?php
/**
* Calendar RoomSelect 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');
/**
* Calendar RoomSelect Helper
*
* @author Allcreator Co., Ltd. <info@allcreator.net>
* @package NetCommons\Calendars\View\Helper
*/
class CalendarRoomSelectHelper extends AppHelper {
/**
* Other helpers used by FormHelper
*
* @var array
*/
public $helpers = array(
'NetCommons.NetCommonsForm',
'NetCommons.NetCommonsHtml',
'Form',
'Rooms.Rooms'
);
/**
* spaceSelector
*
* @param array $spaces space information
* @return string
*/
public function spaceSelector($spaces) {
$html = '';
$roomTreeList = $this->_View->viewVars['roomTreeList'];
$rooms = $this->_View->viewVars['rooms'];
$html .= '<table class="table table-hover">';
foreach ($spaces as $space) {
$title = $this->Rooms->roomName($space);
if ($space['Space']['id'] == Space::PRIVATE_SPACE_ID) {
$html .= $this->_getSpaceListElm($title, $space);
} else {
$html .= $this->roomSelector(
$roomTreeList[$space['Space']['id']], $rooms[$space['Space']['id']]);
}
}
// 全会員
$html .= $this->_getSpaceListElm(
__d('calendars', 'All the members'),
array('Room' => array('id' => Space::getRoomIdRoot(Space::COMMUNITY_SPACE_ID)))
);
$html .= '</table>';
return $html;
}
/**
* _getSpaceListElm
*
* スペースを表すListタグを取得する
*
* @param string $title liに表示する文字列
* @param array $room ルーム情報
* @return string
*/
protected function _getSpaceListElm($title, $room) {
$roomId = $room['Room']['id'];
$checkbox = $this->_getRoomSelectCheckbox($roomId);
$html = '';
$ngClass = $this->__getNgClass($roomId, 'success', '');
$html .= '<tr><td ' . $ngClass . '>';
$html .= $checkbox;
$className = 'calendar-plan-mark-';
if (isset($room['Room']['space_id'])) {
$className .= ($room['Room']['space_id'] == Space::PRIVATE_SPACE_ID) ? 'private' : 'public';
} else {
$className .= 'member';
}
$html .= "<span class='calendar-plan-mark {$className}'>";
$html .= h($title);
$html .= '</span>';
$html .= '</td></tr>';
//$html .= '</div></div>';
return $html;
}
/**
* _getRoomSelectCheckbox
*
* 表示非表示の目アイコンボタン取得(実態はcheckbox
*
* @param int $roomId ルームID
* @return string
*/
protected function _getRoomSelectCheckbox($roomId) {
$settingId = $this->_View->viewVars['settingId'];
$ngModel = $this->__getNgModelName($roomId);
$ngClassForIcon = $this->__getNgClass(
$roomId, 'ng-not-empty', 'ng-empty', array('glyphicon'));
$ngClassForBtn = '';
$html = '';
// トグルボタンにしたいがこれをやるとng-modelが機能しなくなる....FUJI
//$html = '<div class="btn-group" data-toggle="buttons">';
$html .= $this->NetCommonsForm->hidden(
//$html .= $this->NetCommonsForm->checkbox( //test
'CalendarFrameSettingSelectRoom.' . $roomId . '.room_id', array('value' => ''));
$html .= '<label ' . $ngClassForBtn . '>';
$html .= '<i ' . $ngClassForIcon . '></i>';
$html .= $this->NetCommonsForm->checkbox(
'CalendarFrameSettingSelectRoom.' . $roomId . '.room_id', array(
'div' => false,
'label' => false,
'hiddenField' => false,
'ng-model' => $ngModel,
'ng-true-value' => "'" . $roomId . "'",
'ng-false-value' => "''",
'value' => $roomId,
//'class' => 'nc-checkbox-toggle-btn',
));
$html .= '</label>';
$html .= $this->NetCommonsForm->hidden(
//$html .= $this->NetCommonsForm->checkbox( //test
'CalendarFrameSettingSelectRoom.' . $roomId . '.calendar_frame_setting_id',
array('value' => $settingId));
// トグルボタンにしたいがこれをやるとng-modelが機能しなくなる....FUJI
//$html .= '</div>';
return $html;
}
/**
* __getNgModelName
*
* ルーム選択のためのng-model文字列を返す
*
* @param int $roomId ルームID
* @return string
*/
private function __getNgModelName($roomId) {
return 'data.calendarFrameSettingSelectRoom[' . $roomId . '].roomId';
}
/**
* __getNgClass
*
* ルーム選択のためのng-class設定文字列を返す
*
* @param int $roomId ルームID
* @param string $trueClass チェックされているときに用いるクラス
* @param string $falseClass チェックされていないときに用いるクラス
* @param array $defaultClassArr チェックに関係なく用いるクラス
* @return string
*/
private function __getNgClass($roomId, $trueClass, $falseClass, $defaultClassArr = array()) {
$defaultClass = '';
foreach ($defaultClassArr as $cls) {
$defaultClass .= '\'' . $cls . '\', ';
}
$ngModel = $this->__getNgModelName($roomId);
$ngClass = 'ng-class="[' . $defaultClass . '{\'' .
$trueClass . '\': (' . $ngModel . '==\'' . $roomId . '\'), \'' .
$falseClass . '\': !(' . $ngModel . '==\'' . $roomId . '\')}]"';
return $ngClass;
}
/**
* roomSelector
*
* @param array $roomTreeList room tree list information
* @param array $rooms room information
* @return string
*/
public function roomSelector($roomTreeList, $rooms) {
$html = '';
$className = 'calendar-plan-mark-';
if ($roomTreeList) {
foreach ($roomTreeList as $roomId => $tree) {
$className = 'calendar-plan-mark-';
if (isset($rooms[$roomId])) {
$nest = substr_count($tree, Room::$treeParser);
$ngClass = $this->__getNgClass($roomId, 'success', '', array());
$html .= '<tr><td ' . $ngClass . '>';
if ($nest > 0) {
$nest--;
}
for ($i = 0; $i < $nest; $i++) {
$html .= '<span class="rooms-tree"></span>';
}
$className .= ($rooms[$roomId]['Room']['space_id'] == Space::COMMUNITY_SPACE_ID) ?
'group' : 'public';
$html .= $this->_getRoomSelectCheckbox($roomId);
$html .= "<span class='calendar-plan-mark {$className}'>";
$html .= $this->Rooms->roomName($rooms[$roomId]);
$html .= '</span>';
$html .= '</td></tr>';
}
}
}
return $html;
}
}