Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 1 | Rev 2466 | 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
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
 
1302 efrain 226
            $headers  = $request->getHeaders();
1 www 227
 
1302 efrain 228
            $isJson = false;
229
            if($headers->has('Accept')) {
230
                $accept = $headers->get('Accept');
1 www 231
 
1302 efrain 232
                $prioritized = $accept->getPrioritized();
1 www 233
 
1302 efrain 234
                foreach($prioritized as $key => $value) {
235
                    $raw = trim($value->getRaw());
236
 
237
                    if(!$isJson) {
238
                        $isJson = strpos($raw, 'json');
239
                    }
240
 
241
                }
1 www 242
            }
1302 efrain 243
 
244
            if($isJson) {
245
 
1 www 246
 
1302 efrain 247
                $notificationMapper = NotificationMapper::getInstance($this->adapter);
248
                $records = $notificationMapper->fetchAllsUnreadByUserId($currentUser->id);
249
 
250
                $items = [];
251
                foreach($records as $record)
252
                {
253
                    $dt = \DateTime::createFromFormat('Y-m-d H:i:s', $record->added_on);
254
 
255
                    array_push($items,[
256
                        'message' => $record->message,
257
                        'link' => $record->url,
258
                        'time_elapsed' => Functions::timeElapsedString($dt->getTimestamp())
259
                    ]);
260
 
261
                }
262
 
263
                $response = [
264
                    'success' => true,
265
                    'data' => $items
266
                ];
267
            } else {
268
                $this->layout()->setTemplate('layout/layout.phtml');
269
                $viewModel = new ViewModel();
270
 
271
                $viewModel->setTemplate('leaders-linked/home/notifications.phtml');
272
                return $viewModel ;
273
            }
1 www 274
 
275
        } else {
276
            $response = [
277
                'success' => false,
278
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
279
            ];
280
        }
281
 
282
        return new JsonModel($response);
283
    }
284
 
285
 
286
    public function postAction()
287
    {
288
        $id = $this->params()->fromRoute('id');
289
 
290
        $postMapper = PostMapper::getInstance($this->adapter);
291
        $post = $postMapper->fetchOneByUuid($id);
292
 
293
        if(!$post || $post->status != Post::STATUS_ACTIVE) {
294
            $flashMessenger = $this->plugin('FlashMessenger');
295
 
296
            if(!$id) {
297
                $flashMessenger->addErrorMessage('ERROR_POST_NOT_AVAILABLE');
298
                return $this->redirect()->toRoute('dashboard');
299
            }
300
 
301
 
302
        }
303
 
304
 
305
        $this->layout()->setTemplate('layout/layout.phtml');
306
        $viewModel = new ViewModel();
307
        $viewModel->setTemplate('leaders-linked/home/post.phtml');
308
        $viewModel->setVariable('post', $post);
309
        return $viewModel ;
310
 
311
 
312
    }
313
}