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