Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 17257 | Rev 17259 | Ir a la última revisión | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 17257 Rev 17258
Línea 540... Línea 540...
540
                            
540
                            
541
                            if($slide->file) {
541
                            if($slide->file) {
542
                                if(!$storage->deleteFile($target_path, $slide->uuid, $slide->file)) {
542
                                if(!$storage->deleteFile($target_path, $slide->uuid, $slide->file)) {
543
                                    return new JsonModel([
543
                                    return new JsonModel([
544
                                        'success'   => false,
544
                                        'success'   => false,
545
                                        'data'   =>  'Error al eliminar el video'
545
                                        'data'   =>  'ERROR_THERE_WAS_AN_ERROR'
546
                                    ]);
546
                                    ]);
547
                                }
547
                                }
Línea 548... Línea 548...
548
                            }
548
                            }
549
 
549
 
550
                            if(!$storage->putFile($source_filename, $target_filename)) {
550
                            if(!$storage->putFile($source_filename, $target_filename)) {
551
                                return new JsonModel([
551
                                return new JsonModel([
552
                                    'success'   => false,
552
                                    'success'   => false,
553
                                    'data'   =>  'Error al subir el video'
553
                                    'data'   =>  'ERROR_UPLOAD_FILE'
Línea 554... Línea 554...
554
                                ]);
554
                                ]);
555
                            }
555
                            }
Línea 562... Línea 562...
562
                            $videoConvertMapper = VideoConvertMapper::getInstance($this->adapter);
562
                            $videoConvertMapper = VideoConvertMapper::getInstance($this->adapter);
Línea 563... Línea 563...
563
 
563
 
564
                            try {
564
                            try {
565
                                $videoConvertMapper->insert($videoConvert);
565
                                $videoConvertMapper->insert($videoConvert);
-
 
566
                            } catch (\Exception $e) {
566
                            } catch (\Exception $e) {
567
                                $this->logger->error('Error al insertar el video: ' . $e->getMessage());
567
                                return new JsonModel([
568
                                return new JsonModel([
568
                                    'success'   => false,
569
                                    'success'   => false,
569
                                    'data'   =>  'Error al convertir el video: ' . $e->getMessage()
570
                                    'data'   =>  'ERROR_THERE_WAS_AN_ERROR'
570
                                ]);
571
                                ]);
Línea 571... Línea 572...
571
                            }
572
                            }
Línea 572... Línea 573...
572
                               
573
                               
-
 
574
                            $slide->file = $filename;
573
                            $slide->file = $filename;
575
                            
574
                            
576
                            if(!$slideMapper->update($slide)) {
575
                            if(!$slideMapper->update($slide)) {
577
                                $this->logger->error('Error al actualizar el video: ' . $slideMapper->getError());
576
                                return new JsonModel([
578
                                return new JsonModel([
577
                                    'success'   => false,
579
                                    'success'   => false,
578
                                    'data'   =>  'Error al actualizar el video'
580
                                    'data'   =>  'ERROR_THERE_WAS_AN_ERROR'
579
                                ]);
581
                                ]);
Línea 580... Línea 582...
580
                            }
582
                            }
581
                        break;
583
                        break;
582
                    }
584
                    }
583
 
585
 
584
                    if($storage->setCurrentFilename('background')) {
586
                    if($storage->setCurrentFilename('background')) {
585
                        if($slide->background) {
587
                        if($slide->background) {
586
                            if(!$storage->deleteFile($target_path, $slide->uuid, $slide->background)) {
588
                            if(!$storage->deleteFile($target_path, $slide->uuid, $slide->background)) {
587
                                return new JsonModel([
589
                                return new JsonModel([
588
                                    'success'   => false,
590
                                    'success'   => false,
Línea 589... Línea 591...
589
                                    'data'   =>  'Error al eliminar el fondo'
591
                                    'data'   =>  'ERROR_THERE_WAS_AN_ERROR'
Línea 602... Línea 604...
602
                        list($target_width, $target_height) = explode('x', $this->config['leaderslinked.image_sizes.microlearning_image_size']);
604
                        list($target_width, $target_height) = explode('x', $this->config['leaderslinked.image_sizes.microlearning_image_size']);
Línea 603... Línea 605...
603
                        
605
                        
604
                        if(!$storage->uploadImageCrop($tmp_filename, $target_filename, $target_width, $target_height)) {
606
                        if(!$storage->uploadImageCrop($tmp_filename, $target_filename, $target_width, $target_height)) {
605
                            return new JsonModel([
607
                            return new JsonModel([
606
                                'success'   => false,
608
                                'success'   => false,
607
                                'data'   =>  'Error al subir el fondo'
609
                                'data'   =>  'ERROR_THERE_WAS_AN_ERROR'
608
                            ]);
610
                            ]);
Línea 609... Línea 611...
609
                        }
611
                        }
610
    
612
    
611
                        $slide->background = $filename;
613
                        $slide->background = $filename;
612
                        if(!$slideMapper->update($slide)) {
614
                        if(!$slideMapper->update($slide)) {
613
                            return new JsonModel([
615
                            return new JsonModel([
614
                                'success'   => false,
616
                                'success'   => false,
615
                                'data'   =>  'Error al actualizar el fondo'
617
                                'data'   =>  'ERROR_THERE_WAS_AN_ERROR'
616
                            ]);
618
                            ]);
617
                        }
-
 
618
                    }
619
                        }
619
                    
-
 
620
                    
620
                    }
Línea 621... Línea 621...
621
                    
621
                          
622
                    $this->logger->info('Se agrego la diapositiva ' . $slide->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
622
                    $this->logger->info('Se agrego la diapositiva ' . $slide->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
623
                    
623
                    
Línea 667... Línea 667...
667
     * Borrar un perfil excepto el público
667
     * Borrar un perfil excepto el público
668
     * @return \Laminas\View\Model\JsonModel
668
     * @return \Laminas\View\Model\JsonModel
669
     */
669
     */
670
    public function deleteAction()
670
    public function deleteAction()
671
    {
671
    {
672
        $currentUserPlugin = $this->plugin('currentUserPlugin');
-
 
673
        $currentUser = $currentUserPlugin->getUser();
672
        try {
674
        $currentCompany = $currentUserPlugin->getCompany();
-
 
675
        
-
 
676
        $request    = $this->getRequest();
673
            $request    = $this->getRequest();
677
 
-
 
678
        $capsule_uuid = $this->params()->fromRoute('capsule_uuid');
-
 
679
        $slide_uuid = $this->params()->fromRoute('slide_uuid');
-
 
680
        
-
 
Línea -... Línea 674...
-
 
674
 
-
 
675
            $currentUserPlugin = $this->plugin('currentUserPlugin');
-
 
676
            $currentUser = $currentUserPlugin->getUser();
Línea -... Línea 677...
-
 
677
            $currentCompany = $currentUserPlugin->getCompany();
-
 
678
    
681
 
679
            $capsule_uuid = $this->params()->fromRoute('capsule_uuid');
682
    
680
            $slide_uuid = $this->params()->fromRoute('slide_uuid');
683
        
681
            
684
        $capsuleMapper = MicrolearningCapsuleMapper::getInstance($this->adapter);
682
            $capsuleMapper = MicrolearningCapsuleMapper::getInstance($this->adapter);
685
        $capsule = $capsuleMapper->fetchOneByUuid($capsule_uuid);
683
            $capsule = $capsuleMapper->fetchOneByUuid($capsule_uuid);
686
        if(!$capsule) {
684
            if(!$capsule) {
687
            return new JsonModel([
685
                return new JsonModel([
688
                'success'   => false,
686
                    'success'   => false,
689
                'data'   => 'ERROR_CAPSULE_NOT_FOUND'
687
                    'data'   => 'ERROR_CAPSULE_NOT_FOUND'
690
            ]);
688
                ]);
691
        }
689
            }
692
        
690
            
693
        if($capsule->company_id != $currentCompany->id) {
691
            if($capsule->company_id != $currentCompany->id) {
694
            return new JsonModel([
692
                return new JsonModel([
695
                'success'   => false,
693
                    'success'   => false,
696
                'data'   => 'ERROR_UNAUTHORIZED'
694
                    'data'   => 'ERROR_UNAUTHORIZED'
697
            ]);
695
                ]);
698
        }
696
            }
699
        
697
            
700
        $slideMapper = MicrolearningSlideMapper::getInstance($this->adapter);
698
            $slideMapper = MicrolearningSlideMapper::getInstance($this->adapter);
701
        $slide = $slideMapper->fetchOneByUuid($slide_uuid);
699
            $slide = $slideMapper->fetchOneByUuid($slide_uuid);
702
        if(!$slide) {
700
            if(!$slide) {
703
            return new JsonModel([
701
                return new JsonModel([
704
                'success'   => false,
702
                    'success'   => false,
705
                'data'   => 'ERROR_SLIDE_NOT_FOUND'
703
                    'data'   => 'ERROR_SLIDE_NOT_FOUND'
706
            ]);
704
                ]);
707
        }
705
            }
708
        
706
            
709
        if($slide->capsule_id != $capsule->id) {
707
            if($slide->capsule_id != $capsule->id) {
710
            return new JsonModel([
708
                return new JsonModel([
711
                'success'   => false,
709
                    'success'   => false,
712
                'data'   => 'ERROR_UNAUTHORIZED'
710
                    'data'   => 'ERROR_UNAUTHORIZED'
Línea 713... Línea 711...
713
            ]);
711
                ]);
-
 
712
            }
-
 
713
 
-
 
714
            if(!$request->isPost()) {
-
 
715
                return new JsonModel([
-
 
716
                    'success'   => false,
Línea 714... Línea 717...
714
        }
717
                    'data'   => 'ERROR_METHOD_NOT_ALLOWED'
715
 
-
 
716
        if($request->isPost()) {
718
                ]);
717
            
-
 
718
            $result =  $slideMapper->delete($slide);
-
 
719
            if($result) {
-
 
720
                $this->logger->info('Se borro la diapositiva : ' .  $capsule->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
-
 
721
                
-
 
722
                
-
 
723
                
-
 
724
                $storage = Storage::getInstance($this->config, $this->adapter);
-
 
725
                $target_path = $storage->getPathMicrolearningSlide();
719
            }
726
                
-
 
727
                $storage->deleteFile($target_path, $slide->uuid, $slide->file);
-
 
728
                
-
 
729
                if($slide->background) {
-
 
730
                    $storage->deleteFile($target_path, $slide->uuid, $slide->background);
-
 
731
                }
-
 
732
                
-
 
733
                $data = [
-
 
734
                    'success' => true,
-
 
735
                    'data' => 'LABEL_RECORD_DELETED'
-
 
736
                ];
720
            
737
            } else {
721
            if(!$slideMapper->delete($slide)) {
738
                
722
                $this->logger->error('Error al borrar la diapositiva: ' . $slideMapper->getError());
-
 
723
                return new JsonModel([
-
 
724
                    'success'   => false,
-
 
725
                    'data'   => 'ERROR_THERE_WAS_AN_ERROR'
Línea -... Línea 726...
-
 
726
                ]);
-
 
727
            }
-
 
728
 
-
 
729
            $this->logger->info('Se borro la diapositiva : ' .  $slide->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
-
 
730
                
-
 
731
            $storage = Storage::getInstance($this->config, $this->adapter);
739
                $data = [
732
            $target_path = $storage->getPathMicrolearningSlide();
-
 
733
 
-
 
734
            if($slide->file) {
-
 
735
                if(!$storage->deleteFile($target_path, $slide->uuid, $slide->file)) {
-
 
736
                    $this->logger->error('Error al borrar el archivo: ' . $slide->file);
-
 
737
                    return new JsonModel([
-
 
738
                        'success'   => false,
-
 
739
                        'data'   => 'ERROR_THERE_WAS_AN_ERROR'
-
 
740
                    ]);
-
 
741
                }
-
 
742
            }
-
 
743
 
-
 
744
            if($slide->background) {
-
 
745
                if(!$storage->deleteFile($target_path, $slide->uuid, $slide->background)) {
-
 
746
                    $this->logger->error('Error al borrar el fondo: ' . $slide->background);
740
                    'success'   => false,
747
                    return new JsonModel([
Línea 741... Línea -...
741
                    'data'      => $capsuleMapper->getError()
-
 
742
                ];
-
 
743
                
-
 
744
                return new JsonModel($data);
-
 
745
            }
-
 
Línea 746... Línea 748...
746
            
748
                        'success'   => false,
-
 
749
                        'data'   => 'ERROR_THERE_WAS_AN_ERROR'
-
 
750
                    ]);
-
 
751
                }
-
 
752
            }
-
 
753
            
-
 
754
            
-
 
755
            return new JsonModel([
-
 
756
                'success' => true,
-
 
757
                'data' => 'LABEL_RECORD_DELETED'
747
        } else {
758
            ]);
748
            $data = [
-
 
749
                'success' => false,
-
 
750
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
759
        } catch (\Exception $e) {
Línea 751... Línea 760...
751
            ];
760
            $this->logger->error('Error al borrar la diapositiva: ' . $e->getMessage());
752
            
761
            return new JsonModel([