Proyectos de Subversion LeadersLinked - Backend

Rev

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

Rev 17076 Rev 17077
Línea 625... Línea 625...
625
            $form->setData($dataPost);
625
            $form->setData($dataPost);
Línea 626... Línea 626...
626
            
626
            
627
            if($form->isValid()) {
627
            if($form->isValid()) {
Línea -... Línea 628...
-
 
628
                $dataPost = (array) $form->getData();
-
 
629
                
628
                $dataPost = (array) $form->getData();
630
                $capsule->name = $dataPost['name'];
-
 
631
                $capsule->description = $dataPost['description'];
-
 
632
                $capsule->status = $dataPost['status'];
629
                
633
                $capsule->privacy = $dataPost['privacy'];
-
 
634
                $capsule->type = $dataPost['type'];
-
 
635
                $capsule->cost = $dataPost['cost'];
Línea 630... Línea 636...
630
                $hydrator = new ObjectPropertyHydrator();
636
                $capsule->order = $dataPost['order'];
-
 
637
                $capsule->image = '';
631
                $hydrator->hydrate($dataPost, $capsule);
638
                
-
 
639
                if(!$capsuleMapper->update($capsule)) {
-
 
640
                    return new JsonModel([
-
 
641
                        'success'   => false,
Línea -... Línea 642...
-
 
642
                        'data'      => $capsuleMapper->getError()
632
                
643
                    ]);
633
                $capsule->image = null;
644
                }
-
 
645
                
-
 
646
                $capsule = $capsuleMapper->fetchOne($capsule->id);
Línea -... Línea 647...
-
 
647
                $storage = Storage::getInstance($this->config, $this->adapter);
-
 
648
                $target_path = $storage->getPathMicrolearningCapsule();
-
 
649
 
-
 
650
                $storage->setFiles($request->getFiles()->toArray());
-
 
651
                
-
 
652
                if (!$storage->setCurrentFilename('file')) {
-
 
653
                    return new JsonModel([
-
 
654
                        'success'   => false,
-
 
655
                        'data'      => 'ERROR_UPLOAD_IMAGE'
-
 
656
                    ]);
-
 
657
                }
-
 
658
 
-
 
659
                $target_size = $this->config['leaderslinked.image_sizes.microlearning_image_size'];
-
 
660
                list($target_width, $target_height) = explode('x', $target_size);
-
 
661
 
-
 
662
                $source_filename = $storage->getTmpFilename();
-
 
663
                $filename = 'capsule-' . uniqid() . '.jpg';
-
 
664
                $target_filename = $storage->composePathToFilename(
-
 
665
                    Storage::TYPE_MICROLEARNING_CAPSULE,
-
 
666
                    $capsule->uuid,
-
 
667
                    $filename
-
 
668
                );
-
 
669
 
-
 
670
                if (!$storage->uploadImageCrop($source_filename, $target_filename, $target_width, $target_height)) {
-
 
671
                    return new JsonModel([
-
 
672
                        'success'   => false,
-
 
673
                        'data'      => 'ERROR_UPLOAD_IMAGE'
-
 
674
                    ]);
-
 
675
                }
-
 
676
 
-
 
677
                if($capsule->image) {
634
                $capsule->marketplace = null;
678
                    $storage->deleteFile($target_path, $capsule->uuid, $capsule->image);
-
 
679
                }
-
 
680
 
-
 
681
                $capsule->image = $filename;
-
 
682
 
-
 
683
                if(!$capsuleMapper->update($capsule)) {
-
 
684
                    return new JsonModel([
-
 
685
                        'success'   => false,
Línea 635... Línea -...
635
                
-
 
Línea 636... Línea -...
636
                $image = Image::getInstance($this->config);
-
 
637
                $target_path = $image->getStorage()->getPathMicrolearningCapsule();
-
 
Línea 638... Línea -...
638
                
-
 
639
                if($capsuleMapper->update($capsule)) {
686
                        'data'      => $capsuleMapper->getError()
640
                    
687
                    ]);
641
                    $capsule = $capsuleMapper->fetchOne($capsule->id);
688
                }
642
                    
689
             
643
                    $files = $this->getRequest()->getFiles()->toArray();
690
                /* if(isset($files['marketplace']) && empty($files['marketplace']['error'])) {
644
            
-
 
645
                    
-
 
646
                    if(isset($files['file']) && empty($files['file']['error'])) {
-
 
647
                        $tmp_filename  = $files['file']['tmp_name'];
-
 
648
                        // $filename      = \LeadersLinked\Library\Functions::normalizeStringFilename($files['file']['name']);
-
 
649
                        
-
 
650
                        try {
-
 
651
                            if($capsule->image) {
-
 
652
                                
-
 
653
                                if(!$image->getStorage()->deleteFile($target_path, $capsule->uuid, $capsule->image)) {
-
 
654
                                    return new JsonModel([
-
 
655
                                        'success'   => false,
-
 
656
                                        'data'   =>  'ERROR_THERE_WAS_AN_ERROR'
-
 
657
                                    ]);
-
 
658
                                }
-
 
Línea 659... Línea 691...
659
                            }
691
                    
660
                            
-
 
661
                            
692
                    
662
                            list($target_width, $target_height) = explode('x', $this->config['leaderslinked.image_sizes.microlearning_image_size']);
693
                    
-
 
694
                    $tmp_filename  = $files['marketplace']['tmp_name'];
-
 
695
                    // $filename      = \LeadersLinked\Library\Functions::normalizeStringFilename($files['file']['name']);
663
                            
696
                    
664
                            $filename = 'capsule-' .uniqid() . '.jpg';
-
 
665
                            $crop_to_dimensions = false;
-
 
666
                            $unlink_source = true;
697
                    try {
667
                            
-
 
668
                            if($image->uploadProcessChangeSize($tmp_filename, $target_path, $capsule->uuid, $filename, $target_width, $target_height, $crop_to_dimensions, $unlink_source)) {
-
 
669
        
-
 
670
                                $capsule->image = $filename;
-
 
Línea -... Línea 698...
-
 
698
                        if($capsule->marketplace) {
Línea 671... Línea 699...
671
                                $capsuleMapper->update($capsule);
699
                            
672
                            }
700
                            if(!$image->getStorage()->deleteFile($target_path, $capsule->uuid, $capsule->marketplace)) {
-
 
701
                                return new JsonModel([
Línea 673... Línea -...
673
                        } catch(\Throwable $e) {
-
 
674
                            error_log($e->getTraceAsString());
-
 
675
                        }
-
 
676
                    }
-
 
677
                 
-
 
678
                    if(isset($files['marketplace']) && empty($files['marketplace']['error'])) {
-
 
679
                        
-
 
680
                        
-
 
681
                        
-
 
682
                        $tmp_filename  = $files['marketplace']['tmp_name'];
-
 
683
                        // $filename      = \LeadersLinked\Library\Functions::normalizeStringFilename($files['file']['name']);
-
 
684
                        
-
 
685
                        try {
-
 
686
                            if($capsule->marketplace) {
-
 
687
                                
-
 
688
                                if(!$image->getStorage()->deleteFile($target_path, $capsule->uuid, $capsule->marketplace)) {
-
 
689
                                    return new JsonModel([
-
 
690
                                        'success'   => false,
702
                                    'success'   => false,
691
                                        'data'   =>  'ERROR_THERE_WAS_AN_ERROR'
703
                                    'data'   =>  'ERROR_THERE_WAS_AN_ERROR'
692
                                    ]);
704
                                ]);
693
                                }
705
                            }
694
                            }
-
 
695
                            
-
 
696
                            list($target_width, $target_height) = explode('x', $this->config['leaderslinked.image_sizes.marketplace']);
-
 
697
                            
706
                        }
-
 
707
                        
-
 
708
                        list($target_width, $target_height) = explode('x', $this->config['leaderslinked.image_sizes.marketplace']);
698
                            $filename = 'marketplace-' .uniqid() . '.jpg';
709
                        
-
 
710
                        $filename = 'marketplace-' .uniqid() . '.jpg';
699
                            $crop_to_dimensions = false;
711
                        $crop_to_dimensions = false;
700
                            $unlink_source = true;
-
 
701
                            
-
 
702
                            if($image->uploadProcessChangeSize($tmp_filename, $target_path, $capsule->uuid, $filename, $target_width, $target_height, $crop_to_dimensions, $unlink_source)) {
-
 
703
                         
712
                        $unlink_source = true;
704
                                $capsule->marketplace = $filename;
-
 
705
                                $capsuleMapper->update($capsule);
-
 
706
                            }
-
 
707
                        } catch(\Throwable $e) {
-
 
708
                            error_log($e->getTraceAsString());
-
 
709
                        }
-
 
710
                    }
-
 
711
                    
-
 
712
            
-
 
713
                    
-
 
714
                   
-
 
715
                    $this->logger->info('Se edito la cápsula ' . $capsule->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
-
 
Línea 716... Línea 713...
716
                    
713
                        
-
 
714
                        if($image->uploadProcessChangeSize($tmp_filename, $target_path, $capsule->uuid, $filename, $target_width, $target_height, $crop_to_dimensions, $unlink_source)) {
-
 
715
                     
-
 
716
                            $capsule->marketplace = $filename;
Línea 717... Línea 717...
717
                    $data = [
717
                            $capsuleMapper->update($capsule);
718
                        'success'   => true,
718
                        }
719
                        'data'   => 'LABEL_RECORD_UPDATED'
719
                    } catch(\Throwable $e) {
720
                    ];
720
                        error_log($e->getTraceAsString());
Línea 741... Línea 741...
741
                    'success'   => false,
741
                    'success'   => false,
742
                    'data'   => $messages
742
                    'data'   => $messages
743
                ]);
743
                ]);
744
            }
744
            }
745
        } else {
745
        } else {
746
            $data = [
746
            return new JsonModel([
747
                'success' => false,
747
                'success' => false,
748
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
748
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
749
            ];
749
            ]);
750
            
-
 
751
            return new JsonModel($data);
-
 
752
        }
750
        }
753
        
-
 
754
        return new JsonModel($data);
-
 
755
    }
751
    }
Línea 756... Línea 752...
756
    
752
    
757
    
753