Proyectos de Subversion LeadersLinked - Backend

Rev

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

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