Proyectos de Subversion LeadersLinked - Services

Rev

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