| 7231 |
nelberth |
1 |
<?php
|
|
|
2 |
declare(strict_types=1);
|
|
|
3 |
|
|
|
4 |
namespace LeadersLinked\Controller;
|
|
|
5 |
|
| 16768 |
efrain |
6 |
|
| 7231 |
nelberth |
7 |
use Laminas\Db\Adapter\AdapterInterface;
|
|
|
8 |
use Laminas\Mvc\Controller\AbstractActionController;
|
|
|
9 |
use Laminas\Log\LoggerInterface;
|
|
|
10 |
use Laminas\View\Model\ViewModel;
|
|
|
11 |
use Laminas\View\Model\JsonModel;
|
| 7233 |
nelberth |
12 |
use LeadersLinked\Model\HighPerformanceTeamsGroups;
|
|
|
13 |
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
|
|
|
14 |
use LeadersLinked\Form\HighPerformanceTeamsGroupsForm;
|
| 7231 |
nelberth |
15 |
use LeadersLinked\Library\Functions;
|
| 7233 |
nelberth |
16 |
use LeadersLinked\Mapper\UserMapper;
|
|
|
17 |
use LeadersLinked\Mapper\HighPerformanceTeamsGroupsMapper;
|
| 7276 |
nelberth |
18 |
use LeadersLinked\Mapper\CompanyUserMapper;
|
| 11620 |
nelberth |
19 |
use LeadersLinked\Model\ChatGroupUser;
|
|
|
20 |
use LeadersLinked\Model\ChatGroup;
|
| 7305 |
nelberth |
21 |
use LeadersLinked\Model\HighPerformanceTeamsGroupsMembers;
|
| 11620 |
nelberth |
22 |
use LeadersLinked\Mapper\ChatGroupMapper;
|
| 7305 |
nelberth |
23 |
use LeadersLinked\Mapper\HighPerformanceTeamsGroupsMembersMapper;
|
| 11620 |
nelberth |
24 |
use LeadersLinked\Mapper\ChatGroupUserMapper;
|
| 11664 |
nelberth |
25 |
|
|
|
26 |
use LeadersLinked\Mapper\ChatGroupUserMessageMapper;
|
|
|
27 |
use LeadersLinked\Mapper\ChatGroupMessageMapper;
|
| 16768 |
efrain |
28 |
|
| 7231 |
nelberth |
29 |
class HighPerformanceTeamsGroupsController extends AbstractActionController
|
|
|
30 |
{
|
|
|
31 |
/**
|
|
|
32 |
*
|
|
|
33 |
* @var AdapterInterface
|
|
|
34 |
*/
|
|
|
35 |
private $adapter;
|
|
|
36 |
|
|
|
37 |
/**
|
|
|
38 |
*
|
|
|
39 |
* @var LoggerInterface
|
|
|
40 |
*/
|
|
|
41 |
private $logger;
|
|
|
42 |
|
|
|
43 |
/**
|
|
|
44 |
*
|
|
|
45 |
* @var array
|
|
|
46 |
*/
|
|
|
47 |
private $config;
|
|
|
48 |
|
|
|
49 |
/**
|
|
|
50 |
*
|
|
|
51 |
* @param AdapterInterface $adapter
|
|
|
52 |
* @param LoggerInterface $logger
|
|
|
53 |
* @param array $config
|
|
|
54 |
*/
|
| 16768 |
efrain |
55 |
public function __construct($adapter, $logger, $config)
|
| 7231 |
nelberth |
56 |
{
|
| 16768 |
efrain |
57 |
$this->adapter = $adapter;
|
|
|
58 |
$this->logger = $logger;
|
|
|
59 |
$this->config = $config;
|
| 7231 |
nelberth |
60 |
}
|
|
|
61 |
|
| 7233 |
nelberth |
62 |
|
|
|
63 |
|
|
|
64 |
|
| 7231 |
nelberth |
65 |
public function indexAction()
|
|
|
66 |
{
|
| 7233 |
nelberth |
67 |
|
|
|
68 |
|
| 7231 |
nelberth |
69 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
70 |
$currentUser = $currentUserPlugin->getUser();
|
| 7233 |
nelberth |
71 |
$currentCompany = $currentUserPlugin->getCompany();
|
| 7231 |
nelberth |
72 |
|
| 7233 |
nelberth |
73 |
|
| 7231 |
nelberth |
74 |
$request = $this->getRequest();
|
|
|
75 |
if($request->isGet()) {
|
|
|
76 |
|
|
|
77 |
|
|
|
78 |
$headers = $request->getHeaders();
|
|
|
79 |
|
|
|
80 |
$isJson = false;
|
|
|
81 |
if($headers->has('Accept')) {
|
|
|
82 |
$accept = $headers->get('Accept');
|
|
|
83 |
|
|
|
84 |
$prioritized = $accept->getPrioritized();
|
|
|
85 |
|
|
|
86 |
foreach($prioritized as $key => $value) {
|
|
|
87 |
$raw = trim($value->getRaw());
|
|
|
88 |
|
|
|
89 |
if(!$isJson) {
|
|
|
90 |
$isJson = strpos($raw, 'json');
|
|
|
91 |
}
|
|
|
92 |
|
|
|
93 |
}
|
|
|
94 |
}
|
|
|
95 |
|
|
|
96 |
if($isJson) {
|
|
|
97 |
|
| 7233 |
nelberth |
98 |
|
| 7231 |
nelberth |
99 |
$acl = $this->getEvent()->getViewModel()->getVariable('acl');
|
| 7233 |
nelberth |
100 |
$allowEdit = $acl->isAllowed($currentUser->usertype_id, 'high-performance-teams/groups/edit');
|
|
|
101 |
$allowDelete = $acl->isAllowed($currentUser->usertype_id,'high-performance-teams/groups/delete');
|
| 7249 |
nelberth |
102 |
$allowView = $acl->isAllowed($currentUser->usertype_id,'high-performance-teams/groups/view');
|
| 7251 |
nelberth |
103 |
|
| 7233 |
nelberth |
104 |
|
|
|
105 |
$search = $this->params()->fromQuery('search', []);
|
| 16766 |
efrain |
106 |
$search = empty($search['value']) ? '' : Functions::sanitizeFilterString($search['value']);
|
| 7231 |
nelberth |
107 |
|
|
|
108 |
|
| 7233 |
nelberth |
109 |
$records_x_page = intval($this->params()->fromQuery('length', 10), 10);
|
|
|
110 |
$page = (intval($this->params()->fromQuery('start', 1), 10)/$records_x_page)+1;
|
|
|
111 |
$order = $this->params()->fromQuery('order', []);
|
|
|
112 |
$order_field = empty($order[0]['column']) ? 99 : intval($order[0]['column'], 10);
|
| 16766 |
efrain |
113 |
$order_direction = empty($order[0]['dir']) ? 'ASC' : strtoupper(Functions::sanitizeFilterString($order[0]['dir']));
|
| 7233 |
nelberth |
114 |
|
|
|
115 |
$fields = ['title', 'date'];
|
|
|
116 |
$order_field = isset($fields[$order_field]) ? $fields[$order_field] : 'title';
|
|
|
117 |
|
|
|
118 |
if(!in_array($order_direction, ['ASC', 'DESC'])) {
|
|
|
119 |
$order_direction = 'ASC';
|
| 7231 |
nelberth |
120 |
}
|
|
|
121 |
|
| 7243 |
nelberth |
122 |
$highPerformanceTeamsGroupsMapper = HighPerformanceTeamsGroupsMapper::getInstance($this->adapter);
|
| 11206 |
nelberth |
123 |
|
| 11205 |
nelberth |
124 |
$paginator = $highPerformanceTeamsGroupsMapper->fetchAllDataTableInnerJoinMember($search, $page, $records_x_page, $order_field, $order_direction, $currentUser->id);
|
| 11208 |
nelberth |
125 |
|
| 7231 |
nelberth |
126 |
$items = [];
|
| 7233 |
nelberth |
127 |
|
|
|
128 |
$records = $paginator->getCurrentItems();
|
| 11203 |
nelberth |
129 |
|
| 7233 |
nelberth |
130 |
|
| 11204 |
nelberth |
131 |
|
| 11196 |
nelberth |
132 |
$highPerformanceTeamsGroupsMembersMapper = HighPerformanceTeamsGroupsMembersMapper::getInstance($this->adapter);
|
| 7231 |
nelberth |
133 |
foreach($records as $record)
|
|
|
134 |
{
|
|
|
135 |
|
| 11196 |
nelberth |
136 |
$highPerformanceTeamsGroupsMember = $highPerformanceTeamsGroupsMembersMapper->fetchOneByGroupIdAndUserId($record->id, $currentUser->id);
|
|
|
137 |
if($highPerformanceTeamsGroupsMember) {
|
|
|
138 |
if(($highPerformanceTeamsGroupsMember->status == HighPerformanceTeamsGroupsMembers::STATUS_ACCEPTED || $highPerformanceTeamsGroupsMember->status == HighPerformanceTeamsGroupsMembers::STATUS_ADDED_BY_ADMIN) ){
|
| 11200 |
nelberth |
139 |
$contentAllowDelete=$allowDelete;
|
| 11198 |
nelberth |
140 |
$contentAllowEdit=$allowEdit;
|
| 11201 |
nelberth |
141 |
if($highPerformanceTeamsGroupsMember->type==HighPerformanceTeamsGroupsMembers::TYPE_MODERATOR||$highPerformanceTeamsGroupsMember->type==HighPerformanceTeamsGroupsMembers::TYPE_USER){
|
| 11196 |
nelberth |
142 |
$allowDelete=false;
|
|
|
143 |
$allowEdit=false;
|
|
|
144 |
}
|
| 11201 |
nelberth |
145 |
if($highPerformanceTeamsGroupsMember->type==HighPerformanceTeamsGroupsMembers::TYPE_ADMINISTRATOR){
|
| 11196 |
nelberth |
146 |
$allowDelete=false;
|
|
|
147 |
}
|
| 11201 |
nelberth |
148 |
|
| 11196 |
nelberth |
149 |
$item = [
|
|
|
150 |
'title' => $record->title,
|
|
|
151 |
'description' => $record->description,
|
|
|
152 |
'status'=> $record->status,
|
|
|
153 |
'actions' => [
|
|
|
154 |
'link_edit' => $allowEdit ? $this->url()->fromRoute('high-performance-teams/groups/edit', ['group_id' => $record->uuid]) : '',
|
|
|
155 |
'link_delete' => $allowDelete ? $this->url()->fromRoute('high-performance-teams/groups/delete', ['group_id' => $record->uuid]) : '',
|
|
|
156 |
'link_view' => $allowView ? $this->url()->fromRoute('high-performance-teams/groups/view', ['group_id' => $record->uuid]) : '',
|
|
|
157 |
]
|
|
|
158 |
|
|
|
159 |
];
|
|
|
160 |
|
|
|
161 |
array_push($items, $item);
|
| 11201 |
nelberth |
162 |
|
| 11196 |
nelberth |
163 |
$allowDelete=$contentAllowDelete;
|
|
|
164 |
$allowEdit=$contentAllowEdit;
|
| 11201 |
nelberth |
165 |
|
| 11196 |
nelberth |
166 |
}
|
|
|
167 |
}
|
| 7233 |
nelberth |
168 |
|
| 7231 |
nelberth |
169 |
}
|
| 7233 |
nelberth |
170 |
|
|
|
171 |
return new JsonModel([
|
| 7231 |
nelberth |
172 |
'success' => true,
|
| 7233 |
nelberth |
173 |
'data' => [
|
|
|
174 |
'items' => $items,
|
|
|
175 |
'total' => $paginator->getTotalItemCount(),
|
|
|
176 |
]
|
|
|
177 |
]);
|
| 7231 |
nelberth |
178 |
|
| 7233 |
nelberth |
179 |
} else {
|
| 7271 |
nelberth |
180 |
$formAdd = new HighPerformanceTeamsGroupsForm($this->adapter, $currentCompany->id);
|
| 7231 |
nelberth |
181 |
$this->layout()->setTemplate('layout/layout-backend');
|
|
|
182 |
$viewModel = new ViewModel();
|
| 7233 |
nelberth |
183 |
$viewModel->setTemplate('leaders-linked/high-performance-teams-groups/index.phtml');
|
| 7231 |
nelberth |
184 |
$viewModel->setVariables([
|
| 7233 |
nelberth |
185 |
'formAdd' => $formAdd,
|
| 7231 |
nelberth |
186 |
]);
|
|
|
187 |
return $viewModel ;
|
|
|
188 |
}
|
|
|
189 |
} else {
|
|
|
190 |
return new JsonModel([
|
|
|
191 |
'success' => false,
|
|
|
192 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
193 |
]);
|
|
|
194 |
}
|
|
|
195 |
}
|
| 7244 |
nelberth |
196 |
|
| 7231 |
nelberth |
197 |
public function addAction()
|
|
|
198 |
{
|
| 7233 |
nelberth |
199 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
200 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
201 |
$currentCompany = $currentUserPlugin->getCompany();
|
|
|
202 |
|
| 7231 |
nelberth |
203 |
$request = $this->getRequest();
|
|
|
204 |
if($request->isPost()) {
|
| 7271 |
nelberth |
205 |
$form = new HighPerformanceTeamsGroupsForm($this->adapter, $currentCompany->id);
|
| 7231 |
nelberth |
206 |
$dataPost = $request->getPost()->toArray();
|
|
|
207 |
|
|
|
208 |
$form->setData($dataPost);
|
|
|
209 |
|
|
|
210 |
if($form->isValid()) {
|
|
|
211 |
$dataPost = (array) $form->getData();
|
| 7233 |
nelberth |
212 |
$dataPost['status'] = isset($dataPost['status']) ? $dataPost['status'] : HighPerformanceTeamsGroups::STATUS_INACTIVE;
|
|
|
213 |
$dataPost['company_id']=$currentCompany->id;
|
| 7231 |
nelberth |
214 |
|
| 7233 |
nelberth |
215 |
$hydrator = new ObjectPropertyHydrator();
|
|
|
216 |
$highPerformanceTeamsGroups = new HighPerformanceTeamsGroups();
|
|
|
217 |
$hydrator->hydrate($dataPost, $highPerformanceTeamsGroups);
|
| 7231 |
nelberth |
218 |
|
| 7233 |
nelberth |
219 |
$highPerformanceTeamsGroupsMapper = HighPerformanceTeamsGroupsMapper::getInstance($this->adapter);
|
| 7248 |
nelberth |
220 |
|
| 7233 |
nelberth |
221 |
$result = $highPerformanceTeamsGroupsMapper->insert($highPerformanceTeamsGroups);
|
| 7231 |
nelberth |
222 |
|
|
|
223 |
if($result) {
|
| 7304 |
nelberth |
224 |
|
| 7296 |
nelberth |
225 |
$highPerformanceTeamsGroupsMember = new HighPerformanceTeamsGroupsMembers();
|
|
|
226 |
$highPerformanceTeamsGroupsMember->group_id = $highPerformanceTeamsGroups->id;
|
| 7306 |
nelberth |
227 |
|
| 7296 |
nelberth |
228 |
$highPerformanceTeamsGroupsMember->user_id = $currentUser->id;
|
|
|
229 |
$highPerformanceTeamsGroupsMember->status = HighPerformanceTeamsGroupsMembers::STATUS_ADDED_BY_ADMIN;
|
|
|
230 |
$highPerformanceTeamsGroupsMember->type = HighPerformanceTeamsGroupsMembers::TYPE_CREATOR;
|
|
|
231 |
$highPerformanceTeamsGroupsMemberMapper = HighPerformanceTeamsGroupsMembersMapper::getInstance($this->adapter);
|
| 7305 |
nelberth |
232 |
|
| 7296 |
nelberth |
233 |
$highPerformanceTeamsGroupsMemberMapper->insert($highPerformanceTeamsGroupsMember);
|
| 11620 |
nelberth |
234 |
|
|
|
235 |
$chatGroup = new ChatGroup();
|
|
|
236 |
$chatGroup->name = $highPerformanceTeamsGroups->title;
|
| 12666 |
nelberth |
237 |
$chatGroup->high_performance_team_group_id =$highPerformanceTeamsGroups->id;
|
| 11620 |
nelberth |
238 |
$chatGroupMapper = ChatGroupMapper::getInstance($this->adapter);
|
|
|
239 |
$result = $chatGroupMapper->insert($chatGroup);
|
|
|
240 |
if ($result) {
|
|
|
241 |
$chatGroup = $chatGroupMapper->fetchOne($chatGroup->id);
|
|
|
242 |
$chatGroupUser = new ChatGroupUser();
|
|
|
243 |
$chatGroupUser->group_id = $chatGroup->id;
|
|
|
244 |
$chatGroupUser->user_id = $currentUser->id;
|
|
|
245 |
$chatGroupUser->owner = ChatGroupUser::OWNER_YES;
|
|
|
246 |
$chatGroupUserMapper = ChatGroupUserMapper::getInstance($this->adapter);
|
|
|
247 |
$result = $chatGroupUserMapper->insert($chatGroupUser);
|
|
|
248 |
|
|
|
249 |
if($result) {
|
|
|
250 |
$fullpath_chat = $this->config['leaderslinked.fullpath.chat'];
|
|
|
251 |
$dirpath = $fullpath_chat . $chatGroup->uuid;
|
|
|
252 |
if (! file_exists($dirpath)) {
|
|
|
253 |
mkdir($dirpath, 0777, true);
|
|
|
254 |
chmod($dirpath, 0777);
|
|
|
255 |
}
|
|
|
256 |
|
|
|
257 |
|
|
|
258 |
} else {
|
|
|
259 |
$response = [
|
|
|
260 |
'success' => false,
|
|
|
261 |
'data' => $chatGroupUserMapper->getError(),
|
|
|
262 |
];
|
|
|
263 |
return new JsonModel($response);
|
|
|
264 |
}
|
|
|
265 |
|
|
|
266 |
} else {
|
|
|
267 |
$response = [
|
|
|
268 |
'success' => false,
|
|
|
269 |
'data' => $chatGroupMapper->getError(),
|
|
|
270 |
];
|
|
|
271 |
return new JsonModel($response);
|
|
|
272 |
}
|
|
|
273 |
|
|
|
274 |
|
|
|
275 |
|
|
|
276 |
|
| 7296 |
nelberth |
277 |
|
| 7287 |
nelberth |
278 |
|
| 7244 |
nelberth |
279 |
$this->logger->info('Se agrego el grupo de alto rendimiento ' . $highPerformanceTeamsGroups->title, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
|
| 7231 |
nelberth |
280 |
|
|
|
281 |
$data = [
|
|
|
282 |
'success' => true,
|
|
|
283 |
'data' => 'LABEL_RECORD_ADDED'
|
|
|
284 |
];
|
|
|
285 |
} else {
|
|
|
286 |
$data = [
|
|
|
287 |
'success' => false,
|
| 7246 |
nelberth |
288 |
'data' => $highPerformanceTeamsGroupsMapper->getError()
|
| 7231 |
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 |
}
|
| 7233 |
nelberth |
309 |
|
| 7275 |
nelberth |
310 |
}else if ($request->isGet()) {
|
|
|
311 |
$companyUserMapper = CompanyUserMapper::getInstance($this->adapter);
|
|
|
312 |
$userMapper = UserMapper::getInstance($this->adapter);
|
|
|
313 |
$datosCompanyUser = $companyUserMapper->fetchAllByCompanyId($currentCompany->id);
|
|
|
314 |
|
|
|
315 |
$users=[];
|
|
|
316 |
|
|
|
317 |
foreach($datosCompanyUser as $record){
|
|
|
318 |
$datosUser = $userMapper->fetchOne($record->user_id);
|
|
|
319 |
|
|
|
320 |
$user=[
|
|
|
321 |
'uuid'=>$datosUser->uuid,
|
|
|
322 |
'email'=>$datosUser->email,
|
|
|
323 |
'first_name'=>$datosUser->first_name,
|
|
|
324 |
'last_name'=>$datosUser->last_name,
|
|
|
325 |
|
|
|
326 |
];
|
|
|
327 |
array_push($users, $user);
|
|
|
328 |
|
|
|
329 |
}
|
|
|
330 |
|
|
|
331 |
return new JsonModel([
|
|
|
332 |
'success' => true,
|
|
|
333 |
'data' => $users
|
|
|
334 |
|
|
|
335 |
]);
|
| 7231 |
nelberth |
336 |
} else {
|
|
|
337 |
$data = [
|
|
|
338 |
'success' => false,
|
|
|
339 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
340 |
];
|
|
|
341 |
|
|
|
342 |
return new JsonModel($data);
|
|
|
343 |
}
|
|
|
344 |
|
|
|
345 |
return new JsonModel($data);
|
| 7233 |
nelberth |
346 |
|
|
|
347 |
|
| 7231 |
nelberth |
348 |
}
|
| 7233 |
nelberth |
349 |
|
|
|
350 |
|
| 7259 |
nelberth |
351 |
|
| 7233 |
nelberth |
352 |
public function editAction(){
|
|
|
353 |
|
|
|
354 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
355 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
356 |
$currentCompany = $currentUserPlugin->getCompany();
|
| 7231 |
nelberth |
357 |
$request = $this->getRequest();
|
| 11082 |
nelberth |
358 |
$uuid = $this->params()->fromRoute('group_id');
|
| 7233 |
nelberth |
359 |
|
| 7231 |
nelberth |
360 |
|
| 7233 |
nelberth |
361 |
if(!$uuid) {
|
| 7231 |
nelberth |
362 |
$data = [
|
|
|
363 |
'success' => false,
|
|
|
364 |
'data' => 'ERROR_INVALID_PARAMETER'
|
|
|
365 |
];
|
|
|
366 |
|
|
|
367 |
return new JsonModel($data);
|
|
|
368 |
}
|
|
|
369 |
|
| 7233 |
nelberth |
370 |
$highPerformanceTeamsGroupsMapper = HighPerformanceTeamsGroupsMapper::getInstance($this->adapter);
|
| 11210 |
nelberth |
371 |
$highPerformanceTeamsGroups = $highPerformanceTeamsGroupsMapper->fetchOneByUuid($uuid);
|
| 7233 |
nelberth |
372 |
|
| 11210 |
nelberth |
373 |
if (!$highPerformanceTeamsGroups) {
|
| 7231 |
nelberth |
374 |
$data = [
|
|
|
375 |
'success' => false,
|
| 7233 |
nelberth |
376 |
'data' => 'ERROR_RECORD_NOT_FOUND'
|
| 7231 |
nelberth |
377 |
];
|
|
|
378 |
|
|
|
379 |
return new JsonModel($data);
|
|
|
380 |
}
|
| 11212 |
nelberth |
381 |
|
| 11210 |
nelberth |
382 |
$highPerformanceTeamsGroupsMembersMapper = HighPerformanceTeamsGroupsMembersMapper::getInstance($this->adapter);
|
|
|
383 |
$highPerformanceTeamsGroupsMember = $highPerformanceTeamsGroupsMembersMapper->fetchOneByGroupIdAndUserId($highPerformanceTeamsGroups->id, $currentUser->id);
|
|
|
384 |
if(!$highPerformanceTeamsGroupsMember) {
|
| 7233 |
nelberth |
385 |
return new JsonModel([
|
| 7231 |
nelberth |
386 |
'success' => false,
|
| 11210 |
nelberth |
387 |
'data' => 'ERROR_RECORD_NOT_FOUND'
|
| 7233 |
nelberth |
388 |
]);
|
| 11210 |
nelberth |
389 |
}
|
| 11213 |
nelberth |
390 |
|
| 11210 |
nelberth |
391 |
if(!($highPerformanceTeamsGroupsMember->status == HighPerformanceTeamsGroupsMembers::STATUS_ACCEPTED || $highPerformanceTeamsGroupsMember->status == HighPerformanceTeamsGroupsMembers::STATUS_ADDED_BY_ADMIN) ){
|
|
|
392 |
return new JsonModel([
|
|
|
393 |
'success' => false,
|
|
|
394 |
'data' => 'ERROR_YOU_DO_NOT_HAVE_ACCESS'
|
|
|
395 |
]);
|
|
|
396 |
}
|
| 7233 |
nelberth |
397 |
|
| 11210 |
nelberth |
398 |
if($highPerformanceTeamsGroupsMember->type==HighPerformanceTeamsGroupsMembers::TYPE_MODERATOR||$highPerformanceTeamsGroupsMember->type==HighPerformanceTeamsGroupsMembers::TYPE_USER){
|
|
|
399 |
return new JsonModel([
|
|
|
400 |
'success' => false,
|
|
|
401 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
402 |
]);
|
|
|
403 |
}
|
| 7233 |
nelberth |
404 |
if($request->isPost()) {
|
| 7271 |
nelberth |
405 |
$form = new HighPerformanceTeamsGroupsForm($this->adapter, $currentCompany->id);
|
| 7231 |
nelberth |
406 |
$dataPost = $request->getPost()->toArray();
|
| 7233 |
nelberth |
407 |
$dataPost['status'] = isset($dataPost['status']) ? $dataPost['status'] : HighPerformanceTeamsGroups::STATUS_INACTIVE;
|
| 7231 |
nelberth |
408 |
$form->setData($dataPost);
|
|
|
409 |
|
|
|
410 |
if($form->isValid()) {
|
|
|
411 |
$dataPost = (array) $form->getData();
|
|
|
412 |
|
|
|
413 |
$hydrator = new ObjectPropertyHydrator();
|
| 11213 |
nelberth |
414 |
$hydrator->hydrate($dataPost, $highPerformanceTeamsGroups);
|
|
|
415 |
$result = $highPerformanceTeamsGroupsMapper->update($highPerformanceTeamsGroups);
|
| 7231 |
nelberth |
416 |
|
| 7233 |
nelberth |
417 |
if($result) {
|
| 11675 |
nelberth |
418 |
$chatGroup = new ChatGroup();
|
|
|
419 |
$chatGroup->name = $highPerformanceTeamsGroups->title;
|
| 12666 |
nelberth |
420 |
$chatGroup->high_performance_team_group_id=$highPerformanceTeamsGroups->id;
|
| 11675 |
nelberth |
421 |
$chatGroupMapper = ChatGroupMapper::getInstance($this->adapter);
|
|
|
422 |
$result = $chatGroupMapper->update($chatGroup);
|
|
|
423 |
|
|
|
424 |
|
| 11213 |
nelberth |
425 |
$this->logger->info('Se actualizo el grupo de alto rendimiento ' . $highPerformanceTeamsGroups->title, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
|
| 7233 |
nelberth |
426 |
|
|
|
427 |
$data = [
|
|
|
428 |
'success' => true,
|
|
|
429 |
'data' => 'LABEL_RECORD_UPDATED'
|
|
|
430 |
];
|
|
|
431 |
} else {
|
|
|
432 |
$data = [
|
|
|
433 |
'success' => false,
|
|
|
434 |
'data' => $highPerformanceTeamsGroupsMapper->getError()
|
|
|
435 |
];
|
|
|
436 |
}
|
| 7231 |
nelberth |
437 |
|
| 7233 |
nelberth |
438 |
return new JsonModel($data);
|
| 7231 |
nelberth |
439 |
|
|
|
440 |
} else {
|
|
|
441 |
$messages = [];
|
|
|
442 |
$form_messages = (array) $form->getMessages();
|
|
|
443 |
foreach($form_messages as $fieldname => $field_messages)
|
|
|
444 |
{
|
|
|
445 |
$messages[$fieldname] = array_values($field_messages);
|
|
|
446 |
}
|
|
|
447 |
|
|
|
448 |
return new JsonModel([
|
|
|
449 |
'success' => false,
|
|
|
450 |
'data' => $messages
|
|
|
451 |
]);
|
|
|
452 |
}
|
| 7233 |
nelberth |
453 |
}else if ($request->isGet()) {
|
|
|
454 |
$hydrator = new ObjectPropertyHydrator();
|
|
|
455 |
|
|
|
456 |
$data = [
|
|
|
457 |
'success' => true,
|
| 11213 |
nelberth |
458 |
'data' => $hydrator->extract($highPerformanceTeamsGroups)
|
| 7231 |
nelberth |
459 |
];
|
|
|
460 |
|
| 7233 |
nelberth |
461 |
return new JsonModel($data);
|
|
|
462 |
} else {
|
|
|
463 |
$data = [
|
| 7231 |
nelberth |
464 |
'success' => false,
|
| 7233 |
nelberth |
465 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
| 7231 |
nelberth |
466 |
];
|
|
|
467 |
|
| 7233 |
nelberth |
468 |
return new JsonModel($data);
|
| 7231 |
nelberth |
469 |
}
|
|
|
470 |
|
| 7233 |
nelberth |
471 |
return new JsonModel($data);
|
| 7231 |
nelberth |
472 |
|
| 7233 |
nelberth |
473 |
}
|
| 7231 |
nelberth |
474 |
|
|
|
475 |
|
| 7233 |
nelberth |
476 |
|
|
|
477 |
|
|
|
478 |
public function deleteAction(){
|
|
|
479 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
480 |
$currentCompany = $currentUserPlugin->getCompany();
|
|
|
481 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
482 |
|
|
|
483 |
$request = $this->getRequest();
|
| 11082 |
nelberth |
484 |
$uuid = $this->params()->fromRoute('group_id');
|
| 7231 |
nelberth |
485 |
|
|
|
486 |
|
| 7233 |
nelberth |
487 |
if (!$uuid) {
|
|
|
488 |
$data = [
|
| 7231 |
nelberth |
489 |
'success' => false,
|
|
|
490 |
'data' => 'ERROR_INVALID_PARAMETER'
|
|
|
491 |
];
|
| 7233 |
nelberth |
492 |
|
|
|
493 |
return new JsonModel($data);
|
| 7231 |
nelberth |
494 |
}
|
|
|
495 |
|
| 7233 |
nelberth |
496 |
|
|
|
497 |
|
|
|
498 |
$highPerformanceTeamsGroupsMapper = HighPerformanceTeamsGroupsMapper::getInstance($this->adapter);
|
| 11210 |
nelberth |
499 |
$highPerformanceTeamsGroups = $highPerformanceTeamsGroupsMapper->fetchOneByUuid($uuid);
|
| 7233 |
nelberth |
500 |
|
| 11210 |
nelberth |
501 |
if (!$highPerformanceTeamsGroups) {
|
| 7233 |
nelberth |
502 |
$data = [
|
| 7231 |
nelberth |
503 |
'success' => false,
|
|
|
504 |
'data' => 'ERROR_RECORD_NOT_FOUND'
|
|
|
505 |
];
|
| 7233 |
nelberth |
506 |
|
|
|
507 |
return new JsonModel($data);
|
| 7231 |
nelberth |
508 |
}
|
| 11210 |
nelberth |
509 |
|
|
|
510 |
$highPerformanceTeamsGroupsMembersMapper = HighPerformanceTeamsGroupsMembersMapper::getInstance($this->adapter);
|
|
|
511 |
$highPerformanceTeamsGroupsMember = $highPerformanceTeamsGroupsMembersMapper->fetchOneByGroupIdAndUserId($highPerformanceTeamsGroups->id, $currentUser->id);
|
|
|
512 |
if(!$highPerformanceTeamsGroupsMember) {
|
| 7233 |
nelberth |
513 |
return new JsonModel([
|
| 7231 |
nelberth |
514 |
'success' => false,
|
| 11210 |
nelberth |
515 |
'data' => 'ERROR_RECORD_NOT_FOUND'
|
| 7233 |
nelberth |
516 |
]);
|
| 11210 |
nelberth |
517 |
}
|
|
|
518 |
if(!($highPerformanceTeamsGroupsMember->status == HighPerformanceTeamsGroupsMembers::STATUS_ACCEPTED || $highPerformanceTeamsGroupsMember->status == HighPerformanceTeamsGroupsMembers::STATUS_ADDED_BY_ADMIN) ){
|
|
|
519 |
return new JsonModel([
|
|
|
520 |
'success' => false,
|
|
|
521 |
'data' => 'ERROR_YOU_DO_NOT_HAVE_ACCESS'
|
|
|
522 |
]);
|
|
|
523 |
}
|
|
|
524 |
|
| 11213 |
nelberth |
525 |
if($highPerformanceTeamsGroupsMember->type==HighPerformanceTeamsGroupsMembers::TYPE_ADMINISTRATOR||$highPerformanceTeamsGroupsMember->type==HighPerformanceTeamsGroupsMembers::TYPE_MODERATOR||$highPerformanceTeamsGroupsMember->type==HighPerformanceTeamsGroupsMembers::TYPE_USER){
|
| 11210 |
nelberth |
526 |
return new JsonModel([
|
|
|
527 |
'success' => false,
|
|
|
528 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
529 |
]);
|
|
|
530 |
}
|
| 7233 |
nelberth |
531 |
|
|
|
532 |
if ($request->isPost()) {
|
| 11682 |
nelberth |
533 |
|
|
|
534 |
|
|
|
535 |
$chatGroupMapper = ChatGroupMapper::getInstance($this->adapter);
|
|
|
536 |
$chatGroup = $chatGroupMapper->fetchOneHptg($highPerformanceTeamsGroups->id);
|
|
|
537 |
|
|
|
538 |
if(!$chatGroup) {
|
|
|
539 |
return new JsonModel([
|
|
|
540 |
'success' => false,
|
|
|
541 |
'data' => 'ERROR_GROUP_NOT_FOUND'
|
|
|
542 |
]);
|
|
|
543 |
}
|
|
|
544 |
|
|
|
545 |
$chatGroupUserMapper = ChatGroupUserMapper::getInstance($this->adapter);
|
|
|
546 |
$chatGroupOwner = $chatGroupUserMapper->fetchOwnerByGroupId($chatGroup->id);
|
|
|
547 |
|
|
|
548 |
if($chatGroupOwner->user_id != $currentUser->id) {
|
|
|
549 |
return new JsonModel([
|
|
|
550 |
'success' => false,
|
|
|
551 |
'data' => 'ERROR_CHAT_GROUP_YOU_ARE_NOT_OWNER'
|
|
|
552 |
]);
|
|
|
553 |
}
|
| 7231 |
nelberth |
554 |
|
|
|
555 |
|
| 11682 |
nelberth |
556 |
$chatGroupUserMessageMapper = ChatGroupUserMessageMapper::getInstance($this->adapter);
|
|
|
557 |
$result = $chatGroupUserMessageMapper->deleteAllByGroupId($chatGroup->id);
|
|
|
558 |
if(!$result) {
|
|
|
559 |
return new JsonModel([
|
|
|
560 |
'success' => false,
|
|
|
561 |
'data' => $chatGroupUserMessageMapper->getError()
|
|
|
562 |
]);
|
|
|
563 |
}
|
|
|
564 |
|
|
|
565 |
$chatGroupMessageMapper = ChatGroupMessageMapper::getInstance($this->adapter);
|
|
|
566 |
$result = $chatGroupMessageMapper->deleteAllByGroupId($chatGroup->id);
|
|
|
567 |
if(!$result) {
|
|
|
568 |
return new JsonModel([
|
|
|
569 |
'success' => false,
|
|
|
570 |
'data' => $chatGroupMessageMapper->getError()
|
|
|
571 |
]);
|
|
|
572 |
}
|
|
|
573 |
|
|
|
574 |
$result = $chatGroupUserMapper->deleteAllByGroupId($chatGroup->id);
|
|
|
575 |
if(!$result) {
|
|
|
576 |
return new JsonModel([
|
|
|
577 |
'success' => false,
|
|
|
578 |
'data' => $chatGroupUserMapper->getError()
|
|
|
579 |
]);
|
|
|
580 |
}
|
|
|
581 |
|
|
|
582 |
$chatGroupMapper->deleteByGroupId($chatGroup->id);
|
|
|
583 |
if(!$result) {
|
|
|
584 |
return new JsonModel([
|
|
|
585 |
'success' => false,
|
|
|
586 |
'data' => $chatGroupMapper->getError()
|
|
|
587 |
]);
|
|
|
588 |
}
|
|
|
589 |
|
|
|
590 |
|
|
|
591 |
$fullpath_chat = $this->config['leaderslinked.fullpath.chat'];
|
|
|
592 |
$dirpath = $fullpath_chat . $chatGroup->uuid;
|
|
|
593 |
|
|
|
594 |
Functions::rmDirRecursive($dirpath);
|
|
|
595 |
|
|
|
596 |
|
|
|
597 |
|
| 11681 |
nelberth |
598 |
$result = $highPerformanceTeamsGroupsMapper->delete($highPerformanceTeamsGroups->id);
|
|
|
599 |
if ($result) {
|
|
|
600 |
|
| 11680 |
nelberth |
601 |
|
| 11668 |
nelberth |
602 |
$this->logger->info('Se borro el grupo de alto rendimiento ' . $highPerformanceTeamsGroups->title, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
|
| 7233 |
nelberth |
603 |
|
| 11668 |
nelberth |
604 |
$data = [
|
|
|
605 |
'success' => true,
|
|
|
606 |
'data' => 'LABEL_RECORD_DELETED'
|
|
|
607 |
];
|
| 7231 |
nelberth |
608 |
} else {
|
| 7233 |
nelberth |
609 |
|
|
|
610 |
$data = [
|
|
|
611 |
'success' => false,
|
|
|
612 |
'data' => $highPerformanceTeamsGroupsMapper->getError()
|
|
|
613 |
];
|
|
|
614 |
|
|
|
615 |
return new JsonModel($data);
|
| 7231 |
nelberth |
616 |
}
|
| 7233 |
nelberth |
617 |
} else {
|
|
|
618 |
$data = [
|
| 7231 |
nelberth |
619 |
'success' => false,
|
| 7233 |
nelberth |
620 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
| 7231 |
nelberth |
621 |
];
|
| 7233 |
nelberth |
622 |
|
| 7231 |
nelberth |
623 |
return new JsonModel($data);
|
|
|
624 |
}
|
| 7233 |
nelberth |
625 |
|
| 7231 |
nelberth |
626 |
return new JsonModel($data);
|
|
|
627 |
}
|
|
|
628 |
|
| 7233 |
nelberth |
629 |
|
|
|
630 |
|
| 7259 |
nelberth |
631 |
|
| 7233 |
nelberth |
632 |
}
|