| 279 |
efrain |
1 |
<?php
|
| 431 |
geraldo |
2 |
|
| 279 |
efrain |
3 |
/**
|
|
|
4 |
*
|
| 291 |
geraldo |
5 |
* Controlador: Autoevaluación
|
| 279 |
efrain |
6 |
*
|
|
|
7 |
*/
|
|
|
8 |
declare(strict_types=1);
|
|
|
9 |
|
|
|
10 |
namespace LeadersLinked\Controller;
|
|
|
11 |
|
|
|
12 |
use Laminas\Db\Adapter\AdapterInterface;
|
| 6849 |
efrain |
13 |
|
| 279 |
efrain |
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;
|
| 4283 |
efrain |
19 |
use LeadersLinked\Mapper\SelfEvaluationTestMapper;
|
| 279 |
efrain |
20 |
use LeadersLinked\Mapper\NotificationMapper;
|
|
|
21 |
use LeadersLinked\Mapper\QueryMapper;
|
| 4283 |
efrain |
22 |
use LeadersLinked\Model\SelfEvaluationForm;
|
|
|
23 |
use LeadersLinked\Mapper\SelfEvaluationFormMapper;
|
|
|
24 |
use LeadersLinked\Model\SelfEvaluationTest;
|
| 279 |
efrain |
25 |
use Laminas\Db\Sql\Select;
|
| 523 |
geraldo |
26 |
use LeadersLinked\Library\SelfEvaluationPDF;
|
| 4283 |
efrain |
27 |
use LeadersLinked\Mapper\SelfEvaluationFormUserMapper;
|
| 279 |
efrain |
28 |
use LeadersLinked\Form\SelfEvaluation\SelfEvaluationTestForm;
|
|
|
29 |
use LeadersLinked\Library\Functions;
|
| 630 |
efrain |
30 |
use LeadersLinked\Mapper\UserMapper;
|
| 279 |
efrain |
31 |
|
| 431 |
geraldo |
32 |
class SelfEvaluationController extends AbstractActionController {
|
|
|
33 |
|
| 279 |
efrain |
34 |
/**
|
|
|
35 |
*
|
| 6866 |
efrain |
36 |
* @var \Laminas\Db\Adapter\AdapterInterface
|
| 279 |
efrain |
37 |
*/
|
|
|
38 |
private $adapter;
|
| 6866 |
efrain |
39 |
|
| 279 |
efrain |
40 |
/**
|
|
|
41 |
*
|
| 6866 |
efrain |
42 |
* @var \LeadersLinked\Cache\CacheInterface
|
| 279 |
efrain |
43 |
*/
|
| 6866 |
efrain |
44 |
private $cache;
|
|
|
45 |
|
|
|
46 |
|
|
|
47 |
/**
|
|
|
48 |
*
|
|
|
49 |
* @var \Laminas\Log\LoggerInterface
|
|
|
50 |
*/
|
| 279 |
efrain |
51 |
private $logger;
|
| 6866 |
efrain |
52 |
|
| 279 |
efrain |
53 |
/**
|
|
|
54 |
*
|
|
|
55 |
* @var array
|
|
|
56 |
*/
|
|
|
57 |
private $config;
|
| 6866 |
efrain |
58 |
|
|
|
59 |
|
| 279 |
efrain |
60 |
/**
|
|
|
61 |
*
|
| 6866 |
efrain |
62 |
* @var \Laminas\Mvc\I18n\Translator
|
|
|
63 |
*/
|
|
|
64 |
private $translator;
|
|
|
65 |
|
|
|
66 |
|
|
|
67 |
/**
|
|
|
68 |
*
|
|
|
69 |
* @param \Laminas\Db\Adapter\AdapterInterface $adapter
|
|
|
70 |
* @param \LeadersLinked\Cache\CacheInterface $cache
|
|
|
71 |
* @param \Laminas\Log\LoggerInterface LoggerInterface $logger
|
| 279 |
efrain |
72 |
* @param array $config
|
| 6866 |
efrain |
73 |
* @param \Laminas\Mvc\I18n\Translator $translator
|
| 279 |
efrain |
74 |
*/
|
| 6866 |
efrain |
75 |
public function __construct($adapter, $cache, $logger, $config, $translator)
|
|
|
76 |
{
|
|
|
77 |
$this->adapter = $adapter;
|
|
|
78 |
$this->cache = $cache;
|
|
|
79 |
$this->logger = $logger;
|
|
|
80 |
$this->config = $config;
|
|
|
81 |
$this->translator = $translator;
|
| 431 |
geraldo |
82 |
}
|
| 279 |
efrain |
83 |
|
|
|
84 |
/**
|
|
|
85 |
*
|
| 291 |
geraldo |
86 |
* Generación del listado de evaluaciones
|
| 279 |
efrain |
87 |
* {@inheritDoc}
|
|
|
88 |
* @see \Laminas\Mvc\Controller\AbstractActionController::indexAction()
|
|
|
89 |
*/
|
| 431 |
geraldo |
90 |
public function indexAction() {
|
| 279 |
efrain |
91 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
92 |
$currentUser = $currentUserPlugin->getUser();
|
| 431 |
geraldo |
93 |
|
| 279 |
efrain |
94 |
$request = $this->getRequest();
|
| 431 |
geraldo |
95 |
if ($request->isGet()) {
|
|
|
96 |
|
|
|
97 |
|
|
|
98 |
$headers = $request->getHeaders();
|
| 279 |
efrain |
99 |
$isJson = false;
|
| 431 |
geraldo |
100 |
if ($headers->has('Accept')) {
|
| 279 |
efrain |
101 |
$accept = $headers->get('Accept');
|
| 431 |
geraldo |
102 |
|
| 279 |
efrain |
103 |
$prioritized = $accept->getPrioritized();
|
| 431 |
geraldo |
104 |
|
|
|
105 |
foreach ($prioritized as $key => $value) {
|
| 279 |
efrain |
106 |
$raw = trim($value->getRaw());
|
| 431 |
geraldo |
107 |
|
|
|
108 |
if (!$isJson) {
|
| 279 |
efrain |
109 |
$isJson = strpos($raw, 'json');
|
|
|
110 |
}
|
|
|
111 |
}
|
|
|
112 |
}
|
| 431 |
geraldo |
113 |
|
|
|
114 |
if ($isJson) {
|
| 6749 |
efrain |
115 |
$search = Functions::sanitizeFilterString($this->params()->fromQuery('search', ''));
|
| 281 |
efrain |
116 |
|
| 431 |
geraldo |
117 |
|
| 281 |
efrain |
118 |
$acl = $this->getEvent()->getViewModel()->getVariable('acl');
|
|
|
119 |
$allowTakeATest = $acl->isAllowed($currentUser->usertype_id, 'profile/self-evaluation/take-a-test');
|
|
|
120 |
$allowReport = $acl->isAllowed($currentUser->usertype_id, 'profile/self-evaluation/report');
|
|
|
121 |
|
|
|
122 |
|
| 279 |
efrain |
123 |
|
| 431 |
geraldo |
124 |
|
| 279 |
efrain |
125 |
$queryMapper = QueryMapper::getInstance($this->adapter);
|
| 431 |
geraldo |
126 |
|
| 279 |
efrain |
127 |
$select = $queryMapper->getSql()->select();
|
| 431 |
geraldo |
128 |
$select->columns(['uuid', 'name', 'description', 'text', 'language']);
|
| 4283 |
efrain |
129 |
$select->from(['f' => SelfEvaluationFormMapper::_TABLE]);
|
|
|
130 |
$select->join(['fu' => SelfEvaluationFormUserMapper::_TABLE], 'f.id = fu.form_id', []);
|
|
|
131 |
$select->join(['t' => SelfEvaluationTestMapper::_TABLE], 'fu.form_id = t.form_id AND fu.user_id = t.user_id', ['status'], Select::JOIN_LEFT_OUTER);
|
|
|
132 |
$select->where->equalTo('f.status', SelfEvaluationForm::STATUS_ACTIVE);
|
| 296 |
efrain |
133 |
$select->where->equalTo('fu.user_id', $currentUser->id);
|
| 431 |
geraldo |
134 |
|
|
|
135 |
|
|
|
136 |
if ($search) {
|
| 279 |
efrain |
137 |
$select->where->NEST->like('name', '%' . $search . '%');
|
|
|
138 |
}
|
|
|
139 |
$select->order('name ASC, language ASC');
|
| 431 |
geraldo |
140 |
|
| 279 |
efrain |
141 |
$records = $queryMapper->fetchAll($select);
|
|
|
142 |
$items = [];
|
| 431 |
geraldo |
143 |
foreach ($records as $record) {
|
|
|
144 |
switch ($record['language']) {
|
| 4283 |
efrain |
145 |
case SelfEvaluationForm::LANGUAGE_ENGLISH :
|
| 279 |
efrain |
146 |
$language = 'LABEL_ENGLISH';
|
|
|
147 |
break;
|
| 431 |
geraldo |
148 |
|
| 4283 |
efrain |
149 |
case SelfEvaluationForm::LANGUAGE_SPANISH :
|
| 279 |
efrain |
150 |
$language = 'LABEL_SPANISH';
|
|
|
151 |
break;
|
| 431 |
geraldo |
152 |
|
|
|
153 |
default :
|
| 279 |
efrain |
154 |
$language = '';
|
|
|
155 |
break;
|
|
|
156 |
}
|
| 431 |
geraldo |
157 |
|
|
|
158 |
switch ($record['status']) {
|
|
|
159 |
|
| 4283 |
efrain |
160 |
case SelfEvaluationTest::STATUS_DRAFT :
|
| 431 |
geraldo |
161 |
$status = 'LABEL_DRAFT';
|
|
|
162 |
break;
|
|
|
163 |
|
| 4283 |
efrain |
164 |
case SelfEvaluationTest::STATUS_COMPLETED :
|
| 279 |
efrain |
165 |
$status = 'LABEL_COMPLETED';
|
|
|
166 |
break;
|
| 431 |
geraldo |
167 |
|
| 4283 |
efrain |
168 |
case SelfEvaluationTest::STATUS_PENDING :
|
| 279 |
efrain |
169 |
$status = 'LABEL_PENDING';
|
|
|
170 |
break;
|
| 431 |
geraldo |
171 |
|
| 4283 |
efrain |
172 |
case SelfEvaluationTest::STATUS_REVIEW :
|
| 279 |
efrain |
173 |
$status = 'LABEL_REVIEW';
|
|
|
174 |
break;
|
| 431 |
geraldo |
175 |
|
|
|
176 |
|
|
|
177 |
default :
|
| 281 |
efrain |
178 |
$status = 'LABEL_AVAILABLE';
|
| 279 |
efrain |
179 |
break;
|
|
|
180 |
}
|
| 431 |
geraldo |
181 |
|
|
|
182 |
|
| 279 |
efrain |
183 |
$item = [
|
| 431 |
geraldo |
184 |
'name' => $record['name'],
|
| 279 |
efrain |
185 |
'description' => $record['description'],
|
| 431 |
geraldo |
186 |
'text' => $record['text'],
|
| 279 |
efrain |
187 |
'language' => $language,
|
|
|
188 |
'status' => $status,
|
| 4283 |
efrain |
189 |
'link_take_a_test' => $allowTakeATest && ( empty($record['status']) || $record['status'] == SelfEvaluationTest::STATUS_DRAFT) ? $this->url()->fromRoute('profile/self-evaluation/take-a-test', ['id' => $record['uuid']]) : '',
|
|
|
190 |
'link_report' => $allowReport && $record['status'] == SelfEvaluationTest::STATUS_COMPLETED ? $this->url()->fromRoute('profile/self-evaluation/report', ['id' => $record['uuid']]) : '',
|
| 279 |
efrain |
191 |
];
|
|
|
192 |
|
| 431 |
geraldo |
193 |
|
|
|
194 |
|
| 279 |
efrain |
195 |
array_push($items, $item);
|
|
|
196 |
}
|
|
|
197 |
|
| 431 |
geraldo |
198 |
|
|
|
199 |
|
|
|
200 |
|
| 279 |
efrain |
201 |
$response = [
|
|
|
202 |
'success' => true,
|
| 493 |
geraldo |
203 |
'data' => $items
|
| 279 |
efrain |
204 |
];
|
| 431 |
geraldo |
205 |
|
| 279 |
efrain |
206 |
return new JsonModel($response);
|
|
|
207 |
} else {
|
| 431 |
geraldo |
208 |
|
| 279 |
efrain |
209 |
$notificationMapper = NotificationMapper::getInstance($this->adapter);
|
|
|
210 |
$notificationMapper->markAllNotificationsAsReadByTypeAndUserId(Notification::TYPE_ACCEPT_MY_REQUEST_CONNECTION, $currentUser->id);
|
| 431 |
geraldo |
211 |
|
| 279 |
efrain |
212 |
$this->layout()->setTemplate('layout/layout.phtml');
|
|
|
213 |
$viewModel = new ViewModel();
|
|
|
214 |
$viewModel->setTemplate('leaders-linked/self-evaluation/index.phtml');
|
| 431 |
geraldo |
215 |
return $viewModel;
|
| 279 |
efrain |
216 |
}
|
|
|
217 |
} else {
|
|
|
218 |
return new JsonModel([
|
|
|
219 |
'success' => false,
|
|
|
220 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
221 |
]);
|
|
|
222 |
}
|
|
|
223 |
}
|
| 431 |
geraldo |
224 |
|
|
|
225 |
public function takeaTestAction() {
|
| 279 |
efrain |
226 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
227 |
$currentUser = $currentUserPlugin->getUser();
|
| 431 |
geraldo |
228 |
|
| 279 |
efrain |
229 |
$uuid = $this->params()->fromRoute('id');
|
| 431 |
geraldo |
230 |
|
| 4283 |
efrain |
231 |
$companySelfEvaluationFormMapper = SelfEvaluationFormMapper::getInstance($this->adapter);
|
| 431 |
geraldo |
232 |
$companySelfEvaluationForm = $companySelfEvaluationFormMapper->fetchOneByUuid($uuid);
|
|
|
233 |
|
|
|
234 |
if (!$companySelfEvaluationForm) {
|
| 279 |
efrain |
235 |
return new JsonModel([
|
|
|
236 |
'success' => false,
|
| 561 |
geraldo |
237 |
'data' => 'ERROR_FORM_EVALUATION_NOT_FOUND'
|
| 431 |
geraldo |
238 |
]);
|
| 279 |
efrain |
239 |
}
|
|
|
240 |
|
| 4283 |
efrain |
241 |
if ($companySelfEvaluationForm->status == SelfEvaluationForm::STATUS_INACTIVE) {
|
| 279 |
efrain |
242 |
return new JsonModel([
|
|
|
243 |
'success' => false,
|
| 561 |
geraldo |
244 |
'data' => 'ERROR_FORM_EVALUATION_IS_INACTIVE'
|
| 431 |
geraldo |
245 |
]);
|
| 279 |
efrain |
246 |
}
|
| 431 |
geraldo |
247 |
|
|
|
248 |
|
| 4283 |
efrain |
249 |
$companySelfEvaluationFormUserMapper = SelfEvaluationFormUserMapper::getInstance($this->adapter);
|
| 279 |
efrain |
250 |
$companySelfEvaluationFormUser = $companySelfEvaluationFormUserMapper->fetchOneByFormIdAndUserId($companySelfEvaluationForm->id, $currentUser->id);
|
| 431 |
geraldo |
251 |
if (!$companySelfEvaluationFormUser) {
|
| 279 |
efrain |
252 |
return new JsonModel([
|
|
|
253 |
'success' => false,
|
| 561 |
geraldo |
254 |
'data' => 'ERROR_FORM_EVALUATION_YOU_CAN_NOT_TAKE'
|
| 431 |
geraldo |
255 |
]);
|
| 279 |
efrain |
256 |
}
|
| 431 |
geraldo |
257 |
|
|
|
258 |
|
| 4283 |
efrain |
259 |
$companySelfEvaluationTestMapper = SelfEvaluationTestMapper::getInstance($this->adapter);
|
| 279 |
efrain |
260 |
$companySelfEvaluationTest = $companySelfEvaluationTestMapper->fetchOneBy($companySelfEvaluationForm->id, $currentUser->id);
|
| 431 |
geraldo |
261 |
|
| 4283 |
efrain |
262 |
if ($companySelfEvaluationTest && $companySelfEvaluationTest->status != SelfEvaluationTest::STATUS_DRAFT) {
|
| 279 |
efrain |
263 |
return new JsonModel([
|
|
|
264 |
'success' => false,
|
| 561 |
geraldo |
265 |
'data' => 'ERROR_FORM_EVALUATION_ALREADY_YOUR_APPLICATION_IN_THIS_TEST'
|
| 431 |
geraldo |
266 |
]);
|
| 279 |
efrain |
267 |
}
|
| 431 |
geraldo |
268 |
|
|
|
269 |
|
| 279 |
efrain |
270 |
$request = $this->getRequest();
|
| 431 |
geraldo |
271 |
if ($request->isGet()) {
|
| 279 |
efrain |
272 |
return new JsonModel([
|
| 585 |
geraldo |
273 |
'success' => true,
|
| 441 |
geraldo |
274 |
'data' => [
|
| 279 |
efrain |
275 |
'name' => $companySelfEvaluationForm->name,
|
|
|
276 |
'description' => $companySelfEvaluationForm->description,
|
|
|
277 |
'text' => $companySelfEvaluationForm->text,
|
| 4283 |
efrain |
278 |
'content' => $companySelfEvaluationTest && $companySelfEvaluationTest->status == SelfEvaluationTest::STATUS_DRAFT ?
|
| 441 |
geraldo |
279 |
json_decode($companySelfEvaluationTest->content) :
|
|
|
280 |
json_decode($companySelfEvaluationForm->content),
|
| 279 |
efrain |
281 |
]
|
| 431 |
geraldo |
282 |
]);
|
| 279 |
efrain |
283 |
}
|
| 431 |
geraldo |
284 |
|
|
|
285 |
if ($request->isPost()) {
|
|
|
286 |
$form = new SelfEvaluationTestForm();
|
| 279 |
efrain |
287 |
$dataPost = $request->getPost()->toArray();
|
| 431 |
geraldo |
288 |
|
| 279 |
efrain |
289 |
$form->setData($dataPost);
|
| 431 |
geraldo |
290 |
|
|
|
291 |
if ($form->isValid()) {
|
| 279 |
efrain |
292 |
$dataPost = (array) $form->getData();
|
| 431 |
geraldo |
293 |
|
| 4283 |
efrain |
294 |
$selfEvaluationTest = new SelfEvaluationTest();
|
| 279 |
efrain |
295 |
$selfEvaluationTest->company_id = $companySelfEvaluationForm->company_id;
|
|
|
296 |
$selfEvaluationTest->form_id = $companySelfEvaluationForm->id;
|
|
|
297 |
$selfEvaluationTest->user_id = $currentUser->id;
|
| 431 |
geraldo |
298 |
$selfEvaluationTest->status = $dataPost['status'];
|
| 279 |
efrain |
299 |
$selfEvaluationTest->content = $dataPost['content'];
|
| 431 |
geraldo |
300 |
|
|
|
301 |
|
|
|
302 |
//Check if the form is already registered
|
|
|
303 |
$companySelfEvaluationTest = $companySelfEvaluationTestMapper->fetchOneBy($companySelfEvaluationForm->id, $currentUser->id);
|
|
|
304 |
|
|
|
305 |
$result = $companySelfEvaluationTest ?
|
| 471 |
geraldo |
306 |
$companySelfEvaluationTestMapper->update($selfEvaluationTest, $companySelfEvaluationTest->id) :
|
| 431 |
geraldo |
307 |
$companySelfEvaluationTestMapper->insert($selfEvaluationTest);
|
|
|
308 |
|
|
|
309 |
|
|
|
310 |
if ($result) {
|
| 279 |
efrain |
311 |
$this->logger->info('Se agrego un nuevo test de auto-evaluación : ' . $companySelfEvaluationForm->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
|
| 431 |
geraldo |
312 |
|
| 279 |
efrain |
313 |
$data = [
|
| 431 |
geraldo |
314 |
'success' => true,
|
| 448 |
geraldo |
315 |
'data' => $companySelfEvaluationTest ? 'LABEL_RECORD_UPDATED' : 'LABEL_RECORD_ADDED'
|
| 279 |
efrain |
316 |
];
|
|
|
317 |
} else {
|
|
|
318 |
$data = [
|
| 431 |
geraldo |
319 |
'success' => false,
|
|
|
320 |
'data' => $companySelfEvaluationTestMapper->getError()
|
| 279 |
efrain |
321 |
];
|
|
|
322 |
}
|
| 431 |
geraldo |
323 |
|
| 279 |
efrain |
324 |
return new JsonModel($data);
|
|
|
325 |
} else {
|
|
|
326 |
$messages = [];
|
|
|
327 |
$form_messages = (array) $form->getMessages();
|
| 431 |
geraldo |
328 |
foreach ($form_messages as $fieldname => $field_messages) {
|
|
|
329 |
|
| 279 |
efrain |
330 |
$messages[$fieldname] = array_values($field_messages);
|
|
|
331 |
}
|
| 431 |
geraldo |
332 |
|
| 279 |
efrain |
333 |
return new JsonModel([
|
| 431 |
geraldo |
334 |
'success' => false,
|
|
|
335 |
'data' => $messages
|
| 279 |
efrain |
336 |
]);
|
|
|
337 |
}
|
|
|
338 |
}
|
| 431 |
geraldo |
339 |
|
| 279 |
efrain |
340 |
return new JsonModel([
|
|
|
341 |
'success' => false,
|
|
|
342 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
343 |
]);
|
|
|
344 |
}
|
| 431 |
geraldo |
345 |
|
|
|
346 |
public function reportAction() {
|
| 484 |
geraldo |
347 |
|
| 487 |
geraldo |
348 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
349 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
350 |
|
|
|
351 |
$uuid = $this->params()->fromRoute('id');
|
|
|
352 |
|
| 4283 |
efrain |
353 |
$companySelfEvaluationFormMapper = SelfEvaluationFormMapper::getInstance($this->adapter);
|
| 493 |
geraldo |
354 |
$companySelfEvaluationForm = $companySelfEvaluationFormMapper->fetchOneByUuid($uuid);
|
|
|
355 |
|
|
|
356 |
if (!$companySelfEvaluationForm) {
|
|
|
357 |
return new JsonModel([
|
|
|
358 |
'success' => false,
|
| 561 |
geraldo |
359 |
'data' => 'ERROR_FORM_EVALUATION_NOT_FOUND'
|
| 493 |
geraldo |
360 |
]);
|
|
|
361 |
}
|
|
|
362 |
|
| 4283 |
efrain |
363 |
if ($companySelfEvaluationForm->status == SelfEvaluationForm::STATUS_INACTIVE) {
|
| 493 |
geraldo |
364 |
return new JsonModel([
|
|
|
365 |
'success' => false,
|
| 561 |
geraldo |
366 |
'data' => 'ERROR_FORM_EVALUATION_IS_INACTIVE'
|
| 493 |
geraldo |
367 |
]);
|
|
|
368 |
}
|
|
|
369 |
|
|
|
370 |
|
| 4283 |
efrain |
371 |
$companySelfEvaluationFormUserMapper = SelfEvaluationFormUserMapper::getInstance($this->adapter);
|
| 493 |
geraldo |
372 |
$companySelfEvaluationFormUser = $companySelfEvaluationFormUserMapper->fetchOneByFormIdAndUserId($companySelfEvaluationForm->id, $currentUser->id);
|
|
|
373 |
if (!$companySelfEvaluationFormUser) {
|
|
|
374 |
return new JsonModel([
|
|
|
375 |
'success' => false,
|
| 561 |
geraldo |
376 |
'data' => 'ERROR_FORM_EVALUATION_YOU_CAN_NOT_TAKE'
|
| 493 |
geraldo |
377 |
]);
|
|
|
378 |
}
|
|
|
379 |
|
|
|
380 |
|
| 4283 |
efrain |
381 |
$companySelfEvaluationTestMapper = SelfEvaluationTestMapper::getInstance($this->adapter);
|
| 493 |
geraldo |
382 |
$companySelfEvaluationTest = $companySelfEvaluationTestMapper->fetchOneBy($companySelfEvaluationForm->id, $currentUser->id);
|
| 487 |
geraldo |
383 |
|
| 488 |
geraldo |
384 |
if (!$companySelfEvaluationTest) {
|
| 487 |
geraldo |
385 |
return new JsonModel([
|
|
|
386 |
'success' => false,
|
| 561 |
geraldo |
387 |
'data' => 'ERROR_FORM_EVALUATION_TEST_NOT_FOUND'
|
| 487 |
geraldo |
388 |
]);
|
|
|
389 |
}
|
|
|
390 |
|
| 4283 |
efrain |
391 |
if ($companySelfEvaluationTest->status != SelfEvaluationTest::STATUS_COMPLETED) {
|
| 487 |
geraldo |
392 |
return new JsonModel([
|
|
|
393 |
'success' => false,
|
| 561 |
geraldo |
394 |
'data' => 'ERROR_FORM_EVALUATION_TEST_IS_INCOPLETE'
|
| 487 |
geraldo |
395 |
]);
|
|
|
396 |
}
|
|
|
397 |
|
|
|
398 |
|
|
|
399 |
$request = $this->getRequest();
|
| 504 |
geraldo |
400 |
|
| 487 |
geraldo |
401 |
if ($request->isGet()) {
|
| 504 |
geraldo |
402 |
|
| 506 |
geraldo |
403 |
return $this->renderPDF($companySelfEvaluationForm, $companySelfEvaluationTest, $currentUser);
|
| 493 |
geraldo |
404 |
}
|
| 488 |
geraldo |
405 |
|
| 487 |
geraldo |
406 |
return new JsonModel([
|
|
|
407 |
'success' => false,
|
|
|
408 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
409 |
]);
|
| 279 |
efrain |
410 |
}
|
|
|
411 |
|
| 504 |
geraldo |
412 |
/**
|
|
|
413 |
* Render Pdf document
|
| 4283 |
efrain |
414 |
* @param SelfEvaluationForm $companySelfEvaluationForm
|
|
|
415 |
* @param SelfEvaluationTest $companySelfEvaluationTest
|
| 630 |
efrain |
416 |
* @param UserMapper $userMapper
|
|
|
417 |
* @return mixed
|
| 504 |
geraldo |
418 |
*/
|
|
|
419 |
public function renderPDF($companySelfEvaluationForm, $companySelfEvaluationTest, $userMapper) {
|
|
|
420 |
|
|
|
421 |
// Set Data
|
| 6849 |
efrain |
422 |
$headerFormName = Functions::utf8_decode($companySelfEvaluationForm->name);
|
|
|
423 |
$headerUserName = Functions::utf8_decode('Informe de Auto-evaluación: ' . trim($userMapper->first_name . ' ' . $userMapper->last_name) . ' al ' . date("m-d-Y H:i:s", strtotime($companySelfEvaluationTest->added_on)));
|
| 504 |
geraldo |
424 |
$sections = json_decode($companySelfEvaluationTest->content, true);
|
| 518 |
geraldo |
425 |
$labels = ['Total', 'Logrado'];
|
| 504 |
geraldo |
426 |
|
|
|
427 |
|
|
|
428 |
//Generate New PDF
|
| 523 |
geraldo |
429 |
$pdf = new SelfEvaluationPDF();
|
| 504 |
geraldo |
430 |
|
|
|
431 |
$pdf->AliasNbPages();
|
|
|
432 |
$pdf->AddPage();
|
| 553 |
geraldo |
433 |
|
| 504 |
geraldo |
434 |
// Set header secundary
|
| 523 |
geraldo |
435 |
$pdf->customHeader($headerFormName, $headerUserName);
|
| 504 |
geraldo |
436 |
|
|
|
437 |
$valueFormSections = 0;
|
|
|
438 |
$valueFormQuestions = 0;
|
|
|
439 |
|
|
|
440 |
$countSection = 0;
|
|
|
441 |
|
| 508 |
geraldo |
442 |
for ($i = 0; $i < count($sections); $i++) {
|
| 504 |
geraldo |
443 |
if ($countSection > 1) {
|
|
|
444 |
$countSection = 0;
|
|
|
445 |
$pdf->AddPage();
|
| 523 |
geraldo |
446 |
$pdf->customHeader($headerFormName, $headerUserName);
|
| 504 |
geraldo |
447 |
}
|
|
|
448 |
|
|
|
449 |
$pdf->SetY(70 + (92 * $countSection));
|
|
|
450 |
$totalQuestion = 0;
|
|
|
451 |
|
|
|
452 |
$valueSection = floatval($sections[$i]['value']);
|
|
|
453 |
$valueFormSections = $valueFormSections + $valueSection;
|
|
|
454 |
|
|
|
455 |
for ($j = 0; $j < count($sections[$i]['questions']); $j++) {
|
|
|
456 |
$totalQuestion = $totalQuestion + $this->getPtosAnswer($sections[$i]['questions'][$j]);
|
|
|
457 |
}
|
|
|
458 |
|
|
|
459 |
$values = [$valueSection, $totalQuestion];
|
|
|
460 |
$valueFormQuestions = $valueFormQuestions + $totalQuestion;
|
|
|
461 |
|
|
|
462 |
|
| 553 |
geraldo |
463 |
$filename = 'data' . DIRECTORY_SEPARATOR . 'self-evaluation' . $sections[$i]['slug_section'] . '.png';
|
|
|
464 |
$pdf->PieChart($labels, $values, '', $filename);
|
| 504 |
geraldo |
465 |
$pdf->SetFont('Arial', '', 8);
|
| 6849 |
efrain |
466 |
$pdf->Cell(190, 10, Functions::utf8_decode($sections[$i]['name']), 0, 0, 'C');
|
| 504 |
geraldo |
467 |
$pdf->setY($pdf->getY() + 10);
|
|
|
468 |
// Salto de línea
|
| 509 |
geraldo |
469 |
$pdf->Image($filename, 60, $pdf->getY(), 90);
|
| 504 |
geraldo |
470 |
$pdf->setY($pdf->getY() + 60);
|
|
|
471 |
|
|
|
472 |
$countSection++;
|
|
|
473 |
}
|
|
|
474 |
|
|
|
475 |
$pdf->AddPage();
|
| 523 |
geraldo |
476 |
$pdf->customHeader($headerFormName, $headerUserName);
|
| 504 |
geraldo |
477 |
|
|
|
478 |
$pdf->SetFont('Arial', 'B', 10);
|
| 6849 |
efrain |
479 |
$pdf->Cell(190, 10, Functions::utf8_decode('Desempeño General'), 0, 0, 'C');
|
| 504 |
geraldo |
480 |
$pdf->setY($pdf->getY() + 10);
|
|
|
481 |
|
|
|
482 |
|
|
|
483 |
$values = [$valueFormSections, $valueFormQuestions];
|
|
|
484 |
|
| 553 |
geraldo |
485 |
$filenameGeneral = 'data' . DIRECTORY_SEPARATOR . 'self-evaluation' . uniqid() . '.png';
|
| 523 |
geraldo |
486 |
$pdf->PieChart($labels, $values, '', $filenameGeneral);
|
| 509 |
geraldo |
487 |
$pdf->Image($filenameGeneral, 60, $pdf->getY(), 90);
|
| 504 |
geraldo |
488 |
$pdf->setY($pdf->getY() + 60);
|
|
|
489 |
|
|
|
490 |
|
| 553 |
geraldo |
491 |
if ($companySelfEvaluationTest->comments) {
|
|
|
492 |
|
|
|
493 |
$pdf->SetFont('Arial', 'B', 10);
|
| 6849 |
efrain |
494 |
$pdf->Cell(190, 10, Functions::utf8_decode('Comentarios finales'), 0, 0, 'C');
|
| 542 |
geraldo |
495 |
$pdf->setY($pdf->getY() + 10);
|
| 553 |
geraldo |
496 |
|
|
|
497 |
$pdf->SetFont('Arial', '', 8);
|
| 6849 |
efrain |
498 |
$pdf->MultiCell(180, 8, Functions::utf8_decode($companySelfEvaluationTest->comments));
|
| 542 |
geraldo |
499 |
$pdf->setY(60);
|
| 553 |
geraldo |
500 |
}
|
| 542 |
geraldo |
501 |
|
| 504 |
geraldo |
502 |
return $pdf->Output();
|
|
|
503 |
}
|
|
|
504 |
|
|
|
505 |
/**
|
|
|
506 |
* get total ptos Answer
|
| 630 |
efrain |
507 |
* @param array $question
|
|
|
508 |
* @return int
|
| 504 |
geraldo |
509 |
*/
|
|
|
510 |
public function getPtosAnswer($question) {
|
|
|
511 |
|
|
|
512 |
$ptos = 0;
|
|
|
513 |
|
|
|
514 |
if ($question['type'] == "open" || $question['type'] == "rating-open" || $question['type'] == "rating-range") {
|
|
|
515 |
|
|
|
516 |
$ptos = isset($question['question_value']) ? $question['question_value'] : 0;
|
|
|
517 |
} else {
|
|
|
518 |
if ($question['type'] == 'multiple') {
|
|
|
519 |
|
|
|
520 |
for ($o = 0; $o < count($question['options']); $o++) {
|
|
|
521 |
if (in_array($question['options'][$o]['slug_option'], $question['answer'])) {
|
|
|
522 |
$ptos = $ptos + $question['options'][$o]['value'];
|
|
|
523 |
}
|
|
|
524 |
}
|
|
|
525 |
} else {
|
|
|
526 |
|
|
|
527 |
for ($o = 0; $o < count($question['options']); $o++) {
|
|
|
528 |
if ($question['options'][$o]['slug_option'] == $question['answer']) {
|
|
|
529 |
$ptos = $question['options'][$o]['value'];
|
|
|
530 |
}
|
|
|
531 |
}
|
|
|
532 |
}
|
|
|
533 |
}
|
|
|
534 |
return $ptos;
|
|
|
535 |
}
|
|
|
536 |
|
| 279 |
efrain |
537 |
}
|