Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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

Rev 1302 Rev 2466
Línea 1... Línea 1...
1
<?php
1
<?php
-
 
2
 
2
declare(strict_types=1);
3
declare(strict_types=1);
Línea 3... Línea 4...
3
 
4
 
Línea 4... Línea 5...
4
namespace LeadersLinked\Controller;
5
namespace LeadersLinked\Controller;
Línea 14... Línea 15...
14
use LeadersLinked\Mapper\CompanyMapper;
15
use LeadersLinked\Mapper\CompanyMapper;
15
use LeadersLinked\Mapper\CompanyUserMapper;
16
use LeadersLinked\Mapper\CompanyUserMapper;
16
use LeadersLinked\Model\Company;
17
use LeadersLinked\Model\Company;
17
use LeadersLinked\Mapper\PageMapper;
18
use LeadersLinked\Mapper\PageMapper;
18
use LeadersLinked\Mapper\MessageMapper;
19
use LeadersLinked\Mapper\MessageMapper;
-
 
20
use LeadersLinked\Mapper\UserMapper;
-
 
21
use LeadersLinked\Mapper\UserProfileMapper;
19
use LeadersLinked\Mapper\CompanyUserRoleMapper;
22
use LeadersLinked\Mapper\CompanyUserRoleMapper;
20
use LeadersLinked\Model\Role;
23
use LeadersLinked\Model\Role;
21
use LeadersLinked\Library\Functions;
24
use LeadersLinked\Library\Functions;
-
 
25
use LeadersLinked\Mapper\ConnectionMapper;
-
 
26
use LeadersLinked\Mapper\LocationMapper;
22
use LeadersLinked\Mapper\PostMapper;
27
use LeadersLinked\Mapper\PostMapper;
-
 
28
use LeadersLinked\Mapper\ProfileVisitMapper;
23
use LeadersLinked\Model\Post;
29
use LeadersLinked\Model\Post;
Línea 24... Línea 30...
24
 
30
 
25
class HomeController extends AbstractActionController
31
class HomeController extends AbstractActionController
26
{
32
{
27
    /**
33
    /**
28
     *
34
     *
29
     * @var AdapterInterface
35
     * @var AdapterInterface
30
     */
36
     */
31
    private $adapter;
37
    private $adapter;
32
    
38
 
33
    
39
 
34
    /**
40
    /**
35
     *
41
     *
36
     * @var AbstractAdapter
42
     * @var AbstractAdapter
37
     */
43
     */
38
    private $cache;
44
    private $cache;
39
    
45
 
40
    /**
46
    /**
41
     *
47
     *
42
     * @var  LoggerInterface
48
     * @var  LoggerInterface
43
     */
49
     */
Línea 44... Línea 50...
44
    private $logger;
50
    private $logger;
45
 
51
 
46
    
52
 
47
    /**
53
    /**
48
     *
54
     *
49
     * @var array
55
     * @var array
50
     */
56
     */
51
    private $config;
57
    private $config;
52
    
58
 
53
    /**
59
    /**
54
     *
60
     *
55
     * @param AdapterInterface $adapter
61
     * @param AdapterInterface $adapter
56
     * @param AbstractAdapter $cache
62
     * @param AbstractAdapter $cache
57
     * @param LoggerInterface $logger
63
     * @param LoggerInterface $logger
58
     * @param array $config
64
     * @param array $config
59
     */
65
     */
60
    public function __construct($adapter, $cache , $logger,  $config)
66
    public function __construct($adapter, $cache, $logger,  $config)
61
    {
67
    {
62
        $this->adapter      = $adapter;
68
        $this->adapter      = $adapter;
63
        $this->cache        = $cache;
69
        $this->cache        = $cache;
64
        $this->logger       = $logger;
-
 
65
        $this->config       = $config;
70
        $this->logger       = $logger;
66
        
71
        $this->config       = $config;
67
    }
72
    }
68
    
73
 
69
    
74
 
70
    
75
 
Línea 71... Línea 76...
71
    public function indexAction()
76
    public function indexAction()
72
    {
77
    {
73
 
78
 
74
        $authService = new \Laminas\Authentication\AuthenticationService();
79
        $authService = new \Laminas\Authentication\AuthenticationService();
75
        if($authService->hasIdentity()) {
80
        if ($authService->hasIdentity()) {
76
            return $this->redirect()->toRoute('dashboard');    
81
            return $this->redirect()->toRoute('dashboard');
77
        } else {
82
        } else {
78
            return $this->redirect()->toRoute('signin');    
83
            return $this->redirect()->toRoute('signin');
79
        }
84
        }
80
    }
85
    }
81
    
86
 
82
    
87
 
83
    public function dashboardAction()
88
    public function dashboardAction()
84
    {
89
    {
85
        $this->layout()->setTemplate('layout/layout.phtml');
90
        $this->layout()->setTemplate('layout/layout.phtml');
86
        $viewModel = new ViewModel();
91
        $viewModel = new ViewModel();
87
        $viewModel->setTemplate('leaders-linked/home/dashboard.phtml');
92
        $viewModel->setTemplate('leaders-linked/home/dashboard.phtml');
88
        return $viewModel ;
93
        return $viewModel;
89
    }
94
    }
90
    
95
 
91
    
96
 
92
    
97
 
93
    public function privacyPolicyAction()
98
    public function privacyPolicyAction()
94
    {
99
    {
95
        $pageMapper = PageMapper::getInstance($this->adapter);
100
        $pageMapper = PageMapper::getInstance($this->adapter);
96
        $page = $pageMapper->fetchOne(Page::PAGE_ID_PRIVACY_POLICY);
101
        $page = $pageMapper->fetchOne(Page::PAGE_ID_PRIVACY_POLICY);
97
        
102
 
98
        $this->layout()->setTemplate('layout/layout.phtml');
103
        $this->layout()->setTemplate('layout/layout.phtml');
99
        $viewModel = new ViewModel();
104
        $viewModel = new ViewModel();
100
        $viewModel->setTemplate('leaders-linked/home/privacy-policy.phtml');
-
 
101
        $viewModel->setVariable('page', $page);
-
 
102
        return $viewModel ;
105
        $viewModel->setTemplate('leaders-linked/home/privacy-policy.phtml');
103
        
106
        $viewModel->setVariable('page', $page);
104
        
107
        return $viewModel;
105
    }
108
    }
106
    
109
 
107
    public function cookiesAction()
110
    public function cookiesAction()
108
    {
111
    {
109
        $pageMapper = PageMapper::getInstance($this->adapter);
112
        $pageMapper = PageMapper::getInstance($this->adapter);
110
        $page = $pageMapper->fetchOne(Page::PAGE_ID_COOKIES);
113
        $page = $pageMapper->fetchOne(Page::PAGE_ID_COOKIES);
111
        
114
 
112
        $this->layout()->setTemplate('layout/layout.phtml');
115
        $this->layout()->setTemplate('layout/layout.phtml');
113
        $viewModel = new ViewModel();
116
        $viewModel = new ViewModel();
114
        $viewModel->setTemplate('leaders-linked/home/cookies.phtml');
-
 
115
        $viewModel->setVariable('page', $page);
-
 
116
        return $viewModel ;
117
        $viewModel->setTemplate('leaders-linked/home/cookies.phtml');
117
        
118
        $viewModel->setVariable('page', $page);
118
        
119
        return $viewModel;
119
    }
120
    }
120
    
121
 
121
    public function professionalismPolicyAction()
122
    public function professionalismPolicyAction()
122
    {
123
    {
123
        //
124
        //
124
        
125
 
125
        $pageMapper = PageMapper::getInstance($this->adapter);
126
        $pageMapper = PageMapper::getInstance($this->adapter);
126
        $page = $pageMapper->fetchOne(Page::PAGE_ID_PROFESSIONALISM_POLICY);
127
        $page = $pageMapper->fetchOne(Page::PAGE_ID_PROFESSIONALISM_POLICY);
127
        
128
 
128
        $this->layout()->setTemplate('layout/layout.phtml');
129
        $this->layout()->setTemplate('layout/layout.phtml');
129
        $viewModel = new ViewModel();
130
        $viewModel = new ViewModel();
130
        $viewModel->setTemplate('leaders-linked/home/professionalism-policy');
131
        $viewModel->setTemplate('leaders-linked/home/professionalism-policy');
131
        $viewModel->setVariable('page', $page);
132
        $viewModel->setVariable('page', $page);
132
        return $viewModel ;
133
        return $viewModel;
133
    }
134
    }
134
    
135
 
135
    
136
 
136
    public function termsAndConditionsAction()
137
    public function termsAndConditionsAction()
137
    {
138
    {
138
        $pageMapper = PageMapper::getInstance($this->adapter);
139
        $pageMapper = PageMapper::getInstance($this->adapter);
139
        $page = $pageMapper->fetchOne(Page::PAGE_ID_TERMS_AND_CONDITIONS);
140
        $page = $pageMapper->fetchOne(Page::PAGE_ID_TERMS_AND_CONDITIONS);
140
        
141
 
141
        $this->layout()->setTemplate('layout/layout.phtml');
142
        $this->layout()->setTemplate('layout/layout.phtml');
142
        $viewModel = new ViewModel();
143
        $viewModel = new ViewModel();
143
        $viewModel->setTemplate('leaders-linked/home/terms-and-conditions.phtml');
-
 
144
        $viewModel->setVariable('page', $page);
-
 
145
        return $viewModel ;
144
        $viewModel->setTemplate('leaders-linked/home/terms-and-conditions.phtml');
146
        
145
        $viewModel->setVariable('page', $page);
147
        
146
        return $viewModel;
148
    }
147
    }
Línea 149... Línea 148...
149
    
148
 
150
    public function checkSessionAction()
149
    public function checkSessionAction()
151
    {
150
    {
152
 
151
 
153
        $request = $this->getRequest();
152
        $request = $this->getRequest();
154
        if($request->isGet()) {
153
        if ($request->isGet()) {
155
            
154
 
156
            $currentUserPlugin = $this->plugin('currentUserPlugin');
155
            $currentUserPlugin = $this->plugin('currentUserPlugin');
157
            if(!$currentUserPlugin->hasIdentity()) {
156
            if (!$currentUserPlugin->hasIdentity()) {
158
                $flashMessenger = $this->plugin('FlashMessenger');
157
                $flashMessenger = $this->plugin('FlashMessenger');
159
                $flashMessenger->addErrorMessage('ERROR_SESSION_NOT_FOUND');
158
                $flashMessenger->addErrorMessage('ERROR_SESSION_NOT_FOUND');
160
                
159
 
161
                $response = [
160
                $response = [
162
                    'success' => false,
161
                    'success' => false,
163
                    'data' => [
162
                    'data' => [
164
                        'message' =>  'ERROR_SESSION_NOT_FOUND',
163
                        'message' =>  'ERROR_SESSION_NOT_FOUND',
165
                        'url' => $this->url()->fromRoute('signout')
164
                        'url' => $this->url()->fromRoute('signout')
166
                    ]
-
 
167
                ];
165
                    ]
168
                
166
                ];
169
                return new JsonModel($response);
167
 
170
                
168
                return new JsonModel($response);
171
            }
169
            }
172
            
170
 
173
            $currentUser = $currentUserPlugin->getUser();
171
            $currentUser = $currentUserPlugin->getUser();
174
            
172
 
175
           
173
 
176
            if($currentUser->last_activity_on) {
174
            if ($currentUser->last_activity_on) {
Línea 177... Línea 175...
177
                $last_activity_on = strtotime($currentUser->last_activity_on);
175
                $last_activity_on = strtotime($currentUser->last_activity_on);
178
            } else {
176
            } else {
179
                $last_activity_on = strtotime('-1 day');
177
                $last_activity_on = strtotime('-1 day');
180
            }
178
            }
Línea 181... Línea 179...
181
 
179
 
182
            $expiry_time = $last_activity_on + $this->config['leaderslinked.security.last_activity_expired'];
180
            $expiry_time = $last_activity_on + $this->config['leaderslinked.security.last_activity_expired'];
183
            if (time() > $expiry_time) {
181
            if (time() > $expiry_time) {
184
                    //$flashMessenger = $this->plugin('FlashMessenger');
182
                //$flashMessenger = $this->plugin('FlashMessenger');
Línea 192... Línea 190...
192
                    ]
190
                    ]
193
                ];
191
                ];
194
            } else {
192
            } else {
195
                $notificationMapper = NotificationMapper::getInstance($this->adapter);
193
                $notificationMapper = NotificationMapper::getInstance($this->adapter);
196
                $total_notifications = $notificationMapper->fetchUnreadNotificationsCount($currentUser->id);
194
                $total_notifications = $notificationMapper->fetchUnreadNotificationsCount($currentUser->id);
197
                        
195
 
198
                $messageMapper = MessageMapper::getInstance($this->adapter);  
196
                $messageMapper = MessageMapper::getInstance($this->adapter);
199
                $total_messages =  $messageMapper->fetchCountUnreadMessagesReceiverId($currentUser->id);
197
                $total_messages =  $messageMapper->fetchCountUnreadMessagesReceiverId($currentUser->id);
200
                $response = [
198
                $response = [
201
                    'success' => true,
199
                    'success' => true,
202
                    'data' => [
200
                    'data' => [
203
                        'total_notifications' => $total_notifications,
201
                        'total_notifications' => $total_notifications,
Línea 209... Línea 207...
209
            $response = [
207
            $response = [
210
                'success' => false,
208
                'success' => false,
211
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
209
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
212
            ];
210
            ];
213
        }
211
        }
214
        
212
 
215
        return new JsonModel($response);
213
        return new JsonModel($response);
216
    }
214
    }
217
    
215
 
218
    public function notificationsAction()
216
    public function notificationsAction()
219
    {
217
    {
220
        $request = $this->getRequest();
218
        $request = $this->getRequest();
221
        if($request->isGet()) {
219
        if ($request->isGet()) {
222
            
220
 
223
            $currentUserPlugin = $this->plugin('currentUserPlugin');
221
            $currentUserPlugin = $this->plugin('currentUserPlugin');
224
            $currentUser = $currentUserPlugin->getUser();
222
            $currentUser = $currentUserPlugin->getUser();
225
            
223
 
-
 
224
            $userMapper = UserMapper::getInstance($this->adapter);
-
 
225
            $user = $userMapper->fetchOne($currentUser->id);
-
 
226
 
-
 
227
            $userProfileMapper = UserProfileMapper::getInstance($this->adapter);
-
 
228
            $userProfile = $userProfileMapper->fetchOnePublicByUserId($currentUser->id);
-
 
229
 
226
            $headers  = $request->getHeaders();
230
            $headers  = $request->getHeaders();
227
            
231
 
228
            $isJson = false;
232
            $isJson = false;
229
            if($headers->has('Accept')) {
233
            if ($headers->has('Accept')) {
230
                $accept = $headers->get('Accept');
234
                $accept = $headers->get('Accept');
231
                
235
 
232
                $prioritized = $accept->getPrioritized();
236
                $prioritized = $accept->getPrioritized();
233
                
237
 
234
                foreach($prioritized as $key => $value) {
238
                foreach ($prioritized as $key => $value) {
235
                    $raw = trim($value->getRaw());
239
                    $raw = trim($value->getRaw());
236
                    
240
 
237
                    if(!$isJson) {
241
                    if (!$isJson) {
238
                        $isJson = strpos($raw, 'json');
242
                        $isJson = strpos($raw, 'json');
239
                    }
243
                    }
240
                    
-
 
241
                }
244
                }
242
            }
245
            }
243
            
246
 
244
            if($isJson) {
247
            if ($isJson) {
245
            
248
 
246
               
249
 
247
                $notificationMapper = NotificationMapper::getInstance($this->adapter);
250
                $notificationMapper = NotificationMapper::getInstance($this->adapter);
248
                $records = $notificationMapper->fetchAllsUnreadByUserId($currentUser->id);
251
                $records = $notificationMapper->fetchAllsUnreadByUserId($currentUser->id);
249
                
252
 
250
                $items = [];
253
                $items = [];
251
                foreach($records as $record)
254
                foreach ($records as $record) {
252
                {
-
 
253
                    $dt = \DateTime::createFromFormat('Y-m-d H:i:s', $record->added_on);
255
                    $dt = \DateTime::createFromFormat('Y-m-d H:i:s', $record->added_on);
254
                    
256
 
255
                    array_push($items,[
257
                    array_push($items, [
256
                        'message' => $record->message,
258
                        'message' => $record->message,
257
                        'link' => $record->url,
259
                        'link' => $record->url,
258
                        'time_elapsed' => Functions::timeElapsedString($dt->getTimestamp())
260
                        'time_elapsed' => Functions::timeElapsedString($dt->getTimestamp())
259
                    ]);
261
                    ]);
260
                    
-
 
261
                }
262
                }
262
                   
263
 
263
                $response = [
264
                $response = [
264
                    'success' => true,
265
                    'success' => true,
265
                    'data' => $items
266
                    'data' => $items
266
                ];
267
                ];
267
            } else {
268
            } else {
-
 
269
 
-
 
270
                if ($user->location_id) {
-
 
271
                    $locationMapper = LocationMapper::getInstance($this->adapter);
-
 
272
                    $location = $locationMapper->fetchOne($user->location_id);
-
 
273
 
-
 
274
                    $country = $location->country;
-
 
275
                } else {
-
 
276
                    $country = '';
-
 
277
                }
-
 
278
 
-
 
279
                $profileVisitMapper = ProfileVisitMapper::getInstance($this->adapter);
-
 
280
                $visits = $profileVisitMapper->getTotalByVisitedId($currentUser->id);
-
 
281
 
-
 
282
                $connectionMapper = ConnectionMapper::getInstance($this->adapter);
-
 
283
                $connections = $connectionMapper->fetchTotalConnectionByUser($currentUser->id);
-
 
284
 
268
                $this->layout()->setTemplate('layout/layout.phtml');
285
                $this->layout()->setTemplate('layout/layout.phtml');
269
                $viewModel = new ViewModel();
286
                $viewModel = new ViewModel();
-
 
287
                $viewModel->setVariables([
-
 
288
                    'image' => $this->url()->fromRoute('storage', ['type' => 'user', 'code' => $user->uuid, 'filename' => $user->image]),
-
 
289
                    'fullname' => trim($user->first_name . ' ' . $user->last_name),
-
 
290
                    'description' => empty($userProfile->description) ? '' :  trim($userProfile->description),
-
 
291
                    'country' => $country,
-
 
292
                    'visits' => $visits,
-
 
293
                    'connections' => $connections
-
 
294
                ]);
270
               
295
 
271
                $viewModel->setTemplate('leaders-linked/home/notifications.phtml');
296
                $viewModel->setTemplate('leaders-linked/home/notifications.phtml');
272
                return $viewModel ;
297
                return $viewModel;
273
            }
298
            }
274
             
-
 
275
        } else {
299
        } else {
276
            $response = [
300
            $response = [
277
                'success' => false,
301
                'success' => false,
278
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
302
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
279
            ];
303
            ];
280
        }
304
        }
281
        
305
 
282
        return new JsonModel($response);
306
        return new JsonModel($response);
283
    }
307
    }
284
    
308
 
285
    
309
 
286
    public function postAction()
310
    public function postAction()
287
    {
311
    {
288
        $id = $this->params()->fromRoute('id');
312
        $id = $this->params()->fromRoute('id');
289
        
313
 
290
        $postMapper = PostMapper::getInstance($this->adapter);
314
        $postMapper = PostMapper::getInstance($this->adapter);
291
        $post = $postMapper->fetchOneByUuid($id);
315
        $post = $postMapper->fetchOneByUuid($id);
292
        
316
 
293
        if(!$post || $post->status != Post::STATUS_ACTIVE) {
317
        if (!$post || $post->status != Post::STATUS_ACTIVE) {
294
            $flashMessenger = $this->plugin('FlashMessenger');
318
            $flashMessenger = $this->plugin('FlashMessenger');
295
            
319
 
296
            if(!$id) {
320
            if (!$id) {
297
                $flashMessenger->addErrorMessage('ERROR_POST_NOT_AVAILABLE');
321
                $flashMessenger->addErrorMessage('ERROR_POST_NOT_AVAILABLE');
298
                return $this->redirect()->toRoute('dashboard');
322
                return $this->redirect()->toRoute('dashboard');
299
            }
323
            }
300
            
-
 
301
            
-
 
302
        }
324
        }
303
        
325
 
304
        
326
 
305
        $this->layout()->setTemplate('layout/layout.phtml');
327
        $this->layout()->setTemplate('layout/layout.phtml');
306
        $viewModel = new ViewModel();
328
        $viewModel = new ViewModel();
307
        $viewModel->setTemplate('leaders-linked/home/post.phtml');
329
        $viewModel->setTemplate('leaders-linked/home/post.phtml');
308
        $viewModel->setVariable('post', $post);
330
        $viewModel->setVariable('post', $post);
309
        return $viewModel ;
331
        return $viewModel;
310
        
-
 
311
        
-
 
312
    }
332
    }
313
}
333
}