Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 6749 | Ir a la última revisión | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 www 1
<?php
2
/**
3
 *
4
 * Controlador: Microlearning
5
 *
6
 */
7
declare(strict_types=1);
8
 
9
namespace LeadersLinked\Controller;
10
 
11
use Laminas\Db\Adapter\AdapterInterface;
6849 efrain 12
 
1 www 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\Mapper\CompanyMicrolearningUserLogMapper;
18
use LeadersLinked\Model\CompanyMicrolearningUserLog;
19
use LeadersLinked\Mapper\CompanyMicrolearningCapsuleUserMapper;
20
use LeadersLinked\Mapper\CompanyMicrolearningUserProgressMapper;
21
use LeadersLinked\Mapper\CompanyMicrolearningSlideMapper;
22
 
23
class ProfileMicrolearningController extends AbstractActionController
24
{
25
    /**
26
     *
27
     * @var AdapterInterface
28
     */
29
    private $adapter;
30
 
31
    /**
32
     *
33
     * @var  LoggerInterface
34
     */
35
    private $logger;
36
 
37
 
38
    /**
39
     *
40
     * @var array
41
     */
42
    private $config;
43
 
44
    /**
45
     *
46
     * @param AdapterInterface $adapter
47
     * @param LoggerInterface $logger
48
     * @param array $config
49
     */
6849 efrain 50
    public function __construct($adapter, $logger,  $config)
1 www 51
    {
52
        $this->adapter      = $adapter;
53
        $this->logger       = $logger;
54
        $this->config       = $config;
55
 
56
    }
57
 
58
    /**
59
     *
60
     * Generación del listado de perfiles
61
     * {@inheritDoc}
62
     * @see \Laminas\Mvc\Controller\AbstractActionController::indexAction()
63
     */
64
    public function indexAction()
65
    {
66
        //$currentUserPlugin = $this->plugin('currentUserPlugin');
67
        //$currentUser = $currentUserPlugin->getUser();
68
 
69
        $request = $this->getRequest();
70
        if($request->isGet()) {
71
 
72
 
73
 
74
            $this->layout()->setTemplate('layout/layout.phtml');
75
            $viewModel = new ViewModel();
76
            $viewModel->setTemplate('leaders-linked/profile/microlearning.phtml');
77
            $viewModel->setVariables([
78
                'activities' => [
79
                    'ACTIVITY_SIGNIN' =>  CompanyMicrolearningUserLog::ACTIVITY_SIGNIN,
80
                    'ACTIVITY_SIGNOUT' => CompanyMicrolearningUserLog::ACTIVITY_SIGNOUT,
81
                    'ACTIVITY_START_TOPIC' => CompanyMicrolearningUserLog::ACTIVITY_START_TOPIC,
82
                    'ACTIVITY_START_CAPSULE' => CompanyMicrolearningUserLog::ACTIVITY_START_CAPSULE,
83
                    'ACTIVITY_VIEW_SLIDE' => CompanyMicrolearningUserLog::ACTIVITY_VIEW_SLIDE,
84
                    'ACTIVITY_TAKE_A_TEST' => CompanyMicrolearningUserLog::ACTIVITY_TAKE_A_TEST,
85
                    'ACTIVITY_RETAKE_A_TEST' => CompanyMicrolearningUserLog::ACTIVITY_RETAKE_A_TEST,
86
                    'ACTIVITY_APPROVED_TEST' => CompanyMicrolearningUserLog::ACTIVITY_APPROVED_TEST,
87
                    'ACTIVITY_COMPLETED_CAPSULE' => CompanyMicrolearningUserLog::ACTIVITY_COMPLETED_CAPSULE,
88
                    'ACTIVITY_COMPLETED_TOPIC' => CompanyMicrolearningUserLog::ACTIVITY_COMPLETED_TOPIC
89
                ]
90
            ]);
91
            return $viewModel ;
92
 
93
 
94
        } else {
95
            return new JsonModel([
96
                'success' => false,
97
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
98
            ]);
99
        }
100
    }
101
 
102
 
103
    /**
104
     *
105
     * Generación del timeline de microaprendizaje para el usuario actual
106
     * solo con agregar ?page=XX
107
     *
108
     * Para las repuesta afirmativa
109
     * [
110
     *    'success' => true,
111
     *    'data' => [
112
     *      'total' => [
113
     *          'count' => cantidad de registros totales,
114
     *          'pages' => cantidad de páginas totales,
115
     *      ],
116
     *      'current' => [
117
     *          'items'    => [
118
     *              [
119
     *                  'activity' => actividad realizada,
120
     *                  'added_on' => fecha en la que fué realizada
121
     *              ]
122
     *           ] ,
123
     *          'page'     => página actual,
124
     *          'count'    => cantidad de registros de la página actual,
125
     *       ]
126
     *    ]
127
     *
128
     *  En caso contrario
129
     *  [
130
     *      'success' => false,
131
     *      'data' => mensaje de error
132
     *  ]
133
     *
134
     *
135
     * @return \Laminas\View\Model\JsonModel
136
     */
137
    public function timelineAction()
138
    {
139
 
140
        $request = $this->getRequest();
141
        if($request->isGet()) {
142
            $currentUserPlugin = $this->plugin('currentUserPlugin');
143
            $currentUser = $currentUserPlugin->getUser();
144
 
145
 
146
            $page = intval($this->params()->fromQuery('page'), 10);
147
 
148
            $companyMicrolearningUserLogMapper = CompanyMicrolearningUserLogMapper::getInstance($this->adapter);
149
            $paginator = $companyMicrolearningUserLogMapper->getAllMessagesPaginatorByUserId($currentUser->id, $page);
150
 
151
            $items = [];
152
            foreach($paginator as $record)
153
            {
154
                $dt = \DateTime::createFromFormat('Y-m-d H:i:s', $record->added_on);
155
 
156
                array_push($items, [
157
                    'activity' => $record->activity,
158
                    'added_on' => $dt->format('d/m/Y H:i a')
159
                ]);
160
            }
161
 
162
 
163
            return new JsonModel([
164
                    'success' => true,
165
                    'data' => [
166
                        'total' => [
167
                            'count' => $paginator->getTotalItemCount(),
168
                            'pages' => $paginator->getPages()->pageCount,
169
                        ],
170
                        'current' => [
171
                            'items'    => $items,
172
                            'page'     => $paginator->getCurrentPageNumber(),
173
                            'count'    => $paginator->getCurrentItemCount(),
174
                        ]
175
                    ]
176
            ]);
177
 
178
 
179
        } else {
180
            return new JsonModel([
181
                'success' => false,
182
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
183
            ]);
184
        }
185
    }
186
 
187
    /**
188
     * Valores para la generación de los gráficos de progreso
189
     * Para las repuesta afirmativa
190
     * [
191
     *  'success' => true,
192
     *      'data' => [
193
     *          'topicTotal' => cantidad total de tópicos,
194
     *          'topicStarted' => cantidad de tópicos iniciados,
195
     *          'topicIncompleted' => cantidad de tópicos incompletos,
196
     *          'topicCompleted' => cantidad de tópicos completos,
197
     *          'percentCompleted' => % de diapositivas completados ,
198
     *          'percentIncompleted' => % de diapositivas incompletos ,
199
     *          'percentWithoutReturning' => % de cápsulas sin retorno después de completada,
200
     *          'percentWithReturning' => % de cápsulas con retorno después de completada,
201
     *       ],
202
     * ]
203
     *
204
     *
205
     *  En caso contrario
206
     *  [
207
     *      'success' => false,
208
     *      'data' => mensaje de error
209
     *  ]
210
     *
211
     *
212
     * @return \Laminas\View\Model\JsonModel
213
     */
214
    public function progressAction()
215
    {
216
 
217
        $request = $this->getRequest();
218
        if($request->isGet()) {
219
            $currentUserPlugin = $this->plugin('currentUserPlugin');
220
            $currentUser = $currentUserPlugin->getUser();
221
 
222
            $topicIdsUsers = [];
223
            $capsuleIdsUser = [];
224
 
225
            $topicTotal = 0;
226
            $topicStarted = 0;
227
            $topicIncompleted = 0;
228
            $topicCompleted =  0;
229
            $totalSlides = 0;
230
            $totalSlidesCompleted = 0;
231
            //$totalSlideWithReturning = 0;
232
 
233
            $totalCapsules = 0;
234
            $totalCapsulesCompleted = 0;
235
            $totalCapsulesCompletedWithReturn = 0;
236
            $totalCapsulesCompletedWithoutReturn = 0;
237
 
238
            //$companyMicrolearningTopicMapper = CompanyMicrolearningTopicMapper::getInstance($this->adapter);
239
            $companyMicrolearningSlideMapper = CompanyMicrolearningSlideMapper::getInstance($this->adapter);
240
 
241
            $companyMicrolearningUserProgressMapper = CompanyMicrolearningUserProgressMapper::getInstance($this->adapter);
242
 
243
 
244
            $companyMicrolearningCapsuleUserMapper = CompanyMicrolearningCapsuleUserMapper::getInstance($this->adapter);
245
            $capsulesUser = $companyMicrolearningCapsuleUserMapper->fetchAllActiveByUserId($currentUser->id);
246
 
247
            foreach($capsulesUser as $capsuleUser)
248
            {
249
                $company_id = $capsuleUser->company_id;
250
                $topic_id   = $capsuleUser->topic_id;
251
                $capsule_id = $capsuleUser->capsule_id;
252
 
253
                if(!in_array($topic_id, $topicIdsUsers)) {
254
                    $topicTotal++;
255
                    array_push($topicIdsUsers, $topic_id);
256
 
257
                    $progress = $companyMicrolearningUserProgressMapper->fetchOneByUserIdAndTopicId($currentUser->id, $topic_id);
258
                    if($progress) {
259
                        $topicStarted++;
260
                        if(100 > $progress->progress) {
261
                            $topicIncompleted++;
262
                        } else {
263
                            $topicCompleted++;
264
                        }
265
 
266
                    }
267
                }
268
 
269
                if(!in_array($capsule_id, $capsuleIdsUser)) {
270
 
271
                    $totalSlides += $companyMicrolearningSlideMapper->fetchTotalCountByCompanyIdAndTopicIdAndCapsuleId($company_id, $topic_id, $capsule_id);
272
                    $totalSlidesCompleted += $companyMicrolearningUserProgressMapper->fetchCountAllSlideCompletedByUserIdAndCapsuleId($currentUser->id, $capsule_id);
273
 
274
                    array_push($capsuleIdsUser, $capsule_id);
275
 
276
                    $totalCapsules++;
277
                    $progress = $companyMicrolearningUserProgressMapper->fetchOneByUseridAndCapsuleId($currentUser->id, $capsule_id);
278
                    if($progress && $progress->completed) {
279
 
280
                        $totalCapsulesCompleted++;
281
                        if($progress->returning_after_completed) {
282
                            $totalCapsulesCompletedWithReturn++;
283
                        } else {
284
                            $totalCapsulesCompletedWithoutReturn++;
285
                        }
286
 
287
                    }
288
 
289
 
290
                }
291
 
292
 
293
            }
294
 
295
            $percentCompleted = 0;
296
            $percentIncompleted = 100;
297
 
298
            if( $totalSlides > 0) {
299
                $percentCompleted = ($totalSlidesCompleted  * 100) /  $totalSlides;
300
                $percentIncompleted = 100 - $percentCompleted;
301
            }
302
 
303
 
304
            $percentWithoutReturning  = 0;
305
            $percentWithReturning = 0;
306
 
307
            if($totalCapsulesCompleted > 0) {
308
                $percentWithReturning = ($totalCapsulesCompletedWithReturn  * 100) / $totalCapsulesCompleted;
309
                $percentWithoutReturning = ($totalCapsulesCompletedWithoutReturn  * 100) / $totalCapsulesCompleted;
310
            }
311
 
312
 
313
 
314
            return new JsonModel([
315
                'success' => true,
316
                'data' => [
317
                    'topicTotal' => $topicTotal,
318
                    'topicStarted' => $topicStarted,
319
                    'topicIncompleted' => $topicIncompleted,
320
                    'topicCompleted' => $topicCompleted,
321
                    'percentCompleted' => number_format($percentCompleted, 2, '.', ','),
322
                    'percentIncompleted' => number_format($percentIncompleted, 2, '.', ','),
323
                    'percentWithoutReturning' => number_format($percentWithoutReturning, 2, '.', ','),
324
                    'percentWithReturning' => number_format($percentWithReturning, 2, '.', ','),
325
                ],
326
            ]);
327
 
328
 
329
        } else {
330
            return new JsonModel([
331
                'success' => false,
332
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
333
            ]);
334
        }
335
    }
336
 
337
 
338
 
339
}