Proyectos de Subversion LeadersLinked - Backend

Rev

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

Rev 17292 Rev 17350
Línea 40... Línea 40...
40
 
40
 
Línea 41... Línea 41...
41
    const TYPE_MICROLEARNING_CAPSULE = 'capsule';
41
    const TYPE_MICROLEARNING_CAPSULE = 'capsule';
Línea 42... Línea -...
42
 
-
 
43
    const TYPE_MICROLEARNING_SLIDE = 'slide';
-
 
44
 
42
 
Línea 45... Línea 43...
45
    const TYPE_MICROLEARNING_ACCESS_FOR_STUDENTS = 'access-for-students';
43
    const TYPE_MICROLEARNING_SLIDE = 'slide';
Línea 46... Línea 44...
46
 
44
 
Línea 102... Línea 100...
102
     */
100
     */
103
    private $storagePath;
101
    private $storagePath;
Línea 104... Línea 102...
104
 
102
 
105
    /**
103
    /**
-
 
104
     *
-
 
105
     * @var string
-
 
106
     */
-
 
107
    private $fullStoragePath;
-
 
108
 
-
 
109
    /**
-
 
110
     *
-
 
111
     * @var array
-
 
112
     */
-
 
113
    private $storageConfig;
-
 
114
 
-
 
115
    /**
106
     *
116
     *
107
     * @var array
117
     * @var array
108
     */
118
     */
Línea 124... Línea 134...
124
    {
134
    {
125
        $this->config = $config;
135
        $this->config = $config;
126
        $this->adapter = $adapter;
136
        $this->adapter = $adapter;
127
        $this->currentFile = [];
137
        $this->currentFile = [];
Línea -... Línea 138...
-
 
138
 
128
 
139
        // Ruta relativa para BD
-
 
140
        $this->storagePath = 'data' . DIRECTORY_SEPARATOR . 'storage';
-
 
141
        
-
 
142
        // Ruta completa para operaciones de archivo
-
 
143
        $this->fullStoragePath = $this->config['leaderslinked.storage.path'] . DIRECTORY_SEPARATOR . $this->storagePath;
129
        $this->storagePath = 'data' . DIRECTORY_SEPARATOR . 'storage';
144
 
130
        if (! file_exists($this->storagePath)) {
145
        if (!file_exists($this->fullStoragePath)) {
131
            mkdir($this->storagePath, 0775, true);
146
            mkdir($this->fullStoragePath, 0775, true);
Línea 132... Línea 147...
132
        }
147
        }
Línea 133... Línea 148...
133
 
148
 
134
        $this->tempPath = 'data' . DIRECTORY_SEPARATOR . 'storage' . DIRECTORY_SEPARATOR . 'tmp';
149
        $this->tempPath = $this->storagePath . DIRECTORY_SEPARATOR . 'tmp';
135
 
150
 
136
        if (! file_exists($this->tempPath)) {
151
        if (! file_exists($this->tempPath)) {
Línea 157... Línea 172...
157
     *
172
     *
158
     * @return string
173
     * @return string
159
     */
174
     */
160
    public function getFullPathImageDefault()
175
    public function getFullPathImageDefault()
161
    {
176
    {
162
        return $this->storagePath . DIRECTORY_SEPARATOR . 'no-image.jpg';
177
        return $this->fullStoragePath . DIRECTORY_SEPARATOR . 'no-image.jpg';
163
    }
178
    }
Línea 164... Línea 179...
164
 
179
 
165
    /**
180
    /**
166
     *
181
     *
167
     * @return string
182
     * @return string
168
     */
183
     */
169
    public function getFullPathImageUserDefault()
184
    public function getFullPathImageUserDefault()
170
    {
185
    {
171
        return $this->storagePath . DIRECTORY_SEPARATOR . 'no-image-user.jpg';
186
        return $this->fullStoragePath . DIRECTORY_SEPARATOR . 'no-image-user.jpg';
Línea 172... Línea 187...
172
    }
187
    }
173
 
188
 
174
    /**
189
    /**
175
     *
190
     *
176
     * @return string
191
     * @return string
177
     */
192
     */
178
    public function getFullPathImageUserPofileDefault()
193
    public function getFullPathImageUserPofileDefault()
179
    {
194
    {
Línea 180... Línea 195...
180
        return $this->storagePath . DIRECTORY_SEPARATOR . 'no-image-user-profile.png';
195
        return $this->fullStoragePath . DIRECTORY_SEPARATOR . 'no-image-user-profile.png';
181
    }
196
    }
182
 
197
 
183
    /**
198
    /**
184
     *
199
     *
185
     * @return string
200
     * @return string
186
     */
201
     */
187
    public function getFullPathImageUserCoverDefault()
202
    public function getFullPathImageUserCoverDefault()
Línea 188... Línea 203...
188
    {
203
    {
189
        return $this->storagePath . DIRECTORY_SEPARATOR . 'no-image-cover.jpg';
204
        return $this->fullStoragePath . DIRECTORY_SEPARATOR . 'no-image-cover.jpg';
190
    }
205
    }
191
 
206
 
192
    /**
207
    /**
193
     *
208
     *
194
     * @return string
209
     * @return string
195
     */
210
     */
Línea 196... Línea 211...
196
    public function getFullPathImageCompanyDefault()
211
    public function getFullPathImageCompanyDefault()
197
    {
212
    {
198
        return $this->storagePath . DIRECTORY_SEPARATOR . 'no-image-company.jpg';
213
        return $this->fullStoragePath . DIRECTORY_SEPARATOR . 'no-image-company.jpg';
199
    }
214
    }
200
 
215
 
201
    /**
216
    /**
202
     *
217
     *
203
     * @return string
218
     * @return string
Línea 204... Línea 219...
204
     */
219
     */
205
    public function getFullPathImageCompanyCoverDefault()
220
    public function getFullPathImageCompanyCoverDefault()
206
    {
221
    {
207
        return $this->storagePath . DIRECTORY_SEPARATOR . 'no-image-cover.jpg';
222
        return $this->fullStoragePath . DIRECTORY_SEPARATOR . 'no-image-cover.jpg';
208
    }
223
    }
209
 
224
 
210
    /**
225
    /**
211
     *
226
     *
Línea 212... Línea 227...
212
     * @return string
227
     * @return string
213
     */
228
     */
214
    public function getFullPathImageGroupDefault()
229
    public function getFullPathImageGroupDefault()
215
    {
230
    {
216
        return $this->storagePath . DIRECTORY_SEPARATOR . 'no-image-group.jpg';
231
        return $this->fullStoragePath . DIRECTORY_SEPARATOR . 'no-image-group.jpg';
217
    }
232
    }
218
 
233
 
219
    /**
234
    /**
Línea 220... Línea 235...
220
     *
235
     *
221
     * @return string
236
     * @return string
222
     */
237
     */
223
    public function getFullPathImageGroupCoverDefault()
238
    public function getFullPathImageGroupCoverDefault()
224
    {
239
    {
225
        return $this->storagePath . DIRECTORY_SEPARATOR . 'no-image-cover.jpg';
240
        return $this->fullStoragePath . DIRECTORY_SEPARATOR . 'no-image-cover.jpg';
226
    }
241
    }
227
 
242
 
Línea 228... Línea 243...
228
    /**
243
    /**
229
     *
244
     *
230
     * @return string
245
     * @return string
231
     */
246
     */
232
    public function getFullPathImageCompanyHeaderPdfDefault()
247
    public function getFullPathImageCompanyHeaderPdfDefault()
233
    {
248
    {
234
        return $this->storagePath . DIRECTORY_SEPARATOR . 'default' . DIRECTORY_SEPARATOR . 'company-header.png';
249
        return $this->fullStoragePath . DIRECTORY_SEPARATOR . 'default' . DIRECTORY_SEPARATOR . 'company-header.png';
-
 
250
    }
-
 
251
 
-
 
252
    /**
-
 
253
     *
-
 
254
     * @return string
-
 
255
     */
-
 
256
    public function getFullPathImageCompanyFooterPdfDefault()
-
 
257
    {
-
 
258
        return $this->fullStoragePath . DIRECTORY_SEPARATOR . 'default' . DIRECTORY_SEPARATOR . 'company-footer.png';
-
 
259
    }
-
 
260
 
-
 
261
    /**
-
 
262
     * Convierte una ruta relativa a ruta completa para operaciones de archivo
-
 
263
     * @param string $relativePath
-
 
264
     * @return string
-
 
265
     */
-
 
266
    private function getFullPathFromRelative($relativePath)
-
 
267
    {
-
 
268
        // Si la ruta ya es absoluta, la devolvemos tal como está
-
 
269
        if (strpos($relativePath, $this->fullStoragePath) === 0) {
-
 
270
            return $relativePath;
-
 
271
        }
-
 
272
        
-
 
273
        // Reemplazar la ruta base relativa con la ruta completa
-
 
274
        return str_replace($this->storagePath, $this->fullStoragePath, $relativePath);
-
 
275
    }
-
 
276
 
-
 
277
    /**
-
 
278
     * Convierte una ruta completa a ruta relativa para almacenar en BD
-
 
279
     * @param string $fullPath
-
 
280
     * @return string
-
 
281
     */
235
    }
282
    private function getRelativePathFromFull($fullPath)
Línea 236... Línea 283...
236
 
283
    {
237
    /**
284
        // Si ya es una ruta relativa, la devolvemos tal como está
238
     *
285
        if (strpos($fullPath, $this->fullStoragePath) !== 0) {
Línea 251... Línea 298...
251
    {
298
    {
252
        return $this->storagePath;
299
        return $this->storagePath;
253
    }
300
    }
Línea 254... Línea 301...
254
 
301
 
-
 
302
    /**
-
 
303
     * Obtiene la ruta completa para operaciones de archivo
-
 
304
     * @return string
-
 
305
     */
-
 
306
    public function getFullStoragePath()
-
 
307
    {
-
 
308
        return $this->fullStoragePath;
-
 
309
    }
-
 
310
 
255
    /**
311
    /**
256
     *
312
     *
257
     * @return string
313
     * @return string
258
     */
314
     */
259
    public function getTempPath()
315
    public function getTempPath()
Línea 329... Línea 385...
329
     */
385
     */
330
    public function composePathToFilename($type, $code, $filename)
386
    public function composePathToFilename($type, $code, $filename)
331
    {
387
    {
332
        $path = $this->getPathByType($type);
388
        $path = $this->getPathByType($type);
333
        $path = $path . DIRECTORY_SEPARATOR . $code;
389
        $path = $path . DIRECTORY_SEPARATOR . $code;
334
        if (! file_exists($path)) {
390
        if (!file_exists($path)) {
335
            mkdir($path, 0775, true);
391
            mkdir($path, 0775, true);
336
        }
392
        }
337
        return $path . DIRECTORY_SEPARATOR . $filename;
393
        return $path . DIRECTORY_SEPARATOR . $filename;
338
    }
394
    }
Línea 464... Línea 520...
464
     * @param string $filename
520
     * @param string $filename
465
     * @return string
521
     * @return string
466
     */
522
     */
467
    public function getGroupImageForCodeAndFilename($code, $filename)
523
    public function getGroupImageForCodeAndFilename($code, $filename)
468
    {
524
    {
469
        return $this->_getProcessedImageOrCoverUrl(self::TYPE_COMPANY, $code, $filename, 'getFullPathImageGroupDefault');
525
        return $this->_getProcessedImageOrCoverUrl(self::TYPE_GROUP, $code, $filename, 'getFullPathImageGroupDefault');
470
    }
526
    }
Línea -... Línea 527...
-
 
527
 
471
 
528
 
472
    /**
529
    /**
473
     *
530
     *
474
     * @param Group $group
531
     * @param Group $group
475
     * @return string
532
     * @return string
476
     */
533
     */
477
    public function getGroupCover($group)
534
    public function getGroupCover($group)
478
    {
535
    {
-
 
536
        return $this->_getProcessedImageOrCoverUrl(self::TYPE_GROUP, $group->uuid, $group->cover, 'getFullPathImageGroupCoverDefault');
-
 
537
    }
-
 
538
 
-
 
539
    public function getGroupCoverForCodeAndFilename($code, $filename)
-
 
540
    {
479
        return $this->_getProcessedImageOrCoverUrl(self::TYPE_COMPANY, $group->uuid, $group->cover, 'getFullPathImageGroupCoverDefault');
541
        return $this->_getProcessedImageOrCoverUrl(self::TYPE_COMPANY, $code, $filename, 'getFullPathCoverGroupDefault');
Línea 480... Línea 542...
480
    }
542
    }
481
 
543
 
482
    /**
544
    /**
Línea 490... Línea 552...
490
 
552
 
491
        if (file_exists($remoto)) {
553
        if (file_exists($remoto)) {
492
            return $this->getPresignedUrl($remoto);
554
            return $this->getPresignedUrl($remoto);
Línea -... Línea 555...
-
 
555
        }
-
 
556
 
-
 
557
        $remoto = $path . DIRECTORY_SEPARATOR . $filename;
-
 
558
 
-
 
559
        if (file_exists($remoto)) {
-
 
560
            return $this->getPresignedUrl($remoto);
493
        }
561
        }
494
 
562
 
495
        $remoto = $this->getFullPathImageDefault();
563
        $remoto = $this->getFullPathImageDefault();
Línea 496... Línea 564...
496
        return $this->getPresignedUrl($remoto);
564
        return $this->getPresignedUrl($remoto);
Línea 505... Línea 573...
505
     */
573
     */
506
    public function getGenericFile($path, $code, $filename)
574
    public function getGenericFile($path, $code, $filename)
507
    {
575
    {
508
        $remoto = $path . DIRECTORY_SEPARATOR . $code . DIRECTORY_SEPARATOR . $filename;
576
        $remoto = $path . DIRECTORY_SEPARATOR . $code . DIRECTORY_SEPARATOR . $filename;
Línea 509... Línea -...
509
 
-
 
510
 
-
 
511
 
577
 
512
        if (file_exists($remoto)) {
578
        if (file_exists($remoto)) {
Línea 513... Línea 579...
513
            if ($code == 'd8e6c5de-52a6-4c28-bdce-4ba2823ba841') {
579
            if ($code == 'd8e6c5de-52a6-4c28-bdce-4ba2823ba841') {
514
 
580
 
Línea 515... Línea 581...
515
                error_log('getGenericFile = ' . $remoto);
581
                error_log('getGenericFile = ' . $remoto);
516
            }
582
            }
-
 
583
 
-
 
584
 
-
 
585
            return $this->getPresignedUrl($remoto);
-
 
586
        }
-
 
587
 
517
 
588
        $remoto = $path . DIRECTORY_SEPARATOR . $filename;
-
 
589
 
-
 
590
        if (file_exists($remoto)) {
-
 
591
            return $this->getPresignedUrl($remoto);
518
 
592
        }
Línea 519... Línea 593...
519
            return $this->getPresignedUrl($remoto);
593
 
520
        }
594
        $remoto = $this->getFullPathImageDefault();
521
        return;
595
        return $this->getPresignedUrl($remoto);
Línea 667... Línea 741...
667
 
741
 
668
    public function getPathByType($type)
742
    public function getPathByType($type)
669
    {
743
    {
670
        switch ($type) {
744
        switch ($type) {
671
            case self::TYPE_DEFAULT:
745
            case self::TYPE_DEFAULT:
672
                $path = $this->storagePath . DIRECTORY_SEPARATOR . 'default';
746
                $path = $this->fullStoragePath . DIRECTORY_SEPARATOR . 'default';
Línea 673... Línea 747...
673
                break;
747
                break;
674
 
748
 
675
            case self::TYPE_CHAT:
749
            case self::TYPE_CHAT:
Línea 676... Línea 750...
676
                $path = $this->storagePath . DIRECTORY_SEPARATOR . 'chat';
750
                $path = $this->fullStoragePath . DIRECTORY_SEPARATOR . 'chat';
677
                break;
751
                break;
678
 
752
 
Línea 679... Línea 753...
679
            case self::TYPE_GROUP:
753
            case self::TYPE_GROUP:
680
                $path = $this->storagePath . DIRECTORY_SEPARATOR . 'group';
754
                $path = $this->fullStoragePath . DIRECTORY_SEPARATOR . 'group';
681
                break;
755
                break;
Línea 682... Línea 756...
682
 
756
 
683
            case self::TYPE_USER:
757
            case self::TYPE_USER:
684
                $path = $this->storagePath . DIRECTORY_SEPARATOR . 'user';
758
                $path = $this->fullStoragePath . DIRECTORY_SEPARATOR . 'user';
Línea 685... Línea 759...
685
                break;
759
                break;
686
 
760
 
687
            case self::TYPE_IMAGE:
761
            case self::TYPE_IMAGE:
Línea 688... Línea 762...
688
                $path = $this->storagePath . DIRECTORY_SEPARATOR . 'image';
762
                $path = $this->fullStoragePath . DIRECTORY_SEPARATOR . 'image';
689
                break;
763
                break;
690
 
764
 
Línea 691... Línea 765...
691
            case self::TYPE_JOB:
765
            case self::TYPE_JOB:
692
                $path = $this->storagePath . DIRECTORY_SEPARATOR . 'job';
766
                $path = $this->fullStoragePath . DIRECTORY_SEPARATOR . 'job';
693
                break;
767
                break;
Línea 694... Línea 768...
694
 
768
 
695
            case self::TYPE_COMPANY:
769
            case self::TYPE_COMPANY:
696
                $path = $this->storagePath . DIRECTORY_SEPARATOR . 'company';
770
                $path = $this->fullStoragePath . DIRECTORY_SEPARATOR . 'company';
Línea 697... Línea 771...
697
                break;
771
                break;
698
 
772
 
699
            case self::TYPE_FEED:
773
            case self::TYPE_FEED:
Línea 700... Línea 774...
700
                $path = $this->storagePath . DIRECTORY_SEPARATOR . 'feed';
774
                $path = $this->fullStoragePath . DIRECTORY_SEPARATOR . 'feed';
701
                break;
775
                break;
702
 
776
 
Línea 703... Línea 777...
703
            case self::TYPE_MEDIA:
777
            case self::TYPE_MEDIA:
704
                $path = $this->storagePath . DIRECTORY_SEPARATOR . 'media';
778
                $path = $this->fullStoragePath . DIRECTORY_SEPARATOR . 'media';
705
                break;
779
                break;
Línea 706... Línea 780...
706
 
780
 
707
            case self::TYPE_POST:
781
            case self::TYPE_POST:
708
                $path = $this->storagePath . DIRECTORY_SEPARATOR . 'post';
782
                $path = $this->fullStoragePath . DIRECTORY_SEPARATOR . 'post';
Línea 709... Línea 783...
709
                break;
783
                break;
710
 
784
 
711
            case self::TYPE_MICROLEARNING_TOPIC:
785
            case self::TYPE_MICROLEARNING_TOPIC:
Línea 712... Línea 786...
712
                $path = $this->storagePath . DIRECTORY_SEPARATOR . 'microlearning' . DIRECTORY_SEPARATOR . 'topic';
786
                $path = $this->fullStoragePath . DIRECTORY_SEPARATOR . 'microlearning' . DIRECTORY_SEPARATOR . 'topic';
713
                break;
787
                break;
714
 
788
 
Línea 715... Línea 789...
715
            case self::TYPE_MICROLEARNING_CAPSULE:
789
            case self::TYPE_MICROLEARNING_CAPSULE:
716
                $path = $this->storagePath . DIRECTORY_SEPARATOR . 'microlearning' . DIRECTORY_SEPARATOR . 'capsule';
790
                $path = $this->fullStoragePath . DIRECTORY_SEPARATOR . 'microlearning' . DIRECTORY_SEPARATOR . 'capsule';
717
                break;
791
                break;
Línea 718... Línea 792...
718
 
792
 
719
            case self::TYPE_MICROLEARNING_SLIDE:
793
            case self::TYPE_MICROLEARNING_SLIDE:
720
                $path = $this->storagePath . DIRECTORY_SEPARATOR . 'microlearning' . DIRECTORY_SEPARATOR . 'slide';
794
                $path = $this->fullStoragePath . DIRECTORY_SEPARATOR . 'microlearning' . DIRECTORY_SEPARATOR . 'slide';
Línea 721... Línea 795...
721
                break;
795
                break;
722
 
796
 
723
            case self::TYPE_JOB_DESCRIPTION:
797
            case self::TYPE_JOB_DESCRIPTION:
Línea 724... Línea 798...
724
                $path = $this->storagePath . DIRECTORY_SEPARATOR . 'job-description';
798
                $path = $this->fullStoragePath . DIRECTORY_SEPARATOR . 'job-description';
725
                break;
799
                break;
726
 
800
 
Línea 727... Línea 801...
727
            case self::TYPE_SELF_EVALUATION:
801
            case self::TYPE_SELF_EVALUATION:
728
                $path = $this->storagePath . DIRECTORY_SEPARATOR . 'self-evaluation';
802
                $path = $this->fullStoragePath . DIRECTORY_SEPARATOR . 'self-evaluation';
729
                break;
803
                break;
Línea 730... Línea 804...
730
 
804
 
731
            case self::TYPE_PERFORMANCE_EVALUATION:
805
            case self::TYPE_PERFORMANCE_EVALUATION:
732
                $path = $this->storagePath . DIRECTORY_SEPARATOR . 'performance-evaluation';
806
                $path = $this->fullStoragePath . DIRECTORY_SEPARATOR . 'performance-evaluation';
Línea 733... Línea 807...
733
                break;
807
                break;
734
 
808
 
735
            case self::TYPE_RECRUITMENT_SELECTION:
809
            case self::TYPE_RECRUITMENT_SELECTION:
Línea 736... Línea 810...
736
                $path = $this->storagePath . DIRECTORY_SEPARATOR . 'recruitment-selection';
810
                $path = $this->fullStoragePath . DIRECTORY_SEPARATOR . 'recruitment-selection';
737
                break;
811
                break;
738
 
812
 
Línea 739... Línea 813...
739
            case self::TYPE_PLANNING_OBJECTIVES_AND_GOALS:
813
            case self::TYPE_PLANNING_OBJECTIVES_AND_GOALS:
740
                $path = $this->storagePath . DIRECTORY_SEPARATOR . 'planning-objectives-and-goals';
814
                $path = $this->fullStoragePath . DIRECTORY_SEPARATOR . 'planning-objectives-and-goals';
741
                break;
815
                break;
Línea 742... Línea 816...
742
 
816
 
743
            case self::TYPE_MESSAGE:
817
            case self::TYPE_MESSAGE:
744
                $path = $this->storagePath . DIRECTORY_SEPARATOR . 'message';
818
                $path = $this->fullStoragePath . DIRECTORY_SEPARATOR . 'message';
Línea 745... Línea 819...
745
                break;
819
                break;
746
 
820
 
747
            case self::TYPE_SURVEY:
821
            case self::TYPE_SURVEY:
Línea 748... Línea 822...
748
                $path = $this->storagePath . DIRECTORY_SEPARATOR . 'survey';
822
                $path = $this->fullStoragePath . DIRECTORY_SEPARATOR . 'survey';
749
                break;
823
                break;
750
 
824
 
Línea 751... Línea 825...
751
            case self::TYPE_NETWORK:
825
            case self::TYPE_NETWORK:
752
                $path = $this->storagePath . DIRECTORY_SEPARATOR . 'network';
826
                $path = $this->fullStoragePath . DIRECTORY_SEPARATOR . 'network';
753
                break;
827
                break;
754
 
828
 
Línea 755... Línea 829...
755
            case self::TYPE_DAILY_PULSE:
829
            case self::TYPE_DAILY_PULSE:
756
                $path = $this->storagePath . DIRECTORY_SEPARATOR . 'daily-pulse';
830
                $path = $this->fullStoragePath . DIRECTORY_SEPARATOR . 'daily-pulse';
Línea 889... Línea 963...
889
     * @param string $url
963
     * @param string $url
890
     * @return string
964
     * @return string
891
     */
965
     */
892
    public function getPresignedUrl($url)
966
    public function getPresignedUrl($url)
893
    {
967
    {
-
 
968
        // Convertir la ruta completa a ruta relativa para almacenar en BD
-
 
969
        $relativePath = $this->getRelativePathFromFull($url);
894
        $code = hash('sha256', $url);
970
        $code = hash('sha256', $url);
Línea 895... Línea 971...
895
 
971
 
896
        $storageFileMapper = \LeadersLinked\Mapper\StorageFileMapper::getInstance($this->adapter);
972
        $storageFileMapper = \LeadersLinked\Mapper\StorageFileMapper::getInstance($this->adapter);
897
        $storageFile = $storageFileMapper->fetchOneByCode($code);
973
        $storageFile = $storageFileMapper->fetchOneByCode($code);
898
        if (! $storageFile) {
974
        if (! $storageFile) {
899
            $storageFile = new \LeadersLinked\Model\StorageFile();
975
            $storageFile = new \LeadersLinked\Model\StorageFile();
-
 
976
            $storageFile->code = $code;
900
            $storageFile->code = $code;
977
            // Guardar la ruta relativa en la base de datos
901
            $storageFile->path = $url;
978
            $storageFile->path = $relativePath;
Línea 902... Línea -...
902
            $storageFile->salt = \LeadersLinked\Library\Functions::generatePassword(8);
-
 
903
 
-
 
904
 
979
            $storageFile->salt = \LeadersLinked\Library\Functions::generatePassword(8);
905
 
980
 
Línea 906... Línea -...
906
            $storageFileMapper->insert($storageFile);
-
 
907
        }
981
            $storageFileMapper->insert($storageFile);
Línea 908... Línea 982...
908
 
982
        }
909
 
983
 
Línea 910... Línea 984...
910
        $url = 'https://' . $_SERVER['SERVER_NAME'] . '/storage/' . $code;
984
        $url = 'https://' . $_SERVER['SERVER_NAME'] . '/storage/' . $code;
-
 
985
 
-
 
986
        return $url;
-
 
987
    }
-
 
988
 
-
 
989
    /**
-
 
990
     * Obtiene la ruta completa del archivo basado en el código almacenado
-
 
991
     * @param string $code
-
 
992
     * @return string|null
-
 
993
     */
-
 
994
    public function getFilePathByCode($code)
-
 
995
    {
-
 
996
        $storageFileMapper = \LeadersLinked\Mapper\StorageFileMapper::getInstance($this->adapter);
-
 
997
        $storageFile = $storageFileMapper->fetchOneByCode($code);
-
 
998
        
-
 
999
        if ($storageFile && $storageFile->path) {
-
 
1000
            // Convertir la ruta relativa almacenada en BD a ruta completa
-
 
1001
            return $this->getFullPathFromRelative($storageFile->path);
-
 
1002
        }
-
 
1003
        
-
 
1004
        return null;
-
 
1005
    }
-
 
1006
 
-
 
1007
    /**
-
 
1008
     * Verifica si un archivo existe usando el código almacenado
-
 
1009
     * @param string $code
-
 
1010
     * @return bool
-
 
1011
     */
-
 
1012
    public function fileExistsByCode($code)
-
 
1013
    {
911
 
1014
        $filePath = $this->getFilePathByCode($code);
912
        return $url;
1015
        return $filePath && file_exists($filePath);
913
    }
1016
    }
914
 
1017
 
915
    /**
1018
    /**
Línea 1038... Línea 1141...
1038
            return false;
1141
            return false;
1039
        }
1142
        }
1040
    }
1143
    }
Línea 1041... Línea 1144...
1041
 
1144
 
-
 
1145
    /**
-
 
1146
     * Redimensiona una imagen manteniendo su proporción original.
-
 
1147
     * La imagen resultante tendrá las dimensiones que mejor se ajusten 
1042
    /**
1148
     * dentro de los límites especificados sin recortar contenido.
1043
     *
1149
     *
1044
     * @param string $source
1150
     * @param string $source_filename Ruta del archivo de imagen fuente
1045
     * @param string $target_filename
1151
     * @param string $target_filename Ruta donde guardar la imagen redimensionada
1046
     * @param int $target_width
1152
     * @param int $target_width Ancho máximo deseado
1047
     * @param int $target_height
1153
     * @param int $target_height Alto máximo deseado
1048
     * @return boolean
1154
     * @return boolean True si se redimensionó correctamente, false en caso de error
1049
     */
1155
     */
1050
    public function uploadImageResize($source_filename, $target_filename, $target_width, $target_height)
1156
    public function uploadImageResize($source_filename, $target_filename, $target_width, $target_height)
1051
    {
1157
    {
1052
        try {
1158
        try {
Línea 1068... Línea 1174...
1068
                }
1174
                }
Línea 1069... Línea 1175...
1069
 
1175
 
1070
                $resized_width = round($resized_width);
1176
                $resized_width = round($resized_width);
Línea 1071... Línea 1177...
1071
                $resized_height = round($resized_height);
1177
                $resized_height = round($resized_height);
1072
 
1178
 
1073
                $new_image = $this->_createImageCanvas($target_width, $target_height);
1179
                $new_image = $this->_createImageCanvas($resized_width, $resized_height);
1074
                if ($new_image === false) {
1180
                if ($new_image === false) {
1075
                    imagedestroy($img);
1181
                    imagedestroy($img);
1076
                    unlink($source_filename);
1182
                    unlink($source_filename);
Línea 1195... Línea 1301...
1195
 
1301
 
1196
            unlink($source_filename);
1302
            unlink($source_filename);
1197
            return false;
1303
            return false;
1198
        } catch (\Throwable $e) {
1304
        } catch (\Throwable $e) {
-
 
1305
            error_log($e->getTraceAsString());
1199
            error_log($e->getTraceAsString());
1306
            error_log('Error al subir la imagen: ' . $e->getMessage());
1200
            if (isset($img) && ($img instanceof \GdImage || is_resource($img))) {
1307
            if (isset($img) && ($img instanceof \GdImage || is_resource($img))) {
1201
                imagedestroy($img);
1308
                imagedestroy($img);
1202
            }
1309
            }
1203
            if (isset($new_image) && ($new_image instanceof \GdImage || is_resource($new_image))) {
1310
            if (isset($new_image) && ($new_image instanceof \GdImage || is_resource($new_image))) {