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