Proyectos de Subversion LeadersLinked - Backend

Rev

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