| 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;
|
|
|
23 |
|
|
|
24 |
class DashboardController extends AbstractActionController
|
|
|
25 |
{
|
|
|
26 |
/**
|
|
|
27 |
*
|
|
|
28 |
* @var AdapterInterface
|
|
|
29 |
*/
|
|
|
30 |
private $adapter;
|
|
|
31 |
|
|
|
32 |
|
|
|
33 |
/**
|
|
|
34 |
*
|
|
|
35 |
* @var AbstractAdapter
|
|
|
36 |
*/
|
|
|
37 |
private $cache;
|
|
|
38 |
|
|
|
39 |
/**
|
|
|
40 |
*
|
|
|
41 |
* @var LoggerInterface
|
|
|
42 |
*/
|
|
|
43 |
private $logger;
|
|
|
44 |
|
|
|
45 |
|
|
|
46 |
|
|
|
47 |
/**
|
|
|
48 |
*
|
|
|
49 |
* @param AdapterInterface $adapter
|
|
|
50 |
* @param AbstractAdapter $cache
|
|
|
51 |
* @param LoggerInterface $logger
|
|
|
52 |
* @param array $config
|
|
|
53 |
*/
|
|
|
54 |
public function __construct($adapter, $cache , $logger, $config)
|
|
|
55 |
{
|
|
|
56 |
$this->adapter = $adapter;
|
|
|
57 |
$this->cache = $cache;
|
|
|
58 |
$this->logger = $logger;
|
|
|
59 |
$this->config = $config;
|
|
|
60 |
|
|
|
61 |
|
|
|
62 |
}
|
|
|
63 |
|
|
|
64 |
|
|
|
65 |
public function indexAction()
|
|
|
66 |
{
|
|
|
67 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
68 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
69 |
|
|
|
70 |
$userMapper = UserMapper::getInstance($this->adapter);
|
|
|
71 |
$user = $userMapper->fetchOne($currentUser->id);
|
|
|
72 |
|
|
|
73 |
$request = $this->getRequest();
|
|
|
74 |
if($request->isGet()) {
|
|
|
75 |
|
|
|
76 |
|
|
|
77 |
$headers = $request->getHeaders();
|
|
|
78 |
|
|
|
79 |
$isJson = false;
|
|
|
80 |
if($headers->has('Accept')) {
|
|
|
81 |
$accept = $headers->get('Accept');
|
|
|
82 |
|
|
|
83 |
$prioritized = $accept->getPrioritized();
|
|
|
84 |
|
|
|
85 |
foreach($prioritized as $key => $value) {
|
|
|
86 |
$raw = trim($value->getRaw());
|
|
|
87 |
|
|
|
88 |
if(!$isJson) {
|
|
|
89 |
$isJson = strpos($raw, 'json');
|
|
|
90 |
}
|
|
|
91 |
|
|
|
92 |
}
|
|
|
93 |
}
|
|
|
94 |
|
|
|
95 |
if($isJson) {
|
|
|
96 |
$profileVisitMapper = ProfileVisitMapper::getInstance($this->adapter);
|
|
|
97 |
$visits = $profileVisitMapper->getTotalByVisitedId($currentUser->id);
|
|
|
98 |
|
|
|
99 |
$connectionMapper = ConnectionMapper::getInstance($this->adapter);
|
|
|
100 |
$connections = $connectionMapper->fetchTotalConnectionByUser($currentUser->id);
|
|
|
101 |
|
|
|
102 |
|
|
|
103 |
if($user->location_id) {
|
|
|
104 |
$locationMapper = LocationMapper::getInstance($this->adapter);
|
|
|
105 |
$location = $locationMapper->fetchOne($user->location_id);
|
|
|
106 |
|
|
|
107 |
$country = $location->country;
|
|
|
108 |
} else {
|
|
|
109 |
$country = '';
|
|
|
110 |
}
|
|
|
111 |
|
|
|
112 |
$image_size = $this->config['leaderslinked.image_sizes.feed_image_upload'];
|
|
|
113 |
|
|
|
114 |
return new JsonModel([
|
|
|
115 |
'user_uuid' => $user->uuid,
|
|
|
116 |
'image' => $this->url()->fromRoute('storage', ['type' => 'user', 'code' => $user->uuid, 'filename' => $user->image]),
|
|
|
117 |
'fullname' => trim($user->first_name . ' ' . $user->last_name),
|
|
|
118 |
'country' => $country,
|
|
|
119 |
'visits' => $visits,
|
|
|
120 |
'connections' => $connections,
|
|
|
121 |
'image_size' => $image_size,
|
|
|
122 |
]);
|
|
|
123 |
|
|
|
124 |
} else {
|
|
|
125 |
$feed_uuid = $this->params()->fromRoute('feed');
|
|
|
126 |
if($feed_uuid) {
|
|
|
127 |
$feedMapper = FeedMapper::getInstance($this->adapter);
|
|
|
128 |
$feed = $feedMapper->fetchOneByUuid($feed_uuid);
|
|
|
129 |
if($feed && $feed->type == Feed::TYPE_UPDATE && $feed->user_id == $currentUser->id && $feed->status == Feed::STATUS_PUBLISHED) {
|
|
|
130 |
$notificationMapper = NotificationMapper::getInstance($this->adapter);
|
|
|
131 |
$notificationMapper->markAllNotificationsAsReadByUserIdAndFeedId($currentUser->id, $feed->id);
|
|
|
132 |
} else {
|
|
|
133 |
$feed_uuid = '';
|
|
|
134 |
}
|
|
|
135 |
} else {
|
|
|
136 |
$feed_uuid = '';
|
|
|
137 |
}
|
|
|
138 |
|
|
|
139 |
|
|
|
140 |
|
|
|
141 |
|
|
|
142 |
$profileVisitMapper = ProfileVisitMapper::getInstance($this->adapter);
|
|
|
143 |
$visits = $profileVisitMapper->getTotalByVisitedId($currentUser->id);
|
|
|
144 |
|
|
|
145 |
$connectionMapper = ConnectionMapper::getInstance($this->adapter);
|
|
|
146 |
$connections = $connectionMapper->fetchTotalConnectionByUser($currentUser->id);
|
|
|
147 |
|
|
|
148 |
|
|
|
149 |
if($user->location_id) {
|
|
|
150 |
$locationMapper = LocationMapper::getInstance($this->adapter);
|
|
|
151 |
$location = $locationMapper->fetchOne($user->location_id);
|
|
|
152 |
|
|
|
153 |
$country = $location->country;
|
|
|
154 |
} else {
|
|
|
155 |
$country = '';
|
|
|
156 |
}
|
|
|
157 |
|
|
|
158 |
$userProfileMapper = UserProfileMapper::getInstance($this->adapter);
|
|
|
159 |
$userProfile = $userProfileMapper->fetchOnePublicByUserId($currentUser->id);
|
|
|
160 |
|
|
|
161 |
|
|
|
162 |
$image_size = $this->config['leaderslinked.image_sizes.feed_image_upload'];
|
|
|
163 |
|
|
|
164 |
$formFeed = new CreateForm();
|
|
|
165 |
$formShare = new ShareForm();
|
|
|
166 |
|
|
|
167 |
$this->layout()->setTemplate('layout/layout.phtml');
|
|
|
168 |
$viewModel = new ViewModel();
|
|
|
169 |
$viewModel->setVariables([
|
|
|
170 |
'user_uuid' => $user->uuid,
|
|
|
171 |
'image' => $this->url()->fromRoute('storage', ['type' => 'user', 'code' => $user->uuid, 'filename' => $user->image]),
|
|
|
172 |
'fullname' => trim($user->first_name . ' ' . $user->last_name),
|
|
|
173 |
'description' => empty($userProfile->description) ? '' : trim($userProfile->description) ,
|
|
|
174 |
'country' => $country,
|
|
|
175 |
'visits' => $visits,
|
|
|
176 |
'connections' => $connections,
|
|
|
177 |
'feed' => $feed_uuid,
|
|
|
178 |
'formFeed' => $formFeed,
|
|
|
179 |
'formShare' => $formShare,
|
|
|
180 |
'image_size' => $image_size,
|
|
|
181 |
]);
|
|
|
182 |
$viewModel->setTemplate('leaders-linked/dashboard/index.phtml');
|
|
|
183 |
return $viewModel ;
|
|
|
184 |
}
|
|
|
185 |
}
|
|
|
186 |
|
|
|
187 |
return new JsonModel([
|
|
|
188 |
'success' => false,
|
|
|
189 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
190 |
]);
|
|
|
191 |
}
|
|
|
192 |
|
|
|
193 |
public function error500Action()
|
|
|
194 |
{
|
|
|
195 |
$uuid = '';
|
|
|
196 |
$postMapper = PostMapper::getInstance($this->adapter);
|
|
|
197 |
$postMapper->fetchOneByUuidError500($uuid);
|
|
|
198 |
|
|
|
199 |
return new JsonModel([
|
|
|
200 |
'success' => true,
|
|
|
201 |
'data' => 'Prueba Error 500'
|
|
|
202 |
]);
|
|
|
203 |
|
|
|
204 |
}
|
|
|
205 |
}
|