Proyectos de Subversion LeadersLinked - Services

Rev

Rev 283 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
<?php
2
declare(strict_types=1);
3
 
4
namespace LeadersLinked\Controller;
5
 
6
use Laminas\Db\Adapter\AdapterInterface;
7
 
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;
14
use LeadersLinked\Model\ContentReaction;
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;
24
use LeadersLinked\Model\Network;
25
use LeadersLinked\Library\Functions;
26
use LeadersLinked\Mapper\CompanyMapper;
27
use LeadersLinked\Mapper\CompanyServiceMapper;
283 www 28
use LeadersLinked\Library\Storage;
1 efrain 29
 
30
class DashboardController extends AbstractActionController
31
{
32
    /**
33
     *
34
     * @var \Laminas\Db\Adapter\AdapterInterface
35
     */
36
    private $adapter;
37
 
38
    /**
39
     *
40
     * @var \LeadersLinked\Cache\CacheInterface
41
     */
42
    private $cache;
43
 
44
 
45
    /**
46
     *
47
     * @var \Laminas\Log\LoggerInterface
48
     */
49
    private $logger;
50
 
51
    /**
52
     *
53
     * @var array
54
     */
55
    private $config;
56
 
57
 
58
    /**
59
     *
60
     * @var \Laminas\Mvc\I18n\Translator
61
     */
62
    private $translator;
63
 
64
 
65
    /**
66
     *
67
     * @param \Laminas\Db\Adapter\AdapterInterface $adapter
68
     * @param \LeadersLinked\Cache\CacheInterface $cache
69
     * @param \Laminas\Log\LoggerInterface LoggerInterface $logger
70
     * @param array $config
71
     * @param \Laminas\Mvc\I18n\Translator $translator
72
     */
73
    public function __construct($adapter, $cache, $logger, $config, $translator)
74
    {
75
        $this->adapter      = $adapter;
76
        $this->cache        = $cache;
77
        $this->logger       = $logger;
78
        $this->config       = $config;
79
        $this->translator   = $translator;
80
    }
81
 
82
 
83
    public function indexAction()
84
    {
85
 
86
 
87
 
88
        $currentUserPlugin = $this->plugin('currentUserPlugin');
89
        $currentUser = $currentUserPlugin->getUser();
90
 
91
        $currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
92
        $currentNetwork = $currentNetworkPlugin->getNetwork();
93
 
94
        $userMapper = UserMapper::getInstance($this->adapter);
95
        $user = $userMapper->fetchOne($currentUser->id);
96
 
97
        $request = $this->getRequest();
98
        if($request->isGet()) {
99
            $headers  = $request->getHeaders();
100
 
101
            $isJson = false;
102
            if($headers->has('Accept')) {
103
                $accept = $headers->get('Accept');
104
 
105
                $prioritized = $accept->getPrioritized();
106
 
107
                foreach($prioritized as $key => $value) {
108
                    $raw = trim($value->getRaw());
109
 
110
                    if(!$isJson) {
111
                        $isJson = strpos($raw, 'json');
112
                    }
113
 
114
                }
115
            }
116
 
117
            if($isJson) {
118
                $acl = $this->getEvent()->getViewModel()->getVariable('acl');
119
 
120
                $feed_uuid = $this->params()->fromRoute('feed');
121
                if($feed_uuid) {
122
                    $feedMapper = FeedMapper::getInstance($this->adapter);
123
                    $feed = $feedMapper->fetchOneByUuidAnyStatus($feed_uuid);
124
                } else {
125
                    $feed = '';
126
                }
127
 
128
 
129
                $profileVisitMapper = ProfileVisitMapper::getInstance($this->adapter);
130
                //$visits = $profileVisitMapper->getTotalByVisitedId($currentUser->id);
131
 
132
                $visits = $profileVisitMapper->getTotalByVisitedIdGroupVisitorId($currentUser->id);
133
 
134
                if($currentNetwork->relationship_user_mode == Network::RELATIONSHIP_USER_MODE_USER_2_USER)  {
135
                    $connectionMapper = ConnectionMapper::getInstance($this->adapter);
136
                    $connections = $connectionMapper->fetchTotalConnectionByUser($currentUser->id);
137
                } else {
138
                    if($currentNetwork->default == Network::DEFAULT_YES) {
139
                        $connections = $userMapper->fetchCountActiveByDefaultNetworkId($currentNetwork->id);
140
                    } else {
141
                        $connections = $userMapper->fetchCountActiveByOtherNetworkId($currentNetwork->id);
142
                    }
143
                }
144
 
145
                if($user->location_id) {
146
                    $locationMapper = LocationMapper::getInstance($this->adapter);
147
                    $location = $locationMapper->fetchOne($user->location_id);
148
 
149
                    $country = $location->country;
150
                } else {
151
                    $country = '';
152
                }
153
 
154
                $image_size = $this->config['leaderslinked.image_sizes.feed_image_upload'];
155
 
156
                if($user->location_id) {
157
                    $locationMapper = LocationMapper::getInstance($this->adapter);
158
                    $location = $locationMapper->fetchOne($user->location_id);
159
 
160
                    $country = $location->country;
161
                } else {
162
                    $country = '';
163
                }
164
 
165
                $userProfileMapper = UserProfileMapper::getInstance($this->adapter);
166
                $userProfile = $userProfileMapper->fetchOnePublicByUserId($currentUser->id);
167
 
168
 
169
                if($feed) {
170
                    $routeTimeline = $this->url()->fromRoute('feed/timeline', ['id' => $currentUser->uuid, 'type' => 'user', 'feed' => $feed->uuid]);
171
                } else {
172
                    $routeTimeline = $this->url()->fromRoute('feed/timeline', ['id' => $currentUser->uuid, 'type' => 'user']);
173
                }
174
 
175
                $allowDailyPulse    = $acl->isAllowed($currentUser->usertype_id, 'daily-pulse') ? 1 : 0;
176
                if ($allowDailyPulse) {
177
                    $routeDailyPulse = $this->url()->fromRoute('daily-pulse');
178
                } else {
179
                    $routeDailyPulse = '';
180
                }
181
 
333 www 182
                $storage = Storage::getInstance($this->config, $this->adapter);
283 www 183
                $path = $storage->getPathNetwork();
1 efrain 184
 
283 www 185
                if($currentNetwork->moodle_image) {
186
                    $moodle_image = $storage->getGenericImage($path, $currentNetwork->uuid, $currentNetwork->moodle_image);
187
                } else {
188
                    $moodle_image =  '';
189
                }
1 efrain 190
 
283 www 191
 
1 efrain 192
                return new JsonModel([
193
                    'user_uuid' => $user->uuid,
283 www 194
                    'image' => $storage->getUserImage($user),
1 efrain 195
                    'fullname' => trim($user->first_name . ' ' . $user->last_name),
196
                    'description' => empty($userProfile->description) ? '' :  trim($userProfile->description) ,
197
                    'country' => $country,
198
                    'visits' => $visits,
199
                    'connections' => $connections,
200
                    'image_size' => $image_size,
201
                    'feed' => '',
202
                    'routeTimeline' => $routeTimeline,
203
                    'routeDailyPulse' => $routeDailyPulse,
204
                    'moodle_name' => $currentNetwork->moodle_name ?  $currentNetwork->moodle_name : '',
283 www 205
                    'moodle_image' => $moodle_image,
212 efrain 206
                    'microlearning_name' => $currentNetwork->microlearning_name ?  $currentNetwork->microlearning_name : '' ,
1 efrain 207
                    'microlearning_appstore' => $currentNetwork->microlearning_appstore ?  $currentNetwork->microlearning_appstore : '' ,
208
                    'microlearning_playstore' => $currentNetwork->microlearning_playstore ? $currentNetwork->microlearning_playstore : '',
209
 
210
 
211
                ]);
212
 
213
            } else {
214
 
215
                $feed_uuid = $this->params()->fromRoute('feed');
216
                if($feed_uuid) {
217
                    $feedMapper = FeedMapper::getInstance($this->adapter);
218
                    $feed = $feedMapper->fetchOneByUuidAnyStatus($feed_uuid);
219
                } else {
220
                    $feed = '';
221
                }
222
 
223
 
224
 
225
 
226
                $profileVisitMapper = ProfileVisitMapper::getInstance($this->adapter);
227
               // $visits = $profileVisitMapper->getTotalByVisitedId($currentUser->id);
228
                $visits = $profileVisitMapper->getTotalByVisitedIdGroupVisitorId($currentUser->id);
229
 
230
 
231
                if($currentNetwork->relationship_user_mode == Network::RELATIONSHIP_USER_MODE_USER_2_USER)  {
232
                    $connectionMapper = ConnectionMapper::getInstance($this->adapter);
233
                    $connections = $connectionMapper->fetchTotalConnectionByUser($currentUser->id);
234
                } else {
235
                    if($currentNetwork->default == Network::DEFAULT_YES) {
236
                        $connections = $userMapper->fetchCountActiveByDefaultNetworkId($currentNetwork->id);
237
                    } else {
238
                        $connections = $userMapper->fetchCountActiveByOtherNetworkId($currentNetwork->id);
239
                    }
240
 
241
                    $connections--;
242
                }
243
 
244
 
245
 
246
                if($user->location_id) {
247
                    $locationMapper = LocationMapper::getInstance($this->adapter);
248
                    $location = $locationMapper->fetchOne($user->location_id);
249
 
250
                    $country = $location->country;
251
                } else {
252
                    $country = '';
253
                }
254
 
255
                $userProfileMapper = UserProfileMapper::getInstance($this->adapter);
256
                $userProfile = $userProfileMapper->fetchOnePublicByUserId($currentUser->id);
257
 
258
 
259
                $imageSize = $this->config['leaderslinked.image_sizes.feed_image_upload'];
260
 
261
                $formFeed = new CreateForm();
262
                $formShare = new ShareForm();
263
 
264
 
265
                if($feed) {
266
                    $routeTimeline = $this->url()->fromRoute('feed/timeline', ['id' => $currentUser->uuid, 'type' => 'user', 'feed' => $feed->uuid]);
267
                } else {
268
                    $routeTimeline = $this->url()->fromRoute('feed/timeline', ['id' => $currentUser->uuid, 'type' => 'user']);
269
                }
270
 
271
 
333 www 272
                $storage = Storage::getInstance($this->config, $this->adapter);
283 www 273
                $path = $storage->getPathNetwork();
1 efrain 274
 
283 www 275
                if($currentNetwork->moodle_image) {
276
                    $moodle_image = $storage->getGenericImage($path, $currentNetwork->uuid, $currentNetwork->moodle_image);
277
                } else {
278
                    $moodle_image = '';
279
                }
1 efrain 280
 
283 www 281
 
1 efrain 282
                return new JsonModel([
283
                    'user_uuid' => $user->uuid,
283 www 284
                    'image' => $storage->getUserImage($user),
1 efrain 285
                    'fullname' => trim($user->first_name . ' ' . $user->last_name),
286
                    'description' => empty($userProfile->description) ? '' :  trim($userProfile->description) ,
287
                    'country' => $country,
288
                    'visits' => $visits,
289
                    'connections' => $connections,
290
                    'feed' => '',
291
                    'routeTimeline' => $routeTimeline,
292
                    'formFeed' => $formFeed,
293
                    'formShare' => $formShare,
294
                    'imageSize' => $imageSize,
295
                    'moodle_name' => $currentNetwork->moodle_name,
283 www 296
                    'moodle_image' => $moodle_image,
1 efrain 297
                    'microlearning_appstore' => $currentNetwork->microlearning_appstore,
298
                    'microlearning_playstore' => $currentNetwork->microlearning_playstore,
299
                ]);
300
            }
301
        }
302
 
303
        return new JsonModel([
304
           'success' => false,
305
           'data' => 'ERROR_METHOD_NOT_ALLOWED'
306
        ]);
307
    }
308
 
309
}