Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 7238 | Rev 16768 | Ir a la última revisión | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 www 1
<?php
2
declare(strict_types=1);
3
 
4
namespace LeadersLinked\Controller;
5
 
6
use Laminas\Db\Adapter\AdapterInterface;
16766 efrain 7
use LeadersLinked\Cache\CacheInterface;
1 www 8
use Laminas\Mvc\Controller\AbstractActionController;
9
use Laminas\Log\LoggerInterface;
10
use Laminas\View\Model\ViewModel;
11
use Laminas\View\Model\JsonModel;
12
 
13
use LeadersLinked\Library\Functions;
14
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
15
use LeadersLinked\Library\Image;
16
 
17
 
18
use LeadersLinked\Mapper\CompanyMapper;
19
use LeadersLinked\Mapper\CompanyMicrolearningTopicMapper;
20
use LeadersLinked\Mapper\CompanyMicrolearningCapsuleMapper;
21
use LeadersLinked\Mapper\CompanyMicrolearningSlideMapper;
22
use LeadersLinked\Model\CompanyMicrolearningSlide;
23
use LeadersLinked\Model\VideoConvert;
24
use LeadersLinked\Mapper\VideoConvertMapper;
25
use LeadersLinked\Form\SlideForm;
26
use LeadersLinked\Form\SlideTextAddForm;
27
use LeadersLinked\Form\SlideTextEditForm;
28
use LeadersLinked\Form\SlideImageAddForm;
29
use LeadersLinked\Form\SlideImageEditForm;
30
use LeadersLinked\Form\SlideVideoAddForm;
31
use LeadersLinked\Form\SlideDocumentAddForm;
32
use LeadersLinked\Form\SlideDocumentEditForm;
33
use LeadersLinked\Form\SlideAudioAddForm;
34
use LeadersLinked\Form\SlideAudioEditForm;
35
use LeadersLinked\Form\SlideQuizzAddForm;
36
use LeadersLinked\Form\SlideQuizzEditForm;
37
use LeadersLinked\Form\SlideVideoEditForm;
38
 
39
 
40
class MicrolearningSlideController extends AbstractActionController
41
{
42
    /**
43
     *
44
     * @var AdapterInterface
45
     */
46
    private $adapter;
47
 
48
 
49
    /**
50
     *
16766 efrain 51
     * @var CacheInterface
1 www 52
     */
53
    private $cache;
54
 
55
    /**
56
     *
57
     * @var  LoggerInterface
58
     */
59
    private $logger;
60
 
61
 
62
    /**
63
     *
64
     * @var array
65
     */
66
    private $config;
67
 
68
    /**
69
     *
70
     * @param AdapterInterface $adapter
16766 efrain 71
     *@param CacheInterface $cache
1 www 72
     * @param LoggerInterface $logger
73
     * @param array $config
74
     */
75
    public function __construct($adapter, $cache , $logger,  $config)
76
    {
77
        $this->adapter      = $adapter;
78
        $this->cache        = $cache;
79
        $this->logger       = $logger;
80
        $this->config       = $config;
81
 
82
    }
83
 
84
    /**
85
     *
86
     * Generación del listado de perfiles
87
     * {@inheritDoc}
88
     * @see \Laminas\Mvc\Controller\AbstractActionController::indexAction()
89
     */
90
    public function indexAction()
91
    {
92
        $currentUserPlugin = $this->plugin('currentUserPlugin');
93
        $currentUser = $currentUserPlugin->getUser();
94
        $currentCompany = $currentUserPlugin->getCompany();
95
 
96
        $request = $this->getRequest();
97
        if($request->isGet()) {
98
 
99
 
100
            $headers  = $request->getHeaders();
101
 
102
            $isJson = false;
103
            if($headers->has('Accept')) {
104
                $accept = $headers->get('Accept');
105
 
106
                $prioritized = $accept->getPrioritized();
107
 
108
                foreach($prioritized as $key => $value) {
109
                    $raw = trim($value->getRaw());
110
 
111
                    if(!$isJson) {
112
                        $isJson = strpos($raw, 'json');
113
                    }
114
 
115
                }
116
            }
117
 
118
            if($isJson) {
119
 
120
 
16766 efrain 121
                $topic_uuid     = Functions::sanitizeFilterString($this->params()->fromQuery('topic_uuid'));
122
                $capsule_uuid   = Functions::sanitizeFilterString($this->params()->fromQuery('capsule_uuid'));
1 www 123
 
124
                $data = [
125
                    'link_add' => '',
126
                    'items' => [] ,
127
                    'total' => 0,
128
 
129
                ];
130
 
131
 
132
                if(!$topic_uuid) {
133
                    return new JsonModel([
134
                        'success' => true,
135
                        'data' => $data
136
                    ]);
137
 
138
                }
139
 
140
 
141
                $topicMapper = CompanyMicrolearningTopicMapper::getInstance($this->adapter);
142
                $topic = $topicMapper->fetchOneByUuid($topic_uuid);
143
                if(!$topic) {
144
                    return new JsonModel([
145
                        'success' => true,
146
                        'data' => 'ERROR_TOPIC_NOT_FOUND'
147
                    ]);
148
                }
149
 
150
                if($topic->company_id != $currentCompany->id) {
151
                    return new JsonModel([
152
                        'success' => true,
153
                        'data' => 'ERROR_UNAUTHORIZED'
154
                    ]);
155
                }
156
 
157
 
158
 
159
                if(!$capsule_uuid) {
160
                    $capsuleMapper = CompanyMicrolearningCapsuleMapper::getInstance($this->adapter);
161
                    $records = $capsuleMapper->fetchAllByCompanyIdAndTopicId($topic->company_id, $topic->id);
162
 
163
                    $capsules = [];
164
                    foreach($records as $record)
165
                    {
166
                        if(!$capsule_uuid) {
167
                            $capsule_uuid = $record->uuid;
168
                        }
169
 
170
                        $capsules[ $record->uuid ] = $record->name;
171
                    }
172
 
173
                    $data['capsules']  = $capsules;
174
                }
175
 
176
                if(!$capsule_uuid) {
177
                    return new JsonModel([
178
                        'success' => true,
179
                        'data' => $data
180
                    ]);
181
 
182
                }
183
 
184
                $capsuleMapper = CompanyMicrolearningCapsuleMapper::getInstance($this->adapter);
185
                $capsule = $capsuleMapper->fetchOneByUuid($capsule_uuid);
186
 
187
 
188
 
189
                if(!$capsule) {
190
                    return new JsonModel([
191
                        'success' => true,
192
                        'data' => 'ERROR_CAPSULE_NOT_FOUND'
193
                    ]);
194
                }
195
 
196
                if($capsule->topic_id != $topic->id) {
197
                    return new JsonModel([
198
                        'success' => true,
199
                        'data' => 'ERROR_UNAUTHORIZED'
200
                    ]);
201
                }
202
 
203
                $search = $this->params()->fromQuery('search', []);
16766 efrain 204
                $search = empty($search['value']) ? '' :  Functions::sanitizeFilterString($search['value']);
1 www 205
 
206
                $records_x_page     = intval($this->params()->fromQuery('length', 10), 10);
7065 nelberth 207
                $page               = (intval($this->params()->fromQuery('start', 1), 10)/$records_x_page)+1;
1 www 208
                $order =  $this->params()->fromQuery('order', []);
209
                $order_field        = empty($order[0]['column']) ? 99 :  intval($order[0]['column'], 10);
16766 efrain 210
                $order_direction    = empty($order[0]['dir']) ? 'ASC' : strtoupper(Functions::sanitizeFilterString($order[0]['dir']));
1 www 211
 
212
                $fields =  ['name'];
213
                $order_field = isset($fields[$order_field]) ? $fields[$order_field] : 'name';
214
 
215
                if(!in_array($order_direction, ['ASC', 'DESC'])) {
216
                    $order_direction = 'ASC';
217
                }
218
 
219
 
220
                $acl = $this->getEvent()->getViewModel()->getVariable('acl');
221
                $allowAdd = $acl->isAllowed($currentUser->usertype_id, 'microlearning/content/slides/add');
222
                $allowEdit = $acl->isAllowed($currentUser->usertype_id, 'microlearning/content/slides/edit');
223
                $allowDelete = $acl->isAllowed($currentUser->usertype_id, 'microlearning/content/slides/delete');
224
 
225
                $slideMapper = CompanyMicrolearningSlideMapper::getInstance($this->adapter);
226
                $paginator = $slideMapper->fetchAllDataTableByCompanyIdAndTopicIdAndCapsuleId($currentCompany->id, $topic->id, $capsule->id,  $search, $page, $records_x_page, $order_field, $order_direction);
227
 
228
                $records = $paginator->getCurrentItems();
229
 
230
 
231
                $items = [];
232
                foreach($records as $record)
233
                {
234
 
235
                    $params = [
236
                        'topic_uuid'    => $topic->uuid,
237
                        'capsule_uuid'  => $capsule->uuid,
238
                        'slide_uuid'    => $record->uuid,
239
 
240
                    ];
241
 
242
 
243
                    $item = [
244
 
245
                        'name' => $record->name,
246
                        'details' => [
247
                            'type' => '',
248
                         ],
249
                         'media' => [
250
                            'image' => '',
251
                            'audio' => '',
252
                            'video' => '',
253
                            'document' => '',
254
                            'text'
255
                        ],
256
 
257
                        'actions' => [
258
                            'link_edit' => $allowEdit ? $this->url()->fromRoute('microlearning/content/slides/edit', $params)  : '',
259
                            'link_delete' => $allowDelete ? $this->url()->fromRoute('microlearning/content/slides/delete', $params )  : '',
260
                         ],
261
 
262
                    ];
263
 
264
 
265
                    switch($record->type)
266
                    {
267
                        case CompanyMicrolearningSlide::TYPE_AUDIO :
268
 
269
                            $item['media']['audio'] =  $this->url()->fromRoute('storage', ['type' => 'microlearning-slide', 'code' => $record->uuid, 'filename' =>  $record->file ]);
270
                            $item['media']['image'] = $this->url()->fromRoute('storage', ['type' => 'microlearning-slide', 'code' => $record->uuid, 'filename' =>  $record->background ]);
271
                            $item['details']['type'] = 'LABEL_AUDIO';
272
                            break;
273
 
274
                        case CompanyMicrolearningSlide::TYPE_VIDEO :
275
                            $item['media']['video'] =  $this->url()->fromRoute('storage', ['type' => 'microlearning-slide', 'code' => $record->uuid, 'filename' =>  $record->file ]);
276
                            $item['media']['image'] = $this->url()->fromRoute('storage', ['type' => 'microlearning-slide', 'code' => $record->uuid, 'filename' =>  $record->background ]);
277
                            $item['details']['type'] = 'LABEL_VIDEO';
278
                            break;
279
 
280
                        case CompanyMicrolearningSlide::TYPE_DOCUMENT :
281
                            $item['media']['document'] =  $this->url()->fromRoute('storage', ['type' => 'microlearning-slide', 'code' => $record->uuid, 'filename' =>  $record->file ]);
282
                            $item['media']['image'] = $this->url()->fromRoute('storage', ['type' => 'microlearning-slide', 'code' => $record->uuid, 'filename' =>  $record->background ]);
283
                            $item['details']['type'] = 'LABEL_DOCUMENT';
284
                            break;
285
 
286
                        case CompanyMicrolearningSlide::TYPE_TEXT :
287
                            $item['media']['image'] = $this->url()->fromRoute('storage', ['type' => 'microlearning-slide', 'code' => $record->uuid, 'filename' =>  $record->background ]);
288
                            $item['media']['text'] = $this->url()->fromRoute('microlearning/content/slides/text', $params);
289
                            $item['details']['type'] = 'LABEL_TEXT';
290
                            break;
291
 
292
                        case CompanyMicrolearningSlide::TYPE_QUIZ :
293
                            $item['media']['image'] = $this->url()->fromRoute('storage', ['type' => 'microlearning-slide', 'code' => $record->uuid, 'filename' =>  $record->background ]);
294
                            $item['details']['type'] = 'LABEL_QUIZ';
295
                            break;
296
 
297
                        case CompanyMicrolearningSlide::TYPE_IMAGE :
298
                            $item['media']['image'] = $this->url()->fromRoute('storage', ['type' => 'microlearning-slide', 'code' => $record->uuid, 'filename' =>  $record->file ]);
299
                            $item['details']['type'] = 'LABEL_IMAGE';
300
                            break;
301
 
302
                    }
303
 
304
 
305
                    array_push($items, $item);
306
 
307
                }
308
 
309
                if($allowAdd && $topic && $capsule) {
310
                    $data['link_add'] = $this->url()->fromRoute('microlearning/content/slides/add', ['topic_uuid' => $topic->uuid, 'capsule_uuid' => $capsule->uuid ]);
311
                }
312
                $data['items'] = $items;
313
                $data['total'] = $paginator->getTotalItemCount();
314
 
315
                return new JsonModel([
316
                    'success' => true,
317
                    'data' => $data
318
                ]);
319
 
320
            } else {
321
                $image_size = $this->config['leaderslinked.image_sizes.microlearning_image_upload'];
322
 
323
                $topicMapper = CompanyMicrolearningTopicMapper::getInstance($this->adapter);
324
                $topics = $topicMapper->fetchAllByCompanyId($currentCompany->id);
325
 
326
                if($topics) {
327
                    $topic_id = $topics[0]->id;
328
                }  else {
329
                    $topic_id = 0;
330
                }
331
 
332
 
333
                $form = new SlideForm($this->adapter,  $currentCompany->id, $topic_id);
334
                $formTextAdd = new SlideTextAddForm();
335
                $formTextEdit = new SlideTextEditForm();
336
                $formImageAdd = new SlideImageAddForm();
337
                $formImageEdit = new SlideImageEditForm();
338
                $formVideoAdd = new SlideVideoAddForm();
339
                $formVideoEdit = new SlideVideoEditForm();
340
                $formDocumentAdd = new SlideDocumentAddForm();
341
                $formDocumentEdit = new SlideDocumentEditForm();
342
                $formAudioAdd = new SlideAudioAddForm();
343
                $formAudioEdit = new SlideAudioEditForm();
344
                $formQuizzAdd = new SlideQuizzAddForm($this->adapter, $currentCompany->id);
345
                $formQuizzEdit = new SlideQuizzEditForm($this->adapter, $currentCompany->id);
346
 
347
                $this->layout()->setTemplate('layout/layout-backend.phtml');
348
                $viewModel = new ViewModel();
349
                $viewModel->setTemplate('leaders-linked/microlearning-slides/index.phtml');
350
                $viewModel->setVariables([
351
                    'form' => $form,
352
                    'formTextAdd' => $formTextAdd,
353
                    'formTextEdit' => $formTextEdit,
354
                    'formImageAdd' => $formImageAdd,
355
                    'formImageEdit' => $formImageEdit,
356
                    'formVideoAdd' => $formVideoAdd,
357
                    'formVideoEdit' => $formVideoEdit,
358
                    'formDocumentAdd' => $formDocumentAdd,
359
                    'formDocumentEdit' => $formDocumentEdit,
360
                    'formAudioAdd' => $formAudioAdd,
361
                    'formAudioEdit' => $formAudioEdit,
362
                    'formQuizzAdd' => $formQuizzAdd,
363
                    'formQuizzEdit' => $formQuizzEdit,
364
                    'image_size' => $image_size,
365
 
366
                ]);
367
                return $viewModel ;
368
            }
369
        }
370
 
371
        return new JsonModel([
372
            'success' => false,
373
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
374
        ]);
375
 
376
 
377
 
378
 
379
 
380
 
381
 
382
    }
383
 
384
    public function addAction()
385
    {
386
 
387
        $currentUserPlugin = $this->plugin('currentUserPlugin');
388
        $currentUser = $currentUserPlugin->getUser();
389
        $currentCompany = $currentUserPlugin->getCompany();
390
 
391
        $request    = $this->getRequest();
392
        $topic_uuid   = $this->params()->fromRoute('topic_uuid');
393
        $capsule_uuid = $this->params()->fromRoute('capsule_uuid');
394
 
395
 
396
 
397
        $topicMapper = CompanyMicrolearningTopicMapper::getInstance($this->adapter);
398
        $topic = $topicMapper->fetchOneByUuid($topic_uuid);
399
        if(!$topic) {
400
            return new JsonModel([
401
                'success'   => false,
402
                'data'   => 'ERROR_TOPIC_NOT_FOUND'
403
            ]);
404
        }
405
 
406
        if($topic->company_id != $currentCompany->id) {
407
            return new JsonModel([
408
                'success'   => false,
409
                'data'   => 'ERROR_UNAUTHORIZED'
410
            ]);
411
        }
412
 
413
 
414
        $capsuleMapper = CompanyMicrolearningCapsuleMapper::getInstance($this->adapter);
415
        $capsule = $capsuleMapper->fetchOneByUuid($capsule_uuid);
416
        if(!$capsule) {
417
            return new JsonModel([
418
                'success'   => false,
419
                'data'   => 'ERROR_CAPSULE_NOT_FOUND'
420
            ]);
421
        }
422
 
423
        if($capsule->topic_id != $topic->id) {
424
            return new JsonModel([
425
                'success'   => false,
426
                'data'   => 'ERROR_UNAUTHORIZED'
427
            ]);
428
        }
429
 
430
 
431
        if($request->isPost()) {
432
 
433
            $dataPost = array_merge($request->getPost()->toArray(), $request->getFiles()->toArray());
434
 
435
            switch($dataPost['type'])
436
            {
437
                case CompanyMicrolearningSlide::TYPE_AUDIO :
438
                    $form = new SlideAudioAddForm();
439
                    break;
440
 
441
                case CompanyMicrolearningSlide::TYPE_VIDEO :
442
                    $form = new SlideVideoAddForm();
443
                    break;
444
 
445
                case CompanyMicrolearningSlide::TYPE_DOCUMENT:
446
                    $form = new SlideDocumentAddForm();
447
                    break;
448
 
449
                case CompanyMicrolearningSlide::TYPE_IMAGE :
450
                    $form = new SlideImageAddForm();
451
                    break;
452
 
453
 
454
                case CompanyMicrolearningSlide::TYPE_QUIZ:
455
                    $form = new SlideQuizzAddForm($this->adapter, $currentCompany->id);
456
                    break;
457
 
458
                default :
459
                    $form = new SlideTextAddForm();
460
                    break;
461
            }
462
 
463
            $form->setData($dataPost);
464
 
465
            if($form->isValid()) {
466
                $dataPost = (array) $form->getData();
467
 
468
                $hydrator = new ObjectPropertyHydrator();
469
                $slide = new CompanyMicrolearningSlide();
470
                $hydrator->hydrate($dataPost, $slide);
471
 
472
                $slide->company_id = $topic->company_id;
473
                $slide->topic_id = $topic->id;
474
                $slide->capsule_id = $capsule->id;
475
                $slide->file = null;
476
                $slide->background = null;
6194 nelberth 477
 
1 www 478
                $slideMapper = CompanyMicrolearningSlideMapper::getInstance($this->adapter);
479
                if($slideMapper->insert($slide)) {
480
                    $slide = $slideMapper->fetchOne($slide->id);
481
 
482
                    $files = $this->getRequest()->getFiles()->toArray();
6196 nelberth 483
 
6498 nelberth 484
 
6196 nelberth 485
 
486
                    if($slide->type == CompanyMicrolearningSlide::TYPE_IMAGE) {
6498 nelberth 487
                        $fileBase64Content = $this->params()->fromPost('file');
6197 nelberth 488
 
489
                        try {
490
 
491
                            $fileBase64Content = base64_decode($fileBase64Content);
7115 nelberth 492
                            $filename      = 'slide-' .uniqid() . '.jpg';
6204 nelberth 493
                            $tmp_filename = 'data' . DIRECTORY_SEPARATOR . 'tmp';
494
                            $target_path = $this->config['leaderslinked.fullpath.microlearning_slide'] .  $slide->uuid;
495
                            if(!file_exists($target_path)) {
496
                                mkdir($target_path, 0755, true);
6197 nelberth 497
                            }
6204 nelberth 498
                            $tmp_filename = 'data' . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR . $filename;
499
                                file_put_contents($tmp_filename, $fileBase64Content);
6197 nelberth 500
 
501
                            list($target_width, $target_height) = explode('x', $this->config['leaderslinked.image_sizes.microlearning_image_size']);
502
 
6204 nelberth 503
                            $crop_to_dimensions = true;
504
                            if(Image::uploadImage($tmp_filename, $target_path, $filename, $target_width, $target_height, $crop_to_dimensions )) {
505
                                $slide->file = basename($filename);
506
                                $slideMapper->update($slide);
6197 nelberth 507
                            }
508
                        } catch(\Throwable $e) {
509
                            error_log($e->getTraceAsString());
6499 nelberth 510
                        }
6196 nelberth 511
 
512
                    }
513
 
514
 
515
 
516
 
1 www 517
                    $target_path = $this->config['leaderslinked.fullpath.microlearning_slide'] .  $slide->uuid;
518
                    if(!file_exists($target_path)) {
519
                        mkdir($target_path, 0755, true);
520
                    }
521
 
522
 
523
                    if(isset($files['file']) && empty($files['file']['error'])) {
524
                        $tmp_filename       = $files['file']['tmp_name'];
525
                        $original_filename  = trim(strtolower($files['file']['name']));
526
 
527
 
528
 
529
 
530
 
531
                        if($slide->file) {
532
                            if(!image ::delete($target_path, $slide->file)) {
533
                                return new JsonModel([
534
                                    'success'   => false,
535
                                    'data'   =>  'ERROR_THERE_WAS_AN_ERROR'
536
                                ]);
537
                            }
538
                        }
539
 
540
                        if($slide->type == CompanyMicrolearningSlide::TYPE_DOCUMENT) {
541
                            try {
542
 
543
                                $parts = explode('.', $original_filename);
544
                                $filename = 'document-' . uniqid() . '.' . $parts[ count($parts) - 1 ];
545
 
546
                                $full_filename = $target_path  . DIRECTORY_SEPARATOR .$filename;
547
                                if(move_uploaded_file($tmp_filename, $full_filename)) {
548
                                    $slide->file = basename($full_filename);
549
                                    $slideMapper->update($slide);
550
                                }
551
                            } catch(\Throwable $e) {
552
                                error_log($e->getTraceAsString());
553
                            }
554
                        }
555
 
556
                        if($slide->type == CompanyMicrolearningSlide::TYPE_AUDIO) {
557
                            try {
558
 
559
                                $parts = explode('.', $original_filename);
560
                                $filename = 'audio-' . uniqid() . '.' . $parts[ count($parts) - 1 ];
561
 
562
                                $full_filename      = $target_path  . DIRECTORY_SEPARATOR .$filename;
563
                                if(move_uploaded_file($tmp_filename , $full_filename)) {
564
 
565
 
566
                                    $generateFileName   = substr($filename, 0, strrpos($filename, '.'));
567
                                    $generateFile       =  $target_path  . DIRECTORY_SEPARATOR . $generateFileName .  '.mp3';
568
                                    $cmd                = "/usr/bin/ffmpeg -i $full_filename -b:a 320000 $generateFile";
569
                                    exec($cmd);
570
 
571
                                    $slide->file = basename($full_filename);
572
                                    $slideMapper->update($slide);
573
                                }
574
 
575
                            } catch(\Throwable $e) {
576
                                error_log($e->getTraceAsString());
577
                            }
578
                        }
579
 
580
                        if($slide->type == CompanyMicrolearningSlide::TYPE_VIDEO) {
581
                            try {
582
                                $parts = explode('.', $original_filename);
583
                                $filename = 'video-' . uniqid() . '.' . $parts[ count($parts) - 1 ];
584
 
585
                                $full_filename      = $target_path  . DIRECTORY_SEPARATOR .$filename;
586
 
587
                                if(move_uploaded_file($tmp_filename , $full_filename)) {
588
 
589
                                    $videoConvert = new VideoConvert();
590
                                    $videoConvert->filename = $full_filename;
591
                                    $videoConvert->type = VideoConvert::TYPE_MICRO_LEARNING;
592
 
593
                                    $videoConvertMapper = VideoConvertMapper::getInstance($this->adapter);
594
                                    $videoConvertMapper->insert($videoConvert);
595
 
596
                                    $slide->file = basename($full_filename);
597
                                    $slideMapper->update($slide);
598
                                }
599
 
600
                            } catch(\Throwable $e) {
601
                                echo $e->getMessage();
602
 
603
                                error_log($e->getTraceAsString());
604
                            }
605
                        }
606
 
6187 nelberth 607
 
1 www 608
                    }
6594 nelberth 609
 
610
                        $fileBase64Content = $this->params()->fromPost('background');
611
                        $target_path = $this->config['leaderslinked.fullpath.microlearning_slide'] .  $slide->uuid;
612
                        if($slide->background) {
613
                            if(!image ::delete($target_path, $slide->background)) {
614
                                return new JsonModel([
615
                                    'success'   => false,
616
                                    'data'   =>  'ERROR_THERE_WAS_AN_ERROR'
617
                                ]);
618
                            }
619
                        }
620
 
621
                        try {
622
 
623
                            $fileBase64Content = base64_decode($fileBase64Content);
7115 nelberth 624
                            $filename      = 'background-' .uniqid() . '.jpg';
6594 nelberth 625
                            $tmp_filename = 'data' . DIRECTORY_SEPARATOR . 'tmp';
626
                            if(!file_exists($target_path)) {
627
                                mkdir($target_path, 0755, true);
628
                            }
629
                            $tmp_filename = 'data' . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR . $filename;
630
                                file_put_contents($tmp_filename, $fileBase64Content);
631
 
632
                            list($target_width, $target_height) = explode('x', $this->config['leaderslinked.image_sizes.microlearning_image_size']);
633
 
634
                            $crop_to_dimensions = true;
635
                            if(Image::uploadImage($tmp_filename, $target_path, $filename, $target_width, $target_height, $crop_to_dimensions )) {
636
                                $slide->background = basename($filename);
637
                                $slideMapper->update($slide);
638
                            }
639
                        } catch(\Throwable $e) {
640
                            error_log($e->getTraceAsString());
641
                        }
642
 
1 www 643
 
6594 nelberth 644
                    /*if(isset($files['background']) && empty($files['background']['error'])) {
1 www 645
                        if($slide->background) {
646
                            if(!image ::delete($target_path, $slide->background)) {
647
                                return new JsonModel([
648
                                    'success'   => false,
649
                                    'data'   =>  'ERROR_THERE_WAS_AN_ERROR'
650
                                ]);
651
                            }
652
                        }
653
 
654
                        $tmp_filename  = $files['background']['tmp_name'];
655
 
656
                        try {
657
                            list($target_width, $target_height) = explode('x', $this->config['leaderslinked.image_sizes.microlearning_image_size']);
658
 
659
                            $filename = 'background-' .uniqid() . '.png';
660
                            $crop_to_dimensions = true;
661
                            if(Image::uploadImage($tmp_filename, $target_path, $filename, $target_width, $target_height, $crop_to_dimensions)) {
662
                                $slide->background = $filename;
663
                                $slideMapper->update($slide);
664
                            }
665
                        } catch(\Throwable $e) {
666
                            error_log($e->getTraceAsString());
667
                        }
6594 nelberth 668
                    }*/
1 www 669
 
670
                    $this->logger->info('Se agrego la diapositiva ' . $slide->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
671
 
672
                    $data = [
673
                        'success'   => true,
674
                        'data'   => 'LABEL_RECORD_ADDED'
675
                    ];
676
                } else {
677
                    $data = [
678
                        'success'   => false,
679
                        'data'      => $topicMapper->getError()
680
                    ];
681
 
682
                }
683
 
684
                return new JsonModel($data);
685
 
686
            } else {
687
                $messages = [];
688
                $form_messages = (array) $form->getMessages();
689
                foreach($form_messages  as $fieldname => $field_messages)
690
                {
691
 
692
                    $messages[$fieldname] = array_values($field_messages);
693
                }
694
 
695
                return new JsonModel([
696
                    'success'   => false,
697
                    'data'   => $messages
698
                ]);
699
            }
700
 
701
        } else {
702
            $data = [
703
                'success' => false,
704
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
705
            ];
706
 
707
            return new JsonModel($data);
708
        }
709
 
710
        return new JsonModel($data);
711
    }
712
 
713
    /**
714
     *
715
     * Borrar un perfil excepto el público
716
     * @return \Laminas\View\Model\JsonModel
717
     */
718
    public function deleteAction()
719
    {
720
        $currentUserPlugin = $this->plugin('currentUserPlugin');
721
        $currentUser = $currentUserPlugin->getUser();
722
        $currentCompany = $currentUserPlugin->getCompany();
723
 
724
        $request    = $this->getRequest();
725
        $topic_uuid   = $this->params()->fromRoute('topic_uuid');
726
        $capsule_uuid = $this->params()->fromRoute('capsule_uuid');
727
        $slide_uuid = $this->params()->fromRoute('slide_uuid');
728
 
729
 
730
 
731
        $topicMapper = CompanyMicrolearningTopicMapper::getInstance($this->adapter);
732
        $topic = $topicMapper->fetchOneByUuid($topic_uuid);
733
        if(!$topic) {
734
            return new JsonModel([
735
                'success'   => false,
736
                'data'   => 'ERROR_TOPIC_NOT_FOUND'
737
            ]);
738
        }
739
 
740
        if($topic->company_id != $currentCompany->id) {
741
            return new JsonModel([
742
                'success'   => false,
743
                'data'   => 'ERROR_UNAUTHORIZED'
744
            ]);
745
        }
746
 
747
        $capsuleMapper = CompanyMicrolearningCapsuleMapper::getInstance($this->adapter);
748
        $capsule = $capsuleMapper->fetchOneByUuid($capsule_uuid);
749
        if(!$capsule) {
750
            return new JsonModel([
751
                'success'   => false,
752
                'data'   => 'ERROR_CAPSULE_NOT_FOUND'
753
            ]);
754
        }
755
 
756
        if($capsule->topic_id != $topic->id) {
757
            return new JsonModel([
758
                'success'   => false,
759
                'data'   => 'ERROR_UNAUTHORIZED'
760
            ]);
761
        }
762
 
763
        $slideMapper = CompanyMicrolearningSlideMapper::getInstance($this->adapter);
764
        $slide = $slideMapper->fetchOneByUuid($slide_uuid);
765
        if(!$slide) {
766
            return new JsonModel([
767
                'success'   => false,
768
                'data'   => 'ERROR_SLIDE_NOT_FOUND'
769
            ]);
770
        }
771
 
772
        if($slide->capsule_id != $capsule->id) {
773
            return new JsonModel([
774
                'success'   => false,
775
                'data'   => 'ERROR_UNAUTHORIZED'
776
            ]);
777
        }
778
 
779
        if($request->isPost()) {
780
 
781
            $result =  $slideMapper->delete($slide);
782
            if($result) {
783
                $this->logger->info('Se borro la diapositiva : ' .  $capsule->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
784
                try {
785
                    $target_path = $this->config['leaderslinked.fullpath.microlearning_slide'] . $slide->uuid;
786
                    if(file_exists($target_path)) {
787
                        Functions::rmDirRecursive($target_path);
788
                    }
789
                } catch(\Throwable $e) {
790
                    error_log($e->getTraceAsString());
791
                }
792
 
793
 
794
                $data = [
795
                    'success' => true,
796
                    'data' => 'LABEL_RECORD_DELETED'
797
                ];
798
            } else {
799
 
800
                $data = [
801
                    'success'   => false,
802
                    'data'      => $capsuleMapper->getError()
803
                ];
804
 
805
                return new JsonModel($data);
806
            }
807
 
808
        } else {
809
            $data = [
810
                'success' => false,
811
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
812
            ];
813
 
814
            return new JsonModel($data);
815
        }
816
 
817
        return new JsonModel($data);
818
    }
819
 
820
 
821
    public function editAction()
822
    {
823
        $currentUserPlugin = $this->plugin('currentUserPlugin');
824
        $currentUser = $currentUserPlugin->getUser();
825
        $currentCompany = $currentUserPlugin->getCompany();
826
 
827
        $request    = $this->getRequest();
828
        $topic_uuid   = $this->params()->fromRoute('topic_uuid');
829
        $capsule_uuid = $this->params()->fromRoute('capsule_uuid');
830
        $slide_uuid   = $this->params()->fromRoute('slide_uuid');
831
 
832
 
833
        $topicMapper = CompanyMicrolearningTopicMapper::getInstance($this->adapter);
834
        $topic = $topicMapper->fetchOneByUuid($topic_uuid);
835
        if(!$topic) {
836
            return new JsonModel([
837
                'success'   => false,
838
                'data'   => 'ERROR_TOPIC_NOT_FOUND'
839
            ]);
840
        }
841
 
842
        if($topic->company_id != $currentCompany->id) {
843
            return new JsonModel([
844
                'success'   => false,
845
                'data'   => 'ERROR_UNAUTHORIZED'
846
            ]);
847
        }
848
 
849
        $capsuleMapper = CompanyMicrolearningCapsuleMapper::getInstance($this->adapter);
850
        $capsule = $capsuleMapper->fetchOneByUuid($capsule_uuid);
851
        if(!$capsule) {
852
            return new JsonModel([
853
                'success'   => false,
854
                'data'   => 'ERROR_CAPSULE_NOT_FOUND'
855
            ]);
856
        }
857
 
858
        if($capsule->topic_id != $topic->id) {
859
            return new JsonModel([
860
                'success'   => false,
861
                'data'   => 'ERROR_UNAUTHORIZED'
862
            ]);
863
        }
864
 
865
 
866
        $slideMapper = CompanyMicrolearningSlideMapper::getInstance($this->adapter);
867
        $slide = $slideMapper->fetchOneByUuid($slide_uuid);
868
        if(!$slide) {
869
            return new JsonModel([
870
                'success'   => false,
871
                'data'   => 'ERROR_SLIDE_NOT_FOUND'
872
            ]);
873
        }
874
 
875
        if($slide->capsule_id != $capsule->id) {
876
            return new JsonModel([
877
                'success'   => false,
878
                'data'   => 'ERROR_UNAUTHORIZED'
879
            ]);
880
        }
881
 
882
        if($request->isGet()) {
6647 nelberth 883
            $sliderFile='';
6648 nelberth 884
            if($slide->type=='image'){
6647 nelberth 885
                $sliderFile=$this->url()->fromRoute('storage', ['type' => 'microlearning-slide', 'code' => $slide->uuid, 'filename' => $slide->file]);
886
            }
1 www 887
            $data = [
888
                'success' => true,
889
                'data' => [
890
                    'name' => $slide->name,
891
                    'type' => $slide->type,
892
                    'description' => $slide->description,
893
                    'order' => $slide->order,
6509 nelberth 894
                    'quiz_id' => $slide->quiz_id,
6647 nelberth 895
                    'file'=> $sliderFile,
6595 nelberth 896
                    'background' =>$this->url()->fromRoute('storage', ['type' => 'microlearning-slide', 'code' => $slide->uuid, 'filename' => $slide->background]),
1 www 897
                ]
898
            ];
899
 
900
            return new JsonModel($data);
901
        }
902
        else if($request->isPost()) {
903
            $dataPost = array_merge($request->getPost()->toArray(), $request->getFiles()->toArray());
904
 
905
            switch($dataPost['type'])
906
            {
907
                case CompanyMicrolearningSlide::TYPE_AUDIO :
908
                    $form = new SlideAudioEditForm();
909
                    break;
910
 
911
                case CompanyMicrolearningSlide::TYPE_VIDEO :
912
                    $form = new SlideVideoEditForm();
913
                    break;
914
 
915
                case CompanyMicrolearningSlide::TYPE_DOCUMENT:
916
                    $form = new SlideDocumentEditForm();
917
                    break;
918
 
919
                case CompanyMicrolearningSlide::TYPE_IMAGE :
920
                    $form = new SlideImageEditForm();
921
                    break;
922
 
923
                case CompanyMicrolearningSlide::TYPE_QUIZ:
924
                    $form = new SlideQuizzEditForm($this->adapter, $currentCompany->id);
925
                    break;
926
 
927
                default :
928
                    $form = new SlideTextEditForm();
929
                    break;
930
 
931
            }
932
            $form->setData($dataPost);
933
 
934
            if($form->isValid()) {
935
                $dataPost = (array) $form->getData();
936
                $hydrator = new ObjectPropertyHydrator();
937
                $hydrator->hydrate($dataPost, $slide);
938
 
939
                $slide->file = null;
940
                $slide->background = null;
941
 
942
                if($slideMapper->update($slide)) {
943
                    $slide = $slideMapper->fetchOne($slide->id);
944
 
945
 
946
                    $target_path = $this->config['leaderslinked.fullpath.microlearning_slide'] .  $slide->uuid;
947
                    if(!file_exists($target_path)) {
948
                        mkdir($target_path, 0755, true);
949
                    }
950
 
951
                    $files = $this->getRequest()->getFiles()->toArray();
6520 nelberth 952
 
953
                    if($slide->type == CompanyMicrolearningSlide::TYPE_IMAGE) {
954
                            $fileBase64Content = $this->params()->fromPost('file');
955
 
956
                        try {
7238 nelberth 957
 
958
                            $target_path = $this->config['leaderslinked.fullpath.microlearning_slide'] .  $slide->uuid;
7236 nelberth 959
                            if($slide->file) {
960
                                if(!image ::delete($target_path, $slide->file)) {
961
                                    return new JsonModel([
962
                                        'success'   => false,
963
                                        'data'   =>  'ERROR_THERE_WAS_AN_ERROR'
964
                                    ]);
965
                                }
966
                            }
6520 nelberth 967
                            $fileBase64Content = base64_decode($fileBase64Content);
968
                            $filename      = 'slide-' .uniqid() . '.png';
969
                            $tmp_filename = 'data' . DIRECTORY_SEPARATOR . 'tmp';
970
                            if(!file_exists($target_path)) {
971
                                mkdir($target_path, 0755, true);
972
                            }
973
                            $tmp_filename = 'data' . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR . $filename;
974
                                file_put_contents($tmp_filename, $fileBase64Content);
975
 
976
                            list($target_width, $target_height) = explode('x', $this->config['leaderslinked.image_sizes.microlearning_image_size']);
977
 
978
                            $crop_to_dimensions = true;
979
                            if(Image::uploadImage($tmp_filename, $target_path, $filename, $target_width, $target_height, $crop_to_dimensions )) {
980
                                $slide->file = basename($filename);
981
                                $slideMapper->update($slide);
982
                            }
983
                        } catch(\Throwable $e) {
984
                            error_log($e->getTraceAsString());
985
                        }
986
                        /*
987
                        try {
988
                            list($target_width, $target_height) = explode('x', $this->config['leaderslinked.image_sizes.microlearning_image_size']);
989
 
990
                            $filename = 'slide-' .uniqid() . '.png';
991
                            $crop_to_dimensions = true;
992
                            if(Image::uploadImage($tmp_filename, $target_path, $filename, $target_width, $target_height, $crop_to_dimensions)) {
993
                                $slide->file = $filename;
994
                                $slideMapper->update($slide);
995
                            }
996
                        } catch(\Throwable $e) {
997
                            error_log($e->getTraceAsString());
998
                        }*/
999
                    }
1000
 
1 www 1001
                    if(isset($files['file']) && empty($files['file']['error'])) {
1002
                        $tmp_filename       = $files['file']['tmp_name'];
1003
                        $original_filename  = trim(strtolower($files['file']['name']));
1004
 
1005
 
1006
                        if($slide->file) {
1007
                            if(!image ::delete($target_path, $slide->file)) {
1008
                                return new JsonModel([
1009
                                    'success'   => false,
1010
                                    'data'   =>  'ERROR_THERE_WAS_AN_ERROR'
1011
                                ]);
1012
                            }
1013
                        }
1014
 
1015
                        if($slide->type == CompanyMicrolearningSlide::TYPE_DOCUMENT) {
1016
                            try {
1017
 
1018
                                $parts = explode('.', $original_filename);
1019
                                $filename = 'document-' . uniqid() . '.' . $parts[ count($parts) - 1 ];
1020
 
1021
                                $full_filename = $target_path  . DIRECTORY_SEPARATOR .$filename;
1022
                                if(move_uploaded_file($tmp_filename, $full_filename)) {
1023
                                    $slide->file = basename($full_filename);
1024
                                    $slideMapper->update($slide);
1025
                                }
1026
                            } catch(\Throwable $e) {
1027
                                error_log($e->getTraceAsString());
1028
                            }
1029
                        }
1030
 
1031
                        if($slide->type == CompanyMicrolearningSlide::TYPE_AUDIO) {
1032
                            try {
1033
 
1034
                                $parts = explode('.', $original_filename);
1035
                                $filename = 'audio-' . uniqid() . '.' . $parts[ count($parts) - 1 ];
1036
 
1037
                                $full_filename      = $target_path  . DIRECTORY_SEPARATOR .$filename;
1038
                                if(move_uploaded_file($tmp_filename , $full_filename)) {
1039
 
1040
 
1041
                                    $generateFileName   = substr($filename, 0, strrpos($filename, '.'));
1042
                                    $generateFile       =  $target_path  . DIRECTORY_SEPARATOR . $generateFileName .  '.mp3';
1043
                                    $cmd                = "/usr/bin/ffmpeg -i $full_filename -b:a 320000 $generateFile";
1044
                                    exec($cmd);
1045
 
1046
                                    $slide->file = basename($full_filename);
1047
                                    $slideMapper->update($slide);
1048
                                }
1049
 
1050
                            } catch(\Throwable $e) {
1051
                                error_log($e->getTraceAsString());
1052
                            }
1053
                        }
1054
 
1055
                        if($slide->type == CompanyMicrolearningSlide::TYPE_VIDEO) {
1056
                            try {
1057
                                $parts = explode('.', $original_filename);
1058
                                $filename = 'video-' . uniqid() . '.' . $parts[ count($parts) - 1 ];
1059
 
1060
                                $full_filename      = $target_path  . DIRECTORY_SEPARATOR .$filename;
1061
 
1062
                                if(move_uploaded_file($tmp_filename , $full_filename)) {
1063
 
1064
                                    $videoConvert = new VideoConvert();
1065
                                    $videoConvert->filename = $full_filename;
1066
                                    $videoConvert->type = VideoConvert::TYPE_MICRO_LEARNING;
1067
 
1068
                                    $videoConvertMapper = VideoConvertMapper::getInstance($this->adapter);
1069
                                    $videoConvertMapper->insert($videoConvert);
1070
 
1071
                                    $slide->file = basename($full_filename);
1072
                                    $slideMapper->update($slide);
1073
                                }
1074
 
1075
                            } catch(\Throwable $e) {
1076
                                echo $e->getMessage();
1077
 
1078
                                error_log($e->getTraceAsString());
1079
                            }
1080
                        }
1081
 
6520 nelberth 1082
 
1 www 1083
                    }
6595 nelberth 1084
                    $fileBase64Content = $this->params()->fromPost('background');
1085
                        $target_path = $this->config['leaderslinked.fullpath.microlearning_slide'] .  $slide->uuid;
1086
                        if($slide->background) {
1087
                            if(!image ::delete($target_path, $slide->background)) {
1088
                                return new JsonModel([
1089
                                    'success'   => false,
1090
                                    'data'   =>  'ERROR_THERE_WAS_AN_ERROR'
1091
                                ]);
1092
                            }
1093
                        }
6594 nelberth 1094
 
6595 nelberth 1095
                        try {
1096
 
1097
                            $fileBase64Content = base64_decode($fileBase64Content);
1098
                            $filename      = 'background-' .uniqid() . '.png';
1099
                            $tmp_filename = 'data' . DIRECTORY_SEPARATOR . 'tmp';
1100
                            if(!file_exists($target_path)) {
1101
                                mkdir($target_path, 0755, true);
1102
                            }
1103
                            $tmp_filename = 'data' . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR . $filename;
1104
                                file_put_contents($tmp_filename, $fileBase64Content);
1105
 
1106
                            list($target_width, $target_height) = explode('x', $this->config['leaderslinked.image_sizes.microlearning_image_size']);
1107
 
1108
                            $crop_to_dimensions = true;
1109
                            if(Image::uploadImage($tmp_filename, $target_path, $filename, $target_width, $target_height, $crop_to_dimensions )) {
1110
                                $slide->background = basename($filename);
1111
                                $slideMapper->update($slide);
1112
                            }
1113
                        } catch(\Throwable $e) {
1114
                            error_log($e->getTraceAsString());
1115
                        }
1 www 1116
 
6594 nelberth 1117
                    /*
1 www 1118
                    if(isset($files['background']) && empty($files['background']['error'])) {
1119
                        if($slide->background) {
1120
                            if(!image ::delete($target_path, $slide->background)) {
1121
                                return new JsonModel([
1122
                                    'success'   => false,
1123
                                    'data'   =>  'ERROR_THERE_WAS_AN_ERROR'
1124
                                ]);
1125
                            }
1126
                        }
1127
 
1128
                        $tmp_filename  = $files['background']['tmp_name'];
1129
 
1130
                        try {
1131
                            list($target_width, $target_height) = explode('x', $this->config['leaderslinked.image_sizes.microlearning_image_size']);
1132
 
1133
                            $filename = 'background-' .uniqid() . '.png';
1134
                            $crop_to_dimensions = true;
1135
                            if(Image::uploadImage($tmp_filename, $target_path, $filename, $target_width, $target_height, $crop_to_dimensions)) {
1136
                                $slide->background = $filename;
1137
                                $slideMapper->update($slide);
1138
                            }
1139
                        } catch(\Throwable $e) {
1140
                            error_log($e->getTraceAsString());
1141
                        }
6594 nelberth 1142
                    }*/
1 www 1143
 
1144
                    $this->logger->info('Se edito la diapositiva ' . $slide->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
1145
 
1146
                    $data = [
1147
                        'success'   => true,
1148
                        'data'   => 'LABEL_RECORD_UPDATED'
1149
                    ];
1150
                } else {
1151
                    $data = [
1152
                        'success'   => false,
1153
                        'data'      => $capsuleMapper->getError()
1154
                    ];
1155
 
1156
                }
1157
 
1158
                return new JsonModel($data);
1159
 
1160
            } else {
1161
                $messages = [];
1162
                $form_messages = (array) $form->getMessages();
1163
                foreach($form_messages  as $fieldname => $field_messages)
1164
                {
1165
 
1166
                    $messages[$fieldname] = array_values($field_messages);
1167
                }
1168
 
1169
                return new JsonModel([
1170
                    'success'   => false,
1171
                    'data'   => $messages
1172
                ]);
1173
            }
1174
        } else {
1175
            $data = [
1176
                'success' => false,
1177
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
1178
            ];
1179
 
1180
            return new JsonModel($data);
1181
        }
1182
 
1183
        return new JsonModel($data);
1184
    }
1185
 
1186
 
1187
    public function textAction()
1188
    {
1189
        $currentUserPlugin = $this->plugin('currentUserPlugin');
1190
        $currentUser = $currentUserPlugin->getUser();
1191
        $currentCompany = $currentUserPlugin->getCompany();
1192
 
1193
        $request    = $this->getRequest();
1194
        $topic_uuid   = $this->params()->fromRoute('topic_uuid');
1195
        $capsule_uuid = $this->params()->fromRoute('capsule_uuid');
1196
        $slide_uuid   = $this->params()->fromRoute('slide_uuid');
1197
 
1198
 
1199
        $topicMapper = CompanyMicrolearningTopicMapper::getInstance($this->adapter);
1200
        $topic = $topicMapper->fetchOneByUuid($topic_uuid);
1201
        if(!$topic) {
1202
            return new JsonModel([
1203
                'success'   => false,
1204
                'data'   => 'ERROR_TOPIC_NOT_FOUND'
1205
            ]);
1206
        }
1207
 
1208
        if($topic->company_id != $currentCompany->id) {
1209
            return new JsonModel([
1210
                'success'   => false,
1211
                'data'   => 'ERROR_UNAUTHORIZED'
1212
            ]);
1213
        }
1214
 
1215
        $capsuleMapper = CompanyMicrolearningCapsuleMapper::getInstance($this->adapter);
1216
        $capsule = $capsuleMapper->fetchOneByUuid($capsule_uuid);
1217
        if(!$capsule) {
1218
            return new JsonModel([
1219
                'success'   => false,
1220
                'data'   => 'ERROR_CAPSULE_NOT_FOUND'
1221
            ]);
1222
        }
1223
 
1224
        if($capsule->topic_id != $topic->id) {
1225
            return new JsonModel([
1226
                'success'   => false,
1227
                'data'   => 'ERROR_UNAUTHORIZED'
1228
            ]);
1229
        }
1230
 
1231
 
1232
        $slideMapper = CompanyMicrolearningSlideMapper::getInstance($this->adapter);
1233
        $slide = $slideMapper->fetchOneByUuid($slide_uuid);
1234
        if(!$slide) {
1235
            return new JsonModel([
1236
                'success'   => false,
1237
                'data'   => 'ERROR_SLIDE_NOT_FOUND'
1238
            ]);
1239
        }
1240
 
1241
        if($slide->capsule_id != $capsule->id) {
1242
            return new JsonModel([
1243
                'success'   => false,
1244
                'data'   => 'ERROR_UNAUTHORIZED'
1245
            ]);
1246
        }
1247
 
1248
        if($request->isGet()) {
1249
            $data = [
1250
                'success' => true,
1251
                'data' => $slide->description,
1252
            ];
1253
 
1254
            return new JsonModel($data);
1255
 
1256
        } else {
1257
            $data = [
1258
                'success' => false,
1259
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
1260
            ];
1261
 
1262
            return new JsonModel($data);
1263
        }
1264
 
1265
        return new JsonModel($data);
1266
    }
1267
 
1268
 
1269
 
1270
 
1271
 
1272
}