Proyectos de Subversion LeadersLinked - Backend

Rev

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

Rev 17126 Rev 17127
Línea 239... Línea 239...
239
            
239
            
Línea 240... Línea 240...
240
            $form->setData($dataPost);
240
            $form->setData($dataPost);
241
            
241
            
242
            if($form->isValid()) {
242
            if($form->isValid()) {
243
                $dataPost = (array) $form->getData();
-
 
244
                
243
                $dataPost = (array) $form->getData();
-
 
244
 
-
 
245
                $topic = new MicrolearningTopic();
245
                $hydrator = new ObjectPropertyHydrator();
246
                $topic->name = $dataPost['name'];
246
                $topic = new MicrolearningTopic();
-
 
-
 
247
                $topic->description = $dataPost['description'];
247
                $hydrator->hydrate($dataPost, $topic);
248
                $topic->order = $dataPost['order'];
248
                
249
                $topic->status = $dataPost['status'];        
249
                $topic->company_id = $currentCompany->id;
-
 
250
                $topic->image = null;
-
 
Línea 251... Línea 250...
251
 
250
                $topic->company_id = $currentCompany->id;
252
               
-
 
253
                
-
 
254
                $topicMapper = MicrolearningTopicMapper::getInstance($this->adapter);
251
                $topic->image = '';
255
                if($topicMapper->insert($topic)) {
-
 
256
                    $topic = $topicMapper->fetchOne($topic->id);
252
                
257
                    
-
 
258
                    // Handle capsule associations
-
 
259
                    if (!empty($dataPost['capsule_uuid'])) {
-
 
260
                        $capsuleUuids = is_array($dataPost['capsule_uuid']) ? $dataPost['capsule_uuid'] : [$dataPost['capsule_uuid']];
-
 
261
                        $capsuleMapper = MicrolearningCapsuleMapper::getInstance($this->adapter);
-
 
262
                        $topicCapsuleMapper = MicrolearningTopicCapsuleMapper::getInstance($this->adapter);
-
 
263
                        
253
                $topicMapper = MicrolearningTopicMapper::getInstance($this->adapter);
264
                        foreach ($capsuleUuids as $capsuleUuid) {
-
 
265
                            $capsule = $capsuleMapper->fetchOneByUuid($capsuleUuid);
-
 
266
                            if ($capsule) {
254
 
267
                                $topicCapsule = new MicrolearningTopicCapsule();
-
 
268
                                $topicCapsule->topic_id = $topic->id;
255
                if(!$topicMapper->insert($topic)) {
269
                                $topicCapsule->capsule_id = $capsule->id;
256
                    $data = [
270
                                $topicCapsule->company_id = $currentCompany->id;
257
                        'success'   => false,
271
                                $topicCapsuleMapper->insert($topicCapsule);
258
                        'data'      => $topicMapper->getError()
272
                            }
259
                    ];
273
                        }
260
                    return new JsonModel($data);
274
                    }
-
 
275
                    
261
                }
-
 
262
 
-
 
263
                $topic = $topicMapper->fetchOne($topic->id);
-
 
264
                
-
 
265
                if (!empty($dataPost['capsule_id'])) {
Línea 276... Línea 266...
276
                    $image = Image::getInstance($this->config);
266
                    $capsuleUuids = is_array($dataPost['capsule_id']) ? $dataPost['capsule_id'] : [$dataPost['capsule_id']];
277
                    $target_path = $image->getStorage()->getPathMicrolearningTopic();
-
 
278
                    
267
                    $capsuleMapper = MicrolearningCapsuleMapper::getInstance($this->adapter);
279
                    
-
 
Línea 280... Línea 268...
280
                    $files = $this->getRequest()->getFiles()->toArray();
268
                    $topicCapsuleMapper = MicrolearningTopicCapsuleMapper::getInstance($this->adapter);
281
                    if(isset($files['file']) && empty($files['file']['error'])) {
-
 
282
                        $tmp_filename  = $files['file']['tmp_name'];
-
 
283
                        // $filename      = $\LeadersLinked\Library\Functions::normalizeStringFilename($files['file']['name']);
269
                    
284
                        
270
                    foreach ($capsuleUuids as $capsuleUuid) {
285
                        try {
271
                        $capsule = $capsuleMapper->fetchOneByUuid($capsuleUuid);
286
                            list($target_width, $target_height) = explode('x', $this->config['leaderslinked.image_sizes.microlearning_image_size']);
-
 
287
                            
-
 
288
                            $filename = 'topic-' .uniqid() . '.png';
272
                        
289
                            $crop_to_dimensions = false;
273
                        if ($capsule) {
290
                            $unlink_source = true;
-
 
291
                            
-
 
292
                            if($image->uploadProcessChangeSize($tmp_filename, $target_path, $topic->uuid, $filename, $target_width, $target_height, $crop_to_dimensions, $unlink_source)) {
-
 
293
                                $topic->image = $filename;
274
                            $topicCapsule = new MicrolearningTopicCapsule();
294
                                $topicMapper->update($topic);
275
                            $topicCapsule->topic_id = $topic->id;
-
 
276
                            $topicCapsule->capsule_id = $capsule->id;
295
                            }
277
                            $topicCapsule->company_id = $currentCompany->id;
-
 
278
                            $topicCapsuleMapper->insert($topicCapsule);
-
 
279
                        }
-
 
280
                    }
-
 
281
                }
-
 
282
                
-
 
283
                $storage = Storage::getInstance($this->config, $this->adapter);
-
 
284
                $storage->setFiles($request->getFiles()->toArray());
-
 
285
        
-
 
286
                if (!$storage->setCurrentFilename('file')) {
296
                        } catch(\Throwable $e) {
287
                    return new JsonModel([
297
                            error_log($e->getTraceAsString());
288
                        'success'   => false,
-
 
289
                        'data'      => 'ERROR_UPLOAD_IMAGE'
298
                        }
290
                    ]);
-
 
291
                }
-
 
292
 
-
 
293
                $target_size = $this->config['leaderslinked.image_sizes.microlearning_image_size'];
-
 
294
                list($target_width, $target_height) = explode('x', $target_size);
-
 
295
 
299
                    }
296
                $source_filename = $storage->getTmpFilename();
-
 
297
                $filename = 'topic-' . uniqid() . '.png';
-
 
298
                $target_filename = $storage->composePathToFilename(
-
 
299
                    Storage::TYPE_MICROLEARNING_TOPIC,
-
 
300
                    $topic->uuid,
300
                    
301
                    $filename
301
                   
302
                );
302
                    $this->logger->info('Se agrego el tópico ' . $topic->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
303
 
303
                    
304
                if (!$storage->uploadImageCrop($source_filename, $target_filename, $target_width, $target_height)) {
-
 
305
                    return new JsonModel([
-
 
306
                        'success'   => false,
-
 
307
                        'data'      => 'ERROR_UPLOAD_IMAGE'
-
 
308
                    ]);
304
                    $data = [
309
                }
305
                        'success'   => true,
310
 
306
                        'data'   => 'LABEL_RECORD_ADDED'
311
                $topic->image = $filename;
307
                    ];
312
 
308
                } else {
-
 
309
                    $data = [
313
                if(!$topicMapper->update($topic)) {
Línea 310... Línea 314...
310
                        'success'   => false,
314
                    return new JsonModel([
Línea -... Línea 315...
-
 
315
                        'success'   => false,
-
 
316
                        'data'      => $topicMapper->getError()
-
 
317
                    ]);
-
 
318
                }
-
 
319
                
-
 
320
                $this->logger->info('Se agrego el tópico ' . $topic->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
311
                        'data'      => $topicMapper->getError()
321
                
312
                    ];
322
                $data = [
313
                    
323
                    'success'   => true,
314
                }
324
                    'data'   => 'LABEL_RECORD_ADDED'
315
                
325
                ];