Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 6614 | Rev 6749 | 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\Mapper\PostMapper;
13
use LeadersLinked\Mapper\FeedMapper;
5765 efrain 14
use LeadersLinked\Model\ContentReaction;
1 www 15
use LeadersLinked\Model\Feed;
16
use LeadersLinked\Mapper\LocationMapper;
17
use LeadersLinked\Mapper\UserMapper;
18
use LeadersLinked\Mapper\NotificationMapper;
19
use LeadersLinked\Mapper\UserProfileMapper;
20
use LeadersLinked\Mapper\ProfileVisitMapper;
21
use LeadersLinked\Mapper\ConnectionMapper;
22
use LeadersLinked\Form\Feed\CreateForm;
23
use LeadersLinked\Form\Feed\ShareForm;
4842 efrain 24
use LeadersLinked\Model\Network;
4911 efrain 25
use LeadersLinked\Library\Functions;
5205 efrain 26
use LeadersLinked\Mapper\CompanyMapper;
27
use LeadersLinked\Mapper\CompanyServiceMapper;
1 www 28
 
29
class DashboardController extends AbstractActionController
30
{
31
    /**
32
     *
33
     * @var AdapterInterface
34
     */
35
    private $adapter;
36
 
37
 
38
    /**
39
     *
40
     * @var AbstractAdapter
41
     */
42
    private $cache;
43
 
44
    /**
45
     *
46
     * @var  LoggerInterface
47
     */
48
    private $logger;
49
 
50
 
51
 
52
    /**
53
     *
54
     * @param AdapterInterface $adapter
55
     * @param AbstractAdapter $cache
56
     * @param LoggerInterface $logger
57
     * @param array $config
58
     */
59
    public function __construct($adapter, $cache , $logger, $config)
60
    {
61
        $this->adapter      = $adapter;
62
        $this->cache        = $cache;
63
        $this->logger       = $logger;
64
        $this->config       = $config;
65
 
66
 
67
    }
68
 
69
 
70
    public function indexAction()
71
    {
5765 efrain 72
 
73
 
74
 
1 www 75
        $currentUserPlugin = $this->plugin('currentUserPlugin');
76
        $currentUser = $currentUserPlugin->getUser();
77
 
4842 efrain 78
        $currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
79
        $currentNetwork = $currentNetworkPlugin->getNetwork();
80
 
1 www 81
        $userMapper = UserMapper::getInstance($this->adapter);
82
        $user = $userMapper->fetchOne($currentUser->id);
83
 
84
        $request = $this->getRequest();
85
        if($request->isGet()) {
86
            $headers  = $request->getHeaders();
87
 
88
            $isJson = false;
89
            if($headers->has('Accept')) {
90
                $accept = $headers->get('Accept');
91
 
92
                $prioritized = $accept->getPrioritized();
93
 
94
                foreach($prioritized as $key => $value) {
95
                    $raw = trim($value->getRaw());
96
 
97
                    if(!$isJson) {
98
                        $isJson = strpos($raw, 'json');
99
                    }
100
 
101
                }
102
            }
103
 
104
            if($isJson) {
6614 efrain 105
                $acl = $this->getEvent()->getViewModel()->getVariable('acl');
6605 efrain 106
 
107
                $feed_uuid = $this->params()->fromRoute('feed');
108
                if($feed_uuid) {
109
                    $feedMapper = FeedMapper::getInstance($this->adapter);
110
                    $feed = $feedMapper->fetchOneByUuidAnyStatus($feed_uuid);
111
                } else {
112
                    $feed = '';
113
                }
114
 
115
 
1 www 116
                $profileVisitMapper = ProfileVisitMapper::getInstance($this->adapter);
4714 efrain 117
                //$visits = $profileVisitMapper->getTotalByVisitedId($currentUser->id);
1 www 118
 
4714 efrain 119
                $visits = $profileVisitMapper->getTotalByVisitedIdGroupVisitorId($currentUser->id);
120
 
4842 efrain 121
                if($currentNetwork->relationship_user_mode == Network::RELATIONSHIP_USER_MODE_USER_2_USER)  {
122
                    $connectionMapper = ConnectionMapper::getInstance($this->adapter);
123
                    $connections = $connectionMapper->fetchTotalConnectionByUser($currentUser->id);
124
                } else {
125
                    if($currentNetwork->default == Network::DEFAULT_YES) {
126
                        $connections = $userMapper->fetchCountActiveByDefaultNetworkId($currentNetwork->id);
127
                    } else {
128
                        $connections = $userMapper->fetchCountActiveByOtherNetworkId($currentNetwork->id);
129
                    }
130
                }
1 www 131
 
132
                if($user->location_id) {
133
                    $locationMapper = LocationMapper::getInstance($this->adapter);
134
                    $location = $locationMapper->fetchOne($user->location_id);
135
 
136
                    $country = $location->country;
137
                } else {
138
                    $country = '';
139
                }
140
 
141
                $image_size = $this->config['leaderslinked.image_sizes.feed_image_upload'];
142
 
6605 efrain 143
                if($user->location_id) {
144
                    $locationMapper = LocationMapper::getInstance($this->adapter);
145
                    $location = $locationMapper->fetchOne($user->location_id);
146
 
147
                    $country = $location->country;
148
                } else {
149
                    $country = '';
150
                }
151
 
152
                $userProfileMapper = UserProfileMapper::getInstance($this->adapter);
153
                $userProfile = $userProfileMapper->fetchOnePublicByUserId($currentUser->id);
154
 
155
 
156
                if($feed) {
157
                    $routeTimeline = $this->url()->fromRoute('feed/timeline', ['id' => $currentUser->uuid, 'type' => 'user', 'feed' => $feed->uuid]);
158
                } else {
159
                    $routeTimeline = $this->url()->fromRoute('feed/timeline', ['id' => $currentUser->uuid, 'type' => 'user']);
160
                }
161
 
6614 efrain 162
                $allowDailyPulse    = $acl->isAllowed($currentUser->usertype_id, 'daily-pulse') ? 1 : 0;
163
                if ($allowDailyPulse) {
6615 efrain 164
                    $routeDailyPulse = $this->url()->fromRoute('daily-pulse');
6614 efrain 165
                } else {
166
                    $routeDailyPulse = '';
167
                }
168
 
169
 
170
 
1 www 171
                return new JsonModel([
172
                    'user_uuid' => $user->uuid,
173
                    'image' => $this->url()->fromRoute('storage', ['type' => 'user', 'code' => $user->uuid, 'filename' => $user->image]),
174
                    'fullname' => trim($user->first_name . ' ' . $user->last_name),
6605 efrain 175
                    'description' => empty($userProfile->description) ? '' :  trim($userProfile->description) ,
1 www 176
                    'country' => $country,
177
                    'visits' => $visits,
178
                    'connections' => $connections,
179
                    'image_size' => $image_size,
6605 efrain 180
                    'feed' => '',
181
                    'routeTimeline' => $routeTimeline,
6614 efrain 182
                    'routeDailyPulse' => $routeDailyPulse,
6605 efrain 183
                    'moodle_name' => $currentNetwork->moodle_name ?  $currentNetwork->moodle_name : '',
184
                    'moodle_image' => $this->url()->fromRoute('storage-network', ['type' => 'moodle']),
185
                    'microlearning_appstore' => $currentNetwork->microlearning_appstore ?  $currentNetwork->microlearning_appstore : '' ,
186
                    'microlearning_playstore' => $currentNetwork->microlearning_playstore ? $currentNetwork->microlearning_playstore : '',
187
 
188
 
1 www 189
                ]);
190
 
191
            } else {
3298 efrain 192
 
1 www 193
                $feed_uuid = $this->params()->fromRoute('feed');
194
                if($feed_uuid) {
195
                    $feedMapper = FeedMapper::getInstance($this->adapter);
3146 efrain 196
                    $feed = $feedMapper->fetchOneByUuidAnyStatus($feed_uuid);
1 www 197
                } else {
3298 efrain 198
                    $feed = '';
1 www 199
                }
200
 
201
 
202
 
203
 
204
                $profileVisitMapper = ProfileVisitMapper::getInstance($this->adapter);
4714 efrain 205
               // $visits = $profileVisitMapper->getTotalByVisitedId($currentUser->id);
206
                $visits = $profileVisitMapper->getTotalByVisitedIdGroupVisitorId($currentUser->id);
1 www 207
 
208
 
4842 efrain 209
                if($currentNetwork->relationship_user_mode == Network::RELATIONSHIP_USER_MODE_USER_2_USER)  {
210
                    $connectionMapper = ConnectionMapper::getInstance($this->adapter);
211
                    $connections = $connectionMapper->fetchTotalConnectionByUser($currentUser->id);
212
                } else {
213
                    if($currentNetwork->default == Network::DEFAULT_YES) {
214
                        $connections = $userMapper->fetchCountActiveByDefaultNetworkId($currentNetwork->id);
215
                    } else {
216
                        $connections = $userMapper->fetchCountActiveByOtherNetworkId($currentNetwork->id);
217
                    }
218
 
219
                    $connections--;
220
                }
1 www 221
 
4842 efrain 222
 
223
 
1 www 224
                if($user->location_id) {
225
                    $locationMapper = LocationMapper::getInstance($this->adapter);
226
                    $location = $locationMapper->fetchOne($user->location_id);
227
 
228
                    $country = $location->country;
229
                } else {
230
                    $country = '';
231
                }
232
 
233
                $userProfileMapper = UserProfileMapper::getInstance($this->adapter);
234
                $userProfile = $userProfileMapper->fetchOnePublicByUserId($currentUser->id);
235
 
236
 
5751 efrain 237
                $imageSize = $this->config['leaderslinked.image_sizes.feed_image_upload'];
1 www 238
 
239
                $formFeed = new CreateForm();
240
                $formShare = new ShareForm();
241
 
3146 efrain 242
 
3298 efrain 243
                if($feed) {
5751 efrain 244
                    $routeTimeline = $this->url()->fromRoute('feed/timeline', ['id' => $currentUser->uuid, 'type' => 'user', 'feed' => $feed->uuid]);
3146 efrain 245
                } else {
5751 efrain 246
                    $routeTimeline = $this->url()->fromRoute('feed/timeline', ['id' => $currentUser->uuid, 'type' => 'user']);
3146 efrain 247
                }
248
 
249
 
250
 
251
 
252
 
1 www 253
                $this->layout()->setTemplate('layout/layout.phtml');
254
                $viewModel = new ViewModel();
255
                $viewModel->setVariables([
256
                    'user_uuid' => $user->uuid,
257
                    'image' => $this->url()->fromRoute('storage', ['type' => 'user', 'code' => $user->uuid, 'filename' => $user->image]),
258
                    'fullname' => trim($user->first_name . ' ' . $user->last_name),
259
                    'description' => empty($userProfile->description) ? '' :  trim($userProfile->description) ,
260
                    'country' => $country,
261
                    'visits' => $visits,
262
                    'connections' => $connections,
3146 efrain 263
                    'feed' => '',
5751 efrain 264
                    'routeTimeline' => $routeTimeline,
1 www 265
                    'formFeed' => $formFeed,
266
                    'formShare' => $formShare,
5751 efrain 267
                    'imageSize' => $imageSize,
5848 efrain 268
                    'moodle_name' => $currentNetwork->moodle_name,
269
                    'moodle_image' => $this->url()->fromRoute('storage-network', ['type' => 'moodle']),
270
                    'microlearning_appstore' => $currentNetwork->microlearning_appstore,
271
                    'microlearning_playstore' => $currentNetwork->microlearning_playstore,
1 www 272
                ]);
273
                $viewModel->setTemplate('leaders-linked/dashboard/index.phtml');
274
                return $viewModel ;
275
            }
276
        }
277
 
278
        return new JsonModel([
279
           'success' => false,
280
           'data' => 'ERROR_METHOD_NOT_ALLOWED'
281
        ]);
282
    }
283
 
60 efrain 284
    public function dashboard2Action()
1 www 285
    {
60 efrain 286
        $currentUserPlugin = $this->plugin('currentUserPlugin');
287
        $currentUser = $currentUserPlugin->getUser();
1 www 288
 
60 efrain 289
        $userMapper = UserMapper::getInstance($this->adapter);
290
        $user = $userMapper->fetchOne($currentUser->id);
291
 
292
        $request = $this->getRequest();
293
        if($request->isGet()) {
294
 
295
 
296
            $headers  = $request->getHeaders();
297
 
298
            $isJson = false;
299
            if($headers->has('Accept')) {
300
                $accept = $headers->get('Accept');
301
 
302
                $prioritized = $accept->getPrioritized();
303
 
304
                foreach($prioritized as $key => $value) {
305
                    $raw = trim($value->getRaw());
306
 
307
                    if(!$isJson) {
308
                        $isJson = strpos($raw, 'json');
309
                    }
310
 
311
                }
312
            }
313
 
314
            if($isJson) {
315
                $profileVisitMapper = ProfileVisitMapper::getInstance($this->adapter);
316
                $visits = $profileVisitMapper->getTotalByVisitedId($currentUser->id);
317
 
318
                $connectionMapper = ConnectionMapper::getInstance($this->adapter);
319
                $connections = $connectionMapper->fetchTotalConnectionByUser($currentUser->id);
320
 
321
 
322
                if($user->location_id) {
323
                    $locationMapper = LocationMapper::getInstance($this->adapter);
324
                    $location = $locationMapper->fetchOne($user->location_id);
325
 
326
                    $country = $location->country;
327
                } else {
328
                    $country = '';
329
                }
330
 
331
                $image_size = $this->config['leaderslinked.image_sizes.feed_image_upload'];
332
 
333
                return new JsonModel([
334
                    'user_uuid' => $user->uuid,
335
                    'image' => $this->url()->fromRoute('storage', ['type' => 'user', 'code' => $user->uuid, 'filename' => $user->image]),
336
                    'fullname' => trim($user->first_name . ' ' . $user->last_name),
337
                    'country' => $country,
338
                    'visits' => $visits,
339
                    'connections' => $connections,
340
                    'image_size' => $image_size,
341
                ]);
342
 
343
            } else {
344
                $feed_uuid = $this->params()->fromRoute('feed');
345
                if($feed_uuid) {
346
                    $feedMapper = FeedMapper::getInstance($this->adapter);
347
                    $feed = $feedMapper->fetchOneByUuid($feed_uuid);
348
                    if($feed && $feed->type == Feed::TYPE_UPDATE && $feed->user_id == $currentUser->id && $feed->status == Feed::STATUS_PUBLISHED) {
349
                        $notificationMapper = NotificationMapper::getInstance($this->adapter);
350
                        $notificationMapper->markAllNotificationsAsReadByUserIdAndFeedId($currentUser->id, $feed->id);
351
                    } else {
352
                        $feed_uuid = '';
353
                    }
354
                } else {
355
                    $feed_uuid = '';
356
                }
357
 
358
 
359
 
360
 
361
                $profileVisitMapper = ProfileVisitMapper::getInstance($this->adapter);
362
                $visits = $profileVisitMapper->getTotalByVisitedId($currentUser->id);
363
 
364
                $connectionMapper = ConnectionMapper::getInstance($this->adapter);
365
                $connections = $connectionMapper->fetchTotalConnectionByUser($currentUser->id);
366
 
367
 
368
                if($user->location_id) {
369
                    $locationMapper = LocationMapper::getInstance($this->adapter);
370
                    $location = $locationMapper->fetchOne($user->location_id);
371
 
372
                    $country = $location->country;
373
                } else {
374
                    $country = '';
375
                }
376
 
377
                $userProfileMapper = UserProfileMapper::getInstance($this->adapter);
378
                $userProfile = $userProfileMapper->fetchOnePublicByUserId($currentUser->id);
379
 
380
 
381
                $image_size = $this->config['leaderslinked.image_sizes.feed_image_upload'];
382
 
383
                $formFeed = new CreateForm();
384
                $formShare = new ShareForm();
385
 
386
                $this->layout()->setTemplate('layout/layout.phtml');
387
                $viewModel = new ViewModel();
388
                $viewModel->setVariables([
389
                    'user_uuid' => $user->uuid,
390
                    'image' => $this->url()->fromRoute('storage', ['type' => 'user', 'code' => $user->uuid, 'filename' => $user->image]),
391
                    'fullname' => trim($user->first_name . ' ' . $user->last_name),
392
                    'description' => empty($userProfile->description) ? '' :  trim($userProfile->description) ,
393
                    'country' => $country,
394
                    'visits' => $visits,
395
                    'connections' => $connections,
396
                    'feed' => $feed_uuid,
397
                    'formFeed' => $formFeed,
398
                    'formShare' => $formShare,
399
                    'image_size' => $image_size,
5848 efrain 400
 
60 efrain 401
                ]);
402
                $viewModel->setTemplate('leaders-linked/dashboard/dashboard2.phtml');
403
                return $viewModel ;
404
            }
405
        }
406
 
1 www 407
        return new JsonModel([
60 efrain 408
            'success' => false,
409
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
1 www 410
        ]);
411
    }
412
}