7218 |
eleazar |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
declare(strict_types=1);
|
|
|
4 |
|
|
|
5 |
namespace LeadersLinked\Controller;
|
|
|
6 |
|
|
|
7 |
use Laminas\Db\Adapter\AdapterInterface;
|
16768 |
efrain |
8 |
|
7218 |
eleazar |
9 |
use Laminas\Mvc\Controller\AbstractActionController;
|
|
|
10 |
use Laminas\Log\LoggerInterface;
|
|
|
11 |
use Laminas\View\Model\ViewModel;
|
|
|
12 |
use Laminas\View\Model\JsonModel;
|
|
|
13 |
use LeadersLinked\Library\Functions;
|
|
|
14 |
use LeadersLinked\Mapper\OrganizationalClimateMapper;
|
|
|
15 |
use LeadersLinked\Mapper\OrganizationalClimateFormMapper;
|
|
|
16 |
use LeadersLinked\Mapper\OrganizationalClimateJobDescriptionMapper;
|
|
|
17 |
use LeadersLinked\Mapper\OrganizationalClimateIndustryMapper;
|
|
|
18 |
use LeadersLinked\Mapper\OrganizationalClimateSkillMapper;
|
|
|
19 |
use LeadersLinked\Mapper\OrganizationalClimateLocationMapper;
|
|
|
20 |
use LeadersLinked\Mapper\OrganizationalClimateLanguageMapper;
|
|
|
21 |
use LeadersLinked\Model\Location;
|
|
|
22 |
use LeadersLinked\Mapper\LocationMapper;
|
|
|
23 |
use LeadersLinked\Mapper\IndustryMapper;
|
|
|
24 |
use LeadersLinked\Mapper\JobDescriptionMapper;
|
|
|
25 |
use LeadersLinked\Mapper\BehaviorMapper;
|
|
|
26 |
use LeadersLinked\Mapper\JobDescriptionBehaviorCompetencyMapper;
|
|
|
27 |
use LeadersLinked\Mapper\CompanyMapper;
|
|
|
28 |
use LeadersLinked\Mapper\LanguageMapper;
|
|
|
29 |
use LeadersLinked\Model\Company;
|
|
|
30 |
use LeadersLinked\Mapper\SkillMapper;
|
|
|
31 |
use LeadersLinked\Form\OrganizationalClimateSegmentedForm;
|
|
|
32 |
use LeadersLinked\Form\OrganizationalClimateForm;
|
|
|
33 |
use LeadersLinked\Model\OrganizationalClimate;
|
|
|
34 |
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
|
|
|
35 |
use LeadersLinked\Model\OrganizationalClimateJobDescription;
|
|
|
36 |
use LeadersLinked\Model\OrganizationalClimateSkill;
|
|
|
37 |
use LeadersLinked\Model\OrganizationalClimateIndustry;
|
|
|
38 |
use LeadersLinked\Model\OrganizationalClimateLanguage;
|
|
|
39 |
use LeadersLinked\Model\OrganizationalClimateLocation;
|
|
|
40 |
|
|
|
41 |
class OrganizationalClimateController extends AbstractActionController {
|
|
|
42 |
|
|
|
43 |
/**
|
|
|
44 |
*
|
16769 |
efrain |
45 |
* @var \Laminas\Db\Adapter\AdapterInterface
|
7218 |
eleazar |
46 |
*/
|
|
|
47 |
private $adapter;
|
16768 |
efrain |
48 |
|
7218 |
eleazar |
49 |
/**
|
|
|
50 |
*
|
16769 |
efrain |
51 |
* @var \LeadersLinked\Cache\CacheInterface
|
7218 |
eleazar |
52 |
*/
|
16769 |
efrain |
53 |
private $cache;
|
|
|
54 |
|
|
|
55 |
|
|
|
56 |
/**
|
|
|
57 |
*
|
|
|
58 |
* @var \Laminas\Log\LoggerInterface
|
|
|
59 |
*/
|
7218 |
eleazar |
60 |
private $logger;
|
16768 |
efrain |
61 |
|
7218 |
eleazar |
62 |
/**
|
|
|
63 |
*
|
|
|
64 |
* @var array
|
|
|
65 |
*/
|
|
|
66 |
private $config;
|
16768 |
efrain |
67 |
|
16769 |
efrain |
68 |
|
7218 |
eleazar |
69 |
/**
|
|
|
70 |
*
|
16769 |
efrain |
71 |
* @var \Laminas\Mvc\I18n\Translator
|
|
|
72 |
*/
|
|
|
73 |
private $translator;
|
|
|
74 |
|
|
|
75 |
|
|
|
76 |
/**
|
|
|
77 |
*
|
|
|
78 |
* @param \Laminas\Db\Adapter\AdapterInterface $adapter
|
|
|
79 |
* @param \LeadersLinked\Cache\CacheInterface $cache
|
|
|
80 |
* @param \Laminas\Log\LoggerInterface LoggerInterface $logger
|
7218 |
eleazar |
81 |
* @param array $config
|
16769 |
efrain |
82 |
* @param \Laminas\Mvc\I18n\Translator $translator
|
7218 |
eleazar |
83 |
*/
|
16769 |
efrain |
84 |
public function __construct($adapter, $cache, $logger, $config, $translator)
|
16768 |
efrain |
85 |
{
|
16769 |
efrain |
86 |
$this->adapter = $adapter;
|
|
|
87 |
$this->cache = $cache;
|
|
|
88 |
$this->logger = $logger;
|
|
|
89 |
$this->config = $config;
|
|
|
90 |
$this->translator = $translator;
|
7218 |
eleazar |
91 |
}
|
|
|
92 |
|
|
|
93 |
public function indexAction() {
|
|
|
94 |
$request = $this->getRequest();
|
|
|
95 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
96 |
$currentCompany = $currentUserPlugin->getCompany();
|
|
|
97 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
98 |
|
|
|
99 |
|
|
|
100 |
$request = $this->getRequest();
|
|
|
101 |
if ($request->isGet()) {
|
|
|
102 |
$sandbox = $this->config['leaderslinked.runmode.sandbox'];
|
|
|
103 |
if($sandbox) {
|
|
|
104 |
$google_map_key = $this->config['leaderslinked.google_map.sandbox_api_key'];
|
|
|
105 |
} else {
|
|
|
106 |
$google_map_key = $this->config['leaderslinked.google_map.production_api_key'];
|
|
|
107 |
}
|
|
|
108 |
|
|
|
109 |
$headers = $request->getHeaders();
|
|
|
110 |
|
|
|
111 |
$isJson = false;
|
|
|
112 |
if ($headers->has('Accept')) {
|
|
|
113 |
$accept = $headers->get('Accept');
|
|
|
114 |
|
|
|
115 |
$prioritized = $accept->getPrioritized();
|
|
|
116 |
|
|
|
117 |
foreach ($prioritized as $key => $value) {
|
|
|
118 |
$raw = trim($value->getRaw());
|
|
|
119 |
|
|
|
120 |
if (!$isJson) {
|
|
|
121 |
$isJson = strpos($raw, 'json');
|
|
|
122 |
}
|
|
|
123 |
}
|
|
|
124 |
}
|
|
|
125 |
|
|
|
126 |
if ($isJson) {
|
|
|
127 |
$search = $this->params()->fromQuery('search', []);
|
16766 |
efrain |
128 |
$search = empty($search['value']) ? '' : Functions::sanitizeFilterString($search['value']);
|
7218 |
eleazar |
129 |
|
15371 |
efrain |
130 |
$start = intval($this->params()->fromQuery('start', 0), 10);
|
7218 |
eleazar |
131 |
$records_x_page = intval($this->params()->fromQuery('length', 10), 10);
|
15371 |
efrain |
132 |
$page = intval($start / $records_x_page);
|
|
|
133 |
$page++;
|
|
|
134 |
|
7218 |
eleazar |
135 |
$order = $this->params()->fromQuery('order', []);
|
|
|
136 |
$order_field = empty($order[0]['column']) ? 99 : intval($order[0]['column'], 10);
|
16766 |
efrain |
137 |
$order_direction = empty($order[0]['dir']) ? 'ASC' : Functions::sanitizeFilterString(filter_var($order[0]['dir']));
|
7218 |
eleazar |
138 |
|
|
|
139 |
$fields = ['name'];
|
|
|
140 |
$order_field = isset($fields[$order_field]) ? $fields[$order_field] : 'name';
|
|
|
141 |
|
|
|
142 |
if (!in_array($order_direction, ['ASC', 'DESC'])) {
|
|
|
143 |
$order_direction = 'ASC';
|
|
|
144 |
}
|
|
|
145 |
|
|
|
146 |
$acl = $this->getEvent()->getViewModel()->getVariable('acl');
|
|
|
147 |
$allowAdd = $acl->isAllowed($currentUser->usertype_id, 'organizational-climate/add');
|
|
|
148 |
$allowEdit = $acl->isAllowed($currentUser->usertype_id, 'organizational-climate/edit');
|
|
|
149 |
$allowDelete = $acl->isAllowed($currentUser->usertype_id, 'organizational-climate/delete');
|
|
|
150 |
$allowSegment = $acl->isAllowed($currentUser->usertype_id, 'organizational-climate/segment');
|
|
|
151 |
|
|
|
152 |
$organizationalClimateMapper = OrganizationalClimateMapper::getInstance($this->adapter);
|
|
|
153 |
$paginator = $organizationalClimateMapper->fetchAllDataTableByCompanyId($currentCompany->id, $search, $page, $records_x_page, $order_field, $order_direction);
|
|
|
154 |
|
|
|
155 |
$items = [];
|
|
|
156 |
$records = $paginator->getCurrentItems();
|
|
|
157 |
|
|
|
158 |
foreach ($records as $record) {
|
|
|
159 |
$organizationalClimateFormMapper = OrganizationalClimateFormMapper::getInstance($this->adapter);
|
|
|
160 |
$organizationalClimateForm = $organizationalClimateFormMapper->fetchOne($record->form_id);
|
|
|
161 |
|
|
|
162 |
$item = [
|
|
|
163 |
'id' => $record->id,
|
|
|
164 |
'name' => $record->name,
|
|
|
165 |
'form' => $organizationalClimateForm->name,
|
|
|
166 |
'status' => $record->status,
|
|
|
167 |
'actions' => [
|
|
|
168 |
'link_edit' => $this->url()->fromRoute('organizational-climate/edit', ['id' => $record->uuid]),
|
|
|
169 |
'link_delete' => $this->url()->fromRoute('organizational-climate/delete', ['id' => $record->uuid]),
|
|
|
170 |
'link_segment' => $this->url()->fromRoute('organizational-climate/segment', ['id' => $record->uuid])
|
|
|
171 |
]
|
|
|
172 |
];
|
|
|
173 |
|
|
|
174 |
array_push($items, $item);
|
|
|
175 |
}
|
|
|
176 |
|
|
|
177 |
return new JsonModel([
|
|
|
178 |
'success' => true,
|
|
|
179 |
'data' => [
|
|
|
180 |
'items' => $items,
|
|
|
181 |
'total' => $paginator->getTotalItemCount(),
|
|
|
182 |
]
|
|
|
183 |
]);
|
|
|
184 |
} else {
|
|
|
185 |
|
|
|
186 |
$form = new OrganizationalClimateForm($this->adapter, $currentCompany->id);
|
|
|
187 |
|
|
|
188 |
$this->layout()->setTemplate('layout/layout-backend');
|
|
|
189 |
$viewModel = new ViewModel();
|
|
|
190 |
$viewModel->setTemplate('leaders-linked/organizational-climate/index.phtml');
|
|
|
191 |
$viewModel->setVariable('form', $form);
|
|
|
192 |
$viewModel->setVariable('google_map_key', $google_map_key);
|
|
|
193 |
return $viewModel;
|
|
|
194 |
}
|
|
|
195 |
} else {
|
|
|
196 |
return new JsonModel([
|
|
|
197 |
'success' => false,
|
|
|
198 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
199 |
]);
|
|
|
200 |
}
|
|
|
201 |
}
|
|
|
202 |
|
|
|
203 |
public function addAction() {
|
|
|
204 |
$request = $this->getRequest();
|
|
|
205 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
206 |
$currentCompany = $currentUserPlugin->getCompany();
|
|
|
207 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
208 |
|
|
|
209 |
$request = $this->getRequest();
|
|
|
210 |
|
|
|
211 |
if ($request->isPost()) {
|
|
|
212 |
|
|
|
213 |
$form = new OrganizationalClimateForm($this->adapter, $currentCompany->id);
|
|
|
214 |
|
|
|
215 |
$dataPost = $request->getPost()->toArray();
|
|
|
216 |
$dataPost['status'] = isset($dataPost['status']) ? $dataPost['status'] : OrganizationalClimateForm::STATUS_INACTIVE;
|
|
|
217 |
|
|
|
218 |
|
|
|
219 |
if($dataPost['since_date'] > $dataPost['last_date']){
|
|
|
220 |
new JsonModel([
|
|
|
221 |
'success' => false,
|
|
|
222 |
'data' => 'ERROR_UNAUTHORIZED'
|
|
|
223 |
]);
|
|
|
224 |
}
|
|
|
225 |
|
|
|
226 |
$form->setData($dataPost);
|
|
|
227 |
|
|
|
228 |
if ($form->isValid()) {
|
|
|
229 |
$dataPost = (array) $form->getData();
|
|
|
230 |
|
|
|
231 |
$hydrator = new ObjectPropertyHydrator();
|
|
|
232 |
|
|
|
233 |
$organizationalClimate = new OrganizationalClimate();
|
|
|
234 |
$hydrator->hydrate($dataPost, $organizationalClimate);
|
|
|
235 |
|
|
|
236 |
if (!$organizationalClimate->status) {
|
|
|
237 |
$organizationalClimate->status = OrganizationalClimate::STATUS_INACTIVE;
|
|
|
238 |
}
|
|
|
239 |
$organizationalClimate->company_id = $currentCompany->id;
|
|
|
240 |
|
|
|
241 |
$organizationalClimateFormMapper = OrganizationalClimateFormMapper::getInstance($this->adapter);
|
|
|
242 |
$organizationalClimateForm = $organizationalClimateFormMapper->fetchOneByUuid($dataPost['form_id']);
|
|
|
243 |
$organizationalClimate->form_id = $organizationalClimateForm->id;
|
|
|
244 |
|
|
|
245 |
$organizationalClimateMapper = OrganizationalClimateMapper::getInstance($this->adapter);
|
|
|
246 |
//$result = $organizationalClimateMapper->insert($organizationalClimate);
|
|
|
247 |
|
|
|
248 |
if($organizationalClimateMapper->insert($organizationalClimate)) {
|
|
|
249 |
$organizationalClimate = $organizationalClimateMapper->fetchOne($organizationalClimate->id);
|
|
|
250 |
|
|
|
251 |
$jobDescription = new OrganizationalClimateJobDescription();
|
|
|
252 |
$skill = new OrganizationalClimateSkill();
|
|
|
253 |
$industry = new OrganizationalClimateIndustry();
|
|
|
254 |
$language = new OrganizationalClimateLanguage();
|
|
|
255 |
|
|
|
256 |
if(!empty($dataPost['location_search'])){
|
|
|
257 |
|
|
|
258 |
$organizationalClimateLocationMapper = OrganizationalClimateLocationMapper::getInstance($this->adapter);
|
|
|
259 |
|
|
|
260 |
$ok = true;
|
|
|
261 |
|
|
|
262 |
$formatted_address = $dataPost['formatted_address'];
|
|
|
263 |
$city1 = $dataPost['city1'];
|
|
|
264 |
$city2 = $dataPost['city2'];
|
|
|
265 |
$address1 = $dataPost['address1'];
|
|
|
266 |
$address2 = $dataPost['address2'];
|
|
|
267 |
$country = $dataPost['country'];
|
|
|
268 |
$latitude = $dataPost['latitude'];
|
|
|
269 |
$longitude = $dataPost['longitude'];
|
|
|
270 |
$postal_code = $dataPost['postal_code'];
|
|
|
271 |
$state = $dataPost['state'];
|
|
|
272 |
|
|
|
273 |
|
|
|
274 |
$record = new OrganizationalClimateLocation();
|
|
|
275 |
$record->formatted_address = $formatted_address;
|
|
|
276 |
$record->city1 = $city1;
|
|
|
277 |
$record->city2 = $city2;
|
|
|
278 |
$record->address1 = $address1;
|
|
|
279 |
$record->address2 = $address2;
|
|
|
280 |
$record->country = $country;
|
|
|
281 |
$record->latitude = $latitude;
|
|
|
282 |
$record->longitude = $longitude;
|
|
|
283 |
$record->postal_code = $postal_code;
|
|
|
284 |
$record->state = $state;
|
12997 |
efrain |
285 |
$record->organizational_climate_id = $organizationalClimate->id;
|
7218 |
eleazar |
286 |
$result = $organizationalClimateLocationMapper->insert($record);
|
|
|
287 |
$ok = $ok && $result;
|
|
|
288 |
//}
|
|
|
289 |
if($ok){
|
|
|
290 |
|
|
|
291 |
}
|
|
|
292 |
}
|
|
|
293 |
|
|
|
294 |
if(!empty($dataPost['job_description_id'])){
|
|
|
295 |
|
|
|
296 |
// print_r($dataPost['job_description_id']);
|
|
|
297 |
|
|
|
298 |
$jobDescriptionMapper = JobDescriptionMapper::getInstance($this->adapter);
|
|
|
299 |
$organizationalClimateJobDescriptionMapper = OrganizationalClimateJobDescriptionMapper::getInstance($this->adapter);
|
|
|
300 |
|
|
|
301 |
$ok = true;
|
|
|
302 |
|
|
|
303 |
foreach($dataPost['job_description_id'] as $jobDescriptionUuid) {
|
|
|
304 |
|
|
|
305 |
// echo '$jobDescriptionUuid = ' . $jobDescriptionUuid ;
|
|
|
306 |
|
|
|
307 |
|
|
|
308 |
$jobDescription = $jobDescriptionMapper->fetchOneByUuid($jobDescriptionUuid);
|
|
|
309 |
|
|
|
310 |
// print_r($jobDescription);
|
|
|
311 |
//print_r($currentCompany);
|
|
|
312 |
|
|
|
313 |
if($jobDescription && $jobDescription->company_id == $currentCompany->id) {
|
|
|
314 |
$record = new OrganizationalClimateJobDescription();
|
|
|
315 |
$record->job_description_id = $jobDescription->id;
|
12997 |
efrain |
316 |
$record->organizational_climate_id = $organizationalClimate->id;
|
7218 |
eleazar |
317 |
|
|
|
318 |
|
|
|
319 |
|
|
|
320 |
$result = $organizationalClimateJobDescriptionMapper->insert($record);
|
|
|
321 |
$ok = $ok && $result;
|
|
|
322 |
}
|
|
|
323 |
}
|
|
|
324 |
|
|
|
325 |
if($ok){
|
|
|
326 |
|
|
|
327 |
}
|
|
|
328 |
}
|
|
|
329 |
|
|
|
330 |
$data = [
|
|
|
331 |
'success' => true,
|
|
|
332 |
'data' => 'LABEL_RECORD_ADDED'
|
|
|
333 |
];
|
|
|
334 |
// return new JsonModel($data);
|
|
|
335 |
|
|
|
336 |
if(!empty($dataPost['skill_id'])){
|
|
|
337 |
|
|
|
338 |
// print_r($dataPost['skill_id']);
|
|
|
339 |
|
|
|
340 |
$skillMapper = SkillMapper::getInstance($this->adapter);
|
|
|
341 |
$organizationalClimateSkillMapper = OrganizationalClimateSkillMapper::getInstance($this->adapter);
|
|
|
342 |
|
|
|
343 |
$ok = true;
|
|
|
344 |
|
|
|
345 |
foreach($dataPost['skill_id'] as $skillUuid) {
|
|
|
346 |
|
|
|
347 |
// echo '$jobCategoryUuid = ' . $jobCategoryUuid ;
|
|
|
348 |
|
|
|
349 |
|
|
|
350 |
$skill = $skillMapper->fetchOneByUuid($skillUuid);
|
|
|
351 |
|
|
|
352 |
// print_r($skill);
|
|
|
353 |
//print_r($currentCompany);
|
|
|
354 |
|
|
|
355 |
//if($skill && $skill->company_id == $currentCompany->id) {
|
|
|
356 |
$record = new OrganizationalClimateSkill();
|
|
|
357 |
$record->skill_id = $skill->id;
|
12997 |
efrain |
358 |
$record->organizational_climate_id = $organizationalClimate->id;
|
7218 |
eleazar |
359 |
|
|
|
360 |
|
|
|
361 |
$result = $organizationalClimateSkillMapper->insert($record);
|
|
|
362 |
$ok = $ok && $result;
|
|
|
363 |
// }
|
|
|
364 |
}
|
|
|
365 |
|
|
|
366 |
if($ok){
|
|
|
367 |
|
|
|
368 |
}
|
|
|
369 |
}
|
|
|
370 |
|
|
|
371 |
$data = [
|
|
|
372 |
'success' => true,
|
|
|
373 |
'data' => 'test'
|
|
|
374 |
];
|
|
|
375 |
// return new JsonModel($data); exit;
|
|
|
376 |
|
|
|
377 |
if(!empty($dataPost['industry_id'])){
|
|
|
378 |
|
|
|
379 |
// print_r($dataPost['industry_id']);
|
|
|
380 |
|
|
|
381 |
$industryMapper = IndustryMapper::getInstance($this->adapter);
|
|
|
382 |
$organizationalClimateIndustryMapper = OrganizationalClimateIndustryMapper::getInstance($this->adapter);
|
|
|
383 |
|
|
|
384 |
$ok = true;
|
|
|
385 |
|
|
|
386 |
foreach($dataPost['industry_id'] as $industryUuid) {
|
|
|
387 |
|
|
|
388 |
// echo '$industryUuid = ' . $industryUuid ;
|
|
|
389 |
|
|
|
390 |
|
|
|
391 |
$industry = $industryMapper->fetchOneByUuid($industryUuid);
|
|
|
392 |
|
|
|
393 |
// print_r($industry);
|
|
|
394 |
//print_r($currentCompany);
|
|
|
395 |
|
|
|
396 |
//if($industry && $industry->company_id == $currentCompany->id) {
|
|
|
397 |
$record = new OrganizationalClimateIndustry();
|
|
|
398 |
$record->industry_id = $industry->id;
|
12997 |
efrain |
399 |
$record->organizational_climate_id = $organizationalClimate->id;
|
7218 |
eleazar |
400 |
|
|
|
401 |
|
|
|
402 |
|
|
|
403 |
$result = $organizationalClimateIndustryMapper->insert($record);
|
|
|
404 |
$ok = $ok && $result;
|
|
|
405 |
//}
|
|
|
406 |
}
|
|
|
407 |
|
|
|
408 |
if($ok){
|
|
|
409 |
|
|
|
410 |
}
|
|
|
411 |
}
|
|
|
412 |
|
|
|
413 |
$data = [
|
|
|
414 |
'success' => true,
|
|
|
415 |
'data' => 'test industry'
|
|
|
416 |
];
|
|
|
417 |
// return new JsonModel($data); exit;
|
|
|
418 |
|
|
|
419 |
if(!empty($dataPost['language_id'])){
|
|
|
420 |
|
|
|
421 |
$organizationalClimateLanguageMapper = OrganizationalClimateLanguageMapper::getInstance($this->adapter);
|
|
|
422 |
|
|
|
423 |
$ok = true;
|
|
|
424 |
|
|
|
425 |
foreach($dataPost['language_id'] as $language_id) {
|
|
|
426 |
|
|
|
427 |
$record = new OrganizationalClimateLanguage();
|
|
|
428 |
$record->language_id = $language_id;
|
12997 |
efrain |
429 |
$record->organizational_climate_id = $organizationalClimate->id;
|
7218 |
eleazar |
430 |
|
|
|
431 |
|
|
|
432 |
$result = $organizationalClimateLanguageMapper->insert($record);
|
|
|
433 |
$ok = $ok && $result;
|
|
|
434 |
//}
|
|
|
435 |
}
|
|
|
436 |
if($ok){
|
|
|
437 |
|
|
|
438 |
}
|
|
|
439 |
}
|
|
|
440 |
|
|
|
441 |
$data = [
|
|
|
442 |
'success' => true,
|
|
|
443 |
'data' => 'LABEL_RECORD_ADDED'
|
|
|
444 |
];
|
|
|
445 |
|
|
|
446 |
} else {
|
|
|
447 |
$data = [
|
|
|
448 |
'success' => false,
|
|
|
449 |
'data' => $organizationalClimateMapper->getError()
|
|
|
450 |
];
|
|
|
451 |
}
|
|
|
452 |
|
|
|
453 |
|
|
|
454 |
return new JsonModel($data);
|
|
|
455 |
} else {
|
|
|
456 |
$messages = [];
|
|
|
457 |
$form_messages = (array) $form->getMessages();
|
|
|
458 |
foreach ($form_messages as $fieldname => $field_messages) {
|
|
|
459 |
|
|
|
460 |
$messages[$fieldname] = array_values($field_messages);
|
|
|
461 |
}
|
|
|
462 |
|
|
|
463 |
return new JsonModel([
|
|
|
464 |
'success' => false,
|
|
|
465 |
'data' => $messages
|
|
|
466 |
]);
|
|
|
467 |
}
|
|
|
468 |
} else {
|
|
|
469 |
$data = [
|
|
|
470 |
'success' => false,
|
|
|
471 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
472 |
];
|
|
|
473 |
|
|
|
474 |
return new JsonModel($data);
|
|
|
475 |
}
|
|
|
476 |
|
|
|
477 |
return new JsonModel($data);
|
|
|
478 |
}
|
|
|
479 |
|
|
|
480 |
public function segmentAction() {
|
|
|
481 |
$request = $this->getRequest();
|
|
|
482 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
483 |
$currentCompany = $currentUserPlugin->getCompany();
|
|
|
484 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
485 |
|
|
|
486 |
$request = $this->getRequest();
|
|
|
487 |
$uuid = $this->params()->fromRoute('id');
|
|
|
488 |
|
|
|
489 |
|
|
|
490 |
if (!$uuid) {
|
|
|
491 |
$data = [
|
|
|
492 |
'success' => false,
|
|
|
493 |
'data' => 'ERROR_INVALID_PARAMETER'
|
|
|
494 |
];
|
|
|
495 |
|
|
|
496 |
return new JsonModel($data);
|
|
|
497 |
}
|
|
|
498 |
|
|
|
499 |
$organizationalClimateMapper = OrganizationalClimateMapper::getInstance($this->adapter);
|
|
|
500 |
$organizationalClimate = $organizationalClimateMapper->fetchOneByUuid($uuid);
|
|
|
501 |
if (!$organizationalClimate) {
|
|
|
502 |
$data = [
|
|
|
503 |
'success' => false,
|
|
|
504 |
'data' => 'ERROR_RECORD_NOT_FOUND'
|
|
|
505 |
];
|
|
|
506 |
|
|
|
507 |
return new JsonModel($data);
|
|
|
508 |
}
|
|
|
509 |
|
|
|
510 |
if ($organizationalClimate->company_id != $currentCompany->id) {
|
|
|
511 |
return new JsonModel([
|
|
|
512 |
'success' => false,
|
|
|
513 |
'data' => 'ERROR_UNAUTHORIZED'
|
|
|
514 |
]);
|
|
|
515 |
}
|
|
|
516 |
|
|
|
517 |
if($request->isPost()){
|
|
|
518 |
$form = new OrganizationalClimateSegmentedForm($this->adapter, $currentCompany->id);
|
|
|
519 |
|
|
|
520 |
|
|
|
521 |
$dataPost = $request->getPost()->toArray();
|
|
|
522 |
$form->setData($dataPost);
|
|
|
523 |
|
|
|
524 |
|
|
|
525 |
|
|
|
526 |
if ($form->isValid()) {
|
|
|
527 |
$dataPost = (array) $form->getData();
|
|
|
528 |
|
|
|
529 |
/*
|
|
|
530 |
|
|
|
531 |
$location = new Location();
|
|
|
532 |
$hydrator->hydrate($dataPost, $location);
|
|
|
533 |
|
|
|
534 |
$locationMapper= LocationMapper::getInstance($this->adapter);
|
|
|
535 |
$resultLocation = $locationMapper->insert($location);
|
|
|
536 |
|
|
|
537 |
if (!$resultLocation) {
|
|
|
538 |
return new JsonModel([
|
|
|
539 |
'success' => false,
|
|
|
540 |
'data' => 'ERROR_THERE_WAS_AN_ERROR'
|
|
|
541 |
]);
|
|
|
542 |
}
|
|
|
543 |
*/
|
|
|
544 |
|
|
|
545 |
$jobDescription = new OrganizationalClimateJobDescription();
|
|
|
546 |
$skill = new OrganizationalClimateSkill();
|
|
|
547 |
$industry = new OrganizationalClimateIndustry();
|
|
|
548 |
$language = new OrganizationalClimateLanguage();
|
|
|
549 |
|
|
|
550 |
if(!empty($dataPost['job_description_id'])){
|
|
|
551 |
|
|
|
552 |
// print_r($dataPost['job_description_id']);
|
|
|
553 |
|
|
|
554 |
$jobDescriptionMapper = JobDescriptionMapper::getInstance($this->adapter);
|
|
|
555 |
$organizationalClimateJobDescriptionMapper = OrganizationalClimateJobDescriptionMapper::getInstance($this->adapter);
|
|
|
556 |
|
|
|
557 |
$ok = true;
|
|
|
558 |
|
|
|
559 |
foreach($dataPost['job_description_id'] as $jobDescriptionUuid) {
|
|
|
560 |
|
|
|
561 |
// echo '$jobDescriptionUuid = ' . $jobDescriptionUuid ;
|
|
|
562 |
|
|
|
563 |
|
|
|
564 |
$jobDescription = $jobDescriptionMapper->fetchOneByUuid($jobDescriptionUuid);
|
|
|
565 |
|
|
|
566 |
// print_r($jobDescription);
|
|
|
567 |
//print_r($currentCompany);
|
|
|
568 |
|
|
|
569 |
if($jobDescription && $jobDescription->company_id == $currentCompany->id) {
|
|
|
570 |
$record = new OrganizationalClimateJobDescription();
|
|
|
571 |
$record->job_description_id = $jobDescription->id;
|
12997 |
efrain |
572 |
$record->organizational_climate_id = $organizationalClimate->id;
|
7218 |
eleazar |
573 |
|
|
|
574 |
|
|
|
575 |
|
|
|
576 |
$result = $organizationalClimateJobDescriptionMapper->insert($record);
|
|
|
577 |
$ok = $ok && $result;
|
|
|
578 |
}
|
|
|
579 |
}
|
|
|
580 |
|
|
|
581 |
if($ok){
|
|
|
582 |
|
|
|
583 |
}
|
|
|
584 |
}
|
|
|
585 |
|
|
|
586 |
$data = [
|
|
|
587 |
'success' => true,
|
|
|
588 |
'data' => 'LABEL_RECORD_ADDED'
|
|
|
589 |
];
|
|
|
590 |
// return new JsonModel($data);
|
|
|
591 |
|
|
|
592 |
if(!empty($dataPost['skill_id'])){
|
|
|
593 |
|
|
|
594 |
// print_r($dataPost['skill_id']);
|
|
|
595 |
|
|
|
596 |
$skillMapper = SkillMapper::getInstance($this->adapter);
|
|
|
597 |
$organizationalClimateSkillMapper = OrganizationalClimateSkillMapper::getInstance($this->adapter);
|
|
|
598 |
|
|
|
599 |
$ok = true;
|
|
|
600 |
|
|
|
601 |
foreach($dataPost['skill_id'] as $skillUuid) {
|
|
|
602 |
|
|
|
603 |
// echo '$jobCategoryUuid = ' . $jobCategoryUuid ;
|
|
|
604 |
|
|
|
605 |
|
|
|
606 |
$skill = $skillMapper->fetchOneByUuid($skillUuid);
|
|
|
607 |
|
|
|
608 |
// print_r($skill);
|
|
|
609 |
//print_r($currentCompany);
|
|
|
610 |
|
|
|
611 |
//if($skill && $skill->company_id == $currentCompany->id) {
|
|
|
612 |
$record = new OrganizationalClimateSkill();
|
|
|
613 |
$record->skill_id = $skill->id;
|
12997 |
efrain |
614 |
$record->organizational_climate_id = $organizationalClimate->id;
|
7218 |
eleazar |
615 |
|
|
|
616 |
|
|
|
617 |
$result = $organizationalClimateSkillMapper->insert($record);
|
|
|
618 |
$ok = $ok && $result;
|
|
|
619 |
// }
|
|
|
620 |
}
|
|
|
621 |
|
|
|
622 |
if($ok){
|
|
|
623 |
|
|
|
624 |
}
|
|
|
625 |
}
|
|
|
626 |
|
|
|
627 |
$data = [
|
|
|
628 |
'success' => true,
|
|
|
629 |
'data' => 'test'
|
|
|
630 |
];
|
|
|
631 |
// return new JsonModel($data); exit;
|
|
|
632 |
|
|
|
633 |
if(!empty($dataPost['industry_id'])){
|
|
|
634 |
|
|
|
635 |
// print_r($dataPost['industry_id']);
|
|
|
636 |
|
|
|
637 |
$industryMapper = IndustryMapper::getInstance($this->adapter);
|
|
|
638 |
$organizationalClimateIndustryMapper = OrganizationalClimateIndustryMapper::getInstance($this->adapter);
|
|
|
639 |
|
|
|
640 |
$ok = true;
|
|
|
641 |
|
|
|
642 |
foreach($dataPost['industry_id'] as $industryUuid) {
|
|
|
643 |
|
|
|
644 |
// echo '$industryUuid = ' . $industryUuid ;
|
|
|
645 |
|
|
|
646 |
|
|
|
647 |
$industry = $industryMapper->fetchOneByUuid($industryUuid);
|
|
|
648 |
|
|
|
649 |
// print_r($industry);
|
|
|
650 |
//print_r($currentCompany);
|
|
|
651 |
|
|
|
652 |
//if($industry && $industry->company_id == $currentCompany->id) {
|
|
|
653 |
$record = new OrganizationalClimateIndustry();
|
|
|
654 |
$record->industry_id = $industry->id;
|
12997 |
efrain |
655 |
$record->organizational_climate_id = $organizationalClimate->id;
|
7218 |
eleazar |
656 |
|
|
|
657 |
|
|
|
658 |
|
|
|
659 |
$result = $organizationalClimateIndustryMapper->insert($record);
|
|
|
660 |
$ok = $ok && $result;
|
|
|
661 |
//}
|
|
|
662 |
}
|
|
|
663 |
|
|
|
664 |
if($ok){
|
|
|
665 |
|
|
|
666 |
}
|
|
|
667 |
}
|
|
|
668 |
|
|
|
669 |
$data = [
|
|
|
670 |
'success' => true,
|
|
|
671 |
'data' => 'test industry'
|
|
|
672 |
];
|
|
|
673 |
// return new JsonModel($data); exit;
|
|
|
674 |
|
|
|
675 |
if(!empty($dataPost['language_id'])){
|
|
|
676 |
|
|
|
677 |
$organizationalClimateLanguageMapper = OrganizationalClimateLanguageMapper::getInstance($this->adapter);
|
|
|
678 |
|
|
|
679 |
$ok = true;
|
|
|
680 |
|
|
|
681 |
foreach($dataPost['language_id'] as $language_id) {
|
|
|
682 |
|
|
|
683 |
$record = new OrganizationalClimateLanguage();
|
|
|
684 |
$record->language_id = $language_id;
|
12997 |
efrain |
685 |
$record->organizational_climate_id = $organizationalClimate->id;
|
7218 |
eleazar |
686 |
|
|
|
687 |
|
|
|
688 |
$result = $organizationalClimateLanguageMapper->insert($record);
|
|
|
689 |
$ok = $ok && $result;
|
|
|
690 |
//}
|
|
|
691 |
}
|
|
|
692 |
if($ok){
|
|
|
693 |
|
|
|
694 |
}
|
|
|
695 |
}
|
|
|
696 |
|
|
|
697 |
$data = [
|
|
|
698 |
'success' => true,
|
|
|
699 |
'data' => 'LABEL_RECORD_ADDED'
|
|
|
700 |
];
|
|
|
701 |
// return new JsonModel($data); exit;
|
|
|
702 |
|
|
|
703 |
// return new JsonModel($data);
|
|
|
704 |
} else {
|
|
|
705 |
$messages = [];
|
|
|
706 |
$form_messages = (array) $form->getMessages();
|
|
|
707 |
foreach ($form_messages as $fieldname => $field_messages) {
|
|
|
708 |
|
|
|
709 |
$messages[$fieldname] = array_values($field_messages);
|
|
|
710 |
}
|
|
|
711 |
|
|
|
712 |
return new JsonModel([
|
|
|
713 |
'success' => false,
|
|
|
714 |
'data' => $messages
|
|
|
715 |
]);
|
|
|
716 |
}
|
|
|
717 |
} else {
|
|
|
718 |
$data = [
|
|
|
719 |
'success' => false,
|
|
|
720 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
721 |
];
|
|
|
722 |
|
|
|
723 |
return new JsonModel($data);
|
|
|
724 |
}
|
|
|
725 |
|
|
|
726 |
return new JsonModel($data);
|
|
|
727 |
|
|
|
728 |
}
|
|
|
729 |
|
|
|
730 |
public function editAction() {
|
|
|
731 |
$request = $this->getRequest();
|
|
|
732 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
733 |
$currentCompany = $currentUserPlugin->getCompany();
|
|
|
734 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
735 |
|
|
|
736 |
$request = $this->getRequest();
|
|
|
737 |
$uuid = $this->params()->fromRoute('id');
|
|
|
738 |
|
|
|
739 |
|
|
|
740 |
if (!$uuid) {
|
|
|
741 |
$data = [
|
|
|
742 |
'success' => false,
|
|
|
743 |
'data' => 'ERROR_INVALID_PARAMETER'
|
|
|
744 |
];
|
|
|
745 |
|
|
|
746 |
return new JsonModel($data);
|
|
|
747 |
}
|
|
|
748 |
|
|
|
749 |
$organizationalClimateMapper = OrganizationalClimateMapper::getInstance($this->adapter);
|
|
|
750 |
$organizationalClimate = $organizationalClimateMapper->fetchOneByUuid($uuid);
|
|
|
751 |
|
|
|
752 |
if (!$organizationalClimate) {
|
|
|
753 |
$data = [
|
|
|
754 |
'success' => false,
|
|
|
755 |
'data' => 'ERROR_RECORD_NOT_FOUND'
|
|
|
756 |
];
|
|
|
757 |
|
|
|
758 |
return new JsonModel($data);
|
|
|
759 |
}
|
|
|
760 |
|
|
|
761 |
if ($organizationalClimate->company_id != $currentCompany->id) {
|
|
|
762 |
return new JsonModel([
|
|
|
763 |
'success' => false,
|
|
|
764 |
'data' => 'ERROR_UNAUTHORIZED'
|
|
|
765 |
]);
|
|
|
766 |
}
|
|
|
767 |
|
|
|
768 |
|
|
|
769 |
if ($request->isPost()) {
|
|
|
770 |
$form = new OrganizationalClimateForm($this->adapter, $currentCompany->id);
|
|
|
771 |
$dataPost = $request->getPost()->toArray();
|
|
|
772 |
$dataPost['status'] = isset($dataPost['status']) ? $dataPost['status'] : OrganizationalClimateForm::STATUS_INACTIVE;
|
|
|
773 |
|
|
|
774 |
$form->setData($dataPost);
|
|
|
775 |
|
|
|
776 |
if ($form->isValid()) {
|
|
|
777 |
$dataPost = (array) $form->getData();
|
|
|
778 |
|
|
|
779 |
$hydrator = new ObjectPropertyHydrator();
|
|
|
780 |
$hydrator->hydrate($dataPost, $organizationalClimate);
|
|
|
781 |
|
|
|
782 |
if (!$organizationalClimate->status) {
|
|
|
783 |
$organizationalClimate->status = OrganizationalClimate::STATUS_INACTIVE;
|
|
|
784 |
}
|
|
|
785 |
|
|
|
786 |
$organizationalClimateFormMapper = OrganizationalClimateFormMapper::getInstance($this->adapter);
|
|
|
787 |
$organizationalClimateForm = $organizationalClimateFormMapper->fetchOneByUuid($dataPost['form_id']);
|
|
|
788 |
$organizationalClimate->form_id = $organizationalClimateForm->id;
|
|
|
789 |
$result = $organizationalClimateMapper->update($organizationalClimate);
|
|
|
790 |
if($result){
|
|
|
791 |
$organizationalClimate = $organizationalClimateMapper->fetchOne($organizationalClimate->id);
|
|
|
792 |
|
|
|
793 |
$jobDescription = new OrganizationalClimateJobDescription();
|
|
|
794 |
$skill = new OrganizationalClimateSkill();
|
|
|
795 |
$industry = new OrganizationalClimateIndustry();
|
|
|
796 |
$language = new OrganizationalClimateLanguage();
|
|
|
797 |
|
|
|
798 |
if(!empty($dataPost['location_search'])){
|
|
|
799 |
|
|
|
800 |
$organizationalClimateLocationMapper = OrganizationalClimateLocationMapper::getInstance($this->adapter);
|
|
|
801 |
|
|
|
802 |
$ok = true;
|
|
|
803 |
|
|
|
804 |
$formatted_address = $dataPost['formatted_address'];
|
|
|
805 |
$city1 = $dataPost['city1'];
|
|
|
806 |
$city2 = $dataPost['city2'];
|
|
|
807 |
$address1 = $dataPost['address1'];
|
|
|
808 |
$address2 = $dataPost['address2'];
|
|
|
809 |
$country = $dataPost['country'];
|
|
|
810 |
$latitude = $dataPost['latitude'];
|
|
|
811 |
$longitude = $dataPost['longitude'];
|
|
|
812 |
$postal_code = $dataPost['postal_code'];
|
|
|
813 |
$state = $dataPost['state'];
|
|
|
814 |
|
|
|
815 |
|
|
|
816 |
$record = new OrganizationalClimateLocation();
|
|
|
817 |
$record->formatted_address = $formatted_address;
|
|
|
818 |
$record->city1 = $city1;
|
|
|
819 |
$record->city2 = $city2;
|
|
|
820 |
$record->address1 = $address1;
|
|
|
821 |
$record->address2 = $address2;
|
|
|
822 |
$record->country = $country;
|
|
|
823 |
$record->latitude = $latitude;
|
|
|
824 |
$record->longitude = $longitude;
|
|
|
825 |
$record->postal_code = $postal_code;
|
|
|
826 |
$record->state = $state;
|
12997 |
efrain |
827 |
$record->organizational_climate_id = $organizationalClimate->id;
|
7218 |
eleazar |
828 |
$result = $organizationalClimateLocationMapper->update($record);
|
|
|
829 |
$ok = $ok && $result;
|
|
|
830 |
//}
|
|
|
831 |
if($ok){
|
|
|
832 |
|
|
|
833 |
}
|
|
|
834 |
}
|
|
|
835 |
|
|
|
836 |
if(!empty($dataPost['job_description_id'])){
|
|
|
837 |
|
|
|
838 |
// print_r($dataPost['job_description_id']);
|
|
|
839 |
|
|
|
840 |
$jobDescriptionMapper = JobDescriptionMapper::getInstance($this->adapter);
|
|
|
841 |
$organizationalClimateJobDescriptionMapper = OrganizationalClimateJobDescriptionMapper::getInstance($this->adapter);
|
|
|
842 |
|
|
|
843 |
$ok = true;
|
|
|
844 |
|
|
|
845 |
|
|
|
846 |
$organizationalClimateJobDescriptionMapper->deleteBySurevy($organizationalClimate->id);
|
|
|
847 |
|
|
|
848 |
foreach($dataPost['job_description_id'] as $jobDescriptionUuid) {
|
|
|
849 |
|
|
|
850 |
// echo '$jobDescriptionUuid = ' . $jobDescriptionUuid ;
|
|
|
851 |
|
|
|
852 |
|
|
|
853 |
$jobDescription = $jobDescriptionMapper->fetchOneByUuid($jobDescriptionUuid);
|
|
|
854 |
|
|
|
855 |
// print_r($jobDescription);
|
|
|
856 |
//print_r($currentCompany);
|
|
|
857 |
|
|
|
858 |
if($jobDescription && $jobDescription->company_id == $currentCompany->id) {
|
|
|
859 |
$record = new OrganizationalClimateJobDescription();
|
|
|
860 |
$record->job_description_id = $jobDescription->id;
|
12997 |
efrain |
861 |
$record->organizational_climate_id = $organizationalClimate->id;
|
7218 |
eleazar |
862 |
|
|
|
863 |
|
|
|
864 |
|
|
|
865 |
$result = $organizationalClimateJobDescriptionMapper->insert($record);
|
|
|
866 |
$ok = $ok && $result;
|
|
|
867 |
}
|
|
|
868 |
}
|
|
|
869 |
|
|
|
870 |
if($ok){
|
|
|
871 |
|
|
|
872 |
}
|
|
|
873 |
}
|
|
|
874 |
|
|
|
875 |
$data = [
|
|
|
876 |
'success' => true,
|
|
|
877 |
'data' => 'LABEL_RECORD_ADDED'
|
|
|
878 |
];
|
|
|
879 |
// return new JsonModel($data);
|
|
|
880 |
|
|
|
881 |
if(!empty($dataPost['skill_id'])){
|
|
|
882 |
|
|
|
883 |
// print_r($dataPost['skill_id']);
|
|
|
884 |
|
|
|
885 |
$skillMapper = SkillMapper::getInstance($this->adapter);
|
|
|
886 |
$organizationalClimateSkillMapper = OrganizationalClimateSkillMapper::getInstance($this->adapter);
|
|
|
887 |
|
|
|
888 |
$ok = true;
|
|
|
889 |
|
|
|
890 |
$organizationalClimateSkillMapper->deleteBySurevy($organizationalClimate->id);
|
|
|
891 |
|
|
|
892 |
|
|
|
893 |
foreach($dataPost['skill_id'] as $skillUuid) {
|
|
|
894 |
|
|
|
895 |
// echo '$jobCategoryUuid = ' . $jobCategoryUuid ;
|
|
|
896 |
|
|
|
897 |
|
|
|
898 |
$skill = $skillMapper->fetchOneByUuid($skillUuid);
|
|
|
899 |
|
|
|
900 |
// print_r($skill);
|
|
|
901 |
//print_r($currentCompany);
|
|
|
902 |
|
|
|
903 |
//if($skill && $skill->company_id == $currentCompany->id) {
|
|
|
904 |
$record = new OrganizationalClimateSkill();
|
|
|
905 |
$record->skill_id = $skill->id;
|
12997 |
efrain |
906 |
$record->organizational_climate_id = $organizationalClimate->id;
|
7218 |
eleazar |
907 |
|
|
|
908 |
|
|
|
909 |
$result = $organizationalClimateSkillMapper->insert($record);
|
|
|
910 |
$ok = $ok && $result;
|
|
|
911 |
// }
|
|
|
912 |
}
|
|
|
913 |
|
|
|
914 |
if($ok){
|
|
|
915 |
|
|
|
916 |
}
|
|
|
917 |
}
|
|
|
918 |
// return new JsonModel($data); exit;
|
|
|
919 |
|
|
|
920 |
if(!empty($dataPost['industry_id'])){
|
|
|
921 |
|
|
|
922 |
// print_r($dataPost['industry_id']);
|
|
|
923 |
|
|
|
924 |
$industryMapper = IndustryMapper::getInstance($this->adapter);
|
|
|
925 |
$organizationalClimateIndustryMapper = OrganizationalClimateIndustryMapper::getInstance($this->adapter);
|
|
|
926 |
|
|
|
927 |
$ok = true;
|
|
|
928 |
|
|
|
929 |
$organizationalClimateIndustryMapper->deleteBySurevy($organizationalClimate->id);
|
|
|
930 |
|
|
|
931 |
foreach($dataPost['industry_id'] as $industryUuid) {
|
|
|
932 |
|
|
|
933 |
// echo '$industryUuid = ' . $industryUuid ;
|
|
|
934 |
|
|
|
935 |
|
|
|
936 |
$industry = $industryMapper->fetchOneByUuid($industryUuid);
|
|
|
937 |
|
|
|
938 |
// print_r($industry);
|
|
|
939 |
//print_r($currentCompany);
|
|
|
940 |
|
|
|
941 |
//if($industry && $industry->company_id == $currentCompany->id) {
|
|
|
942 |
$record = new OrganizationalClimateIndustry();
|
|
|
943 |
$record->industry_id = $industry->id;
|
12997 |
efrain |
944 |
$record->organizational_climate_id = $organizationalClimate->id;
|
7218 |
eleazar |
945 |
|
|
|
946 |
|
|
|
947 |
|
|
|
948 |
$result = $organizationalClimateIndustryMapper->insert($record);
|
|
|
949 |
$ok = $ok && $result;
|
|
|
950 |
//}
|
|
|
951 |
}
|
|
|
952 |
|
|
|
953 |
if($ok){
|
|
|
954 |
|
|
|
955 |
}
|
|
|
956 |
}
|
|
|
957 |
|
|
|
958 |
// return new JsonModel($data); exit;
|
|
|
959 |
|
|
|
960 |
if(!empty($dataPost['language_id'])){
|
|
|
961 |
|
|
|
962 |
$organizationalClimateLanguageMapper = OrganizationalClimateLanguageMapper::getInstance($this->adapter);
|
|
|
963 |
|
|
|
964 |
$ok = true;
|
|
|
965 |
|
|
|
966 |
$organizationalClimateLanguageMapper->deleteBySurevy($organizationalClimate->id);
|
|
|
967 |
|
|
|
968 |
foreach($dataPost['language_id'] as $language_id) {
|
|
|
969 |
|
|
|
970 |
$record = new OrganizationalClimateLanguage();
|
|
|
971 |
$record->language_id = $language_id;
|
12997 |
efrain |
972 |
$record->organizational_climate_id = $organizationalClimate->id;
|
7218 |
eleazar |
973 |
|
|
|
974 |
|
|
|
975 |
$result = $organizationalClimateLanguageMapper->insert($record);
|
|
|
976 |
$ok = $ok && $result;
|
|
|
977 |
//}
|
|
|
978 |
}
|
|
|
979 |
if($ok){
|
|
|
980 |
|
|
|
981 |
}
|
|
|
982 |
}
|
|
|
983 |
}
|
|
|
984 |
|
|
|
985 |
return new JsonModel($data);
|
|
|
986 |
|
|
|
987 |
|
|
|
988 |
if ($result) {
|
|
|
989 |
$this->logger->info('Se edito la encuesta ' . $organizationalClimate->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
|
|
|
990 |
$data = [
|
|
|
991 |
'success' => true,
|
|
|
992 |
'id' => $organizationalClimate->id,
|
|
|
993 |
'action_edit' => $this->url()->fromRoute('organizationalClimate/edit', ['id' => $organizationalClimate->uuid]),
|
|
|
994 |
'data' => 'LABEL_RECORD_UPDATED'
|
|
|
995 |
];
|
|
|
996 |
} else {
|
|
|
997 |
$data = [
|
|
|
998 |
'success' => false,
|
|
|
999 |
'data' => $organizationalClimateMapper->getError()
|
|
|
1000 |
];
|
|
|
1001 |
}
|
|
|
1002 |
|
|
|
1003 |
return new JsonModel($data);
|
|
|
1004 |
} else {
|
|
|
1005 |
$messages = [];
|
|
|
1006 |
$form_messages = (array) $form->getMessages();
|
|
|
1007 |
foreach ($form_messages as $fieldname => $field_messages) {
|
|
|
1008 |
$messages[$fieldname] = array_values($field_messages);
|
|
|
1009 |
}
|
|
|
1010 |
|
|
|
1011 |
return new JsonModel([
|
|
|
1012 |
'success' => false,
|
|
|
1013 |
'data' => $messages
|
|
|
1014 |
]);
|
|
|
1015 |
}
|
|
|
1016 |
} else if ($request->isGet()) {
|
|
|
1017 |
$hydrator = new ObjectPropertyHydrator();
|
|
|
1018 |
|
|
|
1019 |
$organizationalClimatelenguageMapper = OrganizationalClimateLanguageMapper::getInstance($this->adapter);
|
7534 |
eleazar |
1020 |
$languages = $organizationalClimatelenguageMapper->fetchAllBySurveyId($organizationalClimate->id);
|
7218 |
eleazar |
1021 |
|
|
|
1022 |
$lenguage = [];
|
|
|
1023 |
foreach($languages as $language)
|
|
|
1024 |
{
|
|
|
1025 |
array_push($lenguage, $language->language_id);
|
|
|
1026 |
}
|
|
|
1027 |
|
|
|
1028 |
$organizationalClimateSkillMapper = OrganizationalClimateSkillMapper::getInstance($this->adapter);
|
7534 |
eleazar |
1029 |
$skills = $organizationalClimateSkillMapper->fetchAllBySurveyId($organizationalClimate->id);
|
7218 |
eleazar |
1030 |
|
|
|
1031 |
$skilla = [];
|
|
|
1032 |
foreach($skills as $skill)
|
|
|
1033 |
{
|
|
|
1034 |
array_push($skilla, $skill->skill_id);
|
|
|
1035 |
}
|
|
|
1036 |
|
|
|
1037 |
|
|
|
1038 |
$skillMaster = [];
|
|
|
1039 |
foreach($skilla as $skillb)
|
|
|
1040 |
{
|
|
|
1041 |
$skillMapper = SkillMapper::getInstance($this->adapter);
|
|
|
1042 |
$skillm = $skillMapper->fetchOne($skillb);
|
|
|
1043 |
array_push($skillMaster, $skillm->uuid);
|
|
|
1044 |
}
|
|
|
1045 |
|
|
|
1046 |
$OrganizationalClimateJobDescriptionMapper = OrganizationalClimateJobDescriptionMapper::getInstance($this->adapter);
|
7534 |
eleazar |
1047 |
$OrganizationalClimateJobDescriptions = $OrganizationalClimateJobDescriptionMapper->fetchAllBySurveyId($organizationalClimate->id);
|
7218 |
eleazar |
1048 |
|
|
|
1049 |
$OrganizationalClimateJobDescriptionA = [];
|
|
|
1050 |
foreach($OrganizationalClimateJobDescriptions as $OrganizationalClimateJobDescription)
|
|
|
1051 |
{
|
|
|
1052 |
array_push($OrganizationalClimateJobDescriptionA, $OrganizationalClimateJobDescription->job_description_id);
|
|
|
1053 |
}
|
|
|
1054 |
|
|
|
1055 |
$OrganizationalClimateJobDescriptionMaster = [];
|
|
|
1056 |
foreach($OrganizationalClimateJobDescriptionA as $OrganizationalClimateJobDescriptionB)
|
|
|
1057 |
{
|
|
|
1058 |
$JobDescriptionMapper = JobDescriptionMapper::getInstance($this->adapter);
|
|
|
1059 |
$JobDescriptionm = $JobDescriptionMapper->fetchOne($OrganizationalClimateJobDescriptionB);
|
|
|
1060 |
array_push($OrganizationalClimateJobDescriptionMaster, $JobDescriptionm->uuid);
|
|
|
1061 |
}
|
|
|
1062 |
|
|
|
1063 |
$organizationalClimateIndustryMapper = OrganizationalClimateIndustryMapper::getInstance($this->adapter);
|
7534 |
eleazar |
1064 |
$industrys = $organizationalClimateIndustryMapper->fetchAllBySurveyId($organizationalClimate->id);
|
7218 |
eleazar |
1065 |
|
|
|
1066 |
$industrya = [];
|
|
|
1067 |
foreach($industrys as $industry)
|
|
|
1068 |
{
|
|
|
1069 |
array_push($industrya, $industry->industry_id);
|
|
|
1070 |
}
|
|
|
1071 |
|
|
|
1072 |
|
|
|
1073 |
$industryMaster = [];
|
|
|
1074 |
foreach($industrya as $industryb)
|
|
|
1075 |
{
|
|
|
1076 |
$industryMapper = IndustryMapper::getInstance($this->adapter);
|
|
|
1077 |
$industrym = $industryMapper->fetchOne($industryb);
|
|
|
1078 |
array_push($industryMaster, $industrym->uuid);
|
|
|
1079 |
}
|
|
|
1080 |
|
|
|
1081 |
|
|
|
1082 |
$organizationalClimateLocationMapper = OrganizationalClimateLocationMapper::getInstance($this->adapter);
|
7534 |
eleazar |
1083 |
$location = $organizationalClimateLocationMapper->fetchAllBySurveyId($organizationalClimate->id);
|
7218 |
eleazar |
1084 |
|
|
|
1085 |
// return new JsonModel([
|
|
|
1086 |
// 'success' => false,
|
|
|
1087 |
// 'data' => $location
|
|
|
1088 |
// ]);
|
|
|
1089 |
|
|
|
1090 |
|
|
|
1091 |
|
|
|
1092 |
$organizationalClimateFormMapper = OrganizationalClimateFormMapper::getInstance($this->adapter);
|
|
|
1093 |
$organizationalClimateForm = $organizationalClimateFormMapper->fetchOne($organizationalClimate->form_id);
|
|
|
1094 |
// return new JsonModel([
|
|
|
1095 |
// 'success' => false,
|
|
|
1096 |
// 'data' => $OrganizationalClimateJobDescriptionA
|
|
|
1097 |
// ]);
|
|
|
1098 |
$data = [
|
|
|
1099 |
'success' => true,
|
|
|
1100 |
'data' => [
|
|
|
1101 |
'name' => $organizationalClimate->name,
|
|
|
1102 |
'form_id' => $organizationalClimateForm->uuid,
|
|
|
1103 |
'target' => $organizationalClimate->target,
|
|
|
1104 |
'identity' => $organizationalClimate->identity,
|
|
|
1105 |
'since_date' => $organizationalClimate->since_date,
|
|
|
1106 |
'last_date' => $organizationalClimate->last_date,
|
|
|
1107 |
'status' => $organizationalClimate->status,
|
|
|
1108 |
'lenguage_id' => $lenguage,
|
|
|
1109 |
'skill_id' => $skillMaster,
|
|
|
1110 |
'job_description_id' => $OrganizationalClimateJobDescriptionMaster,
|
|
|
1111 |
'industry_id' => $industryMaster,
|
|
|
1112 |
//'location' => $location->city1,
|
|
|
1113 |
]
|
|
|
1114 |
];
|
|
|
1115 |
|
|
|
1116 |
return new JsonModel($data);
|
|
|
1117 |
} else {
|
|
|
1118 |
$data = [
|
|
|
1119 |
'success' => false,
|
|
|
1120 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
1121 |
];
|
|
|
1122 |
|
|
|
1123 |
return new JsonModel($data);
|
|
|
1124 |
}
|
|
|
1125 |
|
|
|
1126 |
return new JsonModel($data);
|
|
|
1127 |
}
|
|
|
1128 |
|
|
|
1129 |
public function deleteAction() {
|
|
|
1130 |
$request = $this->getRequest();
|
|
|
1131 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
1132 |
$currentCompany = $currentUserPlugin->getCompany();
|
|
|
1133 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
1134 |
|
|
|
1135 |
$request = $this->getRequest();
|
|
|
1136 |
$uuid = $this->params()->fromRoute('id');
|
|
|
1137 |
|
|
|
1138 |
if (!$uuid) {
|
|
|
1139 |
$data = [
|
|
|
1140 |
'success' => false,
|
|
|
1141 |
'data' => 'ERROR_INVALID_PARAMETER'
|
|
|
1142 |
];
|
|
|
1143 |
|
|
|
1144 |
return new JsonModel($data);
|
|
|
1145 |
}
|
|
|
1146 |
|
|
|
1147 |
$organizationalClimateMapper = OrganizationalClimateMapper::getInstance($this->adapter);
|
|
|
1148 |
$organizationalClimate = $organizationalClimateMapper->fetchOneByUuid($uuid);
|
|
|
1149 |
if (!$organizationalClimate) {
|
|
|
1150 |
$data = [
|
|
|
1151 |
'success' => false,
|
|
|
1152 |
'data' => 'ERROR_RECORD_NOT_FOUND'
|
|
|
1153 |
];
|
|
|
1154 |
|
|
|
1155 |
return new JsonModel($data);
|
|
|
1156 |
}
|
|
|
1157 |
|
|
|
1158 |
if ($organizationalClimate->company_id != $currentCompany->id) {
|
|
|
1159 |
return new JsonModel([
|
|
|
1160 |
'success' => false,
|
|
|
1161 |
'data' => 'ERROR_UNAUTHORIZED'
|
|
|
1162 |
]);
|
|
|
1163 |
}
|
|
|
1164 |
|
|
|
1165 |
if ($request->isPost()) {
|
|
|
1166 |
|
|
|
1167 |
$result = $organizationalClimateMapper->delete($organizationalClimate->id);
|
|
|
1168 |
if ($result) {
|
|
|
1169 |
//$this->logger->info('Se borro la encuesta ' . $organizationalClimate->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
|
|
|
1170 |
|
|
|
1171 |
$data = [
|
|
|
1172 |
'success' => true,
|
|
|
1173 |
'data' => 'LABEL_RECORD_DELETED'
|
|
|
1174 |
];
|
|
|
1175 |
} else {
|
|
|
1176 |
|
|
|
1177 |
$data = [
|
|
|
1178 |
'success' => false,
|
|
|
1179 |
'data' => $organizationalClimateMapper->getError()
|
|
|
1180 |
];
|
|
|
1181 |
|
|
|
1182 |
return new JsonModel($data);
|
|
|
1183 |
}
|
|
|
1184 |
} else {
|
|
|
1185 |
$data = [
|
|
|
1186 |
'success' => false,
|
|
|
1187 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
1188 |
];
|
|
|
1189 |
|
|
|
1190 |
return new JsonModel($data);
|
|
|
1191 |
}
|
|
|
1192 |
|
|
|
1193 |
return new JsonModel($data);
|
|
|
1194 |
}
|
|
|
1195 |
|
|
|
1196 |
}
|