Proyectos de Subversion LeadersLinked - Backend

Rev

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

Rev 16945 Rev 17002
Línea 11... Línea 11...
11
use Laminas\View\Model\JsonModel;
11
use Laminas\View\Model\JsonModel;
Línea 12... Línea 12...
12
 
12
 
13
use LeadersLinked\Library\Functions;
13
use LeadersLinked\Library\Functions;
14
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
14
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
15
use LeadersLinked\Library\Image;
15
use LeadersLinked\Library\Image;
16
use LeadersLinked\Mapper\CompanyMicrolearningTopicMapper;
16
use LeadersLinked\Mapper\MicrolearningTopicMapper;
17
use LeadersLinked\Mapper\CompanyMicrolearningCapsuleMapper;
17
use LeadersLinked\Mapper\MicrolearningCapsuleMapper;
18
use LeadersLinked\Model\CompanyMicrolearningCapsule;
18
use LeadersLinked\Model\MicrolearningCapsule;
19
use LeadersLinked\Form\CapsuleAddForm;
19
use LeadersLinked\Form\Microlearning\CapsuleAddForm;
20
use LeadersLinked\Form\CapsuleEditForm;
20
use LeadersLinked\Form\Microlearning\CapsuleEditForm;
21
use LeadersLinked\Mapper\CompanyMicrolearningCapsuleUserMapper;
21
use LeadersLinked\Mapper\MicrolearningCapsuleUserMapper;
22
use LeadersLinked\Form\CapsuleForm;
22
use LeadersLinked\Form\Microlearning\CapsuleForm;
23
use LeadersLinked\Mapper\QueryMapper;
23
use LeadersLinked\Mapper\QueryMapper;
24
use LeadersLinked\Mapper\UserMapper;
24
use LeadersLinked\Mapper\UserMapper;
-
 
25
use LeadersLinked\Model\MicrolearningCapsuleUser;
Línea 25... Línea 26...
25
use LeadersLinked\Model\CompanyMicrolearningCapsuleUser;
26
use LeadersLinked\Library\Storage;
26
 
27
 
27
class MicrolearningCapsuleController extends AbstractActionController
28
class MicrolearningCapsuleController extends AbstractActionController
28
{
29
{
Línea 115... Línea 116...
115
                }
116
                }
116
            }
117
            }
Línea 117... Línea 118...
117
            
118
            
Línea 118... Línea -...
118
            if($isJson) {
-
 
119
                
-
 
120
 
-
 
121
                $topic_uuid = Functions::sanitizeFilterString($this->params()->fromQuery('topic_uuid')); 
-
 
122
            
-
 
123
                $topicMapper = CompanyMicrolearningTopicMapper::getInstance($this->adapter);
-
 
124
                $topic = $topicMapper->fetchOneByUuid($topic_uuid);
-
 
125
                
-
 
126
                if(!$topic) {
-
 
127
                    return new JsonModel([
-
 
128
                       'success' => false, 
-
 
129
                       'data' => 'ERROR_TOPIC_NOT_FOUND'
-
 
130
                    ]); 
-
 
131
                   
-
 
132
                }
-
 
133
                
-
 
134
                if($topic->company_id != $currentCompany->id) {
-
 
135
                    return new JsonModel([
-
 
136
                        'success'   => false,
-
 
137
                        'data'   => 'ERROR_UNAUTHORIZED'
-
 
Línea 138... Línea 119...
138
                    ]);
119
            if($isJson) {
139
                }
120
                
Línea 140... Línea 121...
140
                
121
                
Línea 160... Línea 141...
160
                $allowAdd = $acl->isAllowed($currentUser->usertype_id, 'microlearning/content/capsules/add');
141
                $allowAdd = $acl->isAllowed($currentUser->usertype_id, 'microlearning/content/capsules/add');
161
                $allowEdit = $acl->isAllowed($currentUser->usertype_id, 'microlearning/content/capsules/edit');
142
                $allowEdit = $acl->isAllowed($currentUser->usertype_id, 'microlearning/content/capsules/edit');
162
                $allowDelete = $acl->isAllowed($currentUser->usertype_id, 'microlearning/content/capsules/delete');
143
                $allowDelete = $acl->isAllowed($currentUser->usertype_id, 'microlearning/content/capsules/delete');
163
                $allowUsers = $acl->isAllowed($currentUser->usertype_id, 'microlearning/content/capsules/users');
144
                $allowUsers = $acl->isAllowed($currentUser->usertype_id, 'microlearning/content/capsules/users');
Línea 164... Línea 145...
164
           
145
           
165
                $capsuleMapper = CompanyMicrolearningCapsuleMapper::getInstance($this->adapter);
146
                $capsuleMapper = MicrolearningCapsuleMapper::getInstance($this->adapter);
Línea 166... Línea 147...
166
                $paginator = $capsuleMapper->fetchAllDataTableByCompanyIdAndTopicId($topic->company_id, $topic->id, $search, $page, $records_x_page, $order_field, $order_direction);
147
                $paginator = $capsuleMapper->fetchAllDataTableByCompanyId($currentCompany->id, $search, $page, $records_x_page, $order_field, $order_direction);
167
                
148
                
Línea -... Línea 149...
-
 
149
                
-
 
150
                $microlearningCapsuleUserMapper = MicrolearningCapsuleUserMapper::getInstance($this->adapter);
-
 
151
                 $records = $paginator->getCurrentItems(); 
Línea 168... Línea 152...
168
                
152
            
169
                $companyMicrolearningCapsuleUserMapper = CompanyMicrolearningCapsuleUserMapper::getInstance($this->adapter);
153
                 $storage = Storage::getInstance($this->config);
170
                 $records = $paginator->getCurrentItems(); 
154
                 $path = $storage->getPathMicrolearningCapsule();
171
            
-
 
172
 
-
 
173
                $items = [];
-
 
174
                foreach($records as $record)
155
                 
175
                {
156
 
176
                    
-
 
177
                    //print_r($record); 
-
 
Línea 178... Línea 157...
178
                    
157
                $items = [];
179
                    $total_users        = $companyMicrolearningCapsuleUserMapper->fetchCountUsersByCompanyIdAndTopicIdAndCapsuleId($topic->company_id, $topic->id, $record->id);
158
                foreach($records as $record)
180
                    $total_users_active = $companyMicrolearningCapsuleUserMapper->fetchCountUsersActiveByCompanyIdAndTopicIdAndCapsuleId($topic->company_id, $topic->id, $record->id);
159
                {
181
                    
160
                    $total_users        = $microlearningCapsuleUserMapper->fetchCountUsersByCompanyIdAndCapsuleId($currentCompany->id,  $record->id);
Línea 182... Línea 161...
182
            
161
                    $total_users_active = $microlearningCapsuleUserMapper->fetchCountUsersActiveByCompanyIdAndCapsuleId($currentCompany->id, $record->id);
183
                    
162
                    
184
                    switch($record->status) {
163
                    switch($record->status) {
Línea 185... Línea 164...
185
                        case  CompanyMicrolearningCapsule::STATUS_ACTIVE :
164
                        case  MicrolearningCapsule::STATUS_ACTIVE :
186
                            $status = 'LABEL_ACTIVE';
165
                            $status = 'LABEL_ACTIVE';
187
                            break;
166
                            break;
188
                            
167
                            
Línea 189... Línea 168...
189
                        case  CompanyMicrolearningCapsule::STATUS_INACTIVE :
168
                        case  MicrolearningCapsule::STATUS_INACTIVE :
190
                            $status = 'LABEL_INACTIVE';
169
                            $status = 'LABEL_INACTIVE';
191
                            break;
170
                            break;
192
                            
171
                            
Línea 193... Línea 172...
193
                        default : 
172
                        default : 
194
                            $status = '';
173
                            $status = '';
195
                            break;
174
                            break;
Línea 196... Línea 175...
196
                    }
175
                    }
197
                    
176
                    
198
                    
177
                    
199
                    switch($record->privacy) {
178
                    switch($record->privacy) {
Línea 200... Línea 179...
200
                        case  CompanyMicrolearningCapsule::PRIVACY_PUBLIC :
179
                        case  MicrolearningCapsule::PRIVACY_PUBLIC :
201
                            $privacy = 'LABEL_PUBLIC';
180
                            $privacy = 'LABEL_PUBLIC';
202
                            break;
181
                            break;
203
                            
182
                            
Línea 204... Línea 183...
204
                        case  CompanyMicrolearningCapsule::PRIVACY_PRIVATE :
183
                        case  MicrolearningCapsule::PRIVACY_PRIVATE :
205
                            $privacy = 'LABEL_PRIVATE';
184
                            $privacy = 'LABEL_PRIVATE';
206
                            break;
185
                            break;
Línea 207... Línea 186...
207
                            
186
                            
208
                        default :
187
                        default :
209
                            $privacy = '';
188
                            $privacy = '';
Línea 210... Línea 189...
210
                            break;
189
                            break;
211
                    }
190
                    }
212
                    
191
                    
213
                    switch($record->type) {
192
                    switch($record->type) {
Línea 214... Línea 193...
214
                        case  CompanyMicrolearningCapsule::TYPE_FREE :
193
                        case  MicrolearningCapsule::TYPE_FREE :
215
                            $type = 'LABEL_FREE';
-
 
216
                            break;
194
                            $type = 'LABEL_FREE';
217
                            
195
                            break;
Línea 218... Línea 196...
218
                        case  CompanyMicrolearningCapsule::TYPE_PRIVATE :
196
                            
Línea 246... Línea 224...
246
                            'total_users' => $total_users,
224
                            'total_users' => $total_users,
247
                            'total_users_active' => $total_users_active,
225
                            'total_users_active' => $total_users_active,
248
                         ],    
226
                         ],    
Línea 249... Línea 227...
249
         
227
         
250
                        'images' => [
228
                        'images' => [
251
                            'image' => $this->url()->fromRoute('storage', ['type' => 'microlearning-capsule', 'code' => $record->uuid, 'filename' => $record->image]),
229
                            'image' =>  $storage->getGenericImage($path, $record->uuid, $record->image),
252
                            'marketplace' => $record->marketplace ?  $this->url()->fromRoute('storage', ['type' => 'microlearning-capsule', 'code' => $record->uuid, 'filename' => $record->marketplace]) : '',
230
                            'marketplace' => $record->marketplace ?  $storage->getGenericImage($path, $record->uuid, $record->marketplace) : '',
253
                        ] ,
231
                        ] ,
254
                        'actions' => [ 
232
                        'actions' => [ 
255
                            'link_edit' => $allowEdit ? $this->url()->fromRoute('microlearning/content/capsules/edit', $params)  : '', 
233
                            'link_edit' => $allowEdit ? $this->url()->fromRoute('microlearning/content/capsules/edit', $params)  : '', 
256
                            'link_delete' => $allowDelete ? $this->url()->fromRoute('microlearning/content/capsules/delete', $params)  : '', 
234
                            'link_delete' => $allowDelete ? $this->url()->fromRoute('microlearning/content/capsules/delete', $params)  : '', 
257
                            'link_total_users' => $allowUsers && $total_users ? $this->url()->fromRoute('microlearning/content/capsules/users', [
-
 
258
                                'topic_uuid'    => $topic->uuid,
235
                            'link_total_users' => $allowUsers && $total_users ? $this->url()->fromRoute('microlearning/content/capsules/users', [
259
                                'capsule_uuid'  => $record->uuid,
236
                                'capsule_uuid'  => $record->uuid,
260
                                'type' => 'all'
237
                                'type' => 'all'
261
                             ])  : '',
238
                             ])  : '',
262
                            'link_total_users_actives' => $allowUsers && $total_users_active ? $this->url()->fromRoute('microlearning/content/capsules/users', [
-
 
263
                                'topic_uuid'    => $topic->uuid,
239
                            'link_total_users_actives' => $allowUsers && $total_users_active ? $this->url()->fromRoute('microlearning/content/capsules/users', [
264
                                'capsule_uuid'  => $record->uuid,
240
                                'capsule_uuid'  => $record->uuid,
265
                                'type' => 'active'
241
                                'type' => 'active'
266
                            ])  : '', 
242
                            ])  : '', 
Línea 276... Línea 252...
276
 
252
 
277
                
253
                
278
                return new JsonModel([
254
                return new JsonModel([
279
                    'success' => true,
255
                    'success' => true,
280
                    'data' => [
256
                    'data' => [
281
                        'link_add' => $allowAdd ? $this->url()->fromRoute('microlearning/content/capsules/add', ['topic_uuid' => $topic->uuid] )  : '', 
257
                        'link_add' => $allowAdd ? $this->url()->fromRoute('microlearning/content/capsules/add' )  : '', 
282
                        'items' => $items,
258
                        'items' => $items,
283
                        'total' => $paginator->getTotalItemCount(),
259
                        'total' => $paginator->getTotalItemCount(),
Línea 328... Línea 304...
328
        $currentCompany     = $currentUserPlugin->getCompany();
304
        $currentCompany     = $currentUserPlugin->getCompany();
Línea 329... Línea 305...
329
        
305
        
330
        $request    = $this->getRequest();
306
        $request    = $this->getRequest();
Línea 331... Línea 307...
331
        $topic_uuid = $this->params()->fromRoute('topic_uuid');
307
        $topic_uuid = $this->params()->fromRoute('topic_uuid');
332
        
308
        
333
        $topicMapper = CompanyMicrolearningTopicMapper::getInstance($this->adapter);
309
        $topicMapper = MicrolearningTopicMapper::getInstance($this->adapter);
334
        $topic = $topicMapper->fetchOneByUuid($topic_uuid);
310
        $topic = $topicMapper->fetchOneByUuid($topic_uuid);
335
        if(!$topic) {
311
        if(!$topic) {
336
            return new JsonModel([
312
            return new JsonModel([
Línea 352... Línea 328...
352
            $dataPost = array_merge($request->getPost()->toArray(), $request->getFiles()->toArray());
328
            $dataPost = array_merge($request->getPost()->toArray(), $request->getFiles()->toArray());
Línea 353... Línea 329...
353
            
329
            
Línea 354... Línea 330...
354
            $form->setData($dataPost);
330
            $form->setData($dataPost);
-
 
331
            
-
 
332
            if($form->isValid()) {
-
 
333
                $image = Image::getInstance($this->config);
-
 
334
                $target_path = $image->getStorage()->getPathMicrolearningCapsule();
-
 
335
                
355
            
336
                
Línea 356... Línea 337...
356
            if($form->isValid()) {
337
                
357
                $dataPost = (array) $form->getData();
338
                $dataPost = (array) $form->getData();
358
                
339
                
Línea 359... Línea 340...
359
                $hydrator = new ObjectPropertyHydrator();
340
                $hydrator = new ObjectPropertyHydrator();
360
                $capsule = new CompanyMicrolearningCapsule();
-
 
361
                $hydrator->hydrate($dataPost, $capsule);
341
                $capsule = new MicrolearningCapsule();
362
                
342
                $hydrator->hydrate($dataPost, $capsule);
Línea 363... Línea 343...
363
                $capsule->company_id = $topic->company_id;
343
                
364
                $capsule->topic_id = $topic->id;
344
                $capsule->company_id = $topic->company_id;
Línea 365... Línea 345...
365
                $capsule->image = '';
345
                $capsule->image = '';
Línea 366... Línea -...
366
                $capsule->marketplace = '';
-
 
367
                
-
 
368
                $capsuleMapper = CompanyMicrolearningCapsuleMapper::getInstance($this->adapter);
-
 
369
                if($capsuleMapper->insert($capsule)) {
-
 
370
                    
-
 
371
                    $capsule = $capsuleMapper->fetchOne($capsule->id);
346
                $capsule->marketplace = '';
372
                    
347
                
373
                    $target_path = $this->config['leaderslinked.fullpath.microlearning_capsule'] .  $capsule->uuid;
348
                $capsuleMapper = MicrolearningCapsuleMapper::getInstance($this->adapter);
374
                    if(!file_exists($target_path)) {
349
                if($capsuleMapper->insert($capsule)) {
Línea 375... Línea 350...
375
                        mkdir($target_path, 0755, true);
350
                    
376
                    }
351
                    $capsule = $capsuleMapper->fetchOne($capsule->id);
Línea 377... Línea 352...
377
     
352
                    
378
                    $files = $this->getRequest()->getFiles()->toArray();
353
                    $files = $this->getRequest()->getFiles()->toArray();
-
 
354
                    if(isset($files['file']) && empty($files['file']['error'])) {
-
 
355
                        $tmp_filename  = $files['file']['tmp_name'];
379
                    if(isset($files['file']) && empty($files['file']['error'])) {
356
                        // $filename      = $this->normalizeString($files['file']['name']);
380
                        $tmp_filename  = $files['file']['tmp_name'];
357
                        
381
                        // $filename      = $this->normalizeString($files['file']['name']);
358
                        try {
382
                        
359
                            list($target_width, $target_height) = explode('x', $this->config['leaderslinked.image_sizes.microlearning_image_size']);
383
                        try {
360
                            
384
                            list($target_width, $target_height) = explode('x', $this->config['leaderslinked.image_sizes.microlearning_image_size']);
361
                            $filename = 'capsule-' .uniqid() . '.jpg';
Línea 401... Línea 378...
401
                        try {
378
                        try {
402
                        list($target_width, $target_height) = explode('x', $this->config['leaderslinked.image_sizes.marketplace']);
379
                        list($target_width, $target_height) = explode('x', $this->config['leaderslinked.image_sizes.marketplace']);
Línea 403... Línea 380...
403
                            
380
                            
404
                            $filename = 'marketplace-' .uniqid() . '.jpg';
381
                            $filename = 'marketplace-' .uniqid() . '.jpg';
-
 
382
                            $crop_to_dimensions = false;
-
 
383
                            $unlink_source = true;
405
                            $crop_to_dimensions = false;
384
                            
406
                            if(Image::uploadImage($tmp_filename, $target_path, $filename, $target_width, $target_height, $crop_to_dimensions)) {
385
                            if($image->uploadImageChangeSize($tmp_filename, $target_path, $capsule->uuid, $filename, $target_width, $target_height, $crop_to_dimensions, $unlink_source)) {
407
                                $capsule->marketplace = $filename;
386
                                $capsule->marketplace = $filename;
408
                                $capsuleMapper->update($capsule);
387
                                $capsuleMapper->update($capsule);
409
                            }
388
                            }
410
                        } catch(\Throwable $e) {
389
                        } catch(\Throwable $e) {
Línea 470... Línea 449...
470
        $request        = $this->getRequest();
449
        $request        = $this->getRequest();
471
        $topic_uuid     = $this->params()->fromRoute('topic_uuid');
450
        $topic_uuid     = $this->params()->fromRoute('topic_uuid');
472
        $capsule_uuid   = $this->params()->fromRoute('capsule_uuid');
451
        $capsule_uuid   = $this->params()->fromRoute('capsule_uuid');
Línea 473... Línea 452...
473
        
452
        
474
 
453
 
475
        $topicMapper = CompanyMicrolearningTopicMapper::getInstance($this->adapter);
454
        $topicMapper = MicrolearningTopicMapper::getInstance($this->adapter);
476
        $topic = $topicMapper->fetchOneByUuid($topic_uuid);
455
        $topic = $topicMapper->fetchOneByUuid($topic_uuid);
477
        if(!$topic) {
456
        if(!$topic) {
478
            return new JsonModel([
457
            return new JsonModel([
Línea 486... Línea 465...
486
                'success'   => false,
465
                'success'   => false,
487
                'data'   => 'ERROR_UNAUTHORIZED'
466
                'data'   => 'ERROR_UNAUTHORIZED'
488
            ]);
467
            ]);
489
        }
468
        }
Línea 490... Línea 469...
490
        
469
        
491
        $capsuleMapper = CompanyMicrolearningCapsuleMapper::getInstance($this->adapter);
470
        $capsuleMapper = MicrolearningCapsuleMapper::getInstance($this->adapter);
492
        $capsule = $capsuleMapper->fetchOneByUuid($capsule_uuid);
471
        $capsule = $capsuleMapper->fetchOneByUuid($capsule_uuid);
493
        if(!$capsule) {
472
        if(!$capsule) {
494
            return new JsonModel([
473
            return new JsonModel([
495
                'success'   => false,
474
                'success'   => false,
496
                'data'   => 'ERROR_CAPSULE_NOT_FOUND'
475
                'data'   => 'ERROR_CAPSULE_NOT_FOUND'
497
            ]);
476
            ]);
Línea 498... Línea 477...
498
        }
477
        }
499
        
478
        
500
        if($capsule->topic_id != $topic->id) {
479
        if($capsule->company_id != $currentCompany->id) {
501
            return new JsonModel([
480
            return new JsonModel([
502
                'success'   => false,
481
                'success'   => false,
503
                'data'   => 'ERROR_UNAUTHORIZED'
482
                'data'   => 'ERROR_UNAUTHORIZED'
Línea 507... Línea 486...
507
        if($request->isPost()) {
486
        if($request->isPost()) {
Línea 508... Línea 487...
508
            
487
            
509
            $result =  $capsuleMapper->delete($capsule);
488
            $result =  $capsuleMapper->delete($capsule);
510
            if($result) {
489
            if($result) {
511
                $this->logger->info('Se borro la cápsula : ' .  $capsule->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
-
 
512
                try {
-
 
513
                    $target_path = $this->config['leaderslinked.fullpath.microlearning_capsule'] . $capsule->uuid;
-
 
514
                    if(file_exists($target_path)) {
-
 
515
                        Functions::rmDirRecursive($target_path);
-
 
516
                    }
-
 
517
                } catch(\Throwable $e) {
-
 
518
                    error_log($e->getTraceAsString());
-
 
-
 
490
                $this->logger->info('Se borro la cápsula : ' .  $capsule->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
Línea -... Línea 491...
-
 
491
               
-
 
492
                
Línea -... Línea 493...
-
 
493
                $storage = Storage::getInstance($this->config);
-
 
494
                $target_path = $storage->getPathMicrolearningCapsule();
-
 
495
                
-
 
496
                $storage->deleteFile($target_path, $capsule->uuid, $capsule->image);
-
 
497
                
-
 
498
                if($capsule->marketplace) {
-
 
499
                
519
                }
500
                    $storage->deleteFile($target_path, $topic->uuid, $capsule->marketplace);
520
                
501
                }
521
                
502
 
522
                $data = [
503
                $data = [
523
                    'success' => true,
504
                    'success' => true,
Línea 555... Línea 536...
555
        $request    = $this->getRequest();
536
        $request    = $this->getRequest();
556
        $topic_uuid     = $this->params()->fromRoute('topic_uuid');
537
        $topic_uuid     = $this->params()->fromRoute('topic_uuid');
557
        $capsule_uuid   = $this->params()->fromRoute('capsule_uuid');
538
        $capsule_uuid   = $this->params()->fromRoute('capsule_uuid');
Línea 558... Línea 539...
558
        
539
        
559
        
540
        
560
        $topicMapper = CompanyMicrolearningTopicMapper::getInstance($this->adapter);
541
        $topicMapper = MicrolearningTopicMapper::getInstance($this->adapter);
561
        $topic = $topicMapper->fetchOneByUuid($topic_uuid);
542
        $topic = $topicMapper->fetchOneByUuid($topic_uuid);
562
        if(!$topic) {
543
        if(!$topic) {
563
            return new JsonModel([
544
            return new JsonModel([
Línea 573... Línea 554...
573
                'success'   => false,
554
                'success'   => false,
574
                'data'   => 'ERROR_UNAUTHORIZED'
555
                'data'   => 'ERROR_UNAUTHORIZED'
575
            ]);
556
            ]);
576
        }
557
        }
Línea 577... Línea 558...
577
        
558
        
578
        $capsuleMapper = CompanyMicrolearningCapsuleMapper::getInstance($this->adapter);
559
        $capsuleMapper = MicrolearningCapsuleMapper::getInstance($this->adapter);
579
        $capsule = $capsuleMapper->fetchOneByUuid($capsule_uuid);
560
        $capsule = $capsuleMapper->fetchOneByUuid($capsule_uuid);
580
        if(!$capsule) {
561
        if(!$capsule) {
581
            return new JsonModel([
562
            return new JsonModel([
582
                'success'   => false,
563
                'success'   => false,
583
                'data'   => 'ERROR_CAPSULE_NOT_FOUND'
564
                'data'   => 'ERROR_CAPSULE_NOT_FOUND'
584
            ]);
565
            ]);
Línea 585... Línea 566...
585
        }
566
        }
586
        
567
        
587
 
568
 
588
        if($capsule->topic_id != $topic->id) {
569
        if($capsule->company_id != $currentCompany->id) {
589
            return new JsonModel([
570
            return new JsonModel([
590
                'success'   => false,
571
                'success'   => false,
Línea 591... Línea 572...
591
                'data'   => 'ERROR_UNAUTHORIZED'
572
                'data'   => 'ERROR_UNAUTHORIZED'
-
 
573
            ]);
-
 
574
        }
-
 
575
        
-
 
576
        if($request->isGet()) {
592
            ]);
577
            $storage = Storage::getInstance($this->config);
593
        }
578
            $path = $storage->getPathMicrolearningCapsule();
594
        
579
            
595
        if($request->isGet()) {
580
            
596
            $data = [
581
            $data = [
597
                'success' => true,
-
 
598
                'data' => [
582
                'success' => true,
599
                    'name' => $capsule->name,
583
                'data' => [
600
                    'description' => $capsule->description,
584
                    'name' => $capsule->name,
601
                    'order' => $capsule->order,
585
                    'description' => $capsule->description,
602
                    'status' => $capsule->status,
586
                    'status' => $capsule->status,
603
                    'privacy' => $capsule->privacy,
587
                    'privacy' => $capsule->privacy,
Línea 604... Línea 588...
604
                    'type' => $capsule->type,
588
                    'type' => $capsule->type,
605
                    'cost' => $capsule->cost,
589
                    'cost' => $capsule->cost,
Línea 606... Línea 590...
606
                    'image' => $this->url()->fromRoute('storage', ['type' => 'microlearning-capsule', 'code' => $capsule->uuid, 'filename' => $capsule->image]),
590
                    'image' => $storage->getGenericImage($path, $capsule->uuid, $capsule->image),
Línea 624... Línea 608...
624
                $hydrator->hydrate($dataPost, $capsule);
608
                $hydrator->hydrate($dataPost, $capsule);
Línea 625... Línea 609...
625
                
609
                
626
                $capsule->image = null;
610
                $capsule->image = null;
Línea -... Línea 611...
-
 
611
                $capsule->marketplace = null;
-
 
612
                
-
 
613
                $image = Image::getInstance($this->config);
627
                $capsule->marketplace = null;
614
                $target_path = $image->getStorage()->getPathMicrolearningCapsule();
Línea 628... Línea 615...
628
                
615
                
Línea 629... Línea 616...
629
                if($capsuleMapper->update($capsule)) {
616
                if($capsuleMapper->update($capsule)) {
630
                    
-
 
631
                    $capsule = $capsuleMapper->fetchOne($capsule->id);
-
 
632
                    
-
 
633
                    $files = $this->getRequest()->getFiles()->toArray();
-
 
-
 
617
                    
Línea 634... Línea 618...
634
                    $target_path = $this->config['leaderslinked.fullpath.microlearning_capsule'] .  $capsule->uuid;
618
                    $capsule = $capsuleMapper->fetchOne($capsule->id);
635
                    if(!file_exists($target_path)) {
619
                    
636
                        mkdir($target_path, 0755, true);
620
                    $files = $this->getRequest()->getFiles()->toArray();
Línea 637... Línea 621...
637
                    }
621
            
638
                    
622
                    
Línea 639... Línea 623...
639
                    if(isset($files['file']) && empty($files['file']['error'])) {
623
                    if(isset($files['file']) && empty($files['file']['error'])) {
640
                        $tmp_filename  = $files['file']['tmp_name'];
624
                        $tmp_filename  = $files['file']['tmp_name'];
641
                        // $filename      = $this->normalizeString($files['file']['name']);
625
                        // $filename      = $this->normalizeString($files['file']['name']);
642
                        
626
                        
643
                        try {
627
                        try {
644
                            if($capsule->image) {
628
                            if($capsule->image) {
Línea 654... Línea 638...
654
                            
638
                            
Línea 655... Línea 639...
655
                            list($target_width, $target_height) = explode('x', $this->config['leaderslinked.image_sizes.microlearning_image_size']);
639
                            list($target_width, $target_height) = explode('x', $this->config['leaderslinked.image_sizes.microlearning_image_size']);
656
                            
640
                            
-
 
641
                            $filename = 'capsule-' .uniqid() . '.jpg';
-
 
642
                            $crop_to_dimensions = false;
657
                            $filename = 'capsule-' .uniqid() . '.jpg';
643
                            $unlink_source = true;
-
 
644
                            
658
                            $crop_to_dimensions = false;
645
                            if($image->uploadImageChangeSize($tmp_filename, $target_path, $capsule->uuid, $filename, $target_width, $target_height, $crop_to_dimensions, $unlink_source)) {
659
                            if(Image::uploadImage($tmp_filename, $target_path, $filename, $target_width, $target_height, $crop_to_dimensions)) {
646
        
660
                                $capsule->image = $filename;
647
                                $capsule->image = $filename;
661
                                $capsuleMapper->update($capsule);
648
                                $capsuleMapper->update($capsule);
662
                            }
649
                            }
Línea 671... Línea 658...
671
                        
658
                        
672
                        $tmp_filename  = $files['marketplace']['tmp_name'];
659
                        $tmp_filename  = $files['marketplace']['tmp_name'];
Línea 673... Línea 660...
673
                        // $filename      = $this->normalizeString($files['file']['name']);
660
                        // $filename      = $this->normalizeString($files['file']['name']);
674
                        
661
                        
Línea 675... Línea 662...
675
                        try {
662
                        try {
676
                            if($capsule->image) {
663
                            if($capsule->marketplace) {
677
                                
664
                                
678
                                if(!image ::delete($target_path, $capsule->marketplace)) {
665
                                if(!$image->getStorage()->deleteFile($target_path, $capsule->uuid, $capsule->marketplace)) {
679
                                    return new JsonModel([
666
                                    return new JsonModel([
680
                                        'success'   => false,
667
                                        'success'   => false,
Línea 685... Línea 672...
685
                            
672
                            
Línea 686... Línea 673...
686
                            list($target_width, $target_height) = explode('x', $this->config['leaderslinked.image_sizes.marketplace']);
673
                            list($target_width, $target_height) = explode('x', $this->config['leaderslinked.image_sizes.marketplace']);
687
                            
674
                            
-
 
675
                            $filename = 'marketplace-' .uniqid() . '.jpg';
-
 
676
                            $crop_to_dimensions = false;
688
                            $filename = 'marketplace-' .uniqid() . '.jpg';
677
                            $unlink_source = true;
-
 
678
                            
689
                            $crop_to_dimensions = false;
679
                            if($image->uploadImageChangeSize($tmp_filename, $target_path, $capsule->uuid, $filename, $target_width, $target_height, $crop_to_dimensions, $unlink_source)) {
690
                            if(Image::uploadImage($tmp_filename, $target_path, $filename, $target_width, $target_height, $crop_to_dimensions)) {
680
                         
691
                                $capsule->marketplace = $filename;
681
                                $capsule->marketplace = $filename;
692
                                $capsuleMapper->update($capsule);
682
                                $capsuleMapper->update($capsule);
693
                            }
683
                            }
Línea 752... Línea 742...
752
        $topic_uuid     = $this->params()->fromRoute('topic_uuid');
742
        $topic_uuid     = $this->params()->fromRoute('topic_uuid');
753
        $capsule_uuid   = $this->params()->fromRoute('capsule_uuid');
743
        $capsule_uuid   = $this->params()->fromRoute('capsule_uuid');
754
        $type           = $this->params()->fromRoute('type'); 
744
        $type           = $this->params()->fromRoute('type'); 
Línea 755... Línea -...
755
        
-
 
756
        
-
 
757
        $topicMapper = CompanyMicrolearningTopicMapper::getInstance($this->adapter);
-
 
758
        $topic = $topicMapper->fetchOneByUuid($topic_uuid);
-
 
759
        if(!$topic) {
-
 
760
            return new JsonModel([
-
 
761
                'success'   => false,
-
 
762
                'data'   => 'ERROR_TOPIC_NOT_FOUND'
-
 
763
            ]);
745
        
764
        }
-
 
765
        
-
 
766
        if($topic->company_id != $currentCompany->id) {
-
 
767
            return new JsonModel([
-
 
768
                'success'   => false,
-
 
769
                'data'   => 'ERROR_UNAUTHORIZED'
-
 
Línea 770... Línea 746...
770
            ]);
746
        
771
        }
747
       
772
        
748
        
773
        $capsuleMapper = CompanyMicrolearningCapsuleMapper::getInstance($this->adapter);
749
        $capsuleMapper = MicrolearningCapsuleMapper::getInstance($this->adapter);
774
        $capsule = $capsuleMapper->fetchOneByUuid($capsule_uuid);
750
        $capsule = $capsuleMapper->fetchOneByUuid($capsule_uuid);
775
        if(!$capsule) {
751
        if(!$capsule) {
776
            return new JsonModel([
752
            return new JsonModel([
777
                'success'   => false,
753
                'success'   => false,
Línea 778... Línea 754...
778
                'data'   => 'ERROR_CAPSULE_NOT_FOUND'
754
                'data'   => 'ERROR_CAPSULE_NOT_FOUND'
779
            ]);
755
            ]);
780
        }
756
        }
781
        
757
        
782
        if($capsule->topic_id != $topic->id) {
758
        if($capsule->company_id != $currentCompany->id) {
783
            return new JsonModel([
759
            return new JsonModel([
Línea 791... Línea 767...
791
 
767
 
792
            $queryMapper = QueryMapper::getInstance($this->adapter);
768
            $queryMapper = QueryMapper::getInstance($this->adapter);
793
            $sql = $queryMapper->getSql();
769
            $sql = $queryMapper->getSql();
794
            $select = $sql->select();
770
            $select = $sql->select();
795
            $select->columns(['access', 'paid_from', 'paid_to', 'added_on']);
771
            $select->columns(['access', 'paid_from', 'paid_to', 'added_on']);
796
            $select->from(['tb1' => CompanyMicrolearningCapsuleUserMapper::_TABLE] );
772
            $select->from(['tb1' => MicrolearningCapsuleUserMapper::_TABLE] );
797
            $select->join(['tb2' => UserMapper::_TABLE], 'tb1.user_id = tb2.id', ['uuid', 'first_name', 'last_name', 'email']);
773
            $select->join(['tb2' => UserMapper::_TABLE], 'tb1.user_id = tb2.id', ['uuid', 'first_name', 'last_name', 'email']);
798
            $select->where->equalTo('tb1.company_id', $capsule->company_id);
-
 
799
            $select->where->equalTo('tb1.topic_id', $capsule->topic_id);
774
            $select->where->equalTo('tb1.company_id', $capsule->company_id);
Línea 800... Línea 775...
800
            $select->where->equalTo('tb1.capsule_id', $capsule->id);
775
            $select->where->equalTo('tb1.capsule_id', $capsule->id);
801
            
776
            
802
            if($type == 'active') {
777
            if($type == 'active') {
803
                $now = date('Y-m-d H:i:s');
778
                $now = date('Y-m-d H:i:s');
804
                $select->where->nest->equalTo('access', CompanyMicrolearningCapsuleUser::ACCESS_UNLIMITED)->or->nest()
779
                $select->where->nest->equalTo('access', MicrolearningCapsuleUser::ACCESS_UNLIMITED)->or->nest()
Línea 805... Línea 780...
805
                ->equalTo('access', CompanyMicrolearningCapsuleUser::ACCESS_PAY_PERIOD)
780
                ->equalTo('access', MicrolearningCapsuleUser::ACCESS_PAY_PERIOD)
Línea 819... Línea 794...
819
                
794
                
820
                
795
                
821
                
796
                
822
                switch($record['access'])
797
                switch($record['access'])
823
                {
798
                {
Línea 824... Línea 799...
824
                    case CompanyMicrolearningCapsuleUser::ACCESS_UNLIMITED :
799
                    case MicrolearningCapsuleUser::ACCESS_UNLIMITED :
825
                        $details['access'] = 'LABEL_UNLIMIT';
800
                        $details['access'] = 'LABEL_UNLIMIT';
826
                        break;
801
                        break;
Línea 827... Línea 802...
827
                        
802
                        
828
                    case CompanyMicrolearningCapsuleUser::ACCESS_REVOKE :
803
                    case MicrolearningCapsuleUser::ACCESS_REVOKE :
829
                        $details['access'] = 'LABEL_REVOKED';
804
                        $details['access'] = 'LABEL_REVOKED';
Línea 830... Línea 805...
830
                        break;
805
                        break;
831
                        
806
                        
832
                    case CompanyMicrolearningCapsuleUser::ACCESS_PAY_PERIOD :
807
                    case MicrolearningCapsuleUser::ACCESS_PAY_PERIOD :
833
                        $dt_paid_from = \DateTime::createFromFormat('Y-m-d', $record['paid_from']);
808
                        $dt_paid_from = \DateTime::createFromFormat('Y-m-d', $record['paid_from']);
Línea 834... Línea 809...
834
                        $dt_paid_to = \DateTime::createFromFormat('Y-m-d', $record['paid_to']);
809
                        $dt_paid_to = \DateTime::createFromFormat('Y-m-d', $record['paid_to']);
835
                        
810
                        
836
                        $details['access'] = 'LABEL_PAY_PERIOD';
811
                        $details['access'] = 'LABEL_PAY_PERIOD';
Línea 837... Línea 812...
837
                        $details['paid_from'] = $dt_paid_from->format('d/m/Y');
812
                        $details['paid_from'] = $dt_paid_from->format('d/m/Y');
838
                        $details['paid_to'] = $dt_paid_to->format('d/m/Y');
813
                        $details['paid_to'] = $dt_paid_to->format('d/m/Y');
839
                        break;
814
                        break;
840
                        
815
                        
Línea 841... Línea 816...
841
                    case CompanyMicrolearningCapsuleUser::ACCESS_SUPENDED :
816
                    case MicrolearningCapsuleUser::ACCESS_SUPENDED :
842
                        $dt_paid_from = \DateTime::createFromFormat('Y-m-d', $record['paid_from']);
817
                        $dt_paid_from = \DateTime::createFromFormat('Y-m-d', $record['paid_from']);
843
                        $dt_paid_to = \DateTime::createFromFormat('Y-m-d', $record['paid_to']);
818
                        $dt_paid_to = \DateTime::createFromFormat('Y-m-d', $record['paid_to']);
Línea 844... Línea 819...
844
                        
819
                        
845
                        $details['access'] = 'LABEL_SUSPENDED';
820
                        $details['access'] = 'LABEL_SUSPENDED';