553 |
geraldo |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
/**
|
|
|
4 |
*
|
|
|
5 |
* Controlador: Autoevaluación
|
|
|
6 |
*
|
|
|
7 |
*/
|
|
|
8 |
declare(strict_types=1);
|
|
|
9 |
|
|
|
10 |
namespace LeadersLinked\Controller;
|
|
|
11 |
|
|
|
12 |
use Laminas\Db\Adapter\AdapterInterface;
|
|
|
13 |
use Laminas\Cache\Storage\Adapter\AbstractAdapter;
|
|
|
14 |
use Laminas\Mvc\Controller\AbstractActionController;
|
|
|
15 |
use Laminas\Log\LoggerInterface;
|
|
|
16 |
use Laminas\View\Model\ViewModel;
|
|
|
17 |
use Laminas\View\Model\JsonModel;
|
|
|
18 |
use LeadersLinked\Model\Notification;
|
|
|
19 |
use LeadersLinked\Mapper\CompanyPerformanceEvaluationTestMapper;
|
|
|
20 |
use LeadersLinked\Mapper\NotificationMapper;
|
|
|
21 |
use LeadersLinked\Mapper\QueryMapper;
|
|
|
22 |
use LeadersLinked\Model\CompanyPerformanceEvaluationForm;
|
|
|
23 |
use LeadersLinked\Mapper\CompanyPerformanceEvaluationFormMapper;
|
|
|
24 |
use LeadersLinked\Model\CompanyPerformanceEvaluationTest;
|
|
|
25 |
use Laminas\Db\Sql\Select;
|
|
|
26 |
use LeadersLinked\Mapper\CompanyPerformanceEvaluationFormUserMapper;
|
|
|
27 |
use LeadersLinked\Form\PerformanceEvaluation\PerformanceEvaluationTestForm;
|
561 |
geraldo |
28 |
use LeadersLinked\Mapper\JobDescriptionMapper;
|
553 |
geraldo |
29 |
use LeadersLinked\Library\Functions;
|
|
|
30 |
|
|
|
31 |
class PerformanceEvaluationController extends AbstractActionController {
|
|
|
32 |
|
|
|
33 |
/**
|
|
|
34 |
*
|
|
|
35 |
* @var AdapterInterface
|
|
|
36 |
*/
|
|
|
37 |
private $adapter;
|
|
|
38 |
|
|
|
39 |
/**
|
|
|
40 |
*
|
|
|
41 |
* @var AbstractAdapter
|
|
|
42 |
*/
|
|
|
43 |
private $cache;
|
|
|
44 |
|
|
|
45 |
/**
|
|
|
46 |
*
|
|
|
47 |
* @var LoggerInterface
|
|
|
48 |
*/
|
|
|
49 |
private $logger;
|
|
|
50 |
|
|
|
51 |
/**
|
|
|
52 |
*
|
|
|
53 |
* @var array
|
|
|
54 |
*/
|
|
|
55 |
private $config;
|
|
|
56 |
|
|
|
57 |
/**
|
|
|
58 |
*
|
|
|
59 |
* @param AdapterInterface $adapter
|
|
|
60 |
* @param AbstractAdapter $cache
|
|
|
61 |
* @param LoggerInterface $logger
|
|
|
62 |
* @param array $config
|
|
|
63 |
*/
|
|
|
64 |
public function __construct($adapter, $cache, $logger, $config) {
|
|
|
65 |
$this->adapter = $adapter;
|
|
|
66 |
$this->cache = $cache;
|
|
|
67 |
$this->logger = $logger;
|
|
|
68 |
$this->config = $config;
|
|
|
69 |
}
|
|
|
70 |
|
|
|
71 |
/**
|
|
|
72 |
*
|
|
|
73 |
* Generación del listado de evaluaciones
|
|
|
74 |
* {@inheritDoc}
|
|
|
75 |
* @see \Laminas\Mvc\Controller\AbstractActionController::indexAction()
|
|
|
76 |
*/
|
|
|
77 |
public function indexAction() {
|
|
|
78 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
79 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
80 |
|
|
|
81 |
$request = $this->getRequest();
|
561 |
geraldo |
82 |
|
553 |
geraldo |
83 |
if ($request->isGet()) {
|
561 |
geraldo |
84 |
|
553 |
geraldo |
85 |
$headers = $request->getHeaders();
|
|
|
86 |
$isJson = false;
|
|
|
87 |
if ($headers->has('Accept')) {
|
|
|
88 |
$accept = $headers->get('Accept');
|
|
|
89 |
|
|
|
90 |
$prioritized = $accept->getPrioritized();
|
|
|
91 |
|
|
|
92 |
foreach ($prioritized as $key => $value) {
|
|
|
93 |
$raw = trim($value->getRaw());
|
|
|
94 |
|
|
|
95 |
if (!$isJson) {
|
|
|
96 |
$isJson = strpos($raw, 'json');
|
|
|
97 |
}
|
|
|
98 |
}
|
|
|
99 |
}
|
|
|
100 |
|
|
|
101 |
if ($isJson) {
|
|
|
102 |
$search = trim(filter_var($this->params()->fromQuery('search', ''), FILTER_SANITIZE_STRING));
|
|
|
103 |
|
|
|
104 |
|
|
|
105 |
$acl = $this->getEvent()->getViewModel()->getVariable('acl');
|
556 |
geraldo |
106 |
$allowTakeATest = $acl->isAllowed($currentUser->usertype_id, 'profile/performance-evaluation/take-a-test');
|
|
|
107 |
$allowReport = $acl->isAllowed($currentUser->usertype_id, 'profile/performance-evaluation/report');
|
553 |
geraldo |
108 |
|
|
|
109 |
$queryMapper = QueryMapper::getInstance($this->adapter);
|
|
|
110 |
|
|
|
111 |
$select = $queryMapper->getSql()->select();
|
556 |
geraldo |
112 |
$select->columns(['uuid', 'name', 'description', 'text', 'job_description_id']);
|
553 |
geraldo |
113 |
$select->from(['f' => CompanyPerformanceEvaluationFormMapper::_TABLE]);
|
|
|
114 |
$select->join(['fu' => CompanyPerformanceEvaluationFormUserMapper::_TABLE], 'f.id = fu.form_id', []);
|
|
|
115 |
$select->join(['t' => CompanyPerformanceEvaluationTestMapper::_TABLE], 'fu.form_id = t.form_id AND fu.user_id = t.user_id', ['status'], Select::JOIN_LEFT_OUTER);
|
|
|
116 |
$select->where->equalTo('f.status', CompanyPerformanceEvaluationForm::STATUS_ACTIVE);
|
|
|
117 |
$select->where->equalTo('fu.user_id', $currentUser->id);
|
|
|
118 |
|
|
|
119 |
|
|
|
120 |
if ($search) {
|
|
|
121 |
$select->where->NEST->like('name', '%' . $search . '%');
|
|
|
122 |
}
|
556 |
geraldo |
123 |
$select->order('name ASC, job_description_id ASC');
|
553 |
geraldo |
124 |
|
|
|
125 |
$records = $queryMapper->fetchAll($select);
|
|
|
126 |
$items = [];
|
561 |
geraldo |
127 |
|
|
|
128 |
$jobDescriptionMapper = JobDescriptionMapper::getInstance($this->adapter);
|
|
|
129 |
|
553 |
geraldo |
130 |
foreach ($records as $record) {
|
|
|
131 |
|
561 |
geraldo |
132 |
|
553 |
geraldo |
133 |
switch ($record['status']) {
|
|
|
134 |
|
|
|
135 |
case CompanyPerformanceEvaluationTest::STATUS_DRAFT :
|
|
|
136 |
$status = 'LABEL_DRAFT';
|
|
|
137 |
break;
|
|
|
138 |
|
|
|
139 |
case CompanyPerformanceEvaluationTest::STATUS_COMPLETED :
|
|
|
140 |
$status = 'LABEL_COMPLETED';
|
|
|
141 |
break;
|
|
|
142 |
|
|
|
143 |
case CompanyPerformanceEvaluationTest::STATUS_PENDING :
|
|
|
144 |
$status = 'LABEL_PENDING';
|
|
|
145 |
break;
|
|
|
146 |
|
|
|
147 |
case CompanyPerformanceEvaluationTest::STATUS_REVIEW :
|
|
|
148 |
$status = 'LABEL_REVIEW';
|
|
|
149 |
break;
|
|
|
150 |
|
|
|
151 |
|
|
|
152 |
default :
|
|
|
153 |
$status = 'LABEL_AVAILABLE';
|
|
|
154 |
break;
|
|
|
155 |
}
|
|
|
156 |
|
563 |
geraldo |
157 |
$jobDescription = $jobDescriptionMapper->fetchOne($record['job_description_id']);
|
561 |
geraldo |
158 |
if ($jobDescription) {
|
|
|
159 |
$item = [
|
|
|
160 |
'name' => $record['name'],
|
|
|
161 |
'description' => $record['description'],
|
|
|
162 |
'text' => $record['text'],
|
|
|
163 |
'job_description' => $jobDescription->name,
|
|
|
164 |
'status' => $status,
|
582 |
geraldo |
165 |
'link_take_a_test' => $allowTakeATest && ( empty($record['status']) || $record['status'] == CompanyPerformanceEvaluationTest::STATUS_DRAFT) ? $this->url()->fromRoute('profile/performance-evaluation/take-a-test', ['id' => $record['uuid']]) : '',
|
|
|
166 |
'link_report' => $allowReport && $record['status'] == CompanyPerformanceEvaluationTest::STATUS_COMPLETED ? $this->url()->fromRoute('profile/performance-evaluation/report', ['id' => $record['uuid']]) : '',
|
561 |
geraldo |
167 |
];
|
553 |
geraldo |
168 |
|
561 |
geraldo |
169 |
array_push($items, $item);
|
|
|
170 |
}
|
553 |
geraldo |
171 |
}
|
|
|
172 |
|
|
|
173 |
|
|
|
174 |
|
|
|
175 |
|
|
|
176 |
$response = [
|
|
|
177 |
'success' => true,
|
|
|
178 |
'data' => $items
|
|
|
179 |
];
|
|
|
180 |
|
|
|
181 |
return new JsonModel($response);
|
|
|
182 |
} else {
|
|
|
183 |
|
|
|
184 |
$notificationMapper = NotificationMapper::getInstance($this->adapter);
|
|
|
185 |
$notificationMapper->markAllNotificationsAsReadByTypeAndUserId(Notification::TYPE_ACCEPT_MY_REQUEST_CONNECTION, $currentUser->id);
|
|
|
186 |
|
|
|
187 |
$this->layout()->setTemplate('layout/layout.phtml');
|
|
|
188 |
$viewModel = new ViewModel();
|
556 |
geraldo |
189 |
$viewModel->setTemplate('leaders-linked/performance-evaluation/index.phtml');
|
553 |
geraldo |
190 |
return $viewModel;
|
|
|
191 |
}
|
|
|
192 |
} else {
|
|
|
193 |
return new JsonModel([
|
|
|
194 |
'success' => false,
|
|
|
195 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
196 |
]);
|
|
|
197 |
}
|
|
|
198 |
}
|
|
|
199 |
|
|
|
200 |
public function takeaTestAction() {
|
571 |
geraldo |
201 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
202 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
203 |
|
|
|
204 |
$uuid = $this->params()->fromRoute('id');
|
|
|
205 |
|
|
|
206 |
$companyPerformanceEvaluationFormMapper = CompanyPerformanceEvaluationFormMapper::getInstance($this->adapter);
|
|
|
207 |
$companyPerformanceEvaluationForm = $companyPerformanceEvaluationFormMapper->fetchOneByUuid($uuid);
|
|
|
208 |
|
|
|
209 |
if (!$companyPerformanceEvaluationForm) {
|
|
|
210 |
return new JsonModel([
|
|
|
211 |
'success' => false,
|
|
|
212 |
'data' => 'ERROR_FORM_EVALUATION_NOT_FOUND'
|
|
|
213 |
]);
|
|
|
214 |
}
|
|
|
215 |
|
|
|
216 |
if ($companyPerformanceEvaluationForm->status == CompanyPerformanceEvaluationForm::STATUS_INACTIVE) {
|
|
|
217 |
return new JsonModel([
|
|
|
218 |
'success' => false,
|
|
|
219 |
'data' => 'ERROR_FORM_EVALUATION_IS_INACTIVE'
|
|
|
220 |
]);
|
|
|
221 |
}
|
|
|
222 |
|
|
|
223 |
|
|
|
224 |
$companyPerformanceEvaluationFormUserMapper = CompanyPerformanceEvaluationFormUserMapper::getInstance($this->adapter);
|
|
|
225 |
$companyPerformanceEvaluationFormUser = $companyPerformanceEvaluationFormUserMapper->fetchOneByFormIdAndUserId($companyPerformanceEvaluationForm->id, $currentUser->id);
|
|
|
226 |
if (!$companyPerformanceEvaluationFormUser) {
|
|
|
227 |
return new JsonModel([
|
|
|
228 |
'success' => false,
|
|
|
229 |
'data' => 'ERROR_FORM_EVALUATION_YOU_CAN_NOT_TAKE'
|
|
|
230 |
]);
|
|
|
231 |
}
|
|
|
232 |
|
|
|
233 |
|
|
|
234 |
$companyPerformanceEvaluationTestMapper = CompanyPerformanceEvaluationTestMapper::getInstance($this->adapter);
|
|
|
235 |
$companyPerformanceEvaluationTest = $companyPerformanceEvaluationTestMapper->fetchOneBy($companyPerformanceEvaluationForm->id, $currentUser->id);
|
|
|
236 |
|
|
|
237 |
if ($companyPerformanceEvaluationTest && $companyPerformanceEvaluationTest->status != CompanyPerformanceEvaluationTest::STATUS_DRAFT) {
|
|
|
238 |
return new JsonModel([
|
|
|
239 |
'success' => false,
|
|
|
240 |
'data' => 'ERROR_FORM_EVALUATION_ALREADY_YOUR_APPLICATION_IN_THIS_TEST'
|
|
|
241 |
]);
|
|
|
242 |
}
|
|
|
243 |
|
|
|
244 |
|
|
|
245 |
$request = $this->getRequest();
|
|
|
246 |
if ($request->isGet()) {
|
|
|
247 |
return new JsonModel([
|
585 |
geraldo |
248 |
'success' => true,
|
571 |
geraldo |
249 |
'data' => [
|
|
|
250 |
'name' => $companyPerformanceEvaluationForm->name,
|
|
|
251 |
'description' => $companyPerformanceEvaluationForm->description,
|
|
|
252 |
'text' => $companyPerformanceEvaluationForm->text,
|
|
|
253 |
'content' => $companyPerformanceEvaluationTest && $companyPerformanceEvaluationTest->status == CompanyPerformanceEvaluationTest::STATUS_DRAFT ?
|
|
|
254 |
json_decode($companyPerformanceEvaluationTest->content) :
|
|
|
255 |
json_decode($companyPerformanceEvaluationForm->content),
|
|
|
256 |
]
|
|
|
257 |
]);
|
|
|
258 |
}
|
|
|
259 |
|
|
|
260 |
if ($request->isPost()) {
|
|
|
261 |
$form = new PerformanceEvaluationTestForm();
|
|
|
262 |
$dataPost = $request->getPost()->toArray();
|
|
|
263 |
|
|
|
264 |
$form->setData($dataPost);
|
|
|
265 |
|
|
|
266 |
if ($form->isValid()) {
|
|
|
267 |
$dataPost = (array) $form->getData();
|
|
|
268 |
|
|
|
269 |
$selfEvaluationTest = new CompanyPerformanceEvaluationTest();
|
|
|
270 |
$selfEvaluationTest->company_id = $companyPerformanceEvaluationForm->company_id;
|
|
|
271 |
$selfEvaluationTest->form_id = $companyPerformanceEvaluationForm->id;
|
|
|
272 |
$selfEvaluationTest->user_id = $currentUser->id;
|
|
|
273 |
$selfEvaluationTest->status = $dataPost['status'];
|
|
|
274 |
$selfEvaluationTest->content = $dataPost['content'];
|
|
|
275 |
|
|
|
276 |
|
|
|
277 |
//Check if the form is already registered
|
|
|
278 |
$companyPerformanceEvaluationTest = $companyPerformanceEvaluationTestMapper->fetchOneBy($companyPerformanceEvaluationForm->id, $currentUser->id);
|
|
|
279 |
|
|
|
280 |
$result = $companyPerformanceEvaluationTest ?
|
|
|
281 |
$companyPerformanceEvaluationTestMapper->update($selfEvaluationTest, $companyPerformanceEvaluationTest->id) :
|
|
|
282 |
$companyPerformanceEvaluationTestMapper->insert($selfEvaluationTest);
|
|
|
283 |
|
|
|
284 |
|
|
|
285 |
if ($result) {
|
|
|
286 |
$this->logger->info('Se agrego un nuevo test de auto-evaluación : ' . $companyPerformanceEvaluationForm->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
|
|
|
287 |
|
|
|
288 |
$data = [
|
|
|
289 |
'success' => true,
|
|
|
290 |
'data' => $companyPerformanceEvaluationTest ? 'LABEL_RECORD_UPDATED' : 'LABEL_RECORD_ADDED'
|
|
|
291 |
];
|
|
|
292 |
} else {
|
|
|
293 |
$data = [
|
|
|
294 |
'success' => false,
|
|
|
295 |
'data' => $companyPerformanceEvaluationTestMapper->getError()
|
|
|
296 |
];
|
|
|
297 |
}
|
|
|
298 |
|
|
|
299 |
return new JsonModel($data);
|
|
|
300 |
} else {
|
|
|
301 |
$messages = [];
|
|
|
302 |
$form_messages = (array) $form->getMessages();
|
|
|
303 |
foreach ($form_messages as $fieldname => $field_messages) {
|
|
|
304 |
|
|
|
305 |
$messages[$fieldname] = array_values($field_messages);
|
|
|
306 |
}
|
|
|
307 |
|
|
|
308 |
return new JsonModel([
|
|
|
309 |
'success' => false,
|
|
|
310 |
'data' => $messages
|
|
|
311 |
]);
|
|
|
312 |
}
|
|
|
313 |
}
|
|
|
314 |
|
553 |
geraldo |
315 |
return new JsonModel([
|
|
|
316 |
'success' => false,
|
|
|
317 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
318 |
]);
|
571 |
geraldo |
319 |
}
|
570 |
geraldo |
320 |
|
553 |
geraldo |
321 |
}
|