Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 3302 | Rev 3335 | 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
 
3334 efrain 262
            print_r($_SERVER); exit;
3298 efrain 263
 
264
 
265
            if(strpos($_SERVER['SERVER_PROTOCOL'], 'HTTPS') === false) {
266
                $base_share_image = 'http://' . $_SERVER['HTTP_HOST'];
267
            } else {
268
                $base_share_image = 'https://' . $_SERVER['HTTP_HOST'];
269
            }
270
 
271
 
272
 
273
 
274
            $share_image        = $base_share_image . '/images/ll-logo.png';
275
            $share_title        = '';
276
            $share_description  = '';
277
            /*
278
            [fullpath]
279
            chat=data/storage/chat/
280
            group=data/storage/group/
281
            user=data/storage/user/
282
            image=data/storage/image/
283
            job=data/storage/job/
284
            company=data/storage/company/
285
            feed=data/storage/feed/
286
            post=data/storage/post/
287
            /storage/type/feed/code/ef1038de-4f26-4253-a886-e125784ab604/filename/th-2400499377.png/
288
            *
289
            */
290
 
291
            if($type == 'feed' && $code ) {
292
                $feedMapper =  FeedMapper::getInstance($this->adapter);
293
                $feed = $feedMapper->fetchOneByUuid($code);
294
 
295
                if($feed && $feed->status == Feed::STATUS_PUBLISHED) {
296
                    $share_title = $feed->title ? $feed->title : $feed->description;
297
                    $share_description = $feed->description;
298
 
299
                    $image_name = '';
300
                    if($feed->file_type == Feed::FILE_TYPE_IMAGE) {
301
 
302
                        $image_name = $feed->file_name;
303
 
304
                    } else  if($feed->file_image_preview) {
305
                        $image_name = $feed->file_image_preview;
306
                    }
307
 
308
 
309
 
310
                    if( $image_name ) {
311
 
312
                        $source = $this->config['leaderslinked.fullpath.feed'] . $feed->uuid . DIRECTORY_SEPARATOR . $image_name;
313
 
314
 
315
                        $target_path = 'public' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'feed'. DIRECTORY_SEPARATOR . $feed->uuid;
316
 
317
                        if(!file_exists($target_path)) {
318
                            mkdir($target_path, 0755, true);
319
                        }
320
 
321
 
322
 
323
                        $target = $target_path . DIRECTORY_SEPARATOR . $image_name;
324
 
325
 
326
 
327
                        if(!file_exists($target)) {
328
 
329
                            copy($source, $target);
330
                            $share_image =  $base_share_image . '/images/feed/' . $feed->uuid . '/' . $image_name;
331
 
332
                        } else {
333
                            $share_image =  $base_share_image . '/images/feed/' . $feed->uuid . '/' . $image_name;
334
 
335
                        }
336
 
337
 
338
 
339
 
340
                    }
341
 
342
                }
343
 
344
 
345
            } else if ($type == 'post' && $code) {
346
 
347
                $postMapper = PostMapper::getInstance($this->adapter);
348
                $post = $postMapper->fetchOneByUuid($code);
349
 
350
                if($post && $post->status == Post::STATUS_ACTIVE) {
351
                    $share_title = $post->title;
352
                    $share_description = $post->description;
353
 
354
 
355
                    if($post->image) {
356
                        $source = $this->config['leaderslinked.fullpath.post'] . $post->uuid . DIRECTORY_SEPARATOR . $post->image;
357
 
358
 
359
                        $target_path = 'public' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'post'. DIRECTORY_SEPARATOR . $post->uuid;
360
 
361
                        if(!file_exists($target_path)) {
362
                            mkdir($target_path, 0755, true);
363
                        }
364
 
365
 
366
 
367
                        $target = $target_path . DIRECTORY_SEPARATOR . $post->image;
368
 
369
 
370
 
371
                        if(!file_exists($target)) {
372
 
373
                            copy($source, $target);
374
                            $share_image =  $base_share_image . '/images/post/' . $post->uuid . '/' . $post->image;
375
 
376
                        } else {
377
                            $share_image =  $base_share_image . '/images/post/' . $post->uuid . '/' . $post->image;
378
 
379
                        }
380
                    }
381
                }
382
            }
383
 
384
            $share_url = $this->url()->fromRoute('share-callback', ['type' => $type, 'code' => $code ], ['force_canonical' => true, 'query' => ['user' => $currentUser->uuid]]);
385
 
386
 
387
 
388
 
389
 
390
            $this->layout()->setTemplate('layout/share.phtml');
391
            $viewModel = new ViewModel();
392
            $viewModel->setTemplate('leaders-linked/home/share.phtml');
393
            $viewModel->setVariables([
394
                'share_image' => $share_image,
395
                'share_url' => $share_url,
396
                'share_title' => $share_title,
397
                'share_description' => $share_description,
398
                'share_description' => $share_description,
399
            ]);
400
 
401
 
402
            return $viewModel;
403
 
404
 
405
        } else {
406
            $response = [
407
                'success' => false,
408
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
409
            ];
410
 
411
            return new JsonModel($response);
412
        }
413
 
414
 
415
    }
416
 
417
    public function shareCallbackAction()
418
    {
419
        $request = $this->getRequest();
420
        if ($request->isGet()) {
421
            $currentUserPlugin = $this->plugin('currentUserPlugin');
422
 
423
 
424
            $code = $this->params()->fromRoute('code');
425
            $type = $this->params()->fromRoute('type');
426
            $user = $this->params()->fromQuery('user');
427
 
428
 
429
 
430
            $url_redirect = '';
431
            $user_redirect = '';
432
            if($type == 'feed' && $code ) {
433
                $feedMapper =  FeedMapper::getInstance($this->adapter);
434
                $feed = $feedMapper->fetchOneByUuid($code);
435
 
436
                if($feed && $feed->status == Feed::STATUS_PUBLISHED) {
437
 
438
                    $url_redirect = $this->url()->fromRoute('dashboard', ['feed' => $feed->uuid]);
439
                }
440
 
441
 
442
            } else if ($type == 'post' && $code) {
443
 
444
                $postMapper = PostMapper::getInstance($this->adapter);
445
                $post = $postMapper->fetchOneByUuid($code);
446
 
447
                if($post && $post->status == Post::STATUS_ACTIVE) {
448
                    $url_redirect = $this->url()->fromRoute('post', ['id' => $post->uuid]);
449
                }
450
            }
451
 
452
            if($user) {
453
                $userMapper = UserMapper::getInstance($this->adapter);
454
                $user = $userMapper->fetchOneByUuid($user);
455
 
456
                if($user && $user->status == User::STATUS_ACTIVE && $currentUserPlugin->hasIdentity()) {
457
                    $currentUser = $currentUserPlugin->getUser();
458
 
459
                    if($user->id != $currentUser->id) {
460
 
461
                        $connectionMapper = ConnectionMapper::getInstance($this->adapter);
462
                        $connection = $connectionMapper->fetchOneByUserId1AndUserId2($currentUser->id, $user->id);
463
 
464
                        if($connection) {
465
 
466
                            if($connection->status != Connection::STATUS_ACCEPTED) {
467
                                $connectionMapper->approve($connection);
468
                            }
469
 
470
                        } else {
471
                            $connection = new Connection();
472
                            $connection->request_from = $currentUser->id;
473
                            $connection->request_to = $user->id;
474
                            $connection->status = Connection::STATUS_ACCEPTED;
475
 
476
                            $connectionMapper->insert($connection);
477
                        }
478
                    }
479
                }
480
            }
481
 
482
 
483
            if ($currentUserPlugin->hasIdentity()) {
484
                if($url_redirect) {
485
                    return $this->redirect()->toUrl($url_redirect);
486
                } else {
487
                    return $this->redirect()->toRoute('dashboard');
488
                }
489
            } else {
490
                $this->cache->addItem('url_redirect', $url_redirect);
491
                $this->cache->addItem('user_redirect', $user_redirect);
492
 
493
                return $this->redirect()->toRoute('signin');
494
            }
495
        } else {
496
            $response = [
497
                'success' => false,
498
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
499
            ];
500
        }
501
 
502
        return new JsonModel($response);
503
    }
1 www 504
}