| 1 |
www |
1 |
<?php
|
| 5992 |
stevensc |
2 |
|
| 1 |
www |
3 |
/**
|
|
|
4 |
*
|
|
|
5 |
* Controlador: Mis Perfiles
|
|
|
6 |
*
|
|
|
7 |
*/
|
| 5992 |
stevensc |
8 |
|
| 1 |
www |
9 |
declare(strict_types=1);
|
|
|
10 |
|
|
|
11 |
namespace LeadersLinked\Controller;
|
|
|
12 |
|
|
|
13 |
use Laminas\Db\Adapter\AdapterInterface;
|
|
|
14 |
use Laminas\Cache\Storage\Adapter\AbstractAdapter;
|
|
|
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\Library\Functions;
|
|
|
21 |
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
|
|
|
22 |
use LeadersLinked\Library\Image;
|
|
|
23 |
|
|
|
24 |
use LeadersLinked\Mapper\CompanyLocationMapper;
|
|
|
25 |
use LeadersLinked\Form\CompanyProfileSocialNetworkForm;
|
|
|
26 |
use LeadersLinked\Form\CompanyProfileLocationForm;
|
|
|
27 |
use LeadersLinked\Form\CompanyProfileExtendedForm;
|
|
|
28 |
use LeadersLinked\Form\CompanyProfileImageForm;
|
|
|
29 |
use LeadersLinked\Form\CompanyProfileCoverForm;
|
| 768 |
geraldo |
30 |
use LeadersLinked\Form\CompanyProfileHeaderForm;
|
|
|
31 |
use LeadersLinked\Form\CompanyProfileFooterForm;
|
| 1 |
www |
32 |
|
|
|
33 |
use LeadersLinked\Form\CompanyProfileIndustryForm;
|
|
|
34 |
use LeadersLinked\Form\CompanyProfileCompanySizeForm;
|
|
|
35 |
use LeadersLinked\Form\CompanyProfileFoundationYearForm;
|
|
|
36 |
use LeadersLinked\Form\CompanyProfileWebsiteForm;
|
|
|
37 |
use LeadersLinked\Model\Location;
|
|
|
38 |
use LeadersLinked\Model\CompanyLocation;
|
|
|
39 |
use LeadersLinked\Model\CompanyUser;
|
|
|
40 |
|
|
|
41 |
use LeadersLinked\Mapper\LocationMapper;
|
|
|
42 |
use LeadersLinked\Mapper\CompanyFollowerMapper;
|
|
|
43 |
use LeadersLinked\Mapper\CompanyUserMapper;
|
|
|
44 |
use LeadersLinked\Mapper\CompanyMapper;
|
|
|
45 |
use LeadersLinked\Mapper\IndustryMapper;
|
|
|
46 |
use LeadersLinked\Mapper\CompanySizeMapper;
|
|
|
47 |
|
|
|
48 |
class ProfileController extends AbstractActionController
|
|
|
49 |
{
|
|
|
50 |
/**
|
|
|
51 |
*
|
|
|
52 |
* @var AdapterInterface
|
|
|
53 |
*/
|
|
|
54 |
private $adapter;
|
| 5992 |
stevensc |
55 |
|
|
|
56 |
|
| 1 |
www |
57 |
/**
|
|
|
58 |
*
|
|
|
59 |
* @var AbstractAdapter
|
|
|
60 |
*/
|
|
|
61 |
private $cache;
|
| 5992 |
stevensc |
62 |
|
| 1 |
www |
63 |
/**
|
|
|
64 |
*
|
|
|
65 |
* @var LoggerInterface
|
|
|
66 |
*/
|
|
|
67 |
private $logger;
|
|
|
68 |
|
| 5992 |
stevensc |
69 |
|
| 1 |
www |
70 |
/**
|
|
|
71 |
*
|
|
|
72 |
* @var array
|
|
|
73 |
*/
|
|
|
74 |
private $config;
|
| 5992 |
stevensc |
75 |
|
| 1 |
www |
76 |
/**
|
|
|
77 |
*
|
|
|
78 |
* @param AdapterInterface $adapter
|
|
|
79 |
* @param AbstractAdapter $cache
|
|
|
80 |
* @param LoggerInterface $logger
|
|
|
81 |
* @param array $config
|
|
|
82 |
*/
|
| 5992 |
stevensc |
83 |
public function __construct($adapter, $cache, $logger, $config)
|
| 1 |
www |
84 |
{
|
|
|
85 |
$this->adapter = $adapter;
|
|
|
86 |
$this->cache = $cache;
|
|
|
87 |
$this->logger = $logger;
|
|
|
88 |
$this->config = $config;
|
|
|
89 |
}
|
|
|
90 |
|
| 5992 |
stevensc |
91 |
|
|
|
92 |
|
| 1 |
www |
93 |
/**
|
|
|
94 |
* Presenta el perfil con las opciónes de edición de cada sección
|
|
|
95 |
* @return \Laminas\Http\Response|\Laminas\View\Model\ViewModel|\Laminas\View\Model\JsonModel
|
|
|
96 |
*/
|
|
|
97 |
public function indexAction()
|
|
|
98 |
{
|
|
|
99 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
100 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
101 |
$currentCompany = $currentUserPlugin->getCompany();
|
|
|
102 |
|
| 5992 |
stevensc |
103 |
|
| 1 |
www |
104 |
$request = $this->getRequest();
|
| 5992 |
stevensc |
105 |
if ($request->isGet()) {
|
|
|
106 |
|
| 1 |
www |
107 |
$sandbox = $this->config['leaderslinked.runmode.sandbox'];
|
| 5992 |
stevensc |
108 |
if ($sandbox) {
|
| 1 |
www |
109 |
$google_map_key = $this->config['leaderslinked.google_map.sandbox_api_key'];
|
|
|
110 |
} else {
|
|
|
111 |
$google_map_key = $this->config['leaderslinked.google_map.production_api_key'];
|
|
|
112 |
}
|
| 5992 |
stevensc |
113 |
|
| 1 |
www |
114 |
$companyMapper = CompanyMapper::getInstance($this->adapter);
|
|
|
115 |
$company = $companyMapper->fetchOne($currentCompany->id);
|
|
|
116 |
|
| 5992 |
stevensc |
117 |
|
| 1 |
www |
118 |
$companyLocationMapper = CompanyLocationMapper::getInstance($this->adapter);
|
|
|
119 |
$records = $companyLocationMapper->fetchAllLocationByCompanyId($company->id);
|
|
|
120 |
|
|
|
121 |
|
|
|
122 |
|
| 5992 |
stevensc |
123 |
|
| 1 |
www |
124 |
$locations = [];
|
| 5992 |
stevensc |
125 |
foreach ($records as $record) {
|
| 1 |
www |
126 |
$location = [
|
|
|
127 |
'formatted_address' => $record['formatted_address'],
|
|
|
128 |
'country' => $record['country'],
|
|
|
129 |
'is_main' => $record['is_main'],
|
| 5992 |
stevensc |
130 |
'link_edit' => $this->url()->fromRoute('profile/location', ['operation' => 'edit', 'id' => $record['company_location_uuid']]),
|
|
|
131 |
'link_delete' => $this->url()->fromRoute('profile/location', ['operation' => 'delete', 'id' => $record['company_location_uuid']])
|
|
|
132 |
|
| 1 |
www |
133 |
];
|
| 5992 |
stevensc |
134 |
|
| 1 |
www |
135 |
array_push($locations, $location);
|
|
|
136 |
}
|
| 5992 |
stevensc |
137 |
|
| 1 |
www |
138 |
$industryMapper = IndustryMapper::getInstance($this->adapter);
|
|
|
139 |
$companySizeMapper = CompanySizeMapper::getInstance($this->adapter);
|
|
|
140 |
|
|
|
141 |
$formSocialNetwork = new CompanyProfileSocialNetworkForm();
|
|
|
142 |
$formLocation = new CompanyProfileLocationForm();
|
|
|
143 |
$formExtended = new CompanyProfileExtendedForm();
|
|
|
144 |
$formFoundationYear = new CompanyProfileFoundationYearForm();
|
|
|
145 |
$formWebsite = new CompanyProfileWebsiteForm();
|
|
|
146 |
$formImage = new CompanyProfileImageForm($this->config);
|
|
|
147 |
$formCover = new CompanyProfileCoverForm($this->config);
|
| 768 |
geraldo |
148 |
$formHeader = new CompanyProfileHeaderForm($this->config);
|
|
|
149 |
$formFooter = new CompanyProfileFooterForm($this->config);
|
|
|
150 |
|
|
|
151 |
|
|
|
152 |
|
| 1 |
www |
153 |
$formCompanySize = new CompanyProfileCompanySizeForm($this->adapter);
|
|
|
154 |
$formIndustry = new CompanyProfileIndustryForm($this->adapter);
|
| 5992 |
stevensc |
155 |
|
| 1 |
www |
156 |
$companyFollowerMapper = CompanyFollowerMapper::getInstance($this->adapter);
|
|
|
157 |
$follower = $companyFollowerMapper->getCountFollowers($currentCompany->id);
|
|
|
158 |
|
|
|
159 |
$image_size_cover = $this->config['leaderslinked.image_sizes.company_cover_upload'];
|
|
|
160 |
$image_size_profile = $this->config['leaderslinked.image_sizes.company_image_upload'];
|
| 1101 |
geraldo |
161 |
$image_size_header = $this->config['leaderslinked.image_sizes.company_header_pdf_upload'];
|
| 5992 |
stevensc |
162 |
$image_size_footer = $this->config['leaderslinked.image_sizes.company_footer_pdf_upload'];
|
|
|
163 |
|
|
|
164 |
|
| 1 |
www |
165 |
$industry = $industryMapper->fetchOne($company->industry_id);
|
|
|
166 |
$companySize = $companySizeMapper->fetchOne($company->company_size_id);
|
| 5992 |
stevensc |
167 |
|
|
|
168 |
|
| 1 |
www |
169 |
$this->layout()->setTemplate('layout/layout-backend');
|
|
|
170 |
$viewModel = new ViewModel();
|
|
|
171 |
$viewModel->setTemplate('leaders-linked/profile/index.phtml');
|
|
|
172 |
$viewModel->setVariables([
|
|
|
173 |
'google_map_key' => $google_map_key,
|
|
|
174 |
'follower' => $follower,
|
|
|
175 |
'company_id' => $currentCompany->id,
|
|
|
176 |
'company_name' => $company->name,
|
|
|
177 |
'company_uuid' => $company->uuid,
|
|
|
178 |
'name' => trim($company->name),
|
|
|
179 |
'image' => $company->image,
|
|
|
180 |
'cover' => $company->cover,
|
| 782 |
geraldo |
181 |
'header' => $company->header,
|
|
|
182 |
'footer' => $company->footer,
|
| 5992 |
stevensc |
183 |
'overview' => strip_tags($company->description, 'p'),
|
| 1 |
www |
184 |
'website' => $company->website,
|
|
|
185 |
'foundation_year' => $company->foundation_year,
|
|
|
186 |
'facebook' => $company->facebook,
|
|
|
187 |
'instagram' => $company->instagram,
|
|
|
188 |
'twitter' => $company->twitter,
|
|
|
189 |
'locations' => $locations,
|
|
|
190 |
'industry' => $industry->name,
|
| 5992 |
stevensc |
191 |
'company_size' => $companySize->name . ' (' . $companySize->minimum_no_of_employee . '-' . $companySize->maximum_no_of_employee . ')',
|
| 1 |
www |
192 |
'formLocation' => $formLocation,
|
|
|
193 |
'formSocialNetwork' => $formSocialNetwork,
|
|
|
194 |
'formExtended' => $formExtended,
|
|
|
195 |
'formImage' => $formImage,
|
|
|
196 |
'formCover' => $formCover,
|
| 768 |
geraldo |
197 |
'formHeader' => $formHeader,
|
|
|
198 |
'formFooter' => $formFooter,
|
| 1 |
www |
199 |
'formFoundationYear' => $formFoundationYear,
|
|
|
200 |
'formWebsite' => $formWebsite,
|
|
|
201 |
'formIndustry' => $formIndustry,
|
|
|
202 |
'formCompanySize' => $formCompanySize,
|
|
|
203 |
'image_size_cover' => $image_size_cover,
|
|
|
204 |
'image_size_profile' => $image_size_profile,
|
| 781 |
geraldo |
205 |
'image_size_header' => $image_size_header,
|
|
|
206 |
'image_size_footer' => $image_size_footer,
|
| 1 |
www |
207 |
]);
|
| 5992 |
stevensc |
208 |
return $viewModel;
|
| 1 |
www |
209 |
} else {
|
|
|
210 |
$data = [
|
|
|
211 |
'success' => false,
|
|
|
212 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
213 |
];
|
| 5992 |
stevensc |
214 |
|
| 1 |
www |
215 |
return new JsonModel($data);
|
|
|
216 |
}
|
| 5992 |
stevensc |
217 |
|
| 1 |
www |
218 |
return new JsonModel($data);
|
|
|
219 |
}
|
| 5992 |
stevensc |
220 |
|
|
|
221 |
|
| 1 |
www |
222 |
/**
|
|
|
223 |
*
|
|
|
224 |
* Borrar un perfil excepto el público
|
|
|
225 |
* @return \Laminas\View\Model\JsonModel
|
|
|
226 |
*/
|
|
|
227 |
public function deleteAction()
|
|
|
228 |
{
|
|
|
229 |
|
|
|
230 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
231 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
232 |
$currentCompany = $currentUserPlugin->getCompany();
|
| 5992 |
stevensc |
233 |
|
| 1 |
www |
234 |
$companyUserMapper = CompanyUserMapper::getInstance($this->adapter);
|
|
|
235 |
$companyUser = $companyUserMapper->fetchOneByCompanyIdAndUserId($currentCompany->id, $currentUser->id);
|
| 5992 |
stevensc |
236 |
|
|
|
237 |
if (!$companyUser || $companyUser->type != CompanyUser::CREATOR_YES) {
|
| 1 |
www |
238 |
$response = [
|
|
|
239 |
'success' => false,
|
|
|
240 |
'data' => 'ERROR_UNAUTHORIZED'
|
|
|
241 |
];
|
| 5992 |
stevensc |
242 |
|
| 1 |
www |
243 |
return new JsonModel($response);
|
|
|
244 |
}
|
| 5992 |
stevensc |
245 |
|
|
|
246 |
|
|
|
247 |
if ($request->isPost()) {
|
| 1 |
www |
248 |
$companyMapper = CompanyMapper::getInstance($this->adapter);
|
|
|
249 |
$result = $companyMapper->delete($companyUser->id);
|
| 5992 |
stevensc |
250 |
if ($result) {
|
| 1 |
www |
251 |
$this->logger->info('Se borro la empresa : ' . $currentCompany->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
|
| 5992 |
stevensc |
252 |
|
| 1 |
www |
253 |
$data = [
|
|
|
254 |
'success' => true,
|
|
|
255 |
'data' => 'LABEL_RECORD_DELETED'
|
|
|
256 |
];
|
|
|
257 |
} else {
|
| 5992 |
stevensc |
258 |
|
| 1 |
www |
259 |
$data = [
|
|
|
260 |
'success' => false,
|
|
|
261 |
'data' => $companyUserMapper->getError()
|
|
|
262 |
];
|
| 5992 |
stevensc |
263 |
|
| 1 |
www |
264 |
return new JsonModel($data);
|
|
|
265 |
}
|
|
|
266 |
} else {
|
|
|
267 |
$data = [
|
|
|
268 |
'success' => false,
|
|
|
269 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
270 |
];
|
| 5992 |
stevensc |
271 |
|
| 1 |
www |
272 |
return new JsonModel($data);
|
|
|
273 |
}
|
| 5992 |
stevensc |
274 |
|
| 1 |
www |
275 |
return new JsonModel($data);
|
|
|
276 |
}
|
| 5992 |
stevensc |
277 |
|
|
|
278 |
|
|
|
279 |
|
| 1 |
www |
280 |
/**
|
|
|
281 |
* Actualización de la descripción y cualquier otro campo extendido del perfil a futuro
|
|
|
282 |
* @return \Laminas\View\Model\JsonModel
|
|
|
283 |
*/
|
|
|
284 |
public function extendedAction()
|
|
|
285 |
{
|
|
|
286 |
|
| 5992 |
stevensc |
287 |
|
| 1 |
www |
288 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
289 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
290 |
$currentCompany = $currentUserPlugin->getCompany();
|
|
|
291 |
|
|
|
292 |
|
| 5992 |
stevensc |
293 |
|
|
|
294 |
|
|
|
295 |
|
| 1 |
www |
296 |
$request = $this->getRequest();
|
| 5992 |
stevensc |
297 |
if ($request->isGet()) {
|
| 1 |
www |
298 |
$companyMapper = CompanyMapper::getInstance($this->adapter);
|
|
|
299 |
$company = $companyMapper->fetchOne($currentCompany->id);
|
| 5992 |
stevensc |
300 |
|
| 1 |
www |
301 |
$data = [
|
|
|
302 |
'success' => true,
|
|
|
303 |
'data' => [
|
|
|
304 |
'description' => $company->description,
|
|
|
305 |
]
|
|
|
306 |
];
|
| 5992 |
stevensc |
307 |
|
| 1 |
www |
308 |
return new JsonModel($data);
|
| 5992 |
stevensc |
309 |
} else if ($request->isPost()) {
|
| 1 |
www |
310 |
$form = new CompanyProfileExtendedForm();
|
|
|
311 |
$dataPost = $request->getPost()->toArray();
|
| 5992 |
stevensc |
312 |
|
| 1 |
www |
313 |
$form->setData($dataPost);
|
| 5992 |
stevensc |
314 |
|
|
|
315 |
if ($form->isValid()) {
|
| 1 |
www |
316 |
$companyMapper = CompanyMapper::getInstance($this->adapter);
|
|
|
317 |
$company = $companyMapper->fetchOne($currentCompany->id);
|
| 5992 |
stevensc |
318 |
|
| 1 |
www |
319 |
$dataPost = (array) $form->getData();
|
| 5992 |
stevensc |
320 |
|
| 1 |
www |
321 |
$hydrator = new ObjectPropertyHydrator();
|
|
|
322 |
$hydrator->hydrate($dataPost, $company);
|
| 5992 |
stevensc |
323 |
|
| 1 |
www |
324 |
$companyMapper->updateExtended($company);
|
| 5992 |
stevensc |
325 |
|
| 1 |
www |
326 |
$this->logger->info('Se actualizo las descripción de la empresa ' . $company->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
|
| 5992 |
stevensc |
327 |
|
| 1 |
www |
328 |
return new JsonModel([
|
|
|
329 |
'success' => true,
|
|
|
330 |
'data' => [
|
|
|
331 |
'description' => $company->description,
|
|
|
332 |
]
|
|
|
333 |
]);
|
|
|
334 |
} else {
|
|
|
335 |
$messages = [];
|
|
|
336 |
$form_messages = (array) $form->getMessages();
|
| 5992 |
stevensc |
337 |
foreach ($form_messages as $fieldname => $field_messages) {
|
| 1 |
www |
338 |
$messages[$fieldname] = array_values($field_messages);
|
|
|
339 |
}
|
| 5992 |
stevensc |
340 |
|
| 1 |
www |
341 |
return new JsonModel([
|
|
|
342 |
'success' => false,
|
|
|
343 |
'data' => $messages
|
|
|
344 |
]);
|
|
|
345 |
}
|
|
|
346 |
}
|
| 5992 |
stevensc |
347 |
|
|
|
348 |
|
| 1 |
www |
349 |
$data = [
|
|
|
350 |
'success' => false,
|
|
|
351 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
352 |
];
|
| 5992 |
stevensc |
353 |
|
|
|
354 |
|
| 1 |
www |
355 |
return new JsonModel($data);
|
|
|
356 |
}
|
| 5992 |
stevensc |
357 |
|
| 1 |
www |
358 |
/**
|
|
|
359 |
* Actualización de la descripción y cualquier otro campo extendido del perfil a futuro
|
|
|
360 |
* @return \Laminas\View\Model\JsonModel
|
|
|
361 |
*/
|
|
|
362 |
public function websiteAction()
|
|
|
363 |
{
|
|
|
364 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
365 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
366 |
$currentCompany = $currentUserPlugin->getCompany();
|
|
|
367 |
|
|
|
368 |
$request = $this->getRequest();
|
| 5992 |
stevensc |
369 |
if ($request->isGet()) {
|
| 1 |
www |
370 |
$companyMapper = CompanyMapper::getInstance($this->adapter);
|
|
|
371 |
$company = $companyMapper->fetchOne($currentCompany->id);
|
| 5992 |
stevensc |
372 |
|
| 1 |
www |
373 |
$data = [
|
|
|
374 |
'success' => true,
|
|
|
375 |
'data' => [
|
|
|
376 |
'website' => $company->website,
|
|
|
377 |
]
|
|
|
378 |
];
|
| 5992 |
stevensc |
379 |
|
| 1 |
www |
380 |
return new JsonModel($data);
|
| 5992 |
stevensc |
381 |
} else if ($request->isPost()) {
|
|
|
382 |
|
|
|
383 |
|
| 1 |
www |
384 |
$form = new CompanyProfileWebsiteForm();
|
|
|
385 |
$dataPost = $request->getPost()->toArray();
|
| 5992 |
stevensc |
386 |
|
| 1 |
www |
387 |
$form->setData($dataPost);
|
| 5992 |
stevensc |
388 |
|
|
|
389 |
if ($form->isValid()) {
|
| 1 |
www |
390 |
$companyMapper = CompanyMapper::getInstance($this->adapter);
|
|
|
391 |
$company = $companyMapper->fetchOne($currentCompany->id);
|
| 5992 |
stevensc |
392 |
|
| 1 |
www |
393 |
$dataPost = (array) $form->getData();
|
| 5992 |
stevensc |
394 |
|
| 1 |
www |
395 |
$hydrator = new ObjectPropertyHydrator();
|
|
|
396 |
$hydrator->hydrate($dataPost, $company);
|
| 5992 |
stevensc |
397 |
|
| 1 |
www |
398 |
$companyMapper->updateWebsite($company);
|
| 5992 |
stevensc |
399 |
|
| 1 |
www |
400 |
$this->logger->info('Se actualizo el website de la empresa ' . $company->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
|
| 5992 |
stevensc |
401 |
|
| 1 |
www |
402 |
return new JsonModel([
|
|
|
403 |
'success' => true,
|
|
|
404 |
'data' => [
|
|
|
405 |
'website' => $company->website,
|
|
|
406 |
]
|
|
|
407 |
]);
|
|
|
408 |
} else {
|
|
|
409 |
$messages = [];
|
|
|
410 |
$form_messages = (array) $form->getMessages();
|
| 5992 |
stevensc |
411 |
foreach ($form_messages as $fieldname => $field_messages) {
|
| 1 |
www |
412 |
$messages[$fieldname] = array_values($field_messages);
|
|
|
413 |
}
|
| 5992 |
stevensc |
414 |
|
| 1 |
www |
415 |
return new JsonModel([
|
|
|
416 |
'success' => false,
|
|
|
417 |
'data' => $messages
|
|
|
418 |
]);
|
|
|
419 |
}
|
|
|
420 |
}
|
| 5992 |
stevensc |
421 |
|
|
|
422 |
|
| 1 |
www |
423 |
$data = [
|
|
|
424 |
'success' => false,
|
|
|
425 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
426 |
];
|
| 5992 |
stevensc |
427 |
|
|
|
428 |
|
| 1 |
www |
429 |
return new JsonModel($data);
|
|
|
430 |
}
|
| 5992 |
stevensc |
431 |
|
| 1 |
www |
432 |
/**
|
|
|
433 |
* Actualización de la descripción y cualquier otro campo extendido del perfil a futuro
|
|
|
434 |
* @return \Laminas\View\Model\JsonModel
|
|
|
435 |
*/
|
|
|
436 |
public function foundationYearAction()
|
|
|
437 |
{
|
| 5992 |
stevensc |
438 |
|
| 1 |
www |
439 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
440 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
441 |
$currentCompany = $currentUserPlugin->getCompany();
|
|
|
442 |
|
| 5992 |
stevensc |
443 |
|
|
|
444 |
|
| 1 |
www |
445 |
$request = $this->getRequest();
|
| 5992 |
stevensc |
446 |
if ($request->isGet()) {
|
| 1 |
www |
447 |
$companyMapper = CompanyMapper::getInstance($this->adapter);
|
|
|
448 |
$company = $companyMapper->fetchOne($currentCompany->id);
|
| 5992 |
stevensc |
449 |
|
| 1 |
www |
450 |
$data = [
|
|
|
451 |
'success' => true,
|
|
|
452 |
'data' => [
|
|
|
453 |
'foundation_year' => $company->foundation_year,
|
|
|
454 |
]
|
| 5992 |
stevensc |
455 |
|
| 1 |
www |
456 |
];
|
| 5992 |
stevensc |
457 |
|
| 1 |
www |
458 |
return new JsonModel($data);
|
| 5992 |
stevensc |
459 |
} else if ($request->isPost()) {
|
|
|
460 |
|
|
|
461 |
|
| 1 |
www |
462 |
$form = new CompanyProfileFoundationYearForm();
|
|
|
463 |
$dataPost = $request->getPost()->toArray();
|
| 5992 |
stevensc |
464 |
|
| 1 |
www |
465 |
$form->setData($dataPost);
|
| 5992 |
stevensc |
466 |
|
|
|
467 |
if ($form->isValid()) {
|
| 1 |
www |
468 |
$companyMapper = CompanyMapper::getInstance($this->adapter);
|
|
|
469 |
$company = $companyMapper->fetchOne($currentCompany->id);
|
| 5992 |
stevensc |
470 |
|
| 1 |
www |
471 |
$dataPost = (array) $form->getData();
|
| 5992 |
stevensc |
472 |
|
| 1 |
www |
473 |
$hydrator = new ObjectPropertyHydrator();
|
|
|
474 |
$hydrator->hydrate($dataPost, $company);
|
| 5992 |
stevensc |
475 |
|
| 1 |
www |
476 |
$companyMapper->updateFoundationYear($company);
|
| 5992 |
stevensc |
477 |
|
| 1 |
www |
478 |
$this->logger->info('Se actualizo el año de fundación de la empresa ' . $company->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
|
| 5992 |
stevensc |
479 |
|
| 1 |
www |
480 |
return new JsonModel([
|
|
|
481 |
'success' => true,
|
|
|
482 |
'data' => $company->foundation_year,
|
|
|
483 |
]);
|
|
|
484 |
} else {
|
|
|
485 |
$messages = [];
|
|
|
486 |
$form_messages = (array) $form->getMessages();
|
| 5992 |
stevensc |
487 |
foreach ($form_messages as $fieldname => $field_messages) {
|
| 1 |
www |
488 |
$messages[$fieldname] = array_values($field_messages);
|
|
|
489 |
}
|
| 5992 |
stevensc |
490 |
|
| 1 |
www |
491 |
return new JsonModel([
|
|
|
492 |
'success' => false,
|
|
|
493 |
'data' => $messages
|
|
|
494 |
]);
|
|
|
495 |
}
|
|
|
496 |
}
|
| 5992 |
stevensc |
497 |
|
|
|
498 |
|
| 1 |
www |
499 |
$data = [
|
|
|
500 |
'success' => false,
|
|
|
501 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
502 |
];
|
| 5992 |
stevensc |
503 |
|
|
|
504 |
|
| 1 |
www |
505 |
return new JsonModel($data);
|
|
|
506 |
}
|
| 5992 |
stevensc |
507 |
|
|
|
508 |
|
| 1 |
www |
509 |
/**
|
|
|
510 |
* Actualización de la ubucación
|
|
|
511 |
* @return \Laminas\View\Model\JsonModel
|
|
|
512 |
*/
|
|
|
513 |
public function locationAction()
|
|
|
514 |
{
|
|
|
515 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
516 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
517 |
$currentCompany = $currentUserPlugin->getCompany();
|
| 5992 |
stevensc |
518 |
|
| 1 |
www |
519 |
$operation = $this->params()->fromRoute('operation');
|
| 5992 |
stevensc |
520 |
if ($operation == 'edit' || $operation == 'delete') {
|
| 1 |
www |
521 |
$id = $this->params()->fromRoute('id');
|
| 5992 |
stevensc |
522 |
if (!$id) {
|
| 1 |
www |
523 |
$response = [
|
|
|
524 |
'success' => false,
|
|
|
525 |
'data' => 'ERROR_INVALID_PARAMETER'
|
|
|
526 |
];
|
| 5992 |
stevensc |
527 |
|
| 1 |
www |
528 |
return new JsonModel($response);
|
|
|
529 |
}
|
|
|
530 |
} else {
|
|
|
531 |
$id = '';
|
|
|
532 |
}
|
|
|
533 |
|
|
|
534 |
$request = $this->getRequest();
|
| 5992 |
stevensc |
535 |
if ($request->isPost()) {
|
| 1 |
www |
536 |
$companyMapper = CompanyMapper::getInstance($this->adapter);
|
|
|
537 |
$company = $companyMapper->fetchOne($currentCompany->id);
|
| 5992 |
stevensc |
538 |
|
| 1 |
www |
539 |
$companyLocationMapper = CompanyLocationMapper::getInstance($this->adapter);
|
| 5992 |
stevensc |
540 |
|
|
|
541 |
|
| 1 |
www |
542 |
$companyLocation = null;
|
| 5992 |
stevensc |
543 |
if ($id) {
|
| 1 |
www |
544 |
$companyLocation = $companyLocationMapper->fetchOneByUuid($id);
|
| 5992 |
stevensc |
545 |
if (!$companyLocation) {
|
| 1 |
www |
546 |
$response = [
|
|
|
547 |
'success' => false,
|
|
|
548 |
'data' => 'ERROR_RECORD_NOT_FOUND'
|
|
|
549 |
];
|
| 5992 |
stevensc |
550 |
|
| 1 |
www |
551 |
return new JsonModel($response);
|
|
|
552 |
}
|
| 5992 |
stevensc |
553 |
|
|
|
554 |
if ($companyLocation->company_id != $company->id) {
|
| 1 |
www |
555 |
$response = [
|
|
|
556 |
'success' => false,
|
|
|
557 |
'data' => 'ERROR_UNAUTHORIZED'
|
|
|
558 |
];
|
|
|
559 |
return new JsonModel($response);
|
|
|
560 |
}
|
|
|
561 |
}
|
| 5992 |
stevensc |
562 |
|
| 1 |
www |
563 |
$locationMapper = LocationMapper::getInstance($this->adapter);
|
|
|
564 |
$response = [];
|
|
|
565 |
|
|
|
566 |
|
| 5992 |
stevensc |
567 |
|
|
|
568 |
if ($operation == 'delete' && $companyLocation) {
|
|
|
569 |
|
|
|
570 |
if ($companyLocationMapper->delete($companyLocation->id)) {
|
| 1 |
www |
571 |
$this->logger->info('Se borrar una ubicación de la empresa: ' . $company->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
|
|
|
572 |
$locationMapper->delete($companyLocation->location_id);
|
|
|
573 |
} else {
|
|
|
574 |
$response = [
|
|
|
575 |
'success' => false,
|
|
|
576 |
'data' => 'ERROR_THERE_WAS_AN_ERROR'
|
|
|
577 |
];
|
|
|
578 |
}
|
|
|
579 |
} else {
|
|
|
580 |
$form = new CompanyProfileLocationForm();
|
|
|
581 |
$dataPost = $request->getPost()->toArray();
|
| 5992 |
stevensc |
582 |
|
|
|
583 |
|
| 1 |
www |
584 |
$dataPost['is_main'] = isset($dataPost['is_main']) ? $dataPost['is_main'] : CompanyLocation::IS_MAIN_NO;
|
|
|
585 |
|
| 5992 |
stevensc |
586 |
|
| 1 |
www |
587 |
$form->setData($dataPost);
|
| 5992 |
stevensc |
588 |
|
|
|
589 |
if ($form->isValid()) {
|
|
|
590 |
|
|
|
591 |
if ($operation == 'edit') {
|
| 1 |
www |
592 |
$location = $locationMapper->fetchOne($companyLocation->location_id);
|
|
|
593 |
} else {
|
|
|
594 |
$location = new Location();
|
|
|
595 |
}
|
| 5992 |
stevensc |
596 |
|
| 1 |
www |
597 |
$dataPost = (array) $form->getData();
|
|
|
598 |
$hydrator = new ObjectPropertyHydrator();
|
|
|
599 |
$hydrator->hydrate($dataPost, $location);
|
| 5992 |
stevensc |
600 |
|
|
|
601 |
if ($operation == 'edit') {
|
|
|
602 |
|
|
|
603 |
|
| 1 |
www |
604 |
$companyLocation->is_main = $dataPost['is_main'];
|
|
|
605 |
$companyLocationMapper->update($companyLocation);
|
| 5992 |
stevensc |
606 |
|
|
|
607 |
|
| 1 |
www |
608 |
$location = $locationMapper->update($location);
|
| 5992 |
stevensc |
609 |
$this->logger->info('Se actualizo una ubicación de la empresa: ' . $company->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
|
| 1 |
www |
610 |
} else {
|
| 5992 |
stevensc |
611 |
|
| 1 |
www |
612 |
$result = $locationMapper->insert($location);
|
| 5992 |
stevensc |
613 |
|
|
|
614 |
if ($result) {
|
| 1 |
www |
615 |
$companyLocation = new CompanyLocation();
|
|
|
616 |
$companyLocation->company_id = $currentCompany->id;
|
|
|
617 |
$companyLocation->location_id = $location->id;
|
|
|
618 |
$companyLocation->is_main = $dataPost['is_main'];
|
| 5992 |
stevensc |
619 |
|
| 1 |
www |
620 |
$companyLocationMapper->insert($companyLocation);
|
| 5992 |
stevensc |
621 |
$this->logger->info('Se agrego una ubicación a la empresa: ' . $company->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
|
| 1 |
www |
622 |
} else {
|
|
|
623 |
$response = [
|
|
|
624 |
'success' => false,
|
|
|
625 |
'data' => 'ERROR_THERE_WAS_AN_ERROR'
|
|
|
626 |
];
|
|
|
627 |
}
|
|
|
628 |
}
|
|
|
629 |
} else {
|
|
|
630 |
return new JsonModel([
|
|
|
631 |
'success' => false,
|
|
|
632 |
'data' => 'ERROR_PLACED_AUTOCOMPLETE_DOES_NOT_CONTAIN_GEOMETRY'
|
|
|
633 |
]);
|
|
|
634 |
}
|
|
|
635 |
}
|
| 5992 |
stevensc |
636 |
|
|
|
637 |
if (!$response) {
|
| 1 |
www |
638 |
$records = $companyLocationMapper->fetchAllLocationByCompanyId($currentCompany->id);
|
| 5992 |
stevensc |
639 |
|
|
|
640 |
|
| 1 |
www |
641 |
$locations = [];
|
| 5992 |
stevensc |
642 |
foreach ($records as $record) {
|
| 1 |
www |
643 |
$location = [
|
|
|
644 |
'formatted_address' => $record['formatted_address'],
|
|
|
645 |
'country' => $record['country'],
|
|
|
646 |
'is_main' => $record['is_main'],
|
| 5992 |
stevensc |
647 |
'link_edit' => $this->url()->fromRoute('profile/location', ['id' => $record['company_location_uuid'], 'operation' => 'edit']),
|
| 4278 |
efrain |
648 |
'link_delete' => $this->url()->fromRoute('profile/location', ['id' => $record['company_location_uuid'], 'operation' => 'delete'])
|
| 5992 |
stevensc |
649 |
|
| 1 |
www |
650 |
];
|
| 5992 |
stevensc |
651 |
|
| 1 |
www |
652 |
array_push($locations, $location);
|
|
|
653 |
}
|
| 5992 |
stevensc |
654 |
|
| 1 |
www |
655 |
$response = [
|
|
|
656 |
'success' => true,
|
|
|
657 |
'data' => $locations
|
|
|
658 |
];
|
|
|
659 |
}
|
| 5992 |
stevensc |
660 |
|
| 1 |
www |
661 |
return new JsonModel($response);
|
| 5992 |
stevensc |
662 |
} else if ($request->isGet() && $operation == 'edit') {
|
| 1 |
www |
663 |
|
| 5992 |
stevensc |
664 |
|
|
|
665 |
|
| 1 |
www |
666 |
$companyLocationMapper = CompanyLocationMapper::getInstance($this->adapter);
|
|
|
667 |
$companyLocation = $companyLocationMapper->fetchOneByUuid($id);
|
|
|
668 |
|
| 5992 |
stevensc |
669 |
|
|
|
670 |
|
|
|
671 |
if (!$companyLocation) {
|
| 1 |
www |
672 |
$response = [
|
|
|
673 |
'success' => false,
|
|
|
674 |
'data' => 'ERROR_RECORD_NOT_FOUND'
|
|
|
675 |
];
|
| 5992 |
stevensc |
676 |
|
| 1 |
www |
677 |
return new JsonModel($response);
|
|
|
678 |
}
|
| 5992 |
stevensc |
679 |
|
|
|
680 |
if ($companyLocation->company_id != $currentCompany->id) {
|
| 1 |
www |
681 |
$response = [
|
|
|
682 |
'success' => false,
|
|
|
683 |
'data' => 'ERROR_UNAUTHORIZED'
|
|
|
684 |
];
|
|
|
685 |
return new JsonModel($response);
|
|
|
686 |
}
|
| 5992 |
stevensc |
687 |
|
| 1 |
www |
688 |
$locationMapper = LocationMapper::getInstance($this->adapter);
|
|
|
689 |
$location = $locationMapper->fetchOne($companyLocation->location_id);
|
|
|
690 |
|
|
|
691 |
$hydrator = new ObjectPropertyHydrator();
|
|
|
692 |
$data = $hydrator->extract($location);
|
| 5992 |
stevensc |
693 |
|
| 1 |
www |
694 |
$data['is_main'] = $companyLocation->is_main;
|
| 5992 |
stevensc |
695 |
|
| 1 |
www |
696 |
$response = [
|
|
|
697 |
'success' => true,
|
|
|
698 |
'data' => $data
|
|
|
699 |
];
|
| 5992 |
stevensc |
700 |
|
| 1 |
www |
701 |
return new JsonModel($response);
|
|
|
702 |
}
|
| 5992 |
stevensc |
703 |
|
| 1 |
www |
704 |
$response = [
|
|
|
705 |
'success' => false,
|
|
|
706 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
707 |
];
|
| 5992 |
stevensc |
708 |
|
|
|
709 |
|
| 1 |
www |
710 |
return new JsonModel($response);
|
|
|
711 |
}
|
| 5992 |
stevensc |
712 |
|
| 1 |
www |
713 |
/**
|
|
|
714 |
* Actualización de las redes sociales
|
|
|
715 |
* @return \Laminas\View\Model\JsonModel
|
|
|
716 |
*/
|
|
|
717 |
public function socialNetworkAction()
|
|
|
718 |
{
|
| 5992 |
stevensc |
719 |
|
|
|
720 |
|
| 1 |
www |
721 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
722 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
723 |
$currentCompany = $currentUserPlugin->getCompany();
|
|
|
724 |
|
| 5992 |
stevensc |
725 |
|
|
|
726 |
|
| 1 |
www |
727 |
$request = $this->getRequest();
|
| 5992 |
stevensc |
728 |
if ($request->isGet()) {
|
| 1 |
www |
729 |
$companyMapper = CompanyMapper::getInstance($this->adapter);
|
|
|
730 |
$company = $companyMapper->fetchOne($currentCompany->id);
|
| 5992 |
stevensc |
731 |
|
| 1 |
www |
732 |
$data = [
|
|
|
733 |
'success' => true,
|
|
|
734 |
'data' => [
|
|
|
735 |
'facebook' => $company->facebook,
|
|
|
736 |
'instagram' => $company->instagram,
|
|
|
737 |
'twitter' => $company->twitter
|
|
|
738 |
]
|
|
|
739 |
];
|
| 5992 |
stevensc |
740 |
|
| 1 |
www |
741 |
return new JsonModel($data);
|
| 5992 |
stevensc |
742 |
} else if ($request->isPost()) {
|
|
|
743 |
|
| 1 |
www |
744 |
$form = new CompanyProfileSocialNetworkForm();
|
|
|
745 |
$dataPost = $request->getPost()->toArray();
|
| 5992 |
stevensc |
746 |
|
| 1 |
www |
747 |
$form->setData($dataPost);
|
| 5992 |
stevensc |
748 |
|
|
|
749 |
if ($form->isValid()) {
|
| 1 |
www |
750 |
$companyMapper = CompanyMapper::getInstance($this->adapter);
|
|
|
751 |
$company = $companyMapper->fetchOne($currentCompany->id);
|
| 5992 |
stevensc |
752 |
|
|
|
753 |
$this->logger->info('Se actualizaron las redes sociales de la empresa: ' . $company->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
|
|
|
754 |
|
| 1 |
www |
755 |
$dataPost = (array) $form->getData();
|
| 5992 |
stevensc |
756 |
|
| 1 |
www |
757 |
$hydrator = new ObjectPropertyHydrator();
|
|
|
758 |
$hydrator->hydrate($dataPost, $company);
|
| 5992 |
stevensc |
759 |
|
| 1 |
www |
760 |
$companyMapper->updateSocialNetwork($company);
|
|
|
761 |
return new JsonModel([
|
|
|
762 |
'success' => true,
|
|
|
763 |
'data' => [
|
|
|
764 |
'facebook' => $company->facebook,
|
|
|
765 |
'instagram' => $company->instagram,
|
|
|
766 |
'twitter' => $company->twitter
|
|
|
767 |
]
|
|
|
768 |
]);
|
|
|
769 |
} else {
|
|
|
770 |
$messages = [];
|
|
|
771 |
$form_messages = (array) $form->getMessages();
|
| 5992 |
stevensc |
772 |
foreach ($form_messages as $fieldname => $field_messages) {
|
| 1 |
www |
773 |
$messages[$fieldname] = array_values($field_messages);
|
|
|
774 |
}
|
| 5992 |
stevensc |
775 |
|
| 1 |
www |
776 |
return new JsonModel([
|
|
|
777 |
'success' => false,
|
|
|
778 |
'data' => $messages
|
|
|
779 |
]);
|
|
|
780 |
}
|
|
|
781 |
}
|
| 5992 |
stevensc |
782 |
|
|
|
783 |
|
| 1 |
www |
784 |
$data = [
|
|
|
785 |
'success' => false,
|
|
|
786 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
787 |
];
|
| 5992 |
stevensc |
788 |
|
|
|
789 |
|
| 1 |
www |
790 |
return new JsonModel($data);
|
|
|
791 |
}
|
| 5992 |
stevensc |
792 |
|
|
|
793 |
|
|
|
794 |
|
| 1 |
www |
795 |
/**
|
|
|
796 |
* Cambio de la imagen del image del perfil
|
|
|
797 |
* @return \Laminas\View\Model\JsonModel
|
|
|
798 |
*/
|
|
|
799 |
public function imageAction()
|
|
|
800 |
{
|
|
|
801 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
802 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
803 |
$currentCompany = $currentUserPlugin->getCompany();
|
| 5992 |
stevensc |
804 |
|
| 1 |
www |
805 |
$operation = $this->params()->fromRoute('operation');
|
|
|
806 |
|
|
|
807 |
|
| 5992 |
stevensc |
808 |
|
|
|
809 |
|
|
|
810 |
|
| 1 |
www |
811 |
$request = $this->getRequest();
|
| 5992 |
stevensc |
812 |
if ($request->isPost()) {
|
| 1 |
www |
813 |
$companyMapper = CompanyMapper::getInstance($this->adapter);
|
|
|
814 |
$company = $companyMapper->fetchOne($currentCompany->id);
|
| 5992 |
stevensc |
815 |
|
| 1 |
www |
816 |
$target_path = $this->config['leaderslinked.fullpath.company'] . DIRECTORY_SEPARATOR . $company->uuid;
|
| 5992 |
stevensc |
817 |
|
|
|
818 |
if ($operation == 'delete') {
|
|
|
819 |
$this->logger->info('Se borro la imagen de la empresa: ' . $company->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
|
|
|
820 |
|
|
|
821 |
if ($company->image) {
|
|
|
822 |
|
|
|
823 |
if (!Image::delete($target_path, $company->image)) {
|
| 1 |
www |
824 |
return new JsonModel([
|
|
|
825 |
'success' => false,
|
|
|
826 |
'data' => 'ERROR_THERE_WAS_AN_ERROR'
|
|
|
827 |
]);
|
|
|
828 |
}
|
|
|
829 |
}
|
| 5992 |
stevensc |
830 |
|
| 1 |
www |
831 |
$company->image = '';
|
| 5992 |
stevensc |
832 |
if (!$companyMapper->updateImage($company)) {
|
| 1 |
www |
833 |
return new JsonModel([
|
|
|
834 |
'success' => false,
|
|
|
835 |
'data' => 'ERROR_THERE_WAS_AN_ERROR'
|
|
|
836 |
]);
|
|
|
837 |
}
|
|
|
838 |
} else {
|
|
|
839 |
$form = new CompanyProfileImageForm($this->config);
|
| 5992 |
stevensc |
840 |
$data = array_merge($request->getPost()->toArray(), $request->getFiles()->toArray());
|
| 1 |
www |
841 |
|
|
|
842 |
$form->setData($data);
|
| 5992 |
stevensc |
843 |
|
|
|
844 |
if ($form->isValid()) {
|
|
|
845 |
|
| 1 |
www |
846 |
$files = $request->getFiles()->toArray();
|
| 5992 |
stevensc |
847 |
if (!empty($files['image']['error'])) {
|
|
|
848 |
|
| 1 |
www |
849 |
return new JsonModel([
|
|
|
850 |
'success' => false,
|
|
|
851 |
'data' => 'ERROR_UPLOAD_FILE'
|
|
|
852 |
]);
|
|
|
853 |
}
|
| 5992 |
stevensc |
854 |
|
|
|
855 |
|
|
|
856 |
if ($company->image) {
|
|
|
857 |
|
|
|
858 |
if (!Image::delete($target_path, $company->image)) {
|
| 1 |
www |
859 |
return new JsonModel([
|
|
|
860 |
'success' => false,
|
|
|
861 |
'data' => 'ERROR_THERE_WAS_AN_ERROR'
|
|
|
862 |
]);
|
|
|
863 |
}
|
| 5992 |
stevensc |
864 |
}
|
| 1 |
www |
865 |
|
| 5992 |
stevensc |
866 |
list($target_width, $target_height) = explode('x', $this->config['leaderslinked.image_sizes.company_image_size']);
|
| 1 |
www |
867 |
$source = $files['image']['tmp_name'];
|
|
|
868 |
$target_filename = 'company-image-' . uniqid() . '.png';
|
|
|
869 |
$crop_to_dimensions = true;
|
|
|
870 |
|
| 5992 |
stevensc |
871 |
if (!Image::uploadImage($source, $target_path, $target_filename, $target_width, $target_height, $crop_to_dimensions)) {
|
| 1 |
www |
872 |
return new JsonModel([
|
|
|
873 |
'success' => false,
|
|
|
874 |
'data' => 'ERROR_THERE_WAS_AN_ERROR'
|
|
|
875 |
]);
|
|
|
876 |
}
|
| 5992 |
stevensc |
877 |
|
|
|
878 |
|
| 1 |
www |
879 |
$company->image = $target_filename;
|
| 5992 |
stevensc |
880 |
if (!$companyMapper->updateImage($company)) {
|
| 1 |
www |
881 |
return new JsonModel([
|
|
|
882 |
'success' => false,
|
|
|
883 |
'data' => 'ERROR_THERE_WAS_AN_ERROR'
|
|
|
884 |
]);
|
|
|
885 |
}
|
| 5992 |
stevensc |
886 |
|
|
|
887 |
$this->logger->info('Se actualizo la imagen de la empresa: ' . $company->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
|
| 1 |
www |
888 |
} else {
|
|
|
889 |
$messages = [];
|
|
|
890 |
$form_messages = (array) $form->getMessages();
|
| 5992 |
stevensc |
891 |
foreach ($form_messages as $fieldname => $field_messages) {
|
| 1 |
www |
892 |
$messages[$fieldname] = array_values($field_messages);
|
|
|
893 |
}
|
| 5992 |
stevensc |
894 |
|
| 1 |
www |
895 |
return new JsonModel([
|
|
|
896 |
'success' => false,
|
|
|
897 |
'data' => $messages
|
|
|
898 |
]);
|
|
|
899 |
}
|
|
|
900 |
}
|
|
|
901 |
return new JsonModel([
|
|
|
902 |
'success' => true,
|
|
|
903 |
'data' => $this->url()->fromRoute('storage', ['type' => 'company', 'code' => $company->uuid, 'filename' => $company->image])
|
| 5992 |
stevensc |
904 |
|
| 1 |
www |
905 |
]);
|
|
|
906 |
}
|
|
|
907 |
|
| 5992 |
stevensc |
908 |
|
| 1 |
www |
909 |
$data = [
|
|
|
910 |
'success' => false,
|
|
|
911 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
912 |
];
|
| 5992 |
stevensc |
913 |
|
|
|
914 |
|
| 1 |
www |
915 |
return new JsonModel($data);
|
|
|
916 |
}
|
| 5992 |
stevensc |
917 |
|
| 1 |
www |
918 |
/**
|
|
|
919 |
* Cambio de la imagen de fondo superior (cover) del perfil
|
|
|
920 |
* @return \Laminas\View\Model\JsonModel
|
|
|
921 |
*/
|
|
|
922 |
public function coverAction()
|
|
|
923 |
{
|
|
|
924 |
$operation = $this->params()->fromRoute('operation');
|
|
|
925 |
|
| 5992 |
stevensc |
926 |
|
| 1 |
www |
927 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
928 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
929 |
$currentCompany = $currentUserPlugin->getCompany();
|
|
|
930 |
|
| 5992 |
stevensc |
931 |
|
|
|
932 |
|
|
|
933 |
|
| 1 |
www |
934 |
$request = $this->getRequest();
|
| 5992 |
stevensc |
935 |
if ($request->isPost()) {
|
|
|
936 |
|
| 1 |
www |
937 |
$companyMapper = CompanyMapper::getInstance($this->adapter);
|
|
|
938 |
$company = $companyMapper->fetchOne($currentCompany->id);
|
| 5992 |
stevensc |
939 |
|
| 1 |
www |
940 |
$target_path = $this->config['leaderslinked.fullpath.company'] . DIRECTORY_SEPARATOR . $company->uuid;
|
|
|
941 |
|
| 5992 |
stevensc |
942 |
|
|
|
943 |
|
|
|
944 |
if ($operation == 'delete') {
|
|
|
945 |
if ($company->cover) {
|
|
|
946 |
|
|
|
947 |
if (!Image::delete($target_path, $company->cover)) {
|
| 1 |
www |
948 |
return new JsonModel([
|
|
|
949 |
'success' => false,
|
|
|
950 |
'data' => 'ERROR_THERE_WAS_AN_ERROR'
|
|
|
951 |
]);
|
|
|
952 |
}
|
|
|
953 |
}
|
| 5992 |
stevensc |
954 |
|
| 1 |
www |
955 |
$this->logger->info('Se borro el cover de la empresa ' . $company->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
|
|
|
956 |
$company->cover = '';
|
| 5992 |
stevensc |
957 |
if (!$companyMapper->updateCover($company)) {
|
| 1 |
www |
958 |
return new JsonModel([
|
|
|
959 |
'success' => false,
|
|
|
960 |
'data' => 'ERROR_THERE_WAS_AN_ERROR'
|
|
|
961 |
]);
|
|
|
962 |
}
|
|
|
963 |
} else {
|
|
|
964 |
$form = new CompanyProfileCoverForm($this->config);
|
| 5992 |
stevensc |
965 |
$data = array_merge($request->getPost()->toArray(), $request->getFiles()->toArray());
|
|
|
966 |
|
| 1 |
www |
967 |
$form->setData($data);
|
|
|
968 |
|
| 5992 |
stevensc |
969 |
if ($form->isValid()) {
|
|
|
970 |
|
|
|
971 |
|
| 1 |
www |
972 |
$files = $request->getFiles()->toArray();
|
| 5992 |
stevensc |
973 |
if (!empty($files['cover']['error'])) {
|
|
|
974 |
|
| 1 |
www |
975 |
return new JsonModel([
|
|
|
976 |
'success' => false,
|
|
|
977 |
'data' => 'ERROR_UPLOAD_FILE'
|
|
|
978 |
]);
|
|
|
979 |
}
|
| 5992 |
stevensc |
980 |
|
|
|
981 |
if ($company->cover) {
|
|
|
982 |
|
|
|
983 |
if (!Image::delete($target_path, $company->cover)) {
|
| 1 |
www |
984 |
return new JsonModel([
|
|
|
985 |
'success' => false,
|
|
|
986 |
'data' => 'ERROR_THERE_WAS_AN_ERROR'
|
|
|
987 |
]);
|
|
|
988 |
}
|
|
|
989 |
}
|
| 5992 |
stevensc |
990 |
|
|
|
991 |
list($target_width, $target_height) = explode('x', $this->config['leaderslinked.image_sizes.company_cover_size']);
|
| 1 |
www |
992 |
$source = $files['cover']['tmp_name'];
|
|
|
993 |
$target_filename = 'company-cover-' . uniqid() . '.png';
|
|
|
994 |
$crop_to_dimensions = false;
|
| 5992 |
stevensc |
995 |
|
|
|
996 |
if (!Image::uploadImage($source, $target_path, $target_filename, $target_width, $target_height, $crop_to_dimensions)) {
|
| 1 |
www |
997 |
return new JsonModel([
|
|
|
998 |
'success' => false,
|
|
|
999 |
'data' => 'ERROR_THERE_WAS_AN_ERROR'
|
|
|
1000 |
]);
|
|
|
1001 |
}
|
| 5992 |
stevensc |
1002 |
|
|
|
1003 |
|
| 1 |
www |
1004 |
$company->cover = $target_filename;
|
| 5992 |
stevensc |
1005 |
if (!$companyMapper->updateCover($company)) {
|
| 1 |
www |
1006 |
return new JsonModel([
|
|
|
1007 |
'success' => false,
|
|
|
1008 |
'data' => 'ERROR_THERE_WAS_AN_ERROR'
|
|
|
1009 |
]);
|
|
|
1010 |
}
|
|
|
1011 |
|
|
|
1012 |
|
| 5992 |
stevensc |
1013 |
|
|
|
1014 |
|
| 1 |
www |
1015 |
$this->logger->info('Se actualizo el cover de la empresa ' . $company->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
|
|
|
1016 |
} else {
|
|
|
1017 |
$messages = [];
|
|
|
1018 |
$form_messages = (array) $form->getMessages();
|
| 5992 |
stevensc |
1019 |
foreach ($form_messages as $fieldname => $field_messages) {
|
| 1 |
www |
1020 |
$messages[$fieldname] = array_values($field_messages);
|
|
|
1021 |
}
|
| 5992 |
stevensc |
1022 |
|
| 1 |
www |
1023 |
return new JsonModel([
|
|
|
1024 |
'success' => false,
|
|
|
1025 |
'data' => $messages
|
|
|
1026 |
]);
|
|
|
1027 |
}
|
|
|
1028 |
}
|
|
|
1029 |
return new JsonModel([
|
|
|
1030 |
'success' => true,
|
|
|
1031 |
'data' => $this->url()->fromRoute('storage', ['type' => 'company-cover', 'code' => $company->uuid, 'filename' => $company->cover])
|
| 5992 |
stevensc |
1032 |
|
| 1 |
www |
1033 |
]);
|
|
|
1034 |
}
|
| 5992 |
stevensc |
1035 |
|
|
|
1036 |
|
| 1 |
www |
1037 |
$data = [
|
|
|
1038 |
'success' => false,
|
|
|
1039 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
1040 |
];
|
| 5992 |
stevensc |
1041 |
|
|
|
1042 |
|
| 1 |
www |
1043 |
return new JsonModel($data);
|
|
|
1044 |
}
|
| 768 |
geraldo |
1045 |
|
|
|
1046 |
|
|
|
1047 |
|
| 5992 |
stevensc |
1048 |
/**
|
| 768 |
geraldo |
1049 |
* Cambio de la imagen de de la cabecera de los reportes
|
|
|
1050 |
* @return \Laminas\View\Model\JsonModel
|
|
|
1051 |
*/
|
|
|
1052 |
public function headerAction()
|
|
|
1053 |
{
|
|
|
1054 |
$operation = $this->params()->fromRoute('operation');
|
|
|
1055 |
|
| 5992 |
stevensc |
1056 |
|
| 768 |
geraldo |
1057 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
1058 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
1059 |
$currentCompany = $currentUserPlugin->getCompany();
|
|
|
1060 |
|
| 5992 |
stevensc |
1061 |
|
|
|
1062 |
|
|
|
1063 |
|
| 768 |
geraldo |
1064 |
$request = $this->getRequest();
|
| 5992 |
stevensc |
1065 |
if ($request->isPost()) {
|
|
|
1066 |
|
| 768 |
geraldo |
1067 |
$companyMapper = CompanyMapper::getInstance($this->adapter);
|
|
|
1068 |
$company = $companyMapper->fetchOne($currentCompany->id);
|
| 5992 |
stevensc |
1069 |
|
| 768 |
geraldo |
1070 |
$target_path = $this->config['leaderslinked.fullpath.company'] . DIRECTORY_SEPARATOR . $company->uuid;
|
|
|
1071 |
|
| 5992 |
stevensc |
1072 |
|
|
|
1073 |
|
|
|
1074 |
if ($operation == 'delete') {
|
|
|
1075 |
if ($company->header) {
|
|
|
1076 |
|
|
|
1077 |
if (!Image::delete($target_path, $company->header)) {
|
| 768 |
geraldo |
1078 |
return new JsonModel([
|
|
|
1079 |
'success' => false,
|
|
|
1080 |
'data' => 'ERROR_THERE_WAS_AN_ERROR'
|
|
|
1081 |
]);
|
|
|
1082 |
}
|
|
|
1083 |
}
|
| 5992 |
stevensc |
1084 |
|
| 768 |
geraldo |
1085 |
$this->logger->info('Se borro el header de la empresa ' . $company->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
|
|
|
1086 |
$company->header = '';
|
| 5992 |
stevensc |
1087 |
if (!$companyMapper->updateHeader($company)) {
|
| 768 |
geraldo |
1088 |
return new JsonModel([
|
|
|
1089 |
'success' => false,
|
|
|
1090 |
'data' => 'ERROR_THERE_WAS_AN_ERROR'
|
|
|
1091 |
]);
|
|
|
1092 |
}
|
|
|
1093 |
} else {
|
|
|
1094 |
$form = new CompanyProfileHeaderForm($this->config);
|
|
|
1095 |
$data = array_merge($request->getPost()->toArray(), $request->getFiles()->toArray());
|
| 5992 |
stevensc |
1096 |
|
| 768 |
geraldo |
1097 |
$form->setData($data);
|
|
|
1098 |
|
| 5992 |
stevensc |
1099 |
if ($form->isValid()) {
|
|
|
1100 |
|
|
|
1101 |
|
| 768 |
geraldo |
1102 |
$files = $request->getFiles()->toArray();
|
| 5992 |
stevensc |
1103 |
if (!empty($files['header']['error'])) {
|
|
|
1104 |
|
| 768 |
geraldo |
1105 |
return new JsonModel([
|
|
|
1106 |
'success' => false,
|
|
|
1107 |
'data' => 'ERROR_UPLOAD_FILE'
|
|
|
1108 |
]);
|
|
|
1109 |
}
|
| 5992 |
stevensc |
1110 |
|
|
|
1111 |
if ($company->header) {
|
|
|
1112 |
|
|
|
1113 |
if (!Image::delete($target_path, $company->header)) {
|
| 768 |
geraldo |
1114 |
return new JsonModel([
|
|
|
1115 |
'success' => false,
|
|
|
1116 |
'data' => 'ERROR_THERE_WAS_AN_ERROR'
|
|
|
1117 |
]);
|
|
|
1118 |
}
|
|
|
1119 |
}
|
| 5992 |
stevensc |
1120 |
|
|
|
1121 |
list($target_width, $target_height) = explode('x', $this->config['leaderslinked.image_sizes.company_header_pdf_size']);
|
| 768 |
geraldo |
1122 |
$source = $files['header']['tmp_name'];
|
|
|
1123 |
$target_filename = 'company-header-' . uniqid() . '.png';
|
|
|
1124 |
$crop_to_dimensions = false;
|
| 5992 |
stevensc |
1125 |
|
|
|
1126 |
if (!Image::uploadImage($source, $target_path, $target_filename, $target_width, $target_height, $crop_to_dimensions)) {
|
| 768 |
geraldo |
1127 |
return new JsonModel([
|
|
|
1128 |
'success' => false,
|
|
|
1129 |
'data' => 'ERROR_THERE_WAS_AN_ERROR'
|
|
|
1130 |
]);
|
|
|
1131 |
}
|
| 5992 |
stevensc |
1132 |
|
|
|
1133 |
|
| 768 |
geraldo |
1134 |
$company->header = $target_filename;
|
| 5992 |
stevensc |
1135 |
if (!$companyMapper->updateHeader($company)) {
|
| 768 |
geraldo |
1136 |
return new JsonModel([
|
|
|
1137 |
'success' => false,
|
|
|
1138 |
'data' => 'ERROR_THERE_WAS_AN_ERROR'
|
|
|
1139 |
]);
|
|
|
1140 |
}
|
| 5992 |
stevensc |
1141 |
|
|
|
1142 |
|
| 768 |
geraldo |
1143 |
$this->logger->info('Se actualizo el header de la empresa ' . $company->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
|
|
|
1144 |
} else {
|
|
|
1145 |
$messages = [];
|
|
|
1146 |
$form_messages = (array) $form->getMessages();
|
| 5992 |
stevensc |
1147 |
foreach ($form_messages as $fieldname => $field_messages) {
|
| 768 |
geraldo |
1148 |
$messages[$fieldname] = array_values($field_messages);
|
|
|
1149 |
}
|
| 5992 |
stevensc |
1150 |
|
| 768 |
geraldo |
1151 |
return new JsonModel([
|
|
|
1152 |
'success' => false,
|
|
|
1153 |
'data' => $messages
|
|
|
1154 |
]);
|
|
|
1155 |
}
|
|
|
1156 |
}
|
|
|
1157 |
return new JsonModel([
|
|
|
1158 |
'success' => true,
|
| 810 |
geraldo |
1159 |
'data' => $this->url()->fromRoute('storage', ['type' => 'company', 'code' => $company->uuid, 'filename' => $company->header])
|
| 5992 |
stevensc |
1160 |
|
| 768 |
geraldo |
1161 |
]);
|
|
|
1162 |
}
|
| 5992 |
stevensc |
1163 |
|
|
|
1164 |
|
| 768 |
geraldo |
1165 |
$data = [
|
|
|
1166 |
'success' => false,
|
|
|
1167 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
1168 |
];
|
| 5992 |
stevensc |
1169 |
|
|
|
1170 |
|
| 768 |
geraldo |
1171 |
return new JsonModel($data);
|
|
|
1172 |
}
|
|
|
1173 |
|
|
|
1174 |
|
| 5992 |
stevensc |
1175 |
/**
|
| 768 |
geraldo |
1176 |
* Cambio de la imagen de de la cabecera de los reportes
|
|
|
1177 |
* @return \Laminas\View\Model\JsonModel
|
|
|
1178 |
*/
|
|
|
1179 |
public function footerAction()
|
|
|
1180 |
{
|
|
|
1181 |
$operation = $this->params()->fromRoute('operation');
|
|
|
1182 |
|
| 5992 |
stevensc |
1183 |
|
| 768 |
geraldo |
1184 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
1185 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
1186 |
$currentCompany = $currentUserPlugin->getCompany();
|
|
|
1187 |
|
| 5992 |
stevensc |
1188 |
|
|
|
1189 |
|
|
|
1190 |
|
| 768 |
geraldo |
1191 |
$request = $this->getRequest();
|
| 5992 |
stevensc |
1192 |
if ($request->isPost()) {
|
|
|
1193 |
|
| 768 |
geraldo |
1194 |
$companyMapper = CompanyMapper::getInstance($this->adapter);
|
|
|
1195 |
$company = $companyMapper->fetchOne($currentCompany->id);
|
| 5992 |
stevensc |
1196 |
|
| 768 |
geraldo |
1197 |
$target_path = $this->config['leaderslinked.fullpath.company'] . DIRECTORY_SEPARATOR . $company->uuid;
|
|
|
1198 |
|
| 5992 |
stevensc |
1199 |
|
|
|
1200 |
|
|
|
1201 |
if ($operation == 'delete') {
|
|
|
1202 |
if ($company->footer) {
|
|
|
1203 |
|
|
|
1204 |
if (!Image::delete($target_path, $company->footer)) {
|
| 768 |
geraldo |
1205 |
return new JsonModel([
|
|
|
1206 |
'success' => false,
|
|
|
1207 |
'data' => 'ERROR_THERE_WAS_AN_ERROR'
|
|
|
1208 |
]);
|
|
|
1209 |
}
|
|
|
1210 |
}
|
| 5992 |
stevensc |
1211 |
|
| 768 |
geraldo |
1212 |
$this->logger->info('Se borro el footer de la empresa ' . $company->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
|
|
|
1213 |
$company->footer = '';
|
| 5992 |
stevensc |
1214 |
if (!$companyMapper->updateFooter($company)) {
|
| 768 |
geraldo |
1215 |
return new JsonModel([
|
|
|
1216 |
'success' => false,
|
|
|
1217 |
'data' => 'ERROR_THERE_WAS_AN_ERROR'
|
|
|
1218 |
]);
|
|
|
1219 |
}
|
|
|
1220 |
} else {
|
|
|
1221 |
$form = new CompanyProfileFooterForm($this->config);
|
|
|
1222 |
$data = array_merge($request->getPost()->toArray(), $request->getFiles()->toArray());
|
| 5992 |
stevensc |
1223 |
|
| 768 |
geraldo |
1224 |
$form->setData($data);
|
|
|
1225 |
|
| 5992 |
stevensc |
1226 |
if ($form->isValid()) {
|
|
|
1227 |
|
|
|
1228 |
|
| 768 |
geraldo |
1229 |
$files = $request->getFiles()->toArray();
|
| 5992 |
stevensc |
1230 |
if (!empty($files['footer']['error'])) {
|
|
|
1231 |
|
| 768 |
geraldo |
1232 |
return new JsonModel([
|
|
|
1233 |
'success' => false,
|
|
|
1234 |
'data' => 'ERROR_UPLOAD_FILE'
|
|
|
1235 |
]);
|
|
|
1236 |
}
|
| 5992 |
stevensc |
1237 |
|
|
|
1238 |
if ($company->footer) {
|
|
|
1239 |
|
|
|
1240 |
if (!Image::delete($target_path, $company->footer)) {
|
| 768 |
geraldo |
1241 |
return new JsonModel([
|
|
|
1242 |
'success' => false,
|
|
|
1243 |
'data' => 'ERROR_THERE_WAS_AN_ERROR'
|
|
|
1244 |
]);
|
|
|
1245 |
}
|
|
|
1246 |
}
|
| 5992 |
stevensc |
1247 |
|
|
|
1248 |
list($target_width, $target_height) = explode('x', $this->config['leaderslinked.image_sizes.company_footer_pdf_size']);
|
| 768 |
geraldo |
1249 |
$source = $files['footer']['tmp_name'];
|
|
|
1250 |
$target_filename = 'company-footer-' . uniqid() . '.png';
|
|
|
1251 |
$crop_to_dimensions = false;
|
| 5992 |
stevensc |
1252 |
|
|
|
1253 |
if (!Image::uploadImage($source, $target_path, $target_filename, $target_width, $target_height, $crop_to_dimensions)) {
|
| 768 |
geraldo |
1254 |
return new JsonModel([
|
|
|
1255 |
'success' => false,
|
|
|
1256 |
'data' => 'ERROR_THERE_WAS_AN_ERROR'
|
|
|
1257 |
]);
|
|
|
1258 |
}
|
| 5992 |
stevensc |
1259 |
|
|
|
1260 |
|
| 768 |
geraldo |
1261 |
$company->footer = $target_filename;
|
| 5992 |
stevensc |
1262 |
if (!$companyMapper->updateFooter($company)) {
|
| 768 |
geraldo |
1263 |
return new JsonModel([
|
|
|
1264 |
'success' => false,
|
|
|
1265 |
'data' => 'ERROR_THERE_WAS_AN_ERROR'
|
|
|
1266 |
]);
|
|
|
1267 |
}
|
|
|
1268 |
|
|
|
1269 |
|
| 5992 |
stevensc |
1270 |
|
|
|
1271 |
|
| 768 |
geraldo |
1272 |
$this->logger->info('Se actualizo el footer de la empresa ' . $company->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
|
|
|
1273 |
} else {
|
|
|
1274 |
$messages = [];
|
|
|
1275 |
$form_messages = (array) $form->getMessages();
|
| 5992 |
stevensc |
1276 |
foreach ($form_messages as $fieldname => $field_messages) {
|
| 768 |
geraldo |
1277 |
$messages[$fieldname] = array_values($field_messages);
|
|
|
1278 |
}
|
| 5992 |
stevensc |
1279 |
|
| 768 |
geraldo |
1280 |
return new JsonModel([
|
|
|
1281 |
'success' => false,
|
|
|
1282 |
'data' => $messages
|
|
|
1283 |
]);
|
|
|
1284 |
}
|
|
|
1285 |
}
|
|
|
1286 |
return new JsonModel([
|
|
|
1287 |
'success' => true,
|
| 810 |
geraldo |
1288 |
'data' => $this->url()->fromRoute('storage', ['type' => 'company', 'code' => $company->uuid, 'filename' => $company->footer])
|
| 5992 |
stevensc |
1289 |
|
| 768 |
geraldo |
1290 |
]);
|
|
|
1291 |
}
|
| 5992 |
stevensc |
1292 |
|
|
|
1293 |
|
| 768 |
geraldo |
1294 |
$data = [
|
|
|
1295 |
'success' => false,
|
|
|
1296 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
1297 |
];
|
| 5992 |
stevensc |
1298 |
|
|
|
1299 |
|
| 768 |
geraldo |
1300 |
return new JsonModel($data);
|
|
|
1301 |
}
|
| 5992 |
stevensc |
1302 |
|
| 1 |
www |
1303 |
/**
|
|
|
1304 |
* Actualización de la descripción y cualquier otro campo extendido del perfil a futuro
|
|
|
1305 |
* @return \Laminas\View\Model\JsonModel
|
|
|
1306 |
*/
|
|
|
1307 |
public function industryAction()
|
|
|
1308 |
{
|
| 5992 |
stevensc |
1309 |
|
| 1 |
www |
1310 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
1311 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
1312 |
$currentCompany = $currentUserPlugin->getCompany();
|
|
|
1313 |
|
| 5992 |
stevensc |
1314 |
|
|
|
1315 |
|
|
|
1316 |
|
|
|
1317 |
|
|
|
1318 |
|
| 1 |
www |
1319 |
$request = $this->getRequest();
|
| 5992 |
stevensc |
1320 |
if ($request->isGet()) {
|
| 1 |
www |
1321 |
$companyMapper = CompanyMapper::getInstance($this->adapter);
|
|
|
1322 |
$company = $companyMapper->fetchOne($currentCompany->id);
|
| 5992 |
stevensc |
1323 |
|
| 1 |
www |
1324 |
$industryMapper = IndustryMapper::getInstance($this->adapter);
|
|
|
1325 |
$industry = $industryMapper->fetchOne($company->industry_id);
|
| 5992 |
stevensc |
1326 |
|
| 1 |
www |
1327 |
$data = [
|
|
|
1328 |
'success' => true,
|
|
|
1329 |
'data' => [
|
|
|
1330 |
'industry_id' => $industry->uuid,
|
|
|
1331 |
]
|
|
|
1332 |
];
|
| 5992 |
stevensc |
1333 |
|
| 1 |
www |
1334 |
return new JsonModel($data);
|
| 5992 |
stevensc |
1335 |
} else if ($request->isPost()) {
|
|
|
1336 |
|
|
|
1337 |
|
| 1 |
www |
1338 |
$form = new CompanyProfileIndustryForm($this->adapter);
|
|
|
1339 |
$dataPost = $request->getPost()->toArray();
|
| 5992 |
stevensc |
1340 |
|
| 1 |
www |
1341 |
$form->setData($dataPost);
|
| 5992 |
stevensc |
1342 |
|
|
|
1343 |
if ($form->isValid()) {
|
| 1 |
www |
1344 |
$companyMapper = CompanyMapper::getInstance($this->adapter);
|
|
|
1345 |
$company = $companyMapper->fetchOne($currentCompany->id);
|
|
|
1346 |
|
|
|
1347 |
$dataPost = (array) $form->getData();
|
| 5992 |
stevensc |
1348 |
|
| 1 |
www |
1349 |
$industryMapper = IndustryMapper::getInstance($this->adapter);
|
|
|
1350 |
$industry = $industryMapper->fetchOneByUuid($dataPost['industry_id']);
|
| 5992 |
stevensc |
1351 |
|
| 1 |
www |
1352 |
$company->industry_id = $industry->id;
|
|
|
1353 |
$companyMapper->updateIndustry($company);
|
| 5992 |
stevensc |
1354 |
|
| 1 |
www |
1355 |
$this->logger->info('Se actualizo la industria de la empresa ' . $company->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
|
| 5992 |
stevensc |
1356 |
|
| 1 |
www |
1357 |
$industryMapper = IndustryMapper::getInstance($this->adapter);
|
|
|
1358 |
$industry = $industryMapper->fetchOne($company->industry_id);
|
| 5992 |
stevensc |
1359 |
|
| 1 |
www |
1360 |
return new JsonModel([
|
|
|
1361 |
'success' => true,
|
|
|
1362 |
'data' => $industry->name,
|
| 5992 |
stevensc |
1363 |
|
| 1 |
www |
1364 |
]);
|
|
|
1365 |
} else {
|
|
|
1366 |
$messages = [];
|
|
|
1367 |
$form_messages = (array) $form->getMessages();
|
| 5992 |
stevensc |
1368 |
foreach ($form_messages as $fieldname => $field_messages) {
|
| 1 |
www |
1369 |
$messages[$fieldname] = array_values($field_messages);
|
|
|
1370 |
}
|
| 5992 |
stevensc |
1371 |
|
| 1 |
www |
1372 |
return new JsonModel([
|
|
|
1373 |
'success' => false,
|
|
|
1374 |
'data' => $messages
|
|
|
1375 |
]);
|
|
|
1376 |
}
|
|
|
1377 |
}
|
| 5992 |
stevensc |
1378 |
|
|
|
1379 |
|
| 1 |
www |
1380 |
$data = [
|
|
|
1381 |
'success' => false,
|
|
|
1382 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
1383 |
];
|
| 5992 |
stevensc |
1384 |
|
|
|
1385 |
|
| 1 |
www |
1386 |
return new JsonModel($data);
|
|
|
1387 |
}
|
| 5992 |
stevensc |
1388 |
|
| 1 |
www |
1389 |
/**
|
|
|
1390 |
* Actualización de la descripción y cualquier otro campo extendido del perfil a futuro
|
|
|
1391 |
* @return \Laminas\View\Model\JsonModel
|
|
|
1392 |
*/
|
|
|
1393 |
public function companySizeAction()
|
|
|
1394 |
{
|
|
|
1395 |
|
|
|
1396 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
1397 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
1398 |
$currentCompany = $currentUserPlugin->getCompany();
|
|
|
1399 |
|
|
|
1400 |
|
| 5992 |
stevensc |
1401 |
|
|
|
1402 |
|
| 1 |
www |
1403 |
$request = $this->getRequest();
|
| 5992 |
stevensc |
1404 |
if ($request->isGet()) {
|
| 1 |
www |
1405 |
$companyMapper = CompanyMapper::getInstance($this->adapter);
|
|
|
1406 |
$company = $companyMapper->fetchOne($currentCompany->id);
|
| 5992 |
stevensc |
1407 |
|
| 1 |
www |
1408 |
$companySizeMapper = CompanySizeMapper::getInstance($this->adapter);
|
|
|
1409 |
$companySize = $companySizeMapper->fetchOne($company->company_size_id);
|
| 5992 |
stevensc |
1410 |
|
| 1 |
www |
1411 |
$data = [
|
|
|
1412 |
'success' => true,
|
|
|
1413 |
'data' => [
|
|
|
1414 |
'company_size_id' => $companySize->uuid
|
|
|
1415 |
]
|
|
|
1416 |
];
|
| 5992 |
stevensc |
1417 |
|
| 1 |
www |
1418 |
return new JsonModel($data);
|
| 5992 |
stevensc |
1419 |
} else if ($request->isPost()) {
|
|
|
1420 |
|
|
|
1421 |
|
| 1 |
www |
1422 |
$form = new CompanyProfileCompanySizeForm($this->adapter);
|
|
|
1423 |
$dataPost = $request->getPost()->toArray();
|
| 5992 |
stevensc |
1424 |
|
| 1 |
www |
1425 |
$form->setData($dataPost);
|
| 5992 |
stevensc |
1426 |
|
|
|
1427 |
if ($form->isValid()) {
|
| 1 |
www |
1428 |
$companyMapper = CompanyMapper::getInstance($this->adapter);
|
|
|
1429 |
$company = $companyMapper->fetchOne($currentCompany->id);
|
| 5992 |
stevensc |
1430 |
|
| 1 |
www |
1431 |
$dataPost = (array) $form->getData();
|
| 5992 |
stevensc |
1432 |
|
| 1 |
www |
1433 |
$companySizeMapper = CompanySizeMapper::getInstance($this->adapter);
|
|
|
1434 |
$companySize = $companySizeMapper->fetchOneByUuid($dataPost['company_size_id']);
|
| 5992 |
stevensc |
1435 |
|
| 1 |
www |
1436 |
$company->company_size_id = $companySize->id;
|
|
|
1437 |
$companyMapper->updateIndustry($company);
|
| 5992 |
stevensc |
1438 |
|
| 1 |
www |
1439 |
$this->logger->info('Se actualizo la industria de la empresa ' . $company->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
|
| 5992 |
stevensc |
1440 |
|
| 1 |
www |
1441 |
$companySizeMapper = CompanySizeMapper::getInstance($this->adapter);
|
|
|
1442 |
$companySize = $companySizeMapper->fetchOne($company->company_size_id);
|
| 5992 |
stevensc |
1443 |
|
| 1 |
www |
1444 |
return new JsonModel([
|
|
|
1445 |
'success' => true,
|
| 5992 |
stevensc |
1446 |
'data' => $companySize->name . ' (' . $companySize->minimum_no_of_employee . '-' . $companySize->maximum_no_of_employee . ')',
|
|
|
1447 |
|
| 1 |
www |
1448 |
]);
|
|
|
1449 |
} else {
|
|
|
1450 |
$messages = [];
|
|
|
1451 |
$form_messages = (array) $form->getMessages();
|
| 5992 |
stevensc |
1452 |
foreach ($form_messages as $fieldname => $field_messages) {
|
| 1 |
www |
1453 |
$messages[$fieldname] = array_values($field_messages);
|
|
|
1454 |
}
|
| 5992 |
stevensc |
1455 |
|
| 1 |
www |
1456 |
return new JsonModel([
|
|
|
1457 |
'success' => false,
|
|
|
1458 |
'data' => $messages
|
|
|
1459 |
]);
|
|
|
1460 |
}
|
|
|
1461 |
}
|
| 5992 |
stevensc |
1462 |
|
|
|
1463 |
|
| 1 |
www |
1464 |
$data = [
|
|
|
1465 |
'success' => false,
|
|
|
1466 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
1467 |
];
|
| 5992 |
stevensc |
1468 |
|
|
|
1469 |
|
| 1 |
www |
1470 |
return new JsonModel($data);
|
|
|
1471 |
}
|
|
|
1472 |
}
|