1384 |
efrain |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
declare(strict_types=1);
|
|
|
4 |
|
|
|
5 |
namespace LeadersLinked\Controller;
|
|
|
6 |
|
|
|
7 |
use Laminas\Db\Adapter\AdapterInterface;
|
16766 |
efrain |
8 |
use LeadersLinked\Cache\CacheInterface;
|
1384 |
efrain |
9 |
use Laminas\Mvc\Controller\AbstractActionController;
|
|
|
10 |
use Laminas\Log\LoggerInterface;
|
|
|
11 |
use Laminas\View\Model\ViewModel;
|
|
|
12 |
use Laminas\View\Model\JsonModel;
|
15457 |
efrain |
13 |
use LeadersLinked\Form\RecruitmentSelection\RecruitmentSelectionVacancyForm;
|
1384 |
efrain |
14 |
use LeadersLinked\Library\Functions;
|
1386 |
eleazar |
15 |
use LeadersLinked\Mapper\RecruitmentSelectionVacancyMapper;
|
1387 |
eleazar |
16 |
use LeadersLinked\Model\RecruitmentSelectionVacancy;
|
1384 |
efrain |
17 |
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
|
|
|
18 |
use LeadersLinked\Model\Location;
|
15461 |
efrain |
19 |
use LeadersLinked\Mapper\BehaviorMapper;
|
|
|
20 |
use LeadersLinked\Mapper\CompetencyMapper;
|
|
|
21 |
use LeadersLinked\Mapper\CompetencyTypeMapper;
|
|
|
22 |
use LeadersLinked\Mapper\JobDescriptionCompetencyBehaviorMapper;
|
|
|
23 |
use LeadersLinked\Mapper\JobDescriptionCompetencyMapper;
|
|
|
24 |
use LeadersLinked\Mapper\JobDescriptionSubordinateMapper;
|
1384 |
efrain |
25 |
use LeadersLinked\Mapper\LocationMapper;
|
|
|
26 |
use LeadersLinked\Mapper\IndustryMapper;
|
|
|
27 |
use LeadersLinked\Mapper\JobDescriptionMapper;
|
|
|
28 |
use LeadersLinked\Mapper\JobCategoryMapper;
|
15457 |
efrain |
29 |
use Laminas\Paginator\Adapter\DbSelect;
|
|
|
30 |
use Laminas\Paginator\Paginator;
|
|
|
31 |
use LeadersLinked\Mapper\QueryMapper;
|
|
|
32 |
use Laminas\Hydrator\ArraySerializableHydrator;
|
|
|
33 |
use Laminas\Db\ResultSet\HydratingResultSet;
|
1384 |
efrain |
34 |
|
12314 |
stevensc |
35 |
class RecruitmentSelectionVacancyController extends AbstractActionController
|
|
|
36 |
{
|
1384 |
efrain |
37 |
|
|
|
38 |
/**
|
|
|
39 |
*
|
|
|
40 |
* @var AdapterInterface
|
|
|
41 |
*/
|
|
|
42 |
private $adapter;
|
|
|
43 |
|
|
|
44 |
/**
|
|
|
45 |
*
|
16766 |
efrain |
46 |
* @var CacheInterface
|
1384 |
efrain |
47 |
*/
|
|
|
48 |
private $cache;
|
|
|
49 |
|
|
|
50 |
/**
|
|
|
51 |
*
|
|
|
52 |
* @var LoggerInterface
|
|
|
53 |
*/
|
|
|
54 |
private $logger;
|
|
|
55 |
|
|
|
56 |
/**
|
|
|
57 |
*
|
|
|
58 |
* @var array
|
|
|
59 |
*/
|
|
|
60 |
private $config;
|
|
|
61 |
|
|
|
62 |
/**
|
|
|
63 |
*
|
|
|
64 |
* @param AdapterInterface $adapter
|
16766 |
efrain |
65 |
*@param CacheInterface $cache
|
1384 |
efrain |
66 |
* @param LoggerInterface $logger
|
|
|
67 |
* @param array $config
|
|
|
68 |
*/
|
12314 |
stevensc |
69 |
public function __construct($adapter, $cache, $logger, $config)
|
|
|
70 |
{
|
1384 |
efrain |
71 |
$this->adapter = $adapter;
|
|
|
72 |
$this->cache = $cache;
|
|
|
73 |
$this->logger = $logger;
|
|
|
74 |
$this->config = $config;
|
|
|
75 |
}
|
|
|
76 |
|
12314 |
stevensc |
77 |
public function indexAction()
|
|
|
78 |
{
|
1384 |
efrain |
79 |
$request = $this->getRequest();
|
|
|
80 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
81 |
$currentCompany = $currentUserPlugin->getCompany();
|
|
|
82 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
83 |
|
|
|
84 |
|
|
|
85 |
$request = $this->getRequest();
|
|
|
86 |
if ($request->isGet()) {
|
|
|
87 |
$sandbox = $this->config['leaderslinked.runmode.sandbox'];
|
12314 |
stevensc |
88 |
if ($sandbox) {
|
1384 |
efrain |
89 |
$google_map_key = $this->config['leaderslinked.google_map.sandbox_api_key'];
|
|
|
90 |
} else {
|
|
|
91 |
$google_map_key = $this->config['leaderslinked.google_map.production_api_key'];
|
|
|
92 |
}
|
|
|
93 |
|
12314 |
stevensc |
94 |
|
1384 |
efrain |
95 |
$headers = $request->getHeaders();
|
|
|
96 |
|
|
|
97 |
$isJson = false;
|
|
|
98 |
if ($headers->has('Accept')) {
|
|
|
99 |
$accept = $headers->get('Accept');
|
|
|
100 |
|
|
|
101 |
$prioritized = $accept->getPrioritized();
|
|
|
102 |
|
|
|
103 |
foreach ($prioritized as $key => $value) {
|
|
|
104 |
$raw = trim($value->getRaw());
|
|
|
105 |
|
|
|
106 |
if (!$isJson) {
|
|
|
107 |
$isJson = strpos($raw, 'json');
|
|
|
108 |
}
|
|
|
109 |
}
|
|
|
110 |
}
|
|
|
111 |
|
|
|
112 |
//$isJson = true;
|
|
|
113 |
if ($isJson) {
|
10093 |
stevensc |
114 |
$search = $this->params()->fromQuery('search');
|
16766 |
efrain |
115 |
$search = empty($search) ? '' : Functions::sanitizeFilterString($search);
|
1384 |
efrain |
116 |
|
15371 |
efrain |
117 |
$start = intval($this->params()->fromQuery('start', 0), 10);
|
1384 |
efrain |
118 |
$records_x_page = intval($this->params()->fromQuery('length', 10), 10);
|
15371 |
efrain |
119 |
$page = intval($start / $records_x_page);
|
|
|
120 |
$page++;
|
|
|
121 |
|
1384 |
efrain |
122 |
$order = $this->params()->fromQuery('order', []);
|
|
|
123 |
$order_field = empty($order[0]['column']) ? 99 : intval($order[0]['column'], 10);
|
16766 |
efrain |
124 |
$order_direction = empty($order[0]['dir']) ? 'ASC' : Functions::sanitizeFilterString(filter_var($order[0]['dir']));
|
1384 |
efrain |
125 |
|
|
|
126 |
$fields = ['name'];
|
|
|
127 |
$order_field = isset($fields[$order_field]) ? $fields[$order_field] : 'name';
|
|
|
128 |
|
|
|
129 |
if (!in_array($order_direction, ['ASC', 'DESC'])) {
|
|
|
130 |
$order_direction = 'ASC';
|
|
|
131 |
}
|
|
|
132 |
|
1434 |
eleazar |
133 |
$acl = $this->getEvent()->getViewModel()->getVariable('acl');
|
1477 |
efrain |
134 |
$allowDelete = $acl->isAllowed($currentUser->usertype_id, 'recruitment-and-selection/vacancies/delete');
|
|
|
135 |
$allowEdit = $acl->isAllowed($currentUser->usertype_id, 'recruitment-and-selection/vacancies/edit');
|
1434 |
eleazar |
136 |
|
12314 |
stevensc |
137 |
|
15457 |
efrain |
138 |
$queryMapper = QueryMapper::getInstance($this->adapter);
|
|
|
139 |
$select = $queryMapper->getSql()->select();
|
|
|
140 |
$select->from(['tb1' => RecruitmentSelectionVacancyMapper::_TABLE]);
|
|
|
141 |
$select->columns(['uuid', 'name', 'last_date', 'status']);
|
|
|
142 |
$select->join(['tb2' => JobDescriptionMapper::_TABLE], 'tb1.job_description_id = tb2.id AND tb1.company_id = tb2.company_id', ['job_description' => 'name']);
|
|
|
143 |
|
|
|
144 |
$select->where->equalTo('tb1.company_id', $currentCompany->network_id);
|
|
|
145 |
|
|
|
146 |
if($search) {
|
|
|
147 |
$select->where->like('tb1.name', '%' . $search . '%');
|
|
|
148 |
}
|
|
|
149 |
$select->order($order_field . ' ' . $order_direction);
|
|
|
150 |
|
|
|
151 |
//echo $select->getSqlString($this->adapter->platform); exit;
|
|
|
152 |
|
|
|
153 |
$hydrator = new ArraySerializableHydrator();
|
|
|
154 |
$resultset = new HydratingResultSet($hydrator);
|
|
|
155 |
|
|
|
156 |
$adapter = new DbSelect($select, $queryMapper->getSql(), $resultset);
|
|
|
157 |
$paginator = new Paginator($adapter);
|
|
|
158 |
$paginator->setItemCountPerPage($records_x_page);
|
|
|
159 |
$paginator->setCurrentPageNumber($page);
|
|
|
160 |
|
|
|
161 |
|
1384 |
efrain |
162 |
|
|
|
163 |
$items = [];
|
|
|
164 |
$records = $paginator->getCurrentItems();
|
12314 |
stevensc |
165 |
|
1384 |
efrain |
166 |
foreach ($records as $record) {
|
15457 |
efrain |
167 |
$dt = \DateTime::createFromFormat('Y-m-d', $record['last_date']);
|
|
|
168 |
|
15461 |
efrain |
169 |
|
|
|
170 |
|
15457 |
efrain |
171 |
switch($record['status'])
|
|
|
172 |
{
|
|
|
173 |
case RecruitmentSelectionVacancy::STATUS_ACTIVE :
|
|
|
174 |
$status = 'LABEL_ACTIVE';
|
|
|
175 |
break;
|
|
|
176 |
|
|
|
177 |
case RecruitmentSelectionVacancy::STATUS_INACTIVE :
|
|
|
178 |
$status = 'LABEL_INACTIVE';
|
|
|
179 |
break;
|
|
|
180 |
|
|
|
181 |
case RecruitmentSelectionVacancy::STATUS_EXPIRED :
|
|
|
182 |
$status = 'LABEL_EXPIRED';
|
|
|
183 |
break;
|
|
|
184 |
|
|
|
185 |
case RecruitmentSelectionVacancy::STATUS_COMPLETED :
|
|
|
186 |
$status = 'LABEL_COMPLETED';
|
|
|
187 |
break;
|
|
|
188 |
|
|
|
189 |
default :
|
|
|
190 |
$status = 'LABEL_UNKNOWN';
|
|
|
191 |
break;
|
|
|
192 |
|
1384 |
efrain |
193 |
}
|
15457 |
efrain |
194 |
|
15461 |
efrain |
195 |
|
|
|
196 |
if($record['status'] == RecruitmentSelectionVacancy::STATUS_ACTIVE || $record['status'] == RecruitmentSelectionVacancy::STATUS_INACTIVE) {
|
|
|
197 |
$actions = [
|
|
|
198 |
'link_edit' => $allowEdit ? $this->url()->fromRoute('recruitment-and-selection/vacancies/edit', ['id' => $record['uuid']]) : '',
|
|
|
199 |
'link_delete' => $allowDelete ? $this->url()->fromRoute('recruitment-and-selection/vacancies/delete', ['id' => $record['uuid']]) : ''
|
|
|
200 |
];
|
|
|
201 |
} else {
|
|
|
202 |
|
|
|
203 |
$actions = [
|
|
|
204 |
'link_edit' => '',
|
|
|
205 |
'link_delete' => '',
|
|
|
206 |
];
|
|
|
207 |
}
|
|
|
208 |
|
15457 |
efrain |
209 |
$item = [
|
|
|
210 |
'name' => $record['name'],
|
|
|
211 |
'job_description' => $record['job_description'],
|
|
|
212 |
'last_date' => $dt->format('d/m/Y'),
|
15461 |
efrain |
213 |
'status' => $status,
|
|
|
214 |
'actions' => $actions,
|
15457 |
efrain |
215 |
];
|
|
|
216 |
|
1384 |
efrain |
217 |
|
|
|
218 |
array_push($items, $item);
|
|
|
219 |
}
|
|
|
220 |
|
|
|
221 |
return new JsonModel([
|
|
|
222 |
'success' => true,
|
|
|
223 |
'data' => [
|
|
|
224 |
'items' => $items,
|
|
|
225 |
'total' => $paginator->getTotalItemCount(),
|
|
|
226 |
]
|
|
|
227 |
]);
|
|
|
228 |
} else {
|
|
|
229 |
|
1544 |
eleazar |
230 |
$form = new RecruitmentSelectionVacancyForm($this->adapter, $currentCompany->id);
|
1384 |
efrain |
231 |
|
1549 |
eleazar |
232 |
$jobDescriptionMapper = JobDescriptionMapper::getInstance($this->adapter);
|
|
|
233 |
$industryMapper = industryMapper::getInstance($this->adapter);
|
12314 |
stevensc |
234 |
$jobCategoryMapper = JobCategoryMapper::getInstance($this->adapter);
|
|
|
235 |
|
|
|
236 |
$jobDescritions = [];
|
|
|
237 |
$industries = [];
|
|
|
238 |
$jobCategories = [];
|
|
|
239 |
|
15087 |
efrain |
240 |
$records = $jobCategoryMapper->fetchAllActive();
|
12314 |
stevensc |
241 |
|
|
|
242 |
foreach ($records as $record) {
|
|
|
243 |
$jobCategories[$record->uuid] = $record->name;
|
|
|
244 |
}
|
|
|
245 |
|
15087 |
efrain |
246 |
$records = $industryMapper->fetchAllActive();
|
12314 |
stevensc |
247 |
|
|
|
248 |
foreach ($records as $record) {
|
|
|
249 |
$industries[$record->uuid] = $record->name;
|
|
|
250 |
}
|
|
|
251 |
|
|
|
252 |
$records = $currentCompany ?
|
|
|
253 |
$jobDescriptionMapper->fetchAllActiveByCompanyId($currentCompany->id) :
|
15087 |
efrain |
254 |
$jobDescriptionMapper->fetchAllActiveByDefault();
|
|
|
255 |
|
12314 |
stevensc |
256 |
foreach ($records as $record) {
|
|
|
257 |
$jobDescritions[$record->uuid] = $record->name;
|
|
|
258 |
}
|
|
|
259 |
|
15087 |
efrain |
260 |
|
|
|
261 |
//print_r($jobDescritions); exit;
|
|
|
262 |
|
1384 |
efrain |
263 |
$this->layout()->setTemplate('layout/layout-backend');
|
|
|
264 |
$viewModel = new ViewModel();
|
1396 |
eleazar |
265 |
$viewModel->setTemplate('leaders-linked/recruitment-and-selection-vacancies/index.phtml');
|
1384 |
efrain |
266 |
$viewModel->setVariable('form', $form);
|
10112 |
stevensc |
267 |
$viewModel->setVariable('google_map_key', $google_map_key);
|
12314 |
stevensc |
268 |
$viewModel->setVariable('jobDescritions', $jobDescritions);
|
|
|
269 |
$viewModel->setVariable('industries', $industries);
|
|
|
270 |
$viewModel->setVariable('jobCategories', $jobCategories);
|
1561 |
efrain |
271 |
|
1384 |
efrain |
272 |
return $viewModel;
|
|
|
273 |
}
|
|
|
274 |
} else {
|
|
|
275 |
return new JsonModel([
|
|
|
276 |
'success' => false,
|
|
|
277 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
12314 |
stevensc |
278 |
]);;
|
1384 |
efrain |
279 |
}
|
|
|
280 |
}
|
|
|
281 |
|
12314 |
stevensc |
282 |
public function addAction()
|
|
|
283 |
{
|
1384 |
efrain |
284 |
$request = $this->getRequest();
|
|
|
285 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
286 |
$currentCompany = $currentUserPlugin->getCompany();
|
|
|
287 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
288 |
|
|
|
289 |
$request = $this->getRequest();
|
|
|
290 |
|
|
|
291 |
|
|
|
292 |
if ($request->isPost()) {
|
1544 |
eleazar |
293 |
$form = new RecruitmentSelectionVacancyForm($this->adapter, $currentCompany->id);
|
1384 |
efrain |
294 |
$dataPost = $request->getPost()->toArray();
|
15087 |
efrain |
295 |
|
|
|
296 |
|
15461 |
efrain |
297 |
if(!empty($dataPost['last_date'])) {
|
|
|
298 |
$dt = \DateTime::createFromFormat('d/m/Y', $dataPost['last_date']);
|
|
|
299 |
if($dt) {
|
|
|
300 |
$dataPost['last_date'] = $dt->format('Y-m-d');
|
|
|
301 |
} else {
|
|
|
302 |
$dataPost['last_date'] = date('Y-m-d');
|
|
|
303 |
}
|
|
|
304 |
}
|
|
|
305 |
|
15087 |
efrain |
306 |
|
|
|
307 |
|
1387 |
eleazar |
308 |
$dataPost['status'] = isset($dataPost['status']) ? $dataPost['status'] : RecruitmentSelectionVacancy::STATUS_INACTIVE;
|
1384 |
efrain |
309 |
|
|
|
310 |
$form->setData($dataPost);
|
|
|
311 |
|
|
|
312 |
if ($form->isValid()) {
|
|
|
313 |
$dataPost = (array) $form->getData();
|
|
|
314 |
|
15087 |
efrain |
315 |
|
1384 |
efrain |
316 |
$hydrator = new ObjectPropertyHydrator();
|
|
|
317 |
|
1417 |
eleazar |
318 |
$location = new Location();
|
|
|
319 |
$hydrator->hydrate($dataPost, $location);
|
12314 |
stevensc |
320 |
|
|
|
321 |
$locationMapper = LocationMapper::getInstance($this->adapter);
|
1452 |
eleazar |
322 |
$result = $locationMapper->insert($location);
|
1451 |
eleazar |
323 |
|
1417 |
eleazar |
324 |
|
1418 |
eleazar |
325 |
if (!$result) {
|
|
|
326 |
return new JsonModel([
|
|
|
327 |
'success' => false,
|
15461 |
efrain |
328 |
'data' => $locationMapper->getError()
|
1418 |
eleazar |
329 |
]);
|
|
|
330 |
}
|
1417 |
eleazar |
331 |
|
1539 |
eleazar |
332 |
$vacancy = new RecruitmentSelectionVacancy();
|
|
|
333 |
$hydrator->hydrate($dataPost, $vacancy);
|
1427 |
eleazar |
334 |
|
1539 |
eleazar |
335 |
$vacancy->location_id = $location->id;
|
1544 |
eleazar |
336 |
$vacancy->company_id = $currentCompany->id;
|
1384 |
efrain |
337 |
|
1427 |
eleazar |
338 |
$jobDescriptionMapper = JobDescriptionMapper::getInstance($this->adapter);
|
|
|
339 |
$jobDescription = $jobDescriptionMapper->fetchOneByUuid($dataPost['job_description_id']);
|
1539 |
eleazar |
340 |
$vacancy->job_description_id = $jobDescription->id;
|
15461 |
efrain |
341 |
$vacancy->content = $this->serialize($jobDescription);
|
1427 |
eleazar |
342 |
|
|
|
343 |
$jobCategoryMapper = JobCategoryMapper::getInstance($this->adapter);
|
12314 |
stevensc |
344 |
$jobCategory = $jobCategoryMapper->fetchOneByUuid($dataPost['job_category_id']);
|
1539 |
eleazar |
345 |
$vacancy->job_category_id = $jobCategory->id;
|
1427 |
eleazar |
346 |
|
1428 |
eleazar |
347 |
$industryMapper = IndustryMapper::getInstance($this->adapter);
|
|
|
348 |
$industry = $industryMapper->fetchOneByUuid($dataPost['industry_id']);
|
1539 |
eleazar |
349 |
$vacancy->industry_id = $industry->id;
|
1425 |
eleazar |
350 |
|
1539 |
eleazar |
351 |
$vacancy->description = $dataPost['description'];
|
12314 |
stevensc |
352 |
|
1428 |
eleazar |
353 |
|
15087 |
efrain |
354 |
|
1427 |
eleazar |
355 |
$recruitmentSelectionVacancyMapper = RecruitmentSelectionVacancyMapper::getInstance($this->adapter);
|
1539 |
eleazar |
356 |
$result = $recruitmentSelectionVacancyMapper->insert($vacancy);
|
1384 |
efrain |
357 |
|
|
|
358 |
if ($result) {
|
15461 |
efrain |
359 |
$this->logger->info('Se agrego la vacante : ' . $vacancy->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
|
1384 |
efrain |
360 |
|
|
|
361 |
$data = [
|
|
|
362 |
'success' => true,
|
|
|
363 |
'data' => 'LABEL_RECORD_ADDED'
|
|
|
364 |
];
|
|
|
365 |
} else {
|
|
|
366 |
$data = [
|
|
|
367 |
'success' => false,
|
1412 |
eleazar |
368 |
'data' => $recruitmentSelectionVacancyMapper->getError()
|
1384 |
efrain |
369 |
];
|
|
|
370 |
}
|
|
|
371 |
|
|
|
372 |
return new JsonModel($data);
|
|
|
373 |
} else {
|
|
|
374 |
$messages = [];
|
|
|
375 |
$form_messages = (array) $form->getMessages();
|
|
|
376 |
foreach ($form_messages as $fieldname => $field_messages) {
|
|
|
377 |
|
|
|
378 |
$messages[$fieldname] = array_values($field_messages);
|
|
|
379 |
}
|
|
|
380 |
|
|
|
381 |
return new JsonModel([
|
|
|
382 |
'success' => false,
|
|
|
383 |
'data' => $messages
|
|
|
384 |
]);
|
|
|
385 |
}
|
|
|
386 |
} else {
|
|
|
387 |
$data = [
|
|
|
388 |
'success' => false,
|
1575 |
eleazar |
389 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
1384 |
efrain |
390 |
];
|
|
|
391 |
|
|
|
392 |
return new JsonModel($data);
|
|
|
393 |
}
|
|
|
394 |
|
|
|
395 |
return new JsonModel($data);
|
|
|
396 |
}
|
|
|
397 |
|
12314 |
stevensc |
398 |
public function editAction()
|
|
|
399 |
{
|
1384 |
efrain |
400 |
$request = $this->getRequest();
|
|
|
401 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
402 |
$currentCompany = $currentUserPlugin->getCompany();
|
|
|
403 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
404 |
|
|
|
405 |
$request = $this->getRequest();
|
|
|
406 |
$uuid = $this->params()->fromRoute('id');
|
|
|
407 |
|
|
|
408 |
|
|
|
409 |
if (!$uuid) {
|
|
|
410 |
$data = [
|
|
|
411 |
'success' => false,
|
|
|
412 |
'data' => 'ERROR_INVALID_PARAMETER'
|
|
|
413 |
];
|
|
|
414 |
|
|
|
415 |
return new JsonModel($data);
|
|
|
416 |
}
|
|
|
417 |
|
1386 |
eleazar |
418 |
$recruitmentSelectionVacancyMapper = RecruitmentSelectionVacancyMapper::getInstance($this->adapter);
|
1575 |
eleazar |
419 |
$vacancy = $recruitmentSelectionVacancyMapper->fetchOneByUuid($uuid);
|
|
|
420 |
if (!$vacancy) {
|
1384 |
efrain |
421 |
$data = [
|
|
|
422 |
'success' => false,
|
|
|
423 |
'data' => 'ERROR_RECORD_NOT_FOUND'
|
|
|
424 |
];
|
|
|
425 |
|
|
|
426 |
return new JsonModel($data);
|
|
|
427 |
}
|
|
|
428 |
|
1575 |
eleazar |
429 |
if ($vacancy->company_id != $currentCompany->id) {
|
1384 |
efrain |
430 |
return new JsonModel([
|
|
|
431 |
'success' => false,
|
|
|
432 |
'data' => 'ERROR_UNAUTHORIZED'
|
|
|
433 |
]);
|
|
|
434 |
}
|
|
|
435 |
|
|
|
436 |
|
|
|
437 |
if ($request->isPost()) {
|
1544 |
eleazar |
438 |
$form = new RecruitmentSelectionVacancyForm($this->adapter, $currentCompany->id);
|
1384 |
efrain |
439 |
$dataPost = $request->getPost()->toArray();
|
15461 |
efrain |
440 |
|
|
|
441 |
if(!empty($dataPost['last_date'])) {
|
|
|
442 |
$dt = \DateTime::createFromFormat('d/m/Y', $dataPost['last_date']);
|
|
|
443 |
if($dt) {
|
|
|
444 |
$dataPost['last_date'] = $dt->format('Y-m-d');
|
|
|
445 |
} else {
|
|
|
446 |
$dataPost['last_date'] = date('Y-m-d');
|
|
|
447 |
}
|
|
|
448 |
}
|
|
|
449 |
|
1387 |
eleazar |
450 |
$dataPost['status'] = isset($dataPost['status']) ? $dataPost['status'] : RecruitmentSelectionVacancy::STATUS_INACTIVE;
|
1384 |
efrain |
451 |
|
|
|
452 |
$form->setData($dataPost);
|
|
|
453 |
|
|
|
454 |
if ($form->isValid()) {
|
|
|
455 |
$dataPost = (array) $form->getData();
|
|
|
456 |
|
|
|
457 |
$hydrator = new ObjectPropertyHydrator();
|
1575 |
eleazar |
458 |
$hydrator->hydrate($dataPost, $vacancy);
|
1384 |
efrain |
459 |
|
1575 |
eleazar |
460 |
if (!$vacancy->status) {
|
|
|
461 |
$vacancy->status = RecruitmentSelectionVacancy::STATUS_INACTIVE;
|
1384 |
efrain |
462 |
}
|
15118 |
efrain |
463 |
|
1578 |
eleazar |
464 |
$locationMapper = LocationMapper::getInstance($this->adapter);
|
|
|
465 |
$location = $locationMapper->fetchOne($vacancy->location_id);
|
|
|
466 |
$hydrator->hydrate($dataPost, $location);
|
|
|
467 |
$locationMapper->update($location);
|
|
|
468 |
|
1384 |
efrain |
469 |
$jobDescriptionMapper = JobDescriptionMapper::getInstance($this->adapter);
|
|
|
470 |
$jobDescription = $jobDescriptionMapper->fetchOneByUuid($dataPost['job_description_id']);
|
1575 |
eleazar |
471 |
$vacancy->job_description_id = $jobDescription->id;
|
1384 |
efrain |
472 |
|
1439 |
eleazar |
473 |
$jobCategoryMapper = JobCategoryMapper::getInstance($this->adapter);
|
12314 |
stevensc |
474 |
$jobCategory = $jobCategoryMapper->fetchOneByUuid($dataPost['job_category_id']);
|
1575 |
eleazar |
475 |
$vacancy->job_category_id = $jobCategory->id;
|
1384 |
efrain |
476 |
|
1439 |
eleazar |
477 |
$industryMapper = IndustryMapper::getInstance($this->adapter);
|
|
|
478 |
$industry = $industryMapper->fetchOneByUuid($dataPost['industry_id']);
|
1575 |
eleazar |
479 |
$vacancy->industry_id = $industry->id;
|
15461 |
efrain |
480 |
|
1439 |
eleazar |
481 |
|
1577 |
eleazar |
482 |
$result = $recruitmentSelectionVacancyMapper->update($vacancy);
|
1439 |
eleazar |
483 |
|
12314 |
stevensc |
484 |
|
1384 |
efrain |
485 |
if ($result) {
|
15461 |
efrain |
486 |
$this->logger->info('Se actualizo la vancante : ' . $vacancy->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
|
1384 |
efrain |
487 |
$data = [
|
|
|
488 |
'success' => true,
|
|
|
489 |
'data' => 'LABEL_RECORD_UPDATED'
|
|
|
490 |
];
|
|
|
491 |
} else {
|
|
|
492 |
$data = [
|
|
|
493 |
'success' => false,
|
1386 |
eleazar |
494 |
'data' => $recruitmentSelectionVacancyMapper->getError()
|
1384 |
efrain |
495 |
];
|
|
|
496 |
}
|
|
|
497 |
|
|
|
498 |
return new JsonModel($data);
|
|
|
499 |
} else {
|
|
|
500 |
$messages = [];
|
|
|
501 |
$form_messages = (array) $form->getMessages();
|
|
|
502 |
foreach ($form_messages as $fieldname => $field_messages) {
|
|
|
503 |
$messages[$fieldname] = array_values($field_messages);
|
|
|
504 |
}
|
|
|
505 |
|
|
|
506 |
return new JsonModel([
|
|
|
507 |
'success' => false,
|
|
|
508 |
'data' => $messages
|
|
|
509 |
]);
|
|
|
510 |
}
|
|
|
511 |
} else if ($request->isGet()) {
|
|
|
512 |
$hydrator = new ObjectPropertyHydrator();
|
|
|
513 |
|
1441 |
eleazar |
514 |
$locationMapper = LocationMapper::getInstance($this->adapter);
|
1575 |
eleazar |
515 |
$location = $locationMapper->fetchOne($vacancy->location_id);
|
1441 |
eleazar |
516 |
|
1384 |
efrain |
517 |
$jobDescriptionMapper = JobDescriptionMapper::getInstance($this->adapter);
|
1575 |
eleazar |
518 |
$jobDescription = $jobDescriptionMapper->fetchOne($vacancy->job_description_id);
|
15461 |
efrain |
519 |
|
|
|
520 |
$jobCategoryMapper = JobCategoryMapper::getInstance($this->adapter);
|
1575 |
eleazar |
521 |
$jobCategory = $jobCategoryMapper->fetchOne($vacancy->job_category_id);
|
15461 |
efrain |
522 |
|
1445 |
eleazar |
523 |
$industryMapper = IndustryMapper::getInstance($this->adapter);
|
1575 |
eleazar |
524 |
$industry = $industryMapper->fetchOne($vacancy->industry_id);
|
15087 |
efrain |
525 |
|
15461 |
efrain |
526 |
|
15087 |
efrain |
527 |
$dt = \DateTime::createFromFormat('Y-m-d', $vacancy->last_date);
|
15461 |
efrain |
528 |
$last_date = $dt->format('d/m/Y');
|
15087 |
efrain |
529 |
|
1384 |
efrain |
530 |
$data = [
|
|
|
531 |
'success' => true,
|
|
|
532 |
'data' => [
|
1575 |
eleazar |
533 |
'name' => $vacancy->name,
|
15461 |
efrain |
534 |
'job_description_id' => $jobDescription->uuid,
|
|
|
535 |
'job_category_id' => $jobCategory->uuid,
|
|
|
536 |
'industry_id' => $industry->uuid,
|
1572 |
eleazar |
537 |
'location_search' => $location->formatted_address,
|
1570 |
eleazar |
538 |
'formatted_address' => $location->formatted_address,
|
1572 |
eleazar |
539 |
'address1' => $location->address1,
|
|
|
540 |
'address2' => $location->address2,
|
1568 |
eleazar |
541 |
'country' => $location->country,
|
|
|
542 |
'state' => $location->state,
|
12314 |
stevensc |
543 |
'city1' => $location->city1,
|
1568 |
eleazar |
544 |
'city2' => $location->city2,
|
|
|
545 |
'postal_code' => $location->postal_code,
|
|
|
546 |
'latitude' => $location->latitude,
|
|
|
547 |
'longitude' => $location->longitude,
|
1575 |
eleazar |
548 |
'description' => $vacancy->description,
|
15087 |
efrain |
549 |
'last_date' => $last_date,
|
1575 |
eleazar |
550 |
'status' => $vacancy->status,
|
15461 |
efrain |
551 |
|
1384 |
efrain |
552 |
]
|
|
|
553 |
];
|
|
|
554 |
|
15461 |
efrain |
555 |
|
1384 |
efrain |
556 |
} else {
|
|
|
557 |
$data = [
|
|
|
558 |
'success' => false,
|
1574 |
eleazar |
559 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
1384 |
efrain |
560 |
];
|
|
|
561 |
|
15461 |
efrain |
562 |
|
1384 |
efrain |
563 |
}
|
|
|
564 |
|
|
|
565 |
return new JsonModel($data);
|
|
|
566 |
}
|
|
|
567 |
|
12314 |
stevensc |
568 |
public function deleteAction()
|
|
|
569 |
{
|
1384 |
efrain |
570 |
$request = $this->getRequest();
|
|
|
571 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
572 |
$currentCompany = $currentUserPlugin->getCompany();
|
|
|
573 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
574 |
|
|
|
575 |
$request = $this->getRequest();
|
|
|
576 |
$uuid = $this->params()->fromRoute('id');
|
|
|
577 |
|
|
|
578 |
if (!$uuid) {
|
|
|
579 |
$data = [
|
|
|
580 |
'success' => false,
|
|
|
581 |
'data' => 'ERROR_INVALID_PARAMETER'
|
|
|
582 |
];
|
|
|
583 |
|
|
|
584 |
return new JsonModel($data);
|
|
|
585 |
}
|
|
|
586 |
|
1386 |
eleazar |
587 |
$recruitmentSelectionVacancyMapper = RecruitmentSelectionVacancyMapper::getInstance($this->adapter);
|
1539 |
eleazar |
588 |
$vacancyMapper = $recruitmentSelectionVacancyMapper->fetchOneByUuid($uuid);
|
|
|
589 |
if (!$vacancyMapper) {
|
1384 |
efrain |
590 |
$data = [
|
|
|
591 |
'success' => false,
|
|
|
592 |
'data' => 'ERROR_RECORD_NOT_FOUND'
|
|
|
593 |
];
|
|
|
594 |
|
|
|
595 |
return new JsonModel($data);
|
|
|
596 |
}
|
|
|
597 |
|
1544 |
eleazar |
598 |
if ($vacancyMapper->company_id != $currentCompany->id) {
|
1384 |
efrain |
599 |
return new JsonModel([
|
|
|
600 |
'success' => false,
|
|
|
601 |
'data' => 'ERROR_UNAUTHORIZED'
|
|
|
602 |
]);
|
|
|
603 |
}
|
|
|
604 |
|
|
|
605 |
if ($request->isPost()) {
|
|
|
606 |
|
|
|
607 |
|
1539 |
eleazar |
608 |
$result = $recruitmentSelectionVacancyMapper->delete($vacancyMapper->id);
|
1384 |
efrain |
609 |
if ($result) {
|
1539 |
eleazar |
610 |
$this->logger->info('Se borro el formulario de reclutamiento ' . $vacancyMapper->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
|
1384 |
efrain |
611 |
|
|
|
612 |
$data = [
|
|
|
613 |
'success' => true,
|
|
|
614 |
'data' => 'LABEL_RECORD_DELETED'
|
|
|
615 |
];
|
|
|
616 |
} else {
|
|
|
617 |
|
|
|
618 |
$data = [
|
|
|
619 |
'success' => false,
|
1386 |
eleazar |
620 |
'data' => $recruitmentSelectionVacancyMapper->getError()
|
1384 |
efrain |
621 |
];
|
|
|
622 |
|
|
|
623 |
return new JsonModel($data);
|
|
|
624 |
}
|
|
|
625 |
} else {
|
|
|
626 |
$data = [
|
|
|
627 |
'success' => false,
|
|
|
628 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
629 |
];
|
|
|
630 |
|
|
|
631 |
return new JsonModel($data);
|
|
|
632 |
}
|
|
|
633 |
|
|
|
634 |
return new JsonModel($data);
|
|
|
635 |
}
|
15461 |
efrain |
636 |
|
|
|
637 |
|
|
|
638 |
|
|
|
639 |
public function serialize($jobDescription)
|
|
|
640 |
{
|
|
|
641 |
|
|
|
642 |
|
|
|
643 |
|
|
|
644 |
|
|
|
645 |
$behaviorMapper = BehaviorMapper::getInstance($this->adapter);
|
|
|
646 |
$competencyMapper = CompetencyMapper::getInstance($this->adapter);
|
|
|
647 |
$competencyTypeMapper = CompetencyTypeMapper::getInstance($this->adapter);
|
|
|
648 |
|
|
|
649 |
$competencyTypes = [];
|
|
|
650 |
$competencies = [];
|
|
|
651 |
$behaviors = [];
|
|
|
652 |
$competencies_selected = [];
|
|
|
653 |
$subordinates_selected = [];
|
|
|
654 |
|
|
|
655 |
$jobDescriptionCompetencyMapper = JobDescriptionCompetencyMapper::getInstance($this->adapter);
|
|
|
656 |
$jobDescriptionCompetencyBehaviorMapper = JobDescriptionCompetencyBehaviorMapper::getInstance($this->adapter);
|
|
|
657 |
|
|
|
658 |
$jobDescriptionCompetencies = $jobDescriptionCompetencyMapper->fetchAllByJobDescriptionId($jobDescription->id);
|
|
|
659 |
foreach($jobDescriptionCompetencies as $jobDescriptionCompetency)
|
|
|
660 |
{
|
|
|
661 |
|
|
|
662 |
if(isset($competencies[$jobDescriptionCompetency->competency_id])) {
|
|
|
663 |
$competency = $competencies[$jobDescriptionCompetency->competency_id];
|
|
|
664 |
} else {
|
|
|
665 |
|
|
|
666 |
$competency = $competencyMapper->fetchOne($jobDescriptionCompetency->competency_id);
|
|
|
667 |
if(!$competency) {
|
|
|
668 |
continue;
|
|
|
669 |
}
|
|
|
670 |
|
|
|
671 |
|
|
|
672 |
|
|
|
673 |
$competencies[$jobDescriptionCompetency->competency_id] = new \stdClass();
|
|
|
674 |
$competencies[$jobDescriptionCompetency->competency_id]->uuid = $competency->uuid;
|
|
|
675 |
$competencies[$jobDescriptionCompetency->competency_id]->name = $competency->name;
|
|
|
676 |
$competencies[$jobDescriptionCompetency->competency_id]->description = $competency->description;
|
|
|
677 |
|
|
|
678 |
}
|
|
|
679 |
|
|
|
680 |
|
|
|
681 |
if(isset($competencyTypes[$competency->competency_type_id])) {
|
|
|
682 |
$competencyType = $competencyTypes[$competency->competency_type_id];
|
|
|
683 |
} else {
|
|
|
684 |
|
|
|
685 |
$competencyType = $competencyTypeMapper->fetchOne($competency->competency_type_id);
|
|
|
686 |
if(!$competencyType) {
|
|
|
687 |
continue;
|
|
|
688 |
}
|
|
|
689 |
|
|
|
690 |
$competencyTypes[$competency->competency_type_id] = new \stdClass();
|
|
|
691 |
$competencyTypes[$competency->competency_type_id]->uuid = $competencyType->uuid;
|
|
|
692 |
$competencyTypes[$competency->competency_type_id]->name = $competencyType->name;
|
|
|
693 |
$competencyTypes[$competency->competency_type_id]->description = $competencyType->description;
|
|
|
694 |
|
|
|
695 |
}
|
|
|
696 |
|
|
|
697 |
$competency_selected = [
|
|
|
698 |
'uuid' => $competency->uuid,
|
|
|
699 |
'competency_type_uuid' => $competencyType->uuid,
|
|
|
700 |
'behaviors' => []
|
|
|
701 |
];
|
|
|
702 |
|
|
|
703 |
|
|
|
704 |
$jobDescriptionCompetencyBehaviors = $jobDescriptionCompetencyBehaviorMapper->fetchAllByJobDescriptionIdAndCompetencyId($jobDescriptionCompetency->job_description_id, $jobDescriptionCompetency->competency_id);
|
|
|
705 |
foreach($jobDescriptionCompetencyBehaviors as $jobDescriptionCompetencyBehavior)
|
|
|
706 |
{
|
|
|
707 |
|
|
|
708 |
|
|
|
709 |
if(isset($behaviors[$jobDescriptionCompetencyBehavior->behavior_id])) {
|
|
|
710 |
$behavior = $behaviors[$jobDescriptionCompetencyBehavior->behavior_id];
|
|
|
711 |
} else {
|
|
|
712 |
|
|
|
713 |
$behavior = $behaviorMapper->fetchOne($jobDescriptionCompetencyBehavior->behavior_id);
|
|
|
714 |
if(!$behavior) {
|
|
|
715 |
|
|
|
716 |
continue;
|
|
|
717 |
}
|
|
|
718 |
|
|
|
719 |
$behaviors[$jobDescriptionCompetencyBehavior->behavior_id] = new \stdClass();
|
|
|
720 |
$behaviors[$jobDescriptionCompetencyBehavior->behavior_id]->uuid = $behavior->uuid;
|
|
|
721 |
$behaviors[$jobDescriptionCompetencyBehavior->behavior_id]->description = $behavior->description;
|
|
|
722 |
|
|
|
723 |
}
|
|
|
724 |
|
|
|
725 |
|
|
|
726 |
|
|
|
727 |
|
|
|
728 |
array_push($competency_selected['behaviors'], ['uuid' => $behavior->uuid, 'level' => $jobDescriptionCompetencyBehavior->level]);
|
|
|
729 |
|
|
|
730 |
|
|
|
731 |
}
|
|
|
732 |
|
|
|
733 |
array_push($competencies_selected, $competency_selected);
|
|
|
734 |
|
|
|
735 |
|
|
|
736 |
|
|
|
737 |
}
|
|
|
738 |
|
|
|
739 |
|
|
|
740 |
$jobDescriptionMapper = JobDescriptionMapper::getInstance($this->adapter);
|
|
|
741 |
|
|
|
742 |
$jobDescriptionSubordinateMapper = JobDescriptionSubordinateMapper::getInstance($this->adapter);
|
|
|
743 |
$jobDescriptionSubordinates = $jobDescriptionSubordinateMapper->fetchAllByJobDescriptionIdTopLevel($jobDescription->id);
|
|
|
744 |
|
|
|
745 |
foreach($jobDescriptionSubordinates as $jobDescriptionSubordinate)
|
|
|
746 |
{
|
|
|
747 |
$jobDescriptionForSubordinate = $jobDescriptionMapper->fetchOne($jobDescriptionSubordinate->job_description_id_low_level);
|
|
|
748 |
if($jobDescriptionForSubordinate) {
|
|
|
749 |
array_push($subordinates_selected, ['uuid' => $jobDescriptionForSubordinate->uuid ]);
|
|
|
750 |
}
|
|
|
751 |
|
|
|
752 |
|
|
|
753 |
|
|
|
754 |
}
|
|
|
755 |
|
|
|
756 |
if($jobDescription->job_description_id_boss) {
|
|
|
757 |
|
|
|
758 |
$jobDescriptionBoss = $jobDescriptionMapper->fetchOne($jobDescription->job_description_id_boss);
|
|
|
759 |
if($jobDescriptionBoss) {
|
|
|
760 |
$job_description_id_boss = $jobDescriptionBoss->uuid;
|
|
|
761 |
}
|
|
|
762 |
} else {
|
|
|
763 |
$job_description_id_boss = '';
|
|
|
764 |
}
|
|
|
765 |
|
|
|
766 |
$content = [
|
|
|
767 |
'uuid' => $jobDescription->uuid,
|
|
|
768 |
'name' => $jobDescription->name,
|
|
|
769 |
'functions' => $jobDescription->functions,
|
|
|
770 |
'objectives' => $jobDescription->objectives,
|
|
|
771 |
'job_description_id_boss' => $job_description_id_boss,
|
|
|
772 |
'competency_types' => $competencyTypes,
|
|
|
773 |
'competencies' => $competencies,
|
|
|
774 |
'behaviors' => $behaviors,
|
|
|
775 |
'competencies_selected' => $competencies_selected,
|
|
|
776 |
'subordinates_selected' => $subordinates_selected,
|
|
|
777 |
|
|
|
778 |
];
|
|
|
779 |
|
|
|
780 |
return json_encode($content);
|
|
|
781 |
}
|
1384 |
efrain |
782 |
}
|