1 |
www |
1 |
<?php
|
|
|
2 |
declare(strict_types=1);
|
|
|
3 |
|
|
|
4 |
namespace LeadersLinked\Controller;
|
|
|
5 |
|
|
|
6 |
use Laminas\Db\Adapter\AdapterInterface;
|
6849 |
efrain |
7 |
|
1 |
www |
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 |
*
|
6866 |
efrain |
33 |
* @var \Laminas\Db\Adapter\AdapterInterface
|
1 |
www |
34 |
*/
|
|
|
35 |
private $adapter;
|
|
|
36 |
|
|
|
37 |
/**
|
|
|
38 |
*
|
6866 |
efrain |
39 |
* @var \LeadersLinked\Cache\CacheInterface
|
1 |
www |
40 |
*/
|
6866 |
efrain |
41 |
private $cache;
|
|
|
42 |
|
|
|
43 |
|
|
|
44 |
/**
|
|
|
45 |
*
|
|
|
46 |
* @var \Laminas\Log\LoggerInterface
|
|
|
47 |
*/
|
1 |
www |
48 |
private $logger;
|
6866 |
efrain |
49 |
|
6749 |
efrain |
50 |
/**
|
6866 |
efrain |
51 |
*
|
6749 |
efrain |
52 |
* @var array
|
|
|
53 |
*/
|
|
|
54 |
private $config;
|
1 |
www |
55 |
|
|
|
56 |
|
|
|
57 |
/**
|
|
|
58 |
*
|
6866 |
efrain |
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
|
1 |
www |
69 |
* @param array $config
|
6866 |
efrain |
70 |
* @param \Laminas\Mvc\I18n\Translator $translator
|
1 |
www |
71 |
*/
|
6866 |
efrain |
72 |
public function __construct($adapter, $cache, $logger, $config, $translator)
|
1 |
www |
73 |
{
|
|
|
74 |
$this->adapter = $adapter;
|
6866 |
efrain |
75 |
$this->cache = $cache;
|
1 |
www |
76 |
$this->logger = $logger;
|
|
|
77 |
$this->config = $config;
|
6866 |
efrain |
78 |
$this->translator = $translator;
|
1 |
www |
79 |
}
|
|
|
80 |
|
|
|
81 |
|
|
|
82 |
public function indexAction()
|
|
|
83 |
{
|
5765 |
efrain |
84 |
|
|
|
85 |
|
|
|
86 |
|
1 |
www |
87 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
88 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
89 |
|
4842 |
efrain |
90 |
$currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
|
|
|
91 |
$currentNetwork = $currentNetworkPlugin->getNetwork();
|
|
|
92 |
|
1 |
www |
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) {
|
6614 |
efrain |
117 |
$acl = $this->getEvent()->getViewModel()->getVariable('acl');
|
6605 |
efrain |
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 |
|
1 |
www |
128 |
$profileVisitMapper = ProfileVisitMapper::getInstance($this->adapter);
|
4714 |
efrain |
129 |
//$visits = $profileVisitMapper->getTotalByVisitedId($currentUser->id);
|
1 |
www |
130 |
|
4714 |
efrain |
131 |
$visits = $profileVisitMapper->getTotalByVisitedIdGroupVisitorId($currentUser->id);
|
|
|
132 |
|
4842 |
efrain |
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 |
}
|
1 |
www |
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 |
|
6605 |
efrain |
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 |
|
6614 |
efrain |
174 |
$allowDailyPulse = $acl->isAllowed($currentUser->usertype_id, 'daily-pulse') ? 1 : 0;
|
|
|
175 |
if ($allowDailyPulse) {
|
6615 |
efrain |
176 |
$routeDailyPulse = $this->url()->fromRoute('daily-pulse');
|
6614 |
efrain |
177 |
} else {
|
|
|
178 |
$routeDailyPulse = '';
|
|
|
179 |
}
|
|
|
180 |
|
|
|
181 |
|
|
|
182 |
|
1 |
www |
183 |
return new JsonModel([
|
|
|
184 |
'user_uuid' => $user->uuid,
|
|
|
185 |
'image' => $this->url()->fromRoute('storage', ['type' => 'user', 'code' => $user->uuid, 'filename' => $user->image]),
|
|
|
186 |
'fullname' => trim($user->first_name . ' ' . $user->last_name),
|
6605 |
efrain |
187 |
'description' => empty($userProfile->description) ? '' : trim($userProfile->description) ,
|
1 |
www |
188 |
'country' => $country,
|
|
|
189 |
'visits' => $visits,
|
|
|
190 |
'connections' => $connections,
|
|
|
191 |
'image_size' => $image_size,
|
6605 |
efrain |
192 |
'feed' => '',
|
|
|
193 |
'routeTimeline' => $routeTimeline,
|
6614 |
efrain |
194 |
'routeDailyPulse' => $routeDailyPulse,
|
6605 |
efrain |
195 |
'moodle_name' => $currentNetwork->moodle_name ? $currentNetwork->moodle_name : '',
|
|
|
196 |
'moodle_image' => $this->url()->fromRoute('storage-network', ['type' => 'moodle']),
|
|
|
197 |
'microlearning_appstore' => $currentNetwork->microlearning_appstore ? $currentNetwork->microlearning_appstore : '' ,
|
|
|
198 |
'microlearning_playstore' => $currentNetwork->microlearning_playstore ? $currentNetwork->microlearning_playstore : '',
|
|
|
199 |
|
|
|
200 |
|
1 |
www |
201 |
]);
|
|
|
202 |
|
|
|
203 |
} else {
|
3298 |
efrain |
204 |
|
1 |
www |
205 |
$feed_uuid = $this->params()->fromRoute('feed');
|
|
|
206 |
if($feed_uuid) {
|
|
|
207 |
$feedMapper = FeedMapper::getInstance($this->adapter);
|
3146 |
efrain |
208 |
$feed = $feedMapper->fetchOneByUuidAnyStatus($feed_uuid);
|
1 |
www |
209 |
} else {
|
3298 |
efrain |
210 |
$feed = '';
|
1 |
www |
211 |
}
|
|
|
212 |
|
|
|
213 |
|
|
|
214 |
|
|
|
215 |
|
|
|
216 |
$profileVisitMapper = ProfileVisitMapper::getInstance($this->adapter);
|
4714 |
efrain |
217 |
// $visits = $profileVisitMapper->getTotalByVisitedId($currentUser->id);
|
|
|
218 |
$visits = $profileVisitMapper->getTotalByVisitedIdGroupVisitorId($currentUser->id);
|
1 |
www |
219 |
|
|
|
220 |
|
4842 |
efrain |
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 |
}
|
1 |
www |
233 |
|
4842 |
efrain |
234 |
|
|
|
235 |
|
1 |
www |
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 |
|
5751 |
efrain |
249 |
$imageSize = $this->config['leaderslinked.image_sizes.feed_image_upload'];
|
1 |
www |
250 |
|
|
|
251 |
$formFeed = new CreateForm();
|
|
|
252 |
$formShare = new ShareForm();
|
|
|
253 |
|
3146 |
efrain |
254 |
|
3298 |
efrain |
255 |
if($feed) {
|
5751 |
efrain |
256 |
$routeTimeline = $this->url()->fromRoute('feed/timeline', ['id' => $currentUser->uuid, 'type' => 'user', 'feed' => $feed->uuid]);
|
3146 |
efrain |
257 |
} else {
|
5751 |
efrain |
258 |
$routeTimeline = $this->url()->fromRoute('feed/timeline', ['id' => $currentUser->uuid, 'type' => 'user']);
|
3146 |
efrain |
259 |
}
|
|
|
260 |
|
|
|
261 |
|
|
|
262 |
|
|
|
263 |
|
|
|
264 |
|
1 |
www |
265 |
$this->layout()->setTemplate('layout/layout.phtml');
|
|
|
266 |
$viewModel = new ViewModel();
|
|
|
267 |
$viewModel->setVariables([
|
|
|
268 |
'user_uuid' => $user->uuid,
|
|
|
269 |
'image' => $this->url()->fromRoute('storage', ['type' => 'user', 'code' => $user->uuid, 'filename' => $user->image]),
|
|
|
270 |
'fullname' => trim($user->first_name . ' ' . $user->last_name),
|
|
|
271 |
'description' => empty($userProfile->description) ? '' : trim($userProfile->description) ,
|
|
|
272 |
'country' => $country,
|
|
|
273 |
'visits' => $visits,
|
|
|
274 |
'connections' => $connections,
|
3146 |
efrain |
275 |
'feed' => '',
|
5751 |
efrain |
276 |
'routeTimeline' => $routeTimeline,
|
1 |
www |
277 |
'formFeed' => $formFeed,
|
|
|
278 |
'formShare' => $formShare,
|
5751 |
efrain |
279 |
'imageSize' => $imageSize,
|
5848 |
efrain |
280 |
'moodle_name' => $currentNetwork->moodle_name,
|
|
|
281 |
'moodle_image' => $this->url()->fromRoute('storage-network', ['type' => 'moodle']),
|
|
|
282 |
'microlearning_appstore' => $currentNetwork->microlearning_appstore,
|
|
|
283 |
'microlearning_playstore' => $currentNetwork->microlearning_playstore,
|
1 |
www |
284 |
]);
|
|
|
285 |
$viewModel->setTemplate('leaders-linked/dashboard/index.phtml');
|
|
|
286 |
return $viewModel ;
|
|
|
287 |
}
|
|
|
288 |
}
|
|
|
289 |
|
|
|
290 |
return new JsonModel([
|
|
|
291 |
'success' => false,
|
|
|
292 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
293 |
]);
|
|
|
294 |
}
|
|
|
295 |
|
60 |
efrain |
296 |
public function dashboard2Action()
|
1 |
www |
297 |
{
|
60 |
efrain |
298 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
299 |
$currentUser = $currentUserPlugin->getUser();
|
1 |
www |
300 |
|
60 |
efrain |
301 |
$userMapper = UserMapper::getInstance($this->adapter);
|
|
|
302 |
$user = $userMapper->fetchOne($currentUser->id);
|
|
|
303 |
|
|
|
304 |
$request = $this->getRequest();
|
|
|
305 |
if($request->isGet()) {
|
|
|
306 |
|
|
|
307 |
|
|
|
308 |
$headers = $request->getHeaders();
|
|
|
309 |
|
|
|
310 |
$isJson = false;
|
|
|
311 |
if($headers->has('Accept')) {
|
|
|
312 |
$accept = $headers->get('Accept');
|
|
|
313 |
|
|
|
314 |
$prioritized = $accept->getPrioritized();
|
|
|
315 |
|
|
|
316 |
foreach($prioritized as $key => $value) {
|
|
|
317 |
$raw = trim($value->getRaw());
|
|
|
318 |
|
|
|
319 |
if(!$isJson) {
|
|
|
320 |
$isJson = strpos($raw, 'json');
|
|
|
321 |
}
|
|
|
322 |
|
|
|
323 |
}
|
|
|
324 |
}
|
|
|
325 |
|
|
|
326 |
if($isJson) {
|
|
|
327 |
$profileVisitMapper = ProfileVisitMapper::getInstance($this->adapter);
|
|
|
328 |
$visits = $profileVisitMapper->getTotalByVisitedId($currentUser->id);
|
|
|
329 |
|
|
|
330 |
$connectionMapper = ConnectionMapper::getInstance($this->adapter);
|
|
|
331 |
$connections = $connectionMapper->fetchTotalConnectionByUser($currentUser->id);
|
|
|
332 |
|
|
|
333 |
|
|
|
334 |
if($user->location_id) {
|
|
|
335 |
$locationMapper = LocationMapper::getInstance($this->adapter);
|
|
|
336 |
$location = $locationMapper->fetchOne($user->location_id);
|
|
|
337 |
|
|
|
338 |
$country = $location->country;
|
|
|
339 |
} else {
|
|
|
340 |
$country = '';
|
|
|
341 |
}
|
|
|
342 |
|
|
|
343 |
$image_size = $this->config['leaderslinked.image_sizes.feed_image_upload'];
|
|
|
344 |
|
|
|
345 |
return new JsonModel([
|
|
|
346 |
'user_uuid' => $user->uuid,
|
|
|
347 |
'image' => $this->url()->fromRoute('storage', ['type' => 'user', 'code' => $user->uuid, 'filename' => $user->image]),
|
|
|
348 |
'fullname' => trim($user->first_name . ' ' . $user->last_name),
|
|
|
349 |
'country' => $country,
|
|
|
350 |
'visits' => $visits,
|
|
|
351 |
'connections' => $connections,
|
|
|
352 |
'image_size' => $image_size,
|
|
|
353 |
]);
|
|
|
354 |
|
|
|
355 |
} else {
|
|
|
356 |
$feed_uuid = $this->params()->fromRoute('feed');
|
|
|
357 |
if($feed_uuid) {
|
|
|
358 |
$feedMapper = FeedMapper::getInstance($this->adapter);
|
|
|
359 |
$feed = $feedMapper->fetchOneByUuid($feed_uuid);
|
|
|
360 |
if($feed && $feed->type == Feed::TYPE_UPDATE && $feed->user_id == $currentUser->id && $feed->status == Feed::STATUS_PUBLISHED) {
|
|
|
361 |
$notificationMapper = NotificationMapper::getInstance($this->adapter);
|
|
|
362 |
$notificationMapper->markAllNotificationsAsReadByUserIdAndFeedId($currentUser->id, $feed->id);
|
|
|
363 |
} else {
|
|
|
364 |
$feed_uuid = '';
|
|
|
365 |
}
|
|
|
366 |
} else {
|
|
|
367 |
$feed_uuid = '';
|
|
|
368 |
}
|
|
|
369 |
|
|
|
370 |
|
|
|
371 |
|
|
|
372 |
|
|
|
373 |
$profileVisitMapper = ProfileVisitMapper::getInstance($this->adapter);
|
|
|
374 |
$visits = $profileVisitMapper->getTotalByVisitedId($currentUser->id);
|
|
|
375 |
|
|
|
376 |
$connectionMapper = ConnectionMapper::getInstance($this->adapter);
|
|
|
377 |
$connections = $connectionMapper->fetchTotalConnectionByUser($currentUser->id);
|
|
|
378 |
|
|
|
379 |
|
|
|
380 |
if($user->location_id) {
|
|
|
381 |
$locationMapper = LocationMapper::getInstance($this->adapter);
|
|
|
382 |
$location = $locationMapper->fetchOne($user->location_id);
|
|
|
383 |
|
|
|
384 |
$country = $location->country;
|
|
|
385 |
} else {
|
|
|
386 |
$country = '';
|
|
|
387 |
}
|
|
|
388 |
|
|
|
389 |
$userProfileMapper = UserProfileMapper::getInstance($this->adapter);
|
|
|
390 |
$userProfile = $userProfileMapper->fetchOnePublicByUserId($currentUser->id);
|
|
|
391 |
|
|
|
392 |
|
|
|
393 |
$image_size = $this->config['leaderslinked.image_sizes.feed_image_upload'];
|
|
|
394 |
|
|
|
395 |
$formFeed = new CreateForm();
|
|
|
396 |
$formShare = new ShareForm();
|
|
|
397 |
|
|
|
398 |
$this->layout()->setTemplate('layout/layout.phtml');
|
|
|
399 |
$viewModel = new ViewModel();
|
|
|
400 |
$viewModel->setVariables([
|
|
|
401 |
'user_uuid' => $user->uuid,
|
|
|
402 |
'image' => $this->url()->fromRoute('storage', ['type' => 'user', 'code' => $user->uuid, 'filename' => $user->image]),
|
|
|
403 |
'fullname' => trim($user->first_name . ' ' . $user->last_name),
|
|
|
404 |
'description' => empty($userProfile->description) ? '' : trim($userProfile->description) ,
|
|
|
405 |
'country' => $country,
|
|
|
406 |
'visits' => $visits,
|
|
|
407 |
'connections' => $connections,
|
|
|
408 |
'feed' => $feed_uuid,
|
|
|
409 |
'formFeed' => $formFeed,
|
|
|
410 |
'formShare' => $formShare,
|
|
|
411 |
'image_size' => $image_size,
|
5848 |
efrain |
412 |
|
60 |
efrain |
413 |
]);
|
|
|
414 |
$viewModel->setTemplate('leaders-linked/dashboard/dashboard2.phtml');
|
|
|
415 |
return $viewModel ;
|
|
|
416 |
}
|
|
|
417 |
}
|
|
|
418 |
|
1 |
www |
419 |
return new JsonModel([
|
60 |
efrain |
420 |
'success' => false,
|
|
|
421 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
1 |
www |
422 |
]);
|
|
|
423 |
}
|
|
|
424 |
}
|