Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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

Rev 3262 Rev 3298
Línea 26... Línea 26...
26
use LeadersLinked\Mapper\LocationMapper;
26
use LeadersLinked\Mapper\LocationMapper;
27
use LeadersLinked\Mapper\PostMapper;
27
use LeadersLinked\Mapper\PostMapper;
28
use LeadersLinked\Mapper\ProfileVisitMapper;
28
use LeadersLinked\Mapper\ProfileVisitMapper;
29
use LeadersLinked\Model\Post;
29
use LeadersLinked\Model\Post;
30
use LeadersLinked\Mapper\UtilMapper;
30
use LeadersLinked\Mapper\UtilMapper;
-
 
31
use LeadersLinked\Mapper\FeedMapper;
-
 
32
use LeadersLinked\Model\Feed;
-
 
33
use LeadersLinked\Model\User;
-
 
34
use LeadersLinked\Model\Connection;
Línea 31... Línea 35...
31
 
35
 
32
class HomeController extends AbstractActionController
36
class HomeController extends AbstractActionController
33
{
37
{
34
    /**
38
    /**
Línea 75... Línea 79...
75
 
79
 
76
 
80
 
Línea 77... Línea 81...
77
    public function indexAction()
81
    public function indexAction()
78
    {
82
    {
79
 
83
 
80
        $authService = new \Laminas\Authentication\AuthenticationService();
84
        $currentUserPlugin = $this->plugin('currentUserPlugin');
81
        if ($authService->hasIdentity()) {
85
        if (!$currentUserPlugin->hasIdentity()) {
82
            return $this->redirect()->toRoute('dashboard');
86
            return $this->redirect()->toRoute('dashboard');
83
        } else {
87
        } else {
Línea 84... Línea -...
84
            return $this->redirect()->toRoute('signin');
-
 
85
        }
-
 
86
    }
-
 
87
 
-
 
88
 
-
 
89
    public function dashboardAction()
-
 
90
    {
-
 
91
        $this->layout()->setTemplate('layout/layout.phtml');
-
 
Línea 92... Línea 88...
92
        $viewModel = new ViewModel();
88
            return $this->redirect()->toRoute('signin');
93
        $viewModel->setTemplate('leaders-linked/home/dashboard.phtml');
89
        }
94
        return $viewModel;
90
    }
Línea 233... Línea 229...
233
 
229
 
234
 
230
 
235
        $this->layout()->setTemplate('layout/layout.phtml');
231
        $this->layout()->setTemplate('layout/layout.phtml');
236
        $viewModel = new ViewModel();
232
        $viewModel = new ViewModel();
-
 
233
        $viewModel->setTemplate('leaders-linked/home/post.phtml');
-
 
234
        $viewModel->setVariables([
-
 
235
            'post' => $post,
-
 
236
            'id' => $post->id,
-
 
237
            'uuid' => $post->uuid,
-
 
238
            'title' => $post->title,
-
 
239
            'description' => $post->description,
-
 
240
            'url' => $post->url,
-
 
241
            'date' => $post->date,
-
 
242
            'status' => $post->status,
-
 
243
            'image' => $post->image,
-
 
244
            'file' => $post->file,
-
 
245
            'added_on' => $post->added_on,
-
 
246
            'share_external_url' => $this->url()->fromRoute('share',  ['type' => 'post', 'code' => $post->uuid]),
237
        $viewModel->setTemplate('leaders-linked/home/post.phtml');
247
            
238
        $viewModel->setVariable('post', $post);
248
        ]);
-
 
249
        return $viewModel;
-
 
250
    }
-
 
251
    
-
 
252
    public function shareAction()
-
 
253
    {
-
 
254
        $request = $this->getRequest();
-
 
255
        if ($request->isGet()) {
-
 
256
            $currentUserPlugin = $this->plugin('currentUserPlugin');
-
 
257
            $currentUser = $currentUserPlugin->getUser();
-
 
258
            
-
 
259
            $code = $this->params()->fromRoute('code');
-
 
260
            $type = $this->params()->fromRoute('type');
-
 
261
       
-
 
262
           
-
 
263
            
-
 
264
            if(strpos($_SERVER['SERVER_PROTOCOL'], 'HTTPS') === false) {
-
 
265
                $base_share_image = 'http://' . $_SERVER['HTTP_HOST']; 
-
 
266
            } else {
-
 
267
                $base_share_image = 'https://' . $_SERVER['HTTP_HOST'];
-
 
268
            }
-
 
269
            
-
 
270
        
-
 
271
            
-
 
272
            
-
 
273
            $share_image        = $base_share_image . '/images/ll-logo.png';
-
 
274
            $share_title        = '';
-
 
275
            $share_description  = '';
-
 
276
            /*
-
 
277
            [fullpath]
-
 
278
            chat=data/storage/chat/
-
 
279
            group=data/storage/group/
-
 
280
            user=data/storage/user/
-
 
281
            image=data/storage/image/
-
 
282
            job=data/storage/job/
-
 
283
            company=data/storage/company/
-
 
284
            feed=data/storage/feed/
-
 
285
            post=data/storage/post/
-
 
286
            /storage/type/feed/code/ef1038de-4f26-4253-a886-e125784ab604/filename/th-2400499377.png/
-
 
287
            *
-
 
288
            */
-
 
289
            
-
 
290
            if($type == 'feed' && $code ) {
-
 
291
                $feedMapper =  FeedMapper::getInstance($this->adapter);
-
 
292
                $feed = $feedMapper->fetchOneByUuid($code);
-
 
293
                
-
 
294
                if($feed && $feed->status == Feed::STATUS_PUBLISHED) {
-
 
295
                    $share_title = $feed->title ? $feed->title : $feed->description;
-
 
296
                    $share_description = $feed->description;
-
 
297
      
-
 
298
                    $image_name = '';
-
 
299
                    if($feed->file_type == Feed::FILE_TYPE_IMAGE) {
-
 
300
                        
-
 
301
                        $image_name = $feed->file_name;
-
 
302
                        
-
 
303
                    } else  if($feed->file_image_preview) {
-
 
304
                        $image_name = $feed->file_image_preview;
-
 
305
                    }
-
 
306
                        
-
 
307
         
-
 
308
                    
-
 
309
                    if( $image_name ) {
-
 
310
                        
-
 
311
                        $source = $this->config['leaderslinked.fullpath.feed'] . $feed->uuid . DIRECTORY_SEPARATOR . $image_name;
-
 
312
                        
-
 
313
                
-
 
314
                        $target_path = 'public' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'feed'. DIRECTORY_SEPARATOR . $feed->uuid;
-
 
315
                        
-
 
316
                        if(!file_exists($target_path)) {
-
 
317
                            mkdir($target_path, 0755, true);
-
 
318
                        }
-
 
319
                        
-
 
320
                        
-
 
321
                        
-
 
322
                        $target = $target_path . DIRECTORY_SEPARATOR . $image_name;
-
 
323
                        
-
 
324
               
-
 
325
                        
-
 
326
                        if(!file_exists($target)) {
-
 
327
                            
-
 
328
                            copy($source, $target);
-
 
329
                            $share_image =  $base_share_image . '/images/feed/' . $feed->uuid . '/' . $image_name;
-
 
330
                            
-
 
331
                        } else {
-
 
332
                            $share_image =  $base_share_image . '/images/feed/' . $feed->uuid . '/' . $image_name;
-
 
333
                            
-
 
334
                        }
-
 
335
                        
-
 
336
                        
-
 
337
                        
-
 
338
                        
-
 
339
                    }
-
 
340
                  
-
 
341
                }
-
 
342
                
-
 
343
                
-
 
344
            } else if ($type == 'post' && $code) {
-
 
345
                
-
 
346
                $postMapper = PostMapper::getInstance($this->adapter);
-
 
347
                $post = $postMapper->fetchOneByUuid($code);
-
 
348
                
-
 
349
                if($post && $post->status == Post::STATUS_ACTIVE) {
-
 
350
                    $share_title = $post->title;
-
 
351
                    $share_description = $post->description;  
-
 
352
                    
-
 
353
                    
-
 
354
                    if($post->image) {
-
 
355
                        $source = $this->config['leaderslinked.fullpath.post'] . $post->uuid . DIRECTORY_SEPARATOR . $post->image;
-
 
356
                        
-
 
357
                        
-
 
358
                        $target_path = 'public' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'post'. DIRECTORY_SEPARATOR . $post->uuid;
-
 
359
                        
-
 
360
                        if(!file_exists($target_path)) {
-
 
361
                            mkdir($target_path, 0755, true);
-
 
362
                        }
-
 
363
                        
-
 
364
                        
-
 
365
                        
-
 
366
                        $target = $target_path . DIRECTORY_SEPARATOR . $post->image;
-
 
367
                        
-
 
368
                        
-
 
369
                        
-
 
370
                        if(!file_exists($target)) {
-
 
371
                            
-
 
372
                            copy($source, $target);
-
 
373
                            $share_image =  $base_share_image . '/images/post/' . $post->uuid . '/' . $post->image;
-
 
374
                            
-
 
375
                        } else {
-
 
376
                            $share_image =  $base_share_image . '/images/post/' . $post->uuid . '/' . $post->image;
-
 
377
                            
-
 
378
                        }
-
 
379
                    }
-
 
380
                }
-
 
381
            }
-
 
382
           
-
 
383
            $share_url = $this->url()->fromRoute('share-callback', ['type' => $type, 'code' => $code ], ['force_canonical' => true, 'query' => ['user' => $currentUser->uuid]]);
-
 
384
            
-
 
385
            
-
 
386
 
-
 
387
            
-
 
388
            
-
 
389
            $this->layout()->setTemplate('layout/share.phtml');
-
 
390
            $viewModel = new ViewModel();
-
 
391
            $viewModel->setTemplate('leaders-linked/home/share.phtml');
-
 
392
            $viewModel->setVariables([
-
 
393
                'share_image' => $share_image,
-
 
394
                'share_url' => $share_url,
-
 
395
                'share_title' => $share_title,
-
 
396
                'share_description' => $share_description,
-
 
397
                'share_description' => $share_description,
-
 
398
            ]);
-
 
399
 
-
 
400
            
-
 
401
            return $viewModel;
-
 
402
            
-
 
403
 
-
 
404
        } else {
-
 
405
            $response = [
-
 
406
                'success' => false,
-
 
407
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
-
 
408
            ];
-
 
409
            
-
 
410
            return new JsonModel($response);
-
 
411
        }
-
 
412
        
-
 
413
       
-
 
414
    }
-
 
415
    
-
 
416
    public function shareCallbackAction()
-
 
417
    {
-
 
418
        $request = $this->getRequest();
-
 
419
        if ($request->isGet()) {
-
 
420
            $currentUserPlugin = $this->plugin('currentUserPlugin');
-
 
421
           
-
 
422
            
-
 
423
            $code = $this->params()->fromRoute('code');
-
 
424
            $type = $this->params()->fromRoute('type');
-
 
425
            $user = $this->params()->fromQuery('user');
-
 
426
            
-
 
427
            
-
 
428
            
-
 
429
            $url_redirect = '';
-
 
430
            $user_redirect = '';
-
 
431
            if($type == 'feed' && $code ) {
-
 
432
                $feedMapper =  FeedMapper::getInstance($this->adapter);
-
 
433
                $feed = $feedMapper->fetchOneByUuid($code);
-
 
434
                
-
 
435
                if($feed && $feed->status == Feed::STATUS_PUBLISHED) {
-
 
436
                        
-
 
437
                    $url_redirect = $this->url()->fromRoute('dashboard', ['feed' => $feed->uuid]);
-
 
438
                }
-
 
439
                
-
 
440
                
-
 
441
            } else if ($type == 'post' && $code) {
-
 
442
                
-
 
443
                $postMapper = PostMapper::getInstance($this->adapter);
-
 
444
                $post = $postMapper->fetchOneByUuid($code);
-
 
445
                
-
 
446
                if($post && $post->status == Post::STATUS_ACTIVE) {
-
 
447
                    $url_redirect = $this->url()->fromRoute('post', ['id' => $post->uuid]);
-
 
448
                }
-
 
449
            }
-
 
450
            
-
 
451
            if($user) {
-
 
452
                $userMapper = UserMapper::getInstance($this->adapter);
-
 
453
                $user = $userMapper->fetchOneByUuid($user);
-
 
454
                
-
 
455
                if($user && $user->status == User::STATUS_ACTIVE && $currentUserPlugin->hasIdentity()) {
-
 
456
                    $currentUser = $currentUserPlugin->getUser();
-
 
457
                    
-
 
458
                    if($user->id != $currentUser->id) {
-
 
459
                        
-
 
460
                        $connectionMapper = ConnectionMapper::getInstance($this->adapter);
-
 
461
                        $connection = $connectionMapper->fetchOneByUserId1AndUserId2($currentUser->id, $user->id);
-
 
462
                        
-
 
463
                        if($connection) {
-
 
464
                            
-
 
465
                            if($connection->status != Connection::STATUS_ACCEPTED) {
-
 
466
                                $connectionMapper->approve($connection);
-
 
467
                            }
-
 
468
                            
-
 
469
                        } else {
-
 
470
                            $connection = new Connection();
-
 
471
                            $connection->request_from = $currentUser->id;
-
 
472
                            $connection->request_to = $user->id;
-
 
473
                            $connection->status = Connection::STATUS_ACCEPTED;
-
 
474
                            
-
 
475
                            $connectionMapper->insert($connection);
-
 
476
                        }
-
 
477
                    }
-
 
478
                }
-
 
479
            }
-
 
480
                
-
 
481
            
-
 
482
            if ($currentUserPlugin->hasIdentity()) {
-
 
483
                if($url_redirect) {
-
 
484
                    return $this->redirect()->toUrl($url_redirect);
-
 
485
                } else {
-
 
486
                    return $this->redirect()->toRoute('dashboard');
-
 
487
                }
-
 
488
            } else {
-
 
489
                $this->cache->addItem('url_redirect', $url_redirect);
-
 
490
                $this->cache->addItem('user_redirect', $user_redirect);
-
 
491
 
-
 
492
                return $this->redirect()->toRoute('signin');
-
 
493
            }
-
 
494
        } else {
-
 
495
            $response = [
-
 
496
                'success' => false,
-
 
497
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
-
 
498
            ];
-
 
499
        }
-
 
500
        
239
        return $viewModel;
501
        return new JsonModel($response);