16248 |
efrain |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
declare(strict_types=1);
|
|
|
4 |
|
|
|
5 |
namespace LeadersLinked\Controller;
|
|
|
6 |
|
|
|
7 |
use Laminas\Db\Adapter\AdapterInterface;
|
16768 |
efrain |
8 |
|
16248 |
efrain |
9 |
use Laminas\Mvc\Controller\AbstractActionController;
|
|
|
10 |
use Laminas\Log\LoggerInterface;
|
|
|
11 |
use Laminas\View\Model\ViewModel;
|
|
|
12 |
use Laminas\View\Model\JsonModel;
|
|
|
13 |
use LeadersLinked\Library\Functions;
|
|
|
14 |
use LeadersLinked\Mapper\KnowledgeAreaCategoryMapper;
|
|
|
15 |
use LeadersLinked\Model\KnowledgeAreaCategory;
|
|
|
16 |
use LeadersLinked\Mapper\UserMapper;
|
|
|
17 |
use LeadersLinked\Mapper\KnowledgeAreaCategoryUserMapper;
|
|
|
18 |
use LeadersLinked\Form\KnowledgeArea\KnowledgeAreaCategoryUserDataForm;
|
|
|
19 |
use LeadersLinked\Form\KnowledgeArea\KnowledgeAreaCategoryUserForm;
|
|
|
20 |
use LeadersLinked\Mapper\QueryMapper;
|
|
|
21 |
use Laminas\Paginator\Adapter\DbSelect;
|
|
|
22 |
use Laminas\Paginator\Paginator;
|
|
|
23 |
use LeadersLinked\Model\KnowledgeAreaCategoryUser;
|
16797 |
efrain |
24 |
use LeadersLinked\Model\User;
|
|
|
25 |
use LeadersLinked\Model\Company;
|
|
|
26 |
use LeadersLinked\Mapper\JobDescriptionMapper;
|
|
|
27 |
use LeadersLinked\Mapper\KnowledgeAreaCategoryJobDescriptionMapper;
|
|
|
28 |
use LeadersLinked\Model\KnowledgeAreaCategoryJobDescription;
|
16248 |
efrain |
29 |
|
|
|
30 |
|
|
|
31 |
class KnowledgeAreaCategoryUserController extends AbstractActionController {
|
|
|
32 |
|
|
|
33 |
/**
|
|
|
34 |
*
|
16769 |
efrain |
35 |
* @var \Laminas\Db\Adapter\AdapterInterface
|
16248 |
efrain |
36 |
*/
|
|
|
37 |
private $adapter;
|
16768 |
efrain |
38 |
|
16248 |
efrain |
39 |
/**
|
|
|
40 |
*
|
16769 |
efrain |
41 |
* @var \LeadersLinked\Cache\CacheInterface
|
16248 |
efrain |
42 |
*/
|
16769 |
efrain |
43 |
private $cache;
|
|
|
44 |
|
|
|
45 |
|
|
|
46 |
/**
|
|
|
47 |
*
|
|
|
48 |
* @var \Laminas\Log\LoggerInterface
|
|
|
49 |
*/
|
16248 |
efrain |
50 |
private $logger;
|
16768 |
efrain |
51 |
|
16248 |
efrain |
52 |
/**
|
|
|
53 |
*
|
|
|
54 |
* @var array
|
|
|
55 |
*/
|
|
|
56 |
private $config;
|
16768 |
efrain |
57 |
|
16769 |
efrain |
58 |
|
16248 |
efrain |
59 |
/**
|
|
|
60 |
*
|
16769 |
efrain |
61 |
* @var \Laminas\Mvc\I18n\Translator
|
|
|
62 |
*/
|
|
|
63 |
private $translator;
|
|
|
64 |
|
|
|
65 |
|
|
|
66 |
/**
|
|
|
67 |
*
|
|
|
68 |
* @param \Laminas\Db\Adapter\AdapterInterface $adapter
|
|
|
69 |
* @param \LeadersLinked\Cache\CacheInterface $cache
|
|
|
70 |
* @param \Laminas\Log\LoggerInterface LoggerInterface $logger
|
16248 |
efrain |
71 |
* @param array $config
|
16769 |
efrain |
72 |
* @param \Laminas\Mvc\I18n\Translator $translator
|
16248 |
efrain |
73 |
*/
|
16769 |
efrain |
74 |
public function __construct($adapter, $cache, $logger, $config, $translator)
|
16768 |
efrain |
75 |
{
|
16769 |
efrain |
76 |
$this->adapter = $adapter;
|
|
|
77 |
$this->cache = $cache;
|
|
|
78 |
$this->logger = $logger;
|
|
|
79 |
$this->config = $config;
|
|
|
80 |
$this->translator = $translator;
|
16248 |
efrain |
81 |
}
|
|
|
82 |
|
|
|
83 |
public function indexAction() {
|
|
|
84 |
$request = $this->getRequest();
|
|
|
85 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
86 |
$currentCompany = $currentUserPlugin->getCompany();
|
|
|
87 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
88 |
|
|
|
89 |
|
|
|
90 |
$request = $this->getRequest();
|
|
|
91 |
if ($request->isGet()) {
|
|
|
92 |
|
|
|
93 |
$headers = $request->getHeaders();
|
|
|
94 |
|
|
|
95 |
$isJson = false;
|
|
|
96 |
if ($headers->has('Accept')) {
|
|
|
97 |
$accept = $headers->get('Accept');
|
|
|
98 |
|
|
|
99 |
$prioritized = $accept->getPrioritized();
|
|
|
100 |
|
|
|
101 |
foreach ($prioritized as $key => $value) {
|
|
|
102 |
$raw = trim($value->getRaw());
|
|
|
103 |
|
|
|
104 |
if (!$isJson) {
|
|
|
105 |
$isJson = strpos($raw, 'json');
|
|
|
106 |
}
|
|
|
107 |
}
|
|
|
108 |
}
|
|
|
109 |
|
|
|
110 |
//$isJson = true;
|
|
|
111 |
if ($isJson) {
|
|
|
112 |
|
16766 |
efrain |
113 |
$category_uuid = Functions::sanitizeFilterString($this->params()->fromQuery('category_id'));
|
|
|
114 |
|
16248 |
efrain |
115 |
if(!$category_uuid) {
|
|
|
116 |
return new JsonModel([
|
|
|
117 |
'success' => true,
|
|
|
118 |
'data' => [
|
|
|
119 |
'total' => 0,
|
|
|
120 |
'items' => [],
|
|
|
121 |
'link_add' => '',
|
|
|
122 |
'link_upload' => '',
|
16797 |
efrain |
123 |
'link_jobs_description' => '',
|
|
|
124 |
'roles' => [],
|
|
|
125 |
'jobs_description' => [],
|
16248 |
efrain |
126 |
]
|
|
|
127 |
]);
|
|
|
128 |
|
|
|
129 |
}
|
|
|
130 |
|
|
|
131 |
|
|
|
132 |
$knowledgeAreaCategoryMapper = KnowledgeAreaCategoryMapper::getInstance($this->adapter);
|
|
|
133 |
$knowledgeAreaCategory = $knowledgeAreaCategoryMapper->fetchOneByUuid($category_uuid);
|
|
|
134 |
|
|
|
135 |
if(!$knowledgeAreaCategory) {
|
|
|
136 |
return new JsonModel([
|
|
|
137 |
'success' => false,
|
|
|
138 |
'data' => 'ERROR_KNOWLEDGE_AREA_CATEGORY_NOT_FOUND'
|
|
|
139 |
]);
|
|
|
140 |
}
|
|
|
141 |
|
|
|
142 |
if($knowledgeAreaCategory->company_id != $currentCompany->id) {
|
|
|
143 |
return new JsonModel([
|
|
|
144 |
'success' => false,
|
|
|
145 |
'data' => 'ERROR_KNOWLEDGE_AREA_CATEGORY_IS_OTHER_COMPANY'
|
|
|
146 |
]);
|
|
|
147 |
}
|
|
|
148 |
|
|
|
149 |
|
|
|
150 |
|
|
|
151 |
|
|
|
152 |
$search = $this->params()->fromQuery('search', []);
|
16766 |
efrain |
153 |
$search = empty($search['value']) ? '' : Functions::sanitizeFilterString($search['value']);
|
16248 |
efrain |
154 |
|
|
|
155 |
$start = intval($this->params()->fromQuery('start', 0), 10);
|
|
|
156 |
$records_x_page = intval($this->params()->fromQuery('length', 10), 10);
|
|
|
157 |
$page = intval($start / $records_x_page);
|
|
|
158 |
$page++;
|
|
|
159 |
|
|
|
160 |
$order = $this->params()->fromQuery('order', []);
|
|
|
161 |
$order_field = empty($order[0]['column']) ? 99 : intval($order[0]['column'], 10);
|
16766 |
efrain |
162 |
$order_direction = empty($order[0]['dir']) ? 'ASC' : Functions::sanitizeFilterString(filter_var($order[0]['dir']));
|
16248 |
efrain |
163 |
|
|
|
164 |
$fields = ['first_name', 'last_name', 'email'];
|
|
|
165 |
$order_field = isset($fields[$order_field]) ? $fields[$order_field] : 'first_name';
|
|
|
166 |
|
|
|
167 |
if (!in_array($order_direction, ['ASC', 'DESC'])) {
|
|
|
168 |
$order_direction = 'ASC';
|
|
|
169 |
}
|
|
|
170 |
|
|
|
171 |
|
|
|
172 |
|
|
|
173 |
$acl = $this->getEvent()->getViewModel()->getVariable('acl');
|
|
|
174 |
$allowAdd = $acl->isAllowed($currentUser->usertype_id, 'knowledge-area/categories/users/add');
|
|
|
175 |
$allowEdit = $acl->isAllowed($currentUser->usertype_id, 'knowledge-area/categories/users/edit');
|
|
|
176 |
$allowDelete = $acl->isAllowed($currentUser->usertype_id, 'knowledge-area/categories/users/delete');
|
|
|
177 |
$allowUpload = $acl->isAllowed($currentUser->usertype_id, 'knowledge-area/categories/users/upload');
|
16797 |
efrain |
178 |
$allowJobsDescription = $acl->isAllowed($currentUser->usertype_id, 'knowledge-area/categories/users/jobs-description');
|
16248 |
efrain |
179 |
|
|
|
180 |
|
|
|
181 |
$items = [];
|
|
|
182 |
|
|
|
183 |
$queryMapper = QueryMapper::getInstance($this->adapter);
|
|
|
184 |
$select = $queryMapper->getSql()->select();
|
|
|
185 |
$select->columns(['role']);
|
|
|
186 |
$select->from(['cu' => KnowledgeAreaCategoryUserMapper::_TABLE]);
|
|
|
187 |
$select->join(['u' => UserMapper::_TABLE], 'cu.user_id = u.id', ['uuid', 'first_name', 'last_name', 'email']);
|
|
|
188 |
$select->where->equalTo('cu.category_id', $knowledgeAreaCategory->id);
|
|
|
189 |
|
|
|
190 |
|
|
|
191 |
if($search) {
|
|
|
192 |
$select->where->nest()->like('first_name', '%' . $search . '%')
|
|
|
193 |
->or->like('last_name', '%' . $search . '%')
|
|
|
194 |
->or->like('email', '%' . $search . '%')->unnest();
|
|
|
195 |
}
|
|
|
196 |
|
|
|
197 |
$select->order($order_field . ' ' . $order_direction);
|
|
|
198 |
|
|
|
199 |
//echo $select->getSqlString($this->adapter->platform); exit;
|
|
|
200 |
|
|
|
201 |
|
|
|
202 |
$paginatorAdapter = new DbSelect($select, $this->adapter);
|
|
|
203 |
$paginator = new Paginator($paginatorAdapter);
|
|
|
204 |
$paginator->setItemCountPerPage($records_x_page);
|
|
|
205 |
$paginator->setCurrentPageNumber($page);
|
|
|
206 |
|
|
|
207 |
$records = $paginator->getCurrentItems();
|
|
|
208 |
|
|
|
209 |
foreach ($records as $record) {
|
|
|
210 |
|
|
|
211 |
switch($record['role'])
|
|
|
212 |
{
|
|
|
213 |
|
|
|
214 |
case KnowledgeAreaCategoryUser::ROLE_ADMINISTRATOR :
|
|
|
215 |
$role = 'LABEL_ADMINISTRATOR';
|
|
|
216 |
break;
|
|
|
217 |
|
|
|
218 |
case KnowledgeAreaCategoryUser::ROLE_EDITOR :
|
|
|
219 |
$role = 'LABEL_EDITOR';
|
|
|
220 |
break;
|
|
|
221 |
|
|
|
222 |
case KnowledgeAreaCategoryUser::ROLE_USER :
|
|
|
223 |
$role = 'LABEL_USER';
|
|
|
224 |
break;
|
|
|
225 |
|
|
|
226 |
default :
|
|
|
227 |
$role = 'LABEL_UNKNOWN';
|
|
|
228 |
break;
|
|
|
229 |
}
|
|
|
230 |
|
|
|
231 |
|
|
|
232 |
|
|
|
233 |
|
|
|
234 |
|
|
|
235 |
|
|
|
236 |
$item = [
|
|
|
237 |
'first_name' => $record['first_name'],
|
|
|
238 |
'last_name' => $record['first_name'],
|
|
|
239 |
'email' => $record['email'],
|
|
|
240 |
'role' => $role,
|
|
|
241 |
'actions' => [
|
|
|
242 |
'link_edit' => $allowEdit ? $this->url()->fromRoute('knowledge-area/categories/users/edit', ['id' => $knowledgeAreaCategory->uuid, 'user_id' => $record['uuid'] ]) : '',
|
|
|
243 |
'link_delete' => $allowDelete ? $this->url()->fromRoute('knowledge-area/categories/users/delete', ['id' => $knowledgeAreaCategory->uuid, 'user_id' => $record['uuid'] ]) : '',
|
|
|
244 |
]
|
|
|
245 |
];
|
|
|
246 |
|
|
|
247 |
array_push($items, $item);
|
|
|
248 |
}
|
|
|
249 |
|
16940 |
efrain |
250 |
$roles = [];
|
16248 |
efrain |
251 |
if($knowledgeAreaCategory->privacy == KnowledgeAreaCategory::PRIVACY_COMPANY) {
|
|
|
252 |
$roles = [
|
16940 |
efrain |
253 |
KnowledgeAreaCategoryUser::ROLE_USER => 'LABEL_USER',
|
16248 |
efrain |
254 |
KnowledgeAreaCategoryUser::ROLE_EDITOR => 'LABEL_EDITOR',
|
16940 |
efrain |
255 |
KnowledgeAreaCategoryUser::ROLE_ADMINISTRATOR => 'LABEL_ADMINISTRATOR',
|
|
|
256 |
];
|
|
|
257 |
|
16248 |
efrain |
258 |
} else {
|
|
|
259 |
$roles = [
|
|
|
260 |
KnowledgeAreaCategoryUser::ROLE_EDITOR => 'LABEL_EDITOR',
|
|
|
261 |
KnowledgeAreaCategoryUser::ROLE_ADMINISTRATOR => 'LABEL_ADMINISTRATOR',
|
|
|
262 |
];
|
|
|
263 |
}
|
|
|
264 |
|
16940 |
efrain |
265 |
|
16797 |
efrain |
266 |
$jobs_description = [];
|
16248 |
efrain |
267 |
|
16797 |
efrain |
268 |
|
|
|
269 |
$jobDescriptionMapper = JobDescriptionMapper::getInstance($this->adapter);
|
|
|
270 |
$knowledgeAreaCategoryJobDescriptionMapper = KnowledgeAreaCategoryJobDescriptionMapper::getInstance($this->adapter);
|
|
|
271 |
$records = $knowledgeAreaCategoryJobDescriptionMapper->fetchAllByCategoryId($knowledgeAreaCategory->id);
|
|
|
272 |
foreach($records as $record)
|
|
|
273 |
{
|
|
|
274 |
$jobDescription = $jobDescriptionMapper->fetchOne($record->job_description_id);
|
|
|
275 |
array_push($jobs_description, $jobDescription->uuid);
|
|
|
276 |
}
|
16940 |
efrain |
277 |
|
16248 |
efrain |
278 |
|
|
|
279 |
return new JsonModel([
|
|
|
280 |
'success' => true,
|
|
|
281 |
'data' => [
|
|
|
282 |
'total' => $paginator->getTotalItemCount(),
|
|
|
283 |
'items' => $items,
|
|
|
284 |
'link_add' => $allowAdd ? $this->url()->fromRoute('knowledge-area/categories/users/add', ['id' => $knowledgeAreaCategory->uuid ] ) : '',
|
|
|
285 |
'link_upload' => $allowUpload ? $this->url()->fromRoute('knowledge-area/categories/users/upload', ['id' => $knowledgeAreaCategory->uuid ] ) : '',
|
16797 |
efrain |
286 |
'link_jobs_description' => $allowJobsDescription ? $this->url()->fromRoute('knowledge-area/categories/users/jobs-description', ['id' => $knowledgeAreaCategory->uuid ] ) : '',
|
16248 |
efrain |
287 |
'roles' => $roles,
|
16797 |
efrain |
288 |
'jobs_description' => $jobs_description,
|
16248 |
efrain |
289 |
]
|
|
|
290 |
]);
|
|
|
291 |
} else {
|
|
|
292 |
|
16797 |
efrain |
293 |
$jobDescriptionIdBoss = 0;
|
|
|
294 |
$jobDescriptionMapper = JobDescriptionMapper::getInstance($this->adapter);
|
|
|
295 |
$jobsDescription = $this->recursiveLoad($currentUser, $currentCompany, $jobDescriptionMapper, $jobDescriptionIdBoss);
|
|
|
296 |
|
|
|
297 |
|
16248 |
efrain |
298 |
$form = new KnowledgeAreaCategoryUserForm($this->adapter, $currentCompany->id, KnowledgeAreaCategory::PRIVACY_COMPANY);
|
|
|
299 |
$formFilter = new KnowledgeAreaCategoryUserDataForm($this->adapter, $currentCompany->id);
|
|
|
300 |
|
|
|
301 |
|
|
|
302 |
$this->layout()->setTemplate('layout/layout-backend');
|
|
|
303 |
$viewModel = new ViewModel();
|
|
|
304 |
$viewModel->setTemplate('leaders-linked/knowledge-area-category-users/index.phtml');
|
|
|
305 |
$viewModel->setVariables([
|
|
|
306 |
'form' => $form,
|
|
|
307 |
'formFilter' => $formFilter,
|
16797 |
efrain |
308 |
'jobsDescription' => $jobsDescription,
|
|
|
309 |
'companyName' => $currentCompany->name,
|
16248 |
efrain |
310 |
]);
|
|
|
311 |
return $viewModel;
|
|
|
312 |
}
|
|
|
313 |
} else {
|
|
|
314 |
return new JsonModel([
|
|
|
315 |
'success' => false,
|
|
|
316 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
317 |
]);
|
|
|
318 |
}
|
|
|
319 |
|
|
|
320 |
}
|
16797 |
efrain |
321 |
|
|
|
322 |
|
|
|
323 |
/**
|
|
|
324 |
*
|
|
|
325 |
* @param User $currentUser
|
|
|
326 |
* @param Company $currentCompany
|
|
|
327 |
* @param JobDescriptionMapper $jobDescriptionMapper
|
|
|
328 |
* @param int $jobDescriptionIdBoss
|
|
|
329 |
* @return array
|
|
|
330 |
*/
|
|
|
331 |
private function recursiveLoad($currentUser, $currentCompany, $jobDescriptionMapper, $jobDescriptionIdBoss)
|
|
|
332 |
{
|
|
|
333 |
$items = [];
|
|
|
334 |
$records = $jobDescriptionMapper->fetchAllByCompanyIdAndJobDescriptionIdBoss($currentCompany->id, $jobDescriptionIdBoss);
|
16248 |
efrain |
335 |
|
16797 |
efrain |
336 |
|
|
|
337 |
foreach($records as $record)
|
|
|
338 |
{
|
|
|
339 |
|
|
|
340 |
|
|
|
341 |
|
|
|
342 |
array_push($items, [
|
|
|
343 |
'uuid' => $record->uuid,
|
|
|
344 |
'name' => $record->name,
|
|
|
345 |
'children' => $this->recursiveLoad($currentUser, $currentCompany, $jobDescriptionMapper, $record->id),
|
|
|
346 |
]);
|
|
|
347 |
}
|
|
|
348 |
|
|
|
349 |
return $items;
|
|
|
350 |
}
|
|
|
351 |
|
16248 |
efrain |
352 |
public function addAction()
|
|
|
353 |
{
|
|
|
354 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
355 |
$currentCompany = $currentUserPlugin->getCompany();
|
|
|
356 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
357 |
$request = $this->getRequest();
|
|
|
358 |
|
|
|
359 |
if($request->isPost()) {
|
|
|
360 |
|
16766 |
efrain |
361 |
$category_uuid = Functions::sanitizeFilterString($this->params()->fromRoute('id'));
|
16248 |
efrain |
362 |
|
|
|
363 |
$knowledgeAreaCategoryMapper = KnowledgeAreaCategoryMapper::getInstance($this->adapter);
|
|
|
364 |
$knowledgeAreaCategory = $knowledgeAreaCategoryMapper->fetchOneByUuid($category_uuid);
|
|
|
365 |
|
|
|
366 |
if(!$knowledgeAreaCategory) {
|
|
|
367 |
return new JsonModel([
|
|
|
368 |
'success' => false,
|
|
|
369 |
'data' => 'ERROR_KNOWLEDGE_AREA_CATEGORY_NOT_FOUND'
|
|
|
370 |
]);
|
|
|
371 |
}
|
|
|
372 |
|
|
|
373 |
if($knowledgeAreaCategory->company_id != $currentCompany->id) {
|
|
|
374 |
return new JsonModel([
|
|
|
375 |
'success' => false,
|
|
|
376 |
'data' => 'ERROR_KNOWLEDGE_AREA_CATEGORY_IS_OTHER_COMPANY'
|
|
|
377 |
]);
|
|
|
378 |
}
|
|
|
379 |
|
|
|
380 |
$dataPost = $request->getPost()->toArray();
|
|
|
381 |
|
|
|
382 |
$form = new KnowledgeAreaCategoryUserForm($this->adapter, $currentCompany->id, $knowledgeAreaCategory->privacy);
|
|
|
383 |
$form->setData($dataPost);
|
|
|
384 |
|
|
|
385 |
if($form->isValid()) {
|
|
|
386 |
|
|
|
387 |
$dataPost = (array) $form->getData();
|
|
|
388 |
|
|
|
389 |
|
|
|
390 |
$userMapper = UserMapper::getInstance($this->adapter);
|
|
|
391 |
$user = $userMapper->fetchOneByUuid($dataPost['user_id']);
|
|
|
392 |
|
|
|
393 |
$knowledgeAreaCategoryUserMapper = KnowledgeAreaCategoryUserMapper::getInstance($this->adapter);
|
|
|
394 |
$knowledgeAreaCategoryUser = $knowledgeAreaCategoryUserMapper->fetchOneByCategoryIdAndUserId($knowledgeAreaCategory->id, $user->id);
|
|
|
395 |
|
|
|
396 |
if($knowledgeAreaCategoryUser) {
|
|
|
397 |
return new JsonModel([
|
|
|
398 |
'success' => false,
|
|
|
399 |
'data' => 'ERROR_KNOWLEDGE_AREA_CATEGORY_USER_ALREADY_FOUND'
|
|
|
400 |
]);
|
|
|
401 |
}
|
|
|
402 |
|
|
|
403 |
|
|
|
404 |
$knowledgeAreaCategoryUser = new KnowledgeAreaCategoryUser();
|
|
|
405 |
$knowledgeAreaCategoryUser->category_id = $knowledgeAreaCategory->id;
|
|
|
406 |
$knowledgeAreaCategoryUser->user_id = $user->id;
|
|
|
407 |
$knowledgeAreaCategoryUser->role = $dataPost['role'];
|
|
|
408 |
$knowledgeAreaCategoryUserMapper = KnowledgeAreaCategoryUserMapper::getInstance($this->adapter);
|
|
|
409 |
|
|
|
410 |
|
|
|
411 |
if($knowledgeAreaCategoryUserMapper->insert($knowledgeAreaCategoryUser)) {
|
|
|
412 |
|
|
|
413 |
|
|
|
414 |
$this->logger->info('Se agrego el usuario ' . $user->first_name . ' ' . $user->last_name . ' (' . $user->email . ') la categoria ' . $knowledgeAreaCategory->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
|
|
|
415 |
|
|
|
416 |
$data = [
|
|
|
417 |
'success' => true,
|
|
|
418 |
'data' => 'LABEL_RECORD_ADDED'
|
|
|
419 |
];
|
|
|
420 |
} else {
|
|
|
421 |
$data = [
|
|
|
422 |
'success' => false,
|
|
|
423 |
'data' => $knowledgeAreaCategoryUserMapper->getError()
|
|
|
424 |
];
|
|
|
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 |
}
|
|
|
444 |
|
|
|
445 |
} else {
|
|
|
446 |
$data = [
|
|
|
447 |
'success' => false,
|
|
|
448 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
449 |
];
|
|
|
450 |
|
|
|
451 |
return new JsonModel($data);
|
|
|
452 |
}
|
|
|
453 |
|
|
|
454 |
return new JsonModel($data);
|
|
|
455 |
|
|
|
456 |
|
|
|
457 |
}
|
|
|
458 |
|
|
|
459 |
public function editAction()
|
|
|
460 |
{
|
|
|
461 |
$request = $this->getRequest();
|
|
|
462 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
463 |
$currentCompany = $currentUserPlugin->getCompany();
|
|
|
464 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
465 |
|
|
|
466 |
$request = $this->getRequest();
|
|
|
467 |
$uuid = $this->params()->fromRoute('id');
|
|
|
468 |
$user_uuid = $this->params()->fromRoute('user_id');
|
|
|
469 |
|
|
|
470 |
$knowledgeAreaCategoryMapper = KnowledgeAreaCategoryMapper::getInstance($this->adapter);
|
|
|
471 |
$knowledgeAreaCategory = $knowledgeAreaCategoryMapper->fetchOneByUuid($uuid);
|
|
|
472 |
|
|
|
473 |
if(!$knowledgeAreaCategory) {
|
|
|
474 |
return new JsonModel([
|
|
|
475 |
'success' => false,
|
|
|
476 |
'data' => 'ERROR_KNOWLEDGE_AREA_CATEGORY_NOT_FOUND'
|
|
|
477 |
]);
|
|
|
478 |
}
|
|
|
479 |
|
|
|
480 |
if($knowledgeAreaCategory->company_id != $currentCompany->id) {
|
|
|
481 |
return new JsonModel([
|
|
|
482 |
'success' => false,
|
|
|
483 |
'data' => 'ERROR_KNOWLEDGE_AREA_CATEGORY_IS_OTHER_COMPANY'
|
|
|
484 |
]);
|
|
|
485 |
}
|
|
|
486 |
|
|
|
487 |
$userMapper = UserMapper::getInstance($this->adapter);
|
|
|
488 |
$user = $userMapper->fetchOneByUuid($user_uuid);
|
|
|
489 |
|
|
|
490 |
if(!$user) {
|
|
|
491 |
return new JsonModel([
|
|
|
492 |
'success' => false,
|
|
|
493 |
'data' => 'ERROR_USER_NOT_FOUND'
|
|
|
494 |
]);
|
|
|
495 |
|
|
|
496 |
}
|
|
|
497 |
|
|
|
498 |
$knowledgeAreaCategoryUserMapper = KnowledgeAreaCategoryUserMapper::getInstance($this->adapter);
|
|
|
499 |
$knowledgeAreaCategoryUser = $knowledgeAreaCategoryUserMapper->fetchOneByCategoryIdAndUserId($knowledgeAreaCategory->id, $user->id);
|
|
|
500 |
|
|
|
501 |
if(!$knowledgeAreaCategoryUser) {
|
|
|
502 |
return new JsonModel([
|
|
|
503 |
'success' => false,
|
|
|
504 |
'data' => 'ERROR_KNOWLEDGE_AREA_CATEGORY_USER_NOT_FOUND'
|
|
|
505 |
]);
|
|
|
506 |
}
|
|
|
507 |
|
|
|
508 |
|
|
|
509 |
|
|
|
510 |
if ($request->isPost()) {
|
|
|
511 |
$dataPost = $request->getPost()->toArray();
|
|
|
512 |
|
|
|
513 |
$form = new KnowledgeAreaCategoryUserForm($this->adapter, $currentCompany->id, $knowledgeAreaCategory->privacy);
|
|
|
514 |
$form->setData($dataPost);
|
|
|
515 |
|
|
|
516 |
|
|
|
517 |
|
|
|
518 |
if ($form->isValid()) {
|
|
|
519 |
$dataPost = (array) $form->getData();
|
|
|
520 |
|
|
|
521 |
$knowledgeAreaCategoryUser->role = $dataPost['role'];
|
|
|
522 |
|
|
|
523 |
|
|
|
524 |
if($knowledgeAreaCategoryUserMapper->update($knowledgeAreaCategoryUser)) {
|
|
|
525 |
|
|
|
526 |
$this->logger->info('Se actualizo el usuario ' . $user->first_name . ' ' . $user->last_name . ' (' . $user->email . ') la categoria ' . $knowledgeAreaCategory->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
|
|
|
527 |
|
|
|
528 |
$data = [
|
|
|
529 |
'success' => true,
|
|
|
530 |
'data' => 'LABEL_RECORD_UPDATED'
|
|
|
531 |
];
|
|
|
532 |
} else {
|
|
|
533 |
$data = [
|
|
|
534 |
'success' => false,
|
|
|
535 |
'data' => $knowledgeAreaCategoryUserMapper->getError()
|
|
|
536 |
];
|
|
|
537 |
|
|
|
538 |
}
|
|
|
539 |
|
|
|
540 |
return new JsonModel($data);
|
|
|
541 |
} else {
|
|
|
542 |
$messages = [];
|
|
|
543 |
$form_messages = (array) $form->getMessages();
|
|
|
544 |
foreach ($form_messages as $fieldname => $field_messages) {
|
|
|
545 |
$messages[$fieldname] = array_values($field_messages);
|
|
|
546 |
}
|
|
|
547 |
|
|
|
548 |
return new JsonModel([
|
|
|
549 |
'success' => false,
|
|
|
550 |
'data' => $messages
|
|
|
551 |
]);
|
|
|
552 |
}
|
|
|
553 |
} else if ($request->isGet()) {
|
|
|
554 |
|
|
|
555 |
|
|
|
556 |
$data = [
|
|
|
557 |
'success' => true,
|
|
|
558 |
'data' => [
|
|
|
559 |
'user_id' => $user->uuid,
|
|
|
560 |
'role' => $knowledgeAreaCategoryUser->role,
|
|
|
561 |
]
|
|
|
562 |
];
|
|
|
563 |
|
|
|
564 |
return new JsonModel($data);
|
|
|
565 |
}
|
|
|
566 |
|
|
|
567 |
|
|
|
568 |
$data = [
|
|
|
569 |
'success' => false,
|
|
|
570 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
571 |
];
|
|
|
572 |
|
|
|
573 |
return new JsonModel($data);
|
|
|
574 |
|
|
|
575 |
}
|
|
|
576 |
|
|
|
577 |
public function deleteAction()
|
|
|
578 |
{
|
|
|
579 |
$request = $this->getRequest();
|
|
|
580 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
581 |
$currentCompany = $currentUserPlugin->getCompany();
|
|
|
582 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
583 |
|
|
|
584 |
$request = $this->getRequest();
|
|
|
585 |
$uuid = $this->params()->fromRoute('id');
|
|
|
586 |
$user_id = $this->params()->fromRoute('user_id');
|
|
|
587 |
|
|
|
588 |
|
|
|
589 |
$knowledgeAreaCategoryMapper = KnowledgeAreaCategoryMapper::getInstance($this->adapter);
|
|
|
590 |
$knowledgeAreaCategory = $knowledgeAreaCategoryMapper->fetchOneByUuid($uuid);
|
|
|
591 |
|
|
|
592 |
if(!$knowledgeAreaCategory) {
|
|
|
593 |
return new JsonModel([
|
|
|
594 |
'success' => false,
|
|
|
595 |
'data' => 'ERROR_KNOWLEDGE_AREA_CATEGORY_NOT_FOUND'
|
|
|
596 |
]);
|
|
|
597 |
}
|
|
|
598 |
|
|
|
599 |
if($knowledgeAreaCategory->company_id != $currentCompany->id) {
|
|
|
600 |
return new JsonModel([
|
|
|
601 |
'success' => false,
|
|
|
602 |
'data' => 'ERROR_KNOWLEDGE_AREA_CATEGORY_IS_OTHER_COMPANY'
|
|
|
603 |
]);
|
|
|
604 |
}
|
|
|
605 |
|
|
|
606 |
$userMapper = UserMapper::getInstance($this->adapter);
|
|
|
607 |
$user = $userMapper->fetchOneByUuid($user_id);
|
|
|
608 |
|
|
|
609 |
if(!$user) {
|
|
|
610 |
return new JsonModel([
|
|
|
611 |
'success' => false,
|
|
|
612 |
'data' => 'ERROR_USER_NOT_FOUND'
|
|
|
613 |
]);
|
|
|
614 |
|
|
|
615 |
}
|
|
|
616 |
|
|
|
617 |
$knowledgeAreaCategoryUserMapper = KnowledgeAreaCategoryUserMapper::getInstance($this->adapter);
|
|
|
618 |
$knowledgeAreaCategoryUser = $knowledgeAreaCategoryUserMapper->fetchOneByCategoryIdAndUserId($knowledgeAreaCategory->id, $user->id);
|
|
|
619 |
|
|
|
620 |
if(!$knowledgeAreaCategoryUser) {
|
|
|
621 |
return new JsonModel([
|
|
|
622 |
'success' => false,
|
|
|
623 |
'data' => 'ERROR_KNOWLEDGE_AREA_CATEGORY_USER_NOT_FOUND'
|
|
|
624 |
]);
|
|
|
625 |
}
|
|
|
626 |
|
|
|
627 |
|
|
|
628 |
|
|
|
629 |
if ($request->isPost()) {
|
|
|
630 |
|
|
|
631 |
if ($knowledgeAreaCategoryUserMapper->deleteOneByCategoryIdAndUserId($knowledgeAreaCategory->id, $user->id)) {
|
|
|
632 |
$this->logger->info('Se borro el usuario ' . $user->first_name . ' ' . $user->last_name . ' (' . $user->email . ') la categoria ' . $knowledgeAreaCategory->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
|
|
|
633 |
|
|
|
634 |
$data = [
|
|
|
635 |
'success' => true,
|
|
|
636 |
'data' => 'LABEL_RECORD_DELETED'
|
|
|
637 |
];
|
|
|
638 |
} else {
|
|
|
639 |
|
|
|
640 |
$data = [
|
|
|
641 |
'success' => false,
|
|
|
642 |
'data' => $knowledgeAreaCategoryUserMapper->getError()
|
|
|
643 |
];
|
|
|
644 |
|
|
|
645 |
|
|
|
646 |
}
|
|
|
647 |
} else {
|
|
|
648 |
$data = [
|
|
|
649 |
'success' => false,
|
|
|
650 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
651 |
];
|
|
|
652 |
|
|
|
653 |
|
|
|
654 |
}
|
|
|
655 |
|
|
|
656 |
|
|
|
657 |
return new JsonModel($data);
|
|
|
658 |
|
|
|
659 |
}
|
16797 |
efrain |
660 |
|
|
|
661 |
public function jobsDescriptionAction()
|
|
|
662 |
{
|
|
|
663 |
$request = $this->getRequest();
|
|
|
664 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
665 |
$currentCompany = $currentUserPlugin->getCompany();
|
|
|
666 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
667 |
|
|
|
668 |
$request = $this->getRequest();
|
|
|
669 |
$uuid = $this->params()->fromRoute('id');
|
|
|
670 |
|
|
|
671 |
|
|
|
672 |
|
|
|
673 |
$knowledgeAreaCategoryMapper = KnowledgeAreaCategoryMapper::getInstance($this->adapter);
|
|
|
674 |
$knowledgeAreaCategory = $knowledgeAreaCategoryMapper->fetchOneByUuid($uuid);
|
|
|
675 |
|
|
|
676 |
if(!$knowledgeAreaCategory) {
|
|
|
677 |
return new JsonModel([
|
|
|
678 |
'success' => false,
|
|
|
679 |
'data' => 'ERROR_KNOWLEDGE_AREA_CATEGORY_NOT_FOUND'
|
|
|
680 |
]);
|
|
|
681 |
}
|
|
|
682 |
|
|
|
683 |
if($knowledgeAreaCategory->company_id != $currentCompany->id) {
|
|
|
684 |
return new JsonModel([
|
|
|
685 |
'success' => false,
|
|
|
686 |
'data' => 'ERROR_KNOWLEDGE_AREA_CATEGORY_IS_OTHER_COMPANY'
|
|
|
687 |
]);
|
|
|
688 |
}
|
|
|
689 |
|
|
|
690 |
if ($request->isPost()) {
|
|
|
691 |
|
|
|
692 |
$knowledgeAreaCategoryJobDescriptionMapper = KnowledgeAreaCategoryJobDescriptionMapper::getInstance($this->adapter);
|
|
|
693 |
$knowledgeAreaCategoryJobDescriptionMapper->deleteAllByCategoryId($knowledgeAreaCategory->id);
|
|
|
694 |
|
|
|
695 |
$jobDescriptionMapper = JobDescriptionMapper::getInstance($this->adapter);
|
|
|
696 |
$jobs_description_uuid = $this->params()->fromPost('job_description_id');
|
|
|
697 |
|
|
|
698 |
if(!empty($jobs_description_uuid)) {
|
|
|
699 |
|
|
|
700 |
foreach($jobs_description_uuid as $job_description_uuid)
|
|
|
701 |
{
|
|
|
702 |
$jobDescription = $jobDescriptionMapper->fetchOneByUuid($job_description_uuid);
|
|
|
703 |
|
|
|
704 |
|
|
|
705 |
if($jobDescription && $jobDescription->company_id == $currentCompany->id) {
|
|
|
706 |
|
|
|
707 |
|
|
|
708 |
$knowledgeAreaCategoryJobDescription = new KnowledgeAreaCategoryJobDescription();
|
|
|
709 |
$knowledgeAreaCategoryJobDescription->category_id = $knowledgeAreaCategory->id;
|
|
|
710 |
$knowledgeAreaCategoryJobDescription->job_description_id = $jobDescription->id;
|
|
|
711 |
|
|
|
712 |
|
|
|
713 |
$knowledgeAreaCategoryJobDescriptionMapper->insert($knowledgeAreaCategoryJobDescription);
|
|
|
714 |
}
|
|
|
715 |
|
|
|
716 |
}
|
|
|
717 |
}
|
|
|
718 |
|
|
|
719 |
|
|
|
720 |
$data = [
|
|
|
721 |
'success' => true,
|
|
|
722 |
'data' => 'LABEL_RECORD_UPDATED'
|
|
|
723 |
];
|
|
|
724 |
|
|
|
725 |
} else {
|
|
|
726 |
$data = [
|
|
|
727 |
'success' => false,
|
|
|
728 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
729 |
];
|
|
|
730 |
|
|
|
731 |
|
|
|
732 |
}
|
|
|
733 |
|
|
|
734 |
|
|
|
735 |
return new JsonModel($data);
|
|
|
736 |
|
|
|
737 |
}
|
16248 |
efrain |
738 |
}
|