| 66 |
efrain |
1 |
<?php
|
| 649 |
geraldo |
2 |
|
| 66 |
efrain |
3 |
declare(strict_types=1);
|
|
|
4 |
|
|
|
5 |
namespace LeadersLinked\Controller;
|
|
|
6 |
|
|
|
7 |
use Laminas\Db\Adapter\AdapterInterface;
|
|
|
8 |
use Laminas\Cache\Storage\Adapter\AbstractAdapter;
|
|
|
9 |
use Laminas\Mvc\Controller\AbstractActionController;
|
|
|
10 |
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
|
|
|
11 |
use Laminas\Log\LoggerInterface;
|
|
|
12 |
use Laminas\View\Model\ViewModel;
|
|
|
13 |
use Laminas\View\Model\JsonModel;
|
|
|
14 |
use LeadersLinked\Library\Functions;
|
| 804 |
geraldo |
15 |
use LeadersLinked\Mapper\CompanyMapper;
|
| 66 |
efrain |
16 |
use LeadersLinked\Mapper\JobDescriptionMapper;
|
|
|
17 |
use LeadersLinked\Mapper\CompetencyTypeMapper;
|
|
|
18 |
use LeadersLinked\Model\JobDescription;
|
|
|
19 |
use LeadersLinked\Form\JobDescriptionForm;
|
|
|
20 |
use LeadersLinked\Mapper\CompetencyMapper;
|
| 567 |
geraldo |
21 |
use LeadersLinked\Library\JobPDF;
|
| 66 |
efrain |
22 |
use LeadersLinked\Mapper\JobDescriptionCompetencyMapper;
|
|
|
23 |
use LeadersLinked\Mapper\JobDescriptionSubordinateMapper;
|
|
|
24 |
use LeadersLinked\Model\JobDescriptionCompetency;
|
|
|
25 |
use LeadersLinked\Model\JobDescriptionSubordinate;
|
|
|
26 |
|
| 649 |
geraldo |
27 |
class JobDescriptionController extends AbstractActionController {
|
| 66 |
efrain |
28 |
|
|
|
29 |
/**
|
|
|
30 |
*
|
|
|
31 |
* @var AdapterInterface
|
|
|
32 |
*/
|
|
|
33 |
private $adapter;
|
| 649 |
geraldo |
34 |
|
| 66 |
efrain |
35 |
/**
|
|
|
36 |
*
|
|
|
37 |
* @var AbstractAdapter
|
|
|
38 |
*/
|
|
|
39 |
private $cache;
|
| 649 |
geraldo |
40 |
|
| 66 |
efrain |
41 |
/**
|
|
|
42 |
*
|
|
|
43 |
* @var LoggerInterface
|
|
|
44 |
*/
|
|
|
45 |
private $logger;
|
|
|
46 |
|
|
|
47 |
/**
|
|
|
48 |
*
|
|
|
49 |
* @var array
|
|
|
50 |
*/
|
|
|
51 |
private $config;
|
| 649 |
geraldo |
52 |
|
| 66 |
efrain |
53 |
/**
|
|
|
54 |
*
|
|
|
55 |
* @param AdapterInterface $adapter
|
|
|
56 |
* @param AbstractAdapter $cache
|
|
|
57 |
* @param LoggerInterface $logger
|
|
|
58 |
* @param array $config
|
|
|
59 |
*/
|
| 649 |
geraldo |
60 |
public function __construct($adapter, $cache, $logger, $config) {
|
|
|
61 |
$this->adapter = $adapter;
|
|
|
62 |
$this->cache = $cache;
|
|
|
63 |
$this->logger = $logger;
|
|
|
64 |
$this->config = $config;
|
| 66 |
efrain |
65 |
}
|
| 649 |
geraldo |
66 |
|
|
|
67 |
public function indexAction() {
|
| 66 |
efrain |
68 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
69 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
70 |
$currentCompany = $currentUserPlugin->getCompany();
|
| 649 |
geraldo |
71 |
|
| 66 |
efrain |
72 |
$request = $this->getRequest();
|
| 649 |
geraldo |
73 |
|
|
|
74 |
$headers = $request->getHeaders();
|
|
|
75 |
|
| 66 |
efrain |
76 |
$request = $this->getRequest();
|
| 649 |
geraldo |
77 |
if ($request->isGet()) {
|
|
|
78 |
|
|
|
79 |
|
|
|
80 |
$headers = $request->getHeaders();
|
|
|
81 |
|
| 66 |
efrain |
82 |
$isJson = false;
|
| 649 |
geraldo |
83 |
if ($headers->has('Accept')) {
|
| 66 |
efrain |
84 |
$accept = $headers->get('Accept');
|
| 649 |
geraldo |
85 |
|
| 66 |
efrain |
86 |
$prioritized = $accept->getPrioritized();
|
| 649 |
geraldo |
87 |
|
|
|
88 |
foreach ($prioritized as $key => $value) {
|
| 66 |
efrain |
89 |
$raw = trim($value->getRaw());
|
| 649 |
geraldo |
90 |
|
|
|
91 |
if (!$isJson) {
|
| 66 |
efrain |
92 |
$isJson = strpos($raw, 'json');
|
|
|
93 |
}
|
|
|
94 |
}
|
|
|
95 |
}
|
| 649 |
geraldo |
96 |
|
|
|
97 |
if ($isJson) {
|
| 66 |
efrain |
98 |
$search = $this->params()->fromQuery('search', []);
|
|
|
99 |
$search = empty($search['value']) ? '' : filter_var($search['value'], FILTER_SANITIZE_STRING);
|
| 649 |
geraldo |
100 |
|
|
|
101 |
$page = intval($this->params()->fromQuery('start', 1), 10);
|
|
|
102 |
$records_x_page = intval($this->params()->fromQuery('length', 10), 10);
|
|
|
103 |
$order = $this->params()->fromQuery('order', []);
|
|
|
104 |
$order_field = empty($order[0]['column']) ? 99 : intval($order[0]['column'], 10);
|
|
|
105 |
$order_direction = empty($order[0]['dir']) ? 'ASC' : strtoupper(filter_var($order[0]['dir'], FILTER_SANITIZE_STRING));
|
|
|
106 |
|
|
|
107 |
$fields = ['name'];
|
| 66 |
efrain |
108 |
$order_field = isset($fields[$order_field]) ? $fields[$order_field] : 'name';
|
| 649 |
geraldo |
109 |
|
|
|
110 |
if (!in_array($order_direction, ['ASC', 'DESC'])) {
|
| 66 |
efrain |
111 |
$order_direction = 'ASC';
|
|
|
112 |
}
|
| 649 |
geraldo |
113 |
|
| 66 |
efrain |
114 |
$jobDescriptionMapper = JobDescriptionMapper::getInstance($this->adapter);
|
|
|
115 |
|
| 842 |
geraldo |
116 |
if ($currentCompany) {
|
|
|
117 |
$paginator = $jobDescriptionMapper->fetchAllDataTableByCompanyId($currentCompany->id, $search, $page, $records_x_page, $order_field, $order_direction);
|
|
|
118 |
} else {
|
|
|
119 |
$paginator = $jobDescriptionMapper->fetchAllDataTable($search, $page, $records_x_page, $order_field, $order_direction);
|
| 840 |
geraldo |
120 |
}
|
| 66 |
efrain |
121 |
$items = [];
|
|
|
122 |
$records = $paginator->getCurrentItems();
|
| 649 |
geraldo |
123 |
foreach ($records as $record) {
|
|
|
124 |
|
|
|
125 |
|
|
|
126 |
|
| 66 |
efrain |
127 |
$item = [
|
|
|
128 |
'name' => $record->name,
|
|
|
129 |
'status' => $record->status,
|
|
|
130 |
'actions' => [
|
| 649 |
geraldo |
131 |
'link_report' => $this->url()->fromRoute('settings/jobs-description/report', ['id' => $record->uuid]),
|
|
|
132 |
'link_edit' => $this->url()->fromRoute('settings/jobs-description/edit', ['id' => $record->uuid]),
|
|
|
133 |
'link_delete' => $this->url()->fromRoute('settings/jobs-description/delete', ['id' => $record->uuid])
|
|
|
134 |
]
|
| 66 |
efrain |
135 |
];
|
| 649 |
geraldo |
136 |
|
| 66 |
efrain |
137 |
array_push($items, $item);
|
|
|
138 |
}
|
| 649 |
geraldo |
139 |
|
| 66 |
efrain |
140 |
return new JsonModel([
|
|
|
141 |
'success' => true,
|
|
|
142 |
'data' => [
|
|
|
143 |
'items' => $items,
|
|
|
144 |
'total' => $paginator->getTotalItemCount(),
|
|
|
145 |
]
|
|
|
146 |
]);
|
| 649 |
geraldo |
147 |
} else {
|
|
|
148 |
|
| 847 |
geraldo |
149 |
$form = new JobDescriptionForm($this->adapter, $currentCompany ? $currentCompany->id : null);
|
| 842 |
geraldo |
150 |
|
| 66 |
efrain |
151 |
$this->layout()->setTemplate('layout/layout-backend');
|
|
|
152 |
$viewModel = new ViewModel();
|
|
|
153 |
$viewModel->setTemplate('leaders-linked/jobs-description/index.phtml');
|
|
|
154 |
$viewModel->setVariable('form', $form);
|
| 649 |
geraldo |
155 |
return $viewModel;
|
|
|
156 |
}
|
| 66 |
efrain |
157 |
} else {
|
|
|
158 |
return new JsonModel([
|
|
|
159 |
'success' => false,
|
|
|
160 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
| 649 |
geraldo |
161 |
]);
|
|
|
162 |
;
|
| 66 |
efrain |
163 |
}
|
|
|
164 |
}
|
| 649 |
geraldo |
165 |
|
|
|
166 |
public function addAction() {
|
| 66 |
efrain |
167 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
168 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
169 |
$currentCompany = $currentUserPlugin->getCompany();
|
| 649 |
geraldo |
170 |
|
| 66 |
efrain |
171 |
$request = $this->getRequest();
|
| 649 |
geraldo |
172 |
|
|
|
173 |
|
|
|
174 |
if ($request->isGet()) {
|
|
|
175 |
|
| 66 |
efrain |
176 |
$data = [
|
| 649 |
geraldo |
177 |
'competency_types' => [],
|
|
|
178 |
'competencies' => [],
|
|
|
179 |
'jobs_description' => [],
|
| 66 |
efrain |
180 |
];
|
| 649 |
geraldo |
181 |
|
| 66 |
efrain |
182 |
$competencyTypeMapper = CompetencyTypeMapper::getInstance($this->adapter);
|
| 649 |
geraldo |
183 |
|
| 856 |
geraldo |
184 |
$records = $currentCompany ?
|
|
|
185 |
$competencyTypeMapper->fetchAllByCompanyId($currentCompany->id) :
|
|
|
186 |
$competencyTypeMapper->fetchAllActivesByDefault();
|
| 842 |
geraldo |
187 |
|
| 856 |
geraldo |
188 |
$competencyTypesUUID = [];
|
|
|
189 |
foreach ($records as $record) {
|
|
|
190 |
array_push($data['competency_types'], [
|
|
|
191 |
'competency_type_id' => $record->uuid,
|
|
|
192 |
'name' => $record->name,
|
|
|
193 |
]);
|
| 649 |
geraldo |
194 |
|
| 856 |
geraldo |
195 |
$competencyTypesUUID[$record->id] = $record->uuid;
|
|
|
196 |
}
|
| 66 |
efrain |
197 |
|
| 649 |
geraldo |
198 |
|
| 856 |
geraldo |
199 |
$competencyMapper = CompetencyMapper::getInstance($this->adapter);
|
| 844 |
geraldo |
200 |
|
| 856 |
geraldo |
201 |
$records = $currentCompany ?
|
|
|
202 |
$competencyMapper->fetchAllActiveByCompanyId($currentCompany->id) :
|
|
|
203 |
$competencyMapper->fetchAllByDefault();
|
| 844 |
geraldo |
204 |
|
| 856 |
geraldo |
205 |
foreach ($records as $record) {
|
|
|
206 |
if (isset($competencyTypesUUID[$record->competency_type_id])) {
|
| 649 |
geraldo |
207 |
|
| 856 |
geraldo |
208 |
array_push($data['competencies'], [
|
|
|
209 |
'competency_type_id' => $competencyTypesUUID[$record->competency_type_id],
|
|
|
210 |
'competency_id' => $record->uuid,
|
|
|
211 |
'name' => $record->name,
|
| 1101 |
geraldo |
212 |
'behaviors' =>$record->behaviors ? json_decode($record->behaviors) : []
|
| 856 |
geraldo |
213 |
]);
|
| 66 |
efrain |
214 |
}
|
| 856 |
geraldo |
215 |
}
|
| 649 |
geraldo |
216 |
|
| 856 |
geraldo |
217 |
$jobDescriptionMapper = JobDescriptionMapper::getInstance($this->adapter);
|
|
|
218 |
$records = $currentCompany ?
|
|
|
219 |
$jobDescriptionMapper->fetchAllActiveByCompanyId($currentCompany->id) :
|
|
|
220 |
$jobDescriptionMapper->fetchAllByDefault();
|
| 649 |
geraldo |
221 |
|
| 856 |
geraldo |
222 |
foreach ($records as $record) {
|
|
|
223 |
array_push($data['jobs_description'], [
|
|
|
224 |
'job_description_id' => $record->uuid,
|
|
|
225 |
'name' => $record->name
|
|
|
226 |
]);
|
| 66 |
efrain |
227 |
}
|
| 649 |
geraldo |
228 |
|
|
|
229 |
|
| 66 |
efrain |
230 |
$data = [
|
| 649 |
geraldo |
231 |
'success' => true,
|
|
|
232 |
'data' => $data,
|
| 66 |
efrain |
233 |
];
|
| 649 |
geraldo |
234 |
|
|
|
235 |
|
| 66 |
efrain |
236 |
return new JsonModel($data);
|
| 649 |
geraldo |
237 |
} else if ($request->isPost()) {
|
| 854 |
geraldo |
238 |
$form = new JobDescriptionForm($this->adapter, $currentCompany ? $currentCompany->id : null);
|
| 66 |
efrain |
239 |
$dataPost = $request->getPost()->toArray();
|
| 649 |
geraldo |
240 |
|
|
|
241 |
|
| 66 |
efrain |
242 |
$form->setData($dataPost);
|
| 649 |
geraldo |
243 |
|
|
|
244 |
if ($form->isValid()) {
|
| 66 |
efrain |
245 |
$dataPost = (array) $form->getData();
|
|
|
246 |
$dataPost['status'] = $dataPost['status'] ? $dataPost['status'] : JobDescription::STATUS_INACTIVE;
|
| 649 |
geraldo |
247 |
|
|
|
248 |
|
| 66 |
efrain |
249 |
$jobDescriptionMapper = JobDescriptionMapper::getInstance($this->adapter);
|
| 649 |
geraldo |
250 |
|
|
|
251 |
if (!empty($dataPost['job_description_id_boss'])) {
|
|
|
252 |
|
| 66 |
efrain |
253 |
$jobDescriptionBoss = $jobDescriptionMapper->fetchOneByUuid($dataPost['job_description_id_boss']);
|
| 649 |
geraldo |
254 |
if ($jobDescriptionBoss) {
|
| 847 |
geraldo |
255 |
if ($jobDescriptionBoss->company_id == $currentCompany ? $currentCompany->id : null) {
|
| 66 |
efrain |
256 |
$dataPost['job_description_id_boss'] = $jobDescriptionBoss->id;
|
|
|
257 |
} else {
|
|
|
258 |
$dataPost['job_description_id_boss'] = null;
|
|
|
259 |
}
|
|
|
260 |
} else {
|
|
|
261 |
$dataPost['job_description_id_boss'] = null;
|
|
|
262 |
}
|
|
|
263 |
}
|
|
|
264 |
|
|
|
265 |
$hydrator = new ObjectPropertyHydrator();
|
|
|
266 |
$jobDescription = new JobDescription();
|
| 649 |
geraldo |
267 |
|
| 66 |
efrain |
268 |
$hydrator->hydrate($dataPost, $jobDescription);
|
| 649 |
geraldo |
269 |
|
|
|
270 |
if ($currentCompany) {
|
| 847 |
geraldo |
271 |
$jobDescription->company_id = $currentCompany ? $currentCompany->id : null;
|
| 66 |
efrain |
272 |
}
|
|
|
273 |
|
| 649 |
geraldo |
274 |
|
| 66 |
efrain |
275 |
$jobDescriptionMapper = JobDescriptionMapper::getInstance($this->adapter);
|
|
|
276 |
$result = $jobDescriptionMapper->insert($jobDescription);
|
| 649 |
geraldo |
277 |
|
|
|
278 |
|
|
|
279 |
if ($result) {
|
| 66 |
efrain |
280 |
$jobDescriptionSubordinateMapper = JobDescriptionSubordinateMapper::getInstance($this->adapter);
|
|
|
281 |
$jobDescriptionSubordinateMapper->deleteAllByJobDescriptionIdTopLevel($jobDescription->id);
|
| 649 |
geraldo |
282 |
|
| 66 |
efrain |
283 |
$jobDescriptionCompetencyMapper = JobDescriptionCompetencyMapper::getInstance($this->adapter);
|
|
|
284 |
$jobDescriptionCompetencyMapper->deleteAllBJobDescriptionId($jobDescription->id);
|
| 649 |
geraldo |
285 |
|
|
|
286 |
|
| 66 |
efrain |
287 |
$competencyMapper = CompetencyMapper::getInstance($this->adapter);
|
| 649 |
geraldo |
288 |
|
| 858 |
geraldo |
289 |
$competencies = $currentCompany ?
|
|
|
290 |
$competencyMapper->fetchAllActiveByCompanyId($currentCompany->id) :
|
|
|
291 |
$competencyMapper->fetchAllByDefault();
|
| 649 |
geraldo |
292 |
|
| 858 |
geraldo |
293 |
|
| 649 |
geraldo |
294 |
foreach ($competencies as $competency) {
|
| 66 |
efrain |
295 |
$level = filter_var($this->params()->fromPost('competency_level' . $competency->uuid, ''), FILTER_SANITIZE_NUMBER_INT);
|
| 649 |
geraldo |
296 |
if (in_array($level, [1, 2, 3, 4])) {
|
| 66 |
efrain |
297 |
$jobDescriptionCompetency = new JobDescriptionCompetency();
|
|
|
298 |
$jobDescriptionCompetency->competency_id = $competency->id;
|
|
|
299 |
$jobDescriptionCompetency->job_description_id = $jobDescription->id;
|
|
|
300 |
$jobDescriptionCompetency->level = $level;
|
|
|
301 |
$jobDescriptionCompetencyMapper->insert($jobDescriptionCompetency);
|
|
|
302 |
}
|
|
|
303 |
}
|
| 649 |
geraldo |
304 |
|
|
|
305 |
|
| 848 |
geraldo |
306 |
$jobsDescriptionListingSubordinate = $jobDescriptionMapper->fetchAllActiveByCompanyIdWhereIdNotEqual($currentCompany ? $currentCompany->id : null, $jobDescription->id);
|
| 858 |
geraldo |
307 |
|
| 649 |
geraldo |
308 |
foreach ($jobsDescriptionListingSubordinate as $jobDescriptionListingSubordinate) {
|
| 66 |
efrain |
309 |
$job_description_subordinate = filter_var($this->params()->fromPost('job_description_id_subordinate' . $jobDescriptionListingSubordinate->uuid, ''), FILTER_SANITIZE_STRING);
|
| 649 |
geraldo |
310 |
if ($job_description_subordinate) {
|
| 66 |
efrain |
311 |
$jobDescriptionSubordinate = new JobDescriptionSubordinate();
|
|
|
312 |
$jobDescriptionSubordinate->job_description_id_top_level = $jobDescription->id;
|
|
|
313 |
$jobDescriptionSubordinate->job_description_id_low_level = $jobDescriptionListingSubordinate->id;
|
|
|
314 |
$jobDescriptionSubordinateMapper->insert($jobDescriptionSubordinate);
|
|
|
315 |
}
|
|
|
316 |
}
|
| 649 |
geraldo |
317 |
|
|
|
318 |
|
|
|
319 |
|
| 66 |
efrain |
320 |
$this->logger->info('Se agrego el cargo ' . $jobDescription->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
|
| 649 |
geraldo |
321 |
|
| 66 |
efrain |
322 |
$data = [
|
| 649 |
geraldo |
323 |
'success' => true,
|
|
|
324 |
'data' => 'LABEL_RECORD_ADDED'
|
| 66 |
efrain |
325 |
];
|
|
|
326 |
} else {
|
|
|
327 |
$data = [
|
| 649 |
geraldo |
328 |
'success' => false,
|
|
|
329 |
'data' => $jobDescriptionMapper->getError()
|
| 66 |
efrain |
330 |
];
|
|
|
331 |
}
|
| 649 |
geraldo |
332 |
|
| 66 |
efrain |
333 |
return new JsonModel($data);
|
|
|
334 |
} else {
|
|
|
335 |
$messages = [];
|
|
|
336 |
$form_messages = (array) $form->getMessages();
|
| 649 |
geraldo |
337 |
foreach ($form_messages as $fieldname => $field_messages) {
|
|
|
338 |
|
| 66 |
efrain |
339 |
$messages[$fieldname] = array_values($field_messages);
|
|
|
340 |
}
|
| 649 |
geraldo |
341 |
|
| 66 |
efrain |
342 |
return new JsonModel([
|
| 649 |
geraldo |
343 |
'success' => false,
|
|
|
344 |
'data' => $messages
|
| 66 |
efrain |
345 |
]);
|
|
|
346 |
}
|
|
|
347 |
} else {
|
|
|
348 |
$data = [
|
|
|
349 |
'success' => false,
|
|
|
350 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
351 |
];
|
| 649 |
geraldo |
352 |
|
| 66 |
efrain |
353 |
return new JsonModel($data);
|
|
|
354 |
}
|
| 649 |
geraldo |
355 |
|
| 66 |
efrain |
356 |
return new JsonModel($data);
|
|
|
357 |
}
|
| 649 |
geraldo |
358 |
|
|
|
359 |
public function editAction() {
|
| 66 |
efrain |
360 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
361 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
362 |
$currentCompany = $currentUserPlugin->getCompany();
|
| 649 |
geraldo |
363 |
|
| 66 |
efrain |
364 |
$request = $this->getRequest();
|
|
|
365 |
$uuid = $this->params()->fromRoute('id');
|
|
|
366 |
|
| 649 |
geraldo |
367 |
|
|
|
368 |
if (!$uuid) {
|
| 66 |
efrain |
369 |
$data = [
|
| 649 |
geraldo |
370 |
'success' => false,
|
|
|
371 |
'data' => 'ERROR_INVALID_PARAMETER'
|
| 66 |
efrain |
372 |
];
|
| 649 |
geraldo |
373 |
|
| 66 |
efrain |
374 |
return new JsonModel($data);
|
|
|
375 |
}
|
|
|
376 |
|
|
|
377 |
$jobDescriptionMapper = JobDescriptionMapper::getInstance($this->adapter);
|
|
|
378 |
$jobDescription = $jobDescriptionMapper->fetchOneByUuid($uuid);
|
| 649 |
geraldo |
379 |
if (!$jobDescription) {
|
| 66 |
efrain |
380 |
$data = [
|
| 649 |
geraldo |
381 |
'success' => false,
|
|
|
382 |
'data' => 'ERROR_RECORD_NOT_FOUND'
|
| 66 |
efrain |
383 |
];
|
| 649 |
geraldo |
384 |
|
| 66 |
efrain |
385 |
return new JsonModel($data);
|
|
|
386 |
}
|
| 649 |
geraldo |
387 |
|
| 851 |
geraldo |
388 |
if ($currentCompany && $jobDescription->company_id != $currentCompany->id) {
|
| 66 |
efrain |
389 |
$data = [
|
| 649 |
geraldo |
390 |
'success' => false,
|
|
|
391 |
'data' => 'ERROR_UNAUTHORIZED'
|
| 66 |
efrain |
392 |
];
|
| 649 |
geraldo |
393 |
|
| 66 |
efrain |
394 |
return new JsonModel($data);
|
|
|
395 |
}
|
|
|
396 |
|
| 649 |
geraldo |
397 |
|
|
|
398 |
if ($request->isPost()) {
|
| 847 |
geraldo |
399 |
$form = new JobDescriptionForm($this->adapter, $currentCompany ? $currentCompany->id : null, $jobDescription->id);
|
| 66 |
efrain |
400 |
$dataPost = $request->getPost()->toArray();
|
| 649 |
geraldo |
401 |
|
|
|
402 |
|
| 66 |
efrain |
403 |
$form->setData($dataPost);
|
| 649 |
geraldo |
404 |
|
|
|
405 |
if ($form->isValid()) {
|
| 66 |
efrain |
406 |
$dataPost = (array) $form->getData();
|
|
|
407 |
$dataPost['status'] = $dataPost['status'] ? $dataPost['status'] : JobDescription::STATUS_INACTIVE;
|
| 649 |
geraldo |
408 |
|
|
|
409 |
|
|
|
410 |
if (!empty($dataPost['job_description_id_boss'])) {
|
|
|
411 |
|
| 66 |
efrain |
412 |
$jobDescriptionBoss = $jobDescriptionMapper->fetchOneByUuid($dataPost['job_description_id_boss']);
|
| 649 |
geraldo |
413 |
if ($jobDescriptionBoss) {
|
|
|
414 |
if ($jobDescriptionBoss->id != $jobDescription->id && $jobDescriptionBoss->company_id == $currentCompany->id) {
|
| 66 |
efrain |
415 |
$dataPost['job_description_id_boss'] = $jobDescriptionBoss->id;
|
|
|
416 |
} else {
|
|
|
417 |
$dataPost['job_description_id_boss'] = null;
|
|
|
418 |
}
|
|
|
419 |
} else {
|
|
|
420 |
$dataPost['job_description_id_boss'] = null;
|
|
|
421 |
}
|
|
|
422 |
}
|
| 649 |
geraldo |
423 |
|
|
|
424 |
|
|
|
425 |
|
| 66 |
efrain |
426 |
$hydrator = new ObjectPropertyHydrator();
|
|
|
427 |
$hydrator->hydrate($dataPost, $jobDescription);
|
|
|
428 |
|
|
|
429 |
$result = $jobDescriptionMapper->update($jobDescription);
|
| 649 |
geraldo |
430 |
|
|
|
431 |
if ($result) {
|
|
|
432 |
|
| 66 |
efrain |
433 |
$jobDescriptionSubordinateMapper = JobDescriptionSubordinateMapper::getInstance($this->adapter);
|
|
|
434 |
$jobDescriptionSubordinateMapper->deleteAllByJobDescriptionIdTopLevel($jobDescription->id);
|
| 649 |
geraldo |
435 |
|
| 66 |
efrain |
436 |
$jobDescriptionCompetencyMapper = JobDescriptionCompetencyMapper::getInstance($this->adapter);
|
|
|
437 |
$jobDescriptionCompetencyMapper->deleteAllBJobDescriptionId($jobDescription->id);
|
| 649 |
geraldo |
438 |
|
|
|
439 |
|
| 66 |
efrain |
440 |
$competencyMapper = CompetencyMapper::getInstance($this->adapter);
|
| 649 |
geraldo |
441 |
|
| 858 |
geraldo |
442 |
$competencies = $currentCompany ?
|
|
|
443 |
$competencyMapper->fetchAllActiveByCompanyId($currentCompany->id) :
|
|
|
444 |
$competencyMapper->fetchAllByDefault();
|
| 649 |
geraldo |
445 |
|
| 858 |
geraldo |
446 |
|
| 649 |
geraldo |
447 |
foreach ($competencies as $competency) {
|
| 66 |
efrain |
448 |
$level = filter_var($this->params()->fromPost('competency_level' . $competency->uuid, ''), FILTER_SANITIZE_NUMBER_INT);
|
| 649 |
geraldo |
449 |
if (in_array($level, [1, 2, 3, 4])) {
|
| 66 |
efrain |
450 |
$jobDescriptionCompetency = new JobDescriptionCompetency();
|
|
|
451 |
$jobDescriptionCompetency->competency_id = $competency->id;
|
|
|
452 |
$jobDescriptionCompetency->job_description_id = $jobDescription->id;
|
|
|
453 |
$jobDescriptionCompetency->level = $level;
|
|
|
454 |
$jobDescriptionCompetencyMapper->insert($jobDescriptionCompetency);
|
|
|
455 |
}
|
|
|
456 |
}
|
| 649 |
geraldo |
457 |
|
|
|
458 |
|
| 847 |
geraldo |
459 |
$jobsDescriptionListingSubordinate = $jobDescriptionMapper->fetchAllActiveByCompanyIdWhereIdNotEqual($currentCompany ? $currentCompany->id : null, $jobDescription->id);
|
| 649 |
geraldo |
460 |
foreach ($jobsDescriptionListingSubordinate as $jobDescriptionListingSubordinate) {
|
| 66 |
efrain |
461 |
$job_description_subordinate = filter_var($this->params()->fromPost('job_description_id_subordinate' . $jobDescriptionListingSubordinate->uuid, ''), FILTER_SANITIZE_STRING);
|
| 649 |
geraldo |
462 |
if ($job_description_subordinate) {
|
| 66 |
efrain |
463 |
$jobDescriptionSubordinate = new JobDescriptionSubordinate();
|
|
|
464 |
$jobDescriptionSubordinate->job_description_id_top_level = $jobDescription->id;
|
|
|
465 |
$jobDescriptionSubordinate->job_description_id_low_level = $jobDescriptionListingSubordinate->id;
|
|
|
466 |
$jobDescriptionSubordinateMapper->insert($jobDescriptionSubordinate);
|
|
|
467 |
}
|
|
|
468 |
}
|
| 649 |
geraldo |
469 |
|
|
|
470 |
|
| 66 |
efrain |
471 |
$this->logger->info('Se actualizo el cargo ' . $jobDescription->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
|
| 649 |
geraldo |
472 |
|
| 66 |
efrain |
473 |
$data = [
|
|
|
474 |
'success' => true,
|
|
|
475 |
'data' => 'LABEL_RECORD_UPDATED'
|
|
|
476 |
];
|
|
|
477 |
} else {
|
|
|
478 |
$data = [
|
| 649 |
geraldo |
479 |
'success' => false,
|
|
|
480 |
'data' => $jobDescriptionMapper->getError()
|
| 66 |
efrain |
481 |
];
|
|
|
482 |
}
|
| 649 |
geraldo |
483 |
|
| 66 |
efrain |
484 |
return new JsonModel($data);
|
|
|
485 |
} else {
|
|
|
486 |
$messages = [];
|
|
|
487 |
$form_messages = (array) $form->getMessages();
|
| 649 |
geraldo |
488 |
foreach ($form_messages as $fieldname => $field_messages) {
|
| 66 |
efrain |
489 |
$messages[$fieldname] = array_values($field_messages);
|
|
|
490 |
}
|
| 649 |
geraldo |
491 |
|
| 66 |
efrain |
492 |
return new JsonModel([
|
| 649 |
geraldo |
493 |
'success' => false,
|
|
|
494 |
'data' => $messages
|
| 66 |
efrain |
495 |
]);
|
|
|
496 |
}
|
|
|
497 |
} else if ($request->isGet()) {
|
|
|
498 |
|
|
|
499 |
$hydrator = new ObjectPropertyHydrator();
|
| 649 |
geraldo |
500 |
|
| 66 |
efrain |
501 |
$data = $hydrator->extract($jobDescription);
|
| 649 |
geraldo |
502 |
|
|
|
503 |
if (!empty($data['job_description_id_boss'])) {
|
|
|
504 |
|
| 66 |
efrain |
505 |
$jobDescriptionBoss = $jobDescriptionMapper->fetchOne($data['job_description_id_boss']);
|
| 649 |
geraldo |
506 |
if ($jobDescriptionBoss) {
|
| 66 |
efrain |
507 |
$data['job_description_id_boss'] = $jobDescriptionBoss->uuid;
|
|
|
508 |
} else {
|
|
|
509 |
$data['job_description_id_boss'] = '';
|
|
|
510 |
}
|
|
|
511 |
} else {
|
|
|
512 |
$data['job_description_id_boss'] = '';
|
|
|
513 |
}
|
|
|
514 |
|
| 649 |
geraldo |
515 |
|
| 66 |
efrain |
516 |
$data['competency_types'] = [];
|
| 649 |
geraldo |
517 |
|
| 66 |
efrain |
518 |
$competencyTypeMapper = CompetencyTypeMapper::getInstance($this->adapter);
|
| 649 |
geraldo |
519 |
|
| 857 |
geraldo |
520 |
$records = $currentCompany ?
|
|
|
521 |
$competencyTypeMapper->fetchAllByCompanyId($currentCompany->id) :
|
|
|
522 |
$competencyTypeMapper->fetchAllActivesByDefault();
|
|
|
523 |
|
| 66 |
efrain |
524 |
$competencyTypesUUID = [];
|
| 649 |
geraldo |
525 |
foreach ($records as $record) {
|
| 66 |
efrain |
526 |
array_push($data['competency_types'], [
|
|
|
527 |
'competency_type_id' => $record->uuid,
|
|
|
528 |
'name' => $record->name,
|
| 1101 |
geraldo |
529 |
'behaviors' =>$record->behaviors ? json_decode($record->behaviors) : []
|
| 66 |
efrain |
530 |
]);
|
| 649 |
geraldo |
531 |
|
| 66 |
efrain |
532 |
$competencyTypesUUID[$record->id] = $record->uuid;
|
|
|
533 |
}
|
| 649 |
geraldo |
534 |
|
| 66 |
efrain |
535 |
$data['competencies'] = [];
|
| 649 |
geraldo |
536 |
|
|
|
537 |
|
| 66 |
efrain |
538 |
$jobDescriptionCompetencyMapper = JobDescriptionCompetencyMapper::getInstance($this->adapter);
|
| 649 |
geraldo |
539 |
|
| 66 |
efrain |
540 |
$competencyMapper = CompetencyMapper::getInstance($this->adapter);
|
| 649 |
geraldo |
541 |
|
| 857 |
geraldo |
542 |
$records = $currentCompany ?
|
|
|
543 |
$competencyMapper->fetchAllActiveByCompanyId($currentCompany->id) :
|
|
|
544 |
$competencyMapper->fetchAllByDefault();
|
| 649 |
geraldo |
545 |
|
|
|
546 |
foreach ($records as $record) {
|
|
|
547 |
if (isset($competencyTypesUUID[$record->competency_type_id])) {
|
|
|
548 |
|
|
|
549 |
|
| 66 |
efrain |
550 |
$level = 0;
|
|
|
551 |
$jobDescriptionCompetency = $jobDescriptionCompetencyMapper->fetchOneByJobDescriptionIdAndCompetencyId($jobDescription->id, $record->id);
|
| 649 |
geraldo |
552 |
if ($jobDescriptionCompetency) {
|
| 66 |
efrain |
553 |
$level = $jobDescriptionCompetency->level;
|
|
|
554 |
}
|
| 649 |
geraldo |
555 |
|
|
|
556 |
|
| 66 |
efrain |
557 |
array_push($data['competencies'], [
|
|
|
558 |
'competency_type_id' => $competencyTypesUUID[$record->competency_type_id],
|
|
|
559 |
'competency_id' => $record->uuid,
|
|
|
560 |
'name' => $record->name,
|
|
|
561 |
'level' => $level
|
|
|
562 |
]);
|
|
|
563 |
}
|
|
|
564 |
}
|
| 649 |
geraldo |
565 |
|
| 66 |
efrain |
566 |
$data['jobs_description'] = [];
|
| 649 |
geraldo |
567 |
|
| 66 |
efrain |
568 |
$jobsDescriptionUUID = [];
|
|
|
569 |
$jobDescriptionMapper = JobDescriptionMapper::getInstance($this->adapter);
|
| 649 |
geraldo |
570 |
|
| 857 |
geraldo |
571 |
$records = $currentCompany ?
|
|
|
572 |
$jobDescriptionMapper->fetchAllActiveByCompanyId($currentCompany->id) :
|
|
|
573 |
$jobDescriptionMapper->fetchAllByDefault();
|
|
|
574 |
|
| 649 |
geraldo |
575 |
foreach ($records as $record) {
|
|
|
576 |
if ($record->id == $jobDescription->id) {
|
| 66 |
efrain |
577 |
continue;
|
|
|
578 |
}
|
| 649 |
geraldo |
579 |
|
|
|
580 |
$jobsDescriptionUUID[$record->id] = $record->uuid;
|
|
|
581 |
|
|
|
582 |
|
| 66 |
efrain |
583 |
array_push($data['jobs_description'], [
|
|
|
584 |
'job_description_id' => $record->uuid,
|
|
|
585 |
'name' => $record->name
|
|
|
586 |
]);
|
|
|
587 |
}
|
| 649 |
geraldo |
588 |
|
| 66 |
efrain |
589 |
$data['subordinates'] = [];
|
|
|
590 |
$jobDescriptionSubordinateMapper = JobDescriptionSubordinateMapper::getInstance($this->adapter);
|
|
|
591 |
$records = $jobDescriptionSubordinateMapper->fetchAllByJobDescriptionIdTopLevel($jobDescription->id);
|
|
|
592 |
|
| 649 |
geraldo |
593 |
|
|
|
594 |
foreach ($records as $record) {
|
|
|
595 |
|
|
|
596 |
if (isset($jobsDescriptionUUID[$record->job_description_id_low_level])) {
|
|
|
597 |
|
|
|
598 |
|
| 66 |
efrain |
599 |
array_push($data['subordinates'], $jobsDescriptionUUID[$record->job_description_id_low_level]);
|
|
|
600 |
}
|
|
|
601 |
}
|
|
|
602 |
|
| 649 |
geraldo |
603 |
|
|
|
604 |
|
| 66 |
efrain |
605 |
$response = [
|
|
|
606 |
'success' => true,
|
|
|
607 |
'data' => $data
|
|
|
608 |
];
|
| 649 |
geraldo |
609 |
|
| 66 |
efrain |
610 |
return new JsonModel($response);
|
|
|
611 |
} else {
|
|
|
612 |
$data = [
|
|
|
613 |
'success' => false,
|
|
|
614 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
615 |
];
|
| 649 |
geraldo |
616 |
|
| 66 |
efrain |
617 |
return new JsonModel($data);
|
|
|
618 |
}
|
| 649 |
geraldo |
619 |
|
| 66 |
efrain |
620 |
return new JsonModel($data);
|
|
|
621 |
}
|
| 649 |
geraldo |
622 |
|
|
|
623 |
public function deleteAction() {
|
| 66 |
efrain |
624 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
625 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
626 |
$currentCompany = $currentUserPlugin->getCompany();
|
| 649 |
geraldo |
627 |
|
| 66 |
efrain |
628 |
$request = $this->getRequest();
|
|
|
629 |
$uuid = $this->params()->fromRoute('id');
|
| 649 |
geraldo |
630 |
|
|
|
631 |
if (!$uuid) {
|
| 66 |
efrain |
632 |
$data = [
|
| 649 |
geraldo |
633 |
'success' => false,
|
|
|
634 |
'data' => 'ERROR_INVALID_PARAMETER'
|
| 66 |
efrain |
635 |
];
|
| 649 |
geraldo |
636 |
|
| 66 |
efrain |
637 |
return new JsonModel($data);
|
|
|
638 |
}
|
| 649 |
geraldo |
639 |
|
|
|
640 |
|
| 66 |
efrain |
641 |
$jobDescriptionMapper = JobDescriptionMapper::getInstance($this->adapter);
|
|
|
642 |
$jobDescription = $jobDescriptionMapper->fetchOneByUuid($uuid);
|
| 649 |
geraldo |
643 |
if (!$jobDescription) {
|
| 66 |
efrain |
644 |
$data = [
|
| 649 |
geraldo |
645 |
'success' => false,
|
|
|
646 |
'data' => 'ERROR_RECORD_NOT_FOUND'
|
| 66 |
efrain |
647 |
];
|
| 649 |
geraldo |
648 |
|
| 66 |
efrain |
649 |
return new JsonModel($data);
|
|
|
650 |
}
|
| 649 |
geraldo |
651 |
|
| 851 |
geraldo |
652 |
if ($currentCompany && $jobDescription->company_id != $currentCompany->id) {
|
| 66 |
efrain |
653 |
$data = [
|
| 649 |
geraldo |
654 |
'success' => false,
|
|
|
655 |
'data' => 'ERROR_UNAUTHORIZED'
|
| 66 |
efrain |
656 |
];
|
| 649 |
geraldo |
657 |
|
| 66 |
efrain |
658 |
return new JsonModel($data);
|
|
|
659 |
}
|
|
|
660 |
|
| 649 |
geraldo |
661 |
|
|
|
662 |
if ($request->isPost()) {
|
| 66 |
efrain |
663 |
$result = $jobDescriptionMapper->delete($jobDescription);
|
| 649 |
geraldo |
664 |
if ($result) {
|
| 66 |
efrain |
665 |
$this->logger->info('Se borro el cargo de trabajo ' . $jobDescription->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
|
| 649 |
geraldo |
666 |
|
| 66 |
efrain |
667 |
$data = [
|
|
|
668 |
'success' => true,
|
|
|
669 |
'data' => 'LABEL_RECORD_DELETED'
|
|
|
670 |
];
|
|
|
671 |
} else {
|
|
|
672 |
|
|
|
673 |
$data = [
|
| 649 |
geraldo |
674 |
'success' => false,
|
|
|
675 |
'data' => $jobDescriptionMapper->getError()
|
| 66 |
efrain |
676 |
];
|
|
|
677 |
|
|
|
678 |
return new JsonModel($data);
|
|
|
679 |
}
|
|
|
680 |
} else {
|
|
|
681 |
$data = [
|
|
|
682 |
'success' => false,
|
|
|
683 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
684 |
];
|
| 649 |
geraldo |
685 |
|
| 66 |
efrain |
686 |
return new JsonModel($data);
|
|
|
687 |
}
|
| 649 |
geraldo |
688 |
|
| 66 |
efrain |
689 |
return new JsonModel($data);
|
|
|
690 |
}
|
| 561 |
geraldo |
691 |
|
| 854 |
geraldo |
692 |
public function importAction() {
|
| 850 |
geraldo |
693 |
|
| 852 |
geraldo |
694 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
695 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
696 |
$currentCompany = $currentUserPlugin->getCompany();
|
| 854 |
geraldo |
697 |
|
|
|
698 |
if (!$currentCompany) {
|
| 852 |
geraldo |
699 |
$data = [
|
|
|
700 |
'success' => false,
|
|
|
701 |
'data' => 'ERROR_UNAUTHORIZED'
|
|
|
702 |
];
|
| 854 |
geraldo |
703 |
|
| 852 |
geraldo |
704 |
return new JsonModel($data);
|
|
|
705 |
}
|
| 854 |
geraldo |
706 |
|
| 852 |
geraldo |
707 |
$request = $this->getRequest();
|
| 854 |
geraldo |
708 |
|
|
|
709 |
if ($request->isPost()) {
|
|
|
710 |
|
| 852 |
geraldo |
711 |
$jobDescriptionMapper = JobDescriptionMapper::getInstance($this->adapter);
|
|
|
712 |
$jobDescriptionsDefault = $jobDescriptionMapper->fetchAllByDefault();
|
| 854 |
geraldo |
713 |
|
| 852 |
geraldo |
714 |
$new_records = 0;
|
| 854 |
geraldo |
715 |
foreach ($jobDescriptionsDefault as $jobDescriptionDefault) {
|
|
|
716 |
if ($jobDescriptionDefault->status == JobDescription::STATUS_INACTIVE) {
|
| 852 |
geraldo |
717 |
continue;
|
|
|
718 |
}
|
| 854 |
geraldo |
719 |
|
| 852 |
geraldo |
720 |
$jobDescription = $jobDescriptionMapper->fetchOneByCompanyId($currentCompany->id, $jobDescriptionDefault->id);
|
| 854 |
geraldo |
721 |
if (!$jobDescription) {
|
|
|
722 |
|
| 852 |
geraldo |
723 |
$jobDescription = new JobDescription();
|
|
|
724 |
$jobDescription->company_id = $currentCompany->id;
|
|
|
725 |
$jobDescription->job_description_id_default = $jobDescriptionDefault->id;
|
|
|
726 |
$jobDescription->name = $jobDescriptionDefault->name;
|
|
|
727 |
$jobDescription->functions = $jobDescriptionDefault->functions;
|
|
|
728 |
$jobDescription->objectives = $jobDescriptionDefault->objectives;
|
|
|
729 |
$jobDescription->status = JobDescription::STATUS_ACTIVE;
|
| 854 |
geraldo |
730 |
|
| 858 |
geraldo |
731 |
$result = $jobDescriptionMapper->insert($jobDescription);
|
| 854 |
geraldo |
732 |
|
| 858 |
geraldo |
733 |
if ($result) {
|
|
|
734 |
|
|
|
735 |
//Add Competencies
|
| 955 |
geraldo |
736 |
$competenceMapper = CompetencyMapper::getInstance($this->adapter);
|
| 858 |
geraldo |
737 |
$jobDescriptionCompetencyMapper = JobDescriptionCompetencyMapper::getInstance($this->adapter);
|
| 953 |
geraldo |
738 |
$jobDescriptionCompetencies = $jobDescriptionCompetencyMapper->fetchByJobDescriptionId($jobDescriptionDefault->id);
|
| 939 |
geraldo |
739 |
|
| 953 |
geraldo |
740 |
if (count($jobDescriptionCompetencies) != 0) {
|
|
|
741 |
foreach ($jobDescriptionCompetencies as $record) {
|
| 955 |
geraldo |
742 |
|
|
|
743 |
$competence = $competenceMapper->fetchOneByCompanyIdAndCompetencyIdDefault($currentCompany->id, $record->competency_id);
|
| 956 |
geraldo |
744 |
if ($competence) {
|
|
|
745 |
$newDescriptionCompetency = new JobDescriptionCompetency();
|
|
|
746 |
$newDescriptionCompetency->competency_id = $competence->id;
|
|
|
747 |
$newDescriptionCompetency->job_description_id = $jobDescription->id;
|
|
|
748 |
$newDescriptionCompetency->level = $record->level;
|
|
|
749 |
$jobDescriptionCompetencyMapper->insert($newDescriptionCompetency);
|
| 955 |
geraldo |
750 |
}
|
| 858 |
geraldo |
751 |
}
|
|
|
752 |
}
|
|
|
753 |
|
| 852 |
geraldo |
754 |
$new_records++;
|
|
|
755 |
} else {
|
|
|
756 |
$data = [
|
|
|
757 |
'success' => false,
|
|
|
758 |
'data' => 'ERROR_CANT_ADD_JOB_DESCRIPTION'
|
|
|
759 |
];
|
| 854 |
geraldo |
760 |
|
| 852 |
geraldo |
761 |
return new JsonModel($data);
|
|
|
762 |
}
|
|
|
763 |
}
|
|
|
764 |
}
|
| 854 |
geraldo |
765 |
|
|
|
766 |
if ($new_records) {
|
|
|
767 |
|
|
|
768 |
if (1 == $new_records) {
|
| 852 |
geraldo |
769 |
$data = [
|
|
|
770 |
'success' => true,
|
|
|
771 |
'data' => 'LABEL_1_JOB_DESCRIPTION_IMPORTED'
|
|
|
772 |
];
|
| 854 |
geraldo |
773 |
|
| 852 |
geraldo |
774 |
return new JsonModel($data);
|
|
|
775 |
} else {
|
|
|
776 |
$data = [
|
|
|
777 |
'success' => true,
|
| 854 |
geraldo |
778 |
'data' => $new_records . ' LABEL_MULTI_JOB_DESCRIPTION_IMPORTED'
|
| 852 |
geraldo |
779 |
];
|
| 854 |
geraldo |
780 |
|
| 852 |
geraldo |
781 |
return new JsonModel($data);
|
|
|
782 |
}
|
|
|
783 |
} else {
|
|
|
784 |
$data = [
|
|
|
785 |
'success' => true,
|
|
|
786 |
'data' => 'LABEL_NO_JOB_DESCRIPTION_IMPORTED'
|
|
|
787 |
];
|
| 854 |
geraldo |
788 |
|
| 852 |
geraldo |
789 |
return new JsonModel($data);
|
|
|
790 |
}
|
|
|
791 |
} else {
|
|
|
792 |
$data = [
|
|
|
793 |
'success' => false,
|
|
|
794 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
795 |
];
|
| 854 |
geraldo |
796 |
|
| 852 |
geraldo |
797 |
return new JsonModel($data);
|
|
|
798 |
}
|
| 854 |
geraldo |
799 |
|
| 852 |
geraldo |
800 |
return new JsonModel($data);
|
| 850 |
geraldo |
801 |
}
|
|
|
802 |
|
| 649 |
geraldo |
803 |
public function reportAction() {
|
| 561 |
geraldo |
804 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
805 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
806 |
$currentCompany = $currentUserPlugin->getCompany();
|
| 649 |
geraldo |
807 |
|
| 561 |
geraldo |
808 |
$request = $this->getRequest();
|
|
|
809 |
$uuid = $this->params()->fromRoute('id');
|
|
|
810 |
|
| 649 |
geraldo |
811 |
|
|
|
812 |
if (!$uuid) {
|
| 561 |
geraldo |
813 |
$data = [
|
| 649 |
geraldo |
814 |
'success' => false,
|
|
|
815 |
'data' => 'ERROR_INVALID_PARAMETER'
|
| 561 |
geraldo |
816 |
];
|
| 649 |
geraldo |
817 |
|
| 561 |
geraldo |
818 |
return new JsonModel($data);
|
|
|
819 |
}
|
|
|
820 |
|
|
|
821 |
$jobDescriptionMapper = JobDescriptionMapper::getInstance($this->adapter);
|
|
|
822 |
$jobDescription = $jobDescriptionMapper->fetchOneByUuid($uuid);
|
| 649 |
geraldo |
823 |
if (!$jobDescription) {
|
| 561 |
geraldo |
824 |
$data = [
|
| 649 |
geraldo |
825 |
'success' => false,
|
|
|
826 |
'data' => 'ERROR_RECORD_NOT_FOUND'
|
| 561 |
geraldo |
827 |
];
|
| 649 |
geraldo |
828 |
|
| 561 |
geraldo |
829 |
return new JsonModel($data);
|
|
|
830 |
}
|
| 649 |
geraldo |
831 |
|
| 851 |
geraldo |
832 |
if ($currentCompany && $jobDescription->company_id != $currentCompany->id) {
|
| 561 |
geraldo |
833 |
$data = [
|
| 649 |
geraldo |
834 |
'success' => false,
|
|
|
835 |
'data' => 'ERROR_UNAUTHORIZED'
|
| 561 |
geraldo |
836 |
];
|
| 649 |
geraldo |
837 |
|
| 561 |
geraldo |
838 |
return new JsonModel($data);
|
|
|
839 |
}
|
|
|
840 |
|
| 649 |
geraldo |
841 |
|
| 561 |
geraldo |
842 |
if ($request->isGet()) {
|
|
|
843 |
|
| 842 |
geraldo |
844 |
return $this->renderPdf($currentCompany, $jobDescription);
|
| 561 |
geraldo |
845 |
} else {
|
|
|
846 |
$data = [
|
|
|
847 |
'success' => false,
|
|
|
848 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
849 |
];
|
| 649 |
geraldo |
850 |
|
| 561 |
geraldo |
851 |
return new JsonModel($data);
|
|
|
852 |
}
|
| 649 |
geraldo |
853 |
|
| 561 |
geraldo |
854 |
return new JsonModel($data);
|
|
|
855 |
}
|
| 842 |
geraldo |
856 |
|
| 788 |
geraldo |
857 |
/**
|
|
|
858 |
* Render PDF
|
|
|
859 |
* @param type $currentCompany
|
|
|
860 |
* @param type $jobDescription
|
|
|
861 |
* @return type
|
|
|
862 |
*/
|
| 789 |
geraldo |
863 |
public function renderPDF($currentCompany, $jobDescription) {
|
| 561 |
geraldo |
864 |
|
|
|
865 |
//Generate New PDF
|
| 789 |
geraldo |
866 |
$pdf = new JobPDF();
|
| 842 |
geraldo |
867 |
|
| 854 |
geraldo |
868 |
$pdf->header = '';
|
|
|
869 |
$pdf->footer = '';
|
| 849 |
geraldo |
870 |
|
| 842 |
geraldo |
871 |
|
| 854 |
geraldo |
872 |
if ($currentCompany) {
|
|
|
873 |
//get company Data
|
|
|
874 |
$companyMapper = CompanyMapper::getInstance($this->adapter);
|
|
|
875 |
$company = $companyMapper->fetchOne($currentCompany->id);
|
| 561 |
geraldo |
876 |
|
| 854 |
geraldo |
877 |
$target_path = $this->config['leaderslinked.fullpath.company'] . DIRECTORY_SEPARATOR . $company->uuid;
|
| 842 |
geraldo |
878 |
|
| 854 |
geraldo |
879 |
$pdf->header = $company->header ? $target_path . DIRECTORY_SEPARATOR . $company->header : '';
|
|
|
880 |
$pdf->footer = $company->footer ? $target_path . DIRECTORY_SEPARATOR . $company->footer : '';
|
| 847 |
geraldo |
881 |
}
|
| 848 |
geraldo |
882 |
|
| 927 |
geraldo |
883 |
$pdf->SetMargins(10, 0, 10);
|
| 714 |
geraldo |
884 |
|
| 561 |
geraldo |
885 |
$pdf->AliasNbPages();
|
|
|
886 |
$pdf->AddPage();
|
| 564 |
geraldo |
887 |
|
| 697 |
geraldo |
888 |
// Add Title
|
|
|
889 |
$pdf->customHeader();
|
| 654 |
geraldo |
890 |
|
| 649 |
geraldo |
891 |
// Job Description Name
|
| 654 |
geraldo |
892 |
|
| 649 |
geraldo |
893 |
$job_descrition[] = array(
|
| 654 |
geraldo |
894 |
'title' => 'Categoría Laboral:',
|
| 709 |
geraldo |
895 |
'content' => ' ' . $jobDescription->name
|
| 649 |
geraldo |
896 |
);
|
| 654 |
geraldo |
897 |
|
| 764 |
geraldo |
898 |
$pdf->borderTable('Nombre del cargo de trabajo:', $job_descrition);
|
| 649 |
geraldo |
899 |
|
|
|
900 |
|
| 654 |
geraldo |
901 |
//Hierarchical Relationship
|
|
|
902 |
|
| 650 |
geraldo |
903 |
$jobDescriptionMapper = JobDescriptionMapper::getInstance($this->adapter);
|
| 714 |
geraldo |
904 |
|
|
|
905 |
$jobDescriptionSubordinateMapper = JobDescriptionSubordinateMapper::getInstance($this->adapter);
|
| 724 |
geraldo |
906 |
$jobDescriptionSubordinate = $jobDescriptionSubordinateMapper->fetchAllByJobDescriptionIdTopLevel($jobDescription->id);
|
| 714 |
geraldo |
907 |
|
|
|
908 |
$subordinate = '';
|
| 745 |
geraldo |
909 |
|
|
|
910 |
if ($jobDescriptionSubordinate) {
|
|
|
911 |
|
|
|
912 |
foreach ($jobDescriptionSubordinate as $rs) {
|
| 725 |
geraldo |
913 |
$jobSubordinate = $jobDescriptionMapper->fetchOne($rs->job_description_id_low_level);
|
| 745 |
geraldo |
914 |
if ($jobSubordinate) {
|
|
|
915 |
$subordinate .= $jobSubordinate->name . ' ';
|
|
|
916 |
}
|
| 717 |
geraldo |
917 |
}
|
|
|
918 |
}
|
| 714 |
geraldo |
919 |
|
| 649 |
geraldo |
920 |
$jobDescriptionBoss = $jobDescriptionMapper->fetchOne($jobDescription->job_description_id_boss);
|
|
|
921 |
|
| 654 |
geraldo |
922 |
$relationship = [
|
| 614 |
geraldo |
923 |
array(
|
| 714 |
geraldo |
924 |
'title' => 'Depende de: ',
|
| 726 |
geraldo |
925 |
'content' => $subordinate ? ' ' . $subordinate : ' No aplica'
|
| 649 |
geraldo |
926 |
),
|
|
|
927 |
array(
|
|
|
928 |
'title' => 'Supervisa a: ',
|
| 709 |
geraldo |
929 |
'content' => $jobDescriptionBoss ? ' ' . $jobDescriptionBoss->name : ' No aplica'
|
| 649 |
geraldo |
930 |
)
|
| 654 |
geraldo |
931 |
];
|
| 579 |
geraldo |
932 |
|
| 701 |
geraldo |
933 |
$pdf->borderTable('Relación jerárquica:', $relationship);
|
| 628 |
geraldo |
934 |
|
| 654 |
geraldo |
935 |
// Objetives
|
| 628 |
geraldo |
936 |
|
| 654 |
geraldo |
937 |
$objetives[] = array('content' => strip_tags($jobDescription->objectives));
|
| 708 |
geraldo |
938 |
$pdf->borderTable('Objetivos:', $objetives);
|
| 653 |
geraldo |
939 |
|
| 654 |
geraldo |
940 |
// Functions
|
| 628 |
geraldo |
941 |
|
| 654 |
geraldo |
942 |
$functions[] = array('content' => strip_tags($jobDescription->functions));
|
| 708 |
geraldo |
943 |
$pdf->borderTable('Funciones principales:', $functions);
|
| 628 |
geraldo |
944 |
|
| 749 |
geraldo |
945 |
// add section signature
|
| 709 |
geraldo |
946 |
$pdf->sectionSignature();
|
|
|
947 |
|
| 654 |
geraldo |
948 |
//Competencies
|
| 628 |
geraldo |
949 |
|
| 658 |
geraldo |
950 |
$jobDescriptionCompetencyMapper = JobDescriptionCompetencyMapper::getInstance($this->adapter);
|
| 667 |
geraldo |
951 |
$jobDescriptionCompetency = $jobDescriptionCompetencyMapper->fetchByJobDescriptionId($jobDescription->id);
|
| 649 |
geraldo |
952 |
|
| 672 |
geraldo |
953 |
$competencyMapper = CompetencyMapper::getInstance($this->adapter);
|
| 933 |
geraldo |
954 |
$competenceTypeMapper = CompetencyTypeMapper::getInstance($this->adapter);
|
| 842 |
geraldo |
955 |
|
| 939 |
geraldo |
956 |
|
| 751 |
geraldo |
957 |
$countCompetencies = count($jobDescriptionCompetency);
|
| 672 |
geraldo |
958 |
|
| 751 |
geraldo |
959 |
if ($countCompetencies != 0) {
|
| 842 |
geraldo |
960 |
|
| 748 |
geraldo |
961 |
// add new page
|
| 842 |
geraldo |
962 |
|
| 748 |
geraldo |
963 |
$pdf->AddPage();
|
| 679 |
geraldo |
964 |
|
| 745 |
geraldo |
965 |
$competencies_header[] = array('content' => 'De acuerdo a la siguiente escala, se deberá asignar un valor a cada conducta deseable correspondiente a cada una de las competencias requeridas para el cargo. La valoración refiere a las conductas deseables requeridas en cada cargo, y no refiere a la persona que lo ocupa');
|
| 679 |
geraldo |
966 |
|
| 745 |
geraldo |
967 |
$pdf->singleTable('Competencias requeridas para el cargo:', $competencies_header);
|
| 709 |
geraldo |
968 |
|
| 745 |
geraldo |
969 |
|
|
|
970 |
// Add scale section
|
|
|
971 |
$pdf->sectionScale();
|
|
|
972 |
|
|
|
973 |
$i = 0;
|
|
|
974 |
foreach ($jobDescriptionCompetency as $record) {
|
|
|
975 |
|
|
|
976 |
$i = $i + 1;
|
|
|
977 |
|
|
|
978 |
$competency = $competencyMapper->fetchOne($record->competency_id);
|
| 933 |
geraldo |
979 |
$competenceType = $competenceTypeMapper->fetchOne($competency->competency_type_id);
|
| 745 |
geraldo |
980 |
|
| 933 |
geraldo |
981 |
$pdf->competencyTable($i, $competenceType, $competency);
|
|
|
982 |
|
| 923 |
geraldo |
983 |
if ($i % 3 == 0 && $i < $countCompetencies) {
|
| 745 |
geraldo |
984 |
$pdf->AddPage();
|
|
|
985 |
}
|
| 709 |
geraldo |
986 |
}
|
| 669 |
geraldo |
987 |
}
|
| 658 |
geraldo |
988 |
|
|
|
989 |
|
| 561 |
geraldo |
990 |
return $pdf->Output();
|
|
|
991 |
}
|
| 649 |
geraldo |
992 |
|
| 66 |
efrain |
993 |
}
|