1 |
www |
1 |
<?php
|
|
|
2 |
/**
|
|
|
3 |
*
|
|
|
4 |
* Controlador: Mis Perfiles
|
|
|
5 |
*
|
|
|
6 |
*/
|
|
|
7 |
declare(strict_types=1);
|
|
|
8 |
|
|
|
9 |
namespace LeadersLinked\Controller;
|
|
|
10 |
|
|
|
11 |
use Laminas\Db\Adapter\AdapterInterface;
|
|
|
12 |
use Laminas\Cache\Storage\Adapter\AbstractAdapter;
|
|
|
13 |
use Laminas\Mvc\Controller\AbstractActionController;
|
|
|
14 |
use Laminas\Log\LoggerInterface;
|
|
|
15 |
use Laminas\View\Model\ViewModel;
|
|
|
16 |
use Laminas\View\Model\JsonModel;
|
|
|
17 |
|
|
|
18 |
use LeadersLinked\Mapper\UserProfileMapper;
|
|
|
19 |
use LeadersLinked\Mapper\CompanyFollowerMapper;
|
|
|
20 |
use LeadersLinked\Mapper\LocationMapper;
|
|
|
21 |
use LeadersLinked\Mapper\UserLanguageMapper;
|
|
|
22 |
use LeadersLinked\Mapper\UserSkillMapper;
|
|
|
23 |
|
|
|
24 |
use LeadersLinked\Mapper\UserMapper;
|
|
|
25 |
use LeadersLinked\Mapper\UserEducationMapper;
|
|
|
26 |
use LeadersLinked\Mapper\DegreeMapper;
|
|
|
27 |
use LeadersLinked\Mapper\UserExperienceMapper;
|
|
|
28 |
use LeadersLinked\Mapper\IndustryMapper;
|
|
|
29 |
use LeadersLinked\Mapper\CompanySizeMapper;
|
|
|
30 |
use LeadersLinked\Mapper\ConnectionMapper;
|
|
|
31 |
use LeadersLinked\Mapper\UserBlockedMapper;
|
|
|
32 |
use LeadersLinked\Model\Connection;
|
|
|
33 |
use LeadersLinked\Mapper\ProfileVisitMapper;
|
|
|
34 |
use LeadersLinked\Model\ProfileVisit;
|
|
|
35 |
use LeadersLinked\Mapper\QueryMapper;
|
|
|
36 |
use Laminas\Paginator\Adapter\DbSelect;
|
|
|
37 |
use Laminas\Paginator\Paginator;
|
|
|
38 |
use LeadersLinked\Model\User;
|
|
|
39 |
use Laminas\Db\Sql\Expression;
|
|
|
40 |
use LeadersLinked\Mapper\LanguageMapper;
|
|
|
41 |
use LeadersLinked\Mapper\SkillMapper;
|
|
|
42 |
|
|
|
43 |
|
|
|
44 |
class ProfileController extends AbstractActionController
|
|
|
45 |
{
|
|
|
46 |
/**
|
|
|
47 |
*
|
|
|
48 |
* @var AdapterInterface
|
|
|
49 |
*/
|
|
|
50 |
private $adapter;
|
|
|
51 |
|
|
|
52 |
|
|
|
53 |
/**
|
|
|
54 |
*
|
|
|
55 |
* @var AbstractAdapter
|
|
|
56 |
*/
|
|
|
57 |
private $cache;
|
|
|
58 |
|
|
|
59 |
/**
|
|
|
60 |
*
|
|
|
61 |
* @var LoggerInterface
|
|
|
62 |
*/
|
|
|
63 |
private $logger;
|
|
|
64 |
|
|
|
65 |
|
|
|
66 |
/**
|
|
|
67 |
*
|
|
|
68 |
* @var array
|
|
|
69 |
*/
|
|
|
70 |
private $config;
|
|
|
71 |
|
|
|
72 |
/**
|
|
|
73 |
*
|
|
|
74 |
* @param AdapterInterface $adapter
|
|
|
75 |
* @param AbstractAdapter $cache
|
|
|
76 |
* @param LoggerInterface $logger
|
|
|
77 |
* @param array $config
|
|
|
78 |
*/
|
|
|
79 |
public function __construct($adapter, $cache , $logger, $config)
|
|
|
80 |
{
|
|
|
81 |
$this->adapter = $adapter;
|
|
|
82 |
$this->cache = $cache;
|
|
|
83 |
$this->logger = $logger;
|
|
|
84 |
$this->config = $config;
|
|
|
85 |
|
|
|
86 |
}
|
|
|
87 |
|
|
|
88 |
/**
|
|
|
89 |
*
|
|
|
90 |
* Generación del listado de perfiles
|
|
|
91 |
* {@inheritDoc}
|
|
|
92 |
* @see \Laminas\Mvc\Controller\AbstractActionController::indexAction()
|
|
|
93 |
*/
|
|
|
94 |
public function indexAction()
|
|
|
95 |
{
|
|
|
96 |
$this->layout()->setTemplate('layout/layout.phtml');
|
|
|
97 |
$viewModel = new ViewModel();
|
|
|
98 |
$viewModel->setTemplate('leaders-linked/profile/index.phtml');
|
|
|
99 |
return $viewModel ;
|
|
|
100 |
|
|
|
101 |
}
|
|
|
102 |
|
|
|
103 |
|
|
|
104 |
/**
|
|
|
105 |
* Presenta el perfil con las opciónes de edición de cada sección
|
|
|
106 |
* @return \Laminas\Http\Response|\Laminas\View\Model\ViewModel|\Laminas\View\Model\JsonModel
|
|
|
107 |
*/
|
|
|
108 |
public function viewAction()
|
|
|
109 |
{
|
|
|
110 |
|
|
|
111 |
$request = $this->getRequest();
|
|
|
112 |
if($request->isGet()) {
|
|
|
113 |
|
|
|
114 |
|
|
|
115 |
$flashMessenger = $this->plugin('FlashMessenger');
|
|
|
116 |
|
|
|
117 |
|
|
|
118 |
$id = $this->params()->fromRoute('id');
|
|
|
119 |
if(!$id) {
|
|
|
120 |
$flashMessenger->addErrorMessage('ERROR_INVALID_PARAMETER');
|
|
|
121 |
return $this->redirect()->toRoute('dashboard');
|
|
|
122 |
}
|
|
|
123 |
|
|
|
124 |
|
|
|
125 |
$userMapper = UserMapper::getInstance($this->adapter);
|
|
|
126 |
$user = $userMapper->fetchOneByUuid($id);
|
|
|
127 |
|
|
|
128 |
$userProfileMapper = UserProfileMapper::getInstance($this->adapter);
|
|
|
129 |
if($user) {
|
|
|
130 |
$userProfile = $userProfileMapper->fetchOnePublicByUserId($user->id);
|
|
|
131 |
} else {
|
|
|
132 |
$userProfile = $userProfileMapper->fetchOneByUuid($id);
|
|
|
133 |
}
|
|
|
134 |
|
|
|
135 |
if(!$userProfile) {
|
|
|
136 |
$flashMessenger->addErrorMessage('ERROR_RECORD_NOT_FOUND');
|
|
|
137 |
return $this->redirect()->toRoute('dashboard');
|
|
|
138 |
}
|
|
|
139 |
|
|
|
140 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
141 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
142 |
|
|
|
143 |
$userBlockedMapper = UserBlockedMapper::getInstance($this->adapter);
|
|
|
144 |
$userBlocked = $userBlockedMapper->fetchOneByUserIdAndBlockedId($userProfile->user_id, $currentUser->id);
|
|
|
145 |
|
|
|
146 |
if($userBlocked) {
|
|
|
147 |
$flashMessenger->addErrorMessage('ERROR_UNAUTHORIZED');
|
|
|
148 |
return $this->redirect()->toRoute('dashboard');
|
|
|
149 |
}
|
|
|
150 |
|
|
|
151 |
if($currentUser->id != $userProfile->user_id) {
|
|
|
152 |
|
|
|
153 |
$visited_on = date('Y-m-d');;
|
|
|
154 |
$profileVisitMapper = ProfileVisitMapper::getInstance($this->adapter);
|
|
|
155 |
$profileVisit = $profileVisitMapper->fetchOneByVisitorIdAndVisitedIdAndVisitedOn($currentUser->id, $userProfile->user_id, $visited_on);
|
|
|
156 |
if(!$profileVisit) {
|
|
|
157 |
$profileVisit = new ProfileVisit();
|
|
|
158 |
$profileVisit->user_profile_id = $userProfile->id;
|
|
|
159 |
$profileVisit->visited_id = $userProfile->user_id;
|
|
|
160 |
$profileVisit->visitor_id = $currentUser->id;
|
|
|
161 |
$profileVisit->visited_on = date('Y-m-d');
|
|
|
162 |
$profileVisitMapper->insert($profileVisit);
|
|
|
163 |
}
|
|
|
164 |
}
|
|
|
165 |
|
|
|
166 |
if($userProfile->location_id) {
|
|
|
167 |
$locationMapper= LocationMapper::getInstance($this->adapter);
|
|
|
168 |
$location = $locationMapper->fetchOne($userProfile->location_id);
|
|
|
169 |
|
|
|
170 |
$formattedAddress = $location->formatted_address;
|
|
|
171 |
$country = $location->country;
|
|
|
172 |
} else {
|
|
|
173 |
$formattedAddress = '';
|
|
|
174 |
$country = '';
|
|
|
175 |
}
|
|
|
176 |
|
|
|
177 |
$connectionMapper = ConnectionMapper::getInstance($this->adapter);
|
|
|
178 |
$connection = $connectionMapper->fetchOneByUserId1AndUserId2($currentUser->id, $userProfile->user_id);
|
|
|
179 |
|
|
|
180 |
$userMapper = UserMapper::getInstance($this->adapter);
|
|
|
181 |
$user = $userMapper->fetchOne($userProfile->user_id);
|
|
|
182 |
|
|
|
183 |
$userLanguages = [];
|
|
|
184 |
$languageMapper = LanguageMapper::getInstance($this->adapter);
|
|
|
185 |
$userLanguageMapper = UserLanguageMapper::getInstance($this->adapter);
|
|
|
186 |
$records = $userLanguageMapper->fetchAllByUserProfileId($userProfile->id);
|
|
|
187 |
foreach($records as $record)
|
|
|
188 |
{
|
|
|
189 |
$language = $languageMapper->fetchOne($record->language_id);
|
|
|
190 |
$userLanguages[$language->id] = $language->name;
|
|
|
191 |
}
|
|
|
192 |
|
|
|
193 |
|
|
|
194 |
$locationMapper = LocationMapper::getInstance($this->adapter);
|
|
|
195 |
|
|
|
196 |
$degreeMapper = DegreeMapper::getInstance($this->adapter);
|
|
|
197 |
$userEducationMapper = UserEducationMapper::getInstance($this->adapter);
|
|
|
198 |
$userEducations = $userEducationMapper->fetchAllByUserProfileId($userProfile->id);
|
|
|
199 |
|
|
|
200 |
foreach($userEducations as &$userEducation)
|
|
|
201 |
{
|
|
|
202 |
$location = $locationMapper->fetchOne($userEducation->location_id);
|
|
|
203 |
$degree = $degreeMapper->fetchOne($userEducation->degree_id) ;
|
|
|
204 |
|
|
|
205 |
|
|
|
206 |
$userEducation = [
|
|
|
207 |
'university' => $userEducation->university,
|
|
|
208 |
'degree' => $degree->name,
|
|
|
209 |
'field_of_study' => $userEducation->field_of_study,
|
|
|
210 |
'grade_or_percentage' => $userEducation->grade_or_percentage,
|
|
|
211 |
'formatted_address' => $location->formatted_address,
|
|
|
212 |
'from_year' => $userEducation->from_year,
|
|
|
213 |
'to_year' => $userEducation->to_year,
|
|
|
214 |
'description' => $userEducation->description,
|
|
|
215 |
];
|
|
|
216 |
}
|
|
|
217 |
|
|
|
218 |
/*
|
|
|
219 |
$industries = [];
|
|
|
220 |
$industryMapper = IndustryMapper::getInstance($this->adapter);
|
3454 |
efrain |
221 |
$records = $industryMapper->fetchAllActive();
|
1 |
www |
222 |
foreach($records as $record)
|
|
|
223 |
{
|
|
|
224 |
$industries[$record->uuid] = $record->name;
|
|
|
225 |
}
|
|
|
226 |
|
|
|
227 |
$companySizes = [];
|
|
|
228 |
$companySizeMapper = CompanySizeMapper::getInstance($this->adapter);
|
3454 |
efrain |
229 |
$records = $companySizeMapper->fetchAllActive();
|
1 |
www |
230 |
foreach($records as $record)
|
|
|
231 |
{
|
|
|
232 |
$companySizes[$record->uuid] = $record->name . ' ('.$record->minimum_no_of_employee . '-' . $record->maximum_no_of_employee .')';
|
|
|
233 |
}
|
|
|
234 |
*/
|
|
|
235 |
|
|
|
236 |
$industryMapper = IndustryMapper::getInstance($this->adapter);
|
|
|
237 |
$companySizeMapper = CompanySizeMapper::getInstance($this->adapter);
|
|
|
238 |
|
|
|
239 |
|
|
|
240 |
$userExperienceMapper = UserExperienceMapper::getInstance($this->adapter);
|
|
|
241 |
$userExperiences = $userExperienceMapper->fetchAllByUserProfileId($userProfile->id);
|
|
|
242 |
|
|
|
243 |
foreach($userExperiences as &$userExperience)
|
|
|
244 |
{
|
|
|
245 |
$industry = $industryMapper->fetchOne($userExperience->industry_id);
|
|
|
246 |
$companySize = $companySizeMapper->fetchOne($userExperience->company_size_id);
|
|
|
247 |
|
|
|
248 |
|
|
|
249 |
$location = $locationMapper->fetchOne($userExperience->location_id);
|
|
|
250 |
|
|
|
251 |
$userExperience = [
|
|
|
252 |
'company' => $userExperience->company,
|
|
|
253 |
'industry' => $industry->name,
|
|
|
254 |
'size' => $companySize->name . ' (' . $companySize->minimum_no_of_employee . ' - ' . $companySize->maximum_no_of_employee . ' ) ',
|
|
|
255 |
'title' => $userExperience->title,
|
|
|
256 |
'formatted_address' => $location->formatted_address,
|
|
|
257 |
'from_year' => $userExperience->from_year,
|
|
|
258 |
'from_month' => $userExperience->from_month,
|
|
|
259 |
'to_year' => $userExperience->to_year,
|
|
|
260 |
'to_month' => $userExperience->to_month,
|
|
|
261 |
'description' => $userExperience->description,
|
|
|
262 |
'is_current' => $userExperience->is_current,
|
|
|
263 |
];
|
|
|
264 |
}
|
|
|
265 |
|
|
|
266 |
$userSkills = [];
|
|
|
267 |
$skillMapper = SkillMapper::getInstance($this->adapter);
|
|
|
268 |
$userSkillMapper = UserSkillMapper::getInstance($this->adapter);
|
|
|
269 |
$records = $userSkillMapper->fetchAllByUserProfileId($userProfile->id);
|
|
|
270 |
foreach($records as $record)
|
|
|
271 |
{
|
|
|
272 |
$skill = $skillMapper->fetchOne($record->skill_id);
|
|
|
273 |
$userSkills[$skill->uuid] = $skill->name;
|
|
|
274 |
}
|
|
|
275 |
|
|
|
276 |
|
|
|
277 |
$companyFollowerMapper = CompanyFollowerMapper::getInstance($this->adapter);
|
|
|
278 |
$following = $companyFollowerMapper->getCountFollowing($user->id);
|
|
|
279 |
|
|
|
280 |
$connectionMapper = ConnectionMapper::getInstance($this->adapter);
|
|
|
281 |
$total_connections = $connectionMapper->fetchTotalConnectionByUser($user->id);
|
|
|
282 |
|
3115 |
efrain |
283 |
$request_connection = 0;
|
1 |
www |
284 |
if($connection) {
|
3189 |
efrain |
285 |
if($connection->status == Connection::STATUS_REJECTED || $connection->status == Connection::STATUS_CANCELLED) {
|
3115 |
efrain |
286 |
$request_connection = 1;
|
1 |
www |
287 |
}
|
3189 |
efrain |
288 |
} else {
|
3190 |
efrain |
289 |
$request_connection = 1;
|
1 |
www |
290 |
}
|
|
|
291 |
|
3189 |
efrain |
292 |
|
1 |
www |
293 |
$common_connection = count($connectionMapper->fetchAllCommonConnectionsUserIdByUser1ReturnIds($currentUser->id, $userProfile->user_id));
|
|
|
294 |
|
|
|
295 |
$profileVisitMapper = ProfileVisitMapper::getInstance($this->adapter);
|
|
|
296 |
$views = $profileVisitMapper->getTotalByVisitedId( $userProfile->user_id );
|
|
|
297 |
|
|
|
298 |
|
|
|
299 |
|
|
|
300 |
$headers = $request->getHeaders();
|
|
|
301 |
$isJson = false;
|
|
|
302 |
if($headers->has('Accept')) {
|
|
|
303 |
$accept = $headers->get('Accept');
|
|
|
304 |
|
|
|
305 |
$prioritized = $accept->getPrioritized();
|
|
|
306 |
|
|
|
307 |
foreach($prioritized as $key => $value) {
|
|
|
308 |
$raw = trim($value->getRaw());
|
|
|
309 |
|
|
|
310 |
if(!$isJson) {
|
|
|
311 |
$isJson = strpos($raw, 'json');
|
|
|
312 |
}
|
|
|
313 |
|
|
|
314 |
}
|
|
|
315 |
}
|
|
|
316 |
|
|
|
317 |
|
|
|
318 |
if($isJson) {
|
|
|
319 |
|
|
|
320 |
$data = [
|
|
|
321 |
'following' => $following ,
|
|
|
322 |
'total_connections' => $total_connections,
|
|
|
323 |
'user_id' => $user->uuid,
|
|
|
324 |
'user_uuid' => ($user->uuid),
|
3188 |
efrain |
325 |
'full_name' => trim($user->first_name . ' ' . $user->last_name),
|
1 |
www |
326 |
'user_profile_id' => $userProfile->id,
|
|
|
327 |
'user_profile_uuid' => $userProfile->uuid,
|
2729 |
efrain |
328 |
'image' => $this->url()->fromRoute('storage',['code' => $user->uuid, 'type' => 'user-profile', 'filename' => $user->image]),
|
|
|
329 |
'cover' => $this->url()->fromRoute('storage',['code' => $user->uuid, 'type' => 'user-cover', 'filename' => $userProfile->cover]),
|
1 |
www |
330 |
'overview' => $userProfile->description,
|
|
|
331 |
'facebook' => $userProfile->facebook,
|
|
|
332 |
'instagram' => $userProfile->instagram,
|
|
|
333 |
'twitter' => $userProfile->twitter,
|
|
|
334 |
'formatted_address' => $formattedAddress,
|
|
|
335 |
'country' => $country,
|
|
|
336 |
'user_skills' => $userSkills,
|
|
|
337 |
'user_languages' => $userLanguages,
|
|
|
338 |
'user_educations' => $userEducations,
|
|
|
339 |
'user_experiences' => $userExperiences,
|
|
|
340 |
'common_connection' => $common_connection,
|
|
|
341 |
'views' => $views,
|
|
|
342 |
'show_contact' => $user->id != $currentUser->id,
|
|
|
343 |
'request_connection' => $request_connection,
|
|
|
344 |
'link_cancel' => $connection && $connection->status == Connection::STATUS_SENT ? $this->url()->fromRoute('connection/delete',['id' => $user->uuid ]) : $this->url()->fromRoute('connection/cancel',['id' => $user->uuid]),
|
3191 |
efrain |
345 |
'link_request' => $request_connection ? $this->url()->fromRoute('connection/request',['id' => $user->uuid ]) : '',
|
1 |
www |
346 |
'link_inmail' => $this->url()->fromRoute('inmail',['id' => $user->uuid ]),
|
|
|
347 |
|
|
|
348 |
];
|
|
|
349 |
|
|
|
350 |
return new JsonModel($data);
|
|
|
351 |
|
|
|
352 |
} else {
|
|
|
353 |
|
|
|
354 |
|
|
|
355 |
$this->layout()->setTemplate('layout/layout.phtml');
|
|
|
356 |
$viewModel = new ViewModel();
|
|
|
357 |
$viewModel->setTemplate('leaders-linked/profile/view.phtml');
|
|
|
358 |
$viewModel->setVariables([
|
|
|
359 |
'following' => $following ,
|
|
|
360 |
'total_connections' => $total_connections,
|
|
|
361 |
'user_id' => $user->uuid,
|
|
|
362 |
'user_uuid' => ($user->uuid),
|
3188 |
efrain |
363 |
'full_name' => trim($user->first_name . ' ' . $user->last_name),
|
1 |
www |
364 |
'user_profile_id' => $userProfile->id,
|
|
|
365 |
'user_profile_uuid' => $userProfile->uuid,
|
|
|
366 |
'image' => $userProfile->image,
|
|
|
367 |
'cover' => $userProfile->cover,
|
|
|
368 |
'overview' => $userProfile->description,
|
|
|
369 |
'facebook' => $userProfile->facebook,
|
|
|
370 |
'instagram' => $userProfile->instagram,
|
|
|
371 |
'twitter' => $userProfile->twitter,
|
|
|
372 |
'formatted_address' => $formattedAddress,
|
|
|
373 |
'country' => $country,
|
|
|
374 |
'user_skills' => $userSkills,
|
|
|
375 |
'user_languages' => $userLanguages,
|
|
|
376 |
'user_educations' => $userEducations,
|
|
|
377 |
'user_experiences' => $userExperiences,
|
|
|
378 |
'show_contact' => $user->id != $currentUser->id,
|
|
|
379 |
'request_connection' => $request_connection,
|
|
|
380 |
'link_cancel' => $connection && $connection->status == Connection::STATUS_SENT ? $this->url()->fromRoute('connection/delete',['id' => $user->uuid ]) : $this->url()->fromRoute('connection/cancel',['id' => $user->uuid]),
|
3191 |
efrain |
381 |
'link_request' => $request_connection ? $this->url()->fromRoute('connection/request',['id' => $user->uuid ]) : '',
|
1 |
www |
382 |
'link_inmail' => $this->url()->fromRoute('inmail',['id' => $user->uuid ]),
|
|
|
383 |
|
|
|
384 |
]);
|
|
|
385 |
return $viewModel ;
|
|
|
386 |
}
|
|
|
387 |
}
|
|
|
388 |
|
|
|
389 |
return new JsonModel([
|
|
|
390 |
'success' => false,
|
|
|
391 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
392 |
]);
|
|
|
393 |
|
|
|
394 |
|
|
|
395 |
|
|
|
396 |
}
|
|
|
397 |
|
|
|
398 |
public function peopleViewedProfileAction()
|
|
|
399 |
{
|
|
|
400 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
401 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
402 |
|
|
|
403 |
$request = $this->getRequest();
|
|
|
404 |
if($request->isGet()) {
|
|
|
405 |
|
|
|
406 |
|
|
|
407 |
$headers = $request->getHeaders();
|
|
|
408 |
$isJson = false;
|
|
|
409 |
if($headers->has('Accept')) {
|
|
|
410 |
$accept = $headers->get('Accept');
|
|
|
411 |
|
|
|
412 |
$prioritized = $accept->getPrioritized();
|
|
|
413 |
|
|
|
414 |
foreach($prioritized as $key => $value) {
|
|
|
415 |
$raw = trim($value->getRaw());
|
|
|
416 |
|
|
|
417 |
if(!$isJson) {
|
|
|
418 |
$isJson = strpos($raw, 'json');
|
|
|
419 |
}
|
|
|
420 |
|
|
|
421 |
}
|
|
|
422 |
}
|
|
|
423 |
|
|
|
424 |
if($isJson) {
|
|
|
425 |
$page = (int) $this->params()->fromQuery('page');
|
|
|
426 |
$search = trim(filter_var($this->params()->fromQuery('search', ''), FILTER_SANITIZE_STRING));
|
|
|
427 |
|
|
|
428 |
$mapper = QueryMapper::getInstance($this->adapter);
|
|
|
429 |
$select = $mapper->getSql()->select();
|
|
|
430 |
$select->columns(['visitor_id' => new Expression('DISTINCT(visitor_id)')]);
|
|
|
431 |
$select->from(['p' => ProfileVisitMapper::_TABLE]);
|
|
|
432 |
$select->join(['u' => UserMapper::_TABLE], 'p.visitor_id = u.id ', ['uuid', 'first_name', 'last_name', 'image']);
|
|
|
433 |
$select->where->equalTo('p.visited_id', $currentUser->id)->and->equalTo('u.status', User::STATUS_ACTIVE);
|
|
|
434 |
|
|
|
435 |
if($search) {
|
|
|
436 |
$select->where->NEST->like('first_name', '%' . $search . '%')->or->like('last_name', '%' . $search . '%')->UNNEST;
|
|
|
437 |
}
|
|
|
438 |
$select->order('first_name','last_name');
|
|
|
439 |
|
|
|
440 |
//echo $select->getSqlString($this->adapter->platform); exit;
|
|
|
441 |
|
|
|
442 |
$dbSelect = new DbSelect($select, $this->adapter);
|
|
|
443 |
$paginator = new Paginator($dbSelect);
|
|
|
444 |
$paginator->setCurrentPageNumber($page ? $page : 1);
|
|
|
445 |
$paginator->setItemCountPerPage(10);
|
|
|
446 |
|
|
|
447 |
$items = [];
|
|
|
448 |
$records = $paginator->getCurrentItems();
|
|
|
449 |
|
|
|
450 |
foreach($records as $record)
|
|
|
451 |
{
|
|
|
452 |
|
|
|
453 |
$item = [
|
|
|
454 |
'name' => trim($record['first_name'] . ' ' . $record['last_name']),
|
|
|
455 |
'image' => $this->url()->fromRoute('storage', ['type' => 'user', 'code' => $record['uuid'], 'filename' => $record['image'] ]),
|
|
|
456 |
'link_view' => $this->url()->fromRoute('profile/view', ['id' => $record['uuid'] ]),
|
|
|
457 |
'link_inmail' => $this->url()->fromRoute('inmail', ['id' => $record['uuid'] ]),
|
|
|
458 |
];
|
|
|
459 |
|
|
|
460 |
array_push($items, $item);
|
|
|
461 |
}
|
|
|
462 |
|
|
|
463 |
$response = [
|
|
|
464 |
'success' => true,
|
|
|
465 |
'data' => [
|
|
|
466 |
'total' => [
|
|
|
467 |
'count' => $paginator->getTotalItemCount(),
|
|
|
468 |
'pages' => $paginator->getPages()->pageCount,
|
|
|
469 |
],
|
|
|
470 |
'current' => [
|
|
|
471 |
'items' => $items,
|
|
|
472 |
'page' => $paginator->getCurrentPageNumber(),
|
|
|
473 |
'count' => $paginator->getCurrentItemCount(),
|
|
|
474 |
]
|
|
|
475 |
]
|
|
|
476 |
];
|
|
|
477 |
|
|
|
478 |
|
|
|
479 |
|
|
|
480 |
return new JsonModel($response);
|
|
|
481 |
} else {
|
|
|
482 |
$this->layout()->setTemplate('layout/layout.phtml');
|
|
|
483 |
$viewModel = new ViewModel();
|
|
|
484 |
$viewModel->setTemplate('leaders-linked/profile/people-viewed-profile.phtml');
|
|
|
485 |
return $viewModel ;
|
|
|
486 |
}
|
|
|
487 |
|
|
|
488 |
} else {
|
|
|
489 |
return new JsonModel([
|
|
|
490 |
'success' => false,
|
|
|
491 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
492 |
]);
|
|
|
493 |
}
|
|
|
494 |
}
|
|
|
495 |
|
|
|
496 |
|
|
|
497 |
}
|