Proyectos de Subversion LeadersLinked - Services

Rev

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

Rev 560 Rev 561
Línea 227... Línea 227...
227
                    if (strlen($description) > 120) {
227
                    if (strlen($description) > 120) {
228
                        $description = substr($description, 0, 120) . '...';
228
                        $description = substr($description, 0, 120) . '...';
229
                    }
229
                    }
Línea 230... Línea 230...
230
 
230
 
231
                    $item = [
231
                    $item = [
232
                        'image' => $storage->getGenericImage($path, $record->uuid,   $record->image),
232
                        'image' => $storage->getGenericImage($path, ($categories[$record->category_id]['uuid'] ?? null), $record->image),
233
                        'title' => $record->title,
233
                        'title' => $record->title,
234
                        'description' => $description,
234
                        'description' => $description,
235
                        'category' => $categories[$record->category_id]['name'],
235
                        'category' => $categories[$record->category_id]['name'],
Línea 347... Línea 347...
347
 
347
 
348
                $knowledgeAreaContentMapper = KnowledgeAreaContentMapper::getInstance($this->adapter);
348
                $knowledgeAreaContentMapper = KnowledgeAreaContentMapper::getInstance($this->adapter);
349
                if ($knowledgeAreaContentMapper->insert($knowledgeAreaContent)) {
349
                if ($knowledgeAreaContentMapper->insert($knowledgeAreaContent)) {
Línea -... Línea 350...
-
 
350
                    $knowledgeAreaContent = $knowledgeAreaContentMapper->fetchOne($knowledgeAreaContent->id);
-
 
351
 
350
                    $knowledgeAreaContent = $knowledgeAreaContentMapper->fetchOne($knowledgeAreaContent->id);
352
                    // Se instancia la clase Storage para manejar el almacenamiento de archivos.
351
 
353
                    // La clase Image fue eliminada debido a que no se encontraba o estaba obsoleta.
-
 
354
                    $storage = Storage::getInstance($this->config, $this->adapter);
Línea 352... Línea 355...
352
                    $storage = Storage::getInstance($this->config, $this->adapter);
355
                    // Obtiene la ruta base para los archivos del área de conocimiento.
Línea -... Línea 356...
-
 
356
                    // $target_path = $storage->getPathKnowledgeArea(); // No longer needed directly here, composePathTo methods use storagePath internally
353
                    $target_path = $storage->getPathKnowledgeArea();
357
 
354
 
358
                    $files = $this->getRequest()->getFiles()->toArray();
355
                    $files = $this->getRequest()->getFiles()->toArray();
359
 
-
 
360
                    // Manejo del archivo de imagen principal.
356
 
361
                    if (isset($files['image']) && empty($files['image']['error'])) {
Línea -... Línea 362...
-
 
362
                        $tmp_image_name  = $files['image']['tmp_name'];
-
 
363
                        $original_image_name_parts = explode('.',  $files['image']['name']);
-
 
364
                        // Genera un nombre de archivo único y normalizado, forzando la extensión .png.
-
 
365
                        $final_image_filename = Functions::normalizeString(uniqid() . '-' . $original_image_name_parts[0] . '.png');
-
 
366
                        
357
                    if (isset($files['image']) && empty($files['image']['error'])) {
367
                        // Obtener dimensiones para el redimensionamiento de la imagen del área de conocimiento.
-
 
368
                        list($target_width_str, $target_height_str) = explode('x', $this->config['leaderslinked.image_sizes.knowledge_area']);
-
 
369
                        $target_width = (int)$target_width_str;
358
                        $tmp_image_name  = $files['image']['tmp_name'];
370
                        $target_height = (int)$target_height_str;
-
 
371
 
359
                        $original_image_name_parts = explode('.',  $files['image']['name']);
372
                        $uuid_path_segment = $knowledgeAreaCategory->uuid;
360
                        $final_image_filename = Functions::normalizeString(uniqid() . '-' . $original_image_name_parts[0] . '.png');
373
                        
361
                        
374
                        // Construye la ruta completa del directorio de destino usando el UUID de la categoría.
-
 
375
                        $full_target_dir = $storage->composePathToDirectory(Storage::TYPE_KNOWLEDGE_AREA, $uuid_path_segment);
362
                        $uuid_path_segment = $knowledgeAreaCategory->uuid;
376
                        // Crea el directorio si no existe.
Línea -... Línea 377...
-
 
377
                        if (!is_dir($full_target_dir)) {
363
                        $full_target_dir_for_image = $target_path . DIRECTORY_SEPARATOR . $uuid_path_segment;
378
                            mkdir($full_target_dir, 0775, true);
364
                        if (!is_dir($full_target_dir_for_image)) {
379
                        }
365
                            mkdir($full_target_dir_for_image, 0775, true);
380
                        // Construye la ruta completa del archivo de destino.
366
                        }
381
                        $full_target_path_for_image = $storage->composePathToFilename(Storage::TYPE_KNOWLEDGE_AREA, $uuid_path_segment, $final_image_filename);
367
                        $full_target_path_for_image = $full_target_dir_for_image . DIRECTORY_SEPARATOR . $final_image_filename;
382
                        
Línea -... Línea 383...
-
 
383
                        // Sube y redimensiona la imagen usando el método de la clase Storage.
368
                        
384
                        if ($storage->uploadImageResize($tmp_image_name, $full_target_path_for_image, $target_width, $target_height)) {
369
                        if ($storage->uploadImageWithOutChangeSize($tmp_image_name, $full_target_path_for_image)) {
385
                            $knowledgeAreaContent->image = $final_image_filename; // Guarda solo el nombre del archivo.
-
 
386
                            $knowledgeAreaContentMapper->update($knowledgeAreaContent);
370
                            $knowledgeAreaContent->image = $final_image_filename;
387
                        }
Línea 371... Línea 388...
371
                            $knowledgeAreaContentMapper->update($knowledgeAreaContent);
388
                    }
-
 
389
 
-
 
390
                    // Manejo del archivo adjunto.
372
                        }
391
                    if (isset($files['attachment']) && empty($files['attachment']['error'])) {
373
                    }
392
                        $tmp_attachment_name   = $files['attachment']['tmp_name'];
374
 
393
                        // Normaliza el nombre del archivo adjunto, manteniendo su extensión original.
375
                    if (isset($files['attachment']) && empty($files['attachment']['error'])) {
394
                        $final_attachment_filename = Functions::normalizeString($files['attachment']['name']);
376
                        $tmp_attachment_name   = $files['attachment']['tmp_name'];
395
                        
Línea -... Línea 396...
-
 
396
                        $uuid_path_segment = $knowledgeAreaCategory->uuid;
377
                        $final_attachment_filename = Functions::normalizeString($files['attachment']['name']);
397
                        // Necesitamos la ruta base para los adjuntos si composePathToDirectory no se usa aquí directamente
378
                        
398
                        $base_attachment_path = $storage->getPathKnowledgeArea(); 
379
                        $uuid_path_segment = $knowledgeAreaCategory->uuid;
399
                        $full_target_dir_for_attachment = $base_attachment_path . DIRECTORY_SEPARATOR . $uuid_path_segment;
380
                        $full_target_dir_for_attachment = $target_path . DIRECTORY_SEPARATOR . $uuid_path_segment;
400
                        if (!is_dir($full_target_dir_for_attachment)) {
381
                        if (!is_dir($full_target_dir_for_attachment)) {
401
                            mkdir($full_target_dir_for_attachment, 0775, true);
Línea 382... Línea -...
382
                            mkdir($full_target_dir_for_attachment, 0775, true);
-
 
383
                        }
402
                        }
Línea 384... Línea 403...
384
                        $full_target_path_for_attachment = $full_target_dir_for_attachment . DIRECTORY_SEPARATOR . $final_attachment_filename;
403
                        $full_target_path_for_attachment = $full_target_dir_for_attachment . DIRECTORY_SEPARATOR . $final_attachment_filename;
385
 
404
 
386
                        if ($storage->moveUploadedFile($tmp_attachment_name, $full_target_path_for_attachment)) {
405
                        // Mueve el archivo adjunto subido a su ubicación final.
Línea 640... Línea 659...
640
                $knowledgeAreaContent->description = $dataPost['description'];
659
                $knowledgeAreaContent->description = $dataPost['description'];
Línea 641... Línea 660...
641
 
660
 
Línea -... Línea 661...
-
 
661
 
642
 
662
                if ($knowledgeAreaContentMapper->update($knowledgeAreaContent)) {
643
                if ($knowledgeAreaContentMapper->update($knowledgeAreaContent)) {
663
 
-
 
664
                    // Se instancia la clase Storage para manejar el almacenamiento de archivos.
Línea 644... Línea 665...
644
 
665
                    $storage = Storage::getInstance($this->config, $this->adapter);
Línea 645... Línea -...
645
                    $storage = Storage::getInstance($this->config, $this->adapter);
-
 
-
 
666
                    // Obtiene la ruta base para los archivos del área de conocimiento.
646
                    $target_path = $storage->getPathKnowledgeArea();
667
                    // $target_path = $storage->getPathKnowledgeArea(); // No longer needed directly here, composePathTo methods use storagePath internally
647
 
-
 
Línea -... Línea 668...
-
 
668
 
648
                    $files = $this->getRequest()->getFiles()->toArray();
669
                    $files = $this->getRequest()->getFiles()->toArray();
649
 
670
 
650
 
671
                    // Manejo de la actualización de la imagen principal.
Línea 651... Línea -...
651
                    if (isset($files['image']) && empty($files['image']['error'])) {
-
 
652
 
672
                    if (isset($files['image']) && empty($files['image']['error'])) {
653
                        
673
                        
-
 
674
                        // Si existe una imagen previa, se elimina.
654
                        if ($knowledgeAreaContent->image) {
675
                        if ($knowledgeAreaContent->image) {
Línea -... Línea 676...
-
 
676
                            $storage->deleteFile($target_path, $knowledgeAreaContent->uuid, $knowledgeAreaContent->image);
-
 
677
                        }
-
 
678
 
-
 
679
                        $tmp_image_name  = $files['image']['tmp_name'];
655
                            $storage->deleteFile($target_path, $knowledgeAreaContent->uuid, $knowledgeAreaContent->image);
680
                        $original_image_name_parts = explode('.',  $files['image']['name']);
656
                        }
681
                        // Genera un nombre de archivo único y normalizado para la nueva imagen, forzando .png.
-
 
682
                        $final_image_filename = Functions::normalizeString(uniqid() . '-' . $original_image_name_parts[0] . '.png');
-
 
683
             
657
 
684
                        // Obtener dimensiones para el redimensionamiento de la imagen del área de conocimiento.
-
 
685
                        list($target_width_str, $target_height_str) = explode('x', $this->config['leaderslinked.image_sizes.knowledge_area']);
658
 
686
                        $target_width = (int)$target_width_str;
659
                        $tmp_image_name  = $files['image']['tmp_name'];
687
                        $target_height = (int)$target_height_str;
660
                        $original_image_name_parts = explode('.',  $files['image']['name']);
688
 
661
                        $final_image_filename = Functions::normalizeString(uniqid() . '-' . $original_image_name_parts[0] . '.png');
689
                        $uuid_path_segment = $knowledgeAreaCategory->uuid;
Línea -... Línea 690...
-
 
690
                        
662
             
691
                        // Construye la ruta completa del directorio de destino.
663
                        
692
                        $full_target_dir = $storage->composePathToDirectory(Storage::TYPE_KNOWLEDGE_AREA, $uuid_path_segment);
664
                        $uuid_path_segment = $knowledgeAreaCategory->uuid;
693
                        // Crea el directorio si no existe.
665
                        $full_target_dir_for_image = $target_path . DIRECTORY_SEPARATOR . $uuid_path_segment;
694
                        if (!is_dir($full_target_dir)) {
Línea 666... Línea 695...
666
                        if (!is_dir($full_target_dir_for_image)) {
695
                            mkdir($full_target_dir, 0775, true);
Línea -... Línea 696...
-
 
696
                        }
667
                            mkdir($full_target_dir_for_image, 0775, true);
697
                        $full_target_path_for_image = $storage->composePathToFilename(Storage::TYPE_KNOWLEDGE_AREA, $uuid_path_segment, $final_image_filename);
668
                        }
698
                        
-
 
699
                        // Sube y redimensiona la imagen.
669
                        $full_target_path_for_image = $full_target_dir_for_image . DIRECTORY_SEPARATOR . $final_image_filename;
700
                        if ($storage->uploadImageResize($tmp_image_name, $full_target_path_for_image, $target_width, $target_height)) {
Línea -... Línea 701...
-
 
701
                            $knowledgeAreaContent->image = $final_image_filename;
670
                        
702
                            $knowledgeAreaContentMapper->update($knowledgeAreaContent);
671
                        if ($storage->uploadImageWithOutChangeSize($tmp_image_name, $full_target_path_for_image)) {
703
                        }
672
                            $knowledgeAreaContent->image = $final_image_filename;
704
          
673
                            $knowledgeAreaContentMapper->update($knowledgeAreaContent);
705
                    }
-
 
706
 
674
                        }
707
                    // Manejo de la actualización del archivo adjunto.
675
          
708
                    if (isset($files['attachment']) && empty($files['attachment']['error'])) {
676
                    }
709
                        $tmp_attachment_name   = $files['attachment']['tmp_name'];
677
 
710
                        // Normaliza el nombre del nuevo archivo adjunto.
678
                    if (isset($files['attachment']) && empty($files['attachment']['error'])) {
711
                        $final_attachment_filename = Functions::normalizeString($files['attachment']['name']);
679
                        $tmp_attachment_name   = $files['attachment']['tmp_name'];
712
             
Línea -... Línea 713...
-
 
713
                        // Si existe un adjunto previo, se elimina.
680
                        $final_attachment_filename = Functions::normalizeString($files['attachment']['name']);
714
                        if ($knowledgeAreaContent->attachment) {
681
             
715
                            $storage->deleteFile($target_path, $knowledgeAreaContent->uuid, $knowledgeAreaContent->attachment);
682
                        if ($knowledgeAreaContent->attachment) {
716
                        }
683
                            $storage->deleteFile($target_path, $knowledgeAreaContent->uuid, $knowledgeAreaContent->attachment);
717
                        
684
                        }
718
                        // Construye la ruta completa del directorio de destino para el adjunto.
Línea 685... Línea -...
685
 
-
 
686
                        $uuid_path_segment = $knowledgeAreaCategory->uuid;
719
                        $uuid_path_segment = $knowledgeAreaCategory->uuid; // Similar al comentario de la imagen.
Línea 687... Línea 720...
687
                        $full_target_dir_for_attachment = $target_path . DIRECTORY_SEPARATOR . $uuid_path_segment;
720
                        $full_target_dir_for_attachment = $target_path . DIRECTORY_SEPARATOR . $uuid_path_segment;
688
                        if (!is_dir($full_target_dir_for_attachment)) {
721
                        if (!is_dir($full_target_dir_for_attachment)) {
689
                            mkdir($full_target_dir_for_attachment, 0775, true);
722
                            mkdir($full_target_dir_for_attachment, 0775, true);