Proyectos de Subversion LeadersLinked - Services

Rev

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

Rev 334 Rev 346
Línea 1... Línea 1...
1
<?php
1
<?php
2
/**
-
 
3
 * 
-
 
4
 * Controlador: Mis Perfiles 
-
 
5
 * 
2
 
6
 */
-
 
7
declare(strict_types=1);
3
declare(strict_types=1);
Línea 8... Línea 4...
8
 
4
 
Línea 9... Línea 5...
9
namespace LeadersLinked\Controller;
5
namespace LeadersLinked\Controller;
Línea 16... Línea 12...
16
use Laminas\View\Model\JsonModel;
12
use Laminas\View\Model\JsonModel;
Línea 17... Línea 13...
17
 
13
 
18
use LeadersLinked\Library\Functions;
14
use LeadersLinked\Library\Functions;
Línea 19... Línea -...
19
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
-
 
20
 
15
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
21
use LeadersLinked\Library\Image;
16
 
22
use LeadersLinked\Form\MyGroups\CreateForm;
17
use LeadersLinked\Form\MyGroups\CreateForm;
23
use LeadersLinked\Model\Group;
18
use LeadersLinked\Model\Group;
24
use LeadersLinked\Mapper\GroupMapper;
19
use LeadersLinked\Mapper\GroupMapper;
Línea 597... Línea 592...
597
            ];
592
            ];
Línea 598... Línea 593...
598
            
593
            
599
            return new JsonModel($response);
594
            return new JsonModel($response);
Línea 600... Línea -...
600
        }
-
 
-
 
595
        }
Línea 601... Línea 596...
601
        
596
        
602
        
597
        $storage = Storage::getInstance($this->config, $this->adapter);
603
        
-
 
604
        $request = $this->getRequest();
-
 
-
 
598
        
605
        if($request->isPost()) {
599
        $request = $this->getRequest();
-
 
600
        if($request->isPost()) {
Línea 606... Línea 601...
606
            $image = Image::getInstance($this->config);
601
            
607
            $target_path = $image->getStorage()->getPathGroup();
602
            
608
 
603
            $target_path = $storage->getPathGroup();
-
 
604
            
609
            
605
            if($operation == 'delete') {
610
            if($operation == 'delete') {
606
                $this->logger->info('Se borro el image del grupo : ' .  $group->name, ['user_id' => $group->user_id, 'ip' => Functions::getUserIP()]);
611
                $this->logger->info('Se borro el image del grupo : ' .  $group->name, ['user_id' => $group->user_id, 'ip' => Functions::getUserIP()]);
607
                if($group->image) {
612
                if($group->image) {
608
                    
613
                    if(!$image->getStorage()->deleteFile($target_path, $group->uuid, $group->image)) {
609
                    if(!$storage->deleteFile($target_path, $group->uuid, $group->image)) {
614
                        return new JsonModel([
610
                        return new JsonModel([
Línea 633... Línea 629...
633
                
629
                
Línea 634... Línea 630...
634
                $form->setData($data);
630
                $form->setData($data);
Línea -... Línea 631...
-
 
631
                
-
 
632
                if($form->isValid()) {
-
 
633
                    
635
                
634
                    list( $target_width, $target_height ) = explode('x', $this->config['leaderslinked.image_sizes.group_image_size']);
636
                if($form->isValid()) {
635
                    
637
                    
-
 
638
                    $files = $request->getFiles()->toArray();
636
                    
639
                    if(!empty($files['image']['error'])) {
637
                    $storage->setFiles($request->getFiles()->toArray());
640
                        
638
                    if(!$storage->setCurrentFilename('image')) {
641
                        return new JsonModel([
639
                        return new JsonModel([
-
 
640
                            'success'   => false,
-
 
641
                            'data'   =>  'ERROR_UPLOAD_FILE'
-
 
642
                        ]);
-
 
643
                    }
-
 
644
                    
-
 
645
                    
-
 
646
 
-
 
647
                    
-
 
648
                    
-
 
649
                    $source_filename    = $storage->getTmpFilename();
-
 
650
                    $filename           = 'group-image-' . uniqid() . '.png';
-
 
651
                    $target_filename    = $storage->composePathToFilename(Storage::TYPE_GROUP, $group->uuid, $filename);
-
 
652
                    
-
 
653
                    if($storage->uploadImageCrop($source_filename, $target_filename, $target_width, $target_height)) {
-
 
654
                        
-
 
655
                        if($group->image) {
Línea 642... Línea -...
642
                            'success'   => false,
-
 
-
 
656
                            $target_path = $storage->getPathGroup();
-
 
657
                            $storage->deleteFile($target_path, $group->uuid, $group->image);
Línea 643... Línea 658...
643
                            'data'   =>  'ERROR_UPLOAD_FILE'
658
                        }
644
                        ]);
659
                        
645
                        
660
                        
646
                        
661
                        
647
                    }
662
                   
648
                    
663
                    
649
                    if($group->image) {
664
                        $group->image = $filename;
650
                        if(!$image->getStorage()->deleteFile($target_path, $group->uuid, $group->image)) {
665
                        if(!$groupMapper->updateImage($group)) {
Línea 651... Línea -...
651
                            return new JsonModel([
-
 
652
                                'success'   => false,
-
 
653
                                'data'   =>  'ERROR_THERE_WAS_AN_ERROR'
-
 
654
                            ]);
-
 
655
                        }
-
 
656
                    }
-
 
657
 
-
 
658
                    
-
 
659
                    list( $target_width, $target_height ) = explode('x', $this->config['leaderslinked.image_sizes.group_image_size']);
-
 
660
                    $source             = $files['image']['tmp_name'];
-
 
661
                    $target_filename    = 'group-image-' . uniqid() . '.png';
-
 
662
                    $crop_to_dimensions = true;
-
 
663
                    $unlink_source = true;
-
 
664
                    
-
 
665
                    if(!$image->uploadProcessChangeSize($source, $target_path, $group->uuid, $target_filename, $target_width, $target_height, $crop_to_dimensions, $unlink_source)) {
-
 
666
                        return new JsonModel([
-
 
667
                            'success'   => false,
-
 
668
                            'data'   =>  'ERROR_THERE_WAS_AN_ERROR'
-
 
669
                        ]);
-
 
670
                    }
-
 
671
                    
-
 
672
                    $group->image = $target_filename;
-
 
673
                    if(!$groupMapper->updateImage($group)) {
666
                            return new JsonModel([
Línea 674... Línea 667...
674
                        return new JsonModel([
667
                                'success'   => false,
675
                            'success'   => false,
668
                                'data'   =>  'ERROR_THERE_WAS_AN_ERROR'
676
                            'data'   =>  'ERROR_THERE_WAS_AN_ERROR'
669
                            ]);
Línea 692... Línea 685...
692
                        'data'   => $messages
685
                        'data'   => $messages
693
                    ]);
686
                    ]);
694
                }
687
                }
695
            }
688
            }
Línea 696... Línea -...
696
            
-
 
-
 
689
            
Línea 697... Línea 690...
697
            $storage = Storage::getInstance($this->config, $this->adapter);
690
            
698
            
691
            
699
            return new JsonModel([
692
            return new JsonModel([
Línea 700... Línea 693...
700
                'success'   => true,
693
                'success'   => true,
701
                'data' => $storage->getGroupImage($group),
694
                'data'      => $storage->getGroupImage($group),
Línea 747... Línea 740...
747
        
740
        
748
        
741
        
-
 
742
        
749
        
743
        $request = $this->getRequest();
750
        $request = $this->getRequest();
744
        if($request->isPost()) {
Línea 751... Línea 745...
751
        if($request->isPost()) {
745
            
752
            $image = Image::getInstance($this->config);
746
            $storage = Storage::getInstance($this->config, $this->adapter);
753
            $target_path = $image->getStorage()->getPathGroup();
747
            $target_path = $storage->getPathGroup();
754
            
748
            
755
            
749
            
756
            if($operation == 'delete') {
750
            if($operation == 'delete') {
757
                if($group->cover) {
751
                if($group->cover) {
758
                    if(!$image->getStorage()->delete($target_path, $group->uuid, $group->cover)) {
752
                    if(!$storage->delete($target_path, $group->uuid, $group->cover)) {
Línea 779... Línea 773...
779
                
773
                
Línea 780... Línea 774...
780
                $form->setData($data);
774
                $form->setData($data);
Línea 781... Línea 775...
781
                
775
                
782
                if($form->isValid()) {
776
                if($form->isValid()) {
783
                    
777
                    
784
                    $files = $request->getFiles()->toArray();
778
                    $storage->setFiles($request->getFiles()->toArray());
785
                    if(!empty($files['cover']['error'])) {
779
                    if(!$storage->setCurrentFilename('cover')) {
786
                        
780
          
787
                        return new JsonModel([
781
                        return new JsonModel([
Línea 788... Línea 782...
788
                            'success'   => false,
782
                            'success'   => false,
Línea -... Línea 783...
-
 
783
                            'data'   =>  'ERROR_UPLOAD_FILE'
-
 
784
                        ]);
-
 
785
                        
-
 
786
                        
-
 
787
                    }
-
 
788
                    
-
 
789
                    list( $target_width, $target_height ) = explode('x', $this->config['leaderslinked.image_sizes.group_cover_size']);
-
 
790
                    
-
 
791
                    
-
 
792
                    
-
 
793
 
789
                            'data'   =>  'ERROR_UPLOAD_FILE'
794
                    
790
                        ]);
795
                    $source_filename    = $storage->getTmpFilename();
-
 
796
                    $filename           = 'group-cover-' . uniqid() . '.png';
-
 
797
                    $target_filename    = $storage->composePathToFilename(Storage::TYPE_GROUP, $group->uuid, $filename);
-
 
798
                   
-
 
799
                    if($storage->uploadImageCrop($source_filename, $target_filename, $target_width, $target_height)) {
-
 
800
                        if($group->cover) {
-
 
801
                            if(!$storage->delete($target_path, $group->uuid, $group->cover)) {
-
 
802
                                return new JsonModel([
-
 
803
                                    'success'   => false,
-
 
804
                                    'data'   =>  'ERROR_THERE_WAS_AN_ERROR'
791
                        
805
                                ]);
792
                        
806
                            }
793
                    }
807
                        }
794
                    
808
                        
795
                    if($group->cover) {
809
                        $group->cover = $filename;
796
                        if(!$image->getStorage()->delete($target_path, $group->uuid, $group->cover)) {
-
 
797
                            return new JsonModel([
810
                        if(!$groupMapper->updateCover($group)) {
798
                                'success'   => false,
-
 
799
                                'data'   =>  'ERROR_THERE_WAS_AN_ERROR'
-
 
800
                            ]);
-
 
801
                        }
-
 
802
                    }
811
                            return new JsonModel([
803
 
-
 
804
                    list( $target_width, $target_height ) = explode('x', $this->config['leaderslinked.image_sizes.group_cover_size']);
-
 
805
                    $source             = $files['cover']['tmp_name'];
812
                                'success'   => false,
806
                    $target_filename    = 'group-cover-' . uniqid() . '.png';
813
                                'data'   =>  'ERROR_THERE_WAS_AN_ERROR'
807
                    $crop_to_dimensions = false;
814
                            ]);
808
                    $unlink_source = true;
815
                        }
809
                    
816
                        
Línea 810... Línea -...
810
                    if(!$image->uploadProcessChangeSize($source, $target_path, $group->uuid, $target_filename, $target_width, $target_height, $crop_to_dimensions, $unlink_source)) {
-
 
811
                        return new JsonModel([
-
 
812
                            'success'   => false,
-
 
813
                            'data'   =>  'ERROR_THERE_WAS_AN_ERROR'
-
 
814
                        ]);
-
 
815
                    }
-
 
816
                    
-
 
-
 
817
                    } else {
Línea 817... Línea 818...
817
                    
818
                        return new JsonModel([
Línea 818... Línea 819...
818
                    
819
                            'success'   => false,
819
                    $group->cover = $target_filename;
820
                            'data'   =>  'ERROR_THERE_WAS_AN_ERROR'