Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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

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