| 1 |
www |
1 |
<?php
|
| 6822 |
stevensc |
2 |
|
| 1 |
www |
3 |
/**
|
|
|
4 |
*
|
|
|
5 |
* Controlador: Mis Perfiles
|
|
|
6 |
*
|
|
|
7 |
*/
|
| 6822 |
stevensc |
8 |
|
| 1 |
www |
9 |
declare(strict_types=1);
|
|
|
10 |
|
|
|
11 |
namespace LeadersLinked\Controller;
|
|
|
12 |
|
|
|
13 |
use Laminas\Db\Adapter\AdapterInterface;
|
| 6749 |
efrain |
14 |
use LeadersLinked\Cache\CacheInterface;
|
| 1 |
www |
15 |
use Laminas\Mvc\Controller\AbstractActionController;
|
|
|
16 |
use Laminas\Log\LoggerInterface;
|
|
|
17 |
use Laminas\View\Model\ViewModel;
|
|
|
18 |
use Laminas\View\Model\JsonModel;
|
|
|
19 |
|
|
|
20 |
use LeadersLinked\Form\UserProfile\SkillForm;
|
|
|
21 |
use LeadersLinked\Form\UserProfile\LanguageForm;
|
|
|
22 |
|
|
|
23 |
use LeadersLinked\Library\Functions;
|
|
|
24 |
use LeadersLinked\Mapper\UserProfileMapper;
|
|
|
25 |
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
|
|
|
26 |
use LeadersLinked\Model\UserProfile;
|
|
|
27 |
use LeadersLinked\Mapper\CompanyFollowerMapper;
|
|
|
28 |
use LeadersLinked\Mapper\LocationMapper;
|
|
|
29 |
use LeadersLinked\Model\UserLanguage;
|
|
|
30 |
use LeadersLinked\Mapper\UserLanguageMapper;
|
|
|
31 |
use LeadersLinked\Mapper\UserSkillMapper;
|
|
|
32 |
|
|
|
33 |
use LeadersLinked\Model\UserSkill;
|
|
|
34 |
use LeadersLinked\Mapper\UserMapper;
|
|
|
35 |
use LeadersLinked\Form\UserProfile\ExtendedForm;
|
|
|
36 |
use LeadersLinked\Form\UserProfile\LocationForm;
|
|
|
37 |
use LeadersLinked\Model\Location;
|
|
|
38 |
use LeadersLinked\Form\UserProfile\SocialNetworkForm;
|
|
|
39 |
use LeadersLinked\Form\UserProfile\EducationForm;
|
|
|
40 |
use LeadersLinked\Model\UserEducation;
|
|
|
41 |
use LeadersLinked\Mapper\UserEducationMapper;
|
|
|
42 |
use LeadersLinked\Mapper\DegreeMapper;
|
|
|
43 |
use LeadersLinked\Form\UserProfile\ExperienceForm;
|
| 3912 |
efrain |
44 |
use LeadersLinked\Mapper\AptitudeMapper;
|
| 1 |
www |
45 |
use LeadersLinked\Mapper\LanguageMapper;
|
| 3912 |
efrain |
46 |
use LeadersLinked\Mapper\UserAptitudeMapper;
|
| 1 |
www |
47 |
use LeadersLinked\Mapper\UserExperienceMapper;
|
|
|
48 |
use LeadersLinked\Mapper\IndustryMapper;
|
|
|
49 |
use LeadersLinked\Mapper\CompanySizeMapper;
|
|
|
50 |
use LeadersLinked\Model\UserExperience;
|
|
|
51 |
use LeadersLinked\Mapper\ConnectionMapper;
|
|
|
52 |
use LeadersLinked\Form\UserProfile\ImageForm;
|
|
|
53 |
use LeadersLinked\Library\Image;
|
|
|
54 |
use LeadersLinked\Form\UserProfile\CoverForm;
|
|
|
55 |
use LeadersLinked\Mapper\SkillMapper;
|
|
|
56 |
use LeadersLinked\Form\MyProfiles\CreateForm;
|
| 3912 |
efrain |
57 |
use LeadersLinked\Form\UserProfile\AptitudeForm;
|
|
|
58 |
use LeadersLinked\Model\UserAptitude;
|
|
|
59 |
use LeadersLinked\Form\UserProfile\HobbyAndInterestForm;
|
|
|
60 |
use LeadersLinked\Mapper\HobbyAndInterestMapper;
|
|
|
61 |
use LeadersLinked\Mapper\UserHobbyAndInterestMapper;
|
|
|
62 |
use LeadersLinked\Model\UserHobbyAndInterest;
|
| 1 |
www |
63 |
|
|
|
64 |
|
|
|
65 |
class MyProfilesController extends AbstractActionController
|
|
|
66 |
{
|
|
|
67 |
/**
|
|
|
68 |
*
|
|
|
69 |
* @var AdapterInterface
|
|
|
70 |
*/
|
|
|
71 |
private $adapter;
|
| 6822 |
stevensc |
72 |
|
|
|
73 |
|
| 1 |
www |
74 |
/**
|
|
|
75 |
*
|
| 6749 |
efrain |
76 |
* @var CacheInterface
|
| 1 |
www |
77 |
*/
|
|
|
78 |
private $cache;
|
| 6822 |
stevensc |
79 |
|
| 1 |
www |
80 |
/**
|
|
|
81 |
*
|
|
|
82 |
* @var LoggerInterface
|
|
|
83 |
*/
|
|
|
84 |
private $logger;
|
|
|
85 |
|
| 6822 |
stevensc |
86 |
|
| 1 |
www |
87 |
/**
|
|
|
88 |
*
|
|
|
89 |
* @var array
|
|
|
90 |
*/
|
|
|
91 |
private $config;
|
| 6822 |
stevensc |
92 |
|
| 1 |
www |
93 |
/**
|
|
|
94 |
*
|
|
|
95 |
* @param AdapterInterface $adapter
|
| 6749 |
efrain |
96 |
* @param CacheInterface $cache
|
| 1 |
www |
97 |
* @param LoggerInterface $logger
|
|
|
98 |
* @param array $config
|
|
|
99 |
*/
|
| 6822 |
stevensc |
100 |
public function __construct($adapter, $cache, $logger, $config)
|
| 1 |
www |
101 |
{
|
|
|
102 |
$this->adapter = $adapter;
|
|
|
103 |
$this->cache = $cache;
|
|
|
104 |
$this->logger = $logger;
|
|
|
105 |
$this->config = $config;
|
| 6822 |
stevensc |
106 |
}
|
| 1 |
www |
107 |
|
|
|
108 |
/**
|
|
|
109 |
*
|
|
|
110 |
* Generación del listado de perfiles
|
|
|
111 |
* {@inheritDoc}
|
|
|
112 |
* @see \Laminas\Mvc\Controller\AbstractActionController::indexAction()
|
|
|
113 |
*/
|
|
|
114 |
public function indexAction()
|
|
|
115 |
{
|
|
|
116 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
117 |
$currentUser = $currentUserPlugin->getUser();
|
| 6822 |
stevensc |
118 |
|
| 1 |
www |
119 |
$request = $this->getRequest();
|
| 6822 |
stevensc |
120 |
if ($request->isGet()) {
|
|
|
121 |
|
|
|
122 |
|
| 1 |
www |
123 |
$headers = $request->getHeaders();
|
|
|
124 |
$isJson = false;
|
| 6822 |
stevensc |
125 |
if ($headers->has('Accept')) {
|
| 1 |
www |
126 |
$accept = $headers->get('Accept');
|
| 6822 |
stevensc |
127 |
|
| 1 |
www |
128 |
$prioritized = $accept->getPrioritized();
|
| 6822 |
stevensc |
129 |
|
|
|
130 |
foreach ($prioritized as $key => $value) {
|
| 1 |
www |
131 |
$raw = trim($value->getRaw());
|
| 6822 |
stevensc |
132 |
|
|
|
133 |
if (!$isJson) {
|
| 1 |
www |
134 |
$isJson = str_contains($raw, 'json');
|
|
|
135 |
}
|
|
|
136 |
}
|
|
|
137 |
}
|
| 6822 |
stevensc |
138 |
if ($isJson) {
|
| 6749 |
efrain |
139 |
$search = Functions::sanitizeFilterString($this->params()->fromQuery('search'));
|
| 6822 |
stevensc |
140 |
|
|
|
141 |
|
| 1 |
www |
142 |
$acl = $this->getEvent()->getViewModel()->getVariable('acl');
|
|
|
143 |
$allowView = $acl->isAllowed($currentUser->usertype_id, 'profile/view');
|
|
|
144 |
$allowEdit = $acl->isAllowed($currentUser->usertype_id, 'profile/my-profiles/edit');
|
|
|
145 |
$allowDelete = $acl->isAllowed($currentUser->usertype_id, 'profile/my-profiles/delete');
|
| 6822 |
stevensc |
146 |
|
|
|
147 |
|
| 1 |
www |
148 |
$userProfileMapper = UserProfileMapper::getInstance($this->adapter);
|
| 3255 |
efrain |
149 |
$records = $userProfileMapper->fetchAllByUserIdAndSearch($currentUser->id, $search);
|
| 1 |
www |
150 |
|
| 6822 |
stevensc |
151 |
|
| 1 |
www |
152 |
$items = [];
|
| 6822 |
stevensc |
153 |
foreach ($records as $record) {
|
| 1 |
www |
154 |
|
|
|
155 |
$item = [
|
|
|
156 |
'id' => $record->id,
|
|
|
157 |
'name' => $record->name,
|
| 6822 |
stevensc |
158 |
'image' => $this->url()->fromRoute('storage', ['type' => 'user', 'code' => $currentUser->uuid, 'filename' => $record->image]),
|
|
|
159 |
'link_view' => $allowView ? $this->url()->fromRoute('profile/view', ['id' => $record->uuid]) : '',
|
|
|
160 |
'link_edit' => $allowEdit ? $this->url()->fromRoute('profile/my-profiles/edit', ['id' => $record->uuid]) : '',
|
|
|
161 |
'link_delete' => $allowDelete && $record->public == UserProfile::PUBLIC_NO ? $this->url()->fromRoute('profile/my-profiles/delete', ['id' => $record->uuid]) : '',
|
| 1 |
www |
162 |
];
|
| 6822 |
stevensc |
163 |
|
| 1 |
www |
164 |
array_push($items, $item);
|
|
|
165 |
}
|
|
|
166 |
|
| 6822 |
stevensc |
167 |
|
|
|
168 |
|
| 1 |
www |
169 |
$response = [
|
|
|
170 |
'success' => true,
|
|
|
171 |
'data' => $items
|
|
|
172 |
];
|
| 6822 |
stevensc |
173 |
|
| 1 |
www |
174 |
return new JsonModel($response);
|
|
|
175 |
} else {
|
|
|
176 |
$formAdd = new CreateForm();
|
| 6822 |
stevensc |
177 |
|
| 1 |
www |
178 |
$this->layout()->setTemplate('layout/layout.phtml');
|
|
|
179 |
$viewModel = new ViewModel();
|
|
|
180 |
$viewModel->setTemplate('leaders-linked/my-profiles/index.phtml');
|
|
|
181 |
$viewModel->setVariables([
|
|
|
182 |
'formAdd' => $formAdd,
|
|
|
183 |
|
|
|
184 |
]);
|
| 6822 |
stevensc |
185 |
return $viewModel;
|
| 1 |
www |
186 |
}
|
|
|
187 |
} else {
|
|
|
188 |
return new JsonModel([
|
|
|
189 |
'success' => false,
|
|
|
190 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
191 |
]);
|
|
|
192 |
}
|
|
|
193 |
}
|
| 6822 |
stevensc |
194 |
|
|
|
195 |
|
|
|
196 |
|
| 1 |
www |
197 |
/**
|
|
|
198 |
*
|
|
|
199 |
* Agregar un nuevo perfil
|
|
|
200 |
* @return \Laminas\View\Model\JsonModel
|
|
|
201 |
*/
|
|
|
202 |
public function addAction()
|
|
|
203 |
{
|
|
|
204 |
$request = $this->getRequest();
|
| 6822 |
stevensc |
205 |
|
|
|
206 |
|
|
|
207 |
if ($request->isPost()) {
|
| 1 |
www |
208 |
$form = new CreateForm();
|
|
|
209 |
$dataPost = $request->getPost()->toArray();
|
| 6822 |
stevensc |
210 |
|
| 1 |
www |
211 |
$form->setData($dataPost);
|
| 6822 |
stevensc |
212 |
|
|
|
213 |
if ($form->isValid()) {
|
| 1 |
www |
214 |
$dataPost = (array) $form->getData();
|
| 6822 |
stevensc |
215 |
|
| 1 |
www |
216 |
$hydrator = new ObjectPropertyHydrator();
|
|
|
217 |
$userProfile = new UserProfile();
|
|
|
218 |
$hydrator->hydrate($dataPost, $userProfile);
|
| 6822 |
stevensc |
219 |
|
| 1 |
www |
220 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
221 |
$currentUser = $currentUserPlugin->getUser();
|
| 6822 |
stevensc |
222 |
|
| 1 |
www |
223 |
$userProfile->uuid = Functions::genUUID();
|
|
|
224 |
$userProfile->user_id = $currentUser->id;
|
|
|
225 |
$userProfile->public = \LeadersLinked\Model\UserProfile::PUBLIC_NO;
|
| 6822 |
stevensc |
226 |
|
| 1 |
www |
227 |
$userProfileMapper = UserProfileMapper::getInstance($this->adapter);
|
|
|
228 |
$result = $userProfileMapper->insert($userProfile);
|
| 6822 |
stevensc |
229 |
|
|
|
230 |
if ($result) {
|
| 1 |
www |
231 |
$this->logger->info('Se agrego el perfil ' . ($userProfile->public == UserProfile::PUBLIC_YES ? 'público' : $userProfile->name), ['user_id' => $userProfile->user_id, 'ip' => Functions::getUserIP()]);
|
| 6822 |
stevensc |
232 |
|
| 1 |
www |
233 |
$data = [
|
|
|
234 |
'success' => true,
|
|
|
235 |
'data' => 'LABEL_RECORD_ADDED'
|
|
|
236 |
];
|
|
|
237 |
} else {
|
|
|
238 |
$data = [
|
|
|
239 |
'success' => false,
|
|
|
240 |
'data' => $userProfile->getError()
|
|
|
241 |
];
|
|
|
242 |
}
|
| 6822 |
stevensc |
243 |
|
| 1 |
www |
244 |
return new JsonModel($data);
|
|
|
245 |
} else {
|
|
|
246 |
$messages = [];
|
|
|
247 |
$form_messages = (array) $form->getMessages();
|
| 6822 |
stevensc |
248 |
foreach ($form_messages as $fieldname => $field_messages) {
|
|
|
249 |
|
| 1 |
www |
250 |
$messages[$fieldname] = array_values($field_messages);
|
|
|
251 |
}
|
| 6822 |
stevensc |
252 |
|
| 1 |
www |
253 |
return new JsonModel([
|
|
|
254 |
'success' => false,
|
|
|
255 |
'data' => $messages
|
|
|
256 |
]);
|
|
|
257 |
}
|
|
|
258 |
} else {
|
|
|
259 |
$data = [
|
|
|
260 |
'success' => false,
|
|
|
261 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
262 |
];
|
| 6822 |
stevensc |
263 |
|
| 1 |
www |
264 |
return new JsonModel($data);
|
|
|
265 |
}
|
| 6822 |
stevensc |
266 |
|
| 1 |
www |
267 |
return new JsonModel($data);
|
|
|
268 |
}
|
| 6822 |
stevensc |
269 |
|
| 1 |
www |
270 |
/**
|
|
|
271 |
*
|
|
|
272 |
* Borrar un perfil excepto el público
|
|
|
273 |
* @return \Laminas\View\Model\JsonModel
|
|
|
274 |
*/
|
|
|
275 |
public function deleteAction()
|
|
|
276 |
{
|
| 3648 |
efrain |
277 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
278 |
$currentUser = $currentUserPlugin->getUser();
|
| 6822 |
stevensc |
279 |
|
| 1 |
www |
280 |
$request = $this->getRequest();
|
|
|
281 |
$id = $this->params()->fromRoute('id');
|
| 6822 |
stevensc |
282 |
|
|
|
283 |
if (!$id) {
|
| 1 |
www |
284 |
$data = [
|
|
|
285 |
'success' => false,
|
|
|
286 |
'data' => 'ERROR_INVALID_PARAMETER'
|
|
|
287 |
];
|
| 6822 |
stevensc |
288 |
|
| 1 |
www |
289 |
return new JsonModel($data);
|
|
|
290 |
}
|
| 6822 |
stevensc |
291 |
|
|
|
292 |
|
|
|
293 |
|
| 1 |
www |
294 |
$userProfileMapper = UserProfileMapper::getInstance($this->adapter);
|
|
|
295 |
$userProfile = $userProfileMapper->fetchOneByUuid($id);
|
| 6822 |
stevensc |
296 |
if (!$userProfile) {
|
| 1 |
www |
297 |
$data = [
|
|
|
298 |
'success' => false,
|
|
|
299 |
'data' => 'ERROR_RECORD_NOT_FOUND'
|
|
|
300 |
];
|
| 6822 |
stevensc |
301 |
|
| 1 |
www |
302 |
return new JsonModel($data);
|
|
|
303 |
}
|
| 3648 |
efrain |
304 |
|
| 6822 |
stevensc |
305 |
|
|
|
306 |
if ($currentUser->id != $userProfile->user_id) {
|
| 1 |
www |
307 |
$response = [
|
|
|
308 |
'success' => false,
|
|
|
309 |
'data' => 'ERROR_UNAUTHORIZED'
|
|
|
310 |
];
|
| 6822 |
stevensc |
311 |
|
| 1 |
www |
312 |
return new JsonModel($response);
|
|
|
313 |
}
|
| 6822 |
stevensc |
314 |
|
|
|
315 |
if (!$userProfile->public == UserProfile::PUBLIC_YES) {
|
| 1 |
www |
316 |
$data = [
|
|
|
317 |
'success' => false,
|
|
|
318 |
'data' => 'ERROR_PUBLIC_PROFILE'
|
|
|
319 |
];
|
| 6822 |
stevensc |
320 |
|
| 1 |
www |
321 |
return new JsonModel($data);
|
|
|
322 |
}
|
| 6822 |
stevensc |
323 |
|
|
|
324 |
if ($request->isPost()) {
|
| 1 |
www |
325 |
$result = $userProfileMapper->delete($userProfile);
|
| 6822 |
stevensc |
326 |
if ($result) {
|
| 1 |
www |
327 |
$this->logger->info('Se borro el perfil ' . ($userProfile->public == UserProfile::PUBLIC_YES ? 'público' : $userProfile->name), ['user_id' => $userProfile->user_id, 'ip' => Functions::getUserIP()]);
|
| 6822 |
stevensc |
328 |
|
| 1 |
www |
329 |
$data = [
|
|
|
330 |
'success' => true,
|
|
|
331 |
'data' => 'LABEL_RECORD_DELETED'
|
|
|
332 |
];
|
|
|
333 |
} else {
|
| 6822 |
stevensc |
334 |
|
| 1 |
www |
335 |
$data = [
|
|
|
336 |
'success' => false,
|
|
|
337 |
'data' => $userProfileMapper->getError()
|
|
|
338 |
];
|
| 6822 |
stevensc |
339 |
|
| 1 |
www |
340 |
return new JsonModel($data);
|
|
|
341 |
}
|
|
|
342 |
} else {
|
|
|
343 |
$data = [
|
|
|
344 |
'success' => false,
|
|
|
345 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
346 |
];
|
| 6822 |
stevensc |
347 |
|
| 1 |
www |
348 |
return new JsonModel($data);
|
|
|
349 |
}
|
| 6822 |
stevensc |
350 |
|
| 1 |
www |
351 |
return new JsonModel($data);
|
|
|
352 |
}
|
| 6822 |
stevensc |
353 |
|
| 1 |
www |
354 |
/**
|
|
|
355 |
* Presenta el perfil con las opciónes de edición de cada sección
|
|
|
356 |
* @return \Laminas\Http\Response|\Laminas\View\Model\ViewModel|\Laminas\View\Model\JsonModel
|
|
|
357 |
*/
|
|
|
358 |
public function editAction()
|
|
|
359 |
{
|
| 3648 |
efrain |
360 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
361 |
$currentUser = $currentUserPlugin->getUser();
|
| 6822 |
stevensc |
362 |
|
| 1 |
www |
363 |
$flashMessenger = $this->plugin('FlashMessenger');
|
| 6822 |
stevensc |
364 |
|
|
|
365 |
|
| 1 |
www |
366 |
$request = $this->getRequest();
|
|
|
367 |
$id = $this->params()->fromRoute('id');
|
| 6822 |
stevensc |
368 |
|
|
|
369 |
|
|
|
370 |
if (!$id) {
|
| 1 |
www |
371 |
$flashMessenger->addErrorMessage('ERROR_INVALID_PARAMETER');
|
|
|
372 |
return $this->redirect()->toRoute('dashboard');
|
|
|
373 |
}
|
| 6822 |
stevensc |
374 |
|
|
|
375 |
|
|
|
376 |
|
| 1 |
www |
377 |
$userProfileMapper = UserProfileMapper::getInstance($this->adapter);
|
|
|
378 |
$userProfile = $userProfileMapper->fetchOneByUuid($id);
|
| 6822 |
stevensc |
379 |
|
|
|
380 |
if (!$userProfile) {
|
| 1 |
www |
381 |
$flashMessenger->addErrorMessage('ERROR_RECORD_NOT_FOUND');
|
|
|
382 |
return $this->redirect()->toRoute('dashboard');
|
|
|
383 |
}
|
| 6822 |
stevensc |
384 |
|
|
|
385 |
if ($currentUser->id != $userProfile->user_id) {
|
| 1 |
www |
386 |
$flashMessenger->addErrorMessage('ERROR_UNAUTHORIZED');
|
|
|
387 |
return $this->redirect()->toRoute('dashboard');
|
|
|
388 |
}
|
| 6822 |
stevensc |
389 |
|
|
|
390 |
|
| 1 |
www |
391 |
$sandbox = $this->config['leaderslinked.runmode.sandbox'];
|
| 6822 |
stevensc |
392 |
if ($sandbox) {
|
| 1 |
www |
393 |
$google_map_key = $this->config['leaderslinked.google_map.sandbox_api_key'];
|
|
|
394 |
} else {
|
|
|
395 |
$google_map_key = $this->config['leaderslinked.google_map.production_api_key'];
|
|
|
396 |
}
|
| 6822 |
stevensc |
397 |
|
|
|
398 |
if ($request->isGet()) {
|
|
|
399 |
|
|
|
400 |
if ($userProfile->location_id) {
|
|
|
401 |
$locationMapper = LocationMapper::getInstance($this->adapter);
|
| 1 |
www |
402 |
$location = $locationMapper->fetchOne($userProfile->location_id);
|
| 6822 |
stevensc |
403 |
|
| 1 |
www |
404 |
$formattedAddress = $location->formatted_address;
|
|
|
405 |
$country = $location->country;
|
|
|
406 |
} else {
|
|
|
407 |
$formattedAddress = '';
|
|
|
408 |
$country = '';
|
|
|
409 |
}
|
| 6822 |
stevensc |
410 |
|
|
|
411 |
|
|
|
412 |
|
| 1 |
www |
413 |
$userMapper = UserMapper::getInstance($this->adapter);
|
|
|
414 |
$user = $userMapper->fetchOne($userProfile->user_id);
|
| 6822 |
stevensc |
415 |
|
| 1 |
www |
416 |
$userLanguages = [];
|
|
|
417 |
$languageMapper = LanguageMapper::getInstance($this->adapter);
|
|
|
418 |
$userLanguageMapper = UserLanguageMapper::getInstance($this->adapter);
|
|
|
419 |
$records = $userLanguageMapper->fetchAllByUserProfileId($userProfile->id);
|
| 6822 |
stevensc |
420 |
foreach ($records as $record) {
|
| 1 |
www |
421 |
$language = $languageMapper->fetchOne($record->language_id);
|
|
|
422 |
$userLanguages[$language->id] = $language->name;
|
|
|
423 |
}
|
| 6822 |
stevensc |
424 |
|
|
|
425 |
|
| 1 |
www |
426 |
$locationMapper = LocationMapper::getInstance($this->adapter);
|
|
|
427 |
$degreeMapper = DegreeMapper::getInstance($this->adapter);
|
|
|
428 |
$userEducationMapper = UserEducationMapper::getInstance($this->adapter);
|
|
|
429 |
$userEducations = $userEducationMapper->fetchAllByUserProfileId($userProfile->id);
|
| 6822 |
stevensc |
430 |
|
|
|
431 |
|
|
|
432 |
|
|
|
433 |
foreach ($userEducations as &$userEducation) {
|
| 1 |
www |
434 |
$location = $locationMapper->fetchOne($userEducation->location_id);
|
|
|
435 |
$degree = $degreeMapper->fetchOne($userEducation->degree_id);
|
| 6822 |
stevensc |
436 |
|
| 1 |
www |
437 |
$userEducation = [
|
|
|
438 |
'university' => $userEducation->university,
|
|
|
439 |
'degree' => $degree->name,
|
|
|
440 |
'field_of_study' => $userEducation->field_of_study,
|
|
|
441 |
'grade_or_percentage' => $userEducation->grade_or_percentage,
|
|
|
442 |
'formatted_address' => $location->formatted_address,
|
|
|
443 |
'from_year' => $userEducation->from_year,
|
|
|
444 |
'to_year' => $userEducation->to_year,
|
|
|
445 |
'description' => $userEducation->description,
|
| 6822 |
stevensc |
446 |
'link_edit' => $this->url()->fromRoute('profile/my-profiles/education', ['id' => $userProfile->uuid, 'operation' => 'edit', 'user_education_id' => $userEducation->uuid]),
|
|
|
447 |
'link_delete' => $this->url()->fromRoute('profile/my-profiles/education', ['id' => $userProfile->uuid, 'operation' => 'delete', 'user_education_id' => $userEducation->uuid]),
|
| 1 |
www |
448 |
];
|
|
|
449 |
}
|
| 6822 |
stevensc |
450 |
|
| 1 |
www |
451 |
$industryMapper = IndustryMapper::getInstance($this->adapter);
|
|
|
452 |
$companySizeMapper = CompanySizeMapper::getInstance($this->adapter);
|
| 6822 |
stevensc |
453 |
|
| 1 |
www |
454 |
$userExperienceMapper = UserExperienceMapper::getInstance($this->adapter);
|
|
|
455 |
$userExperiences = $userExperienceMapper->fetchAllByUserProfileId($userProfile->id);
|
| 6822 |
stevensc |
456 |
|
|
|
457 |
foreach ($userExperiences as &$userExperience) {
|
| 1 |
www |
458 |
$location = $locationMapper->fetchOne($userExperience->location_id);
|
|
|
459 |
$companySize = $companySizeMapper->fetchOne($userExperience->company_size_id);
|
|
|
460 |
$industry = $industryMapper->fetchOne($userExperience->industry_id);
|
| 6822 |
stevensc |
461 |
|
| 1 |
www |
462 |
$userExperience = [
|
|
|
463 |
'company' => $userExperience->company,
|
|
|
464 |
'industry' => $industry->name,
|
| 6822 |
stevensc |
465 |
'size' => $companySize->name . ' (' . $companySize->minimum_no_of_employee . '-' . $companySize->maximum_no_of_employee . ')',
|
| 1 |
www |
466 |
'title' => $userExperience->title,
|
|
|
467 |
'formatted_address' => $location->formatted_address,
|
|
|
468 |
'from_year' => $userExperience->from_year,
|
|
|
469 |
'from_month' => $userExperience->from_month,
|
|
|
470 |
'to_year' => $userExperience->to_year,
|
|
|
471 |
'to_month' => $userExperience->to_month,
|
|
|
472 |
'description' => $userExperience->description,
|
|
|
473 |
'is_current' => $userExperience->is_current,
|
| 6822 |
stevensc |
474 |
'link_edit' => $this->url()->fromRoute('profile/my-profiles/experience', ['id' => $userProfile->uuid, 'operation' => 'edit', 'user_experience_id' => $userExperience->uuid]),
|
|
|
475 |
'link_delete' => $this->url()->fromRoute('profile/my-profiles/experience', ['id' => $userProfile->uuid, 'operation' => 'delete', 'user_experience_id' => $userExperience->uuid]),
|
| 1 |
www |
476 |
];
|
|
|
477 |
}
|
| 6822 |
stevensc |
478 |
|
|
|
479 |
|
| 1 |
www |
480 |
$headers = $request->getHeaders();
|
| 6822 |
stevensc |
481 |
|
| 1 |
www |
482 |
$isJson = false;
|
| 6822 |
stevensc |
483 |
if ($headers->has('Accept')) {
|
| 1 |
www |
484 |
$accept = $headers->get('Accept');
|
| 6822 |
stevensc |
485 |
|
| 1 |
www |
486 |
$prioritized = $accept->getPrioritized();
|
| 6822 |
stevensc |
487 |
|
|
|
488 |
foreach ($prioritized as $key => $value) {
|
| 1 |
www |
489 |
$raw = trim($value->getRaw());
|
| 6822 |
stevensc |
490 |
|
|
|
491 |
if (!$isJson) {
|
| 1 |
www |
492 |
$isJson = strpos($raw, 'json');
|
|
|
493 |
}
|
|
|
494 |
}
|
|
|
495 |
}
|
| 6822 |
stevensc |
496 |
|
| 3912 |
efrain |
497 |
$userAptitudes = [];
|
|
|
498 |
$aptitudeMapper = AptitudeMapper::getInstance($this->adapter);
|
|
|
499 |
$userAptitudeMapper = UserAptitudeMapper::getInstance($this->adapter);
|
|
|
500 |
$records = $userAptitudeMapper->fetchAllByUserProfileId($userProfile->id);
|
| 6822 |
stevensc |
501 |
foreach ($records as $record) {
|
| 3912 |
efrain |
502 |
$aptitude = $aptitudeMapper->fetchOne($record->aptitude_id);
|
| 6822 |
stevensc |
503 |
if ($aptitude) {
|
| 3912 |
efrain |
504 |
$userAptitudes[$aptitude->uuid] = $aptitude->name;
|
|
|
505 |
}
|
|
|
506 |
}
|
| 6822 |
stevensc |
507 |
|
| 3912 |
efrain |
508 |
$userHobbiesAndInterests = [];
|
|
|
509 |
$hobbyAndInterestMapper = HobbyAndInterestMapper::getInstance($this->adapter);
|
|
|
510 |
$userHobbyAndInterestMapper = UserHobbyAndInterestMapper::getInstance($this->adapter);
|
|
|
511 |
$records = $userHobbyAndInterestMapper->fetchAllByUserProfileId($userProfile->id);
|
| 6822 |
stevensc |
512 |
foreach ($records as $record) {
|
| 3912 |
efrain |
513 |
$hobbyAndInterest = $hobbyAndInterestMapper->fetchOne($record->hobby_and_interest_id);
|
| 6822 |
stevensc |
514 |
if ($hobbyAndInterest) {
|
| 3912 |
efrain |
515 |
$userHobbiesAndInterests[$hobbyAndInterest->uuid] = $hobbyAndInterest->name;
|
|
|
516 |
}
|
|
|
517 |
}
|
| 1 |
www |
518 |
|
| 6822 |
stevensc |
519 |
|
| 1 |
www |
520 |
$userSkills = [];
|
|
|
521 |
$userSkillMapper = UserSkillMapper::getInstance($this->adapter);
|
|
|
522 |
$skillMapper = SkillMapper::getInstance($this->adapter);
|
|
|
523 |
$records = $userSkillMapper->fetchAllByUserProfileId($userProfile->id);
|
| 6822 |
stevensc |
524 |
foreach ($records as $record) {
|
| 1 |
www |
525 |
$skill = $skillMapper->fetchOne($record->skill_id);
|
|
|
526 |
$userSkills[$skill->uuid] = $skill->name;
|
|
|
527 |
}
|
| 6822 |
stevensc |
528 |
|
|
|
529 |
|
| 1 |
www |
530 |
$companyFollowerMapper = CompanyFollowerMapper::getInstance($this->adapter);
|
|
|
531 |
$following = $companyFollowerMapper->getCountFollowing($user->id);
|
| 6822 |
stevensc |
532 |
|
| 1 |
www |
533 |
$connectionMapper = ConnectionMapper::getInstance($this->adapter);
|
|
|
534 |
$follower = $connectionMapper->fetchTotalConnectionByUser($user->id);
|
| 6822 |
stevensc |
535 |
|
|
|
536 |
|
| 1 |
www |
537 |
$image_size_cover = $this->config['leaderslinked.image_sizes.user_cover_upload'];
|
|
|
538 |
$image_size_profile = $this->config['leaderslinked.image_sizes.user_upload'];
|
| 6822 |
stevensc |
539 |
|
|
|
540 |
|
|
|
541 |
if ($isJson) {
|
|
|
542 |
|
| 1 |
www |
543 |
$data = [
|
| 6822 |
stevensc |
544 |
'following' => $following,
|
| 1 |
www |
545 |
'follower' => $follower,
|
|
|
546 |
'user_id' => $user->id,
|
|
|
547 |
'user_uuid' => $user->uuid,
|
|
|
548 |
'full_name' => trim($user->first_name . ' ' . $user->last_name),
|
|
|
549 |
'user_profile_id' => $userProfile->id,
|
|
|
550 |
'user_profile_uuid' => $userProfile->uuid,
|
|
|
551 |
'image' => $userProfile->image,
|
|
|
552 |
'cover' => $userProfile->cover,
|
|
|
553 |
'overview' => $userProfile->description,
|
|
|
554 |
'facebook' => $userProfile->facebook,
|
|
|
555 |
'instagram' => $userProfile->instagram,
|
|
|
556 |
'twitter' => $userProfile->twitter,
|
|
|
557 |
'formatted_address' => $formattedAddress,
|
|
|
558 |
'country' => $country,
|
|
|
559 |
'user_skills' => $userSkills,
|
|
|
560 |
'user_languages' => $userLanguages,
|
|
|
561 |
'user_educations' => $userEducations,
|
|
|
562 |
'user_experiences' => $userExperiences,
|
| 3912 |
efrain |
563 |
'user_aptitudes' => $userAptitudes,
|
|
|
564 |
'user_hobbies_and_interests' => $userHobbiesAndInterests,
|
| 1 |
www |
565 |
'image_size_cover' => $image_size_cover,
|
|
|
566 |
'image_size_profile' => $image_size_profile
|
|
|
567 |
];
|
| 6822 |
stevensc |
568 |
|
| 1 |
www |
569 |
$viewModel = new JsonModel($data);
|
|
|
570 |
} else {
|
|
|
571 |
$industries = [];
|
|
|
572 |
$industryMapper = IndustryMapper::getInstance($this->adapter);
|
| 6822 |
stevensc |
573 |
|
| 3454 |
efrain |
574 |
$records = $industryMapper->fetchAllActive();
|
| 6822 |
stevensc |
575 |
foreach ($records as $record) {
|
| 1 |
www |
576 |
$industries[$record->uuid] = $record->name;
|
|
|
577 |
}
|
| 6822 |
stevensc |
578 |
|
| 1 |
www |
579 |
$companySizes = [];
|
|
|
580 |
$companySizeMapper = CompanySizeMapper::getInstance($this->adapter);
|
| 3454 |
efrain |
581 |
$records = $companySizeMapper->fetchAllActive();
|
| 6822 |
stevensc |
582 |
foreach ($records as $record) {
|
|
|
583 |
$companySizes[$record->uuid] = $record->name . ' (' . $record->minimum_no_of_employee . '-' . $record->maximum_no_of_employee . ')';
|
| 1 |
www |
584 |
}
|
| 6822 |
stevensc |
585 |
|
| 1 |
www |
586 |
$degrees = [];
|
|
|
587 |
$degreeMapper = DegreeMapper::getInstance($this->adapter);
|
| 3454 |
efrain |
588 |
$records = $degreeMapper->fetchAllActive();
|
| 6822 |
stevensc |
589 |
foreach ($records as $record) {
|
| 1 |
www |
590 |
$degrees[$record->uuid] = $record->name;
|
|
|
591 |
}
|
| 6822 |
stevensc |
592 |
|
| 1 |
www |
593 |
$languages = [];
|
|
|
594 |
$languageMapper = LanguageMapper::getInstance($this->adapter);
|
| 3454 |
efrain |
595 |
$records = $languageMapper->fetchAllActive();
|
| 6822 |
stevensc |
596 |
foreach ($records as $record) {
|
| 1 |
www |
597 |
$languages[$record->id] = $record->name;
|
|
|
598 |
}
|
| 6822 |
stevensc |
599 |
|
| 1 |
www |
600 |
$skills = [];
|
|
|
601 |
$skillMapper = SkillMapper::getInstance($this->adapter);
|
| 3454 |
efrain |
602 |
$records = $skillMapper->fetchAllActive();
|
| 6822 |
stevensc |
603 |
foreach ($records as $record) {
|
| 1 |
www |
604 |
$skills[$record->uuid] = $record->name;
|
|
|
605 |
}
|
| 6822 |
stevensc |
606 |
|
| 3912 |
efrain |
607 |
$aptitudes = [];
|
|
|
608 |
$aptitudeMapper = AptitudeMapper::getInstance($this->adapter);
|
|
|
609 |
$records = $aptitudeMapper->fetchAllActive();
|
| 6822 |
stevensc |
610 |
foreach ($records as $record) {
|
| 3912 |
efrain |
611 |
$aptitudes[$record->uuid] = $record->name;
|
|
|
612 |
}
|
| 6822 |
stevensc |
613 |
|
|
|
614 |
|
| 3912 |
efrain |
615 |
$hobbiesAndInterests = [];
|
|
|
616 |
$hobbyAndInterestMapper = HobbyAndInterestMapper::getInstance($this->adapter);
|
|
|
617 |
$records = $hobbyAndInterestMapper->fetchAllActive();
|
| 6822 |
stevensc |
618 |
foreach ($records as $record) {
|
| 3912 |
efrain |
619 |
$hobbiesAndInterests[$record->uuid] = $record->name;
|
|
|
620 |
}
|
| 6822 |
stevensc |
621 |
|
|
|
622 |
|
|
|
623 |
|
| 1 |
www |
624 |
$formSkill = new SkillForm($this->adapter);
|
|
|
625 |
$formLanguage = new LanguageForm($this->adapter);
|
|
|
626 |
$formLocation = new LocationForm();
|
|
|
627 |
$formExtended = new ExtendedForm();
|
|
|
628 |
$formExperience = new ExperienceForm($this->adapter);
|
|
|
629 |
$formEducation = new EducationForm($this->adapter);
|
|
|
630 |
$formSocialNetwork = new SocialNetworkForm();
|
|
|
631 |
$formImage = new ImageForm($this->config);
|
|
|
632 |
$formCover = new CoverForm($this->config);
|
|
|
633 |
|
|
|
634 |
|
| 6822 |
stevensc |
635 |
|
|
|
636 |
|
| 1 |
www |
637 |
$this->layout()->setTemplate('layout/layout.phtml');
|
|
|
638 |
$viewModel = new ViewModel();
|
|
|
639 |
$viewModel->setTemplate('leaders-linked/my-profiles/edit.phtml');
|
|
|
640 |
$viewModel->setVariables([
|
|
|
641 |
'google_map_key' => $google_map_key,
|
| 6822 |
stevensc |
642 |
'following' => $following,
|
| 1 |
www |
643 |
'follower' => $follower,
|
|
|
644 |
'user_id' => $user->id,
|
|
|
645 |
'user_uuid' => $user->uuid,
|
|
|
646 |
'full_name' => trim($user->first_name . ' ' . $user->last_name),
|
|
|
647 |
'user_profile_id' => $userProfile->id,
|
|
|
648 |
'user_profile_uuid' => $userProfile->uuid,
|
|
|
649 |
'public' => $userProfile->public,
|
|
|
650 |
'image' => $userProfile->image,
|
|
|
651 |
'cover' => $userProfile->cover,
|
|
|
652 |
'overview' => $userProfile->description,
|
|
|
653 |
'facebook' => $userProfile->facebook,
|
|
|
654 |
'instagram' => $userProfile->instagram,
|
|
|
655 |
'twitter' => $userProfile->twitter,
|
|
|
656 |
'formatted_address' => $formattedAddress,
|
|
|
657 |
'country' => $country,
|
|
|
658 |
'user_skills' => $userSkills,
|
|
|
659 |
'user_languages' => $userLanguages,
|
|
|
660 |
'user_educations' => $userEducations,
|
|
|
661 |
'user_experiences' => $userExperiences,
|
|
|
662 |
'company_sizes' => $companySizes,
|
|
|
663 |
'degrees' => $degrees,
|
|
|
664 |
'industries' => $industries,
|
|
|
665 |
'languages' => $languages,
|
|
|
666 |
'skills' => $skills,
|
| 3912 |
efrain |
667 |
'aptitudes' => $aptitudes,
|
|
|
668 |
'hobbies_and_interests' => $hobbiesAndInterests,
|
| 6822 |
stevensc |
669 |
|
| 3912 |
efrain |
670 |
'user_aptitudes' => $userAptitudes,
|
|
|
671 |
'user_hobbies_and_interests' => $userHobbiesAndInterests,
|
| 1 |
www |
672 |
'formLanguage' => $formLanguage,
|
|
|
673 |
'formLocation' => $formLocation,
|
|
|
674 |
'formSkill' => $formSkill,
|
|
|
675 |
'formSocialNetwork' => $formSocialNetwork,
|
|
|
676 |
'formExtended' => $formExtended,
|
|
|
677 |
'formExperience' => $formExperience,
|
|
|
678 |
'formEducation' => $formEducation,
|
|
|
679 |
'formImage' => $formImage,
|
|
|
680 |
'formCover' => $formCover,
|
|
|
681 |
'image_size_cover' => $image_size_cover,
|
|
|
682 |
'image_size_profile' => $image_size_profile
|
|
|
683 |
]);
|
|
|
684 |
}
|
| 6822 |
stevensc |
685 |
return $viewModel;
|
| 1 |
www |
686 |
} else {
|
|
|
687 |
$data = [
|
|
|
688 |
'success' => false,
|
|
|
689 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
690 |
];
|
| 6822 |
stevensc |
691 |
|
| 1 |
www |
692 |
return new JsonModel($data);
|
|
|
693 |
}
|
| 6822 |
stevensc |
694 |
|
| 1 |
www |
695 |
return new JsonModel($data);
|
|
|
696 |
}
|
| 6822 |
stevensc |
697 |
|
| 1 |
www |
698 |
/**
|
|
|
699 |
* Actualización de las habilidades
|
|
|
700 |
* @return \Laminas\View\Model\JsonModel
|
|
|
701 |
*/
|
|
|
702 |
public function skillAction()
|
|
|
703 |
{
|
| 3648 |
efrain |
704 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
705 |
$currentUser = $currentUserPlugin->getUser();
|
| 6822 |
stevensc |
706 |
|
| 1 |
www |
707 |
$user_profile_id = $this->params()->fromRoute('id');
|
|
|
708 |
$userProfileMapper = UserProfileMapper::getInstance($this->adapter);
|
| 6822 |
stevensc |
709 |
|
| 1 |
www |
710 |
$userProfile = $userProfileMapper->fetchOneByUuid($user_profile_id);
|
| 6822 |
stevensc |
711 |
if (!$userProfile) {
|
| 1 |
www |
712 |
$response = [
|
|
|
713 |
'success' => false,
|
|
|
714 |
'data' => 'ERROR_INVALID_PARAMETER'
|
|
|
715 |
];
|
| 6822 |
stevensc |
716 |
|
| 1 |
www |
717 |
return new JsonModel($response);
|
|
|
718 |
}
|
| 3648 |
efrain |
719 |
|
| 6822 |
stevensc |
720 |
if ($currentUser->id != $userProfile->user_id) {
|
| 1 |
www |
721 |
$response = [
|
|
|
722 |
'success' => false,
|
|
|
723 |
'data' => 'ERROR_UNAUTHORIZED'
|
|
|
724 |
];
|
| 6822 |
stevensc |
725 |
|
| 1 |
www |
726 |
return new JsonModel($response);
|
|
|
727 |
}
|
| 6822 |
stevensc |
728 |
|
|
|
729 |
|
|
|
730 |
|
| 1 |
www |
731 |
$request = $this->getRequest();
|
| 6822 |
stevensc |
732 |
if ($request->isGet()) {
|
| 1 |
www |
733 |
$skillMapper = SkillMapper::getInstance($this->adapter);
|
| 6822 |
stevensc |
734 |
|
|
|
735 |
|
| 1 |
www |
736 |
$userSkillMapper = UserSkillMapper::getInstance($this->adapter);
|
|
|
737 |
$userSkills = $userSkillMapper->fetchAllByUserProfileId($userProfile->id);
|
| 6822 |
stevensc |
738 |
|
| 1 |
www |
739 |
$items = [];
|
| 6822 |
stevensc |
740 |
foreach ($userSkills as $userSkill) {
|
| 1 |
www |
741 |
$skill = $skillMapper->fetchOne($userSkill->skill_id);
|
|
|
742 |
array_push($items, $skill->uuid);
|
|
|
743 |
}
|
| 6822 |
stevensc |
744 |
|
| 1 |
www |
745 |
$data = [
|
|
|
746 |
'success' => true,
|
|
|
747 |
'data' => $items
|
|
|
748 |
];
|
| 6822 |
stevensc |
749 |
|
| 1 |
www |
750 |
return new JsonModel($data);
|
| 6822 |
stevensc |
751 |
} else if ($request->isPost()) {
|
|
|
752 |
|
| 1 |
www |
753 |
$form = new SkillForm($this->adapter);
|
|
|
754 |
$dataPost = $request->getPost()->toArray();
|
| 6822 |
stevensc |
755 |
|
| 1 |
www |
756 |
$form->setData($dataPost);
|
| 6822 |
stevensc |
757 |
|
|
|
758 |
if ($form->isValid()) {
|
| 1 |
www |
759 |
$this->logger->info('Se actualizaron las habilidades del perfil ' . ($userProfile->public == UserProfile::PUBLIC_YES ? 'público' : $userProfile->name), ['user_id' => $userProfile->user_id, 'ip' => Functions::getUserIP()]);
|
| 6822 |
stevensc |
760 |
|
| 1 |
www |
761 |
$skillMapper = SkillMapper::getInstance($this->adapter);
|
| 6822 |
stevensc |
762 |
|
|
|
763 |
|
| 1 |
www |
764 |
$userSkillMapper = UserSkillMapper::getInstance($this->adapter);
|
|
|
765 |
$userSkillMapper->deleteByUserProfileId($userProfile->id);
|
| 6822 |
stevensc |
766 |
|
| 1 |
www |
767 |
$dataPost = (array) $form->getData();
|
|
|
768 |
$skills = $dataPost['skills'];
|
| 6822 |
stevensc |
769 |
foreach ($skills as $skill_uuid) {
|
|
|
770 |
|
| 1 |
www |
771 |
$skill = $skillMapper->fetchOneByUuid($skill_uuid);
|
| 6822 |
stevensc |
772 |
|
|
|
773 |
|
|
|
774 |
|
| 1 |
www |
775 |
$userSkill = new UserSkill();
|
|
|
776 |
$userSkill->user_id = $userProfile->user_id;
|
|
|
777 |
$userSkill->user_profile_id = $userProfile->id;
|
|
|
778 |
$userSkill->skill_id = $skill->id;
|
| 6822 |
stevensc |
779 |
|
| 1 |
www |
780 |
$userSkillMapper->insert($userSkill);
|
|
|
781 |
}
|
| 6822 |
stevensc |
782 |
|
| 1 |
www |
783 |
$items = [];
|
| 6822 |
stevensc |
784 |
|
| 1 |
www |
785 |
$records = $userSkillMapper->fetchAllByUserProfileId($userProfile->id);
|
| 6822 |
stevensc |
786 |
foreach ($records as $record) {
|
| 1 |
www |
787 |
$skill = $skillMapper->fetchOne($record->skill_id);
|
|
|
788 |
array_push($items, ['value' => $skill->uuid, 'label' => $skill->name]);
|
|
|
789 |
}
|
| 6822 |
stevensc |
790 |
|
| 1 |
www |
791 |
return new JsonModel([
|
|
|
792 |
'success' => true,
|
|
|
793 |
'data' => $items
|
|
|
794 |
]);
|
|
|
795 |
} else {
|
|
|
796 |
$messages = [];
|
|
|
797 |
$form_messages = (array) $form->getMessages();
|
| 6822 |
stevensc |
798 |
foreach ($form_messages as $fieldname => $field_messages) {
|
| 1 |
www |
799 |
$messages[$fieldname] = array_values($field_messages);
|
|
|
800 |
}
|
| 6822 |
stevensc |
801 |
|
| 1 |
www |
802 |
return new JsonModel([
|
|
|
803 |
'success' => false,
|
|
|
804 |
'data' => $messages
|
|
|
805 |
]);
|
|
|
806 |
}
|
| 6822 |
stevensc |
807 |
}
|
| 3912 |
efrain |
808 |
|
| 6822 |
stevensc |
809 |
|
| 1 |
www |
810 |
$data = [
|
|
|
811 |
'success' => false,
|
|
|
812 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
813 |
];
|
| 6822 |
stevensc |
814 |
|
|
|
815 |
|
| 1 |
www |
816 |
return new JsonModel($data);
|
|
|
817 |
}
|
| 6822 |
stevensc |
818 |
|
| 1 |
www |
819 |
/**
|
|
|
820 |
* Actualización de los idiomas
|
|
|
821 |
* @return \Laminas\View\Model\JsonModel
|
|
|
822 |
*/
|
|
|
823 |
public function languageAction()
|
|
|
824 |
{
|
| 6822 |
stevensc |
825 |
|
| 3648 |
efrain |
826 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
827 |
$currentUser = $currentUserPlugin->getUser();
|
| 6822 |
stevensc |
828 |
|
| 1 |
www |
829 |
$user_profile_id = $this->params()->fromRoute('id');
|
|
|
830 |
$userProfileMapper = UserProfileMapper::getInstance($this->adapter);
|
| 6822 |
stevensc |
831 |
|
| 1 |
www |
832 |
$userProfile = $userProfileMapper->fetchOneByUuid($user_profile_id);
|
| 6822 |
stevensc |
833 |
if (!$userProfile) {
|
| 1 |
www |
834 |
$response = [
|
|
|
835 |
'success' => false,
|
|
|
836 |
'data' => 'ERROR_INVALID_PARAMETER'
|
|
|
837 |
];
|
| 6822 |
stevensc |
838 |
|
| 1 |
www |
839 |
return new JsonModel($response);
|
|
|
840 |
}
|
| 6822 |
stevensc |
841 |
|
|
|
842 |
|
|
|
843 |
if ($currentUser->id != $userProfile->user_id) {
|
| 1 |
www |
844 |
$response = [
|
|
|
845 |
'success' => false,
|
|
|
846 |
'data' => 'ERROR_UNAUTHORIZED'
|
|
|
847 |
];
|
| 6822 |
stevensc |
848 |
|
| 1 |
www |
849 |
return new JsonModel($response);
|
|
|
850 |
}
|
| 6822 |
stevensc |
851 |
|
|
|
852 |
|
|
|
853 |
|
| 1 |
www |
854 |
$request = $this->getRequest();
|
| 6822 |
stevensc |
855 |
if ($request->isGet()) {
|
| 1 |
www |
856 |
$this->logger->info('Se actualizaron los idiomas del perfil ' . ($userProfile->public == UserProfile::PUBLIC_YES ? 'público' : $userProfile->name), ['user_id' => $userProfile->user_id, 'ip' => Functions::getUserIP()]);
|
| 6822 |
stevensc |
857 |
|
| 1 |
www |
858 |
$userLanguageMapper = UserLanguageMapper::getInstance($this->adapter);
|
|
|
859 |
$languages = $userLanguageMapper->fetchAllByUserProfileId($userProfile->id);
|
| 6822 |
stevensc |
860 |
|
| 1 |
www |
861 |
$items = [];
|
| 6822 |
stevensc |
862 |
foreach ($languages as $language) {
|
| 1 |
www |
863 |
array_push($items, $language->language_id);
|
|
|
864 |
}
|
| 6822 |
stevensc |
865 |
|
| 1 |
www |
866 |
$data = [
|
|
|
867 |
'success' => true,
|
|
|
868 |
'data' => $items
|
|
|
869 |
];
|
| 6822 |
stevensc |
870 |
|
| 1 |
www |
871 |
return new JsonModel($data);
|
| 6822 |
stevensc |
872 |
} else if ($request->isPost()) {
|
|
|
873 |
|
| 1 |
www |
874 |
$form = new LanguageForm($this->adapter);
|
|
|
875 |
$dataPost = $request->getPost()->toArray();
|
| 6822 |
stevensc |
876 |
|
| 1 |
www |
877 |
$form->setData($dataPost);
|
| 6822 |
stevensc |
878 |
|
|
|
879 |
if ($form->isValid()) {
|
|
|
880 |
|
| 1 |
www |
881 |
$languageMapper = LanguageMapper::getInstance($this->adapter);
|
|
|
882 |
$userLanguageMapper = UserLanguageMapper::getInstance($this->adapter);
|
|
|
883 |
$userLanguageMapper->deleteByUserProfileId($userProfile->id);
|
| 6822 |
stevensc |
884 |
|
| 1 |
www |
885 |
$dataPost = (array) $form->getData();
|
|
|
886 |
$languages = $dataPost['languages'];
|
| 6822 |
stevensc |
887 |
foreach ($languages as $language_id) {
|
| 1 |
www |
888 |
$language = $languageMapper->fetchOne($language_id);
|
| 6822 |
stevensc |
889 |
|
| 1 |
www |
890 |
$userLanguage = new UserLanguage();
|
|
|
891 |
$userLanguage->user_id = $userProfile->user_id;
|
|
|
892 |
$userLanguage->user_profile_id = $userProfile->id;
|
|
|
893 |
$userLanguage->language_id = $language->id;
|
| 6822 |
stevensc |
894 |
|
| 1 |
www |
895 |
$userLanguageMapper->insert($userLanguage);
|
|
|
896 |
}
|
| 6822 |
stevensc |
897 |
|
| 1 |
www |
898 |
$items = [];
|
|
|
899 |
$records = $userLanguageMapper->fetchAllByUserProfileId($userProfile->id);
|
| 6822 |
stevensc |
900 |
foreach ($records as $record) {
|
| 1 |
www |
901 |
$language = $languageMapper->fetchOne($record->language_id);
|
|
|
902 |
array_push($items, ['value' => $language->id, 'label' => $language->name]);
|
|
|
903 |
}
|
| 6822 |
stevensc |
904 |
|
| 1 |
www |
905 |
return new JsonModel([
|
|
|
906 |
'success' => true,
|
|
|
907 |
'data' => $items
|
|
|
908 |
]);
|
|
|
909 |
} else {
|
|
|
910 |
$messages = [];
|
|
|
911 |
$form_messages = (array) $form->getMessages();
|
| 6822 |
stevensc |
912 |
foreach ($form_messages as $fieldname => $field_messages) {
|
| 1 |
www |
913 |
$messages[$fieldname] = array_values($field_messages);
|
|
|
914 |
}
|
| 6822 |
stevensc |
915 |
|
| 1 |
www |
916 |
return new JsonModel([
|
|
|
917 |
'success' => false,
|
|
|
918 |
'data' => $messages
|
|
|
919 |
]);
|
|
|
920 |
}
|
|
|
921 |
}
|
| 6822 |
stevensc |
922 |
|
|
|
923 |
|
| 1 |
www |
924 |
$data = [
|
|
|
925 |
'success' => false,
|
|
|
926 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
927 |
];
|
| 6822 |
stevensc |
928 |
|
|
|
929 |
|
| 1 |
www |
930 |
return new JsonModel($data);
|
|
|
931 |
}
|
| 6822 |
stevensc |
932 |
|
| 1 |
www |
933 |
/**
|
|
|
934 |
* Actualización de la descripción y cualquier otro campo extendido del perfil a futuro
|
|
|
935 |
* @return \Laminas\View\Model\JsonModel
|
|
|
936 |
*/
|
|
|
937 |
public function extendedAction()
|
|
|
938 |
{
|
| 3648 |
efrain |
939 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
940 |
$currentUser = $currentUserPlugin->getUser();
|
| 6822 |
stevensc |
941 |
|
|
|
942 |
|
| 1 |
www |
943 |
$user_profile_id = $this->params()->fromRoute('id');
|
|
|
944 |
$userProfileMapper = UserProfileMapper::getInstance($this->adapter);
|
| 6822 |
stevensc |
945 |
|
| 1 |
www |
946 |
$userProfile = $userProfileMapper->fetchOneByUuid($user_profile_id);
|
| 6822 |
stevensc |
947 |
if (!$userProfile) {
|
| 1 |
www |
948 |
$response = [
|
|
|
949 |
'success' => false,
|
|
|
950 |
'data' => 'ERROR_INVALID_PARAMETER'
|
|
|
951 |
];
|
| 6822 |
stevensc |
952 |
|
| 1 |
www |
953 |
return new JsonModel($response);
|
|
|
954 |
}
|
| 6822 |
stevensc |
955 |
|
|
|
956 |
if ($currentUser->id != $userProfile->user_id) {
|
| 1 |
www |
957 |
$response = [
|
|
|
958 |
'success' => false,
|
|
|
959 |
'data' => 'ERROR_UNAUTHORIZED'
|
|
|
960 |
];
|
| 6822 |
stevensc |
961 |
|
| 1 |
www |
962 |
return new JsonModel($response);
|
|
|
963 |
}
|
| 6822 |
stevensc |
964 |
|
|
|
965 |
|
|
|
966 |
|
| 1 |
www |
967 |
$request = $this->getRequest();
|
| 6822 |
stevensc |
968 |
if ($request->isGet()) {
|
| 1 |
www |
969 |
$data = [
|
|
|
970 |
'success' => true,
|
|
|
971 |
'data' => [
|
|
|
972 |
'description' => $userProfile->description,
|
|
|
973 |
]
|
|
|
974 |
];
|
| 6822 |
stevensc |
975 |
|
| 1 |
www |
976 |
return new JsonModel($data);
|
| 6822 |
stevensc |
977 |
} else if ($request->isPost()) {
|
|
|
978 |
|
|
|
979 |
|
| 1 |
www |
980 |
$form = new ExtendedForm();
|
|
|
981 |
$dataPost = $request->getPost()->toArray();
|
| 6822 |
stevensc |
982 |
|
| 1 |
www |
983 |
$form->setData($dataPost);
|
| 6822 |
stevensc |
984 |
|
|
|
985 |
if ($form->isValid()) {
|
| 1 |
www |
986 |
$dataPost = (array) $form->getData();
|
| 6822 |
stevensc |
987 |
|
| 1 |
www |
988 |
$hydrator = new ObjectPropertyHydrator();
|
|
|
989 |
$hydrator->hydrate($dataPost, $userProfile);
|
| 6822 |
stevensc |
990 |
|
| 1 |
www |
991 |
$userProfileMapper->updateExtended($userProfile);
|
| 6822 |
stevensc |
992 |
|
| 1 |
www |
993 |
$this->logger->info('Se actualizo las descripción del perfil ' . ($userProfile->public == UserProfile::PUBLIC_YES ? 'público' : $userProfile->name), ['user_id' => $userProfile->user_id, 'ip' => Functions::getUserIP()]);
|
| 6822 |
stevensc |
994 |
|
| 1 |
www |
995 |
return new JsonModel([
|
|
|
996 |
'success' => true,
|
|
|
997 |
'data' => [
|
|
|
998 |
'description' => $userProfile->description,
|
|
|
999 |
]
|
|
|
1000 |
]);
|
|
|
1001 |
} else {
|
|
|
1002 |
$messages = [];
|
|
|
1003 |
$form_messages = (array) $form->getMessages();
|
| 6822 |
stevensc |
1004 |
foreach ($form_messages as $fieldname => $field_messages) {
|
| 1 |
www |
1005 |
$messages[$fieldname] = array_values($field_messages);
|
|
|
1006 |
}
|
| 6822 |
stevensc |
1007 |
|
| 1 |
www |
1008 |
return new JsonModel([
|
|
|
1009 |
'success' => false,
|
|
|
1010 |
'data' => $messages
|
|
|
1011 |
]);
|
|
|
1012 |
}
|
|
|
1013 |
}
|
| 6822 |
stevensc |
1014 |
|
|
|
1015 |
|
| 1 |
www |
1016 |
$data = [
|
|
|
1017 |
'success' => false,
|
|
|
1018 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
1019 |
];
|
| 6822 |
stevensc |
1020 |
|
|
|
1021 |
|
| 1 |
www |
1022 |
return new JsonModel($data);
|
|
|
1023 |
}
|
| 6822 |
stevensc |
1024 |
|
| 1 |
www |
1025 |
/**
|
|
|
1026 |
* Actualización de la ubucación
|
|
|
1027 |
* @return \Laminas\View\Model\JsonModel
|
|
|
1028 |
*/
|
|
|
1029 |
public function locationAction()
|
|
|
1030 |
{
|
| 3648 |
efrain |
1031 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
1032 |
$currentUser = $currentUserPlugin->getUser();
|
| 6822 |
stevensc |
1033 |
|
| 1 |
www |
1034 |
$user_profile_id = $this->params()->fromRoute('id');
|
|
|
1035 |
$userProfileMapper = UserProfileMapper::getInstance($this->adapter);
|
| 6822 |
stevensc |
1036 |
|
| 1 |
www |
1037 |
$userProfile = $userProfileMapper->fetchOneByUuid($user_profile_id);
|
| 6822 |
stevensc |
1038 |
if (!$userProfile) {
|
| 1 |
www |
1039 |
$response = [
|
|
|
1040 |
'success' => false,
|
|
|
1041 |
'data' => 'ERROR_INVALID_PARAMETER'
|
|
|
1042 |
];
|
| 6822 |
stevensc |
1043 |
|
| 1 |
www |
1044 |
return new JsonModel($response);
|
|
|
1045 |
}
|
| 3648 |
efrain |
1046 |
|
| 6822 |
stevensc |
1047 |
|
|
|
1048 |
if ($currentUser->id != $userProfile->user_id) {
|
| 1 |
www |
1049 |
$response = [
|
|
|
1050 |
'success' => false,
|
|
|
1051 |
'data' => 'ERROR_UNAUTHORIZED'
|
|
|
1052 |
];
|
| 6822 |
stevensc |
1053 |
|
| 1 |
www |
1054 |
return new JsonModel($response);
|
|
|
1055 |
}
|
| 6822 |
stevensc |
1056 |
|
|
|
1057 |
|
|
|
1058 |
|
| 1 |
www |
1059 |
$request = $this->getRequest();
|
| 6822 |
stevensc |
1060 |
if ($request->isPost()) {
|
|
|
1061 |
|
| 1 |
www |
1062 |
$form = new LocationForm();
|
|
|
1063 |
$dataPost = $request->getPost()->toArray();
|
| 6822 |
stevensc |
1064 |
|
| 1 |
www |
1065 |
$form->setData($dataPost);
|
| 6822 |
stevensc |
1066 |
|
|
|
1067 |
if ($form->isValid()) {
|
| 1 |
www |
1068 |
$this->logger->info('Se actualizaron la ubicación del perfil ' . ($userProfile->public == UserProfile::PUBLIC_YES ? 'público' : $userProfile->name), ['user_id' => $userProfile->user_id, 'ip' => Functions::getUserIP()]);
|
| 6822 |
stevensc |
1069 |
|
| 1 |
www |
1070 |
$dataPost = (array) $form->getData();
|
| 6822 |
stevensc |
1071 |
|
| 1 |
www |
1072 |
$location = new Location();
|
|
|
1073 |
$hydrator = new ObjectPropertyHydrator();
|
|
|
1074 |
$hydrator->hydrate($dataPost, $location);
|
| 6822 |
stevensc |
1075 |
|
| 1 |
www |
1076 |
$location->id = $userProfile->location_id ? $userProfile->location_id : null;
|
| 6822 |
stevensc |
1077 |
|
|
|
1078 |
|
|
|
1079 |
|
| 1 |
www |
1080 |
$locationMapper = LocationMapper::getInstance($this->adapter);
|
| 6822 |
stevensc |
1081 |
if ($userProfile->location_id) {
|
| 1 |
www |
1082 |
$result = $locationMapper->update($location);
|
|
|
1083 |
} else {
|
|
|
1084 |
$result = $locationMapper->insert($location);
|
| 6822 |
stevensc |
1085 |
|
|
|
1086 |
if ($result) {
|
| 1 |
www |
1087 |
$userProfile->location_id = $location->id;
|
|
|
1088 |
$userProfileMapper->updateLocation($userProfile);
|
|
|
1089 |
}
|
|
|
1090 |
}
|
| 6822 |
stevensc |
1091 |
|
|
|
1092 |
if ($result) {
|
|
|
1093 |
if ($userProfile->public == UserProfile::PUBLIC_YES) {
|
| 1 |
www |
1094 |
$currentUser->location_id = $location->id;
|
| 6822 |
stevensc |
1095 |
|
| 1 |
www |
1096 |
$userMapper = UserMapper::getInstance($this->adapter);
|
|
|
1097 |
$userMapper->updateLocation($currentUser);
|
|
|
1098 |
}
|
| 6822 |
stevensc |
1099 |
|
|
|
1100 |
|
| 1 |
www |
1101 |
$response = [
|
|
|
1102 |
'success' => true,
|
|
|
1103 |
'data' => [
|
|
|
1104 |
'formatted_address' => $location->formatted_address,
|
|
|
1105 |
'country' => $location->country,
|
|
|
1106 |
]
|
|
|
1107 |
];
|
|
|
1108 |
} else {
|
|
|
1109 |
$response = [
|
|
|
1110 |
'success' => false,
|
|
|
1111 |
'data' => 'ERROR_THERE_WAS_AN_ERROR'
|
|
|
1112 |
];
|
|
|
1113 |
}
|
| 6822 |
stevensc |
1114 |
|
|
|
1115 |
|
|
|
1116 |
|
| 1 |
www |
1117 |
return new JsonModel($response);
|
|
|
1118 |
} else {
|
|
|
1119 |
return new JsonModel([
|
|
|
1120 |
'success' => false,
|
|
|
1121 |
'data' => 'ERROR_PLACED_AUTOCOMPLETE_DOES_NOT_CONTAIN_GEOMETRY'
|
|
|
1122 |
]);
|
|
|
1123 |
}
|
|
|
1124 |
}
|
| 6822 |
stevensc |
1125 |
|
|
|
1126 |
|
| 1 |
www |
1127 |
$data = [
|
|
|
1128 |
'success' => false,
|
|
|
1129 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
1130 |
];
|
| 6822 |
stevensc |
1131 |
|
|
|
1132 |
|
| 1 |
www |
1133 |
return new JsonModel($data);
|
|
|
1134 |
}
|
| 6822 |
stevensc |
1135 |
|
| 1 |
www |
1136 |
/**
|
|
|
1137 |
* Actualización de las redes sociales
|
|
|
1138 |
* @return \Laminas\View\Model\JsonModel
|
|
|
1139 |
*/
|
|
|
1140 |
public function socialNetworkAction()
|
|
|
1141 |
{
|
| 3648 |
efrain |
1142 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
1143 |
$currentUser = $currentUserPlugin->getUser();
|
| 6822 |
stevensc |
1144 |
|
| 1 |
www |
1145 |
$user_profile_id = $this->params()->fromRoute('id');
|
|
|
1146 |
$userProfileMapper = UserProfileMapper::getInstance($this->adapter);
|
| 6822 |
stevensc |
1147 |
|
| 1 |
www |
1148 |
$userProfile = $userProfileMapper->fetchOneByUuid($user_profile_id);
|
| 6822 |
stevensc |
1149 |
if (!$userProfile) {
|
| 1 |
www |
1150 |
$response = [
|
|
|
1151 |
'success' => false,
|
|
|
1152 |
'data' => 'ERROR_INVALID_PARAMETER'
|
|
|
1153 |
];
|
| 6822 |
stevensc |
1154 |
|
| 1 |
www |
1155 |
return new JsonModel($response);
|
|
|
1156 |
}
|
| 3648 |
efrain |
1157 |
|
| 6822 |
stevensc |
1158 |
|
|
|
1159 |
if ($currentUser->id != $userProfile->user_id) {
|
| 1 |
www |
1160 |
$response = [
|
|
|
1161 |
'success' => false,
|
|
|
1162 |
'data' => 'ERROR_UNAUTHORIZED'
|
|
|
1163 |
];
|
| 6822 |
stevensc |
1164 |
|
| 1 |
www |
1165 |
return new JsonModel($response);
|
|
|
1166 |
}
|
| 6822 |
stevensc |
1167 |
|
|
|
1168 |
|
|
|
1169 |
|
| 1 |
www |
1170 |
$request = $this->getRequest();
|
| 6822 |
stevensc |
1171 |
if ($request->isGet()) {
|
| 1 |
www |
1172 |
$data = [
|
|
|
1173 |
'success' => true,
|
|
|
1174 |
'data' => [
|
|
|
1175 |
'facebook' => $userProfile->facebook,
|
|
|
1176 |
'instagram' => $userProfile->instagram,
|
|
|
1177 |
'twitter' => $userProfile->twitter
|
|
|
1178 |
]
|
|
|
1179 |
];
|
| 6822 |
stevensc |
1180 |
|
| 1 |
www |
1181 |
return new JsonModel($data);
|
| 6822 |
stevensc |
1182 |
} else if ($request->isPost()) {
|
|
|
1183 |
|
| 1 |
www |
1184 |
$form = new SocialNetworkForm();
|
|
|
1185 |
$dataPost = $request->getPost()->toArray();
|
| 6822 |
stevensc |
1186 |
|
| 1 |
www |
1187 |
$form->setData($dataPost);
|
| 6822 |
stevensc |
1188 |
|
|
|
1189 |
if ($form->isValid()) {
|
| 1 |
www |
1190 |
$this->logger->info('Se actualizaron las redes sociales del perfil ' . ($userProfile->public == UserProfile::PUBLIC_YES ? 'público' : $userProfile->name), ['user_id' => $userProfile->user_id, 'ip' => Functions::getUserIP()]);
|
| 6822 |
stevensc |
1191 |
|
| 1 |
www |
1192 |
$dataPost = (array) $form->getData();
|
| 6822 |
stevensc |
1193 |
|
| 1 |
www |
1194 |
$hydrator = new ObjectPropertyHydrator();
|
|
|
1195 |
$hydrator->hydrate($dataPost, $userProfile);
|
| 6822 |
stevensc |
1196 |
|
| 1 |
www |
1197 |
$userProfileMapper->updateSocialNetwork($userProfile);
|
|
|
1198 |
return new JsonModel([
|
|
|
1199 |
'success' => true,
|
|
|
1200 |
'data' => [
|
|
|
1201 |
'facebook' => $userProfile->facebook,
|
|
|
1202 |
'instagram' => $userProfile->instagram,
|
|
|
1203 |
'twitter' => $userProfile->twitter
|
|
|
1204 |
]
|
|
|
1205 |
]);
|
|
|
1206 |
} else {
|
|
|
1207 |
$messages = [];
|
|
|
1208 |
$form_messages = (array) $form->getMessages();
|
| 6822 |
stevensc |
1209 |
foreach ($form_messages as $fieldname => $field_messages) {
|
| 1 |
www |
1210 |
$messages[$fieldname] = array_values($field_messages);
|
|
|
1211 |
}
|
| 6822 |
stevensc |
1212 |
|
| 1 |
www |
1213 |
return new JsonModel([
|
|
|
1214 |
'success' => false,
|
|
|
1215 |
'data' => $messages
|
|
|
1216 |
]);
|
|
|
1217 |
}
|
|
|
1218 |
}
|
| 6822 |
stevensc |
1219 |
|
|
|
1220 |
|
| 1 |
www |
1221 |
$data = [
|
|
|
1222 |
'success' => false,
|
|
|
1223 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
1224 |
];
|
| 6822 |
stevensc |
1225 |
|
|
|
1226 |
|
| 1 |
www |
1227 |
return new JsonModel($data);
|
|
|
1228 |
}
|
| 6822 |
stevensc |
1229 |
|
| 1 |
www |
1230 |
/**
|
|
|
1231 |
* Actualización de los registros de estudios realizados
|
|
|
1232 |
* @return \Laminas\View\Model\JsonModel
|
|
|
1233 |
*/
|
|
|
1234 |
public function educationAction()
|
|
|
1235 |
{
|
| 6822 |
stevensc |
1236 |
|
| 3648 |
efrain |
1237 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
1238 |
$currentUser = $currentUserPlugin->getUser();
|
| 6822 |
stevensc |
1239 |
|
| 1 |
www |
1240 |
$user_profile_id = $this->params()->fromRoute('id');
|
|
|
1241 |
$user_education_id = $this->params()->fromRoute('user_education_id');
|
|
|
1242 |
$operation = $this->params()->fromRoute('operation');
|
| 6822 |
stevensc |
1243 |
|
| 1 |
www |
1244 |
$userProfileMapper = UserProfileMapper::getInstance($this->adapter);
|
| 6822 |
stevensc |
1245 |
|
| 1 |
www |
1246 |
$userProfile = $userProfileMapper->fetchOneByUuid($user_profile_id);
|
| 6822 |
stevensc |
1247 |
if (!$userProfile) {
|
| 1 |
www |
1248 |
$response = [
|
|
|
1249 |
'success' => false,
|
|
|
1250 |
'data' => 'ERROR_INVALID_PARAMETER'
|
|
|
1251 |
];
|
| 6822 |
stevensc |
1252 |
|
| 1 |
www |
1253 |
return new JsonModel($response);
|
|
|
1254 |
}
|
| 3648 |
efrain |
1255 |
|
| 6822 |
stevensc |
1256 |
|
|
|
1257 |
if ($currentUser->id != $userProfile->user_id) {
|
| 1 |
www |
1258 |
$response = [
|
|
|
1259 |
'success' => false,
|
|
|
1260 |
'data' => 'ERROR_UNAUTHORIZED'
|
|
|
1261 |
];
|
| 6822 |
stevensc |
1262 |
|
| 1 |
www |
1263 |
return new JsonModel($response);
|
|
|
1264 |
}
|
| 6822 |
stevensc |
1265 |
|
|
|
1266 |
|
|
|
1267 |
|
| 1 |
www |
1268 |
$request = $this->getRequest();
|
| 6822 |
stevensc |
1269 |
if ($request->isPost()) {
|
| 1 |
www |
1270 |
$userEducationMapper = UserEducationMapper::getInstance($this->adapter);
|
| 6822 |
stevensc |
1271 |
|
|
|
1272 |
if ($operation == 'delete' || $operation == 'edit') {
|
| 1 |
www |
1273 |
$userEducation = $userEducationMapper->fetchOneByUuid($user_education_id);
|
| 6822 |
stevensc |
1274 |
|
|
|
1275 |
|
|
|
1276 |
if (!$userEducation) {
|
|
|
1277 |
|
| 1 |
www |
1278 |
$response = [
|
|
|
1279 |
'success' => false,
|
|
|
1280 |
'data' => 'ERROR_RECORD_NOT_FOUND'
|
|
|
1281 |
];
|
| 6822 |
stevensc |
1282 |
|
| 1 |
www |
1283 |
return new JsonModel($response);
|
| 6822 |
stevensc |
1284 |
} else if ($userProfile->id != $userEducation->user_profile_id) {
|
| 1 |
www |
1285 |
$response = [
|
|
|
1286 |
'success' => false,
|
|
|
1287 |
'data' => 'ERROR_UNAUTHORIZED'
|
|
|
1288 |
];
|
| 6822 |
stevensc |
1289 |
|
| 1 |
www |
1290 |
return new JsonModel($response);
|
|
|
1291 |
}
|
|
|
1292 |
} else {
|
|
|
1293 |
$userEducation = null;
|
|
|
1294 |
}
|
| 6822 |
stevensc |
1295 |
|
| 1 |
www |
1296 |
$locationMapper = LocationMapper::getInstance($this->adapter);
|
| 6822 |
stevensc |
1297 |
if ($operation == 'delete') {
|
| 1 |
www |
1298 |
$this->logger->info('Se borro un registro de educación del perfil ' . ($userProfile->public == UserProfile::PUBLIC_YES ? 'público' : $userProfile->name), ['user_id' => $userProfile->user_id, 'ip' => Functions::getUserIP()]);
|
| 6822 |
stevensc |
1299 |
|
| 1 |
www |
1300 |
$result = $userEducationMapper->delete($userEducation);
|
| 6822 |
stevensc |
1301 |
if ($result) {
|
| 1 |
www |
1302 |
$locationMapper->delete($userEducation->location_id);
|
|
|
1303 |
}
|
|
|
1304 |
} else {
|
| 6822 |
stevensc |
1305 |
|
|
|
1306 |
|
| 1 |
www |
1307 |
$form = new EducationForm($this->adapter);
|
|
|
1308 |
$dataPost = $request->getPost()->toArray();
|
| 6822 |
stevensc |
1309 |
|
| 1 |
www |
1310 |
$form->setData($dataPost);
|
| 6822 |
stevensc |
1311 |
|
|
|
1312 |
if ($form->isValid()) {
|
|
|
1313 |
|
|
|
1314 |
if (!$userEducation) {
|
| 1 |
www |
1315 |
$userEducation = new UserEducation();
|
|
|
1316 |
$userEducation->user_id = $userProfile->user_id;
|
|
|
1317 |
$userEducation->user_profile_id = $userProfile->id;
|
|
|
1318 |
}
|
| 6822 |
stevensc |
1319 |
|
| 1 |
www |
1320 |
$dataPost = (array) $form->getData();
|
| 6822 |
stevensc |
1321 |
|
| 1 |
www |
1322 |
$hydrator = new ObjectPropertyHydrator();
|
|
|
1323 |
$hydrator->hydrate($dataPost, $userEducation);
|
| 6822 |
stevensc |
1324 |
|
| 1 |
www |
1325 |
$degreeMapper = DegreeMapper::getInstance($this->adapter);
|
|
|
1326 |
$degree = $degreeMapper->fetchOneByUuid($dataPost['degree_id']);
|
|
|
1327 |
$userEducation->degree_id = $degree->id;
|
| 6822 |
stevensc |
1328 |
|
|
|
1329 |
|
|
|
1330 |
|
|
|
1331 |
|
|
|
1332 |
if ($userEducation->location_id) {
|
| 1 |
www |
1333 |
$location = $locationMapper->fetchOne($userEducation->location_id);
|
|
|
1334 |
} else {
|
|
|
1335 |
$location = new Location();
|
|
|
1336 |
}
|
| 6822 |
stevensc |
1337 |
|
|
|
1338 |
$hydrator->hydrate($dataPost, $location);
|
|
|
1339 |
if ($userEducation->location_id) {
|
| 1 |
www |
1340 |
$this->logger->info('Se actualizo un registro de educación del perfil ' . ($userProfile->public == UserProfile::PUBLIC_YES ? 'público' : $userProfile->name), ['user_id' => $userProfile->user_id, 'ip' => Functions::getUserIP()]);
|
| 6822 |
stevensc |
1341 |
|
| 1 |
www |
1342 |
$result = $locationMapper->update($location);
|
|
|
1343 |
} else {
|
|
|
1344 |
$this->logger->info('Se agrego un registro de educación del perfil ' . ($userProfile->public == UserProfile::PUBLIC_YES ? 'público' : $userProfile->name), ['user_id' => $userProfile->user_id, 'ip' => Functions::getUserIP()]);
|
| 6822 |
stevensc |
1345 |
|
| 1 |
www |
1346 |
$result = $locationMapper->insert($location);
|
| 6822 |
stevensc |
1347 |
|
|
|
1348 |
if ($result) {
|
| 1 |
www |
1349 |
$userEducation->location_id = $location->id;
|
|
|
1350 |
}
|
|
|
1351 |
}
|
| 6822 |
stevensc |
1352 |
if ($result) {
|
|
|
1353 |
if ($userEducation->id) {
|
| 1 |
www |
1354 |
$result = $userEducationMapper->update($userEducation);
|
|
|
1355 |
} else {
|
|
|
1356 |
$result = $userEducationMapper->insert($userEducation);
|
|
|
1357 |
}
|
|
|
1358 |
}
|
|
|
1359 |
} else {
|
|
|
1360 |
$messages = [];
|
|
|
1361 |
$form_messages = (array) $form->getMessages();
|
| 6822 |
stevensc |
1362 |
foreach ($form_messages as $fieldname => $field_messages) {
|
| 1 |
www |
1363 |
$messages[$fieldname] = array_values($field_messages);
|
|
|
1364 |
}
|
| 6822 |
stevensc |
1365 |
|
| 1 |
www |
1366 |
return new JsonModel([
|
|
|
1367 |
'success' => false,
|
|
|
1368 |
'data' => $messages
|
|
|
1369 |
]);
|
|
|
1370 |
}
|
|
|
1371 |
}
|
| 6822 |
stevensc |
1372 |
|
|
|
1373 |
if ($result) {
|
| 1 |
www |
1374 |
$degreeMapper = DegreeMapper::getInstance($this->adapter);
|
|
|
1375 |
$userEducations = $userEducationMapper->fetchAllByUserProfileId($userProfile->id);
|
| 6822 |
stevensc |
1376 |
|
|
|
1377 |
foreach ($userEducations as &$userEducation) {
|
| 1 |
www |
1378 |
$location = $locationMapper->fetchOne($userEducation->location_id);
|
|
|
1379 |
$degree = $degreeMapper->fetchOne($userEducation->degree_id);
|
| 6822 |
stevensc |
1380 |
|
| 1 |
www |
1381 |
$userEducation = [
|
|
|
1382 |
'university' => $userEducation->university,
|
|
|
1383 |
'degree' => $degree->name,
|
|
|
1384 |
'field_of_study' => $userEducation->field_of_study,
|
|
|
1385 |
'grade_or_percentage' => $userEducation->grade_or_percentage,
|
|
|
1386 |
'formatted_address' => $location->formatted_address,
|
|
|
1387 |
'from_year' => $userEducation->from_year,
|
|
|
1388 |
'to_year' => $userEducation->to_year,
|
|
|
1389 |
'description' => $userEducation->description,
|
| 6822 |
stevensc |
1390 |
'link_edit' => $this->url()->fromRoute('profile/my-profiles/education', ['id' => $userProfile->uuid, 'operation' => 'edit', 'user_education_id' => $userEducation->uuid]),
|
|
|
1391 |
'link_delete' => $this->url()->fromRoute('profile/my-profiles/education', ['id' => $userProfile->uuid, 'operation' => 'delete', 'user_education_id' => $userEducation->uuid]),
|
| 1 |
www |
1392 |
];
|
|
|
1393 |
}
|
| 6822 |
stevensc |
1394 |
|
| 1 |
www |
1395 |
$response = [
|
|
|
1396 |
'success' => true,
|
|
|
1397 |
'data' => $userEducations
|
|
|
1398 |
];
|
|
|
1399 |
} else {
|
|
|
1400 |
$response = [
|
|
|
1401 |
'success' => false,
|
|
|
1402 |
'data' => 'ERROR_THERE_WAS_AN_ERROR'
|
|
|
1403 |
];
|
|
|
1404 |
}
|
| 6822 |
stevensc |
1405 |
|
|
|
1406 |
|
|
|
1407 |
|
| 1 |
www |
1408 |
return new JsonModel($response);
|
| 6822 |
stevensc |
1409 |
} else if ($request->isGet() && $operation == 'edit') {
|
| 1 |
www |
1410 |
$userEducationMapper = UserEducationMapper::getInstance($this->adapter);
|
|
|
1411 |
$userEducation = $userEducationMapper->fetchOneByUuid($user_education_id);
|
| 6822 |
stevensc |
1412 |
|
|
|
1413 |
if (!$userEducation) {
|
|
|
1414 |
|
| 1 |
www |
1415 |
$response = [
|
|
|
1416 |
'success' => false,
|
|
|
1417 |
'data' => 'ERROR_RECORD_NOT_FOUND'
|
|
|
1418 |
];
|
| 6822 |
stevensc |
1419 |
} else if ($userProfile->id != $userEducation->user_profile_id) {
|
| 1 |
www |
1420 |
$response = [
|
|
|
1421 |
'success' => false,
|
|
|
1422 |
'data' => 'ERROR_UNAUTHORIZED'
|
|
|
1423 |
];
|
|
|
1424 |
} else {
|
|
|
1425 |
$locationMapper = LocationMapper::getInstance($this->adapter);
|
|
|
1426 |
$location = $locationMapper->fetchOne($userEducation->location_id);
|
| 6822 |
stevensc |
1427 |
|
| 1 |
www |
1428 |
$hydrator = new ObjectPropertyHydrator();
|
|
|
1429 |
$education = $hydrator->extract($userEducation);
|
| 6822 |
stevensc |
1430 |
|
| 1 |
www |
1431 |
$degree = $degreeMapper = DegreeMapper::getInstance($this->adapter);
|
|
|
1432 |
$degree = $degreeMapper->fetchOne($education['degree_id']);
|
|
|
1433 |
$education['degree_id'] = $degree->uuid;
|
| 6822 |
stevensc |
1434 |
|
| 1 |
www |
1435 |
$location = [
|
|
|
1436 |
'address1' => $location->address1,
|
|
|
1437 |
'address2' => $location->address2,
|
|
|
1438 |
'city1' => $location->city1,
|
|
|
1439 |
'city2' => $location->city2,
|
|
|
1440 |
'country' => $location->country,
|
|
|
1441 |
'formatted_address' => $location->formatted_address,
|
|
|
1442 |
'latitude' => $location->latitude,
|
|
|
1443 |
'longitude' => $location->longitude,
|
|
|
1444 |
'postal_code' => $location->postal_code,
|
|
|
1445 |
'state' => $location->state,
|
|
|
1446 |
];
|
| 6822 |
stevensc |
1447 |
|
| 1 |
www |
1448 |
$response = [
|
|
|
1449 |
'success' => true,
|
|
|
1450 |
'data' => [
|
|
|
1451 |
'location' => $location,
|
|
|
1452 |
'education' => $education,
|
|
|
1453 |
]
|
|
|
1454 |
];
|
|
|
1455 |
}
|
| 6822 |
stevensc |
1456 |
|
| 1 |
www |
1457 |
return new JsonModel($response);
|
|
|
1458 |
}
|
| 6822 |
stevensc |
1459 |
|
|
|
1460 |
|
|
|
1461 |
|
|
|
1462 |
|
| 1 |
www |
1463 |
$data = [
|
|
|
1464 |
'success' => false,
|
|
|
1465 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
1466 |
];
|
| 6822 |
stevensc |
1467 |
|
|
|
1468 |
|
| 1 |
www |
1469 |
return new JsonModel($data);
|
|
|
1470 |
}
|
| 6822 |
stevensc |
1471 |
|
| 1 |
www |
1472 |
/**
|
|
|
1473 |
* Actualización de los registros de la experiencia laboral
|
|
|
1474 |
* @return \Laminas\View\Model\JsonModel
|
|
|
1475 |
*/
|
|
|
1476 |
public function experienceAction()
|
|
|
1477 |
{
|
| 3648 |
efrain |
1478 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
1479 |
$currentUser = $currentUserPlugin->getUser();
|
| 6822 |
stevensc |
1480 |
|
| 1 |
www |
1481 |
$user_profile_id = $this->params()->fromRoute('id');
|
|
|
1482 |
$user_experience_id = $this->params()->fromRoute('user_experience_id');
|
|
|
1483 |
$operation = $this->params()->fromRoute('operation');
|
| 6822 |
stevensc |
1484 |
|
| 1 |
www |
1485 |
$userProfileMapper = UserProfileMapper::getInstance($this->adapter);
|
| 6822 |
stevensc |
1486 |
|
| 1 |
www |
1487 |
$userProfile = $userProfileMapper->fetchOneByUuid($user_profile_id);
|
| 6822 |
stevensc |
1488 |
if (!$userProfile) {
|
| 1 |
www |
1489 |
$response = [
|
|
|
1490 |
'success' => false,
|
|
|
1491 |
'data' => 'ERROR_INVALID_PARAMETER'
|
|
|
1492 |
];
|
| 6822 |
stevensc |
1493 |
|
| 1 |
www |
1494 |
return new JsonModel($response);
|
|
|
1495 |
}
|
| 6822 |
stevensc |
1496 |
|
|
|
1497 |
if ($currentUser->id != $userProfile->user_id) {
|
| 1 |
www |
1498 |
$response = [
|
|
|
1499 |
'success' => false,
|
|
|
1500 |
'data' => 'ERROR_UNAUTHORIZED'
|
|
|
1501 |
];
|
| 6822 |
stevensc |
1502 |
|
| 1 |
www |
1503 |
return new JsonModel($response);
|
|
|
1504 |
}
|
| 6822 |
stevensc |
1505 |
|
|
|
1506 |
|
|
|
1507 |
|
| 1 |
www |
1508 |
$request = $this->getRequest();
|
| 6822 |
stevensc |
1509 |
if ($request->isPost()) {
|
| 1 |
www |
1510 |
$userExperienceMapper = UserExperienceMapper::getInstance($this->adapter);
|
| 6822 |
stevensc |
1511 |
|
|
|
1512 |
if ($operation == 'delete' || $operation == 'edit') {
|
| 1 |
www |
1513 |
$userExperience = $userExperienceMapper->fetchOneByUuid($user_experience_id);
|
| 6822 |
stevensc |
1514 |
|
|
|
1515 |
if (!$userExperience) {
|
|
|
1516 |
|
| 1 |
www |
1517 |
$response = [
|
|
|
1518 |
'success' => false,
|
|
|
1519 |
'data' => 'ERROR_RECORD_NOT_FOUND'
|
|
|
1520 |
];
|
| 6822 |
stevensc |
1521 |
|
| 1 |
www |
1522 |
return new JsonModel($response);
|
| 6822 |
stevensc |
1523 |
} else if ($userProfile->id != $userExperience->user_profile_id) {
|
| 1 |
www |
1524 |
$response = [
|
|
|
1525 |
'success' => false,
|
|
|
1526 |
'data' => 'ERROR_UNAUTHORIZED'
|
|
|
1527 |
];
|
| 6822 |
stevensc |
1528 |
|
| 1 |
www |
1529 |
return new JsonModel($response);
|
|
|
1530 |
}
|
|
|
1531 |
} else {
|
|
|
1532 |
$userExperience = null;
|
|
|
1533 |
}
|
| 6822 |
stevensc |
1534 |
|
| 1 |
www |
1535 |
$locationMapper = LocationMapper::getInstance($this->adapter);
|
| 6822 |
stevensc |
1536 |
if ($operation == 'delete') {
|
| 1 |
www |
1537 |
$this->logger->info('Se borro un registro de experiencia del perfil ' . ($userProfile->public == UserProfile::PUBLIC_YES ? 'público' : $userProfile->name), ['user_id' => $userProfile->user_id, 'ip' => Functions::getUserIP()]);
|
| 6822 |
stevensc |
1538 |
|
| 1 |
www |
1539 |
$result = $userExperienceMapper->delete($userExperience);
|
| 6822 |
stevensc |
1540 |
if ($result) {
|
| 1 |
www |
1541 |
$locationMapper->delete($userExperience->location_id);
|
|
|
1542 |
}
|
|
|
1543 |
} else {
|
| 6822 |
stevensc |
1544 |
|
|
|
1545 |
|
| 1 |
www |
1546 |
$form = new ExperienceForm($this->adapter);
|
|
|
1547 |
$dataPost = $request->getPost()->toArray();
|
|
|
1548 |
|
| 6822 |
stevensc |
1549 |
|
| 1 |
www |
1550 |
$dataPost['is_current'] = isset($dataPost['is_current']) ? $dataPost['is_current'] : UserExperience::IS_CURRENT_NO;
|
| 6822 |
stevensc |
1551 |
if ($dataPost['is_current'] == UserExperience::IS_CURRENT_YES) {
|
| 1 |
www |
1552 |
$dataPost['to_month'] = 12;
|
|
|
1553 |
$dataPost['to_year'] = date('Y');
|
|
|
1554 |
}
|
| 6822 |
stevensc |
1555 |
|
|
|
1556 |
|
| 1 |
www |
1557 |
$form->setData($dataPost);
|
| 6822 |
stevensc |
1558 |
|
|
|
1559 |
if ($form->isValid()) {
|
|
|
1560 |
|
|
|
1561 |
|
|
|
1562 |
|
|
|
1563 |
|
|
|
1564 |
if (!$userExperience) {
|
| 1 |
www |
1565 |
$userExperience = new UserExperience();
|
|
|
1566 |
$userExperience->user_id = $userProfile->user_id;
|
|
|
1567 |
$userExperience->user_profile_id = $userProfile->id;
|
|
|
1568 |
}
|
| 6822 |
stevensc |
1569 |
|
| 1 |
www |
1570 |
$dataPost = (array) $form->getData();
|
|
|
1571 |
$companySizeMapper = CompanySizeMapper::getInstance($this->adapter);
|
|
|
1572 |
$companySize = $companySizeMapper->fetchOneByUuid($dataPost['company_size_id']);
|
| 6822 |
stevensc |
1573 |
|
| 1 |
www |
1574 |
$industryMapper = IndustryMapper::getInstance($this->adapter);
|
|
|
1575 |
$industry = $industryMapper->fetchOneByUuid($dataPost['industry_id']);
|
| 6822 |
stevensc |
1576 |
|
| 1 |
www |
1577 |
$hydrator = new ObjectPropertyHydrator();
|
|
|
1578 |
$hydrator->hydrate($dataPost, $userExperience);
|
| 6822 |
stevensc |
1579 |
|
| 1 |
www |
1580 |
$userExperience->company_size_id = $companySize->id;
|
|
|
1581 |
$userExperience->industry_id = $industry->id;
|
| 6822 |
stevensc |
1582 |
|
|
|
1583 |
if ($userExperience->is_current == UserExperience::IS_CURRENT_YES) {
|
| 1 |
www |
1584 |
$userExperience->to_month = null;
|
|
|
1585 |
$userExperience->to_year = null;
|
|
|
1586 |
}
|
| 6822 |
stevensc |
1587 |
|
|
|
1588 |
if ($userExperience->location_id) {
|
| 1 |
www |
1589 |
$location = $locationMapper->fetchOne($userExperience->location_id);
|
|
|
1590 |
} else {
|
|
|
1591 |
$location = new Location();
|
|
|
1592 |
}
|
| 6822 |
stevensc |
1593 |
$hydrator->hydrate($dataPost, $location);
|
|
|
1594 |
|
|
|
1595 |
if ($userExperience->location_id) {
|
| 1 |
www |
1596 |
$this->logger->info('Se actualizo un registro de experiencia del perfil ' . ($userProfile->public == UserProfile::PUBLIC_YES ? 'público' : $userProfile->name), ['user_id' => $userProfile->user_id, 'ip' => Functions::getUserIP()]);
|
| 6822 |
stevensc |
1597 |
|
| 1 |
www |
1598 |
$result = $locationMapper->update($location);
|
|
|
1599 |
} else {
|
|
|
1600 |
$this->logger->info('Se agrego un registro de experiencia del perfil ' . ($userProfile->public == UserProfile::PUBLIC_YES ? 'público' : $userProfile->name), ['user_id' => $userProfile->user_id, 'ip' => Functions::getUserIP()]);
|
| 6822 |
stevensc |
1601 |
|
| 1 |
www |
1602 |
$result = $locationMapper->insert($location);
|
| 6822 |
stevensc |
1603 |
|
|
|
1604 |
if ($result) {
|
| 1 |
www |
1605 |
$userExperience->location_id = $location->id;
|
|
|
1606 |
}
|
|
|
1607 |
}
|
| 6822 |
stevensc |
1608 |
if ($result) {
|
|
|
1609 |
if ($userExperience->id) {
|
| 1 |
www |
1610 |
$result = $userExperienceMapper->update($userExperience);
|
|
|
1611 |
} else {
|
|
|
1612 |
$result = $userExperienceMapper->insert($userExperience);
|
|
|
1613 |
}
|
|
|
1614 |
}
|
|
|
1615 |
} else {
|
|
|
1616 |
$messages = [];
|
|
|
1617 |
$form_messages = (array) $form->getMessages();
|
| 6822 |
stevensc |
1618 |
foreach ($form_messages as $fieldname => $field_messages) {
|
| 1 |
www |
1619 |
$messages[$fieldname] = array_values($field_messages);
|
|
|
1620 |
}
|
| 6822 |
stevensc |
1621 |
|
| 1 |
www |
1622 |
return new JsonModel([
|
|
|
1623 |
'success' => false,
|
| 6822 |
stevensc |
1624 |
'data' => $messages,
|
| 1 |
www |
1625 |
]);
|
|
|
1626 |
}
|
|
|
1627 |
}
|
| 6822 |
stevensc |
1628 |
|
|
|
1629 |
if ($result) {
|
| 1 |
www |
1630 |
$industryMapper = IndustryMapper::getInstance($this->adapter);
|
|
|
1631 |
$companySizeMapper = CompanySizeMapper::getInstance($this->adapter);
|
|
|
1632 |
$userExperiences = $userExperienceMapper->fetchAllByUserProfileId($userProfile->id);
|
| 6822 |
stevensc |
1633 |
|
|
|
1634 |
foreach ($userExperiences as &$userExperience) {
|
| 1 |
www |
1635 |
$location = $locationMapper->fetchOne($userExperience->location_id);
|
|
|
1636 |
$companySize = $companySizeMapper->fetchOne($userExperience->company_size_id);
|
|
|
1637 |
$industry = $industryMapper->fetchOne($userExperience->industry_id);
|
| 6822 |
stevensc |
1638 |
|
| 1 |
www |
1639 |
$userExperience = [
|
|
|
1640 |
'company' => $userExperience->company,
|
|
|
1641 |
'industry' => $industry,
|
|
|
1642 |
'size' => $companySize->name . ' (' . $companySize->minimum_no_of_employee . '-' . $companySize->maximum_no_of_employee . ') ',
|
|
|
1643 |
'title' => $userExperience->title,
|
|
|
1644 |
'formatted_address' => $location->formatted_address,
|
|
|
1645 |
'from_year' => $userExperience->from_year,
|
|
|
1646 |
'from_month' => $userExperience->from_month,
|
|
|
1647 |
'to_year' => $userExperience->to_year,
|
|
|
1648 |
'to_month' => $userExperience->to_month,
|
|
|
1649 |
'description' => $userExperience->description,
|
|
|
1650 |
'is_current' => $userExperience->is_current,
|
| 6822 |
stevensc |
1651 |
'link_edit' => $this->url()->fromRoute('profile/my-profiles/experience', ['id' => $userProfile->uuid, 'operation' => 'edit', 'user_experience_id' => $userExperience->uuid]),
|
|
|
1652 |
'link_delete' => $this->url()->fromRoute('profile/my-profiles/experience', ['id' => $userProfile->uuid, 'operation' => 'delete', 'user_experience_id' => $userExperience->uuid]),
|
| 1 |
www |
1653 |
];
|
|
|
1654 |
}
|
| 6822 |
stevensc |
1655 |
|
| 1 |
www |
1656 |
$response = [
|
|
|
1657 |
'success' => true,
|
|
|
1658 |
'data' => $userExperiences
|
|
|
1659 |
];
|
|
|
1660 |
} else {
|
|
|
1661 |
$response = [
|
|
|
1662 |
'success' => false,
|
|
|
1663 |
'data' => 'ERROR_THERE_WAS_AN_ERROR'
|
|
|
1664 |
];
|
|
|
1665 |
}
|
| 6822 |
stevensc |
1666 |
|
| 1 |
www |
1667 |
return new JsonModel($response);
|
| 6822 |
stevensc |
1668 |
} else if ($request->isGet() && $operation == 'edit') {
|
| 1 |
www |
1669 |
$userExperienceMapper = UserExperienceMapper::getInstance($this->adapter);
|
|
|
1670 |
$userExperience = $userExperienceMapper->fetchOneByUuid($user_experience_id);
|
| 6822 |
stevensc |
1671 |
|
|
|
1672 |
if (!$userExperience) {
|
| 1 |
www |
1673 |
$response = [
|
|
|
1674 |
'success' => false,
|
|
|
1675 |
'data' => 'ERROR_RECORD_NOT_FOUND'
|
|
|
1676 |
];
|
| 6822 |
stevensc |
1677 |
} else if ($userProfile->id != $userExperience->user_profile_id) {
|
| 1 |
www |
1678 |
$response = [
|
|
|
1679 |
'success' => false,
|
|
|
1680 |
'data' => 'ERROR_UNAUTHORIZED'
|
|
|
1681 |
];
|
|
|
1682 |
} else {
|
|
|
1683 |
$hydrator = new ObjectPropertyHydrator();
|
|
|
1684 |
$experience = $hydrator->extract($userExperience);
|
| 6822 |
stevensc |
1685 |
|
|
|
1686 |
|
| 1 |
www |
1687 |
$industryMapper = IndustryMapper::getInstance($this->adapter);
|
|
|
1688 |
$industry = $industryMapper->fetchOne($userExperience->industry_id);
|
| 6822 |
stevensc |
1689 |
|
| 1 |
www |
1690 |
$companySizeMapper = CompanySizeMapper::getInstance($this->adapter);
|
|
|
1691 |
$companySize = $companySizeMapper->fetchOne($userExperience->company_size_id);
|
| 6822 |
stevensc |
1692 |
|
| 1 |
www |
1693 |
$experience['industry_id'] = $industry->uuid;
|
|
|
1694 |
$experience['company_size_id'] = $companySize->uuid;
|
|
|
1695 |
|
|
|
1696 |
$locationMapper = LocationMapper::getInstance($this->adapter);
|
|
|
1697 |
$location = $locationMapper->fetchOne($userExperience->location_id);
|
| 6822 |
stevensc |
1698 |
|
| 1 |
www |
1699 |
$response = [
|
|
|
1700 |
'success' => true,
|
|
|
1701 |
'data' => [
|
|
|
1702 |
'location' => $hydrator->extract($location),
|
|
|
1703 |
'experience' => $experience
|
|
|
1704 |
]
|
|
|
1705 |
];
|
|
|
1706 |
}
|
|
|
1707 |
return new JsonModel($response);
|
|
|
1708 |
}
|
| 6822 |
stevensc |
1709 |
|
| 1 |
www |
1710 |
$data = [
|
|
|
1711 |
'success' => false,
|
|
|
1712 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
1713 |
];
|
| 6822 |
stevensc |
1714 |
|
|
|
1715 |
|
| 1 |
www |
1716 |
return new JsonModel($data);
|
|
|
1717 |
}
|
| 6822 |
stevensc |
1718 |
|
| 1 |
www |
1719 |
/**
|
|
|
1720 |
* Cambio de la imagen del image del perfil
|
|
|
1721 |
* @return \Laminas\View\Model\JsonModel
|
|
|
1722 |
*/
|
|
|
1723 |
public function imageAction()
|
|
|
1724 |
{
|
| 3648 |
efrain |
1725 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
1726 |
$currentUser = $currentUserPlugin->getUser();
|
| 6822 |
stevensc |
1727 |
|
| 1 |
www |
1728 |
$user_profile_id = $this->params()->fromRoute('id');
|
|
|
1729 |
$operation = $this->params()->fromRoute('operation');
|
| 6822 |
stevensc |
1730 |
|
| 1 |
www |
1731 |
$userProfileMapper = UserProfileMapper::getInstance($this->adapter);
|
| 6822 |
stevensc |
1732 |
|
| 1 |
www |
1733 |
$userProfile = $userProfileMapper->fetchOneByUuid($user_profile_id);
|
| 6822 |
stevensc |
1734 |
if (!$userProfile) {
|
| 1 |
www |
1735 |
$response = [
|
|
|
1736 |
'success' => false,
|
|
|
1737 |
'data' => 'ERROR_INVALID_PARAMETER'
|
|
|
1738 |
];
|
| 6822 |
stevensc |
1739 |
|
| 1 |
www |
1740 |
return new JsonModel($response);
|
|
|
1741 |
}
|
| 3648 |
efrain |
1742 |
|
| 6822 |
stevensc |
1743 |
if ($currentUser->id != $userProfile->user_id) {
|
| 1 |
www |
1744 |
$response = [
|
|
|
1745 |
'success' => false,
|
|
|
1746 |
'data' => 'ERROR_UNAUTHORIZED'
|
|
|
1747 |
];
|
| 6822 |
stevensc |
1748 |
|
| 1 |
www |
1749 |
return new JsonModel($response);
|
|
|
1750 |
}
|
| 6822 |
stevensc |
1751 |
|
|
|
1752 |
|
|
|
1753 |
|
| 1 |
www |
1754 |
$request = $this->getRequest();
|
| 6822 |
stevensc |
1755 |
if ($request->isPost()) {
|
| 1 |
www |
1756 |
$target_path = $this->config['leaderslinked.fullpath.user'] . $currentUser->uuid;
|
| 6822 |
stevensc |
1757 |
if ($operation == 'delete') {
|
| 1 |
www |
1758 |
$this->logger->info('Se borro el image del perfil ' . ($userProfile->public == UserProfile::PUBLIC_YES ? 'público' : $userProfile->name), ['user_id' => $userProfile->user_id, 'ip' => Functions::getUserIP()]);
|
| 6822 |
stevensc |
1759 |
|
|
|
1760 |
if ($userProfile->image) {
|
|
|
1761 |
if (!Image::delete($target_path, $userProfile->image)) {
|
| 1 |
www |
1762 |
return new JsonModel([
|
|
|
1763 |
'success' => false,
|
|
|
1764 |
'data' => 'ERROR_THERE_WAS_AN_ERROR'
|
|
|
1765 |
]);
|
|
|
1766 |
}
|
|
|
1767 |
}
|
| 6822 |
stevensc |
1768 |
|
| 1 |
www |
1769 |
$userProfile->image = '';
|
| 6822 |
stevensc |
1770 |
if (!$userProfileMapper->updateImage($userProfile)) {
|
| 1 |
www |
1771 |
return new JsonModel([
|
|
|
1772 |
'success' => false,
|
|
|
1773 |
'data' => 'ERROR_THERE_WAS_AN_ERROR'
|
|
|
1774 |
]);
|
|
|
1775 |
}
|
|
|
1776 |
} else {
|
|
|
1777 |
$form = new ImageForm($this->config);
|
| 6822 |
stevensc |
1778 |
$data = array_merge($request->getPost()->toArray(), $request->getFiles()->toArray());
|
|
|
1779 |
|
| 1 |
www |
1780 |
$form->setData($data);
|
| 6822 |
stevensc |
1781 |
|
|
|
1782 |
if ($form->isValid()) {
|
|
|
1783 |
|
| 1 |
www |
1784 |
$files = $request->getFiles()->toArray();
|
| 6822 |
stevensc |
1785 |
if (!empty($files['image']['error'])) {
|
|
|
1786 |
|
| 1 |
www |
1787 |
return new JsonModel([
|
|
|
1788 |
'success' => false,
|
|
|
1789 |
'data' => 'ERROR_UPLOAD_FILE'
|
|
|
1790 |
]);
|
|
|
1791 |
}
|
| 6822 |
stevensc |
1792 |
|
|
|
1793 |
if ($userProfile->image) {
|
|
|
1794 |
if (!Image::delete($target_path, $userProfile->image)) {
|
| 1 |
www |
1795 |
return new JsonModel([
|
|
|
1796 |
'success' => false,
|
|
|
1797 |
'data' => 'ERROR_THERE_WAS_AN_ERROR'
|
|
|
1798 |
]);
|
|
|
1799 |
}
|
|
|
1800 |
}
|
| 6822 |
stevensc |
1801 |
|
|
|
1802 |
list($target_width, $target_height) = explode('x', $this->config['leaderslinked.image_sizes.user_size']);
|
| 1 |
www |
1803 |
$source = $files['image']['tmp_name'];
|
|
|
1804 |
$target_filename = 'user-profile-' . uniqid() . '.png';
|
|
|
1805 |
$crop_to_dimensions = true;
|
| 6822 |
stevensc |
1806 |
|
|
|
1807 |
if (!Image::uploadImage($source, $target_path, $target_filename, $target_width, $target_height, $crop_to_dimensions)) {
|
| 1 |
www |
1808 |
return new JsonModel([
|
|
|
1809 |
'success' => false,
|
|
|
1810 |
'data' => 'ERROR_THERE_WAS_AN_ERROR'
|
|
|
1811 |
]);
|
|
|
1812 |
}
|
| 6822 |
stevensc |
1813 |
|
| 1 |
www |
1814 |
$userProfile->image = $target_filename;
|
| 6822 |
stevensc |
1815 |
if (!$userProfileMapper->updateImage($userProfile)) {
|
| 1 |
www |
1816 |
return new JsonModel([
|
|
|
1817 |
'success' => false,
|
|
|
1818 |
'data' => 'ERROR_THERE_WAS_AN_ERROR'
|
|
|
1819 |
]);
|
|
|
1820 |
}
|
| 6822 |
stevensc |
1821 |
|
|
|
1822 |
if ($userProfile->public == UserProfile::PUBLIC_YES) {
|
|
|
1823 |
|
| 1 |
www |
1824 |
$currentUser->image = $target_filename;
|
| 6822 |
stevensc |
1825 |
|
| 1 |
www |
1826 |
$userMapper = UserMapper::getInstance($this->adapter);
|
| 3163 |
efrain |
1827 |
$userMapper->updateImage($currentUser);
|
| 6822 |
stevensc |
1828 |
}
|
| 3163 |
efrain |
1829 |
|
| 1 |
www |
1830 |
$this->logger->info('Se actualizo el image del perfil ' . ($userProfile->public == UserProfile::PUBLIC_YES ? 'público' : $userProfile->name), ['user_id' => $userProfile->user_id, 'ip' => Functions::getUserIP()]);
|
|
|
1831 |
} else {
|
|
|
1832 |
$messages = [];
|
|
|
1833 |
$form_messages = (array) $form->getMessages();
|
| 6822 |
stevensc |
1834 |
foreach ($form_messages as $fieldname => $field_messages) {
|
| 1 |
www |
1835 |
$messages[$fieldname] = array_values($field_messages);
|
|
|
1836 |
}
|
| 6822 |
stevensc |
1837 |
|
| 1 |
www |
1838 |
return new JsonModel([
|
|
|
1839 |
'success' => false,
|
|
|
1840 |
'data' => $messages
|
|
|
1841 |
]);
|
|
|
1842 |
}
|
|
|
1843 |
}
|
|
|
1844 |
return new JsonModel([
|
|
|
1845 |
'success' => true,
|
| 6822 |
stevensc |
1846 |
'data' => [
|
| 1 |
www |
1847 |
'user' => $this->url()->fromRoute('storage', ['type' => 'user', 'code' => $currentUser->uuid, 'filename' => $currentUser->image]),
|
|
|
1848 |
'profile' => $this->url()->fromRoute('storage', ['type' => 'user-profile', 'code' => $currentUser->uuid, 'filename' => $userProfile->image]),
|
| 3163 |
efrain |
1849 |
'update_navbar' => $userProfile->public == UserProfile::PUBLIC_YES ? 1 : 0,
|
| 6822 |
stevensc |
1850 |
|
| 1 |
www |
1851 |
]
|
|
|
1852 |
]);
|
|
|
1853 |
}
|
| 6822 |
stevensc |
1854 |
|
|
|
1855 |
|
| 1 |
www |
1856 |
$data = [
|
|
|
1857 |
'success' => false,
|
|
|
1858 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
1859 |
];
|
| 6822 |
stevensc |
1860 |
|
|
|
1861 |
|
| 1 |
www |
1862 |
return new JsonModel($data);
|
|
|
1863 |
}
|
| 6822 |
stevensc |
1864 |
|
| 1 |
www |
1865 |
/**
|
|
|
1866 |
* Cambio de la imagen de fondo superior (cover) del perfil
|
|
|
1867 |
* @return \Laminas\View\Model\JsonModel
|
|
|
1868 |
*/
|
|
|
1869 |
public function coverAction()
|
|
|
1870 |
{
|
| 3648 |
efrain |
1871 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
1872 |
$currentUser = $currentUserPlugin->getUser();
|
| 6822 |
stevensc |
1873 |
|
| 1 |
www |
1874 |
$user_profile_id = $this->params()->fromRoute('id');
|
|
|
1875 |
$operation = $this->params()->fromRoute('operation');
|
| 6822 |
stevensc |
1876 |
|
| 1 |
www |
1877 |
$userProfileMapper = UserProfileMapper::getInstance($this->adapter);
|
| 6822 |
stevensc |
1878 |
|
| 1 |
www |
1879 |
$userProfile = $userProfileMapper->fetchOneByUuid($user_profile_id);
|
| 6822 |
stevensc |
1880 |
if (!$userProfile) {
|
| 1 |
www |
1881 |
$response = [
|
|
|
1882 |
'success' => false,
|
|
|
1883 |
'data' => 'ERROR_INVALID_PARAMETER'
|
|
|
1884 |
];
|
| 6822 |
stevensc |
1885 |
|
| 1 |
www |
1886 |
return new JsonModel($response);
|
|
|
1887 |
}
|
| 3648 |
efrain |
1888 |
|
| 6822 |
stevensc |
1889 |
|
|
|
1890 |
|
|
|
1891 |
if ($currentUser->id != $userProfile->user_id) {
|
| 1 |
www |
1892 |
$response = [
|
|
|
1893 |
'success' => false,
|
|
|
1894 |
'data' => 'ERROR_UNAUTHORIZED'
|
|
|
1895 |
];
|
| 6822 |
stevensc |
1896 |
|
| 1 |
www |
1897 |
return new JsonModel($response);
|
|
|
1898 |
}
|
| 6822 |
stevensc |
1899 |
|
|
|
1900 |
|
|
|
1901 |
|
| 1 |
www |
1902 |
$request = $this->getRequest();
|
| 6822 |
stevensc |
1903 |
if ($request->isPost()) {
|
| 1 |
www |
1904 |
$target_path = $this->config['leaderslinked.fullpath.user'] . $currentUser->uuid;
|
| 6822 |
stevensc |
1905 |
|
|
|
1906 |
if ($operation == 'delete') {
|
|
|
1907 |
if ($userProfile->cover) {
|
|
|
1908 |
if (!Image::delete($target_path, $userProfile->cover)) {
|
| 1 |
www |
1909 |
return new JsonModel([
|
|
|
1910 |
'success' => false,
|
|
|
1911 |
'data' => 'ERROR_THERE_WAS_AN_ERROR'
|
|
|
1912 |
]);
|
|
|
1913 |
}
|
|
|
1914 |
}
|
| 6822 |
stevensc |
1915 |
|
| 1 |
www |
1916 |
$this->logger->info('Se borro el cover del perfil ' . ($userProfile->public == UserProfile::PUBLIC_YES ? 'público' : $userProfile->name), ['user_id' => $userProfile->user_id, 'ip' => Functions::getUserIP()]);
|
|
|
1917 |
$userProfile->cover = '';
|
|
|
1918 |
} else {
|
|
|
1919 |
$form = new CoverForm($this->config);
|
| 6822 |
stevensc |
1920 |
$data = array_merge($request->getPost()->toArray(), $request->getFiles()->toArray());
|
|
|
1921 |
|
|
|
1922 |
|
|
|
1923 |
|
| 1 |
www |
1924 |
$form->setData($data);
|
| 6822 |
stevensc |
1925 |
|
|
|
1926 |
if ($form->isValid()) {
|
|
|
1927 |
|
| 1 |
www |
1928 |
$files = $request->getFiles()->toArray();
|
| 6822 |
stevensc |
1929 |
if (!empty($files['cover']['error'])) {
|
|
|
1930 |
|
| 1 |
www |
1931 |
return new JsonModel([
|
|
|
1932 |
'success' => false,
|
|
|
1933 |
'data' => 'ERROR_UPLOAD_FILE'
|
|
|
1934 |
]);
|
|
|
1935 |
}
|
| 6822 |
stevensc |
1936 |
|
|
|
1937 |
|
|
|
1938 |
if ($userProfile->cover) {
|
|
|
1939 |
if (!Image::delete($target_path, $userProfile->cover)) {
|
| 1 |
www |
1940 |
return new JsonModel([
|
|
|
1941 |
'success' => false,
|
|
|
1942 |
'data' => 'ERROR_THERE_WAS_AN_ERROR'
|
|
|
1943 |
]);
|
|
|
1944 |
}
|
|
|
1945 |
}
|
| 6822 |
stevensc |
1946 |
|
| 1 |
www |
1947 |
//echo '$target_path = ' . $target_path . ' cover = ' . $userProfile->cover;
|
|
|
1948 |
//exit;
|
| 6822 |
stevensc |
1949 |
|
| 1 |
www |
1950 |
list($target_width, $target_height) = explode('x', $this->config['leaderslinked.image_sizes.user_cover_size']);
|
|
|
1951 |
$target_filename = 'user-cover-' . uniqid() . '.png';
|
|
|
1952 |
$source = $files['cover']['tmp_name'];
|
|
|
1953 |
$crop_to_dimensions = false;
|
| 6822 |
stevensc |
1954 |
|
|
|
1955 |
if (!Image::uploadImage($source, $target_path, $target_filename, $target_width, $target_height, $crop_to_dimensions)) {
|
| 1 |
www |
1956 |
return new JsonModel([
|
|
|
1957 |
'success' => false,
|
|
|
1958 |
'data' => 'ERROR_THERE_WAS_AN_ERROR'
|
|
|
1959 |
]);
|
|
|
1960 |
}
|
| 6822 |
stevensc |
1961 |
|
| 1 |
www |
1962 |
$userProfile->cover = $target_filename;
|
| 6822 |
stevensc |
1963 |
|
|
|
1964 |
|
|
|
1965 |
if (!$userProfileMapper->updateCover($userProfile)) {
|
| 1 |
www |
1966 |
return new JsonModel([
|
|
|
1967 |
'success' => false,
|
|
|
1968 |
'data' => 'ERROR_THERE_WAS_AN_ERROR'
|
|
|
1969 |
]);
|
|
|
1970 |
}
|
|
|
1971 |
|
| 6822 |
stevensc |
1972 |
|
| 1 |
www |
1973 |
$this->logger->info('Se actualizo el cover del perfil ' . ($userProfile->public == UserProfile::PUBLIC_YES ? 'público' : $userProfile->name), ['user_id' => $userProfile->user_id, 'ip' => Functions::getUserIP()]);
|
|
|
1974 |
} else {
|
|
|
1975 |
$messages = [];
|
|
|
1976 |
$form_messages = (array) $form->getMessages();
|
| 6822 |
stevensc |
1977 |
foreach ($form_messages as $fieldname => $field_messages) {
|
| 1 |
www |
1978 |
$messages[$fieldname] = array_values($field_messages);
|
|
|
1979 |
}
|
| 6822 |
stevensc |
1980 |
|
| 1 |
www |
1981 |
return new JsonModel([
|
|
|
1982 |
'success' => false,
|
|
|
1983 |
'data' => $messages
|
|
|
1984 |
]);
|
|
|
1985 |
}
|
|
|
1986 |
}
|
|
|
1987 |
return new JsonModel([
|
|
|
1988 |
'success' => true,
|
|
|
1989 |
'data' => $this->url()->fromRoute('storage', ['type' => 'user-cover', 'code' => $currentUser->uuid, 'filename' => $userProfile->cover])
|
| 6822 |
stevensc |
1990 |
|
| 1 |
www |
1991 |
]);
|
|
|
1992 |
}
|
| 6822 |
stevensc |
1993 |
|
|
|
1994 |
|
| 1 |
www |
1995 |
$data = [
|
|
|
1996 |
'success' => false,
|
|
|
1997 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
1998 |
];
|
| 6822 |
stevensc |
1999 |
|
|
|
2000 |
|
| 1 |
www |
2001 |
return new JsonModel($data);
|
|
|
2002 |
}
|
| 6822 |
stevensc |
2003 |
|
| 3912 |
efrain |
2004 |
/**
|
|
|
2005 |
* Actualización de las habilidades
|
|
|
2006 |
* @return \Laminas\View\Model\JsonModel
|
|
|
2007 |
*/
|
|
|
2008 |
public function aptitudeAction()
|
|
|
2009 |
{
|
|
|
2010 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
2011 |
$currentUser = $currentUserPlugin->getUser();
|
| 6822 |
stevensc |
2012 |
|
| 3912 |
efrain |
2013 |
$user_profile_id = $this->params()->fromRoute('id');
|
|
|
2014 |
$userProfileMapper = UserProfileMapper::getInstance($this->adapter);
|
| 6822 |
stevensc |
2015 |
|
| 3912 |
efrain |
2016 |
$userProfile = $userProfileMapper->fetchOneByUuid($user_profile_id);
|
| 6822 |
stevensc |
2017 |
if (!$userProfile) {
|
| 3912 |
efrain |
2018 |
$response = [
|
|
|
2019 |
'success' => false,
|
|
|
2020 |
'data' => 'ERROR_INVALID_PARAMETER'
|
|
|
2021 |
];
|
| 6822 |
stevensc |
2022 |
|
| 3912 |
efrain |
2023 |
return new JsonModel($response);
|
|
|
2024 |
}
|
| 6822 |
stevensc |
2025 |
|
|
|
2026 |
if ($currentUser->id != $userProfile->user_id) {
|
| 3912 |
efrain |
2027 |
$response = [
|
|
|
2028 |
'success' => false,
|
|
|
2029 |
'data' => 'ERROR_UNAUTHORIZED'
|
|
|
2030 |
];
|
| 6822 |
stevensc |
2031 |
|
| 3912 |
efrain |
2032 |
return new JsonModel($response);
|
|
|
2033 |
}
|
| 6822 |
stevensc |
2034 |
|
|
|
2035 |
|
|
|
2036 |
|
| 3912 |
efrain |
2037 |
$request = $this->getRequest();
|
| 6822 |
stevensc |
2038 |
if ($request->isGet()) {
|
| 3912 |
efrain |
2039 |
$aptitudeMapper = AptitudeMapper::getInstance($this->adapter);
|
| 6822 |
stevensc |
2040 |
|
|
|
2041 |
|
| 3912 |
efrain |
2042 |
$userAptitudeMapper = UserAptitudeMapper::getInstance($this->adapter);
|
|
|
2043 |
$userAptitudes = $userAptitudeMapper->fetchAllByUserProfileId($userProfile->id);
|
| 6822 |
stevensc |
2044 |
|
| 3912 |
efrain |
2045 |
$items = [];
|
| 6822 |
stevensc |
2046 |
foreach ($userAptitudes as $userAptitude) {
|
| 3912 |
efrain |
2047 |
$aptitude = $aptitudeMapper->fetchOne($userAptitude->aptitude_id);
|
|
|
2048 |
array_push($items, $aptitude->uuid);
|
|
|
2049 |
}
|
| 6822 |
stevensc |
2050 |
|
| 3912 |
efrain |
2051 |
$data = [
|
|
|
2052 |
'success' => true,
|
|
|
2053 |
'data' => $items
|
|
|
2054 |
];
|
| 6822 |
stevensc |
2055 |
|
| 3912 |
efrain |
2056 |
return new JsonModel($data);
|
| 6822 |
stevensc |
2057 |
} else if ($request->isPost()) {
|
|
|
2058 |
|
| 3912 |
efrain |
2059 |
$form = new AptitudeForm($this->adapter);
|
|
|
2060 |
$dataPost = $request->getPost()->toArray();
|
| 6822 |
stevensc |
2061 |
|
| 3912 |
efrain |
2062 |
$form->setData($dataPost);
|
| 6822 |
stevensc |
2063 |
|
|
|
2064 |
if ($form->isValid()) {
|
| 3912 |
efrain |
2065 |
$this->logger->info('Se actualizaron las habilidades del perfil ' . ($userProfile->public == UserProfile::PUBLIC_YES ? 'público' : $userProfile->name), ['user_id' => $userProfile->user_id, 'ip' => Functions::getUserIP()]);
|
| 6822 |
stevensc |
2066 |
|
| 3912 |
efrain |
2067 |
$aptitudeMapper = AptitudeMapper::getInstance($this->adapter);
|
| 6822 |
stevensc |
2068 |
|
|
|
2069 |
|
| 3912 |
efrain |
2070 |
$userAptitudeMapper = UserAptitudeMapper::getInstance($this->adapter);
|
|
|
2071 |
$userAptitudeMapper->deleteByUserProfileId($userProfile->id);
|
| 6822 |
stevensc |
2072 |
|
| 3912 |
efrain |
2073 |
$dataPost = (array) $form->getData();
|
|
|
2074 |
$aptitudes = $dataPost['aptitudes'];
|
| 6822 |
stevensc |
2075 |
foreach ($aptitudes as $aptitude_uuid) {
|
|
|
2076 |
|
| 3912 |
efrain |
2077 |
$aptitude = $aptitudeMapper->fetchOneByUuid($aptitude_uuid);
|
| 6822 |
stevensc |
2078 |
|
|
|
2079 |
|
| 3912 |
efrain |
2080 |
$userAptitude = new UserAptitude();
|
|
|
2081 |
$userAptitude->user_id = $userProfile->user_id;
|
|
|
2082 |
$userAptitude->user_profile_id = $userProfile->id;
|
|
|
2083 |
$userAptitude->aptitude_id = $aptitude->id;
|
| 6822 |
stevensc |
2084 |
|
| 3912 |
efrain |
2085 |
$userAptitudeMapper->insert($userAptitude);
|
|
|
2086 |
}
|
| 6822 |
stevensc |
2087 |
|
| 3912 |
efrain |
2088 |
$items = [];
|
| 6822 |
stevensc |
2089 |
|
| 3912 |
efrain |
2090 |
$records = $userAptitudeMapper->fetchAllByUserProfileId($userProfile->id);
|
| 6822 |
stevensc |
2091 |
foreach ($records as $record) {
|
| 3912 |
efrain |
2092 |
$aptitude = $aptitudeMapper->fetchOne($record->aptitude_id);
|
|
|
2093 |
array_push($items, ['value' => $aptitude->uuid, 'label' => $aptitude->name]);
|
|
|
2094 |
}
|
| 6822 |
stevensc |
2095 |
|
| 3912 |
efrain |
2096 |
return new JsonModel([
|
|
|
2097 |
'success' => true,
|
|
|
2098 |
'data' => $items
|
|
|
2099 |
]);
|
|
|
2100 |
} else {
|
|
|
2101 |
$messages = [];
|
|
|
2102 |
$form_messages = (array) $form->getMessages();
|
| 6822 |
stevensc |
2103 |
foreach ($form_messages as $fieldname => $field_messages) {
|
| 3912 |
efrain |
2104 |
$messages[$fieldname] = array_values($field_messages);
|
|
|
2105 |
}
|
| 6822 |
stevensc |
2106 |
|
| 3912 |
efrain |
2107 |
return new JsonModel([
|
|
|
2108 |
'success' => false,
|
|
|
2109 |
'data' => $messages
|
|
|
2110 |
]);
|
|
|
2111 |
}
|
| 6822 |
stevensc |
2112 |
|
| 3912 |
efrain |
2113 |
$userAptitudeMapper = UserAptitudeMapper::getInstance($this->adapter);
|
|
|
2114 |
}
|
| 6822 |
stevensc |
2115 |
|
|
|
2116 |
|
| 3912 |
efrain |
2117 |
$data = [
|
|
|
2118 |
'success' => false,
|
|
|
2119 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
2120 |
];
|
| 6822 |
stevensc |
2121 |
|
|
|
2122 |
|
| 3912 |
efrain |
2123 |
return new JsonModel($data);
|
|
|
2124 |
}
|
| 6822 |
stevensc |
2125 |
|
| 3912 |
efrain |
2126 |
/**
|
|
|
2127 |
* Actualización de las habilidades
|
|
|
2128 |
* @return \Laminas\View\Model\JsonModel
|
|
|
2129 |
*/
|
|
|
2130 |
public function hobbyAndInterestAction()
|
|
|
2131 |
{
|
|
|
2132 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
2133 |
$currentUser = $currentUserPlugin->getUser();
|
| 6822 |
stevensc |
2134 |
|
| 3912 |
efrain |
2135 |
$user_profile_id = $this->params()->fromRoute('id');
|
|
|
2136 |
$userProfileMapper = UserProfileMapper::getInstance($this->adapter);
|
| 6822 |
stevensc |
2137 |
|
| 3912 |
efrain |
2138 |
$userProfile = $userProfileMapper->fetchOneByUuid($user_profile_id);
|
| 6822 |
stevensc |
2139 |
if (!$userProfile) {
|
| 3912 |
efrain |
2140 |
$response = [
|
|
|
2141 |
'success' => false,
|
|
|
2142 |
'data' => 'ERROR_INVALID_PARAMETER'
|
|
|
2143 |
];
|
| 6822 |
stevensc |
2144 |
|
| 3912 |
efrain |
2145 |
return new JsonModel($response);
|
|
|
2146 |
}
|
| 6822 |
stevensc |
2147 |
|
|
|
2148 |
if ($currentUser->id != $userProfile->user_id) {
|
| 3912 |
efrain |
2149 |
$response = [
|
|
|
2150 |
'success' => false,
|
|
|
2151 |
'data' => 'ERROR_UNAUTHORIZED'
|
|
|
2152 |
];
|
| 6822 |
stevensc |
2153 |
|
| 3912 |
efrain |
2154 |
return new JsonModel($response);
|
|
|
2155 |
}
|
| 6822 |
stevensc |
2156 |
|
|
|
2157 |
|
|
|
2158 |
|
| 3912 |
efrain |
2159 |
$request = $this->getRequest();
|
| 6822 |
stevensc |
2160 |
if ($request->isGet()) {
|
| 3912 |
efrain |
2161 |
$hobbyAndInterestMapper = HobbyAndInterestMapper::getInstance($this->adapter);
|
| 6822 |
stevensc |
2162 |
|
|
|
2163 |
|
| 3912 |
efrain |
2164 |
$userHobbyAndInterestMapper = UserHobbyAndInterestMapper::getInstance($this->adapter);
|
|
|
2165 |
$userHobbyAndInterests = $userHobbyAndInterestMapper->fetchAllByUserProfileId($userProfile->id);
|
| 6822 |
stevensc |
2166 |
|
| 3912 |
efrain |
2167 |
$items = [];
|
| 6822 |
stevensc |
2168 |
foreach ($userHobbyAndInterests as $userHobbyAndInterest) {
|
| 3912 |
efrain |
2169 |
$hobbyAndInterest = $hobbyAndInterestMapper->fetchOne($userHobbyAndInterest->hobbyAndInterest_id);
|
|
|
2170 |
array_push($items, $hobbyAndInterest->uuid);
|
|
|
2171 |
}
|
| 6822 |
stevensc |
2172 |
|
| 3912 |
efrain |
2173 |
$data = [
|
|
|
2174 |
'success' => true,
|
|
|
2175 |
'data' => $items
|
|
|
2176 |
];
|
| 6822 |
stevensc |
2177 |
|
| 3912 |
efrain |
2178 |
return new JsonModel($data);
|
| 6822 |
stevensc |
2179 |
} else if ($request->isPost()) {
|
|
|
2180 |
|
| 3912 |
efrain |
2181 |
$form = new HobbyAndInterestForm($this->adapter);
|
|
|
2182 |
$dataPost = $request->getPost()->toArray();
|
| 6822 |
stevensc |
2183 |
|
|
|
2184 |
|
| 3912 |
efrain |
2185 |
$form->setData($dataPost);
|
| 6822 |
stevensc |
2186 |
|
|
|
2187 |
if ($form->isValid()) {
|
| 3912 |
efrain |
2188 |
$this->logger->info('Se actualizaron las habilidades del perfil ' . ($userProfile->public == UserProfile::PUBLIC_YES ? 'público' : $userProfile->name), ['user_id' => $userProfile->user_id, 'ip' => Functions::getUserIP()]);
|
| 6822 |
stevensc |
2189 |
|
| 3912 |
efrain |
2190 |
$hobbyAndInterestMapper = HobbyAndInterestMapper::getInstance($this->adapter);
|
| 6822 |
stevensc |
2191 |
|
|
|
2192 |
|
| 3912 |
efrain |
2193 |
$userHobbyAndInterestMapper = UserHobbyAndInterestMapper::getInstance($this->adapter);
|
|
|
2194 |
$userHobbyAndInterestMapper->deleteByUserProfileId($userProfile->id);
|
| 6822 |
stevensc |
2195 |
|
| 3912 |
efrain |
2196 |
$dataPost = (array) $form->getData();
|
|
|
2197 |
$hobbyAndInterests = $dataPost['hobbies_and_interests'];
|
| 6822 |
stevensc |
2198 |
foreach ($hobbyAndInterests as $hobbyAndInterest_uuid) {
|
|
|
2199 |
|
| 3912 |
efrain |
2200 |
$hobbyAndInterest = $hobbyAndInterestMapper->fetchOneByUuid($hobbyAndInterest_uuid);
|
| 6822 |
stevensc |
2201 |
|
|
|
2202 |
|
| 3912 |
efrain |
2203 |
$userHobbyAndInterest = new UserHobbyAndInterest();
|
|
|
2204 |
$userHobbyAndInterest->user_id = $userProfile->user_id;
|
|
|
2205 |
$userHobbyAndInterest->user_profile_id = $userProfile->id;
|
| 3919 |
efrain |
2206 |
$userHobbyAndInterest->hobby_and_interest_id = $hobbyAndInterest->id;
|
| 6822 |
stevensc |
2207 |
|
| 3912 |
efrain |
2208 |
$userHobbyAndInterestMapper->insert($userHobbyAndInterest);
|
|
|
2209 |
}
|
| 6822 |
stevensc |
2210 |
|
| 3912 |
efrain |
2211 |
$items = [];
|
| 6822 |
stevensc |
2212 |
|
| 3912 |
efrain |
2213 |
$records = $userHobbyAndInterestMapper->fetchAllByUserProfileId($userProfile->id);
|
| 6822 |
stevensc |
2214 |
foreach ($records as $record) {
|
| 3920 |
efrain |
2215 |
$hobbyAndInterest = $hobbyAndInterestMapper->fetchOne($record->hobby_and_interest_id);
|
| 3912 |
efrain |
2216 |
array_push($items, ['value' => $hobbyAndInterest->uuid, 'label' => $hobbyAndInterest->name]);
|
|
|
2217 |
}
|
| 6822 |
stevensc |
2218 |
|
| 3912 |
efrain |
2219 |
return new JsonModel([
|
|
|
2220 |
'success' => true,
|
|
|
2221 |
'data' => $items
|
|
|
2222 |
]);
|
|
|
2223 |
} else {
|
|
|
2224 |
$messages = [];
|
|
|
2225 |
$form_messages = (array) $form->getMessages();
|
| 6822 |
stevensc |
2226 |
foreach ($form_messages as $fieldname => $field_messages) {
|
| 3912 |
efrain |
2227 |
$messages[$fieldname] = array_values($field_messages);
|
|
|
2228 |
}
|
| 6822 |
stevensc |
2229 |
|
| 3912 |
efrain |
2230 |
return new JsonModel([
|
|
|
2231 |
'success' => false,
|
|
|
2232 |
'data' => $messages
|
|
|
2233 |
]);
|
|
|
2234 |
}
|
| 6822 |
stevensc |
2235 |
|
| 3912 |
efrain |
2236 |
$userHobbyAndInterestMapper = UserHobbyAndInterestMapper::getInstance($this->adapter);
|
|
|
2237 |
}
|
| 6822 |
stevensc |
2238 |
|
|
|
2239 |
|
| 3912 |
efrain |
2240 |
$data = [
|
|
|
2241 |
'success' => false,
|
|
|
2242 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
2243 |
];
|
| 6822 |
stevensc |
2244 |
|
|
|
2245 |
|
| 3912 |
efrain |
2246 |
return new JsonModel($data);
|
|
|
2247 |
}
|
| 1 |
www |
2248 |
}
|