7489 |
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\Mvc\I18n\Translator;
|
|
|
12 |
use Laminas\Log\LoggerInterface;
|
|
|
13 |
use Laminas\View\Model\ViewModel;
|
|
|
14 |
use Laminas\View\Model\JsonModel;
|
|
|
15 |
use LeadersLinked\Model\HighPerformanceTeamsGroupsViewTopic;
|
|
|
16 |
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
|
|
|
17 |
use LeadersLinked\Form\HighPerformanceTeamsGroupsViewTopicForm;
|
|
|
18 |
use LeadersLinked\Library\Functions;
|
|
|
19 |
use LeadersLinked\Mapper\UserMapper;
|
|
|
20 |
use LeadersLinked\Mapper\HighPerformanceTeamsGroupsViewTopicMapper;
|
7515 |
nelberth |
21 |
use LeadersLinked\Mapper\HighPerformanceTeamsGroupsMapper;
|
7759 |
nelberth |
22 |
use LeadersLinked\Mapper\HighPerformanceTeamsGroupsMembersMapper;
|
|
|
23 |
use LeadersLinked\Model\HighPerformanceTeamsGroupsMembers;
|
7489 |
nelberth |
24 |
use LeadersLinked\Mapper\CompanyMapper;
|
|
|
25 |
use LeadersLinked\Mapper\CompanyUserMapper;
|
|
|
26 |
|
|
|
27 |
|
|
|
28 |
|
|
|
29 |
class HighPerformanceTeamsGroupsViewTopicController extends AbstractActionController
|
|
|
30 |
{
|
|
|
31 |
/**
|
|
|
32 |
*
|
|
|
33 |
* @var AdapterInterface
|
|
|
34 |
*/
|
|
|
35 |
private $adapter;
|
|
|
36 |
|
|
|
37 |
|
|
|
38 |
/**
|
|
|
39 |
*
|
|
|
40 |
* @var AbstractAdapter
|
|
|
41 |
*/
|
|
|
42 |
private $cache;
|
|
|
43 |
|
|
|
44 |
/**
|
|
|
45 |
*
|
|
|
46 |
* @var LoggerInterface
|
|
|
47 |
*/
|
|
|
48 |
private $logger;
|
|
|
49 |
|
|
|
50 |
/**
|
|
|
51 |
*
|
|
|
52 |
* @var array
|
|
|
53 |
*/
|
|
|
54 |
private $config;
|
|
|
55 |
|
|
|
56 |
|
|
|
57 |
|
|
|
58 |
/**
|
|
|
59 |
*
|
|
|
60 |
* @param AdapterInterface $adapter
|
|
|
61 |
* @param AbstractAdapter $cache
|
|
|
62 |
* @param LoggerInterface $logger
|
|
|
63 |
* @param array $config
|
|
|
64 |
*/
|
|
|
65 |
public function __construct($adapter, $cache , $logger, $config)
|
|
|
66 |
{
|
|
|
67 |
$this->adapter = $adapter;
|
|
|
68 |
$this->cache = $cache;
|
|
|
69 |
$this->logger = $logger;
|
|
|
70 |
$this->config = $config;
|
|
|
71 |
|
|
|
72 |
|
|
|
73 |
}
|
|
|
74 |
|
|
|
75 |
|
|
|
76 |
|
|
|
77 |
|
|
|
78 |
public function indexAction()
|
|
|
79 |
{
|
|
|
80 |
|
7713 |
nelberth |
81 |
|
7489 |
nelberth |
82 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
83 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
84 |
$currentCompany = $currentUserPlugin->getCompany();
|
|
|
85 |
|
7622 |
nelberth |
86 |
|
7489 |
nelberth |
87 |
$request = $this->getRequest();
|
|
|
88 |
if($request->isGet()) {
|
|
|
89 |
|
|
|
90 |
|
|
|
91 |
$headers = $request->getHeaders();
|
|
|
92 |
|
|
|
93 |
$isJson = false;
|
|
|
94 |
if($headers->has('Accept')) {
|
|
|
95 |
$accept = $headers->get('Accept');
|
|
|
96 |
|
|
|
97 |
$prioritized = $accept->getPrioritized();
|
|
|
98 |
|
|
|
99 |
foreach($prioritized as $key => $value) {
|
|
|
100 |
$raw = trim($value->getRaw());
|
|
|
101 |
|
|
|
102 |
if(!$isJson) {
|
|
|
103 |
$isJson = strpos($raw, 'json');
|
|
|
104 |
}
|
|
|
105 |
|
|
|
106 |
}
|
|
|
107 |
}
|
7855 |
nelberth |
108 |
|
7489 |
nelberth |
109 |
if($isJson) {
|
7621 |
nelberth |
110 |
|
7847 |
nelberth |
111 |
$group_uuid = $this->params()->fromRoute('group_uuid');
|
|
|
112 |
if(!$group_uuid) {
|
7547 |
nelberth |
113 |
$data = [
|
|
|
114 |
'success' => false,
|
|
|
115 |
'data' => 'ERROR_INVALID_PARAMETER'
|
|
|
116 |
];
|
|
|
117 |
|
|
|
118 |
return new JsonModel($data);
|
|
|
119 |
}
|
7856 |
nelberth |
120 |
|
7547 |
nelberth |
121 |
$highPerformanceTeamsGroupsMapper = HighPerformanceTeamsGroupsMapper::getInstance($this->adapter);
|
7847 |
nelberth |
122 |
$highPerformanceTeamsGroups = $highPerformanceTeamsGroupsMapper->fetchOneByUuid($group_uuid);
|
7547 |
nelberth |
123 |
|
|
|
124 |
if (!$highPerformanceTeamsGroups) {
|
|
|
125 |
$data = [
|
|
|
126 |
'success' => false,
|
|
|
127 |
'data' => 'ERROR_RECORD_NOT_FOUND'
|
|
|
128 |
];
|
|
|
129 |
|
|
|
130 |
return new JsonModel($data);
|
|
|
131 |
}
|
7857 |
nelberth |
132 |
|
7759 |
nelberth |
133 |
$highPerformanceTeamsGroupsMemberMapper = HighPerformanceTeamsGroupsMembersMapper::getInstance($this->adapter);
|
|
|
134 |
$highPerformanceTeamsGroupsMember = $highPerformanceTeamsGroupsMemberMapper->fetchOneByGroupIdAndUserId($highPerformanceTeamsGroups->id, $currentUser->id);
|
7760 |
nelberth |
135 |
if(!$highPerformanceTeamsGroupsMember) {
|
|
|
136 |
return new JsonModel([
|
|
|
137 |
'success' => false,
|
|
|
138 |
'data' => 'ERROR_RECORD_NOT_FOUND'
|
|
|
139 |
]);
|
|
|
140 |
}
|
7763 |
nelberth |
141 |
if(!($highPerformanceTeamsGroupsMember->status == HighPerformanceTeamsGroupsMembers::STATUS_ACCEPTED || $highPerformanceTeamsGroupsMember->status == HighPerformanceTeamsGroupsMembers::STATUS_ADDED_BY_ADMIN) ){
|
7760 |
nelberth |
142 |
return new JsonModel([
|
|
|
143 |
'success' => false,
|
|
|
144 |
'data' => 'ERROR_YOU_DO_NOT_HAVE_ACCESS'
|
|
|
145 |
]);
|
|
|
146 |
}
|
7551 |
nelberth |
147 |
|
7760 |
nelberth |
148 |
$acl = $this->getEvent()->getViewModel()->getVariable('acl');
|
|
|
149 |
$allowEdit = $acl->isAllowed($currentUser->usertype_id, 'high-performance-teams/groups/view/topic/edit');
|
|
|
150 |
$allowDelete = $acl->isAllowed($currentUser->usertype_id,'high-performance-teams/groups/view/topic/delete');
|
|
|
151 |
$allowView = $acl->isAllowed($currentUser->usertype_id,'high-performance-teams/groups/view');
|
|
|
152 |
|
|
|
153 |
|
|
|
154 |
$search = $this->params()->fromQuery('search', []);
|
|
|
155 |
$search = empty($search['value']) ? '' : filter_var($search['value'], FILTER_SANITIZE_STRING);
|
|
|
156 |
|
|
|
157 |
|
|
|
158 |
$records_x_page = intval($this->params()->fromQuery('length', 10), 10);
|
|
|
159 |
$page = (intval($this->params()->fromQuery('start', 1), 10)/$records_x_page)+1;
|
|
|
160 |
$order = $this->params()->fromQuery('order', []);
|
|
|
161 |
$order_field = empty($order[0]['column']) ? 99 : intval($order[0]['column'], 10);
|
|
|
162 |
$order_direction = empty($order[0]['dir']) ? 'ASC' : strtoupper(filter_var( $order[0]['dir'], FILTER_SANITIZE_STRING));
|
|
|
163 |
|
|
|
164 |
$fields = ['title', 'date'];
|
|
|
165 |
$order_field = isset($fields[$order_field]) ? $fields[$order_field] : 'title';
|
|
|
166 |
|
|
|
167 |
if(!in_array($order_direction, ['ASC', 'DESC'])) {
|
|
|
168 |
$order_direction = 'ASC';
|
|
|
169 |
}
|
|
|
170 |
|
|
|
171 |
$highPerformanceTeamsGroupsViewTopicMapper = HighPerformanceTeamsGroupsViewTopicMapper::getInstance($this->adapter);
|
|
|
172 |
$paginator = $highPerformanceTeamsGroupsViewTopicMapper->fetchAllByGroup($highPerformanceTeamsGroups->id);
|
|
|
173 |
|
|
|
174 |
$items = [];
|
7554 |
nelberth |
175 |
|
7760 |
nelberth |
176 |
|
|
|
177 |
|
|
|
178 |
foreach($paginator as $record)
|
|
|
179 |
{
|
|
|
180 |
|
|
|
181 |
|
|
|
182 |
$item = [
|
|
|
183 |
'title' => $record->title,
|
|
|
184 |
'status'=> $record->status,
|
|
|
185 |
'actions' => [
|
7859 |
nelberth |
186 |
'link_edit' => $allowEdit ? $this->url()->fromRoute('high-performance-teams/groups/view/topic/edit', ['group_uuid' => $highPerformanceTeamsGroups->uuid, 'topic_uuid' => $record->uuid]) : '',
|
|
|
187 |
'link_delete' => $allowDelete ? $this->url()->fromRoute('high-performance-teams/groups/view/topic/delete', ['group_uuid' => $highPerformanceTeamsGroups->uuid,'topic_uuid' => $record->uuid]) : '',
|
|
|
188 |
'link_view' => $allowView ? $this->url()->fromRoute('high-performance-teams/groups/view/topic/view', ['group_uuid' => $highPerformanceTeamsGroups->uuid,'topic_uuid' => $record->uuid]) : '',
|
7760 |
nelberth |
189 |
]
|
|
|
190 |
|
|
|
191 |
];
|
7489 |
nelberth |
192 |
|
7760 |
nelberth |
193 |
array_push($items, $item);
|
7489 |
nelberth |
194 |
|
|
|
195 |
}
|
7760 |
nelberth |
196 |
|
|
|
197 |
return new JsonModel([
|
|
|
198 |
'success' => true,
|
|
|
199 |
'data' => [
|
|
|
200 |
'items' => $items
|
|
|
201 |
]
|
|
|
202 |
]);
|
7489 |
nelberth |
203 |
|
7500 |
nelberth |
204 |
}
|
7489 |
nelberth |
205 |
} else {
|
|
|
206 |
return new JsonModel([
|
|
|
207 |
'success' => false,
|
|
|
208 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
209 |
]);
|
|
|
210 |
}
|
|
|
211 |
}
|
|
|
212 |
|
|
|
213 |
public function addAction()
|
|
|
214 |
{
|
|
|
215 |
|
7857 |
nelberth |
216 |
$group_uuid = $this->params()->fromRoute('group_uuid');
|
|
|
217 |
if(!$group_uuid) {
|
|
|
218 |
$data = [
|
|
|
219 |
'success' => false,
|
|
|
220 |
'data' => 'ERROR_INVALID_PARAMETER'
|
|
|
221 |
];
|
|
|
222 |
|
|
|
223 |
return new JsonModel($data);
|
|
|
224 |
}
|
7717 |
nelberth |
225 |
|
7514 |
nelberth |
226 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
227 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
228 |
$currentCompany = $currentUserPlugin->getCompany();
|
7499 |
nelberth |
229 |
|
7489 |
nelberth |
230 |
$request = $this->getRequest();
|
|
|
231 |
if($request->isPost()) {
|
|
|
232 |
$form = new HighPerformanceTeamsGroupsViewTopicForm($this->adapter);
|
|
|
233 |
$dataPost = $request->getPost()->toArray();
|
|
|
234 |
|
|
|
235 |
$form->setData($dataPost);
|
|
|
236 |
|
|
|
237 |
if($form->isValid()) {
|
|
|
238 |
$dataPost = (array) $form->getData();
|
|
|
239 |
$dataPost['status'] = isset($dataPost['status']) ? $dataPost['status'] : HighPerformanceTeamsGroupsViewTopic::STATUS_INACTIVE;
|
7514 |
nelberth |
240 |
|
7489 |
nelberth |
241 |
|
7514 |
nelberth |
242 |
$highPerformanceTeamsGroupsMapper = HighPerformanceTeamsGroupsMapper::getInstance($this->adapter);
|
7857 |
nelberth |
243 |
$highPerformanceTeamsGroups = $highPerformanceTeamsGroupsMapper->fetchOneByUuid($group_uuid);
|
7514 |
nelberth |
244 |
|
7763 |
nelberth |
245 |
if (!$highPerformanceTeamsGroups) {
|
7514 |
nelberth |
246 |
$data = [
|
|
|
247 |
'success' => false,
|
|
|
248 |
'data' => 'ERROR_RECORD_NOT_FOUND'
|
|
|
249 |
];
|
|
|
250 |
|
|
|
251 |
return new JsonModel($data);
|
|
|
252 |
}
|
|
|
253 |
|
7763 |
nelberth |
254 |
$highPerformanceTeamsGroupsMemberMapper = HighPerformanceTeamsGroupsMembersMapper::getInstance($this->adapter);
|
|
|
255 |
$highPerformanceTeamsGroupsMember = $highPerformanceTeamsGroupsMemberMapper->fetchOneByGroupIdAndUserId($highPerformanceTeamsGroups->id, $currentUser->id);
|
|
|
256 |
if(!$highPerformanceTeamsGroupsMember) {
|
7514 |
nelberth |
257 |
return new JsonModel([
|
|
|
258 |
'success' => false,
|
7763 |
nelberth |
259 |
'data' => 'ERROR_RECORD_NOT_FOUND'
|
7514 |
nelberth |
260 |
]);
|
7763 |
nelberth |
261 |
}
|
|
|
262 |
if(!($highPerformanceTeamsGroupsMember->status == HighPerformanceTeamsGroupsMembers::STATUS_ACCEPTED || $highPerformanceTeamsGroupsMember->status == HighPerformanceTeamsGroupsMembers::STATUS_ADDED_BY_ADMIN) ){
|
|
|
263 |
return new JsonModel([
|
|
|
264 |
'success' => false,
|
|
|
265 |
'data' => 'ERROR_YOU_DO_NOT_HAVE_ACCESS'
|
|
|
266 |
]);
|
|
|
267 |
}
|
7514 |
nelberth |
268 |
|
7515 |
nelberth |
269 |
|
7489 |
nelberth |
270 |
$hydrator = new ObjectPropertyHydrator();
|
|
|
271 |
$highPerformanceTeamsGroupsViewTopic = new HighPerformanceTeamsGroupsViewTopic();
|
|
|
272 |
$hydrator->hydrate($dataPost, $highPerformanceTeamsGroupsViewTopic);
|
7857 |
nelberth |
273 |
$highPerformanceTeamsGroupsViewTopic->group_id=$highPerformanceTeamsGroups->id;
|
7489 |
nelberth |
274 |
$highPerformanceTeamsGroupsViewTopicMapper = HighPerformanceTeamsGroupsViewTopicMapper::getInstance($this->adapter);
|
|
|
275 |
$result = $highPerformanceTeamsGroupsViewTopicMapper->insert($highPerformanceTeamsGroupsViewTopic);
|
|
|
276 |
|
|
|
277 |
if($result) {
|
|
|
278 |
|
7512 |
nelberth |
279 |
$this->logger->info('Se agrego el topic del grupo ' . $highPerformanceTeamsGroupsViewTopic->title, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
|
7489 |
nelberth |
280 |
|
|
|
281 |
$data = [
|
|
|
282 |
'success' => true,
|
|
|
283 |
'data' => 'LABEL_RECORD_ADDED'
|
|
|
284 |
];
|
|
|
285 |
} else {
|
|
|
286 |
$data = [
|
|
|
287 |
'success' => false,
|
7703 |
nelberth |
288 |
'data' => $highPerformanceTeamsGroupsViewTopicMapper->getError()
|
7489 |
nelberth |
289 |
];
|
|
|
290 |
|
|
|
291 |
}
|
|
|
292 |
|
|
|
293 |
return new JsonModel($data);
|
|
|
294 |
|
|
|
295 |
} else {
|
|
|
296 |
$messages = [];
|
|
|
297 |
$form_messages = (array) $form->getMessages();
|
|
|
298 |
foreach($form_messages as $fieldname => $field_messages)
|
|
|
299 |
{
|
|
|
300 |
|
|
|
301 |
$messages[$fieldname] = array_values($field_messages);
|
|
|
302 |
}
|
|
|
303 |
|
|
|
304 |
return new JsonModel([
|
|
|
305 |
'success' => false,
|
|
|
306 |
'data' => $messages
|
|
|
307 |
]);
|
|
|
308 |
}
|
|
|
309 |
|
|
|
310 |
} else {
|
|
|
311 |
$data = [
|
|
|
312 |
'success' => false,
|
7704 |
nelberth |
313 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
7489 |
nelberth |
314 |
];
|
|
|
315 |
|
|
|
316 |
return new JsonModel($data);
|
|
|
317 |
}
|
|
|
318 |
|
|
|
319 |
return new JsonModel($data);
|
|
|
320 |
|
|
|
321 |
|
|
|
322 |
}
|
|
|
323 |
|
|
|
324 |
|
|
|
325 |
|
|
|
326 |
public function editAction(){
|
|
|
327 |
|
|
|
328 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
329 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
330 |
$currentCompany = $currentUserPlugin->getCompany();
|
|
|
331 |
$request = $this->getRequest();
|
7847 |
nelberth |
332 |
$group_uuid = $this->params()->fromRoute('group_uuid');
|
7743 |
nelberth |
333 |
|
7834 |
nelberth |
334 |
$topic_uuid = $this->params()->fromRoute('topic_uuid');
|
7489 |
nelberth |
335 |
|
|
|
336 |
|
7847 |
nelberth |
337 |
if(!$group_uuid) {
|
7489 |
nelberth |
338 |
$data = [
|
|
|
339 |
'success' => false,
|
|
|
340 |
'data' => 'ERROR_INVALID_PARAMETER'
|
|
|
341 |
];
|
|
|
342 |
|
|
|
343 |
return new JsonModel($data);
|
|
|
344 |
}
|
7743 |
nelberth |
345 |
if(!$topic_uuid) {
|
|
|
346 |
$data = [
|
|
|
347 |
'success' => false,
|
|
|
348 |
'data' => 'ERROR_INVALID_PARAMETER'
|
|
|
349 |
];
|
|
|
350 |
|
|
|
351 |
return new JsonModel($data);
|
|
|
352 |
}
|
7750 |
nelberth |
353 |
|
7489 |
nelberth |
354 |
|
|
|
355 |
$highPerformanceTeamsGroupsViewTopicMapper = HighPerformanceTeamsGroupsViewTopicMapper::getInstance($this->adapter);
|
7743 |
nelberth |
356 |
$topic = $highPerformanceTeamsGroupsViewTopicMapper->fetchOneByUuid($topic_uuid);
|
7489 |
nelberth |
357 |
|
7743 |
nelberth |
358 |
if (!$topic) {
|
7489 |
nelberth |
359 |
$data = [
|
|
|
360 |
'success' => false,
|
|
|
361 |
'data' => 'ERROR_RECORD_NOT_FOUND'
|
|
|
362 |
];
|
|
|
363 |
|
|
|
364 |
return new JsonModel($data);
|
|
|
365 |
}
|
|
|
366 |
|
|
|
367 |
|
7743 |
nelberth |
368 |
|
7489 |
nelberth |
369 |
if($request->isPost()) {
|
|
|
370 |
$form = new HighPerformanceTeamsGroupsViewTopicForm($this->adapter);
|
|
|
371 |
$dataPost = $request->getPost()->toArray();
|
|
|
372 |
$dataPost['status'] = isset($dataPost['status']) ? $dataPost['status'] : HighPerformanceTeamsGroupsViewTopic::STATUS_INACTIVE;
|
7756 |
nelberth |
373 |
|
7752 |
nelberth |
374 |
|
7755 |
nelberth |
375 |
|
7756 |
nelberth |
376 |
|
7489 |
nelberth |
377 |
$form->setData($dataPost);
|
|
|
378 |
|
|
|
379 |
if($form->isValid()) {
|
7757 |
nelberth |
380 |
$dataPost = (array) $form->getData();
|
7756 |
nelberth |
381 |
$highPerformanceTeamsGroupsMapper = HighPerformanceTeamsGroupsMapper::getInstance($this->adapter);
|
7860 |
nelberth |
382 |
$highPerformanceTeamsGroups = $highPerformanceTeamsGroupsMapper->fetchOneByUuid($group_uuid);
|
7756 |
nelberth |
383 |
|
7763 |
nelberth |
384 |
if (!$highPerformanceTeamsGroups) {
|
7756 |
nelberth |
385 |
$data = [
|
|
|
386 |
'success' => false,
|
|
|
387 |
'data' => 'ERROR_RECORD_NOT_FOUND'
|
|
|
388 |
];
|
|
|
389 |
|
|
|
390 |
return new JsonModel($data);
|
|
|
391 |
}
|
7763 |
nelberth |
392 |
|
|
|
393 |
$highPerformanceTeamsGroupsMemberMapper = HighPerformanceTeamsGroupsMembersMapper::getInstance($this->adapter);
|
|
|
394 |
$highPerformanceTeamsGroupsMember = $highPerformanceTeamsGroupsMemberMapper->fetchOneByGroupIdAndUserId($highPerformanceTeamsGroups->id, $currentUser->id);
|
|
|
395 |
if(!$highPerformanceTeamsGroupsMember) {
|
|
|
396 |
return new JsonModel([
|
|
|
397 |
'success' => false,
|
|
|
398 |
'data' => 'ERROR_RECORD_NOT_FOUND'
|
|
|
399 |
]);
|
|
|
400 |
}
|
|
|
401 |
if(!($highPerformanceTeamsGroupsMember->status == HighPerformanceTeamsGroupsMembers::STATUS_ACCEPTED || $highPerformanceTeamsGroupsMember->status == HighPerformanceTeamsGroupsMembers::STATUS_ADDED_BY_ADMIN) ){
|
|
|
402 |
return new JsonModel([
|
|
|
403 |
'success' => false,
|
|
|
404 |
'data' => 'ERROR_YOU_DO_NOT_HAVE_ACCESS'
|
|
|
405 |
]);
|
|
|
406 |
}
|
7756 |
nelberth |
407 |
|
7489 |
nelberth |
408 |
$hydrator = new ObjectPropertyHydrator();
|
7748 |
nelberth |
409 |
$hydrator->hydrate($dataPost, $topic);
|
7860 |
nelberth |
410 |
$topic->group_id=$highPerformanceTeamsGroups->id;
|
|
|
411 |
|
7744 |
nelberth |
412 |
$result = $highPerformanceTeamsGroupsViewTopicMapper->update($topic);
|
7751 |
nelberth |
413 |
|
7489 |
nelberth |
414 |
if($result) {
|
7744 |
nelberth |
415 |
$this->logger->info('Se actualizo el grupo de alto rendimiento ' . $topic->title, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
|
7489 |
nelberth |
416 |
|
|
|
417 |
$data = [
|
|
|
418 |
'success' => true,
|
|
|
419 |
'data' => 'LABEL_RECORD_UPDATED'
|
|
|
420 |
];
|
|
|
421 |
} else {
|
|
|
422 |
$data = [
|
|
|
423 |
'success' => false,
|
|
|
424 |
'data' => $highPerformanceTeamsGroupsViewTopicMapper->getError()
|
|
|
425 |
];
|
|
|
426 |
}
|
|
|
427 |
|
|
|
428 |
return new JsonModel($data);
|
|
|
429 |
|
|
|
430 |
} else {
|
|
|
431 |
$messages = [];
|
|
|
432 |
$form_messages = (array) $form->getMessages();
|
|
|
433 |
foreach($form_messages as $fieldname => $field_messages)
|
|
|
434 |
{
|
|
|
435 |
$messages[$fieldname] = array_values($field_messages);
|
|
|
436 |
}
|
|
|
437 |
|
|
|
438 |
return new JsonModel([
|
|
|
439 |
'success' => false,
|
|
|
440 |
'data' => $messages
|
|
|
441 |
]);
|
|
|
442 |
}
|
|
|
443 |
}else if ($request->isGet()) {
|
|
|
444 |
$hydrator = new ObjectPropertyHydrator();
|
|
|
445 |
|
|
|
446 |
$data = [
|
|
|
447 |
'success' => true,
|
7743 |
nelberth |
448 |
'data' => $hydrator->extract($topic)
|
7489 |
nelberth |
449 |
];
|
|
|
450 |
|
|
|
451 |
return new JsonModel($data);
|
|
|
452 |
} else {
|
|
|
453 |
$data = [
|
|
|
454 |
'success' => false,
|
|
|
455 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
456 |
];
|
|
|
457 |
|
|
|
458 |
return new JsonModel($data);
|
|
|
459 |
}
|
|
|
460 |
|
|
|
461 |
return new JsonModel($data);
|
|
|
462 |
|
|
|
463 |
}
|
|
|
464 |
|
|
|
465 |
|
|
|
466 |
|
|
|
467 |
|
|
|
468 |
public function deleteAction(){
|
7737 |
nelberth |
469 |
|
7489 |
nelberth |
470 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
471 |
$currentCompany = $currentUserPlugin->getCompany();
|
|
|
472 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
473 |
|
|
|
474 |
$request = $this->getRequest();
|
7847 |
nelberth |
475 |
$group_uuid = $this->params()->fromRoute('group_uuid');
|
7834 |
nelberth |
476 |
$topic_uuid = $this->params()->fromRoute('topic_uuid');
|
7489 |
nelberth |
477 |
|
|
|
478 |
|
7847 |
nelberth |
479 |
if (!$group_uuid) {
|
7489 |
nelberth |
480 |
$data = [
|
|
|
481 |
'success' => false,
|
|
|
482 |
'data' => 'ERROR_INVALID_PARAMETER'
|
|
|
483 |
];
|
|
|
484 |
|
|
|
485 |
return new JsonModel($data);
|
|
|
486 |
}
|
7763 |
nelberth |
487 |
$highPerformanceTeamsGroupsMapper = HighPerformanceTeamsGroupsMapper::getInstance($this->adapter);
|
7847 |
nelberth |
488 |
$highPerformanceTeamsGroups = $highPerformanceTeamsGroupsMapper->fetchOneByUuid($group_uuid);
|
7763 |
nelberth |
489 |
|
|
|
490 |
if (!$highPerformanceTeamsGroups) {
|
|
|
491 |
$data = [
|
|
|
492 |
'success' => false,
|
|
|
493 |
'data' => 'ERROR_RECORD_NOT_FOUND'
|
|
|
494 |
];
|
|
|
495 |
|
|
|
496 |
return new JsonModel($data);
|
|
|
497 |
}
|
7489 |
nelberth |
498 |
|
7763 |
nelberth |
499 |
$highPerformanceTeamsGroupsMemberMapper = HighPerformanceTeamsGroupsMembersMapper::getInstance($this->adapter);
|
|
|
500 |
$highPerformanceTeamsGroupsMember = $highPerformanceTeamsGroupsMemberMapper->fetchOneByGroupIdAndUserId($highPerformanceTeamsGroups->id, $currentUser->id);
|
|
|
501 |
if(!$highPerformanceTeamsGroupsMember) {
|
|
|
502 |
return new JsonModel([
|
|
|
503 |
'success' => false,
|
|
|
504 |
'data' => 'ERROR_RECORD_NOT_FOUND'
|
|
|
505 |
]);
|
|
|
506 |
}
|
|
|
507 |
if(!($highPerformanceTeamsGroupsMember->status == HighPerformanceTeamsGroupsMembers::STATUS_ACCEPTED || $highPerformanceTeamsGroupsMember->status == HighPerformanceTeamsGroupsMembers::STATUS_ADDED_BY_ADMIN) ){
|
|
|
508 |
return new JsonModel([
|
|
|
509 |
'success' => false,
|
|
|
510 |
'data' => 'ERROR_YOU_DO_NOT_HAVE_ACCESS'
|
|
|
511 |
]);
|
|
|
512 |
}
|
7489 |
nelberth |
513 |
|
|
|
514 |
|
7738 |
nelberth |
515 |
$highPerformanceTeamsGroupsViewTopicMapper = HighPerformanceTeamsGroupsViewTopicMapper::getInstance($this->adapter);
|
7739 |
nelberth |
516 |
$topic = $highPerformanceTeamsGroupsViewTopicMapper->fetchOneByUuid($topic_uuid);
|
7489 |
nelberth |
517 |
|
7737 |
nelberth |
518 |
if (!$topic) {
|
7489 |
nelberth |
519 |
$data = [
|
|
|
520 |
'success' => false,
|
|
|
521 |
'data' => 'ERROR_RECORD_NOT_FOUND'
|
|
|
522 |
];
|
|
|
523 |
|
|
|
524 |
return new JsonModel($data);
|
|
|
525 |
}
|
|
|
526 |
|
7763 |
nelberth |
527 |
|
7489 |
nelberth |
528 |
|
|
|
529 |
if ($request->isPost()) {
|
|
|
530 |
|
|
|
531 |
|
7737 |
nelberth |
532 |
$result = $highPerformanceTeamsGroupsViewTopicMapper->delete($topic->id);
|
7489 |
nelberth |
533 |
if ($result) {
|
7737 |
nelberth |
534 |
$this->logger->info('Se borro el grupo de alto rendimiento ' . $topic->title, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
|
7489 |
nelberth |
535 |
|
|
|
536 |
$data = [
|
|
|
537 |
'success' => true,
|
|
|
538 |
'data' => 'LABEL_RECORD_DELETED'
|
|
|
539 |
];
|
|
|
540 |
} else {
|
|
|
541 |
|
|
|
542 |
$data = [
|
|
|
543 |
'success' => false,
|
|
|
544 |
'data' => $highPerformanceTeamsGroupsViewTopicMapper->getError()
|
|
|
545 |
];
|
|
|
546 |
|
|
|
547 |
return new JsonModel($data);
|
|
|
548 |
}
|
|
|
549 |
} else {
|
|
|
550 |
$data = [
|
|
|
551 |
'success' => false,
|
|
|
552 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
553 |
];
|
|
|
554 |
|
|
|
555 |
return new JsonModel($data);
|
|
|
556 |
}
|
|
|
557 |
|
|
|
558 |
return new JsonModel($data);
|
|
|
559 |
}
|
|
|
560 |
|
|
|
561 |
|
|
|
562 |
|
|
|
563 |
|
|
|
564 |
}
|