Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 1302 | Ir a la última revisión | | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 www 1
<?php
2
declare(strict_types=1);
3
 
4
namespace LeadersLinked\Controller;
5
 
6
use Laminas\Db\Adapter\AdapterInterface;
7
use Laminas\Cache\Storage\Adapter\AbstractAdapter;
8
use Laminas\Mvc\Controller\AbstractActionController;
9
use Laminas\Log\LoggerInterface;
10
use Laminas\View\Model\ViewModel;
11
use Laminas\View\Model\JsonModel;
12
use LeadersLinked\Model\Page;
13
use LeadersLinked\Mapper\NotificationMapper;
14
use LeadersLinked\Mapper\CompanyMapper;
15
use LeadersLinked\Mapper\CompanyUserMapper;
16
use LeadersLinked\Model\Company;
17
use LeadersLinked\Mapper\PageMapper;
18
use LeadersLinked\Mapper\MessageMapper;
19
use LeadersLinked\Mapper\CompanyUserRoleMapper;
20
use LeadersLinked\Model\Role;
21
use LeadersLinked\Library\Functions;
22
use LeadersLinked\Mapper\PostMapper;
23
use LeadersLinked\Model\Post;
24
 
25
class HomeController extends AbstractActionController
26
{
27
    /**
28
     *
29
     * @var AdapterInterface
30
     */
31
    private $adapter;
32
 
33
 
34
    /**
35
     *
36
     * @var AbstractAdapter
37
     */
38
    private $cache;
39
 
40
    /**
41
     *
42
     * @var  LoggerInterface
43
     */
44
    private $logger;
45
 
46
 
47
    /**
48
     *
49
     * @var array
50
     */
51
    private $config;
52
 
53
    /**
54
     *
55
     * @param AdapterInterface $adapter
56
     * @param AbstractAdapter $cache
57
     * @param LoggerInterface $logger
58
     * @param array $config
59
     */
60
    public function __construct($adapter, $cache , $logger,  $config)
61
    {
62
        $this->adapter      = $adapter;
63
        $this->cache        = $cache;
64
        $this->logger       = $logger;
65
        $this->config       = $config;
66
 
67
    }
68
 
69
 
70
 
71
    public function indexAction()
72
    {
73
 
74
        $authService = new \Laminas\Authentication\AuthenticationService();
75
        if($authService->hasIdentity()) {
76
            return $this->redirect()->toRoute('dashboard');
77
        } else {
78
            return $this->redirect()->toRoute('signin');
79
        }
80
    }
81
 
82
 
83
    public function dashboardAction()
84
    {
85
        $this->layout()->setTemplate('layout/layout.phtml');
86
        $viewModel = new ViewModel();
87
        $viewModel->setTemplate('leaders-linked/home/dashboard.phtml');
88
        return $viewModel ;
89
    }
90
 
91
 
92
 
93
    public function privacyPolicyAction()
94
    {
95
        $pageMapper = PageMapper::getInstance($this->adapter);
96
        $page = $pageMapper->fetchOne(Page::PAGE_ID_PRIVACY_POLICY);
97
 
98
        $this->layout()->setTemplate('layout/layout.phtml');
99
        $viewModel = new ViewModel();
100
        $viewModel->setTemplate('leaders-linked/home/privacy-policy.phtml');
101
        $viewModel->setVariable('page', $page);
102
        return $viewModel ;
103
 
104
 
105
    }
106
 
107
    public function cookiesAction()
108
    {
109
        $pageMapper = PageMapper::getInstance($this->adapter);
110
        $page = $pageMapper->fetchOne(Page::PAGE_ID_COOKIES);
111
 
112
        $this->layout()->setTemplate('layout/layout.phtml');
113
        $viewModel = new ViewModel();
114
        $viewModel->setTemplate('leaders-linked/home/cookies.phtml');
115
        $viewModel->setVariable('page', $page);
116
        return $viewModel ;
117
 
118
 
119
    }
120
 
121
    public function professionalismPolicyAction()
122
    {
123
        //
124
 
125
        $pageMapper = PageMapper::getInstance($this->adapter);
126
        $page = $pageMapper->fetchOne(Page::PAGE_ID_PROFESSIONALISM_POLICY);
127
 
128
        $this->layout()->setTemplate('layout/layout.phtml');
129
        $viewModel = new ViewModel();
130
        $viewModel->setTemplate('leaders-linked/home/professionalism-policy');
131
        $viewModel->setVariable('page', $page);
132
        return $viewModel ;
133
    }
134
 
135
 
136
    public function termsAndConditionsAction()
137
    {
138
        $pageMapper = PageMapper::getInstance($this->adapter);
139
        $page = $pageMapper->fetchOne(Page::PAGE_ID_TERMS_AND_CONDITIONS);
140
 
141
        $this->layout()->setTemplate('layout/layout.phtml');
142
        $viewModel = new ViewModel();
143
        $viewModel->setTemplate('leaders-linked/home/terms-and-conditions.phtml');
144
        $viewModel->setVariable('page', $page);
145
        return $viewModel ;
146
 
147
 
148
    }
149
 
150
    public function checkSessionAction()
151
    {
152
 
153
        $request = $this->getRequest();
154
        if($request->isGet()) {
155
 
156
            $currentUserPlugin = $this->plugin('currentUserPlugin');
157
            if(!$currentUserPlugin->hasIdentity()) {
158
                $flashMessenger = $this->plugin('FlashMessenger');
159
                $flashMessenger->addErrorMessage('ERROR_SESSION_NOT_FOUND');
160
 
161
                $response = [
162
                    'success' => false,
163
                    'data' => [
164
                        'message' =>  'ERROR_SESSION_NOT_FOUND',
165
                        'url' => $this->url()->fromRoute('signout')
166
                    ]
167
                ];
168
 
169
                return new JsonModel($response);
170
 
171
            }
172
 
173
            $currentUser = $currentUserPlugin->getUser();
174
 
175
 
176
            if($currentUser->last_activity_on) {
177
                $last_activity_on = strtotime($currentUser->last_activity_on);
178
            } else {
179
                $last_activity_on = strtotime('-1 day');
180
            }
181
 
182
            $expiry_time = $last_activity_on + $this->config['leaderslinked.security.last_activity_expired'];
183
            if (time() > $expiry_time) {
184
                    //$flashMessenger = $this->plugin('FlashMessenger');
185
                    //$flashMessenger->addErrorMessage('ERROR_SESSION_EXPIRED');
186
 
187
                $response = [
188
                    'success' => false,
189
                    'data' => [
190
                        'message' => 'ERROR_SESSION_EXPIRED',
191
                        'url' => $this->url()->fromRoute('signout')
192
                    ]
193
                ];
194
            } else {
195
                $notificationMapper = NotificationMapper::getInstance($this->adapter);
196
                $total_notifications = $notificationMapper->fetchUnreadNotificationsCount($currentUser->id);
197
 
198
                $messageMapper = MessageMapper::getInstance($this->adapter);
199
                $total_messages =  $messageMapper->fetchCountUnreadMessagesReceiverId($currentUser->id);
200
                $response = [
201
                    'success' => true,
202
                    'data' => [
203
                        'total_notifications' => $total_notifications,
204
                        'total_messages' => $total_messages
205
                    ]
206
                ];
207
            }
208
        } else {
209
            $response = [
210
                'success' => false,
211
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
212
            ];
213
        }
214
 
215
        return new JsonModel($response);
216
    }
217
 
218
    public function notificationsAction()
219
    {
220
        $request = $this->getRequest();
221
        if($request->isGet()) {
222
 
223
            $currentUserPlugin = $this->plugin('currentUserPlugin');
224
            $currentUser = $currentUserPlugin->getUser();
225
 
226
 
227
            $notificationMapper = NotificationMapper::getInstance($this->adapter);
228
            $records = $notificationMapper->fetchAllsUnreadByUserId($currentUser->id);
229
 
230
            $items = [];
231
            foreach($records as $record)
232
            {
233
                $dt = \DateTime::createFromFormat('Y-m-d H:i:s', $record->added_on);
234
 
235
                array_push($items,[
236
                    'message' => $record->message,
237
                    'link' => $record->url,
238
                    'time_elapsed' => Functions::timeElapsedString($dt->getTimestamp())
239
                ]);
240
 
241
            }
242
 
243
            $response = [
244
                'success' => true,
245
                'data' => $items
246
            ];
247
 
248
        } else {
249
            $response = [
250
                'success' => false,
251
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
252
            ];
253
        }
254
 
255
        return new JsonModel($response);
256
    }
257
 
258
 
259
    public function postAction()
260
    {
261
        $id = $this->params()->fromRoute('id');
262
 
263
        $postMapper = PostMapper::getInstance($this->adapter);
264
        $post = $postMapper->fetchOneByUuid($id);
265
 
266
        if(!$post || $post->status != Post::STATUS_ACTIVE) {
267
            $flashMessenger = $this->plugin('FlashMessenger');
268
 
269
            if(!$id) {
270
                $flashMessenger->addErrorMessage('ERROR_POST_NOT_AVAILABLE');
271
                return $this->redirect()->toRoute('dashboard');
272
            }
273
 
274
 
275
        }
276
 
277
 
278
        $this->layout()->setTemplate('layout/layout.phtml');
279
        $viewModel = new ViewModel();
280
        $viewModel->setTemplate('leaders-linked/home/post.phtml');
281
        $viewModel->setVariable('post', $post);
282
        return $viewModel ;
283
 
284
 
285
    }
286
}