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