15444 |
efrain |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
declare(strict_types=1);
|
|
|
4 |
|
|
|
5 |
namespace LeadersLinked\Controller;
|
|
|
6 |
|
|
|
7 |
use Laminas\Db\Adapter\AdapterInterface;
|
16768 |
efrain |
8 |
|
15444 |
efrain |
9 |
use Laminas\Mvc\Controller\AbstractActionController;
|
|
|
10 |
use Laminas\Mvc\I18n\Translator;
|
|
|
11 |
use Laminas\Log\LoggerInterface;
|
|
|
12 |
use Laminas\View\Model\ViewModel;
|
|
|
13 |
use Laminas\View\Model\JsonModel;
|
|
|
14 |
use LeadersLinked\Mapper\QueryMapper;
|
|
|
15 |
use LeadersLinked\Mapper\UserMapper;
|
|
|
16 |
use Laminas\Hydrator\ArraySerializableHydrator;
|
|
|
17 |
use Laminas\Db\ResultSet\HydratingResultSet;
|
|
|
18 |
use Laminas\Paginator\Adapter\DbSelect;
|
|
|
19 |
use Laminas\Paginator\Paginator;
|
|
|
20 |
use LeadersLinked\Mapper\PerformanceEvaluationTestMapper;
|
|
|
21 |
use LeadersLinked\Mapper\PerformanceEvaluationFormMapper;
|
|
|
22 |
use LeadersLinked\Model\PerformanceEvaluationTest;
|
|
|
23 |
use LeadersLinked\Form\PerformanceEvaluation\PerformanceEvaluationTestForm;
|
|
|
24 |
use Laminas\Hydrator\ObjectPropertyHydrator;
|
|
|
25 |
use LeadersLinked\Library\Functions;
|
|
|
26 |
use LeadersLinked\Library\PerformanceEvaluationInterviewPDF;
|
|
|
27 |
|
|
|
28 |
class PerformanceEvaluationTestController extends AbstractActionController {
|
|
|
29 |
|
|
|
30 |
/**
|
|
|
31 |
*
|
16769 |
efrain |
32 |
* @var \Laminas\Db\Adapter\AdapterInterface
|
15444 |
efrain |
33 |
*/
|
|
|
34 |
private $adapter;
|
16769 |
efrain |
35 |
|
15444 |
efrain |
36 |
/**
|
|
|
37 |
*
|
16769 |
efrain |
38 |
* @var \LeadersLinked\Cache\CacheInterface
|
15444 |
efrain |
39 |
*/
|
16769 |
efrain |
40 |
private $cache;
|
|
|
41 |
|
|
|
42 |
|
|
|
43 |
/**
|
|
|
44 |
*
|
|
|
45 |
* @var \Laminas\Log\LoggerInterface
|
|
|
46 |
*/
|
15444 |
efrain |
47 |
private $logger;
|
16769 |
efrain |
48 |
|
15444 |
efrain |
49 |
/**
|
|
|
50 |
*
|
|
|
51 |
* @var array
|
|
|
52 |
*/
|
|
|
53 |
private $config;
|
16769 |
efrain |
54 |
|
|
|
55 |
|
15444 |
efrain |
56 |
/**
|
|
|
57 |
*
|
16769 |
efrain |
58 |
* @var \Laminas\Mvc\I18n\Translator
|
15444 |
efrain |
59 |
*/
|
|
|
60 |
private $translator;
|
|
|
61 |
|
16769 |
efrain |
62 |
|
15444 |
efrain |
63 |
/**
|
|
|
64 |
*
|
16769 |
efrain |
65 |
* @param \Laminas\Db\Adapter\AdapterInterface $adapter
|
|
|
66 |
* @param \LeadersLinked\Cache\CacheInterface $cache
|
|
|
67 |
* @param \Laminas\Log\LoggerInterface LoggerInterface $logger
|
15444 |
efrain |
68 |
* @param array $config
|
16769 |
efrain |
69 |
* @param \Laminas\Mvc\I18n\Translator $translator
|
15444 |
efrain |
70 |
*/
|
16769 |
efrain |
71 |
public function __construct($adapter, $cache, $logger, $config, $translator)
|
15444 |
efrain |
72 |
{
|
16769 |
efrain |
73 |
$this->adapter = $adapter;
|
|
|
74 |
$this->cache = $cache;
|
|
|
75 |
$this->logger = $logger;
|
|
|
76 |
$this->config = $config;
|
|
|
77 |
$this->translator = $translator;
|
15444 |
efrain |
78 |
}
|
|
|
79 |
|
|
|
80 |
|
|
|
81 |
public function indexAction() {
|
|
|
82 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
83 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
84 |
$currentCompany = $currentUserPlugin->getCompany();
|
|
|
85 |
|
|
|
86 |
|
|
|
87 |
|
|
|
88 |
|
|
|
89 |
|
|
|
90 |
$request = $this->getRequest();
|
|
|
91 |
|
|
|
92 |
if ($request->isGet()) {
|
|
|
93 |
|
|
|
94 |
$headers = $request->getHeaders();
|
|
|
95 |
|
|
|
96 |
$isJson = false;
|
|
|
97 |
if ($headers->has('Accept')) {
|
|
|
98 |
$accept = $headers->get('Accept');
|
|
|
99 |
|
|
|
100 |
$prioritized = $accept->getPrioritized();
|
|
|
101 |
|
|
|
102 |
foreach ($prioritized as $key => $value) {
|
|
|
103 |
$raw = trim($value->getRaw());
|
|
|
104 |
|
|
|
105 |
if (!$isJson) {
|
|
|
106 |
$isJson = strpos($raw, 'json');
|
|
|
107 |
}
|
|
|
108 |
}
|
|
|
109 |
}
|
|
|
110 |
|
|
|
111 |
|
|
|
112 |
if ($isJson) {
|
|
|
113 |
|
|
|
114 |
|
|
|
115 |
$data = [
|
|
|
116 |
'items' => [],
|
|
|
117 |
'total' => 0,
|
|
|
118 |
];
|
|
|
119 |
|
|
|
120 |
|
|
|
121 |
$search = $this->params()->fromQuery('search');
|
16778 |
efrain |
122 |
$search = empty($search['value']) ? '' : Functions::sanitizeFilterString($search['value']);
|
15444 |
efrain |
123 |
|
|
|
124 |
$start = intval($this->params()->fromQuery('start', 0), 10);
|
|
|
125 |
$records_x_page = intval($this->params()->fromQuery('length', 10), 10);
|
|
|
126 |
$page = intval($start / $records_x_page);
|
|
|
127 |
$page++;
|
|
|
128 |
|
|
|
129 |
$order = $this->params()->fromQuery('order', []);
|
|
|
130 |
$order_field = empty($order[0]['column']) ? 99 : intval($order[0]['column'], 10);
|
16766 |
efrain |
131 |
$order_direction = empty($order[0]['dir']) ? 'ASC' : Functions::sanitizeFilterString(filter_var($order[0]['dir']));
|
15444 |
efrain |
132 |
|
|
|
133 |
$fields = ['max_date'];
|
|
|
134 |
$order_field = isset($fields[$order_field]) ? $fields[$order_field] : 'first_name';
|
|
|
135 |
|
|
|
136 |
if (!in_array($order_direction, ['ASC', 'DESC'])) {
|
|
|
137 |
$order_direction = 'ASC';
|
|
|
138 |
}
|
|
|
139 |
|
|
|
140 |
|
|
|
141 |
$acl = $this->getEvent()->getViewModel()->getVariable('acl');
|
|
|
142 |
//$allowDelete = $acl->isAllowed($currentUser->usertype_id, 'performance-evaluation/evaluations/delete');
|
|
|
143 |
|
|
|
144 |
|
|
|
145 |
|
|
|
146 |
$queryMapper = QueryMapper::getInstance($this->adapter);
|
|
|
147 |
$sql = $queryMapper->getSql();
|
|
|
148 |
$select = $sql->select();
|
|
|
149 |
$select->columns([
|
|
|
150 |
'id',
|
|
|
151 |
'uuid',
|
|
|
152 |
'last_date',
|
|
|
153 |
'status',
|
|
|
154 |
'added_on',
|
|
|
155 |
'updated_on'
|
|
|
156 |
]);
|
|
|
157 |
|
|
|
158 |
$select->from(['tb1' => PerformanceEvaluationTestMapper::_TABLE]);
|
|
|
159 |
$select->join(['tb2' => PerformanceEvaluationFormMapper::_TABLE], 'tb1.form_id = tb2.id ', ['form' => 'name']);
|
|
|
160 |
$select->join(['tb3' => UserMapper::_TABLE], 'tb1.supervisor_id = tb3.id ', ['supervisor_first_name' => 'first_name', 'supervisor_last_name' => 'last_name', 'supervisor_email' => 'email']);
|
|
|
161 |
$select->join(['tb4' => UserMapper::_TABLE], 'tb1.employee_id = tb4.id ', ['employee_first_name' => 'first_name', 'employee_last_name' => 'last_name', 'employee_email' => 'email']);
|
|
|
162 |
$select->where->equalTo('tb1.company_id', $currentCompany->id);
|
|
|
163 |
$select->where->equalTo('tb1.type', PerformanceEvaluationTest::TYPE_BOTH);
|
|
|
164 |
|
|
|
165 |
|
|
|
166 |
|
|
|
167 |
if ($search) {
|
|
|
168 |
$select->where->nest()
|
|
|
169 |
->like('tb1.last_date', '%' . $search . '%')
|
|
|
170 |
->or->like('tb2.name', '%' . $search . '%')
|
|
|
171 |
->or->like('tb3.first_name', '%' . $search . '%')
|
|
|
172 |
->or->like('tb3.last_name', '%' . $search . '%')
|
|
|
173 |
->or->like('tb3.email', '%' . $search . '%')
|
|
|
174 |
->or->like('tb4.first_name', '%' . $search . '%')
|
|
|
175 |
->or->like('tb4.last_name', '%' . $search . '%')
|
|
|
176 |
->or->like('tb4.email', '%' . $search . '%')
|
|
|
177 |
->unnest();
|
|
|
178 |
}
|
|
|
179 |
|
|
|
180 |
|
|
|
181 |
$select->order('tb1.last_date DESC, tb2.name ASC');
|
|
|
182 |
|
|
|
183 |
|
|
|
184 |
$hydrator = new ArraySerializableHydrator();
|
|
|
185 |
$resultset = new HydratingResultSet($hydrator);
|
|
|
186 |
|
|
|
187 |
$adapter = new DbSelect($select, $sql, $resultset);
|
|
|
188 |
$paginator = new Paginator($adapter);
|
|
|
189 |
$paginator->setItemCountPerPage($records_x_page);
|
|
|
190 |
$paginator->setCurrentPageNumber($page);
|
|
|
191 |
|
|
|
192 |
|
|
|
193 |
$performanceEvaluationTestMapper = PerformanceEvaluationTestMapper::getInstance($this->adapter);
|
|
|
194 |
|
|
|
195 |
|
|
|
196 |
$items = [];
|
|
|
197 |
$records = $paginator->getCurrentItems();
|
|
|
198 |
foreach ($records as $record)
|
|
|
199 |
{
|
|
|
200 |
//$performanceEvaluationTestEmployee = $performanceEvaluationTestMapper->fetchOneByParentIdAndType($record['id'], PerformanceEvaluationTest::TYPE_EMPLOYEE);
|
|
|
201 |
//$performanceEvaluationTestSupervisor = $performanceEvaluationTestMapper->fetchOneByParentIdAndType($record['id'], PerformanceEvaluationTest::TYPE_SUPERVISOR);
|
|
|
202 |
|
|
|
203 |
|
|
|
204 |
$dt = \DateTime::createFromFormat('Y-m-d', $record['last_date']);
|
|
|
205 |
$last_date = $dt->format('d/m/Y');
|
|
|
206 |
|
|
|
207 |
switch($record['status'])
|
|
|
208 |
{
|
|
|
209 |
case PerformanceEvaluationTest::STATUS_PENDING :
|
|
|
210 |
$status = 'LABEL_PENDING';
|
|
|
211 |
break;
|
|
|
212 |
|
|
|
213 |
case PerformanceEvaluationTest::STATUS_COMPLETED :
|
|
|
214 |
$status = 'LABEL_COMPLETED';
|
|
|
215 |
break;
|
|
|
216 |
|
|
|
217 |
default :
|
|
|
218 |
$status = 'LABEL_UNKNOW';
|
|
|
219 |
break;
|
|
|
220 |
}
|
|
|
221 |
|
|
|
222 |
|
|
|
223 |
$actions = [
|
|
|
224 |
'link_delete' => $this->url()->fromRoute('performance-evaluation/evaluations/delete', ['id' => $record['uuid']]),
|
|
|
225 |
];
|
|
|
226 |
|
|
|
227 |
if($record['status'] == PerformanceEvaluationTest::STATUS_COMPLETED) {
|
|
|
228 |
|
|
|
229 |
$actions['link_pdf_both'] = $this->url()->fromRoute('performance-evaluation/evaluations/report', ['id' => $record['uuid'] ]);
|
|
|
230 |
} else {
|
|
|
231 |
$actions['link_pdf_both'] = '';
|
|
|
232 |
}
|
|
|
233 |
|
|
|
234 |
$performanceEvaluationTestEmployee = $performanceEvaluationTestMapper->fetchOneByParentIdAndType( $record['id'], PerformanceEvaluationTest::TYPE_EMPLOYEE );
|
|
|
235 |
|
|
|
236 |
if($performanceEvaluationTestEmployee->status == PerformanceEvaluationTest::STATUS_COMPLETED) {
|
|
|
237 |
|
|
|
238 |
$actions['link_pdf_employee'] = $this->url()->fromRoute('performance-evaluation/evaluations/report', ['id' => $performanceEvaluationTestEmployee->uuid ]);
|
|
|
239 |
} else {
|
|
|
240 |
$actions['link_pdf_employee'] = '';
|
|
|
241 |
}
|
|
|
242 |
|
|
|
243 |
$performanceEvaluationTestSupervisor = $performanceEvaluationTestMapper->fetchOneByParentIdAndType( $record['id'], PerformanceEvaluationTest::TYPE_SUPERVISOR );
|
|
|
244 |
|
|
|
245 |
if($performanceEvaluationTestSupervisor->status == PerformanceEvaluationTest::STATUS_COMPLETED) {
|
|
|
246 |
|
|
|
247 |
$actions['link_pdf_supervisor'] = $this->url()->fromRoute('performance-evaluation/evaluations/report', ['id' => $performanceEvaluationTestSupervisor->uuid ]);
|
|
|
248 |
} else {
|
|
|
249 |
$actions['link_pdf_supervisor'] = '';
|
|
|
250 |
}
|
|
|
251 |
|
|
|
252 |
|
|
|
253 |
$item = [
|
|
|
254 |
'last_date' => $last_date,
|
|
|
255 |
'form' => $record['form'],
|
|
|
256 |
'supervisor_first_name' => $record['supervisor_first_name'],
|
|
|
257 |
'supervisor_last_name' => $record['supervisor_last_name'],
|
|
|
258 |
'supervisor_email' => $record['supervisor_email'],
|
|
|
259 |
'employee_first_name' => $record['employee_first_name'],
|
|
|
260 |
'employee_last_name' => $record['employee_last_name'],
|
|
|
261 |
'employee_email' => $record['employee_email'],
|
|
|
262 |
'status' => $status,
|
|
|
263 |
'actions' => $actions
|
|
|
264 |
];
|
|
|
265 |
|
|
|
266 |
|
|
|
267 |
array_push($items, $item);
|
|
|
268 |
}
|
|
|
269 |
|
|
|
270 |
$data['items'] = $items;
|
|
|
271 |
$data['total'] = $paginator->getTotalItemCount();
|
|
|
272 |
|
|
|
273 |
|
|
|
274 |
return new JsonModel([
|
|
|
275 |
'success' => true,
|
|
|
276 |
'data' => $data
|
|
|
277 |
]);
|
|
|
278 |
} else {
|
|
|
279 |
|
|
|
280 |
$form = new PerformanceEvaluationTestForm($this->adapter, $currentCompany->id);
|
|
|
281 |
|
|
|
282 |
$this->layout()->setTemplate('layout/layout-backend');
|
|
|
283 |
$viewModel = new ViewModel();
|
|
|
284 |
$viewModel->setTemplate('leaders-linked/performance-evaluation-tests/index.phtml');
|
|
|
285 |
$viewModel->setVariables([
|
|
|
286 |
'form' => $form,
|
|
|
287 |
]);
|
|
|
288 |
return $viewModel;
|
|
|
289 |
}
|
|
|
290 |
} else {
|
|
|
291 |
return new JsonModel([
|
|
|
292 |
'success' => false,
|
|
|
293 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
294 |
]);
|
|
|
295 |
|
|
|
296 |
}
|
|
|
297 |
|
|
|
298 |
}
|
|
|
299 |
|
|
|
300 |
public function addAction()
|
|
|
301 |
{
|
|
|
302 |
$request = $this->getRequest();
|
|
|
303 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
304 |
$currentCompany = $currentUserPlugin->getCompany();
|
|
|
305 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
306 |
|
|
|
307 |
$request = $this->getRequest();
|
|
|
308 |
|
|
|
309 |
|
|
|
310 |
if ($request->isPost()) {
|
|
|
311 |
$dataPost = $request->getPost()->toArray();
|
|
|
312 |
|
|
|
313 |
$dt = \DateTime::createFromFormat('d/m/Y', $dataPost['last_date']);
|
|
|
314 |
if($dt) {
|
|
|
315 |
$dataPost['last_date'] = $dt->format('Y-m-d');
|
|
|
316 |
}
|
|
|
317 |
|
|
|
318 |
|
|
|
319 |
$form = new PerformanceEvaluationTestForm($this->adapter, $currentCompany->id);
|
|
|
320 |
$form->setData($dataPost);
|
|
|
321 |
|
|
|
322 |
if ($form->isValid()) {
|
|
|
323 |
|
|
|
324 |
|
|
|
325 |
$dataPost = (array) $form->getData();
|
|
|
326 |
|
|
|
327 |
$companyPerformanceFormMapper = PerformanceEvaluationFormMapper::getInstance($this->adapter);
|
|
|
328 |
$companyPerformanceForm = $companyPerformanceFormMapper->fetchOneByUuid($dataPost['form_id']);
|
|
|
329 |
|
|
|
330 |
$userMapper = UserMapper::getInstance($this->adapter);
|
|
|
331 |
$supervisor = $userMapper->fetchOneByUuid($dataPost['supervisor_id']);
|
|
|
332 |
$employee = $userMapper->fetchOneByUuid($dataPost['employee_id']);
|
|
|
333 |
|
|
|
334 |
|
|
|
335 |
$performanceEvaluationTest = new PerformanceEvaluationTest();
|
|
|
336 |
$performanceEvaluationTest->company_id = $currentCompany->id;
|
|
|
337 |
$performanceEvaluationTest->form_id = $companyPerformanceForm->id;
|
|
|
338 |
$performanceEvaluationTest->supervisor_id = $supervisor->id;
|
|
|
339 |
$performanceEvaluationTest->employee_id = $employee->id;
|
|
|
340 |
$performanceEvaluationTest->last_date = $dataPost['last_date'];
|
|
|
341 |
$performanceEvaluationTest->type = PerformanceEvaluationTest::TYPE_BOTH;
|
|
|
342 |
$performanceEvaluationTest->status = PerformanceEvaluationTest::STATUS_PENDING;
|
|
|
343 |
$performanceEvaluationTest->content = $companyPerformanceForm->content;
|
|
|
344 |
|
|
|
345 |
|
|
|
346 |
|
|
|
347 |
$performanceTestMapper = PerformanceEvaluationTestMapper::getInstance($this->adapter);
|
|
|
348 |
$result = $performanceTestMapper->insert($performanceEvaluationTest);
|
|
|
349 |
|
|
|
350 |
|
|
|
351 |
if ($result) {
|
|
|
352 |
|
|
|
353 |
$this->logger->info('Se agrego la Evaluación para el Formulario de Evaluación de Desempeño : ' . $companyPerformanceForm->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
|
|
|
354 |
|
|
|
355 |
|
|
|
356 |
$performanceEvaluationTestEmployee = new PerformanceEvaluationTest();
|
|
|
357 |
$performanceEvaluationTestEmployee->company_id = $currentCompany->id;
|
|
|
358 |
$performanceEvaluationTestEmployee->form_id = $companyPerformanceForm->id;
|
|
|
359 |
$performanceEvaluationTestEmployee->employee_id = $employee->id;
|
|
|
360 |
$performanceEvaluationTestEmployee->supervisor_id = $supervisor->id;
|
|
|
361 |
$performanceEvaluationTestEmployee->parent_id = $performanceEvaluationTest->id;
|
|
|
362 |
$performanceEvaluationTestEmployee->last_date = $performanceEvaluationTest->last_date;
|
|
|
363 |
$performanceEvaluationTestEmployee->type = PerformanceEvaluationTest::TYPE_EMPLOYEE;
|
|
|
364 |
$performanceEvaluationTestEmployee->status = PerformanceEvaluationTest::STATUS_PENDING;
|
|
|
365 |
$performanceEvaluationTestEmployee->content = $companyPerformanceForm->content;
|
|
|
366 |
$performanceTestMapper->insert($performanceEvaluationTestEmployee);
|
|
|
367 |
|
|
|
368 |
$performanceEvaluationTestSurpevisor = new PerformanceEvaluationTest();
|
|
|
369 |
$performanceEvaluationTestSurpevisor->company_id = $currentCompany->id;
|
|
|
370 |
$performanceEvaluationTestSurpevisor->form_id = $companyPerformanceForm->id;
|
|
|
371 |
$performanceEvaluationTestSurpevisor->employee_id = $employee->id;
|
|
|
372 |
$performanceEvaluationTestSurpevisor->supervisor_id = $supervisor->id;
|
|
|
373 |
$performanceEvaluationTestSurpevisor->parent_id = $performanceEvaluationTest->id;
|
|
|
374 |
$performanceEvaluationTestSurpevisor->last_date = $performanceEvaluationTest->last_date;
|
|
|
375 |
$performanceEvaluationTestSurpevisor->type = PerformanceEvaluationTest::TYPE_SUPERVISOR;
|
|
|
376 |
$performanceEvaluationTestSurpevisor->status = PerformanceEvaluationTest::STATUS_PENDING;
|
|
|
377 |
$performanceEvaluationTestSurpevisor->content = $companyPerformanceForm->content;
|
|
|
378 |
$performanceTestMapper->insert($performanceEvaluationTestSurpevisor);
|
|
|
379 |
|
|
|
380 |
|
|
|
381 |
$data = [
|
|
|
382 |
'success' => true,
|
|
|
383 |
'data' => 'LABEL_RECORD_ADDED'
|
|
|
384 |
];
|
|
|
385 |
|
|
|
386 |
} else {
|
|
|
387 |
$data = [
|
|
|
388 |
'success' => false,
|
|
|
389 |
'data' => $performanceTestMapper->getError()
|
|
|
390 |
];
|
|
|
391 |
}
|
|
|
392 |
|
|
|
393 |
return new JsonModel($data);
|
|
|
394 |
} else {
|
|
|
395 |
$messages = [];
|
|
|
396 |
$form_messages = (array) $form->getMessages();
|
|
|
397 |
foreach ($form_messages as $fieldname => $field_messages) {
|
|
|
398 |
|
|
|
399 |
$messages[$fieldname] = array_values($field_messages);
|
|
|
400 |
}
|
|
|
401 |
|
|
|
402 |
return new JsonModel([
|
|
|
403 |
'success' => false,
|
|
|
404 |
'data' => $messages
|
|
|
405 |
]);
|
|
|
406 |
}
|
|
|
407 |
} else {
|
|
|
408 |
$data = [
|
|
|
409 |
'success' => false,
|
|
|
410 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
411 |
];
|
|
|
412 |
|
|
|
413 |
return new JsonModel($data);
|
|
|
414 |
}
|
|
|
415 |
|
|
|
416 |
return new JsonModel($data);
|
|
|
417 |
}
|
|
|
418 |
|
|
|
419 |
|
|
|
420 |
public function deleteAction()
|
|
|
421 |
{
|
|
|
422 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
423 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
424 |
$currentCompany = $currentUserPlugin->getCompany();
|
|
|
425 |
|
|
|
426 |
$request = $this->getRequest();
|
|
|
427 |
$uuid = $this->params()->fromRoute('id');
|
|
|
428 |
|
|
|
429 |
if (!$uuid) {
|
|
|
430 |
$data = [
|
|
|
431 |
'success' => false,
|
|
|
432 |
'data' => 'ERROR_INVALID_PARAMETER'
|
|
|
433 |
];
|
|
|
434 |
|
|
|
435 |
return new JsonModel($data);
|
|
|
436 |
}
|
|
|
437 |
|
|
|
438 |
|
|
|
439 |
$performanceTestMapper = PerformanceEvaluationTestMapper::getInstance($this->adapter);
|
|
|
440 |
$performanceTest = $performanceTestMapper->fetchOneByUuid($uuid);
|
|
|
441 |
if (!$performanceTest) {
|
|
|
442 |
$data = [
|
|
|
443 |
'success' => false,
|
|
|
444 |
'data' => 'ERROR_RECORD_NOT_FOUND'
|
|
|
445 |
];
|
|
|
446 |
|
|
|
447 |
return new JsonModel($data);
|
|
|
448 |
}
|
|
|
449 |
|
|
|
450 |
if ($currentCompany && $performanceTest->company_id != $currentCompany->id) {
|
|
|
451 |
$data = [
|
|
|
452 |
'success' => false,
|
|
|
453 |
'data' => 'ERROR_UNAUTHORIZED'
|
|
|
454 |
];
|
|
|
455 |
|
|
|
456 |
return new JsonModel($data);
|
|
|
457 |
}
|
|
|
458 |
|
|
|
459 |
|
|
|
460 |
if ($request->isPost()) {
|
|
|
461 |
$result = $performanceTestMapper->delete($performanceTest);
|
|
|
462 |
if ($result) {
|
|
|
463 |
$performanceFormMapper = PerformanceEvaluationFormMapper::getInstance($this->adapter);
|
|
|
464 |
$performanceForm = $performanceFormMapper->fetchOne($performanceTest->form_id);
|
|
|
465 |
|
|
|
466 |
|
|
|
467 |
$this->logger->info('Se borro una evaluación del formulario ' . $performanceForm->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
|
|
|
468 |
|
|
|
469 |
$data = [
|
|
|
470 |
'success' => true,
|
|
|
471 |
'data' => 'LABEL_RECORD_DELETED'
|
|
|
472 |
];
|
|
|
473 |
} else {
|
|
|
474 |
|
|
|
475 |
$data = [
|
|
|
476 |
'success' => false,
|
|
|
477 |
'data' => $performanceTestMapper->getError()
|
|
|
478 |
];
|
|
|
479 |
|
|
|
480 |
return new JsonModel($data);
|
|
|
481 |
}
|
|
|
482 |
} else {
|
|
|
483 |
$data = [
|
|
|
484 |
'success' => false,
|
|
|
485 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
486 |
];
|
|
|
487 |
|
|
|
488 |
return new JsonModel($data);
|
|
|
489 |
}
|
|
|
490 |
|
|
|
491 |
return new JsonModel($data);
|
|
|
492 |
}
|
|
|
493 |
|
|
|
494 |
public function reportAction()
|
|
|
495 |
{
|
|
|
496 |
$request = $this->getRequest();
|
|
|
497 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
498 |
$currentCompany = $currentUserPlugin->getCompany();
|
|
|
499 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
500 |
|
|
|
501 |
$request = $this->getRequest();
|
|
|
502 |
$uuid = $this->params()->fromRoute('id');
|
|
|
503 |
|
|
|
504 |
if (!$uuid) {
|
|
|
505 |
$data = [
|
|
|
506 |
'success' => false,
|
|
|
507 |
'data' => 'ERROR_INVALID_PARAMETER'
|
|
|
508 |
];
|
|
|
509 |
|
|
|
510 |
return new JsonModel($data);
|
|
|
511 |
}
|
|
|
512 |
|
|
|
513 |
$performanceEvaluationTestMapper = PerformanceEvaluationTestMapper::getInstance($this->adapter);
|
|
|
514 |
$performanceEvaluationTest = $performanceEvaluationTestMapper->fetchOneByUuid($uuid);
|
|
|
515 |
if (!$performanceEvaluationTest) {
|
|
|
516 |
$data = [
|
|
|
517 |
'success' => false,
|
|
|
518 |
'data' => 'ERROR_RECORD_NOT_FOUND'
|
|
|
519 |
];
|
|
|
520 |
|
|
|
521 |
return new JsonModel($data);
|
|
|
522 |
}
|
|
|
523 |
|
|
|
524 |
|
|
|
525 |
if ($performanceEvaluationTest->company_id != $currentCompany->id) {
|
|
|
526 |
return new JsonModel([
|
|
|
527 |
'success' => false,
|
|
|
528 |
'data' => 'ERROR_UNAUTHORIZED'
|
|
|
529 |
]);
|
|
|
530 |
}
|
|
|
531 |
|
|
|
532 |
if ($performanceEvaluationTest->employee_id != $currentUser->id
|
|
|
533 |
&& $performanceEvaluationTest->supervisor_id != $currentUser->id ) {
|
|
|
534 |
return new JsonModel([
|
|
|
535 |
'success' => false,
|
|
|
536 |
'data' => 'ERROR_UNAUTHORIZED'
|
|
|
537 |
]);
|
|
|
538 |
}
|
|
|
539 |
|
|
|
540 |
if($performanceEvaluationTest->status ==PerformanceEvaluationTest::STATUS_PENDING) {
|
|
|
541 |
return new JsonModel([
|
|
|
542 |
'success' => false,
|
|
|
543 |
'data' => 'ERROR_RECORD_IS_PENDING'
|
|
|
544 |
]);
|
|
|
545 |
|
|
|
546 |
}
|
|
|
547 |
|
|
|
548 |
|
|
|
549 |
|
|
|
550 |
$request = $this->getRequest();
|
|
|
551 |
if ($request->isGet()) {
|
|
|
552 |
|
|
|
553 |
switch( $performanceEvaluationTest->type)
|
|
|
554 |
{
|
|
|
555 |
case PerformanceEvaluationTest::TYPE_BOTH :
|
|
|
556 |
$type = $this->translator->translate('LABEL_PERFORMANCE_EVALUATION_TYPE_BOTH');
|
|
|
557 |
break;
|
|
|
558 |
|
|
|
559 |
case PerformanceEvaluationTest::TYPE_SUPERVISOR :
|
|
|
560 |
$type = $this->translator->translate('LABEL_PERFORMANCE_EVALUATION_TYPE_SUPERVISOR');
|
|
|
561 |
break;
|
|
|
562 |
|
|
|
563 |
case PerformanceEvaluationTest::TYPE_EMPLOYEE :
|
|
|
564 |
$type = $this->translator->translate('LABEL_PERFORMANCE_EVALUATION_TYPE_EMPLOYEE');
|
|
|
565 |
break;
|
|
|
566 |
|
|
|
567 |
default :
|
|
|
568 |
$type = $this->translator->translate('LABEL_UNKNOWN');
|
|
|
569 |
break;
|
|
|
570 |
}
|
|
|
571 |
|
|
|
572 |
|
|
|
573 |
$performanceEvaluationFormMapper = PerformanceEvaluationFormMapper::getInstance($this->adapter);
|
|
|
574 |
$performanceEvaluationForm = $performanceEvaluationFormMapper->fetchOne($performanceEvaluationTest->form_id);
|
|
|
575 |
|
|
|
576 |
$userMapper = UserMapper::getInstance($this->adapter);
|
|
|
577 |
$employee = $userMapper->fetchOne($performanceEvaluationTest->employee_id);
|
|
|
578 |
|
|
|
579 |
$filename = $performanceEvaluationForm->name . '-' . trim($employee->first_name) . '-' . trim($employee->last_name) . '-' . $type . '-' . date('Y-m-d H:i a') . '.pdf';
|
|
|
580 |
|
|
|
581 |
$filename = Functions::normalizeStringFilename( $filename );
|
|
|
582 |
|
|
|
583 |
|
|
|
584 |
|
|
|
585 |
|
|
|
586 |
$content = base64_encode($this->renderPDF($performanceEvaluationTest));
|
|
|
587 |
$data = [
|
|
|
588 |
'success' => true,
|
|
|
589 |
'data' => [
|
|
|
590 |
'basename' => $filename,
|
|
|
591 |
'content' => $content
|
|
|
592 |
]
|
|
|
593 |
];
|
|
|
594 |
|
|
|
595 |
return new JsonModel($data);
|
|
|
596 |
|
|
|
597 |
/*
|
|
|
598 |
|
|
|
599 |
$content = $this->renderPdf($currentCompany, $jobDescription);
|
|
|
600 |
$response = new Response();
|
|
|
601 |
$response->setStatusCode(200);
|
|
|
602 |
$response->setContent($content);
|
|
|
603 |
|
|
|
604 |
|
|
|
605 |
|
|
|
606 |
$headers = $response->getHeaders();
|
|
|
607 |
$headers->clearHeaders();
|
|
|
608 |
|
|
|
609 |
$headers->addHeaderLine('Content-Description: File Transfer');
|
|
|
610 |
$headers->addHeaderLine('Content-Type: application/pdf');
|
|
|
611 |
//$headers->addHeaderLine('Content-Disposition: attachment; filename=' . $filename);
|
|
|
612 |
$headers->addHeaderLine('Content-Transfer-Encoding: binary');
|
|
|
613 |
$headers->addHeaderLine('Expires: 0');
|
|
|
614 |
$headers->addHeaderLine('Cache-Control: must-revalidate');
|
|
|
615 |
$headers->addHeaderLine('Pragma: public');
|
|
|
616 |
return $response;
|
|
|
617 |
*/
|
|
|
618 |
|
|
|
619 |
|
|
|
620 |
|
|
|
621 |
|
|
|
622 |
return ;
|
|
|
623 |
} else {
|
|
|
624 |
|
|
|
625 |
|
|
|
626 |
return new JsonModel([
|
|
|
627 |
'success' => false,
|
|
|
628 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
629 |
]);
|
|
|
630 |
}
|
|
|
631 |
}
|
|
|
632 |
|
|
|
633 |
/**
|
|
|
634 |
* Render PDF
|
|
|
635 |
* @param PerformanceEvaluationTest $performanceEvaluationTest
|
|
|
636 |
|
|
|
637 |
* @return mixed
|
|
|
638 |
*/
|
|
|
639 |
private function renderPDF($performanceEvaluationTest)
|
|
|
640 |
{
|
|
|
641 |
$request = $this->getRequest();
|
|
|
642 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
643 |
$currentCompany = $currentUserPlugin->getCompany();
|
|
|
644 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
645 |
|
|
|
646 |
|
|
|
647 |
//Generate New PDF
|
|
|
648 |
$pdf = new PerformanceEvaluationInterviewPDF();
|
|
|
649 |
|
|
|
650 |
$target_path = $this->config['leaderslinked.fullpath.company'] . DIRECTORY_SEPARATOR . $currentCompany->uuid;
|
|
|
651 |
$header = $currentCompany->header ? $target_path . DIRECTORY_SEPARATOR . $currentCompany->header : '';
|
|
|
652 |
if (empty($header) || !file_exists($header)) {
|
|
|
653 |
$header = $this->config['leaderslinked.images_default.company_pdf_header'];
|
|
|
654 |
}
|
|
|
655 |
|
|
|
656 |
$footer = $currentCompany->footer ? $target_path . DIRECTORY_SEPARATOR . $currentCompany->footer : '';
|
|
|
657 |
if (empty($footer) || !file_exists($footer)) {
|
|
|
658 |
$footer = $this->config['leaderslinked.images_default.company_pdf_footer'];
|
|
|
659 |
}
|
|
|
660 |
|
|
|
661 |
$content = json_decode($performanceEvaluationTest->content);
|
|
|
662 |
|
|
|
663 |
$pdf->header = $header;
|
|
|
664 |
$pdf->footer = $footer;
|
|
|
665 |
$pdf->translator = $this->translator;
|
|
|
666 |
|
|
|
667 |
$pdf->SetMargins(10, 0, 10);
|
|
|
668 |
|
|
|
669 |
$pdf->AliasNbPages();
|
|
|
670 |
$pdf->AddPage();
|
|
|
671 |
|
|
|
672 |
switch( $performanceEvaluationTest->type)
|
|
|
673 |
{
|
|
|
674 |
case PerformanceEvaluationTest::TYPE_BOTH :
|
|
|
675 |
$type = $this->translator->translate('LABEL_PERFORMANCE_EVALUATION_TYPE_BOTH');
|
|
|
676 |
break;
|
|
|
677 |
|
|
|
678 |
case PerformanceEvaluationTest::TYPE_SUPERVISOR :
|
|
|
679 |
$type = $this->translator->translate('LABEL_PERFORMANCE_EVALUATION_TYPE_SUPERVISOR');
|
|
|
680 |
break;
|
|
|
681 |
|
|
|
682 |
case PerformanceEvaluationTest::TYPE_EMPLOYEE :
|
|
|
683 |
$type = $this->translator->translate('LABEL_PERFORMANCE_EVALUATION_TYPE_EMPLOYEE');
|
|
|
684 |
break;
|
|
|
685 |
|
|
|
686 |
default :
|
|
|
687 |
$type = $this->translator->translate('LABEL_UNKNOWN');
|
|
|
688 |
break;
|
|
|
689 |
}
|
|
|
690 |
|
|
|
691 |
$dt = \DateTime::createFromFormat('Y-m-d H:i:s', $performanceEvaluationTest->updated_on);
|
|
|
692 |
|
|
|
693 |
$evaluated = '';
|
|
|
694 |
$evaluator = '';
|
|
|
695 |
|
|
|
696 |
$userMapper = UserMapper::getInstance($this->adapter);
|
|
|
697 |
if($performanceEvaluationTest->employee_id) {
|
|
|
698 |
$user = $userMapper->fetchOne($performanceEvaluationTest->employee_id);
|
|
|
699 |
if($user) {
|
|
|
700 |
$evaluated = ucwords(strtolower(trim($user->first_name . ' ' . $user->last_name)));
|
|
|
701 |
}
|
|
|
702 |
}
|
|
|
703 |
if($performanceEvaluationTest->supervisor_id) {
|
|
|
704 |
$user = $userMapper->fetchOne($performanceEvaluationTest->supervisor_id);
|
|
|
705 |
if($user) {
|
|
|
706 |
$evaluator = ucwords(strtolower(trim($user->first_name . ' ' . $user->last_name)));
|
|
|
707 |
}
|
|
|
708 |
}
|
|
|
709 |
|
|
|
710 |
$rows = [
|
|
|
711 |
[
|
|
|
712 |
'title' => $this->translator->translate('LABEL_TYPE') . ' : ',
|
|
|
713 |
'content' => $type,
|
|
|
714 |
],
|
|
|
715 |
[
|
|
|
716 |
'title' => $this->translator->translate('LABEL_PDF_PERFORMANCE_EVALUATION_POSITION') . ' : ',
|
|
|
717 |
'content' => $content->name,
|
|
|
718 |
],
|
|
|
719 |
[
|
|
|
720 |
'title' => $this->translator->translate('LABEL_PDF_PERFORMANCE_EVALUATION_EVALUATED') . ' : ',
|
16768 |
efrain |
721 |
'content' => Functions::utf8_decode($evaluated),
|
15444 |
efrain |
722 |
],
|
|
|
723 |
|
|
|
724 |
[
|
|
|
725 |
'title' => $this->translator->translate('LABEL_PDF_PERFORMANCE_EVALUATION_EVALUATE_SIGNATURE') . ' : ',
|
|
|
726 |
'content' => ''
|
|
|
727 |
],
|
|
|
728 |
[
|
|
|
729 |
'title' => $this->translator->translate('LABEL_PDF_PERFORMANCE_EVALUATION_EVALUATOR') . ' : ',
|
16768 |
efrain |
730 |
'content' => Functions::utf8_decode($evaluator),
|
15444 |
efrain |
731 |
],
|
|
|
732 |
[
|
|
|
733 |
'title' => $this->translator->translate('LABEL_PDF_PERFORMANCE_EVALUATION_EVALUATOR_SIGNATURE') . ' : ',
|
|
|
734 |
'content' => ''
|
|
|
735 |
],
|
|
|
736 |
[
|
|
|
737 |
'title' => $this->translator->translate( 'LABEL_PDF_PERFORMANCE_EVALUATION_MANAGER_SIGNATURE') . ' : ',
|
|
|
738 |
'content' => ''
|
|
|
739 |
],
|
|
|
740 |
[
|
|
|
741 |
'title' => $this->translator->translate('LABEL_DATE'),
|
|
|
742 |
'content' => $dt->format('d/m/Y H:i a')
|
|
|
743 |
]
|
|
|
744 |
];
|
|
|
745 |
|
|
|
746 |
|
|
|
747 |
|
|
|
748 |
$pdf->borderTable($this->translator->translate('LABEL_PDF_PERFORMANCE_EVALUATION_TITLE'), $rows);
|
|
|
749 |
|
|
|
750 |
$pdf->evaluationTable($content->comment, $content->points);
|
|
|
751 |
|
|
|
752 |
|
|
|
753 |
|
|
|
754 |
// Competencies
|
|
|
755 |
if ($content->competencies_selected) {
|
|
|
756 |
$pdf->AddPage();
|
|
|
757 |
|
|
|
758 |
$i = 0;
|
|
|
759 |
|
|
|
760 |
$max = count($content->competencies_selected);
|
|
|
761 |
for($i = 0; $i < $max; $i++)
|
|
|
762 |
{
|
|
|
763 |
$competency_selected = $content->competencies_selected[$i];
|
|
|
764 |
|
|
|
765 |
$j = $i + 1;
|
|
|
766 |
$last = $j == $max;
|
|
|
767 |
$pdf->competencyTable($i, $competency_selected, $content->competencies, $content->competency_types, $content->behaviors, $content->evaluation, $last);
|
|
|
768 |
}
|
|
|
769 |
|
|
|
770 |
}
|
|
|
771 |
|
|
|
772 |
return $pdf->Output('S');
|
|
|
773 |
}
|
|
|
774 |
|
|
|
775 |
}
|