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