Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 16769 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 16769 Rev 17002
Línea 16... Línea 16...
16
use Laminas\View\Model\JsonModel;
16
use Laminas\View\Model\JsonModel;
Línea 17... Línea 17...
17
 
17
 
18
use LeadersLinked\Library\Functions;
18
use LeadersLinked\Library\Functions;
19
use LeadersLinked\Mapper\QueryMapper;
19
use LeadersLinked\Mapper\QueryMapper;
20
use LeadersLinked\Mapper\CompanyMapper;
20
use LeadersLinked\Mapper\CompanyMapper;
21
use LeadersLinked\Mapper\CompanyMicrolearningQuizMapper;
21
use LeadersLinked\Mapper\MicrolearningQuizMapper;
22
use LeadersLinked\Form\AnswerCreateOrEditForm;
22
use LeadersLinked\Form\AnswerCreateOrEditForm;
23
use Laminas\Hydrator\ObjectPropertyHydrator;
23
use Laminas\Hydrator\ObjectPropertyHydrator;
24
use LeadersLinked\Model\CompanyMicrolearningQuestion;
24
use LeadersLinked\Model\MicrolearningQuestion;
25
use LeadersLinked\Mapper\CompanyMicrolearningQuestionMapper;
25
use LeadersLinked\Mapper\MicrolearningQuestionMapper;
26
use LeadersLinked\Model\CompanyMicrolearningAnswer;
26
use LeadersLinked\Model\MicrolearningAnswer;
27
use LeadersLinked\Mapper\CompanyMicrolearningAnswerMapper;
27
use LeadersLinked\Mapper\MicrolearningAnswerMapper;
Línea 28... Línea 28...
28
use LeadersLinked\Model\CompanyMicrolearningQuiz;
28
use LeadersLinked\Model\MicrolearningQuiz;
29
 
29
 
30
class MicrolearningAnswerController extends AbstractActionController
30
class MicrolearningAnswerController extends AbstractActionController
31
{
31
{
Línea 89... Línea 89...
89
        $quiz_id            = $this->params()->fromRoute('quiz_id');
89
        $quiz_id            = $this->params()->fromRoute('quiz_id');
90
        $question_id        = $this->params()->fromRoute('question_id');
90
        $question_id        = $this->params()->fromRoute('question_id');
91
        $flashMessenger     = $this->plugin('FlashMessenger');
91
        $flashMessenger     = $this->plugin('FlashMessenger');
Línea 92... Línea 92...
92
 
92
 
93
        
93
        
94
        $quizMapper = CompanyMicrolearningQuizMapper::getInstance($this->adapter);
94
        $quizMapper = MicrolearningQuizMapper::getInstance($this->adapter);
95
        $quiz = $quizMapper->fetchOneByUuid($quiz_id);
95
        $quiz = $quizMapper->fetchOneByUuid($quiz_id);
96
        if(!$quiz) {
96
        if(!$quiz) {
97
            $flashMessenger->addErrorMessage('ERROR_FORM_NOT_FOUND');
97
            $flashMessenger->addErrorMessage('ERROR_FORM_NOT_FOUND');
Línea 102... Línea 102...
102
            $flashMessenger->addErrorMessage('ERROR_UNAUTHORIZED');
102
            $flashMessenger->addErrorMessage('ERROR_UNAUTHORIZED');
103
            return $this->redirect()->toRoute('dashboard');
103
            return $this->redirect()->toRoute('dashboard');
104
        }
104
        }
Línea 105... Línea 105...
105
        
105
        
106
        
106
        
Línea 107... Línea 107...
107
        $questionMapper = CompanyMicrolearningQuestionMapper::getInstance($this->adapter);
107
        $questionMapper = MicrolearningQuestionMapper::getInstance($this->adapter);
108
        $question = $questionMapper->fetchOneByUuid($question_id);
108
        $question = $questionMapper->fetchOneByUuid($question_id);
109
        
109
        
Línea 160... Línea 160...
160
                    $order_direction = 'ASC';
160
                    $order_direction = 'ASC';
161
                }
161
                }
Línea 162... Línea 162...
162
                
162
                
163
                
163
                
Línea 164... Línea 164...
164
                
164
                
165
                $companyMicrolearningAnswerMapper = CompanyMicrolearningAnswerMapper::getInstance($this->adapter);
165
                $microlearningAnswerMapper = MicrolearningAnswerMapper::getInstance($this->adapter);
166
                $paginator = $companyMicrolearningAnswerMapper->fetchAllDataTableByCompanyIdAndQuizId($question->company_id, $question->quiz_id, $question->id, $search, $page, $records_x_page, $order_field, $order_direction);
166
                $paginator = $microlearningAnswerMapper->fetchAllDataTableByCompanyIdAndQuizId($question->company_id, $question->quiz_id, $question->id, $search, $page, $records_x_page, $order_field, $order_direction);
167
                
167
                
Línea 186... Línea 186...
186
                        ], 
186
                        ], 
187
                    ];
187
                    ];
Línea 188... Línea 188...
188
                    
188
                    
189
                    
189
                    
190
 
190
 
191
                    if($record->correct == CompanyMicrolearningAnswer::CORRECT_YES) {
191
                    if($record->correct == MicrolearningAnswer::CORRECT_YES) {
192
                        $item['details']['correct'] = 'LABEL_ANSWER_CORRECT';
192
                        $item['details']['correct'] = 'LABEL_ANSWER_CORRECT';
Línea 218... Línea 218...
218
                return new JsonModel($response);
218
                return new JsonModel($response);
Línea 219... Línea 219...
219
                
219
                
Línea 220... Línea 220...
220
                
220
                
221
            } else {
221
            } else {
222
                
222
                
223
                if($question->type == CompanyMicrolearningQuestion::TYPE_SINGLE_SELECTION) {
223
                if($question->type == MicrolearningQuestion::TYPE_SINGLE_SELECTION) {
224
                    $showPoints = 0;
224
                    $showPoints = 0;
Línea 262... Línea 262...
262
        $currentCompany     = $currentUserPlugin->getCompany();
262
        $currentCompany     = $currentUserPlugin->getCompany();
263
        $quiz_id            = $this->params()->fromRoute('quiz_id');
263
        $quiz_id            = $this->params()->fromRoute('quiz_id');
264
        $question_id        = $this->params()->fromRoute('question_id');
264
        $question_id        = $this->params()->fromRoute('question_id');
Línea 265... Línea 265...
265
 
265
 
266
        
266
        
267
        $quizMapper = CompanyMicrolearningQuizMapper::getInstance($this->adapter);
267
        $quizMapper = MicrolearningQuizMapper::getInstance($this->adapter);
268
        $quiz = $quizMapper->fetchOneByUuid($quiz_id);
268
        $quiz = $quizMapper->fetchOneByUuid($quiz_id);
269
        if(!$quiz) {
269
        if(!$quiz) {
270
            return new JsonModel([
270
            return new JsonModel([
Línea 278... Línea 278...
278
                'success'   => false,
278
                'success'   => false,
279
                'data'   => 'ERROR_UNAUTHORIZED'
279
                'data'   => 'ERROR_UNAUTHORIZED'
280
            ]);
280
            ]);
281
        }
281
        }
Línea 282... Línea 282...
282
        
282
        
283
        $questionMapper = CompanyMicrolearningQuestionMapper::getInstance($this->adapter);
283
        $questionMapper = MicrolearningQuestionMapper::getInstance($this->adapter);
Línea 284... Línea 284...
284
        $question = $questionMapper->fetchOneByUuid($question_id);
284
        $question = $questionMapper->fetchOneByUuid($question_id);
285
        
285
        
286
        if(!$question) {
286
        if(!$question) {
Línea 303... Línea 303...
303
            
303
            
304
            if($quizCreateOrEdit->isValid()) {
304
            if($quizCreateOrEdit->isValid()) {
Línea 305... Línea 305...
305
                $dataPost = (array) $quizCreateOrEdit->getData();
305
                $dataPost = (array) $quizCreateOrEdit->getData();
306
                
306
                
307
                $hydrator = new ObjectPropertyHydrator();
307
                $hydrator = new ObjectPropertyHydrator();
Línea 308... Línea 308...
308
                $answer = new CompanyMicrolearningAnswer();
308
                $answer = new MicrolearningAnswer();
309
                $hydrator->hydrate($dataPost, $answer);
309
                $hydrator->hydrate($dataPost, $answer);
310
                
310
                
Línea 311... Línea 311...
311
                $answer->company_id = $question->company_id;
311
                $answer->company_id = $question->company_id;
312
                $answer->quiz_id = $question->quiz_id;
312
                $answer->quiz_id = $question->quiz_id;
Línea 313... Línea 313...
313
                $answer->question_id = $question->id;
313
                $answer->question_id = $question->id;
314
                
314
                
Línea 315... Línea 315...
315
                $answerMapper = CompanyMicrolearningAnswerMapper::getInstance($this->adapter);
315
                $answerMapper = MicrolearningAnswerMapper::getInstance($this->adapter);
316
                if($answerMapper->insert($answer)) {
316
                if($answerMapper->insert($answer)) {
Línea 317... Línea 317...
317
                    
317
                    
Línea 318... Línea 318...
318
                    $question->check = CompanyMicrolearningQuestion::CHECK_PENDING;
318
                    $question->check = MicrolearningQuestion::CHECK_PENDING;
Línea 378... Línea 378...
378
        $quiz_id            = $this->params()->fromRoute('quiz_id');
378
        $quiz_id            = $this->params()->fromRoute('quiz_id');
379
        $question_id        = $this->params()->fromRoute('question_id');
379
        $question_id        = $this->params()->fromRoute('question_id');
380
        $answer_id          = $this->params()->fromRoute('answer_id');
380
        $answer_id          = $this->params()->fromRoute('answer_id');
Línea 381... Línea 381...
381
 
381
 
382
        
382
        
383
        $quizMapper = CompanyMicrolearningQuizMapper::getInstance($this->adapter);
383
        $quizMapper = MicrolearningQuizMapper::getInstance($this->adapter);
384
        $quiz = $quizMapper->fetchOneByUuid($quiz_id);
384
        $quiz = $quizMapper->fetchOneByUuid($quiz_id);
385
        if(!$quiz) {
385
        if(!$quiz) {
386
            return new JsonModel([
386
            return new JsonModel([
Línea 394... Línea 394...
394
                'success'   => false,
394
                'success'   => false,
395
                'data'   => 'ERROR_UNAUTHORIZED'
395
                'data'   => 'ERROR_UNAUTHORIZED'
396
            ]);
396
            ]);
397
        }
397
        }
Línea 398... Línea 398...
398
        
398
        
399
        $questionMapper = CompanyMicrolearningQuestionMapper::getInstance($this->adapter);
399
        $questionMapper = MicrolearningQuestionMapper::getInstance($this->adapter);
400
        $question = $questionMapper->fetchOneByUuid($question_id);
400
        $question = $questionMapper->fetchOneByUuid($question_id);
401
        if(!$question) {
401
        if(!$question) {
402
            return new JsonModel([
402
            return new JsonModel([
403
                'success'   => false,
403
                'success'   => false,
Línea 410... Línea 410...
410
                'success'   => false,
410
                'success'   => false,
411
                'data'   => 'ERROR_UNAUTHORIZED'
411
                'data'   => 'ERROR_UNAUTHORIZED'
412
            ]);
412
            ]);
413
        }
413
        }
Línea 414... Línea 414...
414
        
414
        
415
        $answerMapper = CompanyMicrolearningAnswerMapper::getInstance($this->adapter);
415
        $answerMapper = MicrolearningAnswerMapper::getInstance($this->adapter);
416
        $answer = $answerMapper->fetchOneByUuid($answer_id);
416
        $answer = $answerMapper->fetchOneByUuid($answer_id);
417
        if(!$answer) {
417
        if(!$answer) {
418
            return new JsonModel([
418
            return new JsonModel([
419
                'success'   => false,
419
                'success'   => false,
Línea 429... Línea 429...
429
        }
429
        }
Línea 430... Línea 430...
430
        
430
        
431
        if($request->isPost()) {
431
        if($request->isPost()) {
432
            $result = $answerMapper->delete($answer);
432
            $result = $answerMapper->delete($answer);
433
            if($result) {
433
            if($result) {
434
                $question->check = CompanyMicrolearningQuestion::CHECK_PENDING;
434
                $question->check = MicrolearningQuestion::CHECK_PENDING;
Línea 435... Línea 435...
435
                $questionMapper->update($question);
435
                $questionMapper->update($question);
436
                
436
                
Línea 437... Línea 437...
437
                $quiz->check = CompanyMicrolearningQuiz::CHECK_PENDING;
437
                $quiz->check = MicrolearningQuiz::CHECK_PENDING;
Línea 438... Línea 438...
438
                $quizMapper->update($quiz);
438
                $quizMapper->update($quiz);
Línea 475... Línea 475...
475
        $quiz_id            = $this->params()->fromRoute('quiz_id');
475
        $quiz_id            = $this->params()->fromRoute('quiz_id');
476
        $question_id        = $this->params()->fromRoute('question_id');
476
        $question_id        = $this->params()->fromRoute('question_id');
477
        $answer_id          = $this->params()->fromRoute('answer_id');
477
        $answer_id          = $this->params()->fromRoute('answer_id');
Línea 478... Línea 478...
478
 
478
 
479
 
479
 
480
        $quizMapper = CompanyMicrolearningQuizMapper::getInstance($this->adapter);
480
        $quizMapper = MicrolearningQuizMapper::getInstance($this->adapter);
481
        $quiz = $quizMapper->fetchOneByUuid($quiz_id);
481
        $quiz = $quizMapper->fetchOneByUuid($quiz_id);
482
        if(!$quiz) {
482
        if(!$quiz) {
483
            return new JsonModel([
483
            return new JsonModel([
Línea 491... Línea 491...
491
                'success'   => false,
491
                'success'   => false,
492
                'data'   => 'ERROR_UNAUTHORIZED'
492
                'data'   => 'ERROR_UNAUTHORIZED'
493
            ]);
493
            ]);
494
        }
494
        }
Línea 495... Línea 495...
495
        
495
        
496
        $questionMapper = CompanyMicrolearningQuestionMapper::getInstance($this->adapter);
496
        $questionMapper = MicrolearningQuestionMapper::getInstance($this->adapter);
497
        $question = $questionMapper->fetchOneByUuid($question_id);
497
        $question = $questionMapper->fetchOneByUuid($question_id);
498
        if(!$question) {
498
        if(!$question) {
499
            return new JsonModel([
499
            return new JsonModel([
500
                'success'   => false,
500
                'success'   => false,
Línea 507... Línea 507...
507
                'success'   => false,
507
                'success'   => false,
508
                'data'   => 'ERROR_UNAUTHORIZED'
508
                'data'   => 'ERROR_UNAUTHORIZED'
509
            ]);
509
            ]);
510
        }
510
        }
Línea 511... Línea 511...
511
        
511
        
512
        $answerMapper = CompanyMicrolearningAnswerMapper::getInstance($this->adapter);
512
        $answerMapper = MicrolearningAnswerMapper::getInstance($this->adapter);
513
        $answer = $answerMapper->fetchOneByUuid($answer_id);
513
        $answer = $answerMapper->fetchOneByUuid($answer_id);
514
        if(!$answer) {
514
        if(!$answer) {
515
            return new JsonModel([
515
            return new JsonModel([
516
                'success'   => false,
516
                'success'   => false,
Línea 548... Línea 548...
548
                
548
                
549
                $hydrator = new ObjectPropertyHydrator();
549
                $hydrator = new ObjectPropertyHydrator();
Línea 550... Línea 550...
550
                $hydrator->hydrate($dataPost, $answer);
550
                $hydrator->hydrate($dataPost, $answer);
551
                
551
                
552
                if($answerMapper->update($answer)) {
552
                if($answerMapper->update($answer)) {
Línea 553... Línea 553...
553
                    $question->check = CompanyMicrolearningQuestion::CHECK_PENDING;
553
                    $question->check = MicrolearningQuestion::CHECK_PENDING;
554
                    $questionMapper->update($question);
554
                    $questionMapper->update($question);
Línea 555... Línea 555...
555
 
555
 
Línea 556... Línea 556...
556
                    $quiz->check = CompanyMicrolearningQuiz::CHECK_PENDING;
556
                    $quiz->check = MicrolearningQuiz::CHECK_PENDING;