133 |
efrain |
1 |
<?php
|
|
|
2 |
/**
|
|
|
3 |
*
|
|
|
4 |
* Controlador: Mis Perfiles
|
|
|
5 |
*
|
|
|
6 |
*/
|
|
|
7 |
declare(strict_types=1);
|
|
|
8 |
|
|
|
9 |
namespace LeadersLinked\Controller;
|
|
|
10 |
|
|
|
11 |
use Laminas\Db\Adapter\AdapterInterface;
|
16768 |
efrain |
12 |
|
133 |
efrain |
13 |
use Laminas\Mvc\Controller\AbstractActionController;
|
|
|
14 |
use Laminas\Log\LoggerInterface;
|
|
|
15 |
use Laminas\View\Model\ViewModel;
|
|
|
16 |
use Laminas\View\Model\JsonModel;
|
|
|
17 |
|
|
|
18 |
use LeadersLinked\Library\Functions;
|
|
|
19 |
use LeadersLinked\Mapper\QueryMapper;
|
|
|
20 |
use LeadersLinked\Mapper\CompanyMapper;
|
|
|
21 |
use LeadersLinked\Mapper\CompanyMicrolearningQuizMapper;
|
|
|
22 |
use LeadersLinked\Form\QuestionCreateOrEditForm;
|
|
|
23 |
use Laminas\Hydrator\ObjectPropertyHydrator;
|
|
|
24 |
use LeadersLinked\Model\CompanyMicrolearningQuestion;
|
|
|
25 |
use LeadersLinked\Mapper\CompanyMicrolearningQuestionMapper;
|
|
|
26 |
use LeadersLinked\Model\CompanyMicroLearningQuiz;
|
|
|
27 |
|
|
|
28 |
class MicrolearningQuestionController extends AbstractActionController
|
|
|
29 |
{
|
|
|
30 |
/**
|
|
|
31 |
*
|
16769 |
efrain |
32 |
* @var \Laminas\Db\Adapter\AdapterInterface
|
133 |
efrain |
33 |
*/
|
|
|
34 |
private $adapter;
|
|
|
35 |
|
|
|
36 |
/**
|
|
|
37 |
*
|
16769 |
efrain |
38 |
* @var \LeadersLinked\Cache\CacheInterface
|
133 |
efrain |
39 |
*/
|
16769 |
efrain |
40 |
private $cache;
|
|
|
41 |
|
|
|
42 |
|
|
|
43 |
/**
|
|
|
44 |
*
|
|
|
45 |
* @var \Laminas\Log\LoggerInterface
|
|
|
46 |
*/
|
133 |
efrain |
47 |
private $logger;
|
|
|
48 |
|
|
|
49 |
/**
|
|
|
50 |
*
|
|
|
51 |
* @var array
|
|
|
52 |
*/
|
|
|
53 |
private $config;
|
|
|
54 |
|
16769 |
efrain |
55 |
|
133 |
efrain |
56 |
/**
|
|
|
57 |
*
|
16769 |
efrain |
58 |
* @var \Laminas\Mvc\I18n\Translator
|
|
|
59 |
*/
|
|
|
60 |
private $translator;
|
|
|
61 |
|
|
|
62 |
|
|
|
63 |
/**
|
|
|
64 |
*
|
|
|
65 |
* @param \Laminas\Db\Adapter\AdapterInterface $adapter
|
|
|
66 |
* @param \LeadersLinked\Cache\CacheInterface $cache
|
|
|
67 |
* @param \Laminas\Log\LoggerInterface LoggerInterface $logger
|
133 |
efrain |
68 |
* @param array $config
|
16769 |
efrain |
69 |
* @param \Laminas\Mvc\I18n\Translator $translator
|
133 |
efrain |
70 |
*/
|
16769 |
efrain |
71 |
public function __construct($adapter, $cache, $logger, $config, $translator)
|
133 |
efrain |
72 |
{
|
16769 |
efrain |
73 |
$this->adapter = $adapter;
|
|
|
74 |
$this->cache = $cache;
|
|
|
75 |
$this->logger = $logger;
|
|
|
76 |
$this->config = $config;
|
|
|
77 |
$this->translator = $translator;
|
133 |
efrain |
78 |
}
|
|
|
79 |
|
|
|
80 |
public function indexAction()
|
|
|
81 |
{
|
|
|
82 |
$request = $this->getRequest();
|
|
|
83 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
84 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
85 |
$currentCompany = $currentUserPlugin->getCompany();
|
|
|
86 |
$quiz_id = $this->params()->fromRoute('quiz_id');
|
|
|
87 |
|
|
|
88 |
$flashMessenger = $this->plugin('FlashMessenger');
|
|
|
89 |
|
|
|
90 |
|
|
|
91 |
$quizMapper = CompanyMicrolearningQuizMapper::getInstance($this->adapter);
|
|
|
92 |
$quiz = $quizMapper->fetchOneByUuid($quiz_id);
|
|
|
93 |
if(!$quiz) {
|
|
|
94 |
$flashMessenger->addErrorMessage('ERROR_FORM_NOT_FOUND');
|
|
|
95 |
return $this->redirect()->toRoute('dashboard');
|
|
|
96 |
}
|
|
|
97 |
|
|
|
98 |
if($quiz->company_id != $currentCompany->id) {
|
|
|
99 |
$flashMessenger->addErrorMessage('ERROR_UNAUTHORIZED');
|
|
|
100 |
return $this->redirect()->toRoute('dashboard');
|
|
|
101 |
}
|
|
|
102 |
|
|
|
103 |
$request = $this->getRequest();
|
|
|
104 |
if($request->isGet()) {
|
|
|
105 |
$headers = $request->getHeaders();
|
|
|
106 |
|
|
|
107 |
$isJson = false;
|
|
|
108 |
if($headers->has('Accept')) {
|
|
|
109 |
$accept = $headers->get('Accept');
|
|
|
110 |
|
|
|
111 |
$prioritized = $accept->getPrioritized();
|
|
|
112 |
|
|
|
113 |
foreach($prioritized as $key => $value) {
|
|
|
114 |
$raw = trim($value->getRaw());
|
|
|
115 |
|
|
|
116 |
if(!$isJson) {
|
|
|
117 |
$isJson = strpos($raw, 'json');
|
|
|
118 |
}
|
|
|
119 |
|
|
|
120 |
}
|
|
|
121 |
}
|
|
|
122 |
|
|
|
123 |
if($isJson) {
|
|
|
124 |
$acl = $this->getEvent()->getViewModel()->getVariable('acl');
|
|
|
125 |
$allowAnswers = $acl->isAllowed($currentUser->usertype_id, 'microlearning/content/quizzes/questions/answers');
|
|
|
126 |
$allowAdd = $acl->isAllowed($currentUser->usertype_id, 'microlearning/content/quizzes/questions/add');
|
|
|
127 |
$allowEdit = $acl->isAllowed($currentUser->usertype_id, 'microlearning/content/quizzes/questions/edit');
|
|
|
128 |
$allowDelete = $acl->isAllowed($currentUser->usertype_id, 'microlearning/content/quizzes/questions/delete');
|
|
|
129 |
|
|
|
130 |
|
|
|
131 |
|
|
|
132 |
$search = $this->params()->fromQuery('search', []);
|
16766 |
efrain |
133 |
$search = empty($search['value']) ? '' : Functions::sanitizeFilterString($search['value']);
|
133 |
efrain |
134 |
|
|
|
135 |
$page = intval($this->params()->fromQuery('start', 1), 10);
|
|
|
136 |
$records_x_page = intval($this->params()->fromQuery('length', 10), 10);
|
|
|
137 |
$order = $this->params()->fromQuery('order', []);
|
|
|
138 |
$order_field = empty($order[0]['column']) ? 99 : intval($order[0]['column'], 10);
|
16766 |
efrain |
139 |
$order_direction = empty($order[0]['dir']) ? 'ASC' : strtoupper(Functions::sanitizeFilterString($order[0]['dir']));
|
133 |
efrain |
140 |
|
|
|
141 |
$fields = ['text'];
|
|
|
142 |
$order_field = isset($fields[$order_field]) ? $fields[$order_field] : 'text';
|
|
|
143 |
|
|
|
144 |
if(!in_array($order_direction, ['ASC', 'DESC'])) {
|
|
|
145 |
$order_direction = 'ASC';
|
|
|
146 |
}
|
|
|
147 |
|
|
|
148 |
|
|
|
149 |
|
|
|
150 |
$companyMicrolearningQuestionMapper = CompanyMicrolearningQuestionMapper::getInstance($this->adapter);
|
|
|
151 |
$paginator = $companyMicrolearningQuestionMapper->fetchAllDataTableByCompanyIdAndQuizId($quiz->company_id, $quiz->id, $search, $page, $records_x_page, $order_field, $order_direction);
|
|
|
152 |
|
|
|
153 |
|
|
|
154 |
$items = [];
|
|
|
155 |
foreach($paginator as $record)
|
|
|
156 |
{
|
|
|
157 |
$params = [
|
|
|
158 |
'quiz_id' => $quiz->uuid,
|
|
|
159 |
'question_id' => $record->uuid,
|
|
|
160 |
];
|
|
|
161 |
|
|
|
162 |
$item = [
|
|
|
163 |
'text' => substr(strip_tags($record->text), 0, 50),
|
|
|
164 |
'details' => [
|
|
|
165 |
'points' => $record->points,
|
|
|
166 |
'check' => '',
|
|
|
167 |
'type' => '',
|
|
|
168 |
],
|
|
|
169 |
'actions' => [
|
|
|
170 |
'link_edit' => $allowEdit ? $this->url()->fromRoute('microlearning/content/quizzes/questions/edit', $params) : '',
|
|
|
171 |
'link_delete' => $allowDelete ? $this->url()->fromRoute('microlearning/content/quizzes/questions/delete', $params) : '',
|
|
|
172 |
],
|
|
|
173 |
];
|
|
|
174 |
|
|
|
175 |
switch($record->check)
|
|
|
176 |
{
|
|
|
177 |
case CompanyMicrolearningQuestion::CHECK_OK :
|
|
|
178 |
$item['details']['check'] = 'LABEL_OK';
|
|
|
179 |
break;
|
|
|
180 |
|
|
|
181 |
case CompanyMicrolearningQuestion::CHECK_WRONG :
|
|
|
182 |
$item['details']['check'] = 'LABEL_WRONG';
|
|
|
183 |
break;
|
|
|
184 |
|
|
|
185 |
case CompanyMicrolearningQuestion::CHECK_PENDING :
|
|
|
186 |
$item['details']['check'] = 'LABEL_PENDING';
|
|
|
187 |
break;
|
|
|
188 |
|
|
|
189 |
default :
|
|
|
190 |
$item['details']['check'] = '';
|
|
|
191 |
break;
|
|
|
192 |
}
|
|
|
193 |
|
|
|
194 |
|
|
|
195 |
|
|
|
196 |
$item['actions']['link_answer'] = '';
|
|
|
197 |
switch($record->type)
|
|
|
198 |
{
|
|
|
199 |
case CompanyMicrolearningQuestion::TYPE_MULTI_LINE :
|
|
|
200 |
$item['details']['type'] = 'LABEL_MULTI_LINE';
|
|
|
201 |
break;
|
|
|
202 |
|
|
|
203 |
case CompanyMicrolearningQuestion::TYPE_SINGLE_LINE :
|
|
|
204 |
$item['details']['type'] = 'LABEL_SINGLE_LINE';
|
|
|
205 |
break;
|
|
|
206 |
|
|
|
207 |
case CompanyMicrolearningQuestion::TYPE_SINGLE_SELECTION :
|
|
|
208 |
$item['details']['type'] = 'LABEL_SINGLE_SELECTION';
|
|
|
209 |
$item['actions']['link_answer'] = $allowAnswers ? $this->url()->fromRoute('microlearning/content/quizzes/questions/answers', $params) : '';
|
|
|
210 |
break;
|
|
|
211 |
|
|
|
212 |
case CompanyMicrolearningQuestion::TYPE_MULTIPLE_SELECTION;
|
|
|
213 |
$item['details']['type'] = 'LABEL_MULTIPLE_SELECTION';
|
|
|
214 |
$item['actions']['link_answer'] = $allowAnswers ? $this->url()->fromRoute('microlearning/content/quizzes/questions/answers', $params) : '';
|
|
|
215 |
break;
|
|
|
216 |
|
|
|
217 |
case CompanyMicrolearningQuestion::TYPE_RANGE_1_5;
|
|
|
218 |
$item['details']['type'] = 'LABEL_RANGE_1_5';
|
|
|
219 |
break;
|
|
|
220 |
|
|
|
221 |
case CompanyMicrolearningQuestion::TYPE_RANGE_1_6;
|
|
|
222 |
$item['details']['type'] = 'LABEL_RANGE_1_6';
|
|
|
223 |
break;
|
|
|
224 |
|
|
|
225 |
case CompanyMicrolearningQuestion::TYPE_RANGE_1_10;
|
|
|
226 |
$item['type'] = 'LABEL_RANGE_1_10';
|
|
|
227 |
break;
|
|
|
228 |
|
|
|
229 |
case CompanyMicrolearningQuestion::TYPE_RANGE_OPEN;
|
|
|
230 |
$item['details']['type'] = 'LABEL_RANGE_OPEN';
|
|
|
231 |
$item['actions']['link_answer'] = $allowAnswers ? $this->url()->fromRoute('microlearning/content/quizzes/questions/answer', $params) : '';
|
|
|
232 |
break;
|
|
|
233 |
|
|
|
234 |
default :
|
|
|
235 |
$item['details']['type'] = '';
|
|
|
236 |
break;
|
|
|
237 |
}
|
|
|
238 |
|
|
|
239 |
|
|
|
240 |
|
|
|
241 |
|
|
|
242 |
|
|
|
243 |
array_push($items, $item);
|
|
|
244 |
}
|
|
|
245 |
|
|
|
246 |
|
|
|
247 |
$data = [];
|
|
|
248 |
$data['items'] = $items;
|
|
|
249 |
$data['total'] = $paginator->getTotalItemCount();
|
|
|
250 |
|
|
|
251 |
if($allowAdd) {
|
|
|
252 |
$data['actions']['link_add'] = $this->url()->fromRoute('microlearning/content/quizzes/questions/add', ['quiz_id' => $quiz->id]);
|
|
|
253 |
} else {
|
|
|
254 |
$data['actions']['link_add'] = '';
|
|
|
255 |
}
|
|
|
256 |
|
|
|
257 |
$response = [
|
|
|
258 |
'success' => true,
|
|
|
259 |
'data' => $data
|
|
|
260 |
];
|
|
|
261 |
|
|
|
262 |
return new JsonModel($response);
|
|
|
263 |
|
|
|
264 |
|
|
|
265 |
} else {
|
|
|
266 |
$quizCreateOrEdit = new QuestionCreateOrEditForm();
|
|
|
267 |
|
|
|
268 |
$this->layout()->setTemplate('layout/layout-backend.phtml');
|
|
|
269 |
$viewModel = new ViewModel();
|
|
|
270 |
$viewModel->setTemplate('leaders-linked/microlearning-questions/index.phtml');
|
|
|
271 |
$viewModel->setVariables([
|
|
|
272 |
'quiz_uuid' => $quiz->uuid,
|
|
|
273 |
'quiz_name' => $quiz->name,
|
|
|
274 |
'formCreateOrEdit' => $quizCreateOrEdit,
|
|
|
275 |
]);
|
|
|
276 |
return $viewModel ;
|
|
|
277 |
}
|
|
|
278 |
|
|
|
279 |
} else {
|
|
|
280 |
return new JsonModel([
|
|
|
281 |
'success' => false,
|
|
|
282 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
283 |
]);
|
|
|
284 |
}
|
|
|
285 |
}
|
|
|
286 |
|
|
|
287 |
public function addAction()
|
|
|
288 |
{
|
|
|
289 |
$request = $this->getRequest();
|
|
|
290 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
291 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
292 |
$currentCompany = $currentUserPlugin->getCompany();
|
|
|
293 |
$quiz_id = $this->params()->fromRoute('quiz_id');
|
|
|
294 |
|
|
|
295 |
|
|
|
296 |
$quizMapper = CompanyMicrolearningQuizMapper::getInstance($this->adapter);
|
|
|
297 |
$quiz = $quizMapper->fetchOneByUuid($quiz_id);
|
|
|
298 |
if(!$quiz) {
|
|
|
299 |
return new JsonModel([
|
|
|
300 |
'success' => false,
|
|
|
301 |
'data' => 'ERROR_FORM_NOT_FOUND'
|
|
|
302 |
]);
|
|
|
303 |
}
|
|
|
304 |
|
|
|
305 |
if($quiz->company_id != $currentCompany->id) {
|
|
|
306 |
return new JsonModel([
|
|
|
307 |
'success' => false,
|
|
|
308 |
'data' => 'ERROR_UNAUTHORIZED'
|
|
|
309 |
]);
|
|
|
310 |
}
|
|
|
311 |
|
|
|
312 |
if($request->isPost()) {
|
|
|
313 |
$quizCreateOrEdit = new QuestionCreateOrEditForm();
|
|
|
314 |
$quizCreateOrEdit->setData($request->getPost()->toArray());
|
|
|
315 |
|
|
|
316 |
if($quizCreateOrEdit->isValid()) {
|
|
|
317 |
$dataPost = (array) $quizCreateOrEdit->getData();
|
|
|
318 |
|
|
|
319 |
$hydrator = new ObjectPropertyHydrator();
|
|
|
320 |
$question = new CompanyMicrolearningQuestion();
|
|
|
321 |
$hydrator->hydrate($dataPost, $question);
|
|
|
322 |
|
|
|
323 |
$question->company_id = $quiz->company_id;
|
|
|
324 |
$question->quiz_id = $quiz->id;
|
|
|
325 |
|
|
|
326 |
|
|
|
327 |
$questionMapper = CompanyMicrolearningQuestionMapper::getInstance($this->adapter);
|
|
|
328 |
if($questionMapper->insert($question)) {
|
|
|
329 |
|
|
|
330 |
$quiz->check = CompanyMicroLearningQuiz::CHECK_PENDING;
|
|
|
331 |
$quizMapper->update($quiz);
|
|
|
332 |
|
|
|
333 |
$this->logger->info('Se agrego la pregunta ' . substr(strip_tags($question->text), 0, 50), ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
|
|
|
334 |
|
|
|
335 |
$data = [
|
|
|
336 |
'success' => true,
|
|
|
337 |
'data' => 'LABEL_RECORD_ADDED'
|
|
|
338 |
];
|
|
|
339 |
} else {
|
|
|
340 |
$data = [
|
|
|
341 |
'success' => false,
|
|
|
342 |
'data' => $questionMapper->getError()
|
|
|
343 |
];
|
|
|
344 |
|
|
|
345 |
}
|
|
|
346 |
|
|
|
347 |
return new JsonModel($data);
|
|
|
348 |
|
|
|
349 |
} else {
|
|
|
350 |
$messages = [];
|
|
|
351 |
$quiz_messages = (array) $quizCreateOrEdit->getMessages();
|
|
|
352 |
foreach($quiz_messages as $fieldname => $field_messages)
|
|
|
353 |
{
|
|
|
354 |
|
|
|
355 |
$messages[$fieldname] = array_values($field_messages);
|
|
|
356 |
}
|
|
|
357 |
|
|
|
358 |
return new JsonModel([
|
|
|
359 |
'success' => false,
|
|
|
360 |
'data' => $messages
|
|
|
361 |
]);
|
|
|
362 |
}
|
|
|
363 |
|
|
|
364 |
} else {
|
|
|
365 |
$data = [
|
|
|
366 |
'success' => false,
|
|
|
367 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
368 |
];
|
|
|
369 |
|
|
|
370 |
return new JsonModel($data);
|
|
|
371 |
}
|
|
|
372 |
|
|
|
373 |
return new JsonModel($data);
|
|
|
374 |
}
|
|
|
375 |
|
|
|
376 |
/**
|
|
|
377 |
*
|
|
|
378 |
* Borrar un perfil excepto el público
|
|
|
379 |
* @return \Laminas\View\Model\JsonModel
|
|
|
380 |
*/
|
|
|
381 |
public function deleteAction()
|
|
|
382 |
{
|
|
|
383 |
$request = $this->getRequest();
|
|
|
384 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
385 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
386 |
$currentCompany = $currentUserPlugin->getCompany();
|
|
|
387 |
$quiz_id = $this->params()->fromRoute('quiz_id');
|
|
|
388 |
$question_id = $this->params()->fromRoute('question_id');
|
|
|
389 |
|
|
|
390 |
|
|
|
391 |
$quizMapper = CompanyMicrolearningQuizMapper::getInstance($this->adapter);
|
|
|
392 |
$quiz = $quizMapper->fetchOneByUuid($quiz_id);
|
|
|
393 |
if(!$quiz) {
|
|
|
394 |
return new JsonModel([
|
|
|
395 |
'success' => false,
|
|
|
396 |
'data' => 'ERROR_FORM_NOT_FOUND'
|
|
|
397 |
]);
|
|
|
398 |
}
|
|
|
399 |
|
|
|
400 |
if($quiz->company_id != $currentCompany->id) {
|
|
|
401 |
return new JsonModel([
|
|
|
402 |
'success' => false,
|
|
|
403 |
'data' => 'ERROR_UNAUTHORIZED'
|
|
|
404 |
]);
|
|
|
405 |
}
|
|
|
406 |
|
|
|
407 |
|
|
|
408 |
$questionMapper = CompanyMicrolearningQuestionMapper::getInstance($this->adapter);
|
|
|
409 |
$question = $questionMapper->fetchOneByUuid($question_id);
|
|
|
410 |
if(!$question) {
|
|
|
411 |
return new JsonModel([
|
|
|
412 |
'success' => false,
|
|
|
413 |
'data' => 'ERROR_QUESTION_NOT_FOUND'
|
|
|
414 |
]);
|
|
|
415 |
}
|
|
|
416 |
|
|
|
417 |
if($question->quiz_id != $quiz->id) {
|
|
|
418 |
return new JsonModel([
|
|
|
419 |
'success' => false,
|
|
|
420 |
'data' => 'ERROR_UNAUTHORIZED'
|
|
|
421 |
]);
|
|
|
422 |
}
|
|
|
423 |
|
|
|
424 |
|
|
|
425 |
if($request->isPost()) {
|
|
|
426 |
$result = $questionMapper->delete($question);
|
|
|
427 |
if($result) {
|
|
|
428 |
|
|
|
429 |
$quiz->check = CompanyMicroLearningQuiz::CHECK_PENDING;
|
|
|
430 |
$quizMapper->update($quiz);
|
|
|
431 |
|
|
|
432 |
|
|
|
433 |
$this->logger->info('Se borro la pregunta : ' . substr(strip_tags($question->text), 0, 50), ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
|
|
|
434 |
|
|
|
435 |
$data = [
|
|
|
436 |
'success' => true,
|
|
|
437 |
'data' => 'LABEL_RECORD_DELETED'
|
|
|
438 |
];
|
|
|
439 |
} else {
|
|
|
440 |
|
|
|
441 |
$data = [
|
|
|
442 |
'success' => false,
|
|
|
443 |
'data' => $questionMapper->getError()
|
|
|
444 |
];
|
|
|
445 |
|
|
|
446 |
return new JsonModel($data);
|
|
|
447 |
}
|
|
|
448 |
|
|
|
449 |
} else {
|
|
|
450 |
$data = [
|
|
|
451 |
'success' => false,
|
|
|
452 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
453 |
];
|
|
|
454 |
|
|
|
455 |
return new JsonModel($data);
|
|
|
456 |
}
|
|
|
457 |
|
|
|
458 |
return new JsonModel($data);
|
|
|
459 |
}
|
|
|
460 |
|
|
|
461 |
|
|
|
462 |
public function editAction()
|
|
|
463 |
{
|
|
|
464 |
$request = $this->getRequest();
|
|
|
465 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
466 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
467 |
$currentCompany = $currentUserPlugin->getCompany();
|
|
|
468 |
$quiz_id = $this->params()->fromRoute('quiz_id');
|
|
|
469 |
$question_id = $this->params()->fromRoute('question_id');
|
|
|
470 |
|
|
|
471 |
|
|
|
472 |
$quizMapper = CompanyMicrolearningQuizMapper::getInstance($this->adapter);
|
|
|
473 |
$quiz = $quizMapper->fetchOneByUuid($quiz_id);
|
|
|
474 |
if(!$quiz) {
|
|
|
475 |
return new JsonModel([
|
|
|
476 |
'success' => false,
|
|
|
477 |
'data' => 'ERROR_FORM_NOT_FOUND'
|
|
|
478 |
]);
|
|
|
479 |
}
|
|
|
480 |
|
|
|
481 |
if($quiz->company_id != $currentCompany->id) {
|
|
|
482 |
return new JsonModel([
|
|
|
483 |
'success' => false,
|
|
|
484 |
'data' => 'ERROR_UNAUTHORIZED'
|
|
|
485 |
]);
|
|
|
486 |
}
|
|
|
487 |
|
|
|
488 |
$questionMapper = CompanyMicrolearningQuestionMapper::getInstance($this->adapter);
|
|
|
489 |
$question = $questionMapper->fetchOneByUuid($question_id);
|
|
|
490 |
if(!$question) {
|
|
|
491 |
return new JsonModel([
|
|
|
492 |
'success' => false,
|
|
|
493 |
'data' => 'ERROR_QUESTION_NOT_FOUND'
|
|
|
494 |
]);
|
|
|
495 |
}
|
|
|
496 |
|
|
|
497 |
if($question->quiz_id != $quiz->id) {
|
|
|
498 |
return new JsonModel([
|
|
|
499 |
'success' => false,
|
|
|
500 |
'data' => 'ERROR_UNAUTHORIZED'
|
|
|
501 |
]);
|
|
|
502 |
}
|
|
|
503 |
|
|
|
504 |
if($request->isGet()) {
|
|
|
505 |
$data = [
|
|
|
506 |
'success' => true,
|
|
|
507 |
'data' => [
|
|
|
508 |
'text' => $question->text,
|
|
|
509 |
'type' => $question->type,
|
|
|
510 |
'maxlength' => $question->maxlength,
|
|
|
511 |
'points' => $question->points,
|
|
|
512 |
]
|
|
|
513 |
];
|
|
|
514 |
|
|
|
515 |
return new JsonModel($data);
|
|
|
516 |
}
|
|
|
517 |
else if($request->isPost()) {
|
|
|
518 |
$quizCreateOrEdit = new QuestionCreateOrEditForm();
|
|
|
519 |
$quizCreateOrEdit->setData($request->getPost()->toArray());
|
|
|
520 |
|
|
|
521 |
if($quizCreateOrEdit->isValid()) {
|
|
|
522 |
$dataPost = (array) $quizCreateOrEdit->getData();
|
|
|
523 |
|
|
|
524 |
$hydrator = new ObjectPropertyHydrator();
|
|
|
525 |
$hydrator->hydrate($dataPost, $question);
|
|
|
526 |
|
|
|
527 |
$question->check = CompanyMicrolearningQuestion::CHECK_PENDING;
|
|
|
528 |
if($questionMapper->update($question)) {
|
|
|
529 |
$quiz->check = CompanyMicroLearningQuiz::CHECK_PENDING;
|
|
|
530 |
$quizMapper->update($quiz);
|
|
|
531 |
|
|
|
532 |
$this->logger->info('Se edito la pregunta ' . substr(strip_tags($question->text), 0, 50), ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
|
|
|
533 |
|
|
|
534 |
$data = [
|
|
|
535 |
'success' => true,
|
|
|
536 |
'data' => 'LABEL_RECORD_UPDATED'
|
|
|
537 |
];
|
|
|
538 |
} else {
|
|
|
539 |
$data = [
|
|
|
540 |
'success' => false,
|
|
|
541 |
'data' => $questionMapper->getError()
|
|
|
542 |
];
|
|
|
543 |
|
|
|
544 |
}
|
|
|
545 |
|
|
|
546 |
return new JsonModel($data);
|
|
|
547 |
|
|
|
548 |
} else {
|
|
|
549 |
$messages = [];
|
|
|
550 |
$quiz_messages = (array) $quizCreateOrEdit->getMessages();
|
|
|
551 |
foreach($quiz_messages as $fieldname => $field_messages)
|
|
|
552 |
{
|
|
|
553 |
|
|
|
554 |
$messages[$fieldname] = array_values($field_messages);
|
|
|
555 |
}
|
|
|
556 |
|
|
|
557 |
return new JsonModel([
|
|
|
558 |
'success' => false,
|
|
|
559 |
'data' => $messages
|
|
|
560 |
]);
|
|
|
561 |
}
|
|
|
562 |
} else {
|
|
|
563 |
$data = [
|
|
|
564 |
'success' => false,
|
|
|
565 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
566 |
];
|
|
|
567 |
|
|
|
568 |
return new JsonModel($data);
|
|
|
569 |
}
|
|
|
570 |
|
|
|
571 |
return new JsonModel($data);
|
|
|
572 |
}
|
|
|
573 |
|
|
|
574 |
|
|
|
575 |
}
|