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