9623 |
nelberth |
1 |
<?php
|
|
|
2 |
declare(strict_types=1);
|
|
|
3 |
|
|
|
4 |
namespace LeadersLinked\Controller;
|
|
|
5 |
|
|
|
6 |
use Laminas\Authentication\AuthenticationService;
|
|
|
7 |
use Laminas\Authentication\Result as AuthResult;
|
|
|
8 |
use Laminas\Db\Adapter\AdapterInterface;
|
|
|
9 |
use Laminas\Cache\Storage\Adapter\AbstractAdapter;
|
|
|
10 |
use Laminas\Mvc\Controller\AbstractActionController;
|
|
|
11 |
use Laminas\Log\LoggerInterface;
|
|
|
12 |
use Laminas\View\Model\ViewModel;
|
|
|
13 |
use Laminas\View\Model\JsonModel;
|
|
|
14 |
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
|
9672 |
nelberth |
15 |
use LeadersLinked\Model\Topic;
|
9659 |
nelberth |
16 |
use LeadersLinked\Mapper\TopicMapper;
|
9623 |
nelberth |
17 |
use LeadersLinked\Model\HighPerformanceTeamsGroupsMembers;
|
|
|
18 |
use LeadersLinked\Model\HighPerformanceTeamsGroups;
|
|
|
19 |
use LeadersLinked\Mapper\HighPerformanceTeamsGroupsMembersMapper;
|
|
|
20 |
use LeadersLinked\Mapper\HighPerformanceTeamsGroupsMapper;
|
|
|
21 |
use LeadersLinked\Mapper\UserMapper;
|
|
|
22 |
|
12007 |
nelberth |
23 |
use LeadersLinked\Form\HighPerformanceTeamsGroupsViewForoCategoriesTopicForm;
|
9623 |
nelberth |
24 |
use LeadersLinked\Library\Functions;
|
|
|
25 |
|
|
|
26 |
|
|
|
27 |
class HighPerformanceTeamsGroupsViewForoCategoriesController extends AbstractActionController
|
|
|
28 |
{
|
|
|
29 |
/**
|
|
|
30 |
*
|
|
|
31 |
* @var AdapterInterface
|
|
|
32 |
*/
|
|
|
33 |
private $adapter;
|
|
|
34 |
|
|
|
35 |
|
|
|
36 |
/**
|
|
|
37 |
*
|
|
|
38 |
* @var AbstractAdapter
|
|
|
39 |
*/
|
|
|
40 |
private $cache;
|
|
|
41 |
|
|
|
42 |
/**
|
|
|
43 |
*
|
|
|
44 |
* @var LoggerInterface
|
|
|
45 |
*/
|
|
|
46 |
private $logger;
|
|
|
47 |
|
|
|
48 |
/**
|
|
|
49 |
*
|
|
|
50 |
* @var array
|
|
|
51 |
*/
|
|
|
52 |
private $config;
|
|
|
53 |
|
|
|
54 |
|
|
|
55 |
|
|
|
56 |
/**
|
|
|
57 |
*
|
|
|
58 |
* @param AdapterInterface $adapter
|
|
|
59 |
* @param AbstractAdapter $cache
|
|
|
60 |
* @param LoggerInterface $logger
|
|
|
61 |
* @param array $config
|
|
|
62 |
*/
|
|
|
63 |
public function __construct($adapter, $cache , $logger, $config)
|
|
|
64 |
{
|
|
|
65 |
$this->adapter = $adapter;
|
|
|
66 |
$this->cache = $cache;
|
|
|
67 |
$this->logger = $logger;
|
|
|
68 |
$this->config = $config;
|
|
|
69 |
|
|
|
70 |
|
|
|
71 |
}
|
|
|
72 |
|
|
|
73 |
|
|
|
74 |
public function indexAction()
|
|
|
75 |
{
|
|
|
76 |
|
|
|
77 |
|
|
|
78 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
79 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
80 |
$currentCompany = $currentUserPlugin->getCompany();
|
11085 |
nelberth |
81 |
$group_uuid = $this->params()->fromRoute('group_id');
|
9623 |
nelberth |
82 |
|
9772 |
nelberth |
83 |
|
9623 |
nelberth |
84 |
$request = $this->getRequest();
|
|
|
85 |
if($request->isGet()) {
|
|
|
86 |
|
|
|
87 |
|
|
|
88 |
$headers = $request->getHeaders();
|
9724 |
nelberth |
89 |
$isJson = false;
|
9623 |
nelberth |
90 |
if($headers->has('Accept')) {
|
|
|
91 |
$accept = $headers->get('Accept');
|
|
|
92 |
|
|
|
93 |
$prioritized = $accept->getPrioritized();
|
|
|
94 |
|
|
|
95 |
foreach($prioritized as $key => $value) {
|
|
|
96 |
$raw = trim($value->getRaw());
|
|
|
97 |
|
|
|
98 |
if(!$isJson) {
|
|
|
99 |
$isJson = strpos($raw, 'json');
|
|
|
100 |
}
|
|
|
101 |
|
|
|
102 |
}
|
|
|
103 |
}
|
11188 |
nelberth |
104 |
$this->layout()->setTemplate('layout/layout-backend');
|
|
|
105 |
$viewModel = new ViewModel();
|
9623 |
nelberth |
106 |
|
|
|
107 |
$highPerformanceTeamsGroupsMapper = HighPerformanceTeamsGroupsMapper::getInstance($this->adapter);
|
|
|
108 |
$highPerformanceTeamsGroups = $highPerformanceTeamsGroupsMapper->fetchOneByUuid($group_uuid);
|
|
|
109 |
|
|
|
110 |
if (!$highPerformanceTeamsGroups) {
|
11188 |
nelberth |
111 |
$viewModel->setTemplate('leaders-linked/no-access/index.phtml');
|
|
|
112 |
return $viewModel;
|
9623 |
nelberth |
113 |
}
|
|
|
114 |
|
|
|
115 |
if($highPerformanceTeamsGroups->status != HighPerformanceTeamsGroups::STATUS_ACTIVE) {
|
11188 |
nelberth |
116 |
$viewModel->setTemplate('leaders-linked/no-access/index.phtml');
|
|
|
117 |
return $viewModel;
|
9623 |
nelberth |
118 |
}
|
9679 |
nelberth |
119 |
|
10374 |
nelberth |
120 |
$highPerformanceTeamsGroupsMembersMapper = HighPerformanceTeamsGroupsMembersMapper::getInstance($this->adapter);
|
|
|
121 |
$highPerformanceTeamsGroupsMember = $highPerformanceTeamsGroupsMembersMapper->fetchOneByGroupIdAndUserId($highPerformanceTeamsGroups->id, $currentUser->id);
|
|
|
122 |
if(!$highPerformanceTeamsGroupsMember) {
|
11188 |
nelberth |
123 |
$viewModel->setTemplate('leaders-linked/no-access/index.phtml');
|
|
|
124 |
return $viewModel;
|
10374 |
nelberth |
125 |
}
|
|
|
126 |
if(!($highPerformanceTeamsGroupsMember->status == HighPerformanceTeamsGroupsMembers::STATUS_ACCEPTED || $highPerformanceTeamsGroupsMember->status == HighPerformanceTeamsGroupsMembers::STATUS_ADDED_BY_ADMIN) ){
|
11188 |
nelberth |
127 |
$viewModel->setTemplate('leaders-linked/no-access/index.phtml');
|
|
|
128 |
return $viewModel;
|
10374 |
nelberth |
129 |
}
|
|
|
130 |
$addTopicBoton=true;
|
|
|
131 |
if($highPerformanceTeamsGroupsMember->type==HighPerformanceTeamsGroupsMembers::TYPE_MODERATOR||$highPerformanceTeamsGroupsMember->type==HighPerformanceTeamsGroupsMembers::TYPE_USER){
|
|
|
132 |
$addTopicBoton=false;
|
|
|
133 |
}
|
|
|
134 |
|
10373 |
nelberth |
135 |
|
|
|
136 |
|
11188 |
nelberth |
137 |
|
9623 |
nelberth |
138 |
|
12007 |
nelberth |
139 |
$formTopic = new HighPerformanceTeamsGroupsViewForoCategoriesTopicForm();
|
9632 |
nelberth |
140 |
$viewModel->setTemplate('leaders-linked/high-performance-teams-groups-view-foro-categories/index.phtml');
|
9623 |
nelberth |
141 |
$viewModel->setVariables([
|
|
|
142 |
'group_uuid' => $group_uuid,
|
|
|
143 |
'group_title'=>$highPerformanceTeamsGroups->title,
|
|
|
144 |
'formTopic'=> $formTopic,
|
10374 |
nelberth |
145 |
'addTopicBoton'=>$addTopicBoton
|
9623 |
nelberth |
146 |
]);
|
|
|
147 |
return $viewModel ;
|
|
|
148 |
|
|
|
149 |
|
|
|
150 |
|
9721 |
nelberth |
151 |
|
9623 |
nelberth |
152 |
} else {
|
|
|
153 |
return new JsonModel([
|
|
|
154 |
'success' => false,
|
|
|
155 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
156 |
]);
|
|
|
157 |
}
|
|
|
158 |
}
|
9720 |
nelberth |
159 |
|
|
|
160 |
public function viewAction(){
|
|
|
161 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
162 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
163 |
$currentCompany = $currentUserPlugin->getCompany();
|
11085 |
nelberth |
164 |
$group_uuid = $this->params()->fromRoute('group_id');
|
9720 |
nelberth |
165 |
|
9772 |
nelberth |
166 |
|
9720 |
nelberth |
167 |
$request = $this->getRequest();
|
|
|
168 |
if($request->isGet()) {
|
|
|
169 |
|
|
|
170 |
|
|
|
171 |
$headers = $request->getHeaders();
|
|
|
172 |
$isJson = false;
|
|
|
173 |
if($headers->has('Accept')) {
|
|
|
174 |
$accept = $headers->get('Accept');
|
|
|
175 |
|
|
|
176 |
$prioritized = $accept->getPrioritized();
|
|
|
177 |
|
|
|
178 |
foreach($prioritized as $key => $value) {
|
|
|
179 |
$raw = trim($value->getRaw());
|
|
|
180 |
|
|
|
181 |
if(!$isJson) {
|
|
|
182 |
$isJson = strpos($raw, 'json');
|
|
|
183 |
}
|
|
|
184 |
|
|
|
185 |
}
|
|
|
186 |
}
|
|
|
187 |
|
|
|
188 |
$highPerformanceTeamsGroupsMapper = HighPerformanceTeamsGroupsMapper::getInstance($this->adapter);
|
|
|
189 |
$highPerformanceTeamsGroups = $highPerformanceTeamsGroupsMapper->fetchOneByUuid($group_uuid);
|
|
|
190 |
|
|
|
191 |
if (!$highPerformanceTeamsGroups) {
|
|
|
192 |
$data = [
|
|
|
193 |
'success' => false,
|
|
|
194 |
'data' => 'ERROR_RECORD_NOT_FOUND'
|
|
|
195 |
];
|
|
|
196 |
|
|
|
197 |
return new JsonModel($data);
|
|
|
198 |
}
|
10374 |
nelberth |
199 |
if($highPerformanceTeamsGroups->status != HighPerformanceTeamsGroups::STATUS_ACTIVE) {
|
|
|
200 |
|
|
|
201 |
return new JsonModel([
|
|
|
202 |
'success' => false,
|
|
|
203 |
'data' => 'ERROR_UNAUTHORIZED'
|
|
|
204 |
]);
|
|
|
205 |
|
|
|
206 |
}
|
|
|
207 |
$highPerformanceTeamsGroupsMembersMapper = HighPerformanceTeamsGroupsMembersMapper::getInstance($this->adapter);
|
|
|
208 |
$highPerformanceTeamsGroupsMember = $highPerformanceTeamsGroupsMembersMapper->fetchOneByGroupIdAndUserId($highPerformanceTeamsGroups->id, $currentUser->id);
|
9720 |
nelberth |
209 |
if(!$highPerformanceTeamsGroupsMember) {
|
|
|
210 |
return new JsonModel([
|
|
|
211 |
'success' => false,
|
|
|
212 |
'data' => 'ERROR_RECORD_NOT_FOUND'
|
|
|
213 |
]);
|
|
|
214 |
}
|
|
|
215 |
if(!($highPerformanceTeamsGroupsMember->status == HighPerformanceTeamsGroupsMembers::STATUS_ACCEPTED || $highPerformanceTeamsGroupsMember->status == HighPerformanceTeamsGroupsMembers::STATUS_ADDED_BY_ADMIN) ){
|
|
|
216 |
return new JsonModel([
|
|
|
217 |
'success' => false,
|
|
|
218 |
'data' => 'ERROR_YOU_DO_NOT_HAVE_ACCESS'
|
|
|
219 |
]);
|
|
|
220 |
}
|
10374 |
nelberth |
221 |
|
9720 |
nelberth |
222 |
$acl = $this->getEvent()->getViewModel()->getVariable('acl');
|
|
|
223 |
$allowEdit = $acl->isAllowed($currentUser->usertype_id, 'high-performance-teams/groups/view/foro/categories/edit');
|
|
|
224 |
$allowDelete = $acl->isAllowed($currentUser->usertype_id,'high-performance-teams/groups/view/foro/categories/delete');
|
|
|
225 |
$allowView = $acl->isAllowed($currentUser->usertype_id,'high-performance-teams/groups/view');
|
10374 |
nelberth |
226 |
|
|
|
227 |
if($highPerformanceTeamsGroupsMember->type==HighPerformanceTeamsGroupsMembers::TYPE_MODERATOR||$highPerformanceTeamsGroupsMember->type==HighPerformanceTeamsGroupsMembers::TYPE_USER){
|
10376 |
nelberth |
228 |
$allowDelete=false;
|
10374 |
nelberth |
229 |
$allowEdit=false;
|
|
|
230 |
}
|
|
|
231 |
|
|
|
232 |
|
|
|
233 |
if($isJson) {
|
9720 |
nelberth |
234 |
|
11085 |
nelberth |
235 |
$group_uuid = $this->params()->fromRoute('group_id');
|
10374 |
nelberth |
236 |
if(!$group_uuid) {
|
|
|
237 |
$data = [
|
|
|
238 |
'success' => false,
|
|
|
239 |
'data' => 'ERROR_INVALID_PARAMETER'
|
|
|
240 |
];
|
|
|
241 |
|
|
|
242 |
return new JsonModel($data);
|
|
|
243 |
}
|
9720 |
nelberth |
244 |
|
|
|
245 |
|
10374 |
nelberth |
246 |
|
|
|
247 |
|
|
|
248 |
|
|
|
249 |
|
|
|
250 |
|
9720 |
nelberth |
251 |
$topicMapper = TopicMapper::getInstance($this->adapter);
|
|
|
252 |
|
|
|
253 |
$paginator = $topicMapper->fetchAllHighPerfromanceTeamsGroupForo($highPerformanceTeamsGroups->id);
|
|
|
254 |
|
|
|
255 |
$items = [];
|
|
|
256 |
|
|
|
257 |
|
|
|
258 |
|
|
|
259 |
foreach($paginator as $record)
|
|
|
260 |
{
|
|
|
261 |
|
|
|
262 |
|
|
|
263 |
$item = [
|
|
|
264 |
'title' => $record->title,
|
|
|
265 |
'description'=>$record->description,
|
|
|
266 |
'status'=> $record->status,
|
|
|
267 |
'actions' => [
|
11085 |
nelberth |
268 |
'link_edit' => $allowEdit ? $this->url()->fromRoute('high-performance-teams/groups/view/foro/categories/edit', ['group_id' => $highPerformanceTeamsGroups->uuid, 'category_id' => $record->uuid]) : '',
|
|
|
269 |
'link_delete' => $allowDelete ? $this->url()->fromRoute('high-performance-teams/groups/view/foro/categories/delete', ['group_id' => $highPerformanceTeamsGroups->uuid,'category_id' => $record->uuid]) : '',
|
|
|
270 |
'link_view' => $allowView ? $this->url()->fromRoute('high-performance-teams/groups/view/foro/categories/articles', ['group_id' => $highPerformanceTeamsGroups->uuid,'category_id' => $record->uuid]) : '',
|
9720 |
nelberth |
271 |
]
|
|
|
272 |
|
|
|
273 |
];
|
|
|
274 |
|
|
|
275 |
array_push($items, $item);
|
|
|
276 |
|
|
|
277 |
}
|
|
|
278 |
|
|
|
279 |
return new JsonModel([
|
|
|
280 |
'success' => true,
|
|
|
281 |
'data' => [
|
|
|
282 |
'items' => $items
|
|
|
283 |
]
|
|
|
284 |
]);
|
|
|
285 |
|
|
|
286 |
}
|
|
|
287 |
} else {
|
|
|
288 |
return new JsonModel([
|
|
|
289 |
'success' => false,
|
|
|
290 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
291 |
]);
|
|
|
292 |
}
|
|
|
293 |
}
|
|
|
294 |
|
9656 |
nelberth |
295 |
public function addAction()
|
|
|
296 |
{
|
9623 |
nelberth |
297 |
|
11085 |
nelberth |
298 |
$group_uuid = $this->params()->fromRoute('group_id');
|
9656 |
nelberth |
299 |
if(!$group_uuid) {
|
|
|
300 |
$data = [
|
|
|
301 |
'success' => false,
|
|
|
302 |
'data' => 'ERROR_INVALID_PARAMETER'
|
|
|
303 |
];
|
|
|
304 |
|
|
|
305 |
return new JsonModel($data);
|
|
|
306 |
}
|
9732 |
nelberth |
307 |
|
9661 |
nelberth |
308 |
|
9656 |
nelberth |
309 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
310 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
311 |
$currentCompany = $currentUserPlugin->getCompany();
|
|
|
312 |
|
|
|
313 |
$request = $this->getRequest();
|
9662 |
nelberth |
314 |
|
9666 |
nelberth |
315 |
|
|
|
316 |
|
9656 |
nelberth |
317 |
if($request->isPost()) {
|
9665 |
nelberth |
318 |
|
12006 |
nelberth |
319 |
$form = new HighPerformanceTeamsGroupsViewForoCategoriesTopicForm();
|
9663 |
nelberth |
320 |
$dataPost = $request->getPost()->toArray();
|
9666 |
nelberth |
321 |
$form->setData($dataPost);
|
9667 |
nelberth |
322 |
|
9656 |
nelberth |
323 |
if($form->isValid()) {
|
|
|
324 |
$dataPost = (array) $form->getData();
|
9659 |
nelberth |
325 |
$dataPost['status'] = isset($dataPost['status']) ? $dataPost['status'] : Topic::STATUS_INACTIVE;
|
9656 |
nelberth |
326 |
|
|
|
327 |
|
|
|
328 |
$highPerformanceTeamsGroupsMapper = HighPerformanceTeamsGroupsMapper::getInstance($this->adapter);
|
|
|
329 |
$highPerformanceTeamsGroups = $highPerformanceTeamsGroupsMapper->fetchOneByUuid($group_uuid);
|
|
|
330 |
|
|
|
331 |
if (!$highPerformanceTeamsGroups) {
|
|
|
332 |
$data = [
|
|
|
333 |
'success' => false,
|
|
|
334 |
'data' => 'ERROR_RECORD_NOT_FOUND'
|
|
|
335 |
];
|
|
|
336 |
|
|
|
337 |
return new JsonModel($data);
|
|
|
338 |
}
|
10373 |
nelberth |
339 |
if($highPerformanceTeamsGroups->status != HighPerformanceTeamsGroups::STATUS_ACTIVE) {
|
|
|
340 |
|
|
|
341 |
return new JsonModel([
|
|
|
342 |
'success' => false,
|
|
|
343 |
'data' => 'ERROR_UNAUTHORIZED'
|
|
|
344 |
]);
|
|
|
345 |
|
|
|
346 |
}
|
|
|
347 |
$highPerformanceTeamsGroupsMembersMapper = HighPerformanceTeamsGroupsMembersMapper::getInstance($this->adapter);
|
|
|
348 |
$highPerformanceTeamsGroupsMember = $highPerformanceTeamsGroupsMembersMapper->fetchOneByGroupIdAndUserId($highPerformanceTeamsGroups->id, $currentUser->id);
|
9656 |
nelberth |
349 |
if(!$highPerformanceTeamsGroupsMember) {
|
|
|
350 |
return new JsonModel([
|
|
|
351 |
'success' => false,
|
|
|
352 |
'data' => 'ERROR_RECORD_NOT_FOUND'
|
|
|
353 |
]);
|
|
|
354 |
}
|
|
|
355 |
if(!($highPerformanceTeamsGroupsMember->status == HighPerformanceTeamsGroupsMembers::STATUS_ACCEPTED || $highPerformanceTeamsGroupsMember->status == HighPerformanceTeamsGroupsMembers::STATUS_ADDED_BY_ADMIN) ){
|
|
|
356 |
return new JsonModel([
|
|
|
357 |
'success' => false,
|
|
|
358 |
'data' => 'ERROR_YOU_DO_NOT_HAVE_ACCESS'
|
|
|
359 |
]);
|
|
|
360 |
}
|
9671 |
nelberth |
361 |
|
10373 |
nelberth |
362 |
if($highPerformanceTeamsGroupsMember->type==HighPerformanceTeamsGroupsMembers::TYPE_MODERATOR||$highPerformanceTeamsGroupsMember->type==HighPerformanceTeamsGroupsMembers::TYPE_USER){
|
|
|
363 |
return new JsonModel([
|
|
|
364 |
'success' => false,
|
|
|
365 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
366 |
]);
|
|
|
367 |
}
|
|
|
368 |
|
9671 |
nelberth |
369 |
$hydrator = new ObjectPropertyHydrator();
|
|
|
370 |
$topic = new Topic();
|
9676 |
nelberth |
371 |
|
|
|
372 |
|
|
|
373 |
$hydrator->hydrate($dataPost, $topic);
|
9677 |
nelberth |
374 |
$topic->type='hptgf';
|
9676 |
nelberth |
375 |
$topic->high_performance_group_id=$highPerformanceTeamsGroups->id;
|
|
|
376 |
$topicMapper = TopicMapper::getInstance($this->adapter);
|
9656 |
nelberth |
377 |
$result = $topicMapper->insert($topic);
|
|
|
378 |
|
|
|
379 |
if($result) {
|
|
|
380 |
|
|
|
381 |
$this->logger->info('Se agrego la categoria del foro con el titulo ' . $topic->title, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
|
|
|
382 |
|
|
|
383 |
$data = [
|
|
|
384 |
'success' => true,
|
|
|
385 |
'data' => 'LABEL_RECORD_ADDED'
|
|
|
386 |
];
|
|
|
387 |
} else {
|
|
|
388 |
$data = [
|
|
|
389 |
'success' => false,
|
|
|
390 |
'data' => $topicMapper->getError()
|
|
|
391 |
];
|
|
|
392 |
|
|
|
393 |
}
|
|
|
394 |
|
|
|
395 |
return new JsonModel($data);
|
|
|
396 |
|
|
|
397 |
} else {
|
|
|
398 |
$messages = [];
|
|
|
399 |
$form_messages = (array) $form->getMessages();
|
|
|
400 |
foreach($form_messages as $fieldname => $field_messages)
|
|
|
401 |
{
|
|
|
402 |
|
|
|
403 |
$messages[$fieldname] = array_values($field_messages);
|
|
|
404 |
}
|
|
|
405 |
|
|
|
406 |
return new JsonModel([
|
|
|
407 |
'success' => false,
|
|
|
408 |
'data' => $messages
|
|
|
409 |
]);
|
|
|
410 |
}
|
|
|
411 |
|
|
|
412 |
} else {
|
|
|
413 |
$data = [
|
|
|
414 |
'success' => false,
|
|
|
415 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
416 |
];
|
|
|
417 |
|
|
|
418 |
return new JsonModel($data);
|
|
|
419 |
}
|
|
|
420 |
|
|
|
421 |
return new JsonModel($data);
|
|
|
422 |
|
|
|
423 |
|
9640 |
nelberth |
424 |
}
|
9727 |
nelberth |
425 |
|
9640 |
nelberth |
426 |
public function editAction(){
|
9725 |
nelberth |
427 |
|
|
|
428 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
429 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
430 |
$currentCompany = $currentUserPlugin->getCompany();
|
|
|
431 |
$request = $this->getRequest();
|
11085 |
nelberth |
432 |
$group_uuid = $this->params()->fromRoute('group_id');
|
9640 |
nelberth |
433 |
|
11085 |
nelberth |
434 |
$category_uuid = $this->params()->fromRoute('category_id');
|
9725 |
nelberth |
435 |
|
|
|
436 |
|
|
|
437 |
if(!$group_uuid) {
|
|
|
438 |
$data = [
|
|
|
439 |
'success' => false,
|
|
|
440 |
'data' => 'ERROR_INVALID_PARAMETER'
|
|
|
441 |
];
|
|
|
442 |
|
|
|
443 |
return new JsonModel($data);
|
|
|
444 |
}
|
9732 |
nelberth |
445 |
if(!$category_uuid) {
|
9725 |
nelberth |
446 |
$data = [
|
|
|
447 |
'success' => false,
|
|
|
448 |
'data' => 'ERROR_INVALID_PARAMETER'
|
|
|
449 |
];
|
|
|
450 |
|
|
|
451 |
return new JsonModel($data);
|
|
|
452 |
}
|
|
|
453 |
|
|
|
454 |
|
|
|
455 |
$topicMapper = TopicMapper::getInstance($this->adapter);
|
9732 |
nelberth |
456 |
$topic = $topicMapper->fetchOneByUuid($category_uuid);
|
9725 |
nelberth |
457 |
|
|
|
458 |
if (!$topic) {
|
|
|
459 |
$data = [
|
|
|
460 |
'success' => false,
|
|
|
461 |
'data' => 'ERROR_RECORD_NOT_FOUND'
|
|
|
462 |
];
|
|
|
463 |
|
|
|
464 |
return new JsonModel($data);
|
|
|
465 |
}
|
|
|
466 |
|
|
|
467 |
|
|
|
468 |
$highPerformanceTeamsGroupsMapper = HighPerformanceTeamsGroupsMapper::getInstance($this->adapter);
|
|
|
469 |
$highPerformanceTeamsGroups = $highPerformanceTeamsGroupsMapper->fetchOneByUuid($group_uuid);
|
|
|
470 |
|
|
|
471 |
if (!$highPerformanceTeamsGroups) {
|
|
|
472 |
$data = [
|
|
|
473 |
'success' => false,
|
|
|
474 |
'data' => 'ERROR_RECORD_NOT_FOUND'
|
|
|
475 |
];
|
|
|
476 |
|
|
|
477 |
return new JsonModel($data);
|
|
|
478 |
}
|
10373 |
nelberth |
479 |
if($highPerformanceTeamsGroups->status != HighPerformanceTeamsGroups::STATUS_ACTIVE) {
|
9725 |
nelberth |
480 |
|
10373 |
nelberth |
481 |
return new JsonModel([
|
|
|
482 |
'success' => false,
|
|
|
483 |
'data' => 'ERROR_UNAUTHORIZED'
|
|
|
484 |
]);
|
|
|
485 |
|
|
|
486 |
}
|
|
|
487 |
$highPerformanceTeamsGroupsMembersMapper = HighPerformanceTeamsGroupsMembersMapper::getInstance($this->adapter);
|
|
|
488 |
$highPerformanceTeamsGroupsMember = $highPerformanceTeamsGroupsMembersMapper->fetchOneByGroupIdAndUserId($highPerformanceTeamsGroups->id, $currentUser->id);
|
9725 |
nelberth |
489 |
if(!$highPerformanceTeamsGroupsMember) {
|
|
|
490 |
return new JsonModel([
|
|
|
491 |
'success' => false,
|
|
|
492 |
'data' => 'ERROR_RECORD_NOT_FOUND'
|
|
|
493 |
]);
|
|
|
494 |
}
|
|
|
495 |
if(!($highPerformanceTeamsGroupsMember->status == HighPerformanceTeamsGroupsMembers::STATUS_ACCEPTED || $highPerformanceTeamsGroupsMember->status == HighPerformanceTeamsGroupsMembers::STATUS_ADDED_BY_ADMIN) ){
|
|
|
496 |
return new JsonModel([
|
|
|
497 |
'success' => false,
|
|
|
498 |
'data' => 'ERROR_YOU_DO_NOT_HAVE_ACCESS'
|
|
|
499 |
]);
|
|
|
500 |
}
|
10373 |
nelberth |
501 |
|
|
|
502 |
if($highPerformanceTeamsGroupsMember->type==HighPerformanceTeamsGroupsMembers::TYPE_MODERATOR||$highPerformanceTeamsGroupsMember->type==HighPerformanceTeamsGroupsMembers::TYPE_USER){
|
|
|
503 |
return new JsonModel([
|
|
|
504 |
'success' => false,
|
|
|
505 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
506 |
]);
|
|
|
507 |
}
|
|
|
508 |
if($request->isPost()) {
|
12006 |
nelberth |
509 |
$form = new HighPerformanceTeamsGroupsViewForoCategoriesTopicForm();
|
10373 |
nelberth |
510 |
$dataPost = $request->getPost()->toArray();
|
|
|
511 |
$dataPost['status'] = isset($dataPost['status']) ? $dataPost['status'] : Topic::STATUS_INACTIVE;
|
|
|
512 |
|
|
|
513 |
|
|
|
514 |
|
|
|
515 |
|
|
|
516 |
$form->setData($dataPost);
|
|
|
517 |
|
|
|
518 |
if($form->isValid()) {
|
|
|
519 |
$dataPost = (array) $form->getData();
|
|
|
520 |
|
9725 |
nelberth |
521 |
|
|
|
522 |
$hydrator = new ObjectPropertyHydrator();
|
|
|
523 |
$hydrator->hydrate($dataPost, $topic);
|
|
|
524 |
|
|
|
525 |
$result = $topicMapper->update($topic);
|
|
|
526 |
|
|
|
527 |
if($result) {
|
9726 |
nelberth |
528 |
$this->logger->info('Se actualizo la categoria del foro de alto rendimiento ' . $topic->title, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
|
9725 |
nelberth |
529 |
|
|
|
530 |
$data = [
|
|
|
531 |
'success' => true,
|
|
|
532 |
'data' => 'LABEL_RECORD_UPDATED'
|
|
|
533 |
];
|
|
|
534 |
} else {
|
|
|
535 |
$data = [
|
|
|
536 |
'success' => false,
|
|
|
537 |
'data' => $topicMapper->getError()
|
|
|
538 |
];
|
|
|
539 |
}
|
|
|
540 |
|
|
|
541 |
return new JsonModel($data);
|
|
|
542 |
|
|
|
543 |
} else {
|
|
|
544 |
$messages = [];
|
|
|
545 |
$form_messages = (array) $form->getMessages();
|
|
|
546 |
foreach($form_messages as $fieldname => $field_messages)
|
|
|
547 |
{
|
|
|
548 |
$messages[$fieldname] = array_values($field_messages);
|
|
|
549 |
}
|
|
|
550 |
|
|
|
551 |
return new JsonModel([
|
|
|
552 |
'success' => false,
|
|
|
553 |
'data' => $messages
|
|
|
554 |
]);
|
|
|
555 |
}
|
|
|
556 |
}else if ($request->isGet()) {
|
|
|
557 |
$hydrator = new ObjectPropertyHydrator();
|
|
|
558 |
|
|
|
559 |
$data = [
|
|
|
560 |
'success' => true,
|
|
|
561 |
'data' => $hydrator->extract($topic)
|
|
|
562 |
];
|
|
|
563 |
|
|
|
564 |
return new JsonModel($data);
|
|
|
565 |
} else {
|
|
|
566 |
$data = [
|
|
|
567 |
'success' => false,
|
|
|
568 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
569 |
];
|
|
|
570 |
|
|
|
571 |
return new JsonModel($data);
|
|
|
572 |
}
|
|
|
573 |
|
|
|
574 |
return new JsonModel($data);
|
|
|
575 |
|
9640 |
nelberth |
576 |
}
|
9727 |
nelberth |
577 |
public function deleteAction(){
|
9623 |
nelberth |
578 |
|
9727 |
nelberth |
579 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
580 |
$currentCompany = $currentUserPlugin->getCompany();
|
|
|
581 |
$currentUser = $currentUserPlugin->getUser();
|
9623 |
nelberth |
582 |
|
9727 |
nelberth |
583 |
$request = $this->getRequest();
|
11085 |
nelberth |
584 |
$group_uuid = $this->params()->fromRoute('group_id');
|
|
|
585 |
$category_uuid = $this->params()->fromRoute('category_id');
|
9727 |
nelberth |
586 |
|
9731 |
nelberth |
587 |
|
9727 |
nelberth |
588 |
if (!$group_uuid) {
|
|
|
589 |
$data = [
|
|
|
590 |
'success' => false,
|
|
|
591 |
'data' => 'ERROR_INVALID_PARAMETER'
|
|
|
592 |
];
|
|
|
593 |
|
|
|
594 |
return new JsonModel($data);
|
|
|
595 |
}
|
9732 |
nelberth |
596 |
if(!$category_uuid) {
|
|
|
597 |
$data = [
|
|
|
598 |
'success' => false,
|
|
|
599 |
'data' => 'ERROR_INVALID_PARAMETER'
|
|
|
600 |
];
|
|
|
601 |
|
|
|
602 |
return new JsonModel($data);
|
|
|
603 |
}
|
9727 |
nelberth |
604 |
$highPerformanceTeamsGroupsMapper = HighPerformanceTeamsGroupsMapper::getInstance($this->adapter);
|
10373 |
nelberth |
605 |
$highPerformanceTeamsGroups = $highPerformanceTeamsGroupsMapper->fetchOneByUuid($group_uuid);
|
|
|
606 |
|
|
|
607 |
if (!$highPerformanceTeamsGroups) {
|
|
|
608 |
$data = [
|
|
|
609 |
'success' => false,
|
|
|
610 |
'data' => 'ERROR_RECORD_NOT_FOUND'
|
|
|
611 |
];
|
9727 |
nelberth |
612 |
|
10373 |
nelberth |
613 |
return new JsonModel($data);
|
|
|
614 |
}
|
|
|
615 |
if($highPerformanceTeamsGroups->status != HighPerformanceTeamsGroups::STATUS_ACTIVE) {
|
|
|
616 |
|
|
|
617 |
return new JsonModel([
|
|
|
618 |
'success' => false,
|
|
|
619 |
'data' => 'ERROR_UNAUTHORIZED'
|
|
|
620 |
]);
|
|
|
621 |
|
|
|
622 |
}
|
|
|
623 |
$highPerformanceTeamsGroupsMembersMapper = HighPerformanceTeamsGroupsMembersMapper::getInstance($this->adapter);
|
|
|
624 |
$highPerformanceTeamsGroupsMember = $highPerformanceTeamsGroupsMembersMapper->fetchOneByGroupIdAndUserId($highPerformanceTeamsGroups->id, $currentUser->id);
|
9727 |
nelberth |
625 |
if(!$highPerformanceTeamsGroupsMember) {
|
|
|
626 |
return new JsonModel([
|
|
|
627 |
'success' => false,
|
|
|
628 |
'data' => 'ERROR_RECORD_NOT_FOUND'
|
|
|
629 |
]);
|
|
|
630 |
}
|
|
|
631 |
if(!($highPerformanceTeamsGroupsMember->status == HighPerformanceTeamsGroupsMembers::STATUS_ACCEPTED || $highPerformanceTeamsGroupsMember->status == HighPerformanceTeamsGroupsMembers::STATUS_ADDED_BY_ADMIN) ){
|
|
|
632 |
return new JsonModel([
|
|
|
633 |
'success' => false,
|
|
|
634 |
'data' => 'ERROR_YOU_DO_NOT_HAVE_ACCESS'
|
|
|
635 |
]);
|
|
|
636 |
}
|
|
|
637 |
|
10373 |
nelberth |
638 |
if($highPerformanceTeamsGroupsMember->type==HighPerformanceTeamsGroupsMembers::TYPE_MODERATOR||$highPerformanceTeamsGroupsMember->type==HighPerformanceTeamsGroupsMembers::TYPE_USER){
|
|
|
639 |
return new JsonModel([
|
|
|
640 |
'success' => false,
|
|
|
641 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
642 |
]);
|
|
|
643 |
}
|
|
|
644 |
|
9727 |
nelberth |
645 |
$topicMapper = TopicMapper::getInstance($this->adapter);
|
9728 |
nelberth |
646 |
$topic = $topicMapper->fetchOneByUuid($category_uuid);
|
9727 |
nelberth |
647 |
|
|
|
648 |
if (!$topic) {
|
|
|
649 |
$data = [
|
|
|
650 |
'success' => false,
|
|
|
651 |
'data' => 'ERROR_RECORD_NOT_FOUND'
|
|
|
652 |
];
|
|
|
653 |
|
|
|
654 |
return new JsonModel($data);
|
|
|
655 |
}
|
|
|
656 |
|
|
|
657 |
|
|
|
658 |
|
|
|
659 |
if ($request->isPost()) {
|
|
|
660 |
|
|
|
661 |
|
|
|
662 |
$result = $topicMapper->delete($topic->id);
|
|
|
663 |
if ($result) {
|
|
|
664 |
$this->logger->info('Se borro la categoria del foro de alto rendimiento ' . $topic->title, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
|
|
|
665 |
|
|
|
666 |
$data = [
|
|
|
667 |
'success' => true,
|
|
|
668 |
'data' => 'LABEL_RECORD_DELETED'
|
|
|
669 |
];
|
|
|
670 |
} else {
|
|
|
671 |
|
|
|
672 |
$data = [
|
|
|
673 |
'success' => false,
|
|
|
674 |
'data' => $topicMapper->getError()
|
|
|
675 |
];
|
|
|
676 |
|
|
|
677 |
return new JsonModel($data);
|
|
|
678 |
}
|
|
|
679 |
} else {
|
|
|
680 |
$data = [
|
|
|
681 |
'success' => false,
|
|
|
682 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
683 |
];
|
|
|
684 |
|
|
|
685 |
return new JsonModel($data);
|
|
|
686 |
}
|
|
|
687 |
|
|
|
688 |
return new JsonModel($data);
|
|
|
689 |
}
|
|
|
690 |
|
|
|
691 |
|
9623 |
nelberth |
692 |
}
|