-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLinkCategoryController.php
More file actions
204 lines (173 loc) · 5.37 KB
/
LinkCategoryController.php
File metadata and controls
204 lines (173 loc) · 5.37 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
<?php
/**
* LinkCategory Controller
*
* @author Ryuji AMANO <ryuji@ryus.co.jp>
* @link http://www.netcommons.org NetCommons Project
* @license http://www.netcommons.org/license.txt NetCommons License
* @copyright Copyright 2014, NetCommons Project
*/
App::uses('LinksAppController', 'Links.Controller');
/**
* LinkCategory Controller
*
* @property LinkCategory $LinkCategory
*
* @author Ryuji AMANO <ryuji@ryus.co.jp>
* @package NetCommons\Links\Controller
*/
class LinkCategoryController extends LinksAppController {
/**
* use model
*
* @var array
*/
//public $uses = array();
/**
* use component
*
* @var array
*/
public $components = array(
'NetCommons.NetCommonsFrame',
'NetCommons.NetCommonsRoomRole',
);
/**
* beforeFilter
*
* @return void
*/
public function beforeFilter() {
parent::beforeFilter();
$this->Auth->allow();
$frameId = (isset($this->params['pass'][0]) ? (int)$this->params['pass'][0] : 0);
//Roleのデータをviewにセット
if (! $this->NetCommonsRoomRole->setView($this)) {
// throw new ForbiddenException();
}
//編集権限チェック
if (! $this->viewVars['contentEditable']) {
// throw new ForbiddenException();
}
//Frameのデータをviewにセット
if (! $this->NetCommonsFrame->setView($this, $frameId)) {
// throw new ForbiddenException();
}
}
/**
* view method
*
* @param int $frameId frames.id
* @param string $lang ex)"en" or "ja" etc.
* @return CakeResponse A response object containing the rendered view.
*/
public function view($frameId = 0, $type = 'list') {
if ($this->response->statusCode() !== 200) {
return $this->render(false);
}
// カテゴリ取得
$linkCategories = $this->LinkCategory->getCategories(
$this->viewVars['blockId'] // MyTodo まだブロックレコードがないときは0なので、どうする?
);
$this->set('linkCategories', $linkCategories);
return $this->render('LinkCategory/view', false);
}
/**
* form method
*
* @param int $frameId frames.id
* @return CakeResponse A response object containing the rendered view.
*/
public function form($frameId = 0) {
return $this->render('LinkCategory/form', false);
}
public function add($frameId = 0) {
if (! $this->request->isPost()) {
throw new MethodNotAllowedException();
}
$postData = $this->data;
// unset($postData['Announcement']['id']);
//保存
if ($this->LinkCategory->saveLinkCategory($postData)) {
// $announcement = $this->Announcement->getAnnouncement(
// $this->viewVars['blockId'],
// $this->viewVars['contentEditable']
// );
$result = array(
'name' => __d('net_commons', 'Successfully finished.'),
'link_category' => $postData,
);
$this->set(compact('result'));
$this->set('_serialize', 'result');
return $this->render(false);
} else {
throw new ForbiddenException(__d('net_commons', 'Failed to register data.'));
}
}
public function categories_form($frameId = 0){
// カテゴリ取得
$linkCategories = $this->LinkCategory->getCategories(
$this->viewVars['blockId'] // MyTodo まだブロックレコードがないときは0なので、どうする?
);
$this->set('linkCategories', $linkCategories);
return $this->render('LinkCategory/categories_form', false);
}
public function update_all($frameId = 0) {
// MyTodo frameIdとLinkCategory.idの関連付けが正当か(セキュリティコンポーネントでIDがhidden変更不可ならOKか)
// MyTodo Frameでの権限チェックも必用
if (! $this->request->isPost()) {
throw new MethodNotAllowedException();
}
$postData = $this->data;
// unset($postData['Announcement']['id']);
//保存
if ($this->LinkCategory->updateCategories($postData)) {
// $announcement = $this->Announcement->getAnnouncement(
// $this->viewVars['blockId'],
// $this->viewVars['contentEditable']
// );
$result = array(
'name' => __d('net_commons', 'Successfully finished.'),
// 'link_category' => $postData,
);
$this->set(compact('result'));
$this->set('_serialize', 'result');
return $this->render(false);
} else {
throw new ForbiddenException(__d('net_commons', 'Failed to register data.'));
}
}
public function delete_form($frameId = 0) {
return $this->render('LinkCategory/delete_form', false);
}
public function delete($frameId = 0) {
if (! $this->request->isPost()) {
throw new MethodNotAllowedException();
}
// MyTodo frameIdとLinkCategory.idの関連付けが正当なら削除OK
// MyTodo Frameでの権限チェックも必用
$id = $this->data['LinkCategory']['id'];
//保存
if ($this->LinkCategory->delete($id)) {
// MyTodo 同一リンクの別バリエーションデータが存在しなければorderも削除。
$result = array(
'name' => __d('net_commons', 'Successfully finished.'),
// 'link_category' => $postData,
);
$this->set(compact('result'));
$this->set('_serialize', 'result');
return $this->render(false);
} else {
throw new ForbiddenException(__d('net_commons', 'Failed to register data.'));
}
}
public function get_categories($frameId = 0) {
// カテゴリ取得
$linkCategories = $this->LinkCategory->getCategories(
$this->viewVars['blockId'] // MyTodo まだブロックレコードがないときは0なので、どうする?
);
$this->set('linkCategories', $linkCategories);
$this->set('_serialize', array('linkCategories'));
return $this->render(false);
}
}