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