-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathopCommunityTopicPluginTopicActions.class.php
More file actions
275 lines (233 loc) · 6.8 KB
/
opCommunityTopicPluginTopicActions.class.php
File metadata and controls
275 lines (233 loc) · 6.8 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
<?php
/**
* This file is part of the OpenPNE package.
* (c) OpenPNE Project (http://www.openpne.jp/)
*
* For the full copyright and license information, please view the LICENSE
* file and the NOTICE file that were distributed with this source code.
*/
/**
* opCommunityTopicPluginTopicActions
*
* @package OpenPNE
* @subpackage action
* @author masabon
* @author Kousuke Ebihara <ebihara@tejimaya.com>
* @author Rimpei Ogawa <ogawa@tejimaya.com>
* @author Shogo Kawahara <kawahara@tejimaya.net>
* @author Eitarow Fukamachi <fukamachi@tejimaya.net>
*/
abstract class opCommunityTopicPluginTopicActions extends sfActions
{
/**
* preExecute
*/
public function preExecute()
{
if ($this->getRoute() instanceof sfDoctrineRoute)
{
$object = $this->getRoute()->getObject();
if ($object instanceof Community)
{
$this->community = $object;
$this->acl = opCommunityTopicAclBuilder::buildCollection($this->community, array($this->getUser()->getMember()));
}
elseif ($object instanceof CommunityTopic)
{
$this->communityTopic = $object;
$this->community = $this->communityTopic->getCommunity();
$this->acl = opCommunityTopicAclBuilder::buildResource($this->communityTopic, array($this->getUser()->getMember()));
}
}
}
/**
* Executes listCommunity action
*
* @param sfRequest $request A request object
*/
public function executeListCommunity($request)
{
$this->forward404Unless($this->acl->isAllowed($this->getUser()->getMemberId(), null, 'view'));
if (!$this->size)
{
$this->size = 20;
}
$this->pager = Doctrine::getTable('CommunityTopic')->getCommunityTopicListPager(
$this->community->getId(),
$request->getParameter('page'),
$this->size
);
return sfView::SUCCESS;
}
/**
* Executes show action
*
* @param sfRequest $request A request object
*/
public function executeShow($request)
{
$this->form = new CommunityTopicCommentForm();
return sfView::SUCCESS;
}
/**
* Executes new action
*
* @param sfRequest $request A request object
*/
public function executeNew($request)
{
$this->forward404Unless($this->acl->isAllowed($this->getUser()->getMemberId(), null, 'add'));
$this->form = new CommunityTopicForm();
return sfView::SUCCESS;
}
/**
* Executes create action
*
* @param sfRequest $request A request object
*/
public function executeCreate($request)
{
$this->forward404Unless($this->acl->isAllowed($this->getUser()->getMemberId(), null, 'add'));
$this->form = new CommunityTopicForm();
$this->form->getObject()->setMemberId($this->getUser()->getMemberId());
$this->form->getObject()->setCommunity($this->community);
$this->processForm($request, $this->form);
$this->setTemplate('new');
return sfView::SUCCESS;
}
/**
* Executes edit action
*
* @param sfRequest $request A request object
*/
public function executeEdit($request)
{
$this->form = new CommunityTopicForm($this->communityTopic);
return sfView::SUCCESS;
}
/**
* Executes update action
*
* @param sfRequest $request A request object
*/
public function executeUpdate($request)
{
$this->form = new CommunityTopicForm($this->communityTopic);
$this->processForm($request, $this->form);
$this->setTemplate('edit');
return sfView::SUCCESS;
}
/**
* Executes deleteConfirm action
*
* @param sfRequest $request A request object
*/
public function executeDeleteConfirm(sfWebRequest $request)
{
$this->form = new sfForm();
return sfView::SUCCESS;
}
/**
* Executes delete action
*
* @param sfRequest $request A request object
*/
public function executeDelete($request)
{
$request->checkCSRFProtection();
$this->communityTopic->delete();
$this->getUser()->setFlash('notice', 'The %community% topic was deleted successfully.');
$this->redirect('community/home?id='.$this->community->getId());
}
/**
* Executes recentlyTopicList
*
* @param sfRequest $request A request object
*/
public function executeRecentlyTopicList($request)
{
if (!$this->size)
{
$this->size = 50;
}
$this->pager = Doctrine::getTable('CommunityTopic')->getRecentlyTopicListPager(
$this->getUser()->getMemberId(),
$request->getParameter('page', 1),
$this->size
);
return sfView::SUCCESS;
}
/**
* Executes search action
*
* @param sfRequest $request A request object
*/
public function executeSearch($request)
{
$params = array(
'keyword' => $request->getParameter('keyword'),
'target' => $request->getParameter('target', 'in_community'),
'type' => $request->getParameter('type', 'topic'),
);
$this->form = new PluginCommunityTopicSearchForm();
$this->form->bind($params);
if ('event' === $request->getParameter('type'))
{
$table = Doctrine::getTable('CommunityEvent');
$this->link_to_detail = 'communityEvent/show?id=%d';
$this->type = 'event';
}
else
{
$table = Doctrine::getTable('CommunityTopic');
$this->link_to_detail = 'communityTopic/show?id=%d';
$this->type = 'topic';
}
$this->communityId = $request->getParameter('id');
$this->pageUrl = '@communityTopic_search';
if (!$request->hasParameter('id'))
{
unset($this->form['target']);
$this->pageUrl .= '_all';
}
else
{
$this->pageUrl .= '?id='.$this->communityId;
}
$q = $table->getSearchQuery($request->getParameter('id'), $request->getParameter('target'), $request->getParameter('keyword'), $this->getUser()->getMemberId());
$this->pager = $table->getResultListPager($q, $request->getParameter('page'));
$this->isResult = false;
if (null !== $request->getParameter('keyword') || null !== $request->getParameter('target') || null !== $request->getParameter('type'))
{
$this->isResult = true;
}
return sfView::SUCCESS;
}
public function executeConfigNotificationMail($request)
{
$form = new opConfigCommunityTopicNotificationMailForm($request['id']);
$form->bind($request['topic_notify']);
if ($form->isValid())
{
$form->save();
$this->getUser()->setFlash('notice', 'Configuring was successfull.');
}
else
{
$this->getUser()->setFlash('error', 'Failed to configure.');
}
$this->redirect('@community_home?id='.$request['id']);
}
protected function processForm($request, sfForm $form)
{
$form->bind(
$request->getParameter($form->getName()),
$request->getFiles($form->getName())
);
if ($form->isValid())
{
$communityTopic = $form->save();
$this->redirect('@communityTopic_show?id='.$communityTopic->getId());
}
}
}