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 15... Línea 15...
15
use Laminas\View\Model\ViewModel;
15
use Laminas\View\Model\ViewModel;
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\Model\CompanyMicrolearningQuiz;
20
use LeadersLinked\Model\MicrolearningQuiz;
21
use LeadersLinked\Mapper\CompanyMicrolearningQuizMapper;
21
use LeadersLinked\Mapper\MicrolearningQuizMapper;
22
use LeadersLinked\Form\QuizCreateOrEditForm;
22
use LeadersLinked\Form\QuizCreateOrEditForm;
23
use Laminas\Hydrator\ObjectPropertyHydrator;
23
use Laminas\Hydrator\ObjectPropertyHydrator;
24
use LeadersLinked\Mapper\CompanyMicrolearningQuestionMapper;
24
use LeadersLinked\Mapper\MicrolearningQuestionMapper;
25
use LeadersLinked\Mapper\CompanyMicrolearningAnswerMapper;
25
use LeadersLinked\Mapper\MicrolearningAnswerMapper;
26
use LeadersLinked\Model\CompanyMicrolearningQuestion;
26
use LeadersLinked\Model\MicrolearningQuestion;
27
use LeadersLinked\Model\CompanyMicrolearningAnswer;
27
use LeadersLinked\Model\MicrolearningAnswer;
Línea 28... Línea 28...
28
use LeadersLinked\Mapper\CompanyMicrolearningSlideMapper;
28
use LeadersLinked\Mapper\MicrolearningSlideMapper;
29
 
29
 
30
class MicrolearningQuizController extends AbstractActionController
30
class MicrolearningQuizController extends AbstractActionController
31
{
31
{
Línea 131... Línea 131...
131
                    $order_direction = 'ASC';
131
                    $order_direction = 'ASC';
132
                }
132
                }
Línea 133... Línea 133...
133
                
133
                
134
 
134
 
135
                
135
                
136
                $companyMicrolearningSlideMapper = CompanyMicrolearningSlideMapper::getInstance($this->adapter);
136
                $microlearningSlideMapper = MicrolearningSlideMapper::getInstance($this->adapter);
137
                $companyMicrolearningQuizMapper = CompanyMicrolearningQuizMapper::getInstance($this->adapter);
137
                $microlearningQuizMapper = MicrolearningQuizMapper::getInstance($this->adapter);
138
                $paginator = $companyMicrolearningQuizMapper->fetchAllDataTableByCompanyId($currentCompany->id,  $search, $page, $records_x_page, $order_field, $order_direction);
138
                $paginator = $microlearningQuizMapper->fetchAllDataTableByCompanyId($currentCompany->id,  $search, $page, $records_x_page, $order_field, $order_direction);
Línea 139... Línea 139...
139
                $items = [];
139
                $items = [];
Línea 140... Línea 140...
140
                foreach($paginator as $record)
140
                foreach($paginator as $record)
141
                {
141
                {
142
 
142
 
143
                    
143
                    
144
                    $slides = $companyMicrolearningSlideMapper->fetchTotalCountByCompanyIdQuizId($currentCompany->id, $record->id);
144
                    $slides = $microlearningSlideMapper->fetchTotalCountByCompanyIdQuizId($currentCompany->id, $record->id);
145
                    
145
                    
Línea 146... Línea 146...
146
                    $status_description = '';
146
                    $status_description = '';
147
                    switch ($record->status) 
147
                    switch ($record->status) 
148
                    {
148
                    {
149
                        case CompanyMicrolearningQuiz::STATUS_ACTIVE : 
149
                        case MicrolearningQuiz::STATUS_ACTIVE : 
Línea 150... Línea 150...
150
                            $status_description = 'LABEL_ACTIVE';
150
                            $status_description = 'LABEL_ACTIVE';
151
                            break;
151
                            break;
152
                            
152
                            
153
                        case CompanyMicrolearningQuiz::STATUS_INACTIVE :
153
                        case MicrolearningQuiz::STATUS_INACTIVE :
154
                            $status_description = 'LABEL_INACTIVE';
154
                            $status_description = 'LABEL_INACTIVE';
155
                            break;
155
                            break;
Línea 156... Línea 156...
156
                    }
156
                    }
157
                    
157
                    
158
                    $check_description = '';
158
                    $check_description = '';
Línea 159... Línea 159...
159
                    switch($record->check)
159
                    switch($record->check)
160
                    {
160
                    {
161
                        case CompanyMicrolearningQuiz::CHECK_OK :
161
                        case MicrolearningQuiz::CHECK_OK :
162
                            $check_description = 'LABEL_WITHOUT_ERRORS';
162
                            $check_description = 'LABEL_WITHOUT_ERRORS';
Línea 163... Línea 163...
163
                            break;
163
                            break;
Línea 248... Línea 248...
248
            
248
            
249
            if($formCreateOrEdit->isValid()) {
249
            if($formCreateOrEdit->isValid()) {
Línea 250... Línea 250...
250
                $dataPost = (array) $formCreateOrEdit->getData();
250
                $dataPost = (array) $formCreateOrEdit->getData();
251
                
251
                
252
                $hydrator = new ObjectPropertyHydrator();
252
                $hydrator = new ObjectPropertyHydrator();
Línea 253... Línea 253...
253
                $quiz = new CompanyMicrolearningQuiz();
253
                $quiz = new MicrolearningQuiz();
Línea 254... Línea 254...
254
                $hydrator->hydrate($dataPost, $quiz);
254
                $hydrator->hydrate($dataPost, $quiz);
255
                
255
                
Línea 256... Línea 256...
256
                $quiz->company_id = $currentCompany->id;
256
                $quiz->company_id = $currentCompany->id;
Línea 313... Línea 313...
313
        $currentUserPlugin  = $this->plugin('currentUserPlugin');
313
        $currentUserPlugin  = $this->plugin('currentUserPlugin');
314
        $currentUser        = $currentUserPlugin->getUser();
314
        $currentUser        = $currentUserPlugin->getUser();
315
        $currentCompany     = $currentUserPlugin->getCompany();
315
        $currentCompany     = $currentUserPlugin->getCompany();
316
        $quiz_id            = $this->params()->fromRoute('quiz_id');
316
        $quiz_id            = $this->params()->fromRoute('quiz_id');
Línea 317... Línea 317...
317
        
317
        
318
        $quizMapper = CompanyMicrolearningQuizMapper::getInstance($this->adapter);
318
        $quizMapper = MicrolearningQuizMapper::getInstance($this->adapter);
319
        $quiz = $quizMapper->fetchOneByUuid($quiz_id);
319
        $quiz = $quizMapper->fetchOneByUuid($quiz_id);
320
        if(!$quiz) {
320
        if(!$quiz) {
321
            return new JsonModel([
321
            return new JsonModel([
322
                'success'   => false,
322
                'success'   => false,
Línea 369... Línea 369...
369
        $currentUserPlugin  = $this->plugin('currentUserPlugin');
369
        $currentUserPlugin  = $this->plugin('currentUserPlugin');
370
        $currentUser        = $currentUserPlugin->getUser();
370
        $currentUser        = $currentUserPlugin->getUser();
371
        $currentCompany     = $currentUserPlugin->getCompany();
371
        $currentCompany     = $currentUserPlugin->getCompany();
372
        $quiz_id            = $this->params()->fromRoute('quiz_id');
372
        $quiz_id            = $this->params()->fromRoute('quiz_id');
Línea 373... Línea 373...
373
        
373
        
374
        $quizMapper = CompanyMicrolearningQuizMapper::getInstance($this->adapter);
374
        $quizMapper = MicrolearningQuizMapper::getInstance($this->adapter);
375
        $quiz = $quizMapper->fetchOneByUuid($quiz_id);
375
        $quiz = $quizMapper->fetchOneByUuid($quiz_id);
376
        if(!$quiz) {
376
        if(!$quiz) {
377
            return new JsonModel([
377
            return new JsonModel([
378
                'success'   => false,
378
                'success'   => false,
Línea 413... Línea 413...
413
                $dataPost = (array) $formCreateOrEdit->getData();
413
                $dataPost = (array) $formCreateOrEdit->getData();
Línea 414... Línea 414...
414
                
414
                
415
                $hydrator = new ObjectPropertyHydrator();
415
                $hydrator = new ObjectPropertyHydrator();
Línea 416... Línea 416...
416
                $hydrator->hydrate($dataPost, $quiz);
416
                $hydrator->hydrate($dataPost, $quiz);
417
                
417
                
Línea 418... Línea 418...
418
                $quiz->check = CompanyMicrolearningQuiz::CHECK_PENDING;
418
                $quiz->check = MicrolearningQuiz::CHECK_PENDING;
Línea 419... Línea 419...
419
                if($quizMapper->update($quiz)) {
419
                if($quizMapper->update($quiz)) {
Línea 467... Línea 467...
467
        $currentUserPlugin  = $this->plugin('currentUserPlugin');
467
        $currentUserPlugin  = $this->plugin('currentUserPlugin');
468
        $currentUser        = $currentUserPlugin->getUser();
468
        $currentUser        = $currentUserPlugin->getUser();
469
        $currentCompany     = $currentUserPlugin->getCompany();
469
        $currentCompany     = $currentUserPlugin->getCompany();
470
        $quiz_id            = $this->params()->fromRoute('quiz_id');
470
        $quiz_id            = $this->params()->fromRoute('quiz_id');
Línea 471... Línea 471...
471
        
471
        
472
        $quizMapper = CompanyMicrolearningQuizMapper::getInstance($this->adapter);
472
        $quizMapper = MicrolearningQuizMapper::getInstance($this->adapter);
473
        $quiz = $quizMapper->fetchOneByUuid($quiz_id);
473
        $quiz = $quizMapper->fetchOneByUuid($quiz_id);
474
        if(!$quiz) {
474
        if(!$quiz) {
475
            return new JsonModel([
475
            return new JsonModel([
476
                'success'   => false,
476
                'success'   => false,
Línea 484... Línea 484...
484
                'data'   => 'ERROR_UNAUTHORIZED'
484
                'data'   => 'ERROR_UNAUTHORIZED'
485
            ]);
485
            ]);
486
        }
486
        }
Línea 487... Línea 487...
487
        
487
        
488
         if($request->isPost()) {
488
         if($request->isPost()) {
489
            $questionMapper = CompanyMicrolearningQuestionMapper::getInstance($this->adapter);
489
            $questionMapper = MicrolearningQuestionMapper::getInstance($this->adapter);
Línea 490... Línea 490...
490
            $answerMapper = CompanyMicrolearningAnswerMapper::getInstance($this->adapter);
490
            $answerMapper = MicrolearningAnswerMapper::getInstance($this->adapter);
491
            
491
            
Línea 498... Línea 498...
498
            foreach($questions as $question)
498
            foreach($questions as $question)
499
            {
499
            {
500
                $total_point_questions += $question->points;
500
                $total_point_questions += $question->points;
501
                $answers = $answerMapper->fetchAllByQuizIdAndQuestionId($question->quiz_id, $question->id);
501
                $answers = $answerMapper->fetchAllByQuizIdAndQuestionId($question->quiz_id, $question->id);
Línea 502... Línea 502...
502
                            
502
                            
503
                if($question->type == CompanyMicrolearningQuestion::TYPE_SINGLE_SELECTION ) {
503
                if($question->type == MicrolearningQuestion::TYPE_SINGLE_SELECTION ) {
504
                    $number_correct     = 0;
504
                    $number_correct     = 0;
505
                    $number_incorrect   = 0;
505
                    $number_incorrect   = 0;
506
                    foreach($answers as $answer)
506
                    foreach($answers as $answer)
507
                    {
507
                    {
508
                        if($answer->correct == CompanyMicrolearningAnswer::CORRECT_YES) {
508
                        if($answer->correct == MicrolearningAnswer::CORRECT_YES) {
509
                            $number_correct++;
509
                            $number_correct++;
510
                        } else {
510
                        } else {
511
                            $number_incorrect++;
511
                            $number_incorrect++;
512
                        }
512
                        }
Línea 513... Línea 513...
513
                    }
513
                    }
514
 
514
 
515
                    if($number_correct == 1 && $number_incorrect >= 1 ) {
515
                    if($number_correct == 1 && $number_incorrect >= 1 ) {
516
                        $check_question = CompanyMicrolearningQuestion::CHECK_OK;
516
                        $check_question = MicrolearningQuestion::CHECK_OK;
517
                    } else {
517
                    } else {
518
                        $check_question = CompanyMicrolearningQuestion::CHECK_WRONG;
518
                        $check_question = MicrolearningQuestion::CHECK_WRONG;
519
                    }
519
                    }
520
                } else if($question->type == CompanyMicrolearningQuestion::TYPE_MULTIPLE_SELECTION ) {
520
                } else if($question->type == MicrolearningQuestion::TYPE_MULTIPLE_SELECTION ) {
521
                    $number_correct     = 0;
521
                    $number_correct     = 0;
Línea 522... Línea 522...
522
                    $number_incorrect   = 0;
522
                    $number_incorrect   = 0;
523
                    $points = 0;
523
                    $points = 0;
524
 
524
 
525
                    foreach($answers as $answer)
525
                    foreach($answers as $answer)
526
                    {
526
                    {
527
                        $points += $answer->points;
527
                        $points += $answer->points;
528
                        if($answer->correct == CompanyMicrolearningAnswer::CORRECT_YES) {
528
                        if($answer->correct == MicrolearningAnswer::CORRECT_YES) {
529
                            $number_correct++;
529
                            $number_correct++;
530
                        } else {
530
                        } else {
Línea 531... Línea 531...
531
                            $number_incorrect++;
531
                            $number_incorrect++;
532
                        }
532
                        }
533
                    }
533
                    }
534
                        
534
                        
535
                    if($number_correct < 2 || $number_incorrect < 1) {
535
                    if($number_correct < 2 || $number_incorrect < 1) {
536
                        $check_question = CompanyMicrolearningQuestion::CHECK_WRONG;
536
                        $check_question = MicrolearningQuestion::CHECK_WRONG;
537
                    } else {
537
                    } else {
538
                        if($points == $question->points) {
538
                        if($points == $question->points) {
Línea 539... Línea 539...
539
                            $check_question = CompanyMicrolearningQuestion::CHECK_OK;
539
                            $check_question = MicrolearningQuestion::CHECK_OK;
540
                        } else {
540
                        } else {
541
                            $check_question = CompanyMicrolearningQuestion::CHECK_WRONG;
541
                            $check_question = MicrolearningQuestion::CHECK_WRONG;
542
                        }
542
                        }
Línea 543... Línea 543...
543
                           
543
                           
544
                    }
544
                    }
545
                } else {
545
                } else {
Línea 546... Línea 546...
546
                    $check_question = CompanyMicrolearningQuestion::CHECK_OK;
546
                    $check_question = MicrolearningQuestion::CHECK_OK;
547
                }
547
                }
548
                    
548
                    
Línea 549... Línea 549...
549
                
549
                
550
                if($check_question == CompanyMicrolearningQuestion::CHECK_WRONG) {
550
                if($check_question == MicrolearningQuestion::CHECK_WRONG) {
551
                    $quiz->check = CompanyMicrolearningQuiz::CHECK_WRONG;
551
                    $quiz->check = MicrolearningQuiz::CHECK_WRONG;
Línea 552... Línea 552...
552
                }
552
                }
Línea 553... Línea 553...
553
 
553
 
554
                $question->check = $check_question;
554
                $question->check = $check_question;
Línea 555... Línea 555...
555
                $questionMapper->update($question);
555
                $questionMapper->update($question);
556
            }
556
            }
557
            
557
            
Línea 610... Línea 610...
610
        $currentUserPlugin  = $this->plugin('currentUserPlugin');
610
        $currentUserPlugin  = $this->plugin('currentUserPlugin');
611
        $currentUser        = $currentUserPlugin->getUser();
611
        $currentUser        = $currentUserPlugin->getUser();
612
        $currentCompany     = $currentUserPlugin->getCompany();
612
        $currentCompany     = $currentUserPlugin->getCompany();
613
        $quiz_id            = $this->params()->fromRoute('quiz_id');
613
        $quiz_id            = $this->params()->fromRoute('quiz_id');
Línea 614... Línea 614...
614
        
614
        
615
        $quizMapper = CompanyMicrolearningQuizMapper::getInstance($this->adapter);
615
        $quizMapper = MicrolearningQuizMapper::getInstance($this->adapter);
616
        $quiz = $quizMapper->fetchOneByUuid($quiz_id);
616
        $quiz = $quizMapper->fetchOneByUuid($quiz_id);
617
        if(!$quiz) {
617
        if(!$quiz) {
618
            return new JsonModel([
618
            return new JsonModel([
619
                'success'   => false,
619
                'success'   => false,
Línea 628... Línea 628...
628
            ]);
628
            ]);
629
        }
629
        }
Línea 630... Línea 630...
630
        
630
        
Línea 631... Línea 631...
631
        if($request->isPost()) {
631
        if($request->isPost()) {
Línea 632... Línea 632...
632
            
632
            
633
            $quizClone = new CompanyMicrolearningQuiz();
633
            $quizClone = new MicrolearningQuiz();
634
            
634
            
635
            $quizClone->check = CompanyMicrolearningQuiz::CHECK_PENDING;
635
            $quizClone->check = MicrolearningQuiz::CHECK_PENDING;
636
            $quizClone->status = CompanyMicrolearningQuiz::STATUS_INACTIVE;
636
            $quizClone->status = MicrolearningQuiz::STATUS_INACTIVE;
637
            $quizClone->company_id = $quiz->company_id;
637
            $quizClone->company_id = $quiz->company_id;
638
            $quizClone->failed = $quiz->failed;
638
            $quizClone->failed = $quiz->failed;
Línea 643... Línea 643...
643
            $quizClone->text = $quiz->text;
643
            $quizClone->text = $quiz->text;
Línea 644... Línea 644...
644
 
644
 
645
            if($quizMapper->insert($quizClone)) {
645
            if($quizMapper->insert($quizClone)) {
Línea 646... Línea 646...
646
                $this->logger->info('Se copio el quiz ' . $quizClone->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
646
                $this->logger->info('Se copio el quiz ' . $quizClone->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
647
                
647
                
Línea 648... Línea 648...
648
                $questionMapper = CompanyMicrolearningQuestionMapper::getInstance($this->adapter);
648
                $questionMapper = MicrolearningQuestionMapper::getInstance($this->adapter);
649
                $answerMapper = CompanyMicrolearningAnswerMapper::getInstance($this->adapter);
649
                $answerMapper = MicrolearningAnswerMapper::getInstance($this->adapter);
650
                
650
                
651
                $questions = $questionMapper->fetchAllByQuizId($quiz->id);
651
                $questions = $questionMapper->fetchAllByQuizId($quiz->id);
652
                foreach($questions as $question)
652
                foreach($questions as $question)
653
                {
653
                {
654
                    $questionClone = new CompanyMicrolearningQuestion();
654
                    $questionClone = new MicrolearningQuestion();
655
                    $questionClone->check = CompanyMicrolearningQuestion::CHECK_PENDING;
655
                    $questionClone->check = MicrolearningQuestion::CHECK_PENDING;
656
                    $questionClone->company_id = $question->company_id;
656
                    $questionClone->company_id = $question->company_id;
657
                    $questionClone->maxlength = $question->maxlength;
657
                    $questionClone->maxlength = $question->maxlength;
Línea 662... Línea 662...
662
                    
662
                    
663
                    if($questionMapper->insert($questionClone)) {
663
                    if($questionMapper->insert($questionClone)) {
664
                        $answers = $answerMapper->fetchAllByQuizIdAndQuestionId($question->quiz_id, $question->id);
664
                        $answers = $answerMapper->fetchAllByQuizIdAndQuestionId($question->quiz_id, $question->id);
665
                        foreach($answers as $answer)
665
                        foreach($answers as $answer)
666
                        {
666
                        {
667
                            $answerClone = new CompanyMicrolearningAnswer();
667
                            $answerClone = new MicrolearningAnswer();
668
                            $answerClone->company_id = $answer->company_id;
668
                            $answerClone->company_id = $answer->company_id;
669
                            $answerClone->correct = $answer->correct;
669
                            $answerClone->correct = $answer->correct;
670
                            $answerClone->points = $answer->points;
670
                            $answerClone->points = $answer->points;
671
                            $answerClone->question_id = $questionClone->id;
671
                            $answerClone->question_id = $questionClone->id;