Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 3298 | Rev 3334 | 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
2466 stevensc 2
 
1 www 3
declare(strict_types=1);
4
 
5
namespace LeadersLinked\Controller;
6
 
7
use Laminas\Db\Adapter\AdapterInterface;
8
use Laminas\Cache\Storage\Adapter\AbstractAdapter;
9
use Laminas\Mvc\Controller\AbstractActionController;
10
use Laminas\Log\LoggerInterface;
11
use Laminas\View\Model\ViewModel;
12
use Laminas\View\Model\JsonModel;
13
use LeadersLinked\Model\Page;
14
use LeadersLinked\Mapper\NotificationMapper;
15
use LeadersLinked\Mapper\CompanyMapper;
16
use LeadersLinked\Mapper\CompanyUserMapper;
17
use LeadersLinked\Model\Company;
18
use LeadersLinked\Mapper\PageMapper;
19
use LeadersLinked\Mapper\MessageMapper;
2466 stevensc 20
use LeadersLinked\Mapper\UserMapper;
21
use LeadersLinked\Mapper\UserProfileMapper;
1 www 22
use LeadersLinked\Mapper\CompanyUserRoleMapper;
23
use LeadersLinked\Model\Role;
24
use LeadersLinked\Library\Functions;
2466 stevensc 25
use LeadersLinked\Mapper\ConnectionMapper;
26
use LeadersLinked\Mapper\LocationMapper;
1 www 27
use LeadersLinked\Mapper\PostMapper;
2466 stevensc 28
use LeadersLinked\Mapper\ProfileVisitMapper;
1 www 29
use LeadersLinked\Model\Post;
3138 efrain 30
use LeadersLinked\Mapper\UtilMapper;
3298 efrain 31
use LeadersLinked\Mapper\FeedMapper;
32
use LeadersLinked\Model\Feed;
33
use LeadersLinked\Model\User;
34
use LeadersLinked\Model\Connection;
1 www 35
 
36
class HomeController extends AbstractActionController
37
{
38
    /**
39
     *
40
     * @var AdapterInterface
41
     */
42
    private $adapter;
2466 stevensc 43
 
44
 
1 www 45
    /**
46
     *
47
     * @var AbstractAdapter
48
     */
49
    private $cache;
2466 stevensc 50
 
1 www 51
    /**
52
     *
53
     * @var  LoggerInterface
54
     */
55
    private $logger;
56
 
2466 stevensc 57
 
1 www 58
    /**
59
     *
60
     * @var array
61
     */
62
    private $config;
2466 stevensc 63
 
1 www 64
    /**
65
     *
66
     * @param AdapterInterface $adapter
67
     * @param AbstractAdapter $cache
68
     * @param LoggerInterface $logger
69
     * @param array $config
70
     */
2466 stevensc 71
    public function __construct($adapter, $cache, $logger,  $config)
1 www 72
    {
73
        $this->adapter      = $adapter;
74
        $this->cache        = $cache;
75
        $this->logger       = $logger;
76
        $this->config       = $config;
77
    }
2466 stevensc 78
 
79
 
80
 
1 www 81
    public function indexAction()
82
    {
83
 
3298 efrain 84
        $currentUserPlugin = $this->plugin('currentUserPlugin');
3302 efrain 85
        if ($currentUserPlugin->hasIdentity()) {
2466 stevensc 86
            return $this->redirect()->toRoute('dashboard');
1 www 87
        } else {
2466 stevensc 88
            return $this->redirect()->toRoute('signin');
1 www 89
        }
90
    }
2466 stevensc 91
 
92
 
93
 
94
 
1 www 95
    public function privacyPolicyAction()
96
    {
97
        $pageMapper = PageMapper::getInstance($this->adapter);
98
        $page = $pageMapper->fetchOne(Page::PAGE_ID_PRIVACY_POLICY);
2466 stevensc 99
 
1 www 100
        $this->layout()->setTemplate('layout/layout.phtml');
101
        $viewModel = new ViewModel();
102
        $viewModel->setTemplate('leaders-linked/home/privacy-policy.phtml');
103
        $viewModel->setVariable('page', $page);
2466 stevensc 104
        return $viewModel;
1 www 105
    }
2466 stevensc 106
 
1 www 107
    public function cookiesAction()
108
    {
109
        $pageMapper = PageMapper::getInstance($this->adapter);
110
        $page = $pageMapper->fetchOne(Page::PAGE_ID_COOKIES);
2466 stevensc 111
 
1 www 112
        $this->layout()->setTemplate('layout/layout.phtml');
113
        $viewModel = new ViewModel();
114
        $viewModel->setTemplate('leaders-linked/home/cookies.phtml');
115
        $viewModel->setVariable('page', $page);
2466 stevensc 116
        return $viewModel;
1 www 117
    }
2466 stevensc 118
 
1 www 119
    public function professionalismPolicyAction()
120
    {
121
        //
2466 stevensc 122
 
1 www 123
        $pageMapper = PageMapper::getInstance($this->adapter);
124
        $page = $pageMapper->fetchOne(Page::PAGE_ID_PROFESSIONALISM_POLICY);
2466 stevensc 125
 
1 www 126
        $this->layout()->setTemplate('layout/layout.phtml');
127
        $viewModel = new ViewModel();
128
        $viewModel->setTemplate('leaders-linked/home/professionalism-policy');
129
        $viewModel->setVariable('page', $page);
2466 stevensc 130
        return $viewModel;
1 www 131
    }
2466 stevensc 132
 
133
 
1 www 134
    public function termsAndConditionsAction()
135
    {
136
        $pageMapper = PageMapper::getInstance($this->adapter);
137
        $page = $pageMapper->fetchOne(Page::PAGE_ID_TERMS_AND_CONDITIONS);
2466 stevensc 138
 
1 www 139
        $this->layout()->setTemplate('layout/layout.phtml');
140
        $viewModel = new ViewModel();
141
        $viewModel->setTemplate('leaders-linked/home/terms-and-conditions.phtml');
142
        $viewModel->setVariable('page', $page);
2466 stevensc 143
        return $viewModel;
1 www 144
    }
2466 stevensc 145
 
1 www 146
    public function checkSessionAction()
147
    {
148
 
149
        $request = $this->getRequest();
2466 stevensc 150
        if ($request->isGet()) {
151
 
1 www 152
            $currentUserPlugin = $this->plugin('currentUserPlugin');
2466 stevensc 153
            if (!$currentUserPlugin->hasIdentity()) {
1 www 154
                $flashMessenger = $this->plugin('FlashMessenger');
155
                $flashMessenger->addErrorMessage('ERROR_SESSION_NOT_FOUND');
2466 stevensc 156
 
1 www 157
                $response = [
158
                    'success' => false,
159
                    'data' => [
160
                        'message' =>  'ERROR_SESSION_NOT_FOUND',
161
                        'url' => $this->url()->fromRoute('signout')
162
                    ]
163
                ];
2466 stevensc 164
 
1 www 165
                return new JsonModel($response);
166
            }
2466 stevensc 167
 
1 www 168
            $currentUser = $currentUserPlugin->getUser();
2466 stevensc 169
 
170
 
171
            if ($currentUser->last_activity_on) {
1 www 172
                $last_activity_on = strtotime($currentUser->last_activity_on);
173
            } else {
174
                $last_activity_on = strtotime('-1 day');
175
            }
176
 
177
            $expiry_time = $last_activity_on + $this->config['leaderslinked.security.last_activity_expired'];
178
            if (time() > $expiry_time) {
2466 stevensc 179
                //$flashMessenger = $this->plugin('FlashMessenger');
180
                //$flashMessenger->addErrorMessage('ERROR_SESSION_EXPIRED');
1 www 181
 
182
                $response = [
183
                    'success' => false,
184
                    'data' => [
185
                        'message' => 'ERROR_SESSION_EXPIRED',
186
                        'url' => $this->url()->fromRoute('signout')
187
                    ]
188
                ];
189
            } else {
190
                $notificationMapper = NotificationMapper::getInstance($this->adapter);
191
                $total_notifications = $notificationMapper->fetchUnreadNotificationsCount($currentUser->id);
2466 stevensc 192
 
193
                $messageMapper = MessageMapper::getInstance($this->adapter);
1 www 194
                $total_messages =  $messageMapper->fetchCountUnreadMessagesReceiverId($currentUser->id);
195
                $response = [
196
                    'success' => true,
197
                    'data' => [
198
                        'total_notifications' => $total_notifications,
199
                        'total_messages' => $total_messages
200
                    ]
201
                ];
202
            }
203
        } else {
204
            $response = [
205
                'success' => false,
206
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
207
            ];
208
        }
2466 stevensc 209
 
1 www 210
        return new JsonModel($response);
211
    }
2466 stevensc 212
 
3262 efrain 213
 
1 www 214
    public function postAction()
215
    {
216
        $id = $this->params()->fromRoute('id');
2466 stevensc 217
 
1 www 218
        $postMapper = PostMapper::getInstance($this->adapter);
219
        $post = $postMapper->fetchOneByUuid($id);
2466 stevensc 220
 
221
        if (!$post || $post->status != Post::STATUS_ACTIVE) {
1 www 222
            $flashMessenger = $this->plugin('FlashMessenger');
2466 stevensc 223
 
224
            if (!$id) {
1 www 225
                $flashMessenger->addErrorMessage('ERROR_POST_NOT_AVAILABLE');
226
                return $this->redirect()->toRoute('dashboard');
227
            }
228
        }
2466 stevensc 229
 
230
 
1 www 231
        $this->layout()->setTemplate('layout/layout.phtml');
232
        $viewModel = new ViewModel();
233
        $viewModel->setTemplate('leaders-linked/home/post.phtml');
3298 efrain 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]),
247
 
248
        ]);
2466 stevensc 249
        return $viewModel;
1 www 250
    }
3298 efrain 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
 
501
        return new JsonModel($response);
502
    }
1 www 503
}