Proyectos de Subversion LeadersLinked - Backend

Rev

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

Rev 17107 Rev 17108
Línea 458... Línea 458...
458
        $currentUser        = $currentUserPlugin->getUser();
458
        $currentUser        = $currentUserPlugin->getUser();
Línea 459... Línea 459...
459
        
459
        
460
        $request    = $this->getRequest();
460
        $request    = $this->getRequest();
Línea 461... Línea -...
461
        $id   = $this->params()->fromRoute('id');
-
 
462
        
-
 
463
 
461
        $id   = $this->params()->fromRoute('id');
464
        
462
        
465
        $topicMapper = MicrolearningTopicMapper::getInstance($this->adapter);
463
        $topicMapper = MicrolearningTopicMapper::getInstance($this->adapter);
466
        $topic = $topicMapper->fetchOneByUuid($id);
464
        $topic = $topicMapper->fetchOneByUuid($id);
467
        if(!$topic) {
465
        if(!$topic) {
Línea 477... Línea 475...
477
                'data'   => 'ERROR_UNAUTHORIZED'
475
                'data'   => 'ERROR_UNAUTHORIZED'
478
            ]);
476
            ]);
479
        }
477
        }
Línea 480... Línea 478...
480
        
478
        
481
        if($request->isGet()) {
-
 
482
            
479
        if($request->isGet()) {
483
            $storage = Storage::getInstance($this->config, $this->adapter);
480
            $storage = Storage::getInstance($this->config, $this->adapter);
Línea -... Línea 481...
-
 
481
            $path = $storage->getPathMicrolearningTopic();
-
 
482
            
-
 
483
            // Get associated capsules
-
 
484
            $topicCapsuleMapper = MicrolearningTopicCapsuleMapper::getInstance($this->adapter);
-
 
485
            $associatedCapsules = $topicCapsuleMapper->fetchAllByTopicId($topic->id);
-
 
486
            $capsuleUuids = [];
-
 
487
            foreach ($associatedCapsules as $associatedCapsule) {
-
 
488
                $capsuleMapper = MicrolearningCapsuleMapper::getInstance($this->adapter);
-
 
489
                $capsule = $capsuleMapper->fetchOne($associatedCapsule->capsule_id);
-
 
490
                if ($capsule) {
-
 
491
                    $capsuleUuids[] = $capsule->uuid;
-
 
492
                }
484
            $path = $storage->getPathMicrolearningTopic();
493
            }
485
            
494
            
486
            $data = [
495
            $data = [
487
                'success' => true,
496
                'success' => true,
488
                'data' => [
497
                'data' => [
489
                    'name' => $topic->name,
498
                    'name' => $topic->name,
490
                    'description' => $topic->description,
499
                    'description' => $topic->description,
491
                    'order' => $topic->order,
500
                    'order' => $topic->order,
-
 
501
                    'status' => $topic->status,
492
                    'status' => $topic->status,
502
                    'image'=> $storage->getGenericImage($path, $topic->uuid, $topic->image),
493
                    'image'=> $storage->getGenericImage($path, $topic->uuid, $topic->image)
503
                    'capsule_uuid' => $capsuleUuids
Línea 494... Línea 504...
494
                ]
504
                ]
495
            ];
505
            ];
Línea 510... Línea 520...
510
                $topic->image = null;
520
                $topic->image = null;
Línea 511... Línea 521...
511
          
521
          
512
                if($topicMapper->update($topic)) {
522
                if($topicMapper->update($topic)) {
Línea -... Línea 523...
-
 
523
                    $topic = $topicMapper->fetchOne($topic->id);
-
 
524
                    
-
 
525
                    // Handle capsule associations
-
 
526
                    if (!empty($dataPost['capsule_uuid'])) {
-
 
527
                        $capsuleUuids = is_array($dataPost['capsule_uuid']) ? $dataPost['capsule_uuid'] : [$dataPost['capsule_uuid']];
-
 
528
                        $capsuleMapper = MicrolearningCapsuleMapper::getInstance($this->adapter);
-
 
529
                        $topicCapsuleMapper = MicrolearningTopicCapsuleMapper::getInstance($this->adapter);
-
 
530
                        
-
 
531
                        // Delete existing associations
-
 
532
                        $topicCapsuleMapper->deleteByTopicId($topic->id);
-
 
533
                        
-
 
534
                        // Create new associations
-
 
535
                        foreach ($capsuleUuids as $capsuleUuid) {
-
 
536
                            $capsule = $capsuleMapper->fetchOneByUuid($capsuleUuid);
-
 
537
                            if ($capsule) {
-
 
538
                                $topicCapsule = new MicrolearningTopicCapsule();
-
 
539
                                $topicCapsule->topic_id = $topic->id;
-
 
540
                                $topicCapsule->capsule_id = $capsule->id;
-
 
541
                                $topicCapsule->company_id = $currentCompany->id;
-
 
542
                                $topicCapsuleMapper->insert($topicCapsule);
-
 
543
                            }
-
 
544
                        }
513
                    $topic = $topicMapper->fetchOne($topic->id);
545
                    }
514
                    
546
                    
Línea 515... Línea -...
515
                    $image = Image::getInstance($this->config);
-
 
516
                    $target_path = $image->getStorage()->getPathMicrolearningTopic();
547
                    $image = Image::getInstance($this->config);
517
                    
548
                    $target_path = $image->getStorage()->getPathMicrolearningTopic();
518
                    
549
                    
519
                    $files = $this->getRequest()->getFiles()->toArray();
-
 
Línea 520... Línea 550...
520
                    if(isset($files['file']) && empty($files['file']['error'])) {
550
                    $files = $this->getRequest()->getFiles()->toArray();
521
                        $tmp_filename  = $files['file']['tmp_name'];
551
                    if(isset($files['file']) && empty($files['file']['error'])) {
522
                        //$filename      = \LeadersLinked\Library\Functions::normalizeStringFilename($files['file']['name']);
-
 
523
                        
552
                        $tmp_filename  = $files['file']['tmp_name'];
524
                        try {
553
                        
525
                            if($topic->image) {
554
                        try {
526
                                
555
                            if($topic->image) {
527
                                if(!$image->getStorage()->deleteFile($target_path, $topic->uuid, $topic->image)) {
556
                                if(!$image->getStorage()->deleteFile($target_path, $topic->uuid, $topic->image)) {
Línea 545... Línea 574...
545
                        } catch(\Throwable $e) {
574
                        } catch(\Throwable $e) {
546
                            error_log($e->getTraceAsString());
575
                            error_log($e->getTraceAsString());
547
                        }
576
                        }
548
                    }
577
                    }
Línea 549... Línea -...
549
                    
-
 
550
                    
-
 
551
                  
-
 
552
                    
578
                    
Línea 553... Línea 579...
553
                    $this->logger->info('Se edito el tópico ' . $topic->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
579
                    $this->logger->info('Se edito el tópico ' . $topic->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
554
                    
580
                    
555
                    $data = [
581
                    $data = [
Línea 569... Línea 595...
569
            } else {
595
            } else {
570
                $messages = [];
596
                $messages = [];
571
                $form_messages = (array) $form->getMessages();
597
                $form_messages = (array) $form->getMessages();
572
                foreach($form_messages  as $fieldname => $field_messages)
598
                foreach($form_messages  as $fieldname => $field_messages)
573
                {
599
                {
574
                    
-
 
575
                    $messages[$fieldname] = array_values($field_messages);
600
                    $messages[$fieldname] = array_values($field_messages);
576
                }
601
                }
Línea 577... Línea 602...
577
                
602
                
578
                return new JsonModel([
603
                return new JsonModel([
Línea 586... Línea 611...
586
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
611
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
587
            ];
612
            ];
Línea 588... Línea 613...
588
            
613
            
589
            return new JsonModel($data);
614
            return new JsonModel($data);
590
        }
-
 
591
        
-
 
592
        return new JsonModel($data);
615
        }
593
    }
616
    }