| 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;
|
| 16768 |
efrain |
8 |
|
| 66 |
efrain |
9 |
use Laminas\Mvc\Controller\AbstractActionController;
|
| 15403 |
efrain |
10 |
|
| 66 |
efrain |
11 |
use Laminas\Log\LoggerInterface;
|
|
|
12 |
use Laminas\View\Model\ViewModel;
|
|
|
13 |
use Laminas\View\Model\JsonModel;
|
| 15403 |
efrain |
14 |
|
|
|
15 |
|
|
|
16 |
use LeadersLinked\Form\JobDescription\JobDescriptionForm;
|
|
|
17 |
|
|
|
18 |
|
|
|
19 |
|
|
|
20 |
|
|
|
21 |
use LeadersLinked\Model\Company;
|
| 66 |
efrain |
22 |
use LeadersLinked\Model\JobDescription;
|
|
|
23 |
use LeadersLinked\Model\JobDescriptionCompetency;
|
| 15403 |
efrain |
24 |
use LeadersLinked\Model\JobDescriptionCompetencyBehavior;
|
| 66 |
efrain |
25 |
use LeadersLinked\Model\JobDescriptionSubordinate;
|
| 15403 |
efrain |
26 |
|
| 1320 |
efrain |
27 |
use LeadersLinked\Mapper\BehaviorMapper;
|
| 15403 |
efrain |
28 |
use LeadersLinked\Mapper\CompetencyMapper;
|
| 15030 |
efrain |
29 |
use LeadersLinked\Mapper\CompetencyBehaviorMapper;
|
| 15403 |
efrain |
30 |
use LeadersLinked\Mapper\CompetencyTypeMapper;
|
| 66 |
efrain |
31 |
|
| 15403 |
efrain |
32 |
use LeadersLinked\Mapper\JobDescriptionMapper;
|
|
|
33 |
use LeadersLinked\Mapper\JobDescriptionCompetencyBehaviorMapper;
|
|
|
34 |
use LeadersLinked\Mapper\JobDescriptionCompetencyMapper;
|
|
|
35 |
use LeadersLinked\Mapper\JobDescriptionSubordinateMapper;
|
| 1320 |
efrain |
36 |
|
| 15403 |
efrain |
37 |
use LeadersLinked\Library\Functions;
|
|
|
38 |
use LeadersLinked\Library\JobDescriptionPdf;
|
|
|
39 |
|
|
|
40 |
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
|
|
|
41 |
use Laminas\Mvc\I18n\Translator;
|
|
|
42 |
|
| 16766 |
efrain |
43 |
|
| 14203 |
stevensc |
44 |
class JobDescriptionController extends AbstractActionController
|
|
|
45 |
{
|
| 66 |
efrain |
46 |
/**
|
|
|
47 |
*
|
| 16769 |
efrain |
48 |
* @var \Laminas\Db\Adapter\AdapterInterface
|
| 66 |
efrain |
49 |
*/
|
|
|
50 |
private $adapter;
|
| 16769 |
efrain |
51 |
|
| 66 |
efrain |
52 |
/**
|
|
|
53 |
*
|
| 16769 |
efrain |
54 |
* @var \LeadersLinked\Cache\CacheInterface
|
| 66 |
efrain |
55 |
*/
|
| 16769 |
efrain |
56 |
private $cache;
|
|
|
57 |
|
|
|
58 |
|
|
|
59 |
/**
|
|
|
60 |
*
|
|
|
61 |
* @var \Laminas\Log\LoggerInterface
|
|
|
62 |
*/
|
| 66 |
efrain |
63 |
private $logger;
|
| 16769 |
efrain |
64 |
|
| 66 |
efrain |
65 |
/**
|
|
|
66 |
*
|
|
|
67 |
* @var array
|
|
|
68 |
*/
|
|
|
69 |
private $config;
|
| 15403 |
efrain |
70 |
|
| 16769 |
efrain |
71 |
|
| 15403 |
efrain |
72 |
/**
|
| 16769 |
efrain |
73 |
*
|
|
|
74 |
* @var \Laminas\Mvc\I18n\Translator
|
| 15403 |
efrain |
75 |
*/
|
|
|
76 |
private $translator;
|
| 16769 |
efrain |
77 |
|
|
|
78 |
|
| 66 |
efrain |
79 |
/**
|
|
|
80 |
*
|
| 16769 |
efrain |
81 |
* @param \Laminas\Db\Adapter\AdapterInterface $adapter
|
|
|
82 |
* @param \LeadersLinked\Cache\CacheInterface $cache
|
|
|
83 |
* @param \Laminas\Log\LoggerInterface LoggerInterface $logger
|
| 66 |
efrain |
84 |
* @param array $config
|
| 16769 |
efrain |
85 |
* @param \Laminas\Mvc\I18n\Translator $translator
|
| 66 |
efrain |
86 |
*/
|
| 16769 |
efrain |
87 |
public function __construct($adapter, $cache, $logger, $config, $translator)
|
| 14203 |
stevensc |
88 |
{
|
| 16769 |
efrain |
89 |
$this->adapter = $adapter;
|
|
|
90 |
$this->cache = $cache;
|
|
|
91 |
$this->logger = $logger;
|
|
|
92 |
$this->config = $config;
|
|
|
93 |
$this->translator = $translator;
|
| 66 |
efrain |
94 |
}
|
| 649 |
geraldo |
95 |
|
| 14203 |
stevensc |
96 |
public function indexAction()
|
|
|
97 |
{
|
| 66 |
efrain |
98 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
99 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
100 |
$currentCompany = $currentUserPlugin->getCompany();
|
| 649 |
geraldo |
101 |
|
| 66 |
efrain |
102 |
$request = $this->getRequest();
|
| 649 |
geraldo |
103 |
|
|
|
104 |
$headers = $request->getHeaders();
|
|
|
105 |
|
| 66 |
efrain |
106 |
$request = $this->getRequest();
|
| 649 |
geraldo |
107 |
if ($request->isGet()) {
|
|
|
108 |
|
|
|
109 |
|
|
|
110 |
$headers = $request->getHeaders();
|
|
|
111 |
|
| 66 |
efrain |
112 |
$isJson = false;
|
| 649 |
geraldo |
113 |
if ($headers->has('Accept')) {
|
| 66 |
efrain |
114 |
$accept = $headers->get('Accept');
|
| 649 |
geraldo |
115 |
|
| 66 |
efrain |
116 |
$prioritized = $accept->getPrioritized();
|
| 649 |
geraldo |
117 |
|
|
|
118 |
foreach ($prioritized as $key => $value) {
|
| 66 |
efrain |
119 |
$raw = trim($value->getRaw());
|
| 649 |
geraldo |
120 |
|
|
|
121 |
if (!$isJson) {
|
| 66 |
efrain |
122 |
$isJson = strpos($raw, 'json');
|
|
|
123 |
}
|
|
|
124 |
}
|
|
|
125 |
}
|
| 649 |
geraldo |
126 |
|
|
|
127 |
if ($isJson) {
|
| 14203 |
stevensc |
128 |
$search = $this->params()->fromQuery('search');
|
| 16768 |
efrain |
129 |
$search = empty($search['value']) ? '' : Functions::sanitizeFilterString($search['value']);
|
| 649 |
geraldo |
130 |
|
| 15371 |
efrain |
131 |
$start = intval($this->params()->fromQuery('start', 0), 10);
|
| 649 |
geraldo |
132 |
$records_x_page = intval($this->params()->fromQuery('length', 10), 10);
|
| 15371 |
efrain |
133 |
$page = intval($start / $records_x_page);
|
|
|
134 |
$page++;
|
|
|
135 |
|
| 649 |
geraldo |
136 |
$order = $this->params()->fromQuery('order', []);
|
|
|
137 |
$order_field = empty($order[0]['column']) ? 99 : intval($order[0]['column'], 10);
|
| 16766 |
efrain |
138 |
$order_direction = empty($order[0]['dir']) ? 'ASC' : Functions::sanitizeFilterString(filter_var($order[0]['dir']));
|
| 649 |
geraldo |
139 |
|
|
|
140 |
$fields = ['name'];
|
| 66 |
efrain |
141 |
$order_field = isset($fields[$order_field]) ? $fields[$order_field] : 'name';
|
| 649 |
geraldo |
142 |
|
|
|
143 |
if (!in_array($order_direction, ['ASC', 'DESC'])) {
|
| 66 |
efrain |
144 |
$order_direction = 'ASC';
|
|
|
145 |
}
|
| 649 |
geraldo |
146 |
|
| 66 |
efrain |
147 |
$jobDescriptionMapper = JobDescriptionMapper::getInstance($this->adapter);
|
|
|
148 |
|
| 842 |
geraldo |
149 |
if ($currentCompany) {
|
|
|
150 |
$paginator = $jobDescriptionMapper->fetchAllDataTableByCompanyId($currentCompany->id, $search, $page, $records_x_page, $order_field, $order_direction);
|
|
|
151 |
} else {
|
|
|
152 |
$paginator = $jobDescriptionMapper->fetchAllDataTable($search, $page, $records_x_page, $order_field, $order_direction);
|
| 840 |
geraldo |
153 |
}
|
| 66 |
efrain |
154 |
$items = [];
|
|
|
155 |
$records = $paginator->getCurrentItems();
|
| 649 |
geraldo |
156 |
foreach ($records as $record) {
|
|
|
157 |
|
| 66 |
efrain |
158 |
$item = [
|
|
|
159 |
'name' => $record->name,
|
|
|
160 |
'status' => $record->status,
|
|
|
161 |
'actions' => [
|
| 15444 |
efrain |
162 |
'link_report' => $this->url()->fromRoute('jobs-description/report', ['id' => $record->uuid]),
|
|
|
163 |
'link_edit' => $this->url()->fromRoute('jobs-description/edit', ['id' => $record->uuid]),
|
|
|
164 |
'link_delete' => $this->url()->fromRoute('jobs-description/delete', ['id' => $record->uuid])
|
| 649 |
geraldo |
165 |
]
|
| 66 |
efrain |
166 |
];
|
| 649 |
geraldo |
167 |
|
| 66 |
efrain |
168 |
array_push($items, $item);
|
|
|
169 |
}
|
| 649 |
geraldo |
170 |
|
| 66 |
efrain |
171 |
return new JsonModel([
|
|
|
172 |
'success' => true,
|
|
|
173 |
'data' => [
|
|
|
174 |
'items' => $items,
|
|
|
175 |
'total' => $paginator->getTotalItemCount(),
|
|
|
176 |
]
|
|
|
177 |
]);
|
| 649 |
geraldo |
178 |
} else {
|
| 15403 |
efrain |
179 |
|
|
|
180 |
|
|
|
181 |
|
| 649 |
geraldo |
182 |
|
| 847 |
geraldo |
183 |
$form = new JobDescriptionForm($this->adapter, $currentCompany ? $currentCompany->id : null);
|
| 842 |
geraldo |
184 |
|
| 66 |
efrain |
185 |
$this->layout()->setTemplate('layout/layout-backend');
|
|
|
186 |
$viewModel = new ViewModel();
|
|
|
187 |
$viewModel->setTemplate('leaders-linked/jobs-description/index.phtml');
|
| 15403 |
efrain |
188 |
$viewModel->setVariables([
|
|
|
189 |
'form' => $form,
|
| 15444 |
efrain |
190 |
|
| 15403 |
efrain |
191 |
|
|
|
192 |
]);
|
| 649 |
geraldo |
193 |
return $viewModel;
|
|
|
194 |
}
|
| 66 |
efrain |
195 |
} else {
|
|
|
196 |
return new JsonModel([
|
|
|
197 |
'success' => false,
|
|
|
198 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
| 14203 |
stevensc |
199 |
]);;
|
| 66 |
efrain |
200 |
}
|
|
|
201 |
}
|
| 649 |
geraldo |
202 |
|
| 14203 |
stevensc |
203 |
public function addAction()
|
|
|
204 |
{
|
| 66 |
efrain |
205 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
206 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
207 |
$currentCompany = $currentUserPlugin->getCompany();
|
| 649 |
geraldo |
208 |
|
| 66 |
efrain |
209 |
$request = $this->getRequest();
|
| 649 |
geraldo |
210 |
|
|
|
211 |
|
|
|
212 |
if ($request->isGet()) {
|
| 15444 |
efrain |
213 |
$behaviors = [];
|
|
|
214 |
$behaviorMapper = BehaviorMapper::getInstance($this->adapter);
|
| 15403 |
efrain |
215 |
|
| 15444 |
efrain |
216 |
|
|
|
217 |
if($currentCompany) {
|
|
|
218 |
$records = $behaviorMapper->fetchAllActiveByCompanyId($currentCompany->id);
|
|
|
219 |
} else {
|
|
|
220 |
$records = $behaviorMapper->fetchAllActiveByDefault();
|
|
|
221 |
}
|
|
|
222 |
|
|
|
223 |
$behaviorIds = [];
|
|
|
224 |
foreach($records as $record)
|
|
|
225 |
{
|
|
|
226 |
|
|
|
227 |
$behaviorIds[ $record->id ] = $record->uuid;
|
|
|
228 |
|
|
|
229 |
array_push($behaviors, [
|
|
|
230 |
'uuid' => $record->uuid,
|
|
|
231 |
'description' => $record->description
|
|
|
232 |
]);
|
|
|
233 |
}
|
|
|
234 |
|
|
|
235 |
|
|
|
236 |
$competencyTypes = [];
|
|
|
237 |
|
|
|
238 |
|
|
|
239 |
$competencyTypeMapper = CompetencyTypeMapper::getInstance($this->adapter);
|
|
|
240 |
|
|
|
241 |
if($currentCompany) {
|
|
|
242 |
$records = $competencyTypeMapper->fetchAllActiveByCompanyId($currentCompany->id);
|
|
|
243 |
} else {
|
|
|
244 |
$records = $competencyTypeMapper->fetchAllActiveByDefault();
|
|
|
245 |
}
|
|
|
246 |
|
|
|
247 |
|
|
|
248 |
$competencyTypeIds = [];
|
|
|
249 |
foreach($records as $record)
|
|
|
250 |
{
|
|
|
251 |
$competencyTypeIds[ $record->id ] = $record->uuid;
|
|
|
252 |
|
|
|
253 |
|
|
|
254 |
array_push($competencyTypes, [
|
|
|
255 |
'uuid' => $record->uuid,
|
|
|
256 |
'name' => $record->name,
|
|
|
257 |
]);
|
|
|
258 |
}
|
|
|
259 |
|
|
|
260 |
$competencyMapper = CompetencyMapper::getInstance($this->adapter);
|
|
|
261 |
if($currentCompany) {
|
|
|
262 |
$records = $competencyMapper->fetchAllActiveByCompanyId($currentCompany->id);
|
|
|
263 |
} else {
|
|
|
264 |
$records = $competencyMapper->fetchAllActiveByDefault();
|
|
|
265 |
}
|
|
|
266 |
|
|
|
267 |
$competencyBehaviorMapper = CompetencyBehaviorMapper::getInstance($this->adapter);
|
|
|
268 |
|
|
|
269 |
|
|
|
270 |
|
|
|
271 |
$competencies = [];
|
|
|
272 |
|
|
|
273 |
foreach($records as $record)
|
|
|
274 |
{
|
|
|
275 |
if(!isset($competencyTypeIds[ $record->competency_type_id ])) {
|
|
|
276 |
continue;
|
|
|
277 |
}
|
|
|
278 |
|
|
|
279 |
$behaviors_by_competency = [];
|
|
|
280 |
|
|
|
281 |
$competencyBehaviors = $competencyBehaviorMapper->fetchAllByCompetencyId($record->id);
|
|
|
282 |
foreach($competencyBehaviors as $competencyBehavior)
|
|
|
283 |
{
|
|
|
284 |
if(!isset($behaviorIds[ $competencyBehavior->behavior_id ])) {
|
|
|
285 |
continue;
|
|
|
286 |
}
|
|
|
287 |
|
|
|
288 |
array_push($behaviors_by_competency, $behaviorIds[ $competencyBehavior->behavior_id ]);
|
|
|
289 |
}
|
|
|
290 |
|
|
|
291 |
|
|
|
292 |
if($behaviors_by_competency) {
|
|
|
293 |
array_push($competencies, [
|
|
|
294 |
'competency_type_uuid' => $competencyTypeIds[ $record->competency_type_id ],
|
|
|
295 |
'uuid' => $record->uuid,
|
|
|
296 |
'name' => $record->name,
|
|
|
297 |
'behaviors' => $behaviors_by_competency,
|
|
|
298 |
]);
|
|
|
299 |
}
|
|
|
300 |
|
|
|
301 |
|
|
|
302 |
}
|
|
|
303 |
|
|
|
304 |
|
|
|
305 |
|
| 649 |
geraldo |
306 |
|
|
|
307 |
|
| 15403 |
efrain |
308 |
$jobDescriptionMapper = JobDescriptionMapper::getInstance($this->adapter);
|
|
|
309 |
if($currentCompany) {
|
|
|
310 |
$records = $jobDescriptionMapper->fetchAllActiveByCompanyId($currentCompany->id);
|
|
|
311 |
} else {
|
|
|
312 |
$jobDescriptionMapper->fetchAllActiveByDefault();
|
| 856 |
geraldo |
313 |
}
|
| 15403 |
efrain |
314 |
|
|
|
315 |
$jobsDescription = [];
|
|
|
316 |
|
|
|
317 |
foreach ($records as $record)
|
|
|
318 |
{
|
|
|
319 |
$jobsDescription[ $record->uuid ] = $record->name;
|
| 856 |
geraldo |
320 |
}
|
| 649 |
geraldo |
321 |
|
|
|
322 |
|
| 66 |
efrain |
323 |
$data = [
|
| 649 |
geraldo |
324 |
'success' => true,
|
| 15403 |
efrain |
325 |
'data' => [
|
|
|
326 |
'jobs_description' => $jobsDescription,
|
| 15444 |
efrain |
327 |
'behaviors' => $behaviors,
|
|
|
328 |
'competency_types' => $competencyTypes,
|
|
|
329 |
'competencies' => $competencies,
|
| 15403 |
efrain |
330 |
]
|
| 66 |
efrain |
331 |
];
|
| 649 |
geraldo |
332 |
|
|
|
333 |
|
| 66 |
efrain |
334 |
return new JsonModel($data);
|
| 649 |
geraldo |
335 |
} else if ($request->isPost()) {
|
| 854 |
geraldo |
336 |
$form = new JobDescriptionForm($this->adapter, $currentCompany ? $currentCompany->id : null);
|
| 66 |
efrain |
337 |
$dataPost = $request->getPost()->toArray();
|
| 649 |
geraldo |
338 |
|
|
|
339 |
|
| 66 |
efrain |
340 |
$form->setData($dataPost);
|
| 649 |
geraldo |
341 |
|
|
|
342 |
if ($form->isValid()) {
|
| 66 |
efrain |
343 |
$dataPost = (array) $form->getData();
|
| 15403 |
efrain |
344 |
|
|
|
345 |
$hydrator = new ObjectPropertyHydrator();
|
|
|
346 |
$jobDescription = new JobDescription();
|
|
|
347 |
|
|
|
348 |
$hydrator->hydrate($dataPost, $jobDescription);
|
|
|
349 |
|
| 66 |
efrain |
350 |
$dataPost['status'] = $dataPost['status'] ? $dataPost['status'] : JobDescription::STATUS_INACTIVE;
|
| 649 |
geraldo |
351 |
|
|
|
352 |
|
| 66 |
efrain |
353 |
$jobDescriptionMapper = JobDescriptionMapper::getInstance($this->adapter);
|
| 649 |
geraldo |
354 |
|
| 15403 |
efrain |
355 |
|
|
|
356 |
if (!empty( $jobDescription->job_description_id_boss)) {
|
|
|
357 |
|
|
|
358 |
$jobDescriptionBoss = $jobDescriptionMapper->fetchOneByUuid($jobDescription->job_description_id_boss);
|
| 649 |
geraldo |
359 |
if ($jobDescriptionBoss) {
|
| 15030 |
efrain |
360 |
|
|
|
361 |
|
| 15403 |
efrain |
362 |
|
| 15030 |
efrain |
363 |
if ($jobDescriptionBoss->company_id == ($currentCompany ? $currentCompany->id : 0)) {
|
| 15403 |
efrain |
364 |
$jobDescription->job_description_id_boss = $jobDescriptionBoss->id;
|
| 66 |
efrain |
365 |
} else {
|
| 15403 |
efrain |
366 |
$jobDescription->job_description_id_boss= null;
|
| 66 |
efrain |
367 |
}
|
|
|
368 |
} else {
|
| 15403 |
efrain |
369 |
$jobDescription->job_description_id_boss = null;
|
| 66 |
efrain |
370 |
}
|
|
|
371 |
}
|
| 15030 |
efrain |
372 |
|
| 66 |
efrain |
373 |
|
| 649 |
geraldo |
374 |
|
|
|
375 |
|
|
|
376 |
if ($currentCompany) {
|
| 847 |
geraldo |
377 |
$jobDescription->company_id = $currentCompany ? $currentCompany->id : null;
|
| 66 |
efrain |
378 |
}
|
|
|
379 |
|
|
|
380 |
$jobDescriptionMapper = JobDescriptionMapper::getInstance($this->adapter);
|
|
|
381 |
$result = $jobDescriptionMapper->insert($jobDescription);
|
| 649 |
geraldo |
382 |
|
| 1195 |
geraldo |
383 |
if ($result) {
|
| 15403 |
efrain |
384 |
$behaviorMapper = BehaviorMapper::getInstance($this->adapter);
|
|
|
385 |
$competencyMapper = CompetencyMapper::getInstance($this->adapter);
|
|
|
386 |
$competencyBehaviorMapper = CompetencyBehaviorMapper::getInstance($this->adapter);
|
|
|
387 |
|
|
|
388 |
|
|
|
389 |
$jobDescriptionCompetencyBehaviorMapper = JobDescriptionCompetencyBehaviorMapper::getInstance($this->adapter);
|
|
|
390 |
$jobDescriptionCompetencyMapper = JobDescriptionCompetencyMapper::getInstance($this->adapter);
|
| 66 |
efrain |
391 |
$jobDescriptionSubordinateMapper = JobDescriptionSubordinateMapper::getInstance($this->adapter);
|
| 15403 |
efrain |
392 |
|
|
|
393 |
|
|
|
394 |
|
|
|
395 |
|
|
|
396 |
|
|
|
397 |
$competencies_selected = isset($dataPost['competencies_selected']) ? $dataPost['competencies_selected'] : [];
|
|
|
398 |
foreach($competencies_selected as $competency_selected)
|
|
|
399 |
{
|
|
|
400 |
|
|
|
401 |
|
|
|
402 |
|
|
|
403 |
$competency_uuid = isset($competency_selected['competency_uuid']) ? $competency_selected['competency_uuid'] : '';
|
|
|
404 |
$competency = $competencyMapper->fetchOneByUuid($competency_uuid);
|
|
|
405 |
|
|
|
406 |
|
|
|
407 |
if($competency) {
|
|
|
408 |
if($currentCompany) {
|
|
|
409 |
$ok = $competency->company_id == $currentCompany->id;
|
|
|
410 |
} else {
|
|
|
411 |
$ok = empty($competency->company_id);
|
|
|
412 |
}
|
|
|
413 |
} else {
|
|
|
414 |
$ok = false;
|
|
|
415 |
}
|
|
|
416 |
|
|
|
417 |
if(!$ok) {
|
|
|
418 |
continue;
|
|
|
419 |
}
|
|
|
420 |
|
|
|
421 |
|
|
|
422 |
$behavior_uuid = isset($competency_selected['behavior_uuid']) ? $competency_selected['behavior_uuid'] : '';
|
|
|
423 |
$behavior = $behaviorMapper->fetchOneByUuid($behavior_uuid);
|
|
|
424 |
if($behavior) {
|
|
|
425 |
if($currentCompany) {
|
|
|
426 |
$ok = $behavior->company_id == $currentCompany->id;
|
|
|
427 |
} else {
|
|
|
428 |
$ok = empty($behavior->company_id);
|
|
|
429 |
}
|
|
|
430 |
|
|
|
431 |
|
|
|
432 |
} else {
|
|
|
433 |
$ok = false;
|
|
|
434 |
}
|
|
|
435 |
|
|
|
436 |
if($competency->company_id != $behavior->company_id) {
|
|
|
437 |
continue;
|
|
|
438 |
}
|
|
|
439 |
|
|
|
440 |
$competencyBehavior = $competencyBehaviorMapper->fetchOneByBehaviorIdAndCompetencyId($behavior->id, $competency->id);
|
|
|
441 |
if(!$competencyBehavior) {
|
|
|
442 |
continue;
|
|
|
443 |
}
|
|
|
444 |
|
|
|
445 |
$level = isset($competency_selected['level']) ? $competency_selected['level'] : 0;
|
|
|
446 |
$level = intval($level, 10);
|
|
|
447 |
|
|
|
448 |
|
|
|
449 |
$jobDescriptionCompetency = $jobDescriptionCompetencyMapper->fetchOneByJobDescriptionIdAndCompetencyId($jobDescription->id, $competency->id);
|
|
|
450 |
if(!$jobDescriptionCompetency) {
|
| 66 |
efrain |
451 |
$jobDescriptionCompetency = new JobDescriptionCompetency();
|
|
|
452 |
$jobDescriptionCompetency->competency_id = $competency->id;
|
|
|
453 |
$jobDescriptionCompetency->job_description_id = $jobDescription->id;
|
|
|
454 |
$jobDescriptionCompetencyMapper->insert($jobDescriptionCompetency);
|
| 15403 |
efrain |
455 |
|
|
|
456 |
}
|
|
|
457 |
|
|
|
458 |
|
|
|
459 |
|
|
|
460 |
$jobDescriptionCompetencyBehavior = new JobDescriptionCompetencyBehavior();
|
|
|
461 |
$jobDescriptionCompetencyBehavior->job_description_id = $jobDescription->id;
|
|
|
462 |
$jobDescriptionCompetencyBehavior->competency_id = $competency->id;
|
|
|
463 |
$jobDescriptionCompetencyBehavior->behavior_id = $behavior->id;
|
|
|
464 |
$jobDescriptionCompetencyBehavior->level = $level;
|
|
|
465 |
$jobDescriptionCompetencyBehaviorMapper->insert($jobDescriptionCompetencyBehavior);
|
|
|
466 |
|
|
|
467 |
|
|
|
468 |
|
|
|
469 |
|
|
|
470 |
}
|
|
|
471 |
|
|
|
472 |
$subordinates_selected = isset($dataPost['subordinates_selected']) ? $dataPost['subordinates_selected'] : [];
|
|
|
473 |
foreach($subordinates_selected as $job_description_uuid)
|
|
|
474 |
{
|
|
|
475 |
$jobDescriptionForSubordinate = $jobDescriptionMapper->fetchOneByUuid($job_description_uuid);
|
|
|
476 |
|
|
|
477 |
|
|
|
478 |
if($jobDescriptionForSubordinate) {
|
|
|
479 |
if($currentCompany) {
|
|
|
480 |
$ok = $jobDescriptionForSubordinate->company_id == $currentCompany->id;
|
|
|
481 |
} else {
|
|
|
482 |
$ok = empty($jobDescriptionForSubordinate->company_id);
|
| 1195 |
geraldo |
483 |
}
|
| 15403 |
efrain |
484 |
} else {
|
|
|
485 |
$ok = false;
|
| 66 |
efrain |
486 |
}
|
| 15403 |
efrain |
487 |
|
|
|
488 |
if(!$ok) {
|
|
|
489 |
continue;
|
|
|
490 |
}
|
|
|
491 |
|
|
|
492 |
|
|
|
493 |
$jobDescriptionSubordinate = new JobDescriptionSubordinate();
|
|
|
494 |
$jobDescriptionSubordinate->job_description_id_top_level = $jobDescription->id;
|
|
|
495 |
$jobDescriptionSubordinate->job_description_id_low_level = $jobDescriptionForSubordinate->id;
|
|
|
496 |
$jobDescriptionSubordinateMapper->insert($jobDescriptionSubordinate);
|
|
|
497 |
|
| 66 |
efrain |
498 |
}
|
| 15403 |
efrain |
499 |
|
| 649 |
geraldo |
500 |
|
|
|
501 |
|
| 66 |
efrain |
502 |
$this->logger->info('Se agrego el cargo ' . $jobDescription->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
|
| 649 |
geraldo |
503 |
|
| 66 |
efrain |
504 |
$data = [
|
| 649 |
geraldo |
505 |
'success' => true,
|
|
|
506 |
'data' => 'LABEL_RECORD_ADDED'
|
| 66 |
efrain |
507 |
];
|
|
|
508 |
} else {
|
|
|
509 |
$data = [
|
| 649 |
geraldo |
510 |
'success' => false,
|
|
|
511 |
'data' => $jobDescriptionMapper->getError()
|
| 66 |
efrain |
512 |
];
|
|
|
513 |
}
|
| 649 |
geraldo |
514 |
|
| 66 |
efrain |
515 |
return new JsonModel($data);
|
|
|
516 |
} else {
|
|
|
517 |
$messages = [];
|
|
|
518 |
$form_messages = (array) $form->getMessages();
|
| 649 |
geraldo |
519 |
foreach ($form_messages as $fieldname => $field_messages) {
|
|
|
520 |
|
| 66 |
efrain |
521 |
$messages[$fieldname] = array_values($field_messages);
|
|
|
522 |
}
|
| 649 |
geraldo |
523 |
|
| 66 |
efrain |
524 |
return new JsonModel([
|
| 649 |
geraldo |
525 |
'success' => false,
|
|
|
526 |
'data' => $messages
|
| 66 |
efrain |
527 |
]);
|
|
|
528 |
}
|
|
|
529 |
} else {
|
|
|
530 |
$data = [
|
|
|
531 |
'success' => false,
|
|
|
532 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
533 |
];
|
| 649 |
geraldo |
534 |
|
| 66 |
efrain |
535 |
return new JsonModel($data);
|
|
|
536 |
}
|
| 649 |
geraldo |
537 |
|
| 66 |
efrain |
538 |
return new JsonModel($data);
|
|
|
539 |
}
|
| 649 |
geraldo |
540 |
|
| 14203 |
stevensc |
541 |
public function editAction()
|
|
|
542 |
{
|
| 66 |
efrain |
543 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
544 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
545 |
$currentCompany = $currentUserPlugin->getCompany();
|
| 649 |
geraldo |
546 |
|
| 66 |
efrain |
547 |
$request = $this->getRequest();
|
|
|
548 |
$uuid = $this->params()->fromRoute('id');
|
|
|
549 |
|
| 649 |
geraldo |
550 |
|
|
|
551 |
if (!$uuid) {
|
| 66 |
efrain |
552 |
$data = [
|
| 649 |
geraldo |
553 |
'success' => false,
|
|
|
554 |
'data' => 'ERROR_INVALID_PARAMETER'
|
| 66 |
efrain |
555 |
];
|
| 649 |
geraldo |
556 |
|
| 66 |
efrain |
557 |
return new JsonModel($data);
|
|
|
558 |
}
|
|
|
559 |
|
|
|
560 |
$jobDescriptionMapper = JobDescriptionMapper::getInstance($this->adapter);
|
|
|
561 |
$jobDescription = $jobDescriptionMapper->fetchOneByUuid($uuid);
|
| 649 |
geraldo |
562 |
if (!$jobDescription) {
|
| 66 |
efrain |
563 |
$data = [
|
| 649 |
geraldo |
564 |
'success' => false,
|
|
|
565 |
'data' => 'ERROR_RECORD_NOT_FOUND'
|
| 66 |
efrain |
566 |
];
|
| 649 |
geraldo |
567 |
|
| 66 |
efrain |
568 |
return new JsonModel($data);
|
|
|
569 |
}
|
| 649 |
geraldo |
570 |
|
| 851 |
geraldo |
571 |
if ($currentCompany && $jobDescription->company_id != $currentCompany->id) {
|
| 66 |
efrain |
572 |
$data = [
|
| 649 |
geraldo |
573 |
'success' => false,
|
|
|
574 |
'data' => 'ERROR_UNAUTHORIZED'
|
| 66 |
efrain |
575 |
];
|
| 649 |
geraldo |
576 |
|
| 66 |
efrain |
577 |
return new JsonModel($data);
|
|
|
578 |
}
|
|
|
579 |
|
| 649 |
geraldo |
580 |
|
|
|
581 |
if ($request->isPost()) {
|
| 847 |
geraldo |
582 |
$form = new JobDescriptionForm($this->adapter, $currentCompany ? $currentCompany->id : null, $jobDescription->id);
|
| 66 |
efrain |
583 |
$dataPost = $request->getPost()->toArray();
|
| 649 |
geraldo |
584 |
|
|
|
585 |
|
| 66 |
efrain |
586 |
$form->setData($dataPost);
|
| 649 |
geraldo |
587 |
|
|
|
588 |
if ($form->isValid()) {
|
| 15403 |
efrain |
589 |
|
|
|
590 |
|
|
|
591 |
|
| 66 |
efrain |
592 |
$dataPost = (array) $form->getData();
|
| 15403 |
efrain |
593 |
|
|
|
594 |
$hydrator = new ObjectPropertyHydrator();
|
|
|
595 |
$hydrator->hydrate($dataPost, $jobDescription);
|
|
|
596 |
|
| 66 |
efrain |
597 |
$dataPost['status'] = $dataPost['status'] ? $dataPost['status'] : JobDescription::STATUS_INACTIVE;
|
| 15403 |
efrain |
598 |
|
|
|
599 |
|
|
|
600 |
$jobDescriptionMapper = JobDescriptionMapper::getInstance($this->adapter);
|
|
|
601 |
|
|
|
602 |
if (!empty( $jobDescription->job_description_id_boss)) {
|
|
|
603 |
|
|
|
604 |
$jobDescriptionBoss = $jobDescriptionMapper->fetchOneByUuid($jobDescription->job_description_id_boss);
|
| 649 |
geraldo |
605 |
if ($jobDescriptionBoss) {
|
| 15403 |
efrain |
606 |
|
|
|
607 |
|
|
|
608 |
|
|
|
609 |
if ($jobDescriptionBoss->company_id == ($currentCompany ? $currentCompany->id : 0)) {
|
|
|
610 |
$jobDescription->job_description_id_boss = $jobDescriptionBoss->id;
|
| 66 |
efrain |
611 |
} else {
|
| 15403 |
efrain |
612 |
$jobDescription->job_description_id_boss= null;
|
| 66 |
efrain |
613 |
}
|
|
|
614 |
} else {
|
| 15403 |
efrain |
615 |
$jobDescription->job_description_id_boss = null;
|
| 66 |
efrain |
616 |
}
|
|
|
617 |
}
|
| 15403 |
efrain |
618 |
|
|
|
619 |
$subordinates_for_update = [];
|
|
|
620 |
|
|
|
621 |
|
|
|
622 |
$subordinates_selected = isset($dataPost['subordinates_selected']) ? $dataPost['subordinates_selected'] : [];
|
|
|
623 |
foreach($subordinates_selected as $job_description_uuid)
|
|
|
624 |
{
|
|
|
625 |
$jobDescriptionForSubordinate = $jobDescriptionMapper->fetchOneByUuid($job_description_uuid);
|
|
|
626 |
|
|
|
627 |
|
|
|
628 |
if($jobDescriptionForSubordinate) {
|
|
|
629 |
if($currentCompany) {
|
|
|
630 |
$ok = $jobDescriptionForSubordinate->company_id == $currentCompany->id;
|
|
|
631 |
} else {
|
|
|
632 |
$ok = empty($jobDescriptionForSubordinate->company_id);
|
|
|
633 |
}
|
|
|
634 |
} else {
|
|
|
635 |
$ok = false;
|
|
|
636 |
}
|
|
|
637 |
|
|
|
638 |
if(!$ok) {
|
|
|
639 |
continue;
|
|
|
640 |
}
|
|
|
641 |
|
|
|
642 |
array_push($subordinates_for_update, $jobDescriptionForSubordinate->id);
|
|
|
643 |
|
|
|
644 |
|
|
|
645 |
|
|
|
646 |
}
|
|
|
647 |
|
|
|
648 |
$error_recursive_job_description = false;
|
|
|
649 |
$jobDescriptionSubordinateMapper = JobDescriptionSubordinateMapper::getInstance($this->adapter);
|
| 649 |
geraldo |
650 |
|
| 15403 |
efrain |
651 |
if($jobDescription->job_description_id_boss) {
|
|
|
652 |
$jobDescriptionSubordinate = $jobDescriptionSubordinateMapper->fetchOneByJobDescriptionIdTopAndLowLevel($jobDescription->id, $jobDescription->job_description_id_boss);
|
|
|
653 |
if($jobDescriptionSubordinate) {
|
|
|
654 |
$error_recursive_job_description = true;
|
|
|
655 |
|
|
|
656 |
|
|
|
657 |
}
|
|
|
658 |
|
|
|
659 |
|
|
|
660 |
}
|
| 14350 |
kerby |
661 |
|
| 15403 |
efrain |
662 |
if(!$error_recursive_job_description && $subordinates_for_update) {
|
|
|
663 |
foreach($subordinates_for_update as $subordinate_id)
|
|
|
664 |
{
|
|
|
665 |
if($jobDescription->job_description_id_boss) {
|
|
|
666 |
if($jobDescription->job_description_id_boss == $subordinate_id) {
|
|
|
667 |
$error_recursive_job_description = true;
|
|
|
668 |
break;
|
|
|
669 |
}
|
|
|
670 |
}
|
|
|
671 |
|
|
|
672 |
|
|
|
673 |
$jobDescriptionSubordinate = $jobDescriptionSubordinateMapper->fetchOneByJobDescriptionIdTopAndLowLevel($subordinate_id, $jobDescription->id);
|
|
|
674 |
if($jobDescriptionSubordinate) {
|
|
|
675 |
$error_recursive_job_description = true;
|
|
|
676 |
break;
|
|
|
677 |
|
|
|
678 |
}
|
|
|
679 |
|
|
|
680 |
|
|
|
681 |
}
|
|
|
682 |
}
|
|
|
683 |
|
|
|
684 |
if($error_recursive_job_description) {
|
|
|
685 |
$data = [
|
|
|
686 |
'success' => false,
|
|
|
687 |
'data' => 'ERROR_JOB_DESCRIPTIONS_RECURSIVE'
|
|
|
688 |
];
|
|
|
689 |
|
|
|
690 |
|
|
|
691 |
return new JsonModel($data);
|
|
|
692 |
}
|
|
|
693 |
|
|
|
694 |
|
|
|
695 |
|
|
|
696 |
|
| 66 |
efrain |
697 |
$result = $jobDescriptionMapper->update($jobDescription);
|
| 649 |
geraldo |
698 |
|
|
|
699 |
if ($result) {
|
| 15403 |
efrain |
700 |
$behaviorMapper = BehaviorMapper::getInstance($this->adapter);
|
|
|
701 |
$competencyMapper = CompetencyMapper::getInstance($this->adapter);
|
|
|
702 |
$competencyBehaviorMapper = CompetencyBehaviorMapper::getInstance($this->adapter);
|
|
|
703 |
|
|
|
704 |
|
|
|
705 |
$jobDescriptionCompetencyBehaviorMapper = JobDescriptionCompetencyBehaviorMapper::getInstance($this->adapter);
|
|
|
706 |
$jobDescriptionCompetencyBehaviorMapper->deleteAllBJobDescriptionId($jobDescription->id);
|
|
|
707 |
|
| 1195 |
geraldo |
708 |
$jobDescriptionCompetencyMapper = JobDescriptionCompetencyMapper::getInstance($this->adapter);
|
| 15403 |
efrain |
709 |
$jobDescriptionCompetencyMapper->deleteAllBJobDescriptionId($jobDescription->id);
|
|
|
710 |
|
|
|
711 |
|
|
|
712 |
|
| 66 |
efrain |
713 |
$jobDescriptionSubordinateMapper->deleteAllByJobDescriptionIdTopLevel($jobDescription->id);
|
| 15403 |
efrain |
714 |
|
|
|
715 |
|
|
|
716 |
$competencies_selected = isset($dataPost['competencies_selected']) ? $dataPost['competencies_selected'] : [];
|
|
|
717 |
foreach($competencies_selected as $competency_selected)
|
|
|
718 |
{
|
|
|
719 |
|
|
|
720 |
|
|
|
721 |
|
|
|
722 |
$competency_uuid = isset($competency_selected['competency_uuid']) ? $competency_selected['competency_uuid'] : '';
|
|
|
723 |
$competency = $competencyMapper->fetchOneByUuid($competency_uuid);
|
|
|
724 |
|
|
|
725 |
|
|
|
726 |
if($competency) {
|
|
|
727 |
if($currentCompany) {
|
|
|
728 |
$ok = $competency->company_id == $currentCompany->id;
|
|
|
729 |
} else {
|
|
|
730 |
$ok = empty($competency->company_id);
|
|
|
731 |
}
|
|
|
732 |
} else {
|
|
|
733 |
$ok = false;
|
|
|
734 |
}
|
|
|
735 |
|
|
|
736 |
if(!$ok) {
|
|
|
737 |
continue;
|
|
|
738 |
}
|
|
|
739 |
|
|
|
740 |
|
|
|
741 |
$behavior_uuid = isset($competency_selected['behavior_uuid']) ? $competency_selected['behavior_uuid'] : '';
|
|
|
742 |
$behavior = $behaviorMapper->fetchOneByUuid($behavior_uuid);
|
|
|
743 |
if($behavior) {
|
|
|
744 |
if($currentCompany) {
|
|
|
745 |
$ok = $behavior->company_id == $currentCompany->id;
|
|
|
746 |
} else {
|
|
|
747 |
$ok = empty($behavior->company_id);
|
|
|
748 |
}
|
|
|
749 |
|
|
|
750 |
|
|
|
751 |
} else {
|
|
|
752 |
$ok = false;
|
|
|
753 |
}
|
|
|
754 |
|
|
|
755 |
if($competency->company_id != $behavior->company_id) {
|
|
|
756 |
continue;
|
|
|
757 |
}
|
|
|
758 |
|
|
|
759 |
$competencyBehavior = $competencyBehaviorMapper->fetchOneByBehaviorIdAndCompetencyId($behavior->id, $competency->id);
|
|
|
760 |
if(!$competencyBehavior) {
|
|
|
761 |
continue;
|
|
|
762 |
}
|
|
|
763 |
|
|
|
764 |
$level = isset($competency_selected['level']) ? $competency_selected['level'] : 0;
|
|
|
765 |
$level = intval($level, 10);
|
|
|
766 |
|
|
|
767 |
|
|
|
768 |
$jobDescriptionCompetency = $jobDescriptionCompetencyMapper->fetchOneByJobDescriptionIdAndCompetencyId($jobDescription->id, $competency->id);
|
|
|
769 |
if(!$jobDescriptionCompetency) {
|
| 66 |
efrain |
770 |
$jobDescriptionCompetency = new JobDescriptionCompetency();
|
|
|
771 |
$jobDescriptionCompetency->competency_id = $competency->id;
|
|
|
772 |
$jobDescriptionCompetency->job_description_id = $jobDescription->id;
|
|
|
773 |
$jobDescriptionCompetencyMapper->insert($jobDescriptionCompetency);
|
| 15403 |
efrain |
774 |
|
| 66 |
efrain |
775 |
}
|
| 15030 |
efrain |
776 |
|
| 15403 |
efrain |
777 |
|
|
|
778 |
|
|
|
779 |
$jobDescriptionCompetencyBehavior = new JobDescriptionCompetencyBehavior();
|
|
|
780 |
$jobDescriptionCompetencyBehavior->job_description_id = $jobDescription->id;
|
|
|
781 |
$jobDescriptionCompetencyBehavior->competency_id = $competency->id;
|
|
|
782 |
$jobDescriptionCompetencyBehavior->behavior_id = $behavior->id;
|
|
|
783 |
$jobDescriptionCompetencyBehavior->level = $level;
|
|
|
784 |
$jobDescriptionCompetencyBehaviorMapper->insert($jobDescriptionCompetencyBehavior);
|
|
|
785 |
|
|
|
786 |
|
|
|
787 |
foreach($subordinates_for_update as $subordinate_id)
|
|
|
788 |
{
|
|
|
789 |
|
| 66 |
efrain |
790 |
$jobDescriptionSubordinate = new JobDescriptionSubordinate();
|
|
|
791 |
$jobDescriptionSubordinate->job_description_id_top_level = $jobDescription->id;
|
| 15403 |
efrain |
792 |
$jobDescriptionSubordinate->job_description_id_low_level = $subordinate_id;
|
| 66 |
efrain |
793 |
$jobDescriptionSubordinateMapper->insert($jobDescriptionSubordinate);
|
|
|
794 |
}
|
| 15403 |
efrain |
795 |
|
|
|
796 |
|
| 66 |
efrain |
797 |
}
|
| 15403 |
efrain |
798 |
|
|
|
799 |
|
|
|
800 |
|
| 66 |
efrain |
801 |
$this->logger->info('Se actualizo el cargo ' . $jobDescription->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
|
| 649 |
geraldo |
802 |
|
| 66 |
efrain |
803 |
$data = [
|
|
|
804 |
'success' => true,
|
|
|
805 |
'data' => 'LABEL_RECORD_UPDATED'
|
|
|
806 |
];
|
|
|
807 |
} else {
|
|
|
808 |
$data = [
|
| 649 |
geraldo |
809 |
'success' => false,
|
|
|
810 |
'data' => $jobDescriptionMapper->getError()
|
| 66 |
efrain |
811 |
];
|
|
|
812 |
}
|
| 649 |
geraldo |
813 |
|
| 66 |
efrain |
814 |
return new JsonModel($data);
|
|
|
815 |
} else {
|
|
|
816 |
$messages = [];
|
|
|
817 |
$form_messages = (array) $form->getMessages();
|
| 649 |
geraldo |
818 |
foreach ($form_messages as $fieldname => $field_messages) {
|
| 66 |
efrain |
819 |
$messages[$fieldname] = array_values($field_messages);
|
|
|
820 |
}
|
| 649 |
geraldo |
821 |
|
| 66 |
efrain |
822 |
return new JsonModel([
|
| 649 |
geraldo |
823 |
'success' => false,
|
|
|
824 |
'data' => $messages
|
| 66 |
efrain |
825 |
]);
|
|
|
826 |
}
|
|
|
827 |
} else if ($request->isGet()) {
|
|
|
828 |
|
| 15403 |
efrain |
829 |
if ($jobDescription->job_description_id_boss) {
|
|
|
830 |
|
|
|
831 |
$jobDescriptionBoss = $jobDescriptionMapper->fetchOne($jobDescription->job_description_id_boss);
|
| 649 |
geraldo |
832 |
if ($jobDescriptionBoss) {
|
| 15403 |
efrain |
833 |
$job_description_uuid_boss = $jobDescriptionBoss->uuid;
|
| 66 |
efrain |
834 |
} else {
|
| 15403 |
efrain |
835 |
$job_description_uuid_boss = '';
|
| 66 |
efrain |
836 |
}
|
|
|
837 |
} else {
|
| 15403 |
efrain |
838 |
$job_description_uuid_boss = '';
|
| 66 |
efrain |
839 |
}
|
| 15403 |
efrain |
840 |
|
|
|
841 |
if($currentCompany) {
|
|
|
842 |
$records = $jobDescriptionMapper->fetchAllActiveByCompanyId($currentCompany->id);
|
|
|
843 |
} else {
|
| 15087 |
efrain |
844 |
$jobDescriptionMapper->fetchAllActiveByDefault();
|
| 66 |
efrain |
845 |
}
|
| 15403 |
efrain |
846 |
|
|
|
847 |
$jobsDescription = [];
|
|
|
848 |
|
|
|
849 |
foreach ($records as $record)
|
|
|
850 |
{
|
|
|
851 |
|
|
|
852 |
if($jobDescription->id != $record->id) {
|
|
|
853 |
|
|
|
854 |
$jobsDescription[ $record->uuid ] = $record->name;
|
|
|
855 |
}
|
|
|
856 |
}
|
|
|
857 |
|
| 15444 |
efrain |
858 |
$behaviors = [];
|
|
|
859 |
$behaviorMapper = BehaviorMapper::getInstance($this->adapter);
|
|
|
860 |
|
|
|
861 |
|
|
|
862 |
if($currentCompany) {
|
|
|
863 |
$records = $behaviorMapper->fetchAllActiveByCompanyId($currentCompany->id);
|
|
|
864 |
} else {
|
|
|
865 |
$records = $behaviorMapper->fetchAllActiveByDefault();
|
|
|
866 |
}
|
|
|
867 |
|
|
|
868 |
$behaviorIds = [];
|
|
|
869 |
foreach($records as $record)
|
|
|
870 |
{
|
|
|
871 |
|
|
|
872 |
$behaviorIds[ $record->id ] = $record->uuid;
|
|
|
873 |
|
|
|
874 |
array_push($behaviors, [
|
|
|
875 |
'uuid' => $record->uuid,
|
|
|
876 |
'description' => $record->description
|
|
|
877 |
]);
|
|
|
878 |
}
|
|
|
879 |
|
|
|
880 |
|
|
|
881 |
$competencyTypes = [];
|
|
|
882 |
|
|
|
883 |
|
|
|
884 |
$competencyTypeMapper = CompetencyTypeMapper::getInstance($this->adapter);
|
|
|
885 |
|
|
|
886 |
if($currentCompany) {
|
|
|
887 |
$records = $competencyTypeMapper->fetchAllActiveByCompanyId($currentCompany->id);
|
|
|
888 |
} else {
|
|
|
889 |
$records = $competencyTypeMapper->fetchAllActiveByDefault();
|
|
|
890 |
}
|
|
|
891 |
|
|
|
892 |
|
|
|
893 |
$competencyTypeIds = [];
|
|
|
894 |
foreach($records as $record)
|
|
|
895 |
{
|
|
|
896 |
$competencyTypeIds[ $record->id ] = $record->uuid;
|
|
|
897 |
|
|
|
898 |
|
|
|
899 |
array_push($competencyTypes, [
|
|
|
900 |
'uuid' => $record->uuid,
|
|
|
901 |
'name' => $record->name,
|
|
|
902 |
]);
|
|
|
903 |
}
|
|
|
904 |
|
|
|
905 |
$competencyMapper = CompetencyMapper::getInstance($this->adapter);
|
|
|
906 |
if($currentCompany) {
|
|
|
907 |
$records = $competencyMapper->fetchAllActiveByCompanyId($currentCompany->id);
|
|
|
908 |
} else {
|
|
|
909 |
$records = $competencyMapper->fetchAllActiveByDefault();
|
|
|
910 |
}
|
|
|
911 |
|
|
|
912 |
$competencyBehaviorMapper = CompetencyBehaviorMapper::getInstance($this->adapter);
|
|
|
913 |
|
|
|
914 |
|
|
|
915 |
|
|
|
916 |
$competencies = [];
|
|
|
917 |
|
|
|
918 |
foreach($records as $record)
|
|
|
919 |
{
|
|
|
920 |
if(!isset($competencyTypeIds[ $record->competency_type_id ])) {
|
|
|
921 |
continue;
|
|
|
922 |
}
|
|
|
923 |
|
|
|
924 |
$behaviors_by_competency = [];
|
|
|
925 |
|
|
|
926 |
$competencyBehaviors = $competencyBehaviorMapper->fetchAllByCompetencyId($record->id);
|
|
|
927 |
foreach($competencyBehaviors as $competencyBehavior)
|
|
|
928 |
{
|
|
|
929 |
if(!isset($behaviorIds[ $competencyBehavior->behavior_id ])) {
|
|
|
930 |
continue;
|
|
|
931 |
}
|
|
|
932 |
|
|
|
933 |
array_push($behaviors_by_competency, $behaviorIds[ $competencyBehavior->behavior_id ]);
|
|
|
934 |
}
|
|
|
935 |
|
|
|
936 |
|
|
|
937 |
if($behaviors_by_competency) {
|
|
|
938 |
array_push($competencies, [
|
|
|
939 |
'competency_type_uuid' => $competencyTypeIds[ $record->competency_type_id ],
|
|
|
940 |
'uuid' => $record->uuid,
|
|
|
941 |
'name' => $record->name,
|
|
|
942 |
'behaviors' => $behaviors_by_competency,
|
|
|
943 |
]);
|
|
|
944 |
}
|
|
|
945 |
|
|
|
946 |
|
|
|
947 |
}
|
|
|
948 |
|
|
|
949 |
|
|
|
950 |
|
|
|
951 |
|
|
|
952 |
|
|
|
953 |
$jobDescriptionMapper = JobDescriptionMapper::getInstance($this->adapter);
|
|
|
954 |
if($currentCompany) {
|
|
|
955 |
$records = $jobDescriptionMapper->fetchAllActiveByCompanyId($currentCompany->id);
|
|
|
956 |
} else {
|
|
|
957 |
$jobDescriptionMapper->fetchAllActiveByDefault();
|
|
|
958 |
}
|
|
|
959 |
|
|
|
960 |
$jobsDescription = [];
|
|
|
961 |
|
|
|
962 |
foreach ($records as $record)
|
|
|
963 |
{
|
|
|
964 |
$jobsDescription[ $record->uuid ] = $record->name;
|
|
|
965 |
}
|
|
|
966 |
|
| 649 |
geraldo |
967 |
|
| 15403 |
efrain |
968 |
$data = [
|
|
|
969 |
'name' => $jobDescription->name,
|
|
|
970 |
'functions' => $jobDescription->functions,
|
|
|
971 |
'objectives' => $jobDescription->objectives,
|
|
|
972 |
'status' => $jobDescription->status,
|
|
|
973 |
'job_description_id_boss' => $job_description_uuid_boss,
|
|
|
974 |
'jobs_description' => $jobsDescription,
|
|
|
975 |
'subordinates_selected' => [],
|
|
|
976 |
'competencies_selected' => [],
|
| 15444 |
efrain |
977 |
'behaviors' => $behaviors,
|
|
|
978 |
'competency_types' => $competencyTypes,
|
|
|
979 |
'competencies' => $competencies,
|
| 15403 |
efrain |
980 |
];
|
|
|
981 |
|
| 1320 |
efrain |
982 |
$behaviorMapper = BehaviorMapper::getInstance($this->adapter);
|
| 66 |
efrain |
983 |
$competencyMapper = CompetencyMapper::getInstance($this->adapter);
|
| 15403 |
efrain |
984 |
$competencyTypeMapper = CompetencyTypeMapper::getInstance($this->adapter);
|
|
|
985 |
|
|
|
986 |
$competencyTypes = [];
|
| 649 |
geraldo |
987 |
|
| 15403 |
efrain |
988 |
$jobDescriptionCompetencyMapper = JobDescriptionCompetencyMapper::getInstance($this->adapter);
|
|
|
989 |
$jobDescriptionCompetencyBehaviorMapper = JobDescriptionCompetencyBehaviorMapper::getInstance($this->adapter);
|
|
|
990 |
|
|
|
991 |
$jobDescriptionCompetencies = $jobDescriptionCompetencyMapper->fetchAllByJobDescriptionId($jobDescription->id);
|
|
|
992 |
foreach($jobDescriptionCompetencies as $jobDescriptionCompetency)
|
|
|
993 |
{
|
|
|
994 |
|
|
|
995 |
|
|
|
996 |
|
|
|
997 |
$competency = $competencyMapper->fetchOne($jobDescriptionCompetency->competency_id);
|
|
|
998 |
if(!$competency) {
|
|
|
999 |
continue;
|
|
|
1000 |
}
|
|
|
1001 |
|
|
|
1002 |
if(isset($competencyTypes[$competency->competency_type_id])) {
|
|
|
1003 |
$competencyType = $competencyTypes[$competency->competency_type_id];
|
|
|
1004 |
} else {
|
|
|
1005 |
|
|
|
1006 |
$competencyType = $competencyTypeMapper->fetchOne($competency->competency_type_id);
|
|
|
1007 |
if(!$competencyType) {
|
|
|
1008 |
continue;
|
| 1154 |
geraldo |
1009 |
}
|
| 15403 |
efrain |
1010 |
|
|
|
1011 |
$competencyTypes[$competency->competency_type_id] = $competencyType;
|
|
|
1012 |
}
|
|
|
1013 |
|
|
|
1014 |
$competency_selected = [
|
|
|
1015 |
'uuid' => $competency->uuid,
|
|
|
1016 |
'competency_type_uuid' => $competencyType->uuid,
|
|
|
1017 |
'behaviors' => []
|
|
|
1018 |
];
|
|
|
1019 |
|
| 15444 |
efrain |
1020 |
|
| 15403 |
efrain |
1021 |
|
| 15444 |
efrain |
1022 |
foreach($competencies as $record_competency)
|
| 15403 |
efrain |
1023 |
{
|
| 15444 |
efrain |
1024 |
if($record_competency['uuid'] == $competency->uuid) {
|
|
|
1025 |
|
|
|
1026 |
foreach($record_competency['behaviors'] as $uuid_behavior)
|
|
|
1027 |
{
|
| 1154 |
geraldo |
1028 |
|
| 15444 |
efrain |
1029 |
|
|
|
1030 |
$behavior = $behaviorMapper->fetchOneByUuid($uuid_behavior);
|
|
|
1031 |
if($behavior) {
|
|
|
1032 |
|
|
|
1033 |
$jobDescriptionCompetencyBehavior = $jobDescriptionCompetencyBehaviorMapper->fetchOneByJobDescriptionIdAndCompetencyIdAndBehaviorId($jobDescription->id, $competency->id, $behavior->id);
|
|
|
1034 |
if($jobDescriptionCompetencyBehavior) {
|
|
|
1035 |
$level = $jobDescriptionCompetencyBehavior->level;
|
|
|
1036 |
} else {
|
|
|
1037 |
$level = 0;
|
|
|
1038 |
}
|
|
|
1039 |
|
|
|
1040 |
array_push($competency_selected['behaviors'], ['uuid' => $behavior->uuid, 'level' => $level]);
|
|
|
1041 |
}
|
|
|
1042 |
}
|
|
|
1043 |
|
| 1197 |
geraldo |
1044 |
}
|
| 15403 |
efrain |
1045 |
|
| 15444 |
efrain |
1046 |
|
| 66 |
efrain |
1047 |
}
|
| 15403 |
efrain |
1048 |
|
| 15444 |
efrain |
1049 |
|
|
|
1050 |
|
| 15403 |
efrain |
1051 |
array_push($data['competencies_selected'], $competency_selected);
|
|
|
1052 |
|
|
|
1053 |
|
|
|
1054 |
|
| 66 |
efrain |
1055 |
}
|
| 15403 |
efrain |
1056 |
|
| 66 |
efrain |
1057 |
$jobDescriptionSubordinateMapper = JobDescriptionSubordinateMapper::getInstance($this->adapter);
|
| 15403 |
efrain |
1058 |
$jobDescriptionSubordinates = $jobDescriptionSubordinateMapper->fetchAllByJobDescriptionIdTopLevel($jobDescription->id);
|
|
|
1059 |
|
|
|
1060 |
foreach($jobDescriptionSubordinates as $jobDescriptionSubordinate)
|
|
|
1061 |
{
|
|
|
1062 |
$jobDescriptionForSubordinate = $jobDescriptionMapper->fetchOne($jobDescriptionSubordinate->job_description_id_low_level);
|
|
|
1063 |
if($jobDescriptionForSubordinate) {
|
|
|
1064 |
array_push($data['subordinates_selected'], ['uuid' => $jobDescriptionForSubordinate->uuid ]);
|
| 66 |
efrain |
1065 |
}
|
| 15403 |
efrain |
1066 |
|
|
|
1067 |
|
|
|
1068 |
|
| 66 |
efrain |
1069 |
}
|
| 15403 |
efrain |
1070 |
|
|
|
1071 |
|
| 66 |
efrain |
1072 |
|
|
|
1073 |
$response = [
|
|
|
1074 |
'success' => true,
|
|
|
1075 |
'data' => $data
|
|
|
1076 |
];
|
| 649 |
geraldo |
1077 |
|
| 66 |
efrain |
1078 |
return new JsonModel($response);
|
|
|
1079 |
} else {
|
|
|
1080 |
$data = [
|
|
|
1081 |
'success' => false,
|
|
|
1082 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
1083 |
];
|
| 649 |
geraldo |
1084 |
|
| 66 |
efrain |
1085 |
return new JsonModel($data);
|
|
|
1086 |
}
|
| 649 |
geraldo |
1087 |
|
| 66 |
efrain |
1088 |
return new JsonModel($data);
|
|
|
1089 |
}
|
| 649 |
geraldo |
1090 |
|
| 14203 |
stevensc |
1091 |
public function deleteAction()
|
|
|
1092 |
{
|
| 66 |
efrain |
1093 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
1094 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
1095 |
$currentCompany = $currentUserPlugin->getCompany();
|
| 649 |
geraldo |
1096 |
|
| 66 |
efrain |
1097 |
$request = $this->getRequest();
|
|
|
1098 |
$uuid = $this->params()->fromRoute('id');
|
| 649 |
geraldo |
1099 |
|
|
|
1100 |
if (!$uuid) {
|
| 66 |
efrain |
1101 |
$data = [
|
| 649 |
geraldo |
1102 |
'success' => false,
|
|
|
1103 |
'data' => 'ERROR_INVALID_PARAMETER'
|
| 66 |
efrain |
1104 |
];
|
| 649 |
geraldo |
1105 |
|
| 66 |
efrain |
1106 |
return new JsonModel($data);
|
|
|
1107 |
}
|
| 649 |
geraldo |
1108 |
|
|
|
1109 |
|
| 66 |
efrain |
1110 |
$jobDescriptionMapper = JobDescriptionMapper::getInstance($this->adapter);
|
|
|
1111 |
$jobDescription = $jobDescriptionMapper->fetchOneByUuid($uuid);
|
| 649 |
geraldo |
1112 |
if (!$jobDescription) {
|
| 66 |
efrain |
1113 |
$data = [
|
| 649 |
geraldo |
1114 |
'success' => false,
|
|
|
1115 |
'data' => 'ERROR_RECORD_NOT_FOUND'
|
| 66 |
efrain |
1116 |
];
|
| 649 |
geraldo |
1117 |
|
| 66 |
efrain |
1118 |
return new JsonModel($data);
|
|
|
1119 |
}
|
| 649 |
geraldo |
1120 |
|
| 851 |
geraldo |
1121 |
if ($currentCompany && $jobDescription->company_id != $currentCompany->id) {
|
| 66 |
efrain |
1122 |
$data = [
|
| 649 |
geraldo |
1123 |
'success' => false,
|
|
|
1124 |
'data' => 'ERROR_UNAUTHORIZED'
|
| 66 |
efrain |
1125 |
];
|
| 649 |
geraldo |
1126 |
|
| 66 |
efrain |
1127 |
return new JsonModel($data);
|
|
|
1128 |
}
|
|
|
1129 |
|
| 649 |
geraldo |
1130 |
|
|
|
1131 |
if ($request->isPost()) {
|
| 66 |
efrain |
1132 |
$result = $jobDescriptionMapper->delete($jobDescription);
|
| 649 |
geraldo |
1133 |
if ($result) {
|
| 66 |
efrain |
1134 |
$this->logger->info('Se borro el cargo de trabajo ' . $jobDescription->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
|
| 649 |
geraldo |
1135 |
|
| 66 |
efrain |
1136 |
$data = [
|
|
|
1137 |
'success' => true,
|
|
|
1138 |
'data' => 'LABEL_RECORD_DELETED'
|
|
|
1139 |
];
|
|
|
1140 |
} else {
|
|
|
1141 |
|
|
|
1142 |
$data = [
|
| 649 |
geraldo |
1143 |
'success' => false,
|
|
|
1144 |
'data' => $jobDescriptionMapper->getError()
|
| 66 |
efrain |
1145 |
];
|
|
|
1146 |
|
|
|
1147 |
return new JsonModel($data);
|
|
|
1148 |
}
|
|
|
1149 |
} else {
|
|
|
1150 |
$data = [
|
|
|
1151 |
'success' => false,
|
|
|
1152 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
1153 |
];
|
| 649 |
geraldo |
1154 |
|
| 66 |
efrain |
1155 |
return new JsonModel($data);
|
|
|
1156 |
}
|
| 649 |
geraldo |
1157 |
|
| 66 |
efrain |
1158 |
return new JsonModel($data);
|
|
|
1159 |
}
|
| 561 |
geraldo |
1160 |
|
| 14203 |
stevensc |
1161 |
public function importAction()
|
|
|
1162 |
{
|
| 850 |
geraldo |
1163 |
|
| 852 |
geraldo |
1164 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
1165 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
1166 |
$currentCompany = $currentUserPlugin->getCompany();
|
| 854 |
geraldo |
1167 |
|
|
|
1168 |
if (!$currentCompany) {
|
| 852 |
geraldo |
1169 |
$data = [
|
|
|
1170 |
'success' => false,
|
|
|
1171 |
'data' => 'ERROR_UNAUTHORIZED'
|
|
|
1172 |
];
|
| 854 |
geraldo |
1173 |
|
| 852 |
geraldo |
1174 |
return new JsonModel($data);
|
|
|
1175 |
}
|
| 854 |
geraldo |
1176 |
|
| 852 |
geraldo |
1177 |
$request = $this->getRequest();
|
| 854 |
geraldo |
1178 |
|
|
|
1179 |
if ($request->isPost()) {
|
|
|
1180 |
|
| 852 |
geraldo |
1181 |
$jobDescriptionMapper = JobDescriptionMapper::getInstance($this->adapter);
|
|
|
1182 |
$jobDescriptionsDefault = $jobDescriptionMapper->fetchAllByDefault();
|
| 854 |
geraldo |
1183 |
|
| 852 |
geraldo |
1184 |
$new_records = 0;
|
| 854 |
geraldo |
1185 |
foreach ($jobDescriptionsDefault as $jobDescriptionDefault) {
|
|
|
1186 |
if ($jobDescriptionDefault->status == JobDescription::STATUS_INACTIVE) {
|
| 852 |
geraldo |
1187 |
continue;
|
|
|
1188 |
}
|
| 854 |
geraldo |
1189 |
|
| 852 |
geraldo |
1190 |
$jobDescription = $jobDescriptionMapper->fetchOneByCompanyId($currentCompany->id, $jobDescriptionDefault->id);
|
| 854 |
geraldo |
1191 |
if (!$jobDescription) {
|
|
|
1192 |
|
| 852 |
geraldo |
1193 |
$jobDescription = new JobDescription();
|
|
|
1194 |
$jobDescription->company_id = $currentCompany->id;
|
|
|
1195 |
$jobDescription->job_description_id_default = $jobDescriptionDefault->id;
|
|
|
1196 |
$jobDescription->name = $jobDescriptionDefault->name;
|
|
|
1197 |
$jobDescription->functions = $jobDescriptionDefault->functions;
|
|
|
1198 |
$jobDescription->objectives = $jobDescriptionDefault->objectives;
|
|
|
1199 |
$jobDescription->status = JobDescription::STATUS_ACTIVE;
|
| 854 |
geraldo |
1200 |
|
| 858 |
geraldo |
1201 |
$result = $jobDescriptionMapper->insert($jobDescription);
|
| 854 |
geraldo |
1202 |
|
| 858 |
geraldo |
1203 |
if ($result) {
|
|
|
1204 |
|
|
|
1205 |
//Add Competencies
|
| 955 |
geraldo |
1206 |
$competenceMapper = CompetencyMapper::getInstance($this->adapter);
|
| 858 |
geraldo |
1207 |
$jobDescriptionCompetencyMapper = JobDescriptionCompetencyMapper::getInstance($this->adapter);
|
| 953 |
geraldo |
1208 |
$jobDescriptionCompetencies = $jobDescriptionCompetencyMapper->fetchByJobDescriptionId($jobDescriptionDefault->id);
|
| 939 |
geraldo |
1209 |
|
| 953 |
geraldo |
1210 |
if (count($jobDescriptionCompetencies) != 0) {
|
|
|
1211 |
foreach ($jobDescriptionCompetencies as $record) {
|
| 955 |
geraldo |
1212 |
|
|
|
1213 |
$competence = $competenceMapper->fetchOneByCompanyIdAndCompetencyIdDefault($currentCompany->id, $record->competency_id);
|
| 956 |
geraldo |
1214 |
if ($competence) {
|
|
|
1215 |
$newDescriptionCompetency = new JobDescriptionCompetency();
|
|
|
1216 |
$newDescriptionCompetency->competency_id = $competence->id;
|
|
|
1217 |
$newDescriptionCompetency->job_description_id = $jobDescription->id;
|
|
|
1218 |
$newDescriptionCompetency->level = $record->level;
|
|
|
1219 |
$jobDescriptionCompetencyMapper->insert($newDescriptionCompetency);
|
| 955 |
geraldo |
1220 |
}
|
| 858 |
geraldo |
1221 |
}
|
|
|
1222 |
}
|
|
|
1223 |
|
| 852 |
geraldo |
1224 |
$new_records++;
|
|
|
1225 |
} else {
|
|
|
1226 |
$data = [
|
|
|
1227 |
'success' => false,
|
|
|
1228 |
'data' => 'ERROR_CANT_ADD_JOB_DESCRIPTION'
|
|
|
1229 |
];
|
| 854 |
geraldo |
1230 |
|
| 852 |
geraldo |
1231 |
return new JsonModel($data);
|
|
|
1232 |
}
|
|
|
1233 |
}
|
|
|
1234 |
}
|
| 854 |
geraldo |
1235 |
|
|
|
1236 |
if ($new_records) {
|
|
|
1237 |
|
|
|
1238 |
if (1 == $new_records) {
|
| 852 |
geraldo |
1239 |
$data = [
|
|
|
1240 |
'success' => true,
|
|
|
1241 |
'data' => 'LABEL_1_JOB_DESCRIPTION_IMPORTED'
|
|
|
1242 |
];
|
| 854 |
geraldo |
1243 |
|
| 852 |
geraldo |
1244 |
return new JsonModel($data);
|
|
|
1245 |
} else {
|
|
|
1246 |
$data = [
|
|
|
1247 |
'success' => true,
|
| 854 |
geraldo |
1248 |
'data' => $new_records . ' LABEL_MULTI_JOB_DESCRIPTION_IMPORTED'
|
| 852 |
geraldo |
1249 |
];
|
| 854 |
geraldo |
1250 |
|
| 852 |
geraldo |
1251 |
return new JsonModel($data);
|
|
|
1252 |
}
|
|
|
1253 |
} else {
|
|
|
1254 |
$data = [
|
|
|
1255 |
'success' => true,
|
|
|
1256 |
'data' => 'LABEL_NO_JOB_DESCRIPTION_IMPORTED'
|
|
|
1257 |
];
|
| 854 |
geraldo |
1258 |
|
| 852 |
geraldo |
1259 |
return new JsonModel($data);
|
|
|
1260 |
}
|
|
|
1261 |
} else {
|
|
|
1262 |
$data = [
|
|
|
1263 |
'success' => false,
|
|
|
1264 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
1265 |
];
|
| 854 |
geraldo |
1266 |
|
| 852 |
geraldo |
1267 |
return new JsonModel($data);
|
|
|
1268 |
}
|
| 854 |
geraldo |
1269 |
|
| 852 |
geraldo |
1270 |
return new JsonModel($data);
|
| 850 |
geraldo |
1271 |
}
|
|
|
1272 |
|
| 14203 |
stevensc |
1273 |
public function reportAction()
|
|
|
1274 |
{
|
| 561 |
geraldo |
1275 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
1276 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
1277 |
$currentCompany = $currentUserPlugin->getCompany();
|
| 649 |
geraldo |
1278 |
|
| 561 |
geraldo |
1279 |
$request = $this->getRequest();
|
|
|
1280 |
$uuid = $this->params()->fromRoute('id');
|
|
|
1281 |
|
| 649 |
geraldo |
1282 |
|
|
|
1283 |
if (!$uuid) {
|
| 561 |
geraldo |
1284 |
$data = [
|
| 649 |
geraldo |
1285 |
'success' => false,
|
|
|
1286 |
'data' => 'ERROR_INVALID_PARAMETER'
|
| 561 |
geraldo |
1287 |
];
|
| 649 |
geraldo |
1288 |
|
| 561 |
geraldo |
1289 |
return new JsonModel($data);
|
|
|
1290 |
}
|
|
|
1291 |
|
|
|
1292 |
$jobDescriptionMapper = JobDescriptionMapper::getInstance($this->adapter);
|
|
|
1293 |
$jobDescription = $jobDescriptionMapper->fetchOneByUuid($uuid);
|
| 649 |
geraldo |
1294 |
if (!$jobDescription) {
|
| 561 |
geraldo |
1295 |
$data = [
|
| 649 |
geraldo |
1296 |
'success' => false,
|
|
|
1297 |
'data' => 'ERROR_RECORD_NOT_FOUND'
|
| 561 |
geraldo |
1298 |
];
|
| 649 |
geraldo |
1299 |
|
| 561 |
geraldo |
1300 |
return new JsonModel($data);
|
|
|
1301 |
}
|
| 649 |
geraldo |
1302 |
|
| 851 |
geraldo |
1303 |
if ($currentCompany && $jobDescription->company_id != $currentCompany->id) {
|
| 561 |
geraldo |
1304 |
$data = [
|
| 649 |
geraldo |
1305 |
'success' => false,
|
|
|
1306 |
'data' => 'ERROR_UNAUTHORIZED'
|
| 561 |
geraldo |
1307 |
];
|
| 649 |
geraldo |
1308 |
|
| 561 |
geraldo |
1309 |
return new JsonModel($data);
|
|
|
1310 |
}
|
|
|
1311 |
|
| 649 |
geraldo |
1312 |
|
| 561 |
geraldo |
1313 |
if ($request->isGet()) {
|
|
|
1314 |
|
| 15444 |
efrain |
1315 |
|
|
|
1316 |
|
| 15403 |
efrain |
1317 |
$filename = Functions::normalizeStringFilename($jobDescription->name . '-' . date('Y-m-d H:i a') . '.pdf');
|
| 1213 |
geraldo |
1318 |
|
| 15403 |
efrain |
1319 |
|
| 15444 |
efrain |
1320 |
|
|
|
1321 |
|
| 15403 |
efrain |
1322 |
$content = base64_encode($this->renderPdf($currentCompany, $jobDescription));
|
| 15444 |
efrain |
1323 |
$data = [
|
|
|
1324 |
'success' => true,
|
|
|
1325 |
'data' => [
|
|
|
1326 |
'basename' => $filename,
|
|
|
1327 |
'content' => $content
|
|
|
1328 |
]
|
|
|
1329 |
];
|
| 15403 |
efrain |
1330 |
|
| 15444 |
efrain |
1331 |
return new JsonModel($data);
|
|
|
1332 |
|
| 15403 |
efrain |
1333 |
/*
|
| 15444 |
efrain |
1334 |
|
|
|
1335 |
$content = $this->renderPdf($currentCompany, $jobDescription);
|
| 15403 |
efrain |
1336 |
$response = new Response();
|
|
|
1337 |
$response->setStatusCode(200);
|
|
|
1338 |
$response->setContent($content);
|
|
|
1339 |
|
|
|
1340 |
|
|
|
1341 |
|
|
|
1342 |
$headers = $response->getHeaders();
|
|
|
1343 |
$headers->clearHeaders();
|
|
|
1344 |
|
|
|
1345 |
$headers->addHeaderLine('Content-Description: File Transfer');
|
|
|
1346 |
$headers->addHeaderLine('Content-Type: application/pdf');
|
|
|
1347 |
//$headers->addHeaderLine('Content-Disposition: attachment; filename=' . $filename);
|
|
|
1348 |
$headers->addHeaderLine('Content-Transfer-Encoding: binary');
|
|
|
1349 |
$headers->addHeaderLine('Expires: 0');
|
|
|
1350 |
$headers->addHeaderLine('Cache-Control: must-revalidate');
|
|
|
1351 |
$headers->addHeaderLine('Pragma: public');
|
|
|
1352 |
return $response;
|
| 15444 |
efrain |
1353 |
*/
|
| 15403 |
efrain |
1354 |
|
| 15444 |
efrain |
1355 |
|
| 15403 |
efrain |
1356 |
|
|
|
1357 |
|
| 561 |
geraldo |
1358 |
} else {
|
|
|
1359 |
$data = [
|
|
|
1360 |
'success' => false,
|
|
|
1361 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
1362 |
];
|
| 649 |
geraldo |
1363 |
|
| 561 |
geraldo |
1364 |
return new JsonModel($data);
|
|
|
1365 |
}
|
| 649 |
geraldo |
1366 |
|
| 561 |
geraldo |
1367 |
return new JsonModel($data);
|
|
|
1368 |
}
|
| 15403 |
efrain |
1369 |
|
|
|
1370 |
|
| 842 |
geraldo |
1371 |
|
| 15403 |
efrain |
1372 |
|
|
|
1373 |
|
| 788 |
geraldo |
1374 |
/**
|
|
|
1375 |
* Render PDF
|
| 15079 |
efrain |
1376 |
* @param Company $company;
|
| 1336 |
efrain |
1377 |
* @param JobDescription $jobDescription
|
|
|
1378 |
* @return mixed
|
| 788 |
geraldo |
1379 |
*/
|
| 15403 |
efrain |
1380 |
private function renderPDF($company, $jobDescription)
|
| 14203 |
stevensc |
1381 |
{
|
| 561 |
geraldo |
1382 |
|
|
|
1383 |
//Generate New PDF
|
| 15403 |
efrain |
1384 |
$pdf = new JobDescriptionPdf();
|
|
|
1385 |
$pdf->SetTitle($jobDescription->name);
|
| 842 |
geraldo |
1386 |
|
| 15079 |
efrain |
1387 |
|
|
|
1388 |
$target_path = $this->config['leaderslinked.fullpath.company'] . DIRECTORY_SEPARATOR . $company->uuid;
|
|
|
1389 |
|
|
|
1390 |
$header = $company->header ? $target_path . DIRECTORY_SEPARATOR . $company->header : '';
|
|
|
1391 |
if(empty($header) || !file_exists($header)) {
|
|
|
1392 |
$header = $this->config['leaderslinked.images_default.company_pdf_header'];
|
|
|
1393 |
}
|
|
|
1394 |
|
|
|
1395 |
$footer = $company->footer ? $target_path . DIRECTORY_SEPARATOR . $company->footer : '';
|
|
|
1396 |
if(empty($footer) || !file_exists($footer)) {
|
|
|
1397 |
$footer = $this->config['leaderslinked.images_default.company_pdf_footer'];
|
|
|
1398 |
}
|
|
|
1399 |
|
|
|
1400 |
$pdf->header = $header;
|
|
|
1401 |
$pdf->footer = $footer;
|
| 15403 |
efrain |
1402 |
$pdf->translator = $this->translator;
|
| 842 |
geraldo |
1403 |
|
| 561 |
geraldo |
1404 |
|
| 927 |
geraldo |
1405 |
$pdf->SetMargins(10, 0, 10);
|
| 714 |
geraldo |
1406 |
|
| 561 |
geraldo |
1407 |
$pdf->AliasNbPages();
|
|
|
1408 |
$pdf->AddPage();
|
| 564 |
geraldo |
1409 |
|
| 697 |
geraldo |
1410 |
// Add Title
|
|
|
1411 |
$pdf->customHeader();
|
| 654 |
geraldo |
1412 |
|
| 649 |
geraldo |
1413 |
// Job Description Name
|
| 654 |
geraldo |
1414 |
|
| 649 |
geraldo |
1415 |
$job_descrition[] = array(
|
| 15403 |
efrain |
1416 |
'title' => $this->translator->translate('LABEL_PDF_JOB_DESCRIPTION_LABORAL_CATEGORY') . ' : ' ,
|
| 709 |
geraldo |
1417 |
'content' => ' ' . $jobDescription->name
|
| 649 |
geraldo |
1418 |
);
|
| 654 |
geraldo |
1419 |
|
| 649 |
geraldo |
1420 |
|
| 15403 |
efrain |
1421 |
$pdf->borderTable($this->translator->translate('LABEL_PDF_JOB_TITLE_NAME') . ' : ', $job_descrition);
|
| 649 |
geraldo |
1422 |
|
| 15403 |
efrain |
1423 |
|
| 654 |
geraldo |
1424 |
//Hierarchical Relationship
|
|
|
1425 |
|
| 650 |
geraldo |
1426 |
$jobDescriptionMapper = JobDescriptionMapper::getInstance($this->adapter);
|
| 714 |
geraldo |
1427 |
|
|
|
1428 |
$jobDescriptionSubordinateMapper = JobDescriptionSubordinateMapper::getInstance($this->adapter);
|
| 724 |
geraldo |
1429 |
$jobDescriptionSubordinate = $jobDescriptionSubordinateMapper->fetchAllByJobDescriptionIdTopLevel($jobDescription->id);
|
| 714 |
geraldo |
1430 |
|
|
|
1431 |
$subordinate = '';
|
| 745 |
geraldo |
1432 |
|
|
|
1433 |
if ($jobDescriptionSubordinate) {
|
|
|
1434 |
|
|
|
1435 |
foreach ($jobDescriptionSubordinate as $rs) {
|
| 725 |
geraldo |
1436 |
$jobSubordinate = $jobDescriptionMapper->fetchOne($rs->job_description_id_low_level);
|
| 745 |
geraldo |
1437 |
if ($jobSubordinate) {
|
|
|
1438 |
$subordinate .= $jobSubordinate->name . ' ';
|
|
|
1439 |
}
|
| 717 |
geraldo |
1440 |
}
|
|
|
1441 |
}
|
| 714 |
geraldo |
1442 |
|
| 649 |
geraldo |
1443 |
$jobDescriptionBoss = $jobDescriptionMapper->fetchOne($jobDescription->job_description_id_boss);
|
|
|
1444 |
|
| 654 |
geraldo |
1445 |
$relationship = [
|
| 15403 |
efrain |
1446 |
[
|
|
|
1447 |
'title' => $this->translator->translate('LABEL_PDF_JOB_SUPERVISES') . ': ',
|
| 726 |
geraldo |
1448 |
'content' => $subordinate ? ' ' . $subordinate : ' No aplica'
|
| 15403 |
efrain |
1449 |
],
|
|
|
1450 |
[
|
|
|
1451 |
'title' => $this->translator->translate('LABEL_PDF_JOB_SUPERVISED_BY') . ': ',
|
|
|
1452 |
'content' => $jobDescriptionBoss ? ' ' . $jobDescriptionBoss->name : ' ' . $this->translator->translate('LABEL_PDF_JOB_DOES_NOT_APPLY'),
|
|
|
1453 |
]
|
| 654 |
geraldo |
1454 |
];
|
| 579 |
geraldo |
1455 |
|
| 15403 |
efrain |
1456 |
$pdf->borderTable($this->translator->translate('LABEL_PDF_JOB_HIERARCHICAL_RELATIONSHIP') . ' : ', $relationship);
|
| 628 |
geraldo |
1457 |
|
| 654 |
geraldo |
1458 |
// Objetives
|
| 628 |
geraldo |
1459 |
|
| 1259 |
geraldo |
1460 |
$objetives[] = array('content' => strip_tags($jobDescription->objectives));
|
| 15403 |
efrain |
1461 |
$pdf->borderTable($this->translator->translate('LABEL_PDF_JOB_OBJECTIVES') . ' : ', $objetives);
|
| 653 |
geraldo |
1462 |
|
| 654 |
geraldo |
1463 |
// Functions
|
| 628 |
geraldo |
1464 |
|
| 1259 |
geraldo |
1465 |
$functions[] = array('content' => strip_tags($jobDescription->functions));
|
| 15403 |
efrain |
1466 |
$pdf->borderTable($this->translator->translate('LABEL_PDF_JOB_PRINCIPAL_FUNCTIONS') . ' : ', $functions);
|
| 628 |
geraldo |
1467 |
|
| 749 |
geraldo |
1468 |
// add section signature
|
| 709 |
geraldo |
1469 |
$pdf->sectionSignature();
|
|
|
1470 |
|
| 654 |
geraldo |
1471 |
//Competencies
|
| 628 |
geraldo |
1472 |
|
| 658 |
geraldo |
1473 |
$jobDescriptionCompetencyMapper = JobDescriptionCompetencyMapper::getInstance($this->adapter);
|
| 15444 |
efrain |
1474 |
$jobDescriptionCompetencies = $jobDescriptionCompetencyMapper->fetchAllByJobDescriptionId($jobDescription->id);
|
| 649 |
geraldo |
1475 |
|
| 672 |
geraldo |
1476 |
$competencyMapper = CompetencyMapper::getInstance($this->adapter);
|
| 933 |
geraldo |
1477 |
$competenceTypeMapper = CompetencyTypeMapper::getInstance($this->adapter);
|
| 15030 |
efrain |
1478 |
$competencyBehaviorMapper = CompetencyBehaviorMapper::getInstance($this->adapter);
|
| 15403 |
efrain |
1479 |
$jobDescriptionCompetencyBehaviorMapper = JobDescriptionCompetencyBehaviorMapper::getInstance($this->adapter);
|
| 1320 |
efrain |
1480 |
$behaviorMapper = BehaviorMapper::getInstance($this->adapter);
|
| 842 |
geraldo |
1481 |
|
| 939 |
geraldo |
1482 |
|
| 15444 |
efrain |
1483 |
$max = count($jobDescriptionCompetencies);
|
| 672 |
geraldo |
1484 |
|
| 15444 |
efrain |
1485 |
if ($max) {
|
| 842 |
geraldo |
1486 |
|
| 748 |
geraldo |
1487 |
// add new page
|
| 842 |
geraldo |
1488 |
|
| 748 |
geraldo |
1489 |
$pdf->AddPage();
|
| 679 |
geraldo |
1490 |
|
| 745 |
geraldo |
1491 |
$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 |
1492 |
|
| 745 |
geraldo |
1493 |
$pdf->singleTable('Competencias requeridas para el cargo:', $competencies_header);
|
| 709 |
geraldo |
1494 |
|
| 745 |
geraldo |
1495 |
|
|
|
1496 |
// Add scale section
|
| 15444 |
efrain |
1497 |
// $pdf->sectionScale();
|
| 745 |
geraldo |
1498 |
|
|
|
1499 |
|
| 15444 |
efrain |
1500 |
for ($i = 0; $i < $max; $i++) {
|
| 745 |
geraldo |
1501 |
|
| 15444 |
efrain |
1502 |
$record = $jobDescriptionCompetencies[$i];
|
|
|
1503 |
|
| 15030 |
efrain |
1504 |
$behaviorCompetencies = $competencyBehaviorMapper->fetchAllByCompetencyId($record->competency_id);
|
| 1213 |
geraldo |
1505 |
$behaviors = [];
|
|
|
1506 |
|
|
|
1507 |
foreach ($behaviorCompetencies as $rows) {
|
|
|
1508 |
|
|
|
1509 |
$behavior = $behaviorMapper->fetchOne($rows->behavior_id);
|
| 15444 |
efrain |
1510 |
if ($behavior) {
|
|
|
1511 |
$jobDescriptionCompetencyBehavior = $jobDescriptionCompetencyBehaviorMapper->fetchOneByJobDescriptionIdAndCompetencyIdAndBehaviorId($jobDescription->id, $record->competency_id, $rows->behavior_id);
|
|
|
1512 |
if($jobDescriptionCompetencyBehavior) {
|
|
|
1513 |
$level = $jobDescriptionCompetencyBehavior->level;
|
|
|
1514 |
} else {
|
|
|
1515 |
$level = 0;
|
|
|
1516 |
}
|
| 1213 |
geraldo |
1517 |
|
|
|
1518 |
array_push($behaviors, [
|
|
|
1519 |
'description' => $behavior->description,
|
| 15444 |
efrain |
1520 |
'level' => $level
|
| 1213 |
geraldo |
1521 |
]);
|
|
|
1522 |
}
|
|
|
1523 |
}
|
|
|
1524 |
|
| 745 |
geraldo |
1525 |
$competency = $competencyMapper->fetchOne($record->competency_id);
|
| 933 |
geraldo |
1526 |
$competenceType = $competenceTypeMapper->fetchOne($competency->competency_type_id);
|
| 745 |
geraldo |
1527 |
|
| 15444 |
efrain |
1528 |
$j = $i + 1;
|
|
|
1529 |
$last = $j == $max;
|
|
|
1530 |
|
|
|
1531 |
$pdf->competencyTable($j, $competenceType, $competency, $behaviors, $last);
|
|
|
1532 |
|
|
|
1533 |
if(!$last) {
|
|
|
1534 |
$y = $pdf->getY();
|
|
|
1535 |
if($y >= JobDescriptionPdf::MAX_Y_ADD_PAGE) {
|
|
|
1536 |
$this->addPage();
|
|
|
1537 |
}
|
|
|
1538 |
}
|
| 933 |
geraldo |
1539 |
|
| 709 |
geraldo |
1540 |
}
|
| 669 |
geraldo |
1541 |
}
|
| 15403 |
efrain |
1542 |
|
|
|
1543 |
/*
|
|
|
1544 |
|
|
|
1545 |
$temp_file = tempnam(sys_get_temp_dir(), 'job-description');
|
|
|
1546 |
$pdf->Output('F', $temp_file);
|
| 658 |
geraldo |
1547 |
|
| 15403 |
efrain |
1548 |
return $temp_file;*/
|
|
|
1549 |
|
| 15444 |
efrain |
1550 |
|
|
|
1551 |
|
| 15403 |
efrain |
1552 |
return $pdf->Output('S');
|
| 561 |
geraldo |
1553 |
}
|
| 15079 |
efrain |
1554 |
|
| 15403 |
efrain |
1555 |
|
|
|
1556 |
|
| 15079 |
efrain |
1557 |
|
| 66 |
efrain |
1558 |
}
|