Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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

Rev 296 Rev 431
Línea 1... Línea 1...
1
<?php
1
<?php
-
 
2
 
2
/**
3
/**
3
 * 
4
 * 
4
 * Controlador: Autoevaluación 
5
 * Controlador: Autoevaluación 
5
 * 
6
 * 
6
 */
7
 */
Línea 24... Línea 25...
24
use Laminas\Db\Sql\Select;
25
use Laminas\Db\Sql\Select;
25
use LeadersLinked\Mapper\CompanySelfEvaluationFormUserMapper;
26
use LeadersLinked\Mapper\CompanySelfEvaluationFormUserMapper;
26
use LeadersLinked\Form\SelfEvaluation\SelfEvaluationTestForm;
27
use LeadersLinked\Form\SelfEvaluation\SelfEvaluationTestForm;
27
use LeadersLinked\Library\Functions;
28
use LeadersLinked\Library\Functions;
Línea 28... Línea 29...
28
 
29
 
29
class SelfEvaluationController extends AbstractActionController
30
class SelfEvaluationController extends AbstractActionController {
30
{
31
 
31
    /**
32
    /**
32
     *
33
     *
33
     * @var AdapterInterface
34
     * @var AdapterInterface
34
     */
35
     */
35
    private $adapter;
-
 
36
    
36
    private $adapter;
37
    
37
 
38
    /**
38
    /**
39
     *
39
     *
40
     * @var AbstractAdapter
40
     * @var AbstractAdapter
41
     */
41
     */
42
    private $cache;
42
    private $cache;
43
    
43
 
44
    /**
44
    /**
45
     *
45
     *
46
     * @var  LoggerInterface
46
     * @var  LoggerInterface
47
     */
47
     */
Línea 48... Línea -...
48
    private $logger;
-
 
49
 
48
    private $logger;
50
    
49
 
51
    /**
50
    /**
52
     *
51
     *
53
     * @var array
52
     * @var array
54
     */
53
     */
55
    private $config;
54
    private $config;
56
    
55
 
57
    /**
56
    /**
58
     *
57
     *
59
     * @param AdapterInterface $adapter
58
     * @param AdapterInterface $adapter
60
     * @param AbstractAdapter $cache
59
     * @param AbstractAdapter $cache
61
     * @param LoggerInterface $logger
60
     * @param LoggerInterface $logger
62
     * @param array $config
61
     * @param array $config
63
     */
-
 
64
    public function __construct($adapter, $cache , $logger,  $config)
62
     */
65
    {
63
    public function __construct($adapter, $cache, $logger, $config) {
66
        $this->adapter      = $adapter;
64
        $this->adapter = $adapter;
67
        $this->cache        = $cache;
65
        $this->cache = $cache;
68
        $this->logger       = $logger;
-
 
69
        $this->config       = $config;
66
        $this->logger = $logger;
70
 
67
        $this->config = $config;
71
    }
68
    }
72
    
69
 
73
    /**
70
    /**
74
     * 
71
     * 
75
     * Generación del listado de evaluaciones
72
     * Generación del listado de evaluaciones
76
     * {@inheritDoc}
73
     * {@inheritDoc}
77
     * @see \Laminas\Mvc\Controller\AbstractActionController::indexAction()
74
     * @see \Laminas\Mvc\Controller\AbstractActionController::indexAction()
78
     */
-
 
79
    public function indexAction()
75
     */
80
    {
76
    public function indexAction() {
81
        $currentUserPlugin = $this->plugin('currentUserPlugin');
77
        $currentUserPlugin = $this->plugin('currentUserPlugin');
82
        $currentUser = $currentUserPlugin->getUser();
78
        $currentUser = $currentUserPlugin->getUser();
83
        
79
 
84
        $request = $this->getRequest();
80
        $request = $this->getRequest();
85
        if($request->isGet()) {
81
        if ($request->isGet()) {
86
            
82
 
87
            
83
 
88
            $headers  = $request->getHeaders();
84
            $headers = $request->getHeaders();
89
            $isJson = false;
85
            $isJson = false;
90
            if($headers->has('Accept')) {
86
            if ($headers->has('Accept')) {
91
                $accept = $headers->get('Accept');
87
                $accept = $headers->get('Accept');
92
                
88
 
93
                $prioritized = $accept->getPrioritized();
89
                $prioritized = $accept->getPrioritized();
94
                
90
 
95
                foreach($prioritized as $key => $value) {
91
                foreach ($prioritized as $key => $value) {
96
                    $raw = trim($value->getRaw());
92
                    $raw = trim($value->getRaw());
97
                    
93
 
98
                    if(!$isJson) {
94
                    if (!$isJson) {
99
                        $isJson = strpos($raw, 'json');
-
 
100
                    }
95
                        $isJson = strpos($raw, 'json');
101
                    
96
                    }
102
                }
97
                }
103
            }
98
            }
104
            
99
 
105
            if($isJson) {
100
            if ($isJson) {
Línea 106... Línea 101...
106
                $search = trim(filter_var($this->params()->fromQuery('search', ''), FILTER_SANITIZE_STRING));
101
                $search = trim(filter_var($this->params()->fromQuery('search', ''), FILTER_SANITIZE_STRING));
107
                
102
 
108
 
103
 
Línea 109... Línea 104...
109
                $acl = $this->getEvent()->getViewModel()->getVariable('acl');
104
                $acl = $this->getEvent()->getViewModel()->getVariable('acl');
Línea 110... Línea 105...
110
                $allowTakeATest = $acl->isAllowed($currentUser->usertype_id, 'profile/self-evaluation/take-a-test');
105
                $allowTakeATest = $acl->isAllowed($currentUser->usertype_id, 'profile/self-evaluation/take-a-test');
111
                $allowReport = $acl->isAllowed($currentUser->usertype_id, 'profile/self-evaluation/report');
106
                $allowReport = $acl->isAllowed($currentUser->usertype_id, 'profile/self-evaluation/report');
112
 
107
 
113
 
108
 
114
                
109
 
115
 
110
 
116
                $queryMapper = QueryMapper::getInstance($this->adapter);
111
                $queryMapper = QueryMapper::getInstance($this->adapter);
117
                
112
 
118
                $select = $queryMapper->getSql()->select();
113
                $select = $queryMapper->getSql()->select();
119
                $select->columns(['uuid','name', 'description', 'text', 'language']);
114
                $select->columns(['uuid', 'name', 'description', 'text', 'language']);
120
                $select->from(['f' => CompanySelfEvaluationFormMapper::_TABLE]);
115
                $select->from(['f' => CompanySelfEvaluationFormMapper::_TABLE]);
121
                $select->join(['fu' => CompanySelfEvaluationFormUserMapper::_TABLE], 'f.id = fu.form_id', []);
116
                $select->join(['fu' => CompanySelfEvaluationFormUserMapper::_TABLE], 'f.id = fu.form_id', []);
122
                $select->join(['t' => CompanySelfEvaluationTestMapper::_TABLE], 'fu.form_id = t.form_id AND fu.user_id = t.user_id', ['status'], Select::JOIN_LEFT_OUTER );
117
                $select->join(['t' => CompanySelfEvaluationTestMapper::_TABLE], 'fu.form_id = t.form_id AND fu.user_id = t.user_id', ['status'], Select::JOIN_LEFT_OUTER);
123
                $select->where->equalTo('f.status', CompanySelfEvaluationForm::STATUS_ACTIVE);
118
                $select->where->equalTo('f.status', CompanySelfEvaluationForm::STATUS_ACTIVE);
124
                $select->where->equalTo('fu.user_id', $currentUser->id);
119
                $select->where->equalTo('fu.user_id', $currentUser->id);
125
                
120
 
126
                
121
 
127
                if($search) {
122
                if ($search) {
128
                    $select->where->NEST->like('name', '%' . $search . '%');
123
                    $select->where->NEST->like('name', '%' . $search . '%');
129
                }
-
 
130
                $select->order('name ASC, language ASC');
124
                }
131
                
-
 
132
                $records = $queryMapper->fetchAll($select);
125
                $select->order('name ASC, language ASC');
133
                $items = [];
126
 
134
                foreach($records as $record)
127
                $records = $queryMapper->fetchAll($select);
135
                {
128
                $items = [];
136
                    switch($record['language']) 
129
                foreach ($records as $record) {
137
                    { 
130
                    switch ($record['language']) {
138
                        case CompanySelfEvaluationForm::LANGUAGE_ENGLISH :
131
                        case CompanySelfEvaluationForm::LANGUAGE_ENGLISH :
139
                            $language = 'LABEL_ENGLISH';
132
                            $language = 'LABEL_ENGLISH';
140
                            break;
133
                            break;
141
                    
134
 
142
                        case CompanySelfEvaluationForm::LANGUAGE_SPANISH : 
135
                        case CompanySelfEvaluationForm::LANGUAGE_SPANISH :
143
                            $language = 'LABEL_SPANISH';
136
                            $language = 'LABEL_SPANISH';
144
                            break;
137
                            break;
145
                            
138
 
-
 
139
                        default :
-
 
140
                            $language = '';
-
 
141
                            break;
146
                        default : 
142
                    }
-
 
143
 
147
                            $language = '';
144
                    switch ($record['status']) {
148
                            break;
145
 
149
                    }
146
                        case CompanySelfEvaluationTest::STATUS_DRAFT :
150
                    
147
                            $status = 'LABEL_DRAFT';
151
                    switch ($record['status']) 
148
                            break;
152
                    { 
149
 
153
                        case CompanySelfEvaluationTest::STATUS_COMPLETED : 
150
                        case CompanySelfEvaluationTest::STATUS_COMPLETED :
154
                            $status = 'LABEL_COMPLETED';
151
                            $status = 'LABEL_COMPLETED';
155
                            break;
152
                            break;
156
                            
153
 
157
                        case CompanySelfEvaluationTest::STATUS_PENDING :
154
                        case CompanySelfEvaluationTest::STATUS_PENDING :
158
                            $status = 'LABEL_PENDING';
155
                            $status = 'LABEL_PENDING';
159
                            break;
156
                            break;
160
                            
157
 
161
                        case CompanySelfEvaluationTest::STATUS_REVIEW :
158
                        case CompanySelfEvaluationTest::STATUS_REVIEW :
162
                            $status = 'LABEL_REVIEW';
159
                            $status = 'LABEL_REVIEW';
163
                            break;
-
 
164
                            
160
                            break;
165
                            
161
 
166
                        default :     
162
 
167
                            $status = 'LABEL_AVAILABLE';
163
                        default :
168
                            break;
164
                            $status = 'LABEL_AVAILABLE';
169
                            
165
                            break;
170
                    }
166
                    }
171
                    
167
 
172
                    
168
 
173
                    $item = [
169
                    $item = [
174
                        'name' => $record['name'], 
170
                        'name' => $record['name'],
175
                        'description' => $record['description'],
-
 
176
                        'text' => $record['text'], 
171
                        'description' => $record['description'],
177
                        'language' => $language,
-
 
Línea -... Línea 172...
-
 
172
                        'text' => $record['text'],
178
                        'status' => $status,
173
                        'language' => $language,
179
                        'link_take_a_test' => $allowTakeATest && empty($record['status']) ? $this->url()->fromRoute('profile/self-evaluation/take-a-test', ['id' => $record['uuid']  ]) : '',
174
                        'status' => $status,
180
                        'link_report'   => $allowReport && $record['status'] == CompanySelfEvaluationTest::STATUS_COMPLETED ?  $this->url()->fromRoute('profile/self-evaluation/report', ['id' => $record['uuid']  ]) : '',
175
                        'link_take_a_test' => $allowTakeATest && empty($record['status']) ? $this->url()->fromRoute('profile/self-evaluation/take-a-test', ['id' => $record['uuid']]) : '',
181
                        
-
 
Línea -... Línea 176...
-
 
176
                        'link_report' => $allowReport && $record['status'] == CompanySelfEvaluationTest::STATUS_COMPLETED ? $this->url()->fromRoute('profile/self-evaluation/report', ['id' => $record['uuid']]) : '',
182
                    ];
177
                    ];
183
                    
178
 
184
 
179
 
185
                    
180
 
186
                    array_push($items, $item);
181
                    array_push($items, $item);
187
                }
182
                }
188
                
183
 
189
 
184
 
190
                
-
 
191
                
-
 
192
                $response = [
185
 
193
                    'success' => true,
186
 
194
                    'data' => $items
187
                $response = [
195
                ];
188
                    'success' => true,
196
                
189
                    'data' => $items
197
                return new JsonModel($response);
190
                ];
198
                
191
 
199
                
192
                return new JsonModel($response);
200
            } else {
193
            } else {
201
                
194
 
202
                $notificationMapper = NotificationMapper::getInstance($this->adapter);
-
 
203
                $notificationMapper->markAllNotificationsAsReadByTypeAndUserId(Notification::TYPE_ACCEPT_MY_REQUEST_CONNECTION, $currentUser->id);
195
                $notificationMapper = NotificationMapper::getInstance($this->adapter);
204
                
196
                $notificationMapper->markAllNotificationsAsReadByTypeAndUserId(Notification::TYPE_ACCEPT_MY_REQUEST_CONNECTION, $currentUser->id);
205
                $this->layout()->setTemplate('layout/layout.phtml');
197
 
206
                $viewModel = new ViewModel();
198
                $this->layout()->setTemplate('layout/layout.phtml');
207
                $viewModel->setTemplate('leaders-linked/self-evaluation/index.phtml');
199
                $viewModel = new ViewModel();
208
                return $viewModel ;
200
                $viewModel->setTemplate('leaders-linked/self-evaluation/index.phtml');
209
            }
201
                return $viewModel;
210
            
202
            }
211
        } else {
203
        } else {
212
            return new JsonModel([
-
 
213
                'success' => false,
204
            return new JsonModel([
214
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
205
                'success' => false,
215
            ]);
206
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
216
        }
207
            ]);
217
    }
208
        }
218
    
209
    }
219
    public function takeaTestAction()
210
 
220
    {
211
    public function takeaTestAction() {
221
        $currentUserPlugin = $this->plugin('currentUserPlugin');
212
        $currentUserPlugin = $this->plugin('currentUserPlugin');
222
        $currentUser = $currentUserPlugin->getUser();
213
        $currentUser = $currentUserPlugin->getUser();
223
        
214
 
224
        $uuid = $this->params()->fromRoute('id');
215
        $uuid = $this->params()->fromRoute('id');
225
        
216
 
226
        $companySelfEvaluationFormMapper = CompanySelfEvaluationFormMapper::getInstance($this->adapter);
217
        $companySelfEvaluationFormMapper = CompanySelfEvaluationFormMapper::getInstance($this->adapter);
Línea 227... Línea 218...
227
        $companySelfEvaluationForm =  $companySelfEvaluationFormMapper->fetchOneByUuid($uuid);
218
        $companySelfEvaluationForm = $companySelfEvaluationFormMapper->fetchOneByUuid($uuid);
228
        
219
 
229
        if(!$companySelfEvaluationForm) {
220
        if (!$companySelfEvaluationForm) {
230
            return new JsonModel([
221
            return new JsonModel([
231
                'success' => false,
222
                'success' => false,
232
                'data' => 'ERROR_FORM_SELF_EVALUATION_NOT_FOUND'
223
                'data' => 'ERROR_FORM_SELF_EVALUATION_NOT_FOUND'
233
            ]) ;     
224
            ]);
234
        }
225
        }
235
 
226
 
236
        if($companySelfEvaluationForm->status == CompanySelfEvaluationForm::STATUS_INACTIVE) {
227
        if ($companySelfEvaluationForm->status == CompanySelfEvaluationForm::STATUS_INACTIVE) {
237
            return new JsonModel([
228
            return new JsonModel([
238
                'success' => false,
229
                'success' => false,
239
                'data' => 'ERROR_FORM_SELF_EVALUATION_IS_INACTIVE'
230
                'data' => 'ERROR_FORM_SELF_EVALUATION_IS_INACTIVE'
240
            ]) ; 
231
            ]);
241
        }
232
        }
242
        
233
 
243
        
234
 
244
        $companySelfEvaluationFormUserMapper = CompanySelfEvaluationFormUserMapper::getInstance($this->adapter);
235
        $companySelfEvaluationFormUserMapper = CompanySelfEvaluationFormUserMapper::getInstance($this->adapter);
245
        $companySelfEvaluationFormUser = $companySelfEvaluationFormUserMapper->fetchOneByFormIdAndUserId($companySelfEvaluationForm->id, $currentUser->id);
236
        $companySelfEvaluationFormUser = $companySelfEvaluationFormUserMapper->fetchOneByFormIdAndUserId($companySelfEvaluationForm->id, $currentUser->id);
246
        if(!$companySelfEvaluationFormUser) {
237
        if (!$companySelfEvaluationFormUser) {
247
            return new JsonModel([
238
            return new JsonModel([
248
                'success' => false,
239
                'success' => false,
249
                'data' => 'ERROR_FORM_SELF_EVALUATION_YOU_CAN_NOT_TAKE'
240
                'data' => 'ERROR_FORM_SELF_EVALUATION_YOU_CAN_NOT_TAKE'
250
            ]) ; 
241
            ]);
251
        }
242
        }
252
        
243
 
253
        
244
 
254
        $companySelfEvaluationTestMapper = CompanySelfEvaluationTestMapper::getInstance($this->adapter);
245
        $companySelfEvaluationTestMapper = CompanySelfEvaluationTestMapper::getInstance($this->adapter);
255
        $companySelfEvaluationTest = $companySelfEvaluationTestMapper->fetchOneBy($companySelfEvaluationForm->id, $currentUser->id);
246
        $companySelfEvaluationTest = $companySelfEvaluationTestMapper->fetchOneBy($companySelfEvaluationForm->id, $currentUser->id);
256
        
247
 
257
        if($companySelfEvaluationTest) {
248
        if ($companySelfEvaluationTest && $companySelfEvaluationTest->status != CompanySelfEvaluationTest::STATUS_DRAFT) {
258
            return new JsonModel([
249
            return new JsonModel([
259
                'success' => false,
250
                'success' => false,
260
                'data' => 'ERROR_FORM_SELF_EVALUATION_ALREADY_YOUR_APPLICATION_IN_THIS_TEST'
251
                'data' => 'ERROR_FORM_SELF_EVALUATION_ALREADY_YOUR_APPLICATION_IN_THIS_TEST'
261
            ]) ; 
252
            ]);
262
        }
253
        }
263
        
254
 
-
 
255
 
-
 
256
        $request = $this->getRequest();
264
        
257
        if ($request->isGet()) {
265
        $request = $this->getRequest();
258
            return new JsonModel([
266
        if($request->isGet()) {
259
                'success' => false,
267
            return new JsonModel([
260
                'data' => [
268
                'success' => false,
261
                    'name' => $companySelfEvaluationForm->name,
269
                'data' => [
262
                    'description' => $companySelfEvaluationForm->description,
270
                    'name' => $companySelfEvaluationForm->name,
263
                    'text' => $companySelfEvaluationForm->text,
271
                    'description' => $companySelfEvaluationForm->description,
264
                    'content' => $companySelfEvaluationTest && $companySelfEvaluationTest->status == CompanySelfEvaluationTest::STATUS_DRAFT ?
272
                    'text' => $companySelfEvaluationForm->text,
265
                    json_decode($companySelfEvaluationTest->content) :
273
                    'content' => json_decode($companySelfEvaluationForm->content),
266
                    json_decode($companySelfEvaluationForm->content),
274
                ]
267
                ]
275
            ]) ; 
268
            ]);
276
        }
269
        }
277
        
270
 
278
        if($request->isPost()) {
271
        if ($request->isPost()) {
279
            $form = new  SelfEvaluationTestForm();
272
            $form = new SelfEvaluationTestForm();
280
            $dataPost = $request->getPost()->toArray();
273
            $dataPost = $request->getPost()->toArray();
281
            
274
 
282
            $form->setData($dataPost);
275
            $form->setData($dataPost);
283
            
276
 
284
            if($form->isValid()) {
277
            if ($form->isValid()) {
285
                $dataPost = (array) $form->getData();
278
                $dataPost = (array) $form->getData();
-
 
279
 
-
 
280
                $selfEvaluationTest = new CompanySelfEvaluationTest();
286
                
281
                $selfEvaluationTest->company_id = $companySelfEvaluationForm->company_id;
-
 
282
                $selfEvaluationTest->form_id = $companySelfEvaluationForm->id;
-
 
283
                $selfEvaluationTest->user_id = $currentUser->id;
-
 
284
                $selfEvaluationTest->status = $dataPost['status'];
287
                $selfEvaluationTest = new CompanySelfEvaluationTest();
285
                $selfEvaluationTest->content = $dataPost['content'];
288
                $selfEvaluationTest->company_id = $companySelfEvaluationForm->company_id;
-
 
289
                $selfEvaluationTest->form_id = $companySelfEvaluationForm->id;
286
 
290
                $selfEvaluationTest->user_id = $currentUser->id;
287
 
291
                $selfEvaluationTest->status = CompanySelfEvaluationTest::STATUS_PENDING;
288
                //Check if the form is already registered
292
                $selfEvaluationTest->content = $dataPost['content'];
289
                $companySelfEvaluationTest = $companySelfEvaluationTestMapper->fetchOneBy($companySelfEvaluationForm->id, $currentUser->id);
293
                
290
 
294
                
291
                $result = $companySelfEvaluationTest ?
295
                
292
                        $companySelfEvaluationTestMapper->update($selfEvaluationTest):
296
                
293
                        $companySelfEvaluationTestMapper->insert($selfEvaluationTest);
297
                $result = $companySelfEvaluationTestMapper->insert($selfEvaluationTest);
294
 
298
                
295
 
299
                if($result) {
296
                if ($result) {
300
                    $this->logger->info('Se agrego un nuevo test de auto-evaluación : ' . $companySelfEvaluationForm->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
297
                    $this->logger->info('Se agrego un nuevo test de auto-evaluación : ' . $companySelfEvaluationForm->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
301
                    
298
 
302
                    $data = [
-
 
303
                        'success'   => true,
299
                    $data = [
304
                        'data'   => 'LABEL_RECORD_ADDED'
300
                        'success' => true,
305
                    ];
301
                        'data' => 'LABEL_RECORD_ADDED'
306
                } else {
-
 
307
                    $data = [
302
                    ];
308
                        'success'   => false,
303
                } else {
309
                        'data'      => $companySelfEvaluationTestMapper->getError()
304
                    $data = [
310
                    ];
305
                        'success' => false,
311
                    
-
 
312
                }
306
                        'data' => $companySelfEvaluationTestMapper->getError()
313
                
307
                    ];
314
                return new JsonModel($data);
308
                }
315
                
309
 
316
            } else {
310
                return new JsonModel($data);
317
                $messages = [];
311
            } else {
318
                $form_messages = (array) $form->getMessages();
312
                $messages = [];
319
                foreach($form_messages  as $fieldname => $field_messages)
313
                $form_messages = (array) $form->getMessages();
320
                {
314
                foreach ($form_messages as $fieldname => $field_messages) {
321
                    
315
 
322
                    $messages[$fieldname] = array_values($field_messages);
316
                    $messages[$fieldname] = array_values($field_messages);
323
                }
317
                }
324
                
318
 
325
                return new JsonModel([
319
                return new JsonModel([
326
                    'success'   => false,
320
                    'success' => false,
327
                    'data'   => $messages
321
                    'data' => $messages
328
                ]);
322
                ]);
329
            }
323
            }
330
        }
-
 
331
        
324
        }
332
        return new JsonModel([
325
 
333
            'success' => false,
326
        return new JsonModel([
334
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
327
            'success' => false,
335
        ]);
328
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
336
    }
329
        ]);
337
    
330
    }
338
    public function reportAction() 
331
 
339
    {
332
    public function reportAction() {
Línea 340... Línea 333...
340
        /*
333
        /*
341
         *     'ERROR_FORM_SELF_EVALUATION_NOT_FOUND' => 'El Test no existe',
-