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