Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 15132 | Rev 15355 | Ir a la última revisión | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 15132 Rev 15133
Línea 21... Línea 21...
21
use LeadersLinked\Model\CompetencyBehavior;
21
use LeadersLinked\Model\CompetencyBehavior;
22
use LeadersLinked\Mapper\BehaviorMapper;
22
use LeadersLinked\Mapper\BehaviorMapper;
23
use LeadersLinked\Form\BehaviorForm;
23
use LeadersLinked\Form\BehaviorForm;
Línea 24... Línea 24...
24
 
24
 
25
 
-
 
Línea 26... Línea 25...
26
class CompetencyController extends AbstractActionController
25
 
27
{
26
class CompetencyController extends AbstractActionController {
28
 
27
 
29
    /**
28
    /**
Línea 55... Línea 54...
55
     * @param AdapterInterface $adapter
54
     * @param AdapterInterface $adapter
56
     * @param AbstractAdapter $cache
55
     * @param AbstractAdapter $cache
57
     * @param LoggerInterface $logger
56
     * @param LoggerInterface $logger
58
     * @param array $config
57
     * @param array $config
59
     */
58
     */
60
    public function __construct($adapter, $cache, $logger, $config)
59
    public function __construct($adapter, $cache, $logger, $config) {
61
    {
-
 
62
        $this->adapter = $adapter;
60
        $this->adapter = $adapter;
63
        $this->cache = $cache;
61
        $this->cache = $cache;
64
        $this->logger = $logger;
62
        $this->logger = $logger;
65
        $this->config = $config;
63
        $this->config = $config;
66
    }
64
    }
Línea 67... Línea 65...
67
 
65
 
68
    public function indexAction()
-
 
69
    {
66
    public function indexAction() {
70
        $currentUserPlugin = $this->plugin('currentUserPlugin');
67
        $currentUserPlugin = $this->plugin('currentUserPlugin');
71
        $currentUser = $currentUserPlugin->getUser();
68
        $currentUser = $currentUserPlugin->getUser();
Línea 72... Línea 69...
72
        $currentCompany = $currentUserPlugin->getCompany();
69
        $currentCompany = $currentUserPlugin->getCompany();
Línea 95... Línea 92...
95
                    }
92
                    }
96
                }
93
                }
97
            }
94
            }
Línea 98... Línea 95...
98
 
95
 
99
            if ($isJson) {
96
            if ($isJson) {
100
                $search = $this->params()->fromQuery('search');
97
                $search = $this->params()->fromQuery('search', []);
Línea 101... Línea 98...
101
                $search = empty($search) ? '' : filter_var($search, FILTER_SANITIZE_STRING);
98
                $search = empty($search['value']) ? '' : filter_var($search['value'], FILTER_SANITIZE_STRING);
102
 
99
 
103
                $page = intval($this->params()->fromQuery('start', 1), 10);
100
                $page = intval($this->params()->fromQuery('start', 1), 10);
104
                $records_x_page = intval($this->params()->fromQuery('length', 10), 10);
101
                $records_x_page = intval($this->params()->fromQuery('length', 10), 10);
Línea 147... Línea 144...
147
                if ($currentCompany) {
144
                if ($currentCompany) {
148
                    $form = new CompetencyForm($this->adapter, $currentCompany->id);
145
                    $form = new CompetencyForm($this->adapter, $currentCompany->id);
149
                } else {
146
                } else {
150
                    $form = new CompetencyForm($this->adapter);
147
                    $form = new CompetencyForm($this->adapter);
151
                }
148
                }
152
 
149
                
153
 
150
  
154
                $this->layout()->setTemplate('layout/layout-backend');
151
                $this->layout()->setTemplate('layout/layout-backend');
155
                $viewModel = new ViewModel();
152
                $viewModel = new ViewModel();
156
                $viewModel->setTemplate('leaders-linked/competencies/index.phtml');
153
                $viewModel->setTemplate('leaders-linked/competencies/index.phtml');
157
                $viewModel->setVariables([
154
                $viewModel->setVariables([
158
                    'form' =>  $form,
155
                    'form' =>  $form,
Línea 165... Línea 162...
165
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
162
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
166
            ]);
163
            ]);
167
        }
164
        }
168
    }
165
    }
Línea 169... Línea 166...
169
 
166
 
170
    public function addAction()
-
 
171
    {
167
    public function addAction() {
172
        $currentUserPlugin = $this->plugin('currentUserPlugin');
168
        $currentUserPlugin = $this->plugin('currentUserPlugin');
173
        $currentUser = $currentUserPlugin->getUser();
169
        $currentUser = $currentUserPlugin->getUser();
Línea 174... Línea 170...
174
        $currentCompany = $currentUserPlugin->getCompany();
170
        $currentCompany = $currentUserPlugin->getCompany();
Línea 175... Línea 171...
175
 
171
 
176
        $request = $this->getRequest();
172
        $request = $this->getRequest();
177
 
173
 
178
        if ($request->isGet()) {
174
        if ($request->isGet()) {
179
 
175
            
180
 
176
            
181
            $behaviors = [];
177
            $behaviors = [];
182
 
178
            
183
            $behaviorMapper = BehaviorMapper::getInstance($this->adapter);
179
            $behaviorMapper = BehaviorMapper::getInstance($this->adapter);
184
            $records = $behaviorMapper->fetchAllActiveByCompanyId($currentCompany->id);
180
            $records = $behaviorMapper->fetchAllActiveByCompanyId($currentCompany->id);
-
 
181
            
185
 
182
            
186
 
183
            foreach($records as $record)
187
            foreach ($records as $record) {
184
            {
188
                array_push($behaviors, [
185
                array_push($behaviors, [
189
                    'id' => $record->uuid,
186
                    'id' => $record->uuid,
190
                    'description' => $record->description,
187
                    'description' => $record->description,
191
                    'checked' => 0
188
                    'checked' => 0
192
 
189
                    
193
                ]);
190
                ]);
194
            }
191
            }
195
 
192
            
196
            return new JsonModel([
193
            return new JsonModel([
197
                'success' => true,
194
                'success' => true,
198
                'data' => [
195
                'data' => [
-
 
196
                    'behaviors' => $behaviors
-
 
197
                ]
-
 
198
            ]);
199
                    'behaviors' => $behaviors
199
            
200
                ]
200
            
201
            ]);
201
            
202
        } else   if ($request->isPost()) {
202
        } else   if ($request->isPost()) {
203
            if ($currentCompany) {
203
            if ($currentCompany) {
Línea 287... Línea 287...
287
        }
287
        }
Línea 288... Línea 288...
288
 
288
 
289
        return new JsonModel($data);
289
        return new JsonModel($data);
Línea 290... Línea 290...
290
    }
290
    }
291
 
-
 
292
    public function editAction()
291
 
293
    {
292
    public function editAction() {
294
        $currentUserPlugin = $this->plugin('currentUserPlugin');
293
        $currentUserPlugin = $this->plugin('currentUserPlugin');
Línea 295... Línea 294...
295
        $currentUser = $currentUserPlugin->getUser();
294
        $currentUser = $currentUserPlugin->getUser();
Línea 337... Línea 336...
337
 
336
 
338
                return new JsonModel($data);
337
                return new JsonModel($data);
339
            }
338
            }
340
        }
339
        }
341
        if ($request->isGet()) {
340
        if ($request->isGet()) {
342
 
341
            
343
            $competencyTypeMapper = CompetencyTypeMapper::getInstance($this->adapter);
342
            $competencyTypeMapper = CompetencyTypeMapper::getInstance($this->adapter);
344
            $competencyType = $competencyTypeMapper->fetchOne($competency->competency_type_id);
343
            $competencyType = $competencyTypeMapper->fetchOne($competency->competency_type_id);
345
 
344
            
346
            $competencyBehaviorMapper = CompetencyBehaviorMapper::getInstance($this->adapter);
345
            $competencyBehaviorMapper = CompetencyBehaviorMapper::getInstance($this->adapter);
347
 
346
            
348
            $behaviorMapper = BehaviorMapper::getInstance($this->adapter);
347
            $behaviorMapper = BehaviorMapper::getInstance($this->adapter);
349
            $records = $behaviorMapper->fetchAllActiveByCompanyId($currentCompany->id);
348
            $records = $behaviorMapper->fetchAllActiveByCompanyId($currentCompany->id);
350
 
349
            
351
 
350
            
352
            $behaviors = [];
351
            $behaviors = [];
-
 
352
            foreach($records as $record)
353
            foreach ($records as $record) {
353
            {
354
                $competencyBehavior = $competencyBehaviorMapper->fetchOneByBehaviorIdAndCompetencyId($record->id, $competency->id);
354
                $competencyBehavior = $competencyBehaviorMapper->fetchOneByBehaviorIdAndCompetencyId($record->id, $competency->id);
355
 
355
            
356
 
356
            
357
                array_push($behaviors, [
357
                array_push($behaviors, [
358
                    'id' => $record->uuid,
358
                    'id' => $record->uuid,
359
                    'description' => $record->description,
359
                    'description' => $record->description,
360
                    'checked' => $competencyBehavior ? 1 : 0
360
                    'checked' => $competencyBehavior ? 1 : 0
361
 
361
                    
-
 
362
                ]);
362
                ]);
363
            
363
            }
364
            }
364
 
365
            
365
            $response = [
366
            $response = [
366
                'success' => true,
367
                'success' => true,
367
                'data' => [
368
                'data' =>[
368
                    'competency_type_id' => $competencyType->uuid,
369
                    'competency_type_id' => $competencyType->uuid,
369
                    'name' => $competency->name,
370
                    'name' => $competency->name,
370
                    'description' => $competency->description,
371
                    'description' => $competency->description,
371
                    'status' => $competency->status,
372
                    'status' => $competency->status,
372
                    'behaviors' =>  $behaviors,
373
                    'behaviors' =>  $behaviors,
373
                ]
374
               ]
Línea 374... Línea 375...
374
            ];
375
            ];
-
 
376
 
375
 
377
 
376
 
378
            return new JsonModel($response);
377
            return new JsonModel($response);
379
        } 
378
        } else  if ($request->isPost()) {
380
        else  if ($request->isPost()) {
379
            if ($currentCompany) {
381
            if ($currentCompany) {
380
                $form = new CompetencyForm($this->adapter, $currentCompany->id);
382
                $form = new CompetencyForm($this->adapter, $currentCompany->id);
Línea 405... Línea 407...
405
                    $behaviorMapper = BehaviorMapper::getInstance($this->adapter);
407
                    $behaviorMapper = BehaviorMapper::getInstance($this->adapter);
Línea 406... Línea 408...
406
 
408
 
Línea 407... Línea 409...
407
                    $competencyBehaviorMapper->deleteAllBCompetencyId($competency->id);
409
                    $competencyBehaviorMapper->deleteAllBCompetencyId($competency->id);
408
 
410
 
409
                    $behavior_ids = $dataPost['behavior_id'];
411
                    $behavior_ids = $dataPost['behavior_id'];
410
 
412
                    
411
                    foreach ($behavior_ids as $behavior_id) {
413
                    foreach ($behavior_ids as $behavior_id) {
412
                        $behavior = $behaviorMapper->fetchOneByUuid($behavior_id);
414
                        $behavior = $behaviorMapper->fetchOneByUuid($behavior_id);
413
                        if ($behavior) {
415
                        if ($behavior) {
Línea 454... Línea 456...
454
        }
456
        }
Línea 455... Línea 457...
455
 
457
 
456
        return new JsonModel($data);
458
        return new JsonModel($data);
Línea 457... Línea 459...
457
    }
459
    }
458
 
-
 
459
    public function deleteAction()
460
 
460
    {
461
    public function deleteAction() {
461
        $currentUserPlugin = $this->plugin('currentUserPlugin');
462
        $currentUserPlugin = $this->plugin('currentUserPlugin');
Línea 462... Línea 463...
462
        $currentUser = $currentUserPlugin->getUser();
463
        $currentUser = $currentUserPlugin->getUser();
Línea 534... Línea 535...
534
        }
535
        }
Línea 535... Línea 536...
535
 
536
 
536
        return new JsonModel($data);
537
        return new JsonModel($data);
Línea 537... Línea 538...
537
    }
538
    }
538
 
-
 
539
    public function importAction()
539
 
540
    {
540
    public function importAction() {
541
        $currentUserPlugin = $this->plugin('currentUserPlugin');
541
        $currentUserPlugin = $this->plugin('currentUserPlugin');
Línea 542... Línea 542...
542
        $currentUser = $currentUserPlugin->getUser();
542
        $currentUser = $currentUserPlugin->getUser();
Línea 672... Línea 672...
672
            return new JsonModel($data);
672
            return new JsonModel($data);
673
        }
673
        }
Línea 674... Línea 674...
674
 
674
 
675
        return new JsonModel($data);
675
        return new JsonModel($data);
-
 
676
    }
-
 
677
    
-
 
678
    
676
    }
679