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