Proyectos de Subversion LeadersLinked - Backend

Rev

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

Rev 17215 Rev 17216
Línea 4... Línea 4...
4
namespace LeadersLinked\Controller;
4
namespace LeadersLinked\Controller;
Línea 5... Línea 5...
5
 
5
 
6
use Laminas\Mvc\Controller\AbstractActionController;
6
use Laminas\Mvc\Controller\AbstractActionController;
7
use Laminas\View\Model\JsonModel;
7
use Laminas\View\Model\JsonModel;
-
 
8
use Laminas\View\Model\ViewModel;
8
use Laminas\View\Model\ViewModel;
9
use Laminas\Hydrator\ObjectPropertyHydrator;
9
use LeadersLinked\Library\Functions;
10
use LeadersLinked\Library\Functions;
10
use LeadersLinked\Mapper\MicrolearningTopicMapper;
11
use LeadersLinked\Mapper\MicrolearningTopicMapper;
11
use LeadersLinked\Mapper\MicrolearningCapsuleMapper;
12
use LeadersLinked\Mapper\MicrolearningCapsuleMapper;
12
use LeadersLinked\Model\MicrolearningTopic;
13
use LeadersLinked\Model\MicrolearningTopic;
Línea 181... Línea 182...
181
                }
182
                }
Línea 182... Línea 183...
182
 
183
 
Línea 183... Línea 184...
183
                $dataPost = (array) $form->getData();
184
                $dataPost = (array) $form->getData();
184
 
-
 
185
                $topic = new MicrolearningTopic();
-
 
186
                $topic->name = $dataPost['name'];
185
 
187
                $topic->description = $dataPost['description'];
-
 
188
                $topic->order = $dataPost['order'];
-
 
189
                $topic->status = $dataPost['status'];        
186
                $topic = new MicrolearningTopic();
190
                $topic->privacy = $dataPost['privacy'];
-
 
-
 
187
                $hydrator = new ObjectPropertyHydrator();
191
                $topic->type = $dataPost['type'];
188
                $hydrator->hydrate($dataPost, $topic);
192
                $topic->cost = $dataPost['cost'];
189
 
193
                $topic->company_id = $currentCompany->id;
190
                $topic->company_id = $currentCompany->id;
194
                $topic->image = '';
191
                $topic->image = '';
195
                $topic->marketplace = '';
192
                $topic->marketplace = '';
Línea -... Línea 193...
-
 
193
 
196
                
194
                $topicMapper = MicrolearningTopicMapper::getInstance($this->adapter);
197
                $topicMapper = MicrolearningTopicMapper::getInstance($this->adapter);
195
 
198
 
196
                // First insert the topic to get the ID and UUID
Línea -... Línea 197...
-
 
197
                if(!$topicMapper->insert($topic)) {
199
                if(!$topicMapper->insert($topic)) {
198
                    return $this->createErrorResponse($topicMapper->getError());
Línea 200... Línea -...
200
                    return $this->createErrorResponse($topicMapper->getError());
-
 
201
                }
-
 
202
 
-
 
203
                $topic = $topicMapper->fetchOne($topic->id);
-
 
204
                
-
 
205
                // Create capsule relations
-
 
206
                $result = $this->updateTopicCapsuleRelations($topic, $dataPost['capsule_uuid'], $currentCompany->id);
199
                }
207
                if (!$result['success']) {
200
 
208
                    return $this->createErrorResponse($result['error']);
201
                // Get the complete topic with ID and UUID
209
                }
202
                $topic = $topicMapper->fetchOne($topic->id);
210
                
203
                
Línea -... Línea 204...
-
 
204
                // Now process images with the proper UUID
-
 
205
                $imageResult = $this->processTopicImages($request, $topic);
-
 
206
                if (!$imageResult['success']) {
211
                // Process required images for new topic
207
                    return $this->createErrorResponse($imageResult['error']);
-
 
208
                }
-
 
209
 
212
                $imageResult = $this->processTopicImages($request, $topic);
210
                // Update topic with image filenames if processed
-
 
211
                if (!empty($imageResult['image_filename']) || !empty($imageResult['marketplace_filename'])) {
-
 
212
                    if (!empty($imageResult['image_filename'])) {
-
 
213
                        $topic->image = $imageResult['image_filename'];
-
 
214
                    }
-
 
215
                    if (!empty($imageResult['marketplace_filename'])) {
-
 
216
                        $topic->marketplace = $imageResult['marketplace_filename'];
Línea -... Línea 217...
-
 
217
                    }
-
 
218
                    
213
                if (!$imageResult['success']) {
219
                    if(!$topicMapper->update($topic)) {
214
                    return $this->createErrorResponse($imageResult['error']);
220
                        return $this->createErrorResponse($topicMapper->getError());
215
                }
221
                    }
Línea 216... Línea 222...
216
 
222
                }
Línea 217... Línea 223...
217
                $topic->image = $imageResult['image_filename'];
223
 
Línea 438... Línea 444...
438
                }
444
                }
Línea 439... Línea 445...
439
 
445
 
440
                if($topic->company_id != $currentCompany->id) {
446
                if($topic->company_id != $currentCompany->id) {
441
                    return $this->createErrorResponse('ERROR_UNAUTHORIZED');
447
                    return $this->createErrorResponse('ERROR_UNAUTHORIZED');
-
 
448
                }
-
 
449
 
-
 
450
                $hydrator = new ObjectPropertyHydrator();
-
 
451
                // Don't create a new topic, use the existing one
-
 
452
                $hydrator->hydrate($dataPost, $topic);
-
 
453
                
-
 
454
                // Ensure company_id is preserved
Línea 442... Línea -...
442
                }
-
 
443
                
-
 
444
                $topic->name = $dataPost['name'];
-
 
445
                $topic->description = $dataPost['description'];
455
                $topic->company_id = $currentCompany->id;
446
                $topic->order = $dataPost['order'];
-
 
447
                $topic->status = $dataPost['status'];
-
 
448
                $topic->privacy = $dataPost['privacy'];
-
 
449
                $topic->type = $dataPost['type'];
-
 
450
                $topic->cost = $dataPost['cost'];
-
 
451
                $topic->image = $dataPost['image'];
-
 
452
                $topic->marketplace = $dataPost['marketplace'];
456
                
453
          
457
                // Update basic topic data first
454
                if(!$topicMapper->update($topic)) {
458
                if(!$topicMapper->update($topic)) {
455
                    return $this->createErrorResponse($topicMapper->getError());
-
 
456
                }
-
 
457
 
-
 
458
                // Actualizar las relaciones con cápsulas
-
 
459
                $result = $this->updateTopicCapsuleRelations($topic, $dataPost['capsule_uuid'], $currentCompany->id);
-
 
460
                if (!$result['success']) {
-
 
Línea 461... Línea 459...
461
                    return $this->createErrorResponse($result['error']);
459
                    return $this->createErrorResponse($topicMapper->getError());
462
                }
460
                }
463
                
461
                
464
                // Process images if uploaded
462
                // Process images if uploaded
Línea 478... Línea 476...
478
                    
476
                    
479
                    if(!$topicMapper->update($topic)) {
477
                    if(!$topicMapper->update($topic)) {
480
                        return $this->createErrorResponse($topicMapper->getError());
478
                        return $this->createErrorResponse($topicMapper->getError());
481
                    }
479
                    }
-
 
480
                }
-
 
481
 
-
 
482
                // Update capsule relations
-
 
483
                $result = $this->updateTopicCapsuleRelations($topic, $dataPost['capsule_uuid'], $currentCompany->id);
-
 
484
                if (!$result['success']) {
-
 
485
                    return $this->createErrorResponse($result['error']);
Línea 482... Línea 486...
482
                }
486
                }
Línea 483... Línea 487...
483
                
487
                
484
                $this->logger->info('Se edito el tópico ' . $topic->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
488
                $this->logger->info('Se edito el tópico ' . $topic->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);