Proyectos de Subversion LeadersLinked - Backend

Rev

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

Rev 16943 Rev 17002
Línea 14... Línea 14...
14
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
14
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
15
use LeadersLinked\Library\Image;
15
use LeadersLinked\Library\Image;
Línea 16... Línea 16...
16
 
16
 
17
 
17
 
18
use LeadersLinked\Mapper\CompanyMapper;
18
use LeadersLinked\Mapper\CompanyMapper;
19
use LeadersLinked\Mapper\CompanyMicrolearningTopicMapper;
19
use LeadersLinked\Mapper\MicrolearningTopicMapper;
20
use LeadersLinked\Mapper\CompanyMicrolearningCapsuleMapper;
20
use LeadersLinked\Mapper\MicrolearningCapsuleMapper;
21
use LeadersLinked\Mapper\CompanyMicrolearningSlideMapper;
21
use LeadersLinked\Mapper\MicrolearningSlideMapper;
22
use LeadersLinked\Model\CompanyMicrolearningSlide;
22
use LeadersLinked\Model\MicrolearningSlide;
23
use LeadersLinked\Model\VideoConvert;
23
use LeadersLinked\Model\VideoConvert;
24
use LeadersLinked\Mapper\VideoConvertMapper;
24
use LeadersLinked\Mapper\VideoConvertMapper;
25
use LeadersLinked\Form\SlideForm;
25
use LeadersLinked\Form\SlideForm;
Línea 33... Línea 33...
33
use LeadersLinked\Form\SlideAudioAddForm;
33
use LeadersLinked\Form\SlideAudioAddForm;
34
use LeadersLinked\Form\SlideAudioEditForm;
34
use LeadersLinked\Form\SlideAudioEditForm;
35
use LeadersLinked\Form\SlideQuizzAddForm;
35
use LeadersLinked\Form\SlideQuizzAddForm;
36
use LeadersLinked\Form\SlideQuizzEditForm;
36
use LeadersLinked\Form\SlideQuizzEditForm;
37
use LeadersLinked\Form\SlideVideoEditForm;
37
use LeadersLinked\Form\SlideVideoEditForm;
-
 
38
use LeadersLinked\Library\Storage;
Línea 38... Línea 39...
38
 
39
 
39
 
40
 
40
class MicrolearningSlideController extends AbstractActionController
41
class MicrolearningSlideController extends AbstractActionController
Línea 124... Línea 125...
124
            }
125
            }
Línea 125... Línea 126...
125
            
126
            
Línea 126... Línea -...
126
            if($isJson) {
-
 
127
 
127
            if($isJson) {
Línea 128... Línea 128...
128
 
128
 
129
                $topic_uuid     = Functions::sanitizeFilterString($this->params()->fromQuery('topic_uuid'));
129
 
130
                $capsule_uuid   = Functions::sanitizeFilterString($this->params()->fromQuery('capsule_uuid'));
130
                $capsule_uuid   = Functions::sanitizeFilterString($this->params()->fromQuery('capsule_uuid'));
131
                
131
                
Línea 132... Línea 132...
132
                $data = [
132
                $data = [
Línea 133... Línea -...
133
                    'link_add' => '',
-
 
134
                    'items' => [] ,
-
 
135
                    'total' => 0,
-
 
136
                    
-
 
137
                ];
-
 
138
   
-
 
139
 
-
 
140
                if(!$topic_uuid) {
-
 
141
                    return new JsonModel([
-
 
142
                        'success' => true,
-
 
143
                        'data' => $data
-
 
144
                    ]);
-
 
145
                    
-
 
146
                }
-
 
147
                
-
 
148
                
-
 
149
                $topicMapper = CompanyMicrolearningTopicMapper::getInstance($this->adapter);
-
 
150
                $topic = $topicMapper->fetchOneByUuid($topic_uuid);
-
 
151
                if(!$topic) {
-
 
152
                    return new JsonModel([
-
 
153
                        'success' => true,
-
 
154
                        'data' => 'ERROR_TOPIC_NOT_FOUND'
-
 
155
                    ]);
-
 
156
                }
-
 
157
                
-
 
158
                if($topic->company_id != $currentCompany->id) {
-
 
159
                    return new JsonModel([
-
 
160
                        'success' => true,
-
 
161
                        'data' => 'ERROR_UNAUTHORIZED'
-
 
162
                    ]);
-
 
163
                }
-
 
164
                
-
 
165
 
-
 
166
                
-
 
167
                if(!$capsule_uuid) {
-
 
168
                    $capsuleMapper = CompanyMicrolearningCapsuleMapper::getInstance($this->adapter);
-
 
169
                    $records = $capsuleMapper->fetchAllByCompanyIdAndTopicId($topic->company_id, $topic->id);
-
 
170
                    
-
 
171
                    $capsules = []; 
-
 
172
                    foreach($records as $record)
-
 
173
                    {
-
 
174
                        if(!$capsule_uuid) {
-
 
175
                            $capsule_uuid = $record->uuid;
-
 
176
                        } 
-
 
177
                        
-
 
178
                        $capsules[ $record->uuid ] = $record->name;
-
 
179
                    }
-
 
180
                    
-
 
181
                    $data['capsules']  = $capsules;                    
-
 
182
                } 
-
 
183
                
-
 
184
                if(!$capsule_uuid) {
-
 
185
                    return new JsonModel([
-
 
186
                        'success' => true,
133
                    'link_add' => '',
187
                        'data' => $data
134
                    'items' => [] ,
Línea 188... Línea -...
188
                    ]);
-
 
189
                    
135
                    'total' => 0,
190
                }
136
                    
191
                
137
                ];
192
                $capsuleMapper = CompanyMicrolearningCapsuleMapper::getInstance($this->adapter);
138
   
193
                $capsule = $capsuleMapper->fetchOneByUuid($capsule_uuid);
139
                $capsuleMapper = MicrolearningCapsuleMapper::getInstance($this->adapter);
194
                
140
                $capsule = $capsuleMapper->fetchOneByUuid($capsule_uuid);
Línea 195... Línea 141...
195
                
141
                
196
                
142
                
197
                if(!$capsule) {
143
                if(!$capsule) {
198
                    return new JsonModel([
144
                    return new JsonModel([
199
                        'success' => true,
145
                        'success' => true,
200
                        'data' => 'ERROR_CAPSULE_NOT_FOUND'
146
                        'data' => 'ERROR_CAPSULE_NOT_FOUND'
Línea 228... Línea 174...
228
                $acl = $this->getEvent()->getViewModel()->getVariable('acl');
174
                $acl = $this->getEvent()->getViewModel()->getVariable('acl');
229
                $allowAdd = $acl->isAllowed($currentUser->usertype_id, 'microlearning/content/slides/add');
175
                $allowAdd = $acl->isAllowed($currentUser->usertype_id, 'microlearning/content/slides/add');
230
                $allowEdit = $acl->isAllowed($currentUser->usertype_id, 'microlearning/content/slides/edit');
176
                $allowEdit = $acl->isAllowed($currentUser->usertype_id, 'microlearning/content/slides/edit');
231
                $allowDelete = $acl->isAllowed($currentUser->usertype_id, 'microlearning/content/slides/delete');
177
                $allowDelete = $acl->isAllowed($currentUser->usertype_id, 'microlearning/content/slides/delete');
Línea 232... Línea 178...
232
                
178
                
233
                $slideMapper = CompanyMicrolearningSlideMapper::getInstance($this->adapter);   
179
                $slideMapper = MicrolearningSlideMapper::getInstance($this->adapter);   
Línea 234... Línea 180...
234
                $paginator = $slideMapper->fetchAllDataTableByCompanyIdAndTopicIdAndCapsuleId($currentCompany->id, $topic->id, $capsule->id,  $search, $page, $records_x_page, $order_field, $order_direction);
180
                $paginator = $slideMapper->fetchAllDataTableByCompanyIdAndCapsuleId($currentCompany->id, $capsule->id,  $search, $page, $records_x_page, $order_field, $order_direction);
Línea -... Línea 181...
-
 
181
              
-
 
182
                $records = $paginator->getCurrentItems(); 
-
 
183
                
Línea 235... Línea 184...
235
              
184
                $storage = Storage::getInstance($this->config);
236
                $records = $paginator->getCurrentItems(); 
185
                $path = $storage->getPathMicrolearningSlide();
237
                
186
                
Línea 238... Línea 187...
238
                
187
                
239
                $items = [];
-
 
240
                foreach($records as $record)
188
                $items = [];
241
                {
189
                foreach($records as $record)
Línea 242... Línea 190...
242
    
190
                {
Línea 270... Línea 218...
270
                    ];
218
                    ];
Línea 271... Línea 219...
271
                    
219
                    
272
                    
220
                    
273
                    switch($record->type)
221
                    switch($record->type)
Línea 274... Línea 222...
274
                    {
222
                    {
275
                        case CompanyMicrolearningSlide::TYPE_AUDIO :
223
                        case MicrolearningSlide::TYPE_AUDIO :
276
                            
224
                            
277
                            $item['media']['audio'] =  $this->url()->fromRoute('storage', ['type' => 'microlearning-slide', 'code' => $record->uuid, 'filename' =>  $record->file ]);
225
                            $item['media']['audio'] = $storage->getGenericFile($path, $record->uuid, $record->file );
Línea 278... Línea 226...
278
                            $item['media']['image'] = $this->url()->fromRoute('storage', ['type' => 'microlearning-slide', 'code' => $record->uuid, 'filename' =>  $record->background ]);
226
                            $item['media']['image'] = $storage->getGenericImage($path, $record->uuid, $record->background );
279
                            $item['details']['type'] = 'LABEL_AUDIO';
227
                            $item['details']['type'] = 'LABEL_AUDIO';
280
                            break;
228
                            break;
281
                            
229
                            
282
                        case CompanyMicrolearningSlide::TYPE_VIDEO :
230
                        case MicrolearningSlide::TYPE_VIDEO :
Línea 283... Línea 231...
283
                            $item['media']['video'] =  $this->url()->fromRoute('storage', ['type' => 'microlearning-slide', 'code' => $record->uuid, 'filename' =>  $record->file ]);
231
                            $item['media']['video'] = $storage->getGenericFile($path, $record->uuid, $record->file );
284
                            $item['media']['image'] = $this->url()->fromRoute('storage', ['type' => 'microlearning-slide', 'code' => $record->uuid, 'filename' =>  $record->background ]);
232
                            $item['media']['image'] = $storage->getGenericImage($path, $record->uuid, $record->background );
285
                            $item['details']['type'] = 'LABEL_VIDEO';
233
                            $item['details']['type'] = 'LABEL_VIDEO';
286
                            break;
234
                            break;
287
                            
235
                            
Línea 288... Línea 236...
288
                        case CompanyMicrolearningSlide::TYPE_DOCUMENT :
236
                        case MicrolearningSlide::TYPE_DOCUMENT :
289
                            $item['media']['document'] =  $this->url()->fromRoute('storage', ['type' => 'microlearning-slide', 'code' => $record->uuid, 'filename' =>  $record->file ]);
237
                            $item['media']['document'] =  $storage->getGenericFile($path, $record->uuid, $record->file );
290
                            $item['media']['image'] = $this->url()->fromRoute('storage', ['type' => 'microlearning-slide', 'code' => $record->uuid, 'filename' =>  $record->background ]);
238
                            $item['media']['image'] = $storage->getGenericImage($path, $record->uuid, $record->background );
291
                            $item['details']['type'] = 'LABEL_DOCUMENT';
239
                            $item['details']['type'] = 'LABEL_DOCUMENT';
292
                            break;
240
                            break;
Línea 293... Línea 241...
293
                            
241
                            
294
                        case CompanyMicrolearningSlide::TYPE_TEXT :
242
                        case MicrolearningSlide::TYPE_TEXT :
295
                            $item['media']['image'] = $this->url()->fromRoute('storage', ['type' => 'microlearning-slide', 'code' => $record->uuid, 'filename' =>  $record->background ]);
243
                            $item['media']['image'] = $storage->getGenericImage($path, $record->uuid, $record->background );
296
                            $item['media']['text'] = $this->url()->fromRoute('microlearning/content/slides/text', $params); 
244
                            $item['media']['text'] = $this->url()->fromRoute('microlearning/content/slides/text', $params); 
Línea 297... Línea 245...
297
                            $item['details']['type'] = 'LABEL_TEXT';
245
                            $item['details']['type'] = 'LABEL_TEXT';
298
                            break;
246
                            break;
299
                            
247
                            
300
                        case CompanyMicrolearningSlide::TYPE_QUIZ :
248
                        case MicrolearningSlide::TYPE_QUIZ :
Línea 301... Línea 249...
301
                            $item['media']['image'] = $this->url()->fromRoute('storage', ['type' => 'microlearning-slide', 'code' => $record->uuid, 'filename' =>  $record->background ]);
249
                            $item['media']['image'] = $storage->getGenericImage($path, $record->uuid, $record->background );
Línea 302... Línea 250...
302
                            $item['details']['type'] = 'LABEL_QUIZ';
250
                            $item['details']['type'] = 'LABEL_QUIZ';
Línea 303... Línea 251...
303
                            break;
251
                            break;
Línea 304... Línea 252...
304
                            
252
                            
305
                        case CompanyMicrolearningSlide::TYPE_IMAGE :
253
                        case MicrolearningSlide::TYPE_IMAGE :
306
                            $item['media']['image'] = $this->url()->fromRoute('storage', ['type' => 'microlearning-slide', 'code' => $record->uuid, 'filename' =>  $record->file ]);
254
                            $item['media']['image'] =  $storage->getGenericImage($path, $record->uuid, $record->file );
307
                            $item['details']['type'] = 'LABEL_IMAGE';
255
                            $item['details']['type'] = 'LABEL_IMAGE';
308
                            break;
256
                            break;
Línea 309... Línea 257...
309
                            
257
                            
Línea 326... Línea 274...
326
                ]);
274
                ]);
Línea 327... Línea 275...
327
                
275
                
328
            } else {
276
            } else {
Línea 329... Línea -...
329
                $image_size = $this->config['leaderslinked.image_sizes.microlearning_image_upload'];
-
 
330
                
-
 
-
 
277
                $image_size = $this->config['leaderslinked.image_sizes.microlearning_image_upload'];
Línea 331... Línea -...
331
                $topicMapper = CompanyMicrolearningTopicMapper::getInstance($this->adapter);
-
 
332
                $topics = $topicMapper->fetchAllByCompanyId($currentCompany->id); 
-
 
333
                
-
 
334
                if($topics) {
-
 
335
                    $topic_id = $topics[0]->id; 
-
 
336
                }  else { 
-
 
337
                    $topic_id = 0;
-
 
338
                } 
278
                
339
                
279
     
340
                
280
                
341
                $form = new SlideForm($this->adapter,  $currentCompany->id, $topic_id);
281
                $form = new SlideForm($this->adapter,  $currentCompany->id);
342
                $formTextAdd = new SlideTextAddForm();
282
                $formTextAdd = new SlideTextAddForm();
343
                $formTextEdit = new SlideTextEditForm();
283
                $formTextEdit = new SlideTextEditForm();
Línea 395... Línea 335...
395
        $currentUserPlugin = $this->plugin('currentUserPlugin');
335
        $currentUserPlugin = $this->plugin('currentUserPlugin');
396
        $currentUser = $currentUserPlugin->getUser();
336
        $currentUser = $currentUserPlugin->getUser();
397
        $currentCompany = $currentUserPlugin->getCompany();
337
        $currentCompany = $currentUserPlugin->getCompany();
Línea 398... Línea 338...
398
        
338
        
399
        $request    = $this->getRequest();
-
 
400
        $topic_uuid   = $this->params()->fromRoute('topic_uuid');
339
        $request    = $this->getRequest();
Línea 401... Línea -...
401
        $capsule_uuid = $this->params()->fromRoute('capsule_uuid');
-
 
402
 
-
 
403
 
-
 
404
        
-
 
405
        $topicMapper = CompanyMicrolearningTopicMapper::getInstance($this->adapter);
-
 
406
        $topic = $topicMapper->fetchOneByUuid($topic_uuid);
-
 
407
        if(!$topic) {
-
 
408
            return new JsonModel([
-
 
409
                'success'   => false,
-
 
410
                'data'   => 'ERROR_TOPIC_NOT_FOUND'
-
 
Línea 411... Línea -...
411
            ]);
-
 
412
        }
-
 
413
        
-
 
414
        if($topic->company_id != $currentCompany->id) {
-
 
415
            return new JsonModel([
-
 
416
                'success'   => false,
-
 
Línea 417... Línea -...
417
                'data'   => 'ERROR_UNAUTHORIZED'
-
 
418
            ]);
340
        $capsule_uuid = $this->params()->fromRoute('capsule_uuid');
419
        }
341
 
420
        
342
        
421
        
343
        
422
        $capsuleMapper = CompanyMicrolearningCapsuleMapper::getInstance($this->adapter);
344
        $capsuleMapper = MicrolearningCapsuleMapper::getInstance($this->adapter);
423
        $capsule = $capsuleMapper->fetchOneByUuid($capsule_uuid);
345
        $capsule = $capsuleMapper->fetchOneByUuid($capsule_uuid);
424
        if(!$capsule) {
346
        if(!$capsule) {
425
            return new JsonModel([
347
            return new JsonModel([
Línea 426... Línea 348...
426
                'success'   => false,
348
                'success'   => false,
427
                'data'   => 'ERROR_CAPSULE_NOT_FOUND'
349
                'data'   => 'ERROR_CAPSULE_NOT_FOUND'
428
            ]);
350
            ]);
429
        }
351
        }
430
        
352
        
431
        if($capsule->topic_id != $topic->id) {
353
        if($capsule->company_id != $currentCompany->id) {
Línea 440... Línea 362...
440
            
362
            
Línea 441... Línea 363...
441
            $dataPost = array_merge($request->getPost()->toArray(), $request->getFiles()->toArray());
363
            $dataPost = array_merge($request->getPost()->toArray(), $request->getFiles()->toArray());
442
            
364
            
443
            switch($dataPost['type'])
365
            switch($dataPost['type'])
444
            {
366
            {
445
                case CompanyMicrolearningSlide::TYPE_AUDIO : 
367
                case MicrolearningSlide::TYPE_AUDIO : 
Línea 446... Línea 368...
446
                    $form = new SlideAudioAddForm();
368
                    $form = new SlideAudioAddForm();
447
                    break;
369
                    break;
448
                    
370
                    
Línea 449... Línea 371...
449
                case CompanyMicrolearningSlide::TYPE_VIDEO :
371
                case MicrolearningSlide::TYPE_VIDEO :
450
                    $form = new SlideVideoAddForm();
372
                    $form = new SlideVideoAddForm();
451
                    break;
373
                    break;
Línea 452... Línea 374...
452
                
374
                
453
                case CompanyMicrolearningSlide::TYPE_DOCUMENT:
375
                case MicrolearningSlide::TYPE_DOCUMENT:
454
                    $form = new SlideDocumentAddForm();
376
                    $form = new SlideDocumentAddForm();
Línea 455... Línea 377...
455
                    break;
377
                    break;
456
                    
378
                    
457
                case CompanyMicrolearningSlide::TYPE_IMAGE :
379
                case MicrolearningSlide::TYPE_IMAGE :
Línea 458... Línea 380...
458
                    $form = new SlideImageAddForm();
380
                    $form = new SlideImageAddForm();
459
                    break;
381
                    break;
Línea 472... Línea 394...
472
            
394
            
473
            if($form->isValid()) {
395
            if($form->isValid()) {
Línea 474... Línea 396...
474
                $dataPost = (array) $form->getData();
396
                $dataPost = (array) $form->getData();
475
                
397
                
476
                $hydrator = new ObjectPropertyHydrator();
398
                $hydrator = new ObjectPropertyHydrator();
Línea 477... Línea 399...
477
                $slide = new CompanyMicrolearningSlide();
399
                $slide = new MicrolearningSlide();
478
                $hydrator->hydrate($dataPost, $slide);
-
 
479
                
400
                $hydrator->hydrate($dataPost, $slide);
480
                $slide->company_id = $topic->company_id;
401
                
481
                $slide->topic_id = $topic->id;
402
                $slide->company_id = $capsule->company_id;
Línea 482... Línea 403...
482
                $slide->capsule_id = $capsule->id;
403
                $slide->capsule_id = $capsule->id;
483
                $slide->file = null;
404
                $slide->file = null;
484
                $slide->background = null;
405
                $slide->background = null;
Línea -... Línea 406...
-
 
406
                
-
 
407
                $slideMapper = MicrolearningSlideMapper::getInstance($this->adapter);
-
 
408
                if($slideMapper->insert($slide)) {
-
 
409
                    $slide = $slideMapper->fetchOne($slide->id);
-
 
410
                    
485
                
411
                    
486
                $slideMapper = CompanyMicrolearningSlideMapper::getInstance($this->adapter);
-
 
487
                if($slideMapper->insert($slide)) {
-
 
488
                    $slide = $slideMapper->fetchOne($slide->id);
-
 
489
                    
-
 
-
 
412
                    $image = Image::getInstance($this->config);
Línea 490... Línea 413...
490
                    $files = $this->getRequest()->getFiles()->toArray();
413
                    $target_path = $image->getStorage()->getPathMicrolearningSlide();
-
 
414
                    
-
 
415
                    
Línea 491... Línea 416...
491
                    $target_path = $this->config['leaderslinked.fullpath.microlearning_slide'] .  $slide->uuid;
416
                    $files = $this->getRequest()->getFiles()->toArray();
492
                    if(!file_exists($target_path)) {
417
                   
Línea 493... Línea 418...
493
                        mkdir($target_path, 0755, true);
418
                    
Línea 494... Línea 419...
494
                    }
419
                    if(isset($files['file']) && empty($files['file']['error'])) {
495
                    
420
                        
Línea 496... Línea 421...
496
                    if(isset($files['file']) && empty($files['file']['error'])) {
421
                        
497
                    
422
                    
Línea 498... Línea 423...
498
                        switch($slide->type)
423
                        switch($slide->type)
499
                        {
424
                        {
-
 
425
 
-
 
426
                            case MicrolearningSlide::TYPE_IMAGE : 
500
 
427
                        
501
                            case CompanyMicrolearningSlide::TYPE_IMAGE : 
428
                           
502
                        
429
                                $tmp_filename  = $files['file']['tmp_name'];
Línea 503... Línea 430...
503
                           
430
                                // $filename      = $this->normalizeString($files['file']['name']);
504
                                $tmp_filename  = $files['file']['tmp_name'];
431
                                
505
                                // $filename      = $this->normalizeString($files['file']['name']);
432
                                try {
506
                                
433
                                    list($target_width, $target_height) = explode('x', $this->config['leaderslinked.image_sizes.microlearning_image_size']);
Línea 507... Línea 434...
507
                                try {
434
                                    
Línea 508... Línea 435...
508
                                    list($target_width, $target_height) = explode('x', $this->config['leaderslinked.image_sizes.microlearning_image_size']);
435
                                    $filename =  'slide-' .uniqid() . '.jpg';
509
                                    
436
                                    $crop_to_dimensions = false;
510
                                    $filename =  'slide-' .uniqid() . '.jpg';
437
                                    $unlink_source = true;
Línea 511... Línea 438...
511
                                    $crop_to_dimensions = false;
438
                                    
512
                                    if(Image::uploadImage($tmp_filename, $target_path, $filename, $target_width, $target_height, $crop_to_dimensions)) {
439
                                    if($image->uploadImageChangeSize($tmp_filename, $target_path, $slide->uuid, $filename, $target_width, $target_height, $crop_to_dimensions, $unlink_source)) {
513
                                        $slide->file = basename($filename);
440
                                        $slide->file = $filename;
514
                                        $slideMapper->update($slide);
441
                                        $slideMapper->update($slide);
515
                                    
442
                                    
516
                                    }
443
                                    }
517
                                } catch(\Throwable $e) {
444
                                } catch(\Throwable $e) {
Línea 538... Línea 465...
538
                                try {
465
                                try {
Línea 539... Línea 466...
539
                                    
466
                                    
540
                                    $parts = explode('.', $original_filename);
467
                                    $parts = explode('.', $original_filename);
Línea 541... Línea -...
541
                                    $filename = 'document-' . uniqid() . '.' . $parts[ count($parts) - 1 ];
-
 
-
 
468
                                    $filename = 'document-' . uniqid() . '.' . $parts[ count($parts) - 1 ];
542
                                    
469
                                    
543
                                    $full_filename = $target_path  . DIRECTORY_SEPARATOR .$filename;
470
                      
544
                                    if(move_uploaded_file($tmp_filename, $full_filename)) {
471
                                    if($image->getStorage()->moveAndputFile($target_path, $slide->uuid, $tmp_filename, $full_filename)) {
545
                                        $slide->file = basename($full_filename);
472
                                        $slide->file = $filename;
546
                                        $slideMapper->update($slide);
473
                                        $slideMapper->update($slide);
547
                                    }
474
                                    }
548
                                } catch(\Throwable $e) {
475
                                } catch(\Throwable $e) {
Línea 549... Línea 476...
549
                                    error_log($e->getTraceAsString());
476
                                    error_log($e->getTraceAsString());
Línea 550... Línea 477...
550
                                }
477
                                }
551
 
478
 
552
                                break;
479
                                break;
Línea 553... Línea 480...
553
                                
480
                                
Línea 568... Línea 495...
568
                                try {
495
                                try {
Línea 569... Línea 496...
569
                                    
496
                                    
570
                                    $parts = explode('.', $original_filename);
497
                                    $parts = explode('.', $original_filename);
Línea 571... Línea 498...
571
                                    $filename = 'audio-' . uniqid() . '.' . $parts[ count($parts) - 1 ];
498
                                    $filename = 'audio-' . uniqid() . '.' . $parts[ count($parts) - 1 ];
572
                                    
499
                                    
Línea 573... Línea 500...
573
                                    $full_filename      = $target_path  . DIRECTORY_SEPARATOR .$filename;
500
                                    $full_filename      =  sys_get_temp_dir() . DIRECTORY_SEPARATOR .$filename;
574
                                    if(move_uploaded_file($tmp_filename , $full_filename)) {
501
                                    if(move_uploaded_file($tmp_filename , $full_filename)) {
575
                                        
502
                                        
576
                                        
503
                                        
Línea -... Línea 504...
-
 
504
                                        $generateFileName   = substr($filename, 0, strrpos($filename, '.')) .  '.mp3';
-
 
505
                                        $generateFile       = sys_get_temp_dir() .  DIRECTORY_SEPARATOR . $generateFileName;
577
                                        $generateFileName   = substr($filename, 0, strrpos($filename, '.'));
506
                                        $cmd                = "/usr/bin/ffmpeg -i $full_filename -b:a 320000 $generateFile";
578
                                        $generateFile       =  $target_path  . DIRECTORY_SEPARATOR . $generateFileName .  '.mp3';
507
                                        exec($cmd);
-
 
508
                                        
579
                                        $cmd                = "/usr/bin/ffmpeg -i $full_filename -b:a 320000 $generateFile";
509
                                        if($image->getStorage()->putFile($target_path, $slide->uuid, $generateFile)) {
Línea 580... Línea 510...
580
                                        exec($cmd);
510
                                            
581
                                        
511
                                            $slide->file =  $generateFileName;
582
                                        $slide->file = basename($full_filename);
512
                                            $slideMapper->update($slide);
Línea 583... Línea 513...
583
                                        $slideMapper->update($slide);
513
                                        }
Línea 584... Línea 514...
584
                                    }
514
                                    }
585
                                    
515
                                    
586
                                } catch(\Throwable $e) {
516
                                } catch(\Throwable $e) {
Línea 587... Línea 517...
587
                                    error_log($e->getTraceAsString());
517
                                    error_log($e->getTraceAsString());
Línea 606... Línea 536...
606
 
536
 
607
                                try {
537
                                try {
608
                                    $parts = explode('.', $original_filename);
538
                                    $parts = explode('.', $original_filename);
Línea 609... Línea 539...
609
                                    $filename = 'video-' . uniqid() . '.' . $parts[ count($parts) - 1 ];
539
                                    $filename = 'video-' . uniqid() . '.' . $parts[ count($parts) - 1 ];
Línea 610... Línea 540...
610
                                    
540
                                    
Línea 611... Línea -...
611
                                    $full_filename      = $target_path  . DIRECTORY_SEPARATOR .$filename;
-
 
612
                                    
541
                                    $full_filename      = $image->getStorage()->getTempPath()  . DIRECTORY_SEPARATOR .$filename;
613
                                    if(move_uploaded_file($tmp_filename , $full_filename)) {
-
 
Línea -... Línea 542...
-
 
542
                                    
-
 
543
                                    if(move_uploaded_file($tmp_filename , $full_filename)) {
-
 
544
                                        
-
 
545
                                        if($image->getStorage()->putFile($target_path, $slide->uuid, $full_filename)) {
-
 
546
                                        
614
                                        
547
                                            $videoConvert = new VideoConvert();
615
                                        $videoConvert = new VideoConvert();
548
                                            $videoConvert->uuid = $slide->uuid;
-
 
549
                                            $videoConvert->filename = $full_filename;
-
 
550
                                            $videoConvert->type = VideoConvert::TYPE_MICRO_LEARNING_SLIDES;
616
                                        $videoConvert->filename = $full_filename;
551
                                            
617
                                        $videoConvert->type = VideoConvert::TYPE_MICRO_LEARNING;
552
                                            $videoConvertMapper = VideoConvertMapper::getInstance($this->adapter);
618
                                        
553
                                            $videoConvertMapper->insert($videoConvert);
-
 
554
                                            
619
                                        $videoConvertMapper = VideoConvertMapper::getInstance($this->adapter);
555
                                           
Línea 620... Línea 556...
620
                                        $videoConvertMapper->insert($videoConvert);
556
                                            
621
                                        
557
                                            $slide->file = $filename;
Línea 647... Línea 583...
647
                        try {
583
                        try {
648
                            list($target_width, $target_height) = explode('x', $this->config['leaderslinked.image_sizes.microlearning_image_size']);
584
                            list($target_width, $target_height) = explode('x', $this->config['leaderslinked.image_sizes.microlearning_image_size']);
Línea 649... Línea 585...
649
                            
585
                            
650
                            $filename = 'background-' .uniqid() . '.png';
586
                            $filename = 'background-' .uniqid() . '.png';
-
 
587
                            $crop_to_dimensions = true;
-
 
588
                            $unlink_source = true;
651
                            $crop_to_dimensions = true;
589
                            
652
                            if(Image::uploadImage($tmp_filename, $target_path, $filename, $target_width, $target_height, $crop_to_dimensions)) {
590
                            if($image->uploadImageChangeSize($tmp_filename, $target_path, $slide->uuid, $filename, $target_width, $target_height, $crop_to_dimensions, $unlink_source)) {
653
                                $slide->background = $filename;
591
                                $slide->background = $filename;
654
                                $slideMapper->update($slide);
592
                                $slideMapper->update($slide);
655
                            }
593
                            }
656
                        } catch(\Throwable $e) {
594
                        } catch(\Throwable $e) {
Línea 665... Línea 603...
665
                        'data'   => 'LABEL_RECORD_ADDED'
603
                        'data'   => 'LABEL_RECORD_ADDED'
666
                    ];
604
                    ];
667
                } else {
605
                } else {
668
                    $data = [
606
                    $data = [
669
                        'success'   => false,
607
                        'success'   => false,
670
                        'data'      => $topicMapper->getError()
608
                        'data'      => $slideMapper->getError()
671
                    ];
609
                    ];
Línea 672... Línea 610...
672
                    
610
                    
Línea 673... Línea 611...
673
                }
611
                }
Línea 711... Línea 649...
711
        $currentUserPlugin = $this->plugin('currentUserPlugin');
649
        $currentUserPlugin = $this->plugin('currentUserPlugin');
712
        $currentUser = $currentUserPlugin->getUser();
650
        $currentUser = $currentUserPlugin->getUser();
713
        $currentCompany = $currentUserPlugin->getCompany();
651
        $currentCompany = $currentUserPlugin->getCompany();
Línea 714... Línea 652...
714
        
652
        
715
        $request    = $this->getRequest();
-
 
-
 
653
        $request    = $this->getRequest();
716
        $topic_uuid   = $this->params()->fromRoute('topic_uuid');
654
 
717
        $capsule_uuid = $this->params()->fromRoute('capsule_uuid');
655
        $capsule_uuid = $this->params()->fromRoute('capsule_uuid');
Línea -... Línea 656...
-
 
656
        $slide_uuid = $this->params()->fromRoute('slide_uuid');
Línea 718... Línea -...
718
        $slide_uuid = $this->params()->fromRoute('slide_uuid');
-
 
719
        
-
 
720
 
-
 
721
        
-
 
722
        $topicMapper = CompanyMicrolearningTopicMapper::getInstance($this->adapter);
-
 
723
        $topic = $topicMapper->fetchOneByUuid($topic_uuid);
-
 
724
        if(!$topic) {
-
 
725
            return new JsonModel([
-
 
726
                'success'   => false,
-
 
727
                'data'   => 'ERROR_TOPIC_NOT_FOUND'
-
 
728
            ]);
-
 
729
        }
-
 
730
        
-
 
731
        if($topic->company_id != $currentCompany->id) {
-
 
732
            return new JsonModel([
-
 
733
                'success'   => false,
-
 
734
                'data'   => 'ERROR_UNAUTHORIZED'
657
        
735
            ]);
658
 
736
        }
659
    
737
        
660
        
738
        $capsuleMapper = CompanyMicrolearningCapsuleMapper::getInstance($this->adapter);
661
        $capsuleMapper = MicrolearningCapsuleMapper::getInstance($this->adapter);
739
        $capsule = $capsuleMapper->fetchOneByUuid($capsule_uuid);
662
        $capsule = $capsuleMapper->fetchOneByUuid($capsule_uuid);
740
        if(!$capsule) {
663
        if(!$capsule) {
741
            return new JsonModel([
664
            return new JsonModel([
Línea 742... Línea 665...
742
                'success'   => false,
665
                'success'   => false,
743
                'data'   => 'ERROR_CAPSULE_NOT_FOUND'
666
                'data'   => 'ERROR_CAPSULE_NOT_FOUND'
744
            ]);
667
            ]);
745
        }
668
        }
746
        
669
        
747
        if($capsule->topic_id != $topic->id) {
670
        if($capsule->company_id != $currentCompany->id) {
Línea 748... Línea 671...
748
            return new JsonModel([
671
            return new JsonModel([
749
                'success'   => false,
672
                'success'   => false,
750
                'data'   => 'ERROR_UNAUTHORIZED'
673
                'data'   => 'ERROR_UNAUTHORIZED'
751
            ]);
674
            ]);
752
        }
675
        }
753
        
676
        
Línea 770... Línea 693...
770
        if($request->isPost()) {
693
        if($request->isPost()) {
Línea 771... Línea 694...
771
            
694
            
772
            $result =  $slideMapper->delete($slide);
695
            $result =  $slideMapper->delete($slide);
773
            if($result) {
696
            if($result) {
774
                $this->logger->info('Se borro la diapositiva : ' .  $capsule->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
-
 
775
                try {
-
 
776
                    $target_path = $this->config['leaderslinked.fullpath.microlearning_slide'] . $slide->uuid;
-
 
777
                    if(file_exists($target_path)) {
-
 
778
                        Functions::rmDirRecursive($target_path);
-
 
779
                    }
-
 
780
                } catch(\Throwable $e) {
-
 
781
                    error_log($e->getTraceAsString());
-
 
Línea -... Línea 697...
-
 
697
                $this->logger->info('Se borro la diapositiva : ' .  $capsule->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
-
 
698
                
-
 
699
                
-
 
700
                
-
 
701
                $storage = Storage::getInstance($this->config);
-
 
702
                $target_path = $storage->getPathMicrolearningSlide();
-
 
703
                
-
 
704
                $storage->deleteFile($target_path, $slide->uuid, $slide->file);
-
 
705
                
-
 
706
                if($slide->background) {
782
                }
707
                    $storage->deleteFile($target_path, $slide->uuid, $slide->background);
783
                
708
                }
784
                
709
                
785
                $data = [
710
                $data = [
786
                    'success' => true,
711
                    'success' => true,
Línea 814... Línea 739...
814
        $currentUserPlugin = $this->plugin('currentUserPlugin');
739
        $currentUserPlugin = $this->plugin('currentUserPlugin');
815
        $currentUser = $currentUserPlugin->getUser();
740
        $currentUser = $currentUserPlugin->getUser();
816
        $currentCompany = $currentUserPlugin->getCompany();
741
        $currentCompany = $currentUserPlugin->getCompany();
Línea 817... Línea 742...
817
        
742
        
818
        $request    = $this->getRequest();
-
 
819
        $topic_uuid   = $this->params()->fromRoute('topic_uuid');
743
        $request    = $this->getRequest();
820
        $capsule_uuid = $this->params()->fromRoute('capsule_uuid');
744
        $capsule_uuid = $this->params()->fromRoute('capsule_uuid');
821
        $slide_uuid   = $this->params()->fromRoute('slide_uuid');
-
 
822
        
745
        $slide_uuid   = $this->params()->fromRoute('slide_uuid');
823
        
-
 
824
        $topicMapper = CompanyMicrolearningTopicMapper::getInstance($this->adapter);
-
 
825
        $topic = $topicMapper->fetchOneByUuid($topic_uuid);
-
 
826
        if(!$topic) {
-
 
827
            return new JsonModel([
-
 
828
                'success'   => false,
-
 
829
                'data'   => 'ERROR_TOPIC_NOT_FOUND'
-
 
830
            ]);
-
 
831
        }
-
 
832
        
-
 
833
        if($topic->company_id != $currentCompany->id) {
-
 
834
            return new JsonModel([
-
 
835
                'success'   => false,
-
 
836
                'data'   => 'ERROR_UNAUTHORIZED'
-
 
837
            ]);
-
 
838
        }
-
 
839
        
746
 
840
        $capsuleMapper = CompanyMicrolearningCapsuleMapper::getInstance($this->adapter);
747
        $capsuleMapper = MicrolearningCapsuleMapper::getInstance($this->adapter);
841
        $capsule = $capsuleMapper->fetchOneByUuid($capsule_uuid);
748
        $capsule = $capsuleMapper->fetchOneByUuid($capsule_uuid);
842
        if(!$capsule) {
749
        if(!$capsule) {
843
            return new JsonModel([
750
            return new JsonModel([
844
                'success'   => false,
751
                'success'   => false,
845
                'data'   => 'ERROR_CAPSULE_NOT_FOUND'
752
                'data'   => 'ERROR_CAPSULE_NOT_FOUND'
846
            ]);
753
            ]);
Línea 847... Línea 754...
847
        }
754
        }
848
        
755
        
849
        if($capsule->topic_id != $topic->id) {
756
        if($capsule->company_id != $currentCompany->id) {
850
            return new JsonModel([
757
            return new JsonModel([
851
                'success'   => false,
758
                'success'   => false,
852
                'data'   => 'ERROR_UNAUTHORIZED'
759
                'data'   => 'ERROR_UNAUTHORIZED'
Línea 853... Línea 760...
853
            ]);
760
            ]);
854
        }
761
        }
855
        
762
        
856
        
763
        
857
        $slideMapper = CompanyMicrolearningSlideMapper::getInstance($this->adapter);
764
        $slideMapper = MicrolearningSlideMapper::getInstance($this->adapter);
858
        $slide = $slideMapper->fetchOneByUuid($slide_uuid);
765
        $slide = $slideMapper->fetchOneByUuid($slide_uuid);
Línea 869... Línea 776...
869
                'data'   => 'ERROR_UNAUTHORIZED'
776
                'data'   => 'ERROR_UNAUTHORIZED'
870
            ]);
777
            ]);
871
        }
778
        }
Línea 872... Línea 779...
872
        
779
        
-
 
780
        if($request->isGet()) {
-
 
781
    
873
        if($request->isGet()) {
782
            $storage = Storage::getInstance($this->config);
-
 
783
            $path = $storage->getPathMicrolearningSlide();
-
 
784
            
874
            $sliderFile='';
785
            
-
 
786
            if($slide->type =='image'){
-
 
787
                $data = [
-
 
788
                    'success' => true,
-
 
789
                    'data' => [
-
 
790
                        'name' => $slide->name,
-
 
791
                        'type' => $slide->type,
-
 
792
                        'description' => $slide->description,
-
 
793
                        'order' => $slide->order,
875
            if($slide->type=='image'){
794
                        'quiz_id' => $slide->quiz_id,
-
 
795
                        'file'=> $storage->getGenericImage($path, $slide->uuid, $slide->file),
-
 
796
                        'background' => ''
-
 
797
                    ]
-
 
798
                ];
-
 
799
            } else {
-
 
800
                $data = [
-
 
801
                    'success' => true,
-
 
802
                    'data' => [
-
 
803
                        'name' => $slide->name,
-
 
804
                        'type' => $slide->type,
-
 
805
                        'description' => $slide->description,
-
 
806
                        'order' => $slide->order,
-
 
807
                        'quiz_id' => $slide->quiz_id,
-
 
808
                        'file'=> $storage->getGenericFile($path, $slide->uuid, $slide->file),
-
 
809
                        'background' => $storage->getGenericImage($path, $slide->uuid, $slide->background),
-
 
810
                    ]
876
                $sliderFile=$this->url()->fromRoute('storage', ['type' => 'microlearning-slide', 'code' => $slide->uuid, 'filename' => $slide->file]);
811
                ];
877
            }
-
 
878
            $data = [
-
 
879
                'success' => true,
-
 
880
                'data' => [
-
 
881
                    'name' => $slide->name,
-
 
882
                    'type' => $slide->type,
-
 
883
                    'description' => $slide->description,
-
 
884
                    'order' => $slide->order,
-
 
885
                    'quiz_id' => $slide->quiz_id,
-
 
886
                    'file'=> $sliderFile,
-
 
887
                    'background' =>$this->url()->fromRoute('storage', ['type' => 'microlearning-slide', 'code' => $slide->uuid, 'filename' => $slide->background]),
-
 
888
                ]
-
 
Línea 889... Línea 812...
889
            ];
812
            }
890
            
813
            
891
            return new JsonModel($data);
814
            return new JsonModel($data);
892
        } 
815
        } 
Línea 893... Línea 816...
893
        else if($request->isPost()) {
816
        else if($request->isPost()) {
894
            $dataPost = array_merge($request->getPost()->toArray(), $request->getFiles()->toArray());
817
            $dataPost = array_merge($request->getPost()->toArray(), $request->getFiles()->toArray());
895
             
818
             
896
            switch($dataPost['type'])
819
            switch($dataPost['type'])
897
            {
820
            {
Línea 898... Línea 821...
898
                case CompanyMicrolearningSlide::TYPE_AUDIO :
821
                case MicrolearningSlide::TYPE_AUDIO :
899
                    $form = new SlideAudioEditForm();
822
                    $form = new SlideAudioEditForm();
900
                    break;
823
                    break;
Línea 901... Línea 824...
901
                    
824
                    
902
                case CompanyMicrolearningSlide::TYPE_VIDEO :
825
                case MicrolearningSlide::TYPE_VIDEO :
903
                    $form = new SlideVideoEditForm();
826
                    $form = new SlideVideoEditForm();
Línea 904... Línea 827...
904
                    break;
827
                    break;
905
                    
828
                    
906
                case CompanyMicrolearningSlide::TYPE_DOCUMENT:
829
                case MicrolearningSlide::TYPE_DOCUMENT:
Línea 907... Línea 830...
907
                    $form = new SlideDocumentEditForm();
830
                    $form = new SlideDocumentEditForm();
908
                    break;
831
                    break;
909
                    
832
                    
Línea 910... Línea 833...
910
                case CompanyMicrolearningSlide::TYPE_IMAGE :
833
                case MicrolearningSlide::TYPE_IMAGE :
911
                    $form = new SlideImageEditForm();
834
                    $form = new SlideImageEditForm();
Línea 932... Línea 855...
932
                
855
                
933
                if($slideMapper->update($slide)) {
856
                if($slideMapper->update($slide)) {
Línea -... Línea 857...
-
 
857
                    $slide = $slideMapper->fetchOne($slide->id);    
934
                    $slide = $slideMapper->fetchOne($slide->id);    
858
                    
935
                    
-
 
-
 
859
                    
-
 
860
                    
936
                    
861
                    $files = $this->getRequest()->getFiles()->toArray();
937
                    $files = $this->getRequest()->getFiles()->toArray();
862
                    
938
                    $target_path = $this->config['leaderslinked.fullpath.microlearning_slide'] .  $slide->uuid;
-
 
Línea 939... Línea 863...
939
                    if(!file_exists($target_path)) {
863
                    
Línea 940... Línea 864...
940
                        mkdir($target_path, 0755, true);
864
                    $image = Image::getInstance($this->config);
941
                    }
865
                    $target_path = $image->getStorage()->getPathMicrolearningSlide();
Línea 942... Línea 866...
942
                    
866
                    
Línea 943... Línea 867...
943
                    if(isset($files['file']) && empty($files['file']['error'])) {
867
                    if(isset($files['file']) && empty($files['file']['error'])) {
944
                        
868
                        
Línea 945... Línea 869...
945
                        switch($slide->type)
869
                        switch($slide->type)
946
                        {
870
                        {
Línea 947... Línea 871...
947
                            
871
                            
948
                            case CompanyMicrolearningSlide::TYPE_IMAGE :
872
                            case MicrolearningSlide::TYPE_IMAGE :
-
 
873
                                
-
 
874
                                
949
                                
875
                                $tmp_filename  = $files['file']['tmp_name'];
950
                                
876
                                // $filename      = $this->normalizeString($files['file']['name']);
951
                                $tmp_filename  = $files['file']['tmp_name'];
877
                                
Línea 952... Línea 878...
952
                                // $filename      = $this->normalizeString($files['file']['name']);
878
                                try {
953
                                
879
                                    list($target_width, $target_height) = explode('x', $this->config['leaderslinked.image_sizes.microlearning_image_size']);
Línea 966... Línea 892...
966
                                }
892
                                }
Línea 967... Línea 893...
967
                                
893
                                
Línea 968... Línea 894...
968
                                break;
894
                                break;
969
                                
895
                                
970
                                
896
                                
Línea 971... Línea 897...
971
                            case CompanyMicrolearningSlide::TYPE_DOCUMENT :
897
                            case MicrolearningSlide::TYPE_DOCUMENT :
972
                                $tmp_filename       = $files['file']['tmp_name'];
898
                                $tmp_filename       = $files['file']['tmp_name'];
973
                                $original_filename  = trim(strtolower($files['file']['name']));
899
                                $original_filename  = trim(strtolower($files['file']['name']));
974
                                
900
                                
975
                                
901
                                
976
                                if($slide->file) {
902
                                if($slide->file) {
977
                                    if(!image ::delete($target_path, $slide->file)) {
903
                                    if(!$image->getStorage()->deleteFile($target_path, $slide->uuid, $slide->file)) {
Línea 985... Línea 911...
985
                                try {
911
                                try {
Línea 986... Línea 912...
986
                                    
912
                                    
987
                                    $parts = explode('.', $original_filename);
913
                                    $parts = explode('.', $original_filename);
Línea 988... Línea -...
988
                                    $filename = 'document-' . uniqid() . '.' . $parts[ count($parts) - 1 ];
-
 
989
                                    
914
                                    $filename = 'document-' . uniqid() . '.' . $parts[ count($parts) - 1 ];
990
                                    $full_filename = $target_path  . DIRECTORY_SEPARATOR .$filename;
915
                                    
991
                                    if(move_uploaded_file($tmp_filename, $full_filename)) {
916
                                    if($image->getStorage()->moveAndPutFile($target_path, $slide->uuid, $tmp_filename, $filename)) {
992
                                        $slide->file = basename($full_filename);
917
                                        $slide->file = $filename;
993
                                        $slideMapper->update($slide);
918
                                        $slideMapper->update($slide);
994
                                    }
919
                                    }
995
                                } catch(\Throwable $e) {
920
                                } catch(\Throwable $e) {
Línea 996... Línea 921...
996
                                    error_log($e->getTraceAsString());
921
                                    error_log($e->getTraceAsString());
Línea 997... Línea 922...
997
                                }
922
                                }
998
                                
923
                                
999
                                break;
924
                                break;
Línea 1000... Línea 925...
1000
                                
925
                                
Línea 1015... Línea 940...
1015
                                try {
940
                                try {
Línea 1016... Línea 941...
1016
                                    
941
                                    
1017
                                    $parts = explode('.', $original_filename);
942
                                    $parts = explode('.', $original_filename);
Línea 1018... Línea 943...
1018
                                    $filename = 'audio-' . uniqid() . '.' . $parts[ count($parts) - 1 ];
943
                                    $filename = 'audio-' . uniqid() . '.' . $parts[ count($parts) - 1 ];
1019
                                    
944
                                    
Línea 1020... Línea 945...
1020
                                    $full_filename      = $target_path  . DIRECTORY_SEPARATOR .$filename;
945
                                    $full_filename      = $image->getStorage()->getTempPath()  . DIRECTORY_SEPARATOR .$filename;
1021
                                    if(move_uploaded_file($tmp_filename , $full_filename)) {
946
                                    if(move_uploaded_file($tmp_filename , $full_filename)) {
1022
                                        
947
                                        
1023
                                        
948
                                        
Línea -... Línea 949...
-
 
949
                                        $generateFileName   = substr($filename, 0, strrpos($filename, '.')).  '.mp3';
-
 
950
                                        $generateFile       =  $image->getStorage()->getTempPath()  . DIRECTORY_SEPARATOR . $generateFileName ;
1024
                                        $generateFileName   = substr($filename, 0, strrpos($filename, '.'));
951
                                        $cmd                = "/usr/bin/ffmpeg -i $full_filename -b:a 320000 $generateFile";
1025
                                        $generateFile       =  $target_path  . DIRECTORY_SEPARATOR . $generateFileName .  '.mp3';
952
                                        exec($cmd);
-
 
953
                                        
1026
                                        $cmd                = "/usr/bin/ffmpeg -i $full_filename -b:a 320000 $generateFile";
954
                                        if($image->getStorage()->putFile($target_path, $slide->uuid, $generateFile)) {
Línea 1027... Línea 955...
1027
                                        exec($cmd);
955
                                            
1028
                                        
956
                                            $slide->file = $generateFileName;
1029
                                        $slide->file = basename($full_filename);
957
                                            $slideMapper->update($slide);
Línea 1030... Línea 958...
1030
                                        $slideMapper->update($slide);
958
                                        }
Línea 1031... Línea 959...
1031
                                    }
959
                                    }
1032
                                    
960
                                    
1033
                                } catch(\Throwable $e) {
961
                                } catch(\Throwable $e) {
Línea 1034... Línea 962...
1034
                                    error_log($e->getTraceAsString());
962
                                    error_log($e->getTraceAsString());
Línea 1094... Línea 1022...
1094
                        try {
1022
                        try {
1095
                            list($target_width, $target_height) = explode('x', $this->config['leaderslinked.image_sizes.microlearning_image_size']);
1023
                            list($target_width, $target_height) = explode('x', $this->config['leaderslinked.image_sizes.microlearning_image_size']);
Línea 1096... Línea 1024...
1096
                            
1024
                            
1097
                            $filename = 'background-' .uniqid() . '.png';
1025
                            $filename = 'background-' .uniqid() . '.png';
-
 
1026
                            $crop_to_dimensions = true;
-
 
1027
                            $unlink_source = true;
1098
                            $crop_to_dimensions = true;
1028
                            
1099
                            if(Image::uploadImage($tmp_filename, $target_path, $filename, $target_width, $target_height, $crop_to_dimensions)) {
1029
                            if($image->uploadImageChangeSize($tmp_filename, $target_path, $slide->uuid, $filename, $target_width, $target_height, $crop_to_dimensions, $unlink_source)) {
1100
                                $slide->background = $filename;
1030
                               $slide->background = $filename;
1101
                                $slideMapper->update($slide);
1031
                                $slideMapper->update($slide);
1102
                            }
1032
                            }
1103
                        } catch(\Throwable $e) {
1033
                        } catch(\Throwable $e) {
1104
                            error_log($e->getTraceAsString());
1034
                            error_log($e->getTraceAsString());
Línea 1153... Línea 1083...
1153
        $currentUserPlugin = $this->plugin('currentUserPlugin');
1083
        $currentUserPlugin = $this->plugin('currentUserPlugin');
1154
        $currentUser = $currentUserPlugin->getUser();
1084
        $currentUser = $currentUserPlugin->getUser();
1155
        $currentCompany = $currentUserPlugin->getCompany();
1085
        $currentCompany = $currentUserPlugin->getCompany();
Línea 1156... Línea 1086...
1156
        
1086
        
1157
        $request    = $this->getRequest();
-
 
1158
        $topic_uuid   = $this->params()->fromRoute('topic_uuid');
1087
        $request    = $this->getRequest();
1159
        $capsule_uuid = $this->params()->fromRoute('capsule_uuid');
1088
        $capsule_uuid = $this->params()->fromRoute('capsule_uuid');
Línea 1160... Línea -...
1160
        $slide_uuid   = $this->params()->fromRoute('slide_uuid');
-
 
1161
        
-
 
1162
        
-
 
1163
        $topicMapper = CompanyMicrolearningTopicMapper::getInstance($this->adapter);
-
 
1164
        $topic = $topicMapper->fetchOneByUuid($topic_uuid);
-
 
1165
        if(!$topic) {
-
 
1166
            return new JsonModel([
-
 
1167
                'success'   => false,
-
 
1168
                'data'   => 'ERROR_TOPIC_NOT_FOUND'
-
 
1169
            ]);
-
 
1170
        }
-
 
1171
        
-
 
1172
        if($topic->company_id != $currentCompany->id) {
-
 
1173
            return new JsonModel([
-
 
1174
                'success'   => false,
-
 
1175
                'data'   => 'ERROR_UNAUTHORIZED'
-
 
1176
            ]);
-
 
1177
        }
1089
        $slide_uuid   = $this->params()->fromRoute('slide_uuid');
1178
        
1090
        
1179
        $capsuleMapper = CompanyMicrolearningCapsuleMapper::getInstance($this->adapter);
1091
        $capsuleMapper = MicrolearningCapsuleMapper::getInstance($this->adapter);
1180
        $capsule = $capsuleMapper->fetchOneByUuid($capsule_uuid);
1092
        $capsule = $capsuleMapper->fetchOneByUuid($capsule_uuid);
1181
        if(!$capsule) {
1093
        if(!$capsule) {
1182
            return new JsonModel([
1094
            return new JsonModel([
1183
                'success'   => false,
1095
                'success'   => false,
1184
                'data'   => 'ERROR_CAPSULE_NOT_FOUND'
1096
                'data'   => 'ERROR_CAPSULE_NOT_FOUND'
Línea 1185... Línea 1097...
1185
            ]);
1097
            ]);
1186
        }
1098
        }
1187
        
1099
        
1188
        if($capsule->topic_id != $topic->id) {
1100
        if($capsule->company_id != $currentCompany->id) {
1189
            return new JsonModel([
1101
            return new JsonModel([
1190
                'success'   => false,
1102
                'success'   => false,
Línea 1191... Línea 1103...
1191
                'data'   => 'ERROR_UNAUTHORIZED'
1103
                'data'   => 'ERROR_UNAUTHORIZED'
1192
            ]);
1104
            ]);
1193
        }
1105
        }
1194
        
1106
        
1195
        
1107
        
1196
        $slideMapper = CompanyMicrolearningSlideMapper::getInstance($this->adapter);
1108
        $slideMapper = MicrolearningSlideMapper::getInstance($this->adapter);