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