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 10... Línea 10...
10
use Laminas\View\Model\ViewModel;
10
use Laminas\View\Model\ViewModel;
11
use Laminas\View\Model\JsonModel;
11
use Laminas\View\Model\JsonModel;
12
use LeadersLinked\Library\Functions;
12
use LeadersLinked\Library\Functions;
13
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
13
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
14
use LeadersLinked\Library\Image;
14
use LeadersLinked\Library\Image;
15
use LeadersLinked\Mapper\CompanyMapper;
-
 
16
use LeadersLinked\Mapper\CompanyMicrolearningTopicMapper;
15
use LeadersLinked\Mapper\MicrolearningTopicMapper;
17
use LeadersLinked\Model\CompanyMicrolearningTopic;
16
use LeadersLinked\Model\MicrolearningTopic;
18
use LeadersLinked\Form\TopicAddForm;
17
use LeadersLinked\Form\Microlearning\TopicAddForm;
19
use LeadersLinked\Form\TopicEditForm;
18
use LeadersLinked\Form\Microlearning\TopicEditForm;
20
use LeadersLinked\Mapper\CompanyMicrolearningCapsuleMapper;
19
use LeadersLinked\Mapper\MicrolearningCapsuleMapper;
-
 
20
use LeadersLinked\Library\Storage;
Línea 21... Línea 21...
21
 
21
 
22
 
22
 
23
class MicrolearningTopicController extends AbstractActionController
23
class MicrolearningTopicController extends AbstractActionController
Línea 130... Línea 130...
130
                $acl = $this->getEvent()->getViewModel()->getVariable('acl');
130
                $acl = $this->getEvent()->getViewModel()->getVariable('acl');
131
                $allowEdit = $acl->isAllowed($currentUser->usertype_id, 'microlearning/content/topics/edit');
131
                $allowEdit = $acl->isAllowed($currentUser->usertype_id, 'microlearning/content/topics/edit');
132
                $allowDelete = $acl->isAllowed($currentUser->usertype_id, 'microlearning/content/topics/delete');
132
                $allowDelete = $acl->isAllowed($currentUser->usertype_id, 'microlearning/content/topics/delete');
Línea 133... Línea 133...
133
 
133
 
Línea 134... Línea 134...
134
                
134
                
Línea -... Línea 135...
-
 
135
                $microlearningTopicMapper = MicrolearningTopicMapper::getInstance($this->adapter);
-
 
136
 
-
 
137
                $paginator = $microlearningTopicMapper->fetchAllDataTableByCompanyId($currentCompany->id, $search, $page, $records_x_page, $order_field, $order_direction);
-
 
138
 
135
                $companyMicrolearningTopicMapper = CompanyMicrolearningTopicMapper::getInstance($this->adapter);
139
                
Línea 136... Línea 140...
136
 
140
                $storage = Storage::getInstance($this->config);
137
                $paginator = $companyMicrolearningTopicMapper->fetchAllDataTableByCompanyId($currentCompany->id, $search, $page, $records_x_page, $order_field, $order_direction);
141
                $path = $storage->getPathMicrolearningTopic();
138
 
142
                
139
                $records = $paginator->getCurrentItems();
143
                $records = $paginator->getCurrentItems();
140
 
-
 
141
                $items = [];
-
 
142
                foreach($records as $record)
-
 
143
                {
144
 
144
                    
145
                $items = [];
145
                    //print_r($record);
146
                foreach($records as $record)
146
                    
147
                {
Línea 147... Línea 148...
147
                    
148
 
148
                    switch($record->status) {
149
                    switch($record->status) {
149
                        case  CompanyMicrolearningTopic::STATUS_ACTIVE :
150
                        case  MicrolearningTopic::STATUS_ACTIVE :
Línea 150... Línea 151...
150
                            $status = 'LABEL_ACTIVE';
151
                            $status = 'LABEL_ACTIVE';
151
                            break;
152
                            break;
Línea 164... Línea 165...
164
 
165
 
Línea 165... Línea 166...
165
                    $item = [
166
                    $item = [
166
               
167
               
167
                        'name' => $record->name,
168
                        'name' => $record->name,
168
                        'status' => $status,
169
                        'status' => $status,
169
                        'image' => $this->url()->fromRoute('storage', ['type' => 'microlearning-topic', 'code' => $record->uuid, 'filename' => $record->image]),
170
                        'image' => $storage->getGenericImage($path, $record->uuid, $record->image),
170
                        'actions' => [
171
                        'actions' => [
171
                            'link_edit' => $allowEdit ? $this->url()->fromRoute('microlearning/content/topics/edit', ['id' => $record->uuid ])  : '',
172
                            'link_edit' => $allowEdit ? $this->url()->fromRoute('microlearning/content/topics/edit', ['id' => $record->uuid ])  : '',
Línea 235... Línea 236...
235
            
236
            
236
            if($form->isValid()) {
237
            if($form->isValid()) {
Línea 237... Línea 238...
237
                $dataPost = (array) $form->getData();
238
                $dataPost = (array) $form->getData();
238
                
239
                
239
                $hydrator = new ObjectPropertyHydrator();
240
                $hydrator = new ObjectPropertyHydrator();
Línea 240... Línea 241...
240
                $topic = new CompanyMicrolearningTopic();
241
                $topic = new MicrolearningTopic();
241
                $hydrator->hydrate($dataPost, $topic);
242
                $hydrator->hydrate($dataPost, $topic);
Línea 242... Línea 243...
242
                
243
                
243
                $topic->company_id = $currentCompany->id;
244
                $topic->company_id = $currentCompany->id;
244
                $topic->image = null;
245
                $topic->image = null;
Línea 245... Línea -...
245
 
-
 
246
               
246
 
247
                
247
               
248
                $topicMapper = CompanyMicrolearningTopicMapper::getInstance($this->adapter);
-
 
Línea 249... Línea 248...
249
                if($topicMapper->insert($topic)) {
248
                
250
                    $topic = $topicMapper->fetchOne($topic->id);
249
                $topicMapper = MicrolearningTopicMapper::getInstance($this->adapter);
251
                    
250
                if($topicMapper->insert($topic)) {
Línea 263... Línea 262...
263
                        try {
262
                        try {
264
                            list($target_width, $target_height) = explode('x', $this->config['leaderslinked.image_sizes.microlearning_image_size']);
263
                            list($target_width, $target_height) = explode('x', $this->config['leaderslinked.image_sizes.microlearning_image_size']);
Línea 265... Línea 264...
265
                            
264
                            
266
                            $filename = 'topic-' .uniqid() . '.png';
265
                            $filename = 'topic-' .uniqid() . '.png';
-
 
266
                            $crop_to_dimensions = false;
-
 
267
                            $unlink_source = true;
267
                            $crop_to_dimensions = false;
268
                            
268
                            if(Image::uploadImage($tmp_filename, $target_path, $filename, $target_width, $target_height, $crop_to_dimensions)) {
269
                            if($image->uploadImageChangeSize($tmp_filename, $target_path, $topic->uuid, $filename, $target_width, $target_height, $crop_to_dimensions, $unlink_source)) {
269
                                $topic->image = $filename;
270
                                $topic->image = $filename;
270
                                $topicMapper->update($topic);
271
                                $topicMapper->update($topic);
271
                            }
272
                            }
272
                        } catch(\Throwable $e) {
273
                        } catch(\Throwable $e) {
Línea 331... Línea 332...
331
        
332
        
332
        $request    = $this->getRequest();
333
        $request    = $this->getRequest();
Línea 333... Línea 334...
333
        $id   = $this->params()->fromRoute('id');
334
        $id   = $this->params()->fromRoute('id');
334
        
335
        
335
        
336
        
336
        $topicMapper = CompanyMicrolearningTopicMapper::getInstance($this->adapter);
337
        $topicMapper = MicrolearningTopicMapper::getInstance($this->adapter);
337
        $topic = $topicMapper->fetchOneByUuid($id);
338
        $topic = $topicMapper->fetchOneByUuid($id);
338
        if(!$topic) {
339
        if(!$topic) {
Línea 350... Línea 351...
350
        }
351
        }
Línea 351... Línea 352...
351
        
352
        
352
 
353
 
353
        
354
        
354
        if($request->isPost()) {
355
        if($request->isPost()) {
355
            $capsuleMapper = CompanyMicrolearningCapsuleMapper::getInstance($this->adapter);
356
            $capsuleMapper = MicrolearningCapsuleMapper::getInstance($this->adapter);
356
            $count = $capsuleMapper->fetchTotalCountByCompanyIdAndTopicId($topic->company_id, $topic->id); 
357
            $count = $capsuleMapper->fetchTotalCountByCompanyIdAndTopicId($topic->company_id, $topic->id); 
357
            if($count > 0 ) {
358
            if($count > 0 ) {
Línea 364... Línea 365...
364
            
365
            
365
            
366
            
366
            $result = $topicMapper->delete($topic);
367
            $result = $topicMapper->delete($topic);
367
            if($result) {
-
 
368
                $this->logger->info('Se borro el tópico : ' .  $topic->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
-
 
-
 
368
            if($result) {
369
                try {
369
                $this->logger->info('Se borro el tópico : ' .  $topic->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
370
                    $target_path = $this->config['leaderslinked.fullpath.microlearning_topic'] . DIRECTORY_SEPARATOR . $topic->uuid;
370
                
371
                    if(file_exists($target_path)) {
-
 
372
                        Functions::rmDirRecursive($target_path);
-
 
-
 
371
                $storage = Storage::getInstance($this->config);
373
                    }
372
                $target_path = $storage->getPathMicrolearningTopic();
374
                } catch(\Throwable $e) {
-
 
-
 
373
                
Línea 375... Línea 374...
375
                    error_log($e->getTraceAsString());
374
                $storage->deleteFile($target_path, $topic->uuid, $topic->image);
376
                }
375
 
377
                
376
                
Línea 412... Línea 411...
412
        $request    = $this->getRequest();
411
        $request    = $this->getRequest();
413
        $id   = $this->params()->fromRoute('id');
412
        $id   = $this->params()->fromRoute('id');
Línea 414... Línea 413...
414
        
413
        
415
 
414
 
416
        
415
        
417
        $topicMapper = CompanyMicrolearningTopicMapper::getInstance($this->adapter);
416
        $topicMapper = MicrolearningTopicMapper::getInstance($this->adapter);
418
        $topic = $topicMapper->fetchOneByUuid($id);
417
        $topic = $topicMapper->fetchOneByUuid($id);
419
        if(!$topic) {
418
        if(!$topic) {
Línea 429... Línea 428...
429
                'data'   => 'ERROR_UNAUTHORIZED'
428
                'data'   => 'ERROR_UNAUTHORIZED'
430
            ]);
429
            ]);
431
        }
430
        }
Línea 432... Línea 431...
432
        
431
        
-
 
432
        if($request->isGet()) {
-
 
433
            
-
 
434
            $storage = Storage::getInstance($this->config);
-
 
435
            $path = $storage->getPathMicrolearningTopic();
433
        if($request->isGet()) {
436
            
434
            $data = [
437
            $data = [
435
                'success' => true,
438
                'success' => true,
436
                'data' => [
439
                'data' => [
437
                    'name' => $topic->name,
440
                    'name' => $topic->name,
438
                    'description' => $topic->description,
441
                    'description' => $topic->description,
439
                    'order' => $topic->order,
442
                    'order' => $topic->order,
440
                    'status' => $topic->status,
443
                    'status' => $topic->status,
441
                    'image'=> $this->url()->fromRoute('storage', ['type' => 'microlearning-topic', 'code' => $topic->uuid, 'filename' => $topic->image])
444
                    'image'=> $storage->getGenericImage($path, $topic->uuid, $topic->image)
442
                ]
445
                ]
Línea 443... Línea 446...
443
            ];
446
            ];
444
            
447
            
Línea 458... Línea 461...
458
                $topic->image = null;
461
                $topic->image = null;
Línea 459... Línea 462...
459
          
462
          
460
                if($topicMapper->update($topic)) {
463
                if($topicMapper->update($topic)) {
Línea 461... Línea -...
461
                    $topic = $topicMapper->fetchOne($topic->id);
-
 
462
                    
464
                    $topic = $topicMapper->fetchOne($topic->id);
463
                    $target_path = $this->config['leaderslinked.fullpath.microlearning_topic'] .  $topic->uuid;
465
                    
464
                    if(!file_exists($target_path)) {
-
 
Línea 465... Línea 466...
465
                        mkdir($target_path, 0755, true);
466
                    $image = Image::getInstance($this->config);
466
                    }
467
                    $target_path = $image->getStorage()->getPathMicrolearningTopic();
467
                    
468
                    
468
                    
469
                    
Línea 469... Línea 470...
469
                    $files = $this->getRequest()->getFiles()->toArray();
470
                    $files = $this->getRequest()->getFiles()->toArray();
470
                    if(isset($files['file']) && empty($files['file']['error'])) {
471
                    if(isset($files['file']) && empty($files['file']['error'])) {
Línea 471... Línea 472...
471
                        $tmp_filename  = $files['file']['tmp_name'];
472
                        $tmp_filename  = $files['file']['tmp_name'];
472
                        //$filename      = $this->normalizeString($files['file']['name']);
473
                        //$filename      = $this->normalizeString($files['file']['name']);
473
                        
474
                        
474
                        try {
475
                        try {
475
                            if($topic->image) {
476
                            if($topic->image) {
476
                                
477
                                
Línea 484... Línea 485...
484
                            
485
                            
Línea 485... Línea 486...
485
                            list($target_width, $target_height) = explode('x', $this->config['leaderslinked.image_sizes.microlearning_image_size']);
486
                            list($target_width, $target_height) = explode('x', $this->config['leaderslinked.image_sizes.microlearning_image_size']);
486
                            
487
                            
-
 
488
                            $filename = 'topic-' .uniqid() . '.png';
-
 
489
                            $crop_to_dimensions = false;
487
                            $filename = 'topic-' .uniqid() . '.png';
490
                            $unlink_source = true;
488
                            $crop_to_dimensions = false;
491
                            
489
                            if(Image::uploadImage($tmp_filename, $target_path, $filename, $target_width, $target_height, $crop_to_dimensions)) {
492
                            if($image->uploadImageChangeSize($tmp_filename, $target_path, $topic->uuid, $filename, $target_width, $target_height, $crop_to_dimensions, $unlink_source)) {
490
                                $topic->image = $filename;
493
                                $topic->image = $filename;
491
                                $topicMapper->update($topic);
494
                                $topicMapper->update($topic);
492
                            }
495
                            }