Proyectos de Subversion LeadersLinked - Backend

Rev

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

Rev 17108 Rev 17109
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 -... Línea 461...
-
 
461
        $id   = $this->params()->fromRoute('id');
-
 
462
        
461
        $id   = $this->params()->fromRoute('id');
463
 
462
        
464
        
463
        $topicMapper = MicrolearningTopicMapper::getInstance($this->adapter);
465
        $topicMapper = MicrolearningTopicMapper::getInstance($this->adapter);
464
        $topic = $topicMapper->fetchOneByUuid($id);
466
        $topic = $topicMapper->fetchOneByUuid($id);
465
        if(!$topic) {
467
        if(!$topic) {
Línea 475... Línea 477...
475
                'data'   => 'ERROR_UNAUTHORIZED'
477
                'data'   => 'ERROR_UNAUTHORIZED'
476
            ]);
478
            ]);
477
        }
479
        }
Línea 478... Línea 480...
478
        
480
        
-
 
481
        if($request->isGet()) {
479
        if($request->isGet()) {
482
            
480
            $storage = Storage::getInstance($this->config, $this->adapter);
483
            $storage = Storage::getInstance($this->config, $this->adapter);
Línea 481... Línea -...
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
                }
-
 
493
            }
484
            $path = $storage->getPathMicrolearningTopic();
494
            
485
            
495
            $data = [
486
            $data = [
496
                'success' => true,
487
                'success' => true,
497
                'data' => [
488
                'data' => [
498
                    'name' => $topic->name,
489
                    'name' => $topic->name,
499
                    'description' => $topic->description,
490
                    'description' => $topic->description,
500
                    'order' => $topic->order,
491
                    'order' => $topic->order,
501
                    'status' => $topic->status,
-
 
502
                    'image'=> $storage->getGenericImage($path, $topic->uuid, $topic->image),
492
                    'status' => $topic->status,
503
                    'capsule_uuid' => $capsuleUuids
493
                    'image'=> $storage->getGenericImage($path, $topic->uuid, $topic->image)
Línea 504... Línea 494...
504
                ]
494
                ]
505
            ];
495
            ];
Línea 520... Línea 510...
520
                $topic->image = null;
510
                $topic->image = null;
Línea 521... Línea 511...
521
          
511
          
522
                if($topicMapper->update($topic)) {
512
                if($topicMapper->update($topic)) {
Línea 523... Línea -...
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
                        }
-
 
545
                    }
513
                    $topic = $topicMapper->fetchOne($topic->id);
546
                    
514
                    
Línea -... Línea 515...
-
 
515
                    $image = Image::getInstance($this->config);
547
                    $image = Image::getInstance($this->config);
516
                    $target_path = $image->getStorage()->getPathMicrolearningTopic();
548
                    $target_path = $image->getStorage()->getPathMicrolearningTopic();
517
                    
549
                    
518
                    
-
 
519
                    $files = $this->getRequest()->getFiles()->toArray();
Línea 550... Línea 520...
550
                    $files = $this->getRequest()->getFiles()->toArray();
520
                    if(isset($files['file']) && empty($files['file']['error'])) {
551
                    if(isset($files['file']) && empty($files['file']['error'])) {
521
                        $tmp_filename  = $files['file']['tmp_name'];
-
 
522
                        //$filename      = \LeadersLinked\Library\Functions::normalizeStringFilename($files['file']['name']);
552
                        $tmp_filename  = $files['file']['tmp_name'];
523
                        
553
                        
524
                        try {
554
                        try {
525
                            if($topic->image) {
555
                            if($topic->image) {
526
                                
556
                                if(!$image->getStorage()->deleteFile($target_path, $topic->uuid, $topic->image)) {
527
                                if(!$image->getStorage()->deleteFile($target_path, $topic->uuid, $topic->image)) {
Línea 574... Línea 545...
574
                        } catch(\Throwable $e) {
545
                        } catch(\Throwable $e) {
575
                            error_log($e->getTraceAsString());
546
                            error_log($e->getTraceAsString());
576
                        }
547
                        }
577
                    }
548
                    }
Línea -... Línea 549...
-
 
549
                    
-
 
550
                    
-
 
551
                  
578
                    
552
                    
Línea 579... Línea 553...
579
                    $this->logger->info('Se edito el tópico ' . $topic->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
553
                    $this->logger->info('Se edito el tópico ' . $topic->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
580
                    
554
                    
581
                    $data = [
555
                    $data = [
Línea 595... Línea 569...
595
            } else {
569
            } else {
596
                $messages = [];
570
                $messages = [];
597
                $form_messages = (array) $form->getMessages();
571
                $form_messages = (array) $form->getMessages();
598
                foreach($form_messages  as $fieldname => $field_messages)
572
                foreach($form_messages  as $fieldname => $field_messages)
599
                {
573
                {
-
 
574
                    
600
                    $messages[$fieldname] = array_values($field_messages);
575
                    $messages[$fieldname] = array_values($field_messages);
601
                }
576
                }
Línea 602... Línea 577...
602
                
577
                
603
                return new JsonModel([
578
                return new JsonModel([
Línea 611... Línea 586...
611
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
586
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
612
            ];
587
            ];
Línea 613... Línea 588...
613
            
588
            
614
            return new JsonModel($data);
589
            return new JsonModel($data);
-
 
590
        }
-
 
591
        
615
        }
592
        return new JsonModel($data);
616
    }
593
    }