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