1 |
www |
1 |
<?php
|
|
|
2 |
declare(strict_types=1);
|
|
|
3 |
|
|
|
4 |
namespace LeadersLinked\Controller;
|
|
|
5 |
|
|
|
6 |
use Laminas\Db\Adapter\AdapterInterface;
|
|
|
7 |
use Laminas\Cache\Storage\Adapter\AbstractAdapter;
|
|
|
8 |
use Laminas\Mvc\Controller\AbstractActionController;
|
|
|
9 |
use Laminas\Log\LoggerInterface;
|
|
|
10 |
use Laminas\View\Model\ViewModel;
|
|
|
11 |
use Laminas\View\Model\JsonModel;
|
|
|
12 |
use LeadersLinked\Form\ExtendUserMicrolearningForm;
|
|
|
13 |
use LeadersLinked\Mapper\QueryMapper;
|
|
|
14 |
use LeadersLinked\Mapper\UserMapper;
|
|
|
15 |
use Laminas\Db\Sql\Expression;
|
|
|
16 |
use LeadersLinked\Mapper\CompanyMicrolearningCapsuleUserMapper;
|
|
|
17 |
use LeadersLinked\Model\CompanyMicrolearningCapsuleUser;
|
|
|
18 |
use LeadersLinked\Mapper\CompanyMicrolearningCapsuleMapper;
|
|
|
19 |
use LeadersLinked\Mapper\CompanyMicrolearningUserProgressMapper;
|
|
|
20 |
use LeadersLinked\Mapper\CompanyMicrolearningSlideMapper;
|
|
|
21 |
use LeadersLinked\Mapper\CompanyMicrolearningUserLogMapper;
|
|
|
22 |
use Google\Service\Classroom\Student;
|
|
|
23 |
use LeadersLinked\Mapper\CompanyMicrolearningExtendUserCompanyMapper;
|
|
|
24 |
use LeadersLinked\Mapper\CompanyMicrolearningExtendUserFunctionMapper;
|
|
|
25 |
use LeadersLinked\Mapper\CompanyMicrolearningExtendUserGroupMapper;
|
|
|
26 |
use LeadersLinked\Mapper\CompanyMicrolearningExtendUserInstitutionMapper;
|
|
|
27 |
use LeadersLinked\Mapper\CompanyMicrolearningExtendUserProgramMapper;
|
|
|
28 |
use LeadersLinked\Mapper\CompanyMicrolearningExtendUserPartnerMapper;
|
|
|
29 |
use LeadersLinked\Mapper\CompanyMicrolearningExtendUserSectorMapper;
|
|
|
30 |
use LeadersLinked\Mapper\CompanyMicrolearningExtendUserStudentTypeMapper;
|
|
|
31 |
use LeadersLinked\Mapper\CompanyMicrolearningExtendUserMapper;
|
187 |
efrain |
32 |
use LeadersLinked\Mapper\CompanyMicrolearningTopicMapper;
|
2 |
efrain |
33 |
use LeadersLinked\Mapper\DeviceMapper;
|
|
|
34 |
use LeadersLinked\Model\Application;
|
129 |
efrain |
35 |
use LeadersLinked\Mapper\CompanyMicrolearningUserMapper;
|
|
|
36 |
use LeadersLinked\Model\CompanyMicrolearningExtendUser;
|
187 |
efrain |
37 |
use LeadersLinked\Form\TopicCapsuleForm;
|
|
|
38 |
use LeadersLinked\Mapper\CompanyMicrolearningCapsuleCommentMapper;
|
|
|
39 |
use Laminas\Hydrator\ArraySerializableHydrator;
|
|
|
40 |
use Laminas\Db\ResultSet\HydratingResultSet;
|
|
|
41 |
use Laminas\Paginator\Adapter\DbSelect;
|
|
|
42 |
use Laminas\Paginator\Paginator;
|
14612 |
efrain |
43 |
use LeadersLinked\Model\CompanyMicrolearningUserProgress;
|
15386 |
efrain |
44 |
use PhpOffice\PhpSpreadsheet\IOFactory;
|
|
|
45 |
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
|
|
46 |
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
|
|
|
47 |
use PhpOffice\PhpSpreadsheet\Calculation\TextData\Replace;
|
|
|
48 |
use LeadersLinked\Form\TopicReportForm;
|
|
|
49 |
use LeadersLinked\Model\User;
|
|
|
50 |
use LeadersLinked\Mapper\CompanyUserMapper;
|
|
|
51 |
use Laminas\Db\Sql\Select;
|
|
|
52 |
use LeadersLinked\Form\StudentReportForm;
|
1 |
www |
53 |
|
|
|
54 |
|
15386 |
efrain |
55 |
|
1 |
www |
56 |
class MicrolearningReportsController extends AbstractActionController
|
|
|
57 |
{
|
|
|
58 |
/**
|
|
|
59 |
*
|
|
|
60 |
* @var AdapterInterface
|
|
|
61 |
*/
|
|
|
62 |
private $adapter;
|
|
|
63 |
|
|
|
64 |
|
|
|
65 |
/**
|
|
|
66 |
*
|
|
|
67 |
* @var AbstractAdapter
|
|
|
68 |
*/
|
|
|
69 |
private $cache;
|
|
|
70 |
|
|
|
71 |
/**
|
|
|
72 |
*
|
|
|
73 |
* @var LoggerInterface
|
|
|
74 |
*/
|
|
|
75 |
private $logger;
|
|
|
76 |
|
|
|
77 |
|
|
|
78 |
/**
|
|
|
79 |
*
|
|
|
80 |
* @param AdapterInterface $adapter
|
|
|
81 |
* @param AbstractAdapter $cache
|
|
|
82 |
* @param LoggerInterface $logger
|
|
|
83 |
* @param array $config
|
|
|
84 |
*/
|
|
|
85 |
public function __construct($adapter, $cache , $logger, $config)
|
|
|
86 |
{
|
|
|
87 |
$this->adapter = $adapter;
|
|
|
88 |
$this->cache = $cache;
|
|
|
89 |
$this->logger = $logger;
|
|
|
90 |
$this->config = $config;
|
|
|
91 |
|
|
|
92 |
|
|
|
93 |
}
|
|
|
94 |
|
2 |
efrain |
95 |
|
|
|
96 |
public function indexAction()
|
|
|
97 |
{
|
|
|
98 |
|
|
|
99 |
$this->layout()->setTemplate('layout/layout-backend.phtml');
|
|
|
100 |
$viewModel = new ViewModel();
|
|
|
101 |
$viewModel->setTemplate('leaders-linked/microlearning-reports/index.phtml');
|
|
|
102 |
return $viewModel ;
|
|
|
103 |
}
|
|
|
104 |
|
1 |
www |
105 |
|
|
|
106 |
public function overviewAction()
|
|
|
107 |
{
|
|
|
108 |
|
|
|
109 |
|
|
|
110 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
111 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
112 |
$currentCompany = $currentUserPlugin->getCompany();
|
|
|
113 |
|
|
|
114 |
|
|
|
115 |
$request = $this->getRequest();
|
|
|
116 |
if($request->isGet()) {
|
|
|
117 |
$reportsLastWeek = [];
|
|
|
118 |
$reportsCapsuleResume = [];
|
|
|
119 |
$reportsStudentsTotal = [];
|
|
|
120 |
|
|
|
121 |
$companyMicrolearningExtendUserCompanyMapper = CompanyMicrolearningExtendUserCompanyMapper::getInstance($this->adapter);
|
|
|
122 |
$extendCompanies = $companyMicrolearningExtendUserCompanyMapper->fetchAllByCompanyId($currentCompany->id);
|
|
|
123 |
|
|
|
124 |
foreach($extendCompanies as $extendCompany)
|
|
|
125 |
{
|
|
|
126 |
$reportsLastWeek['companies'][$extendCompany->id] = [
|
|
|
127 |
'name' => $extendCompany->name,
|
|
|
128 |
'total' => 0,
|
|
|
129 |
'value' => 0
|
|
|
130 |
] ;
|
|
|
131 |
|
|
|
132 |
$reportsCapsuleResume['companies'][$extendCompany->id] = [
|
|
|
133 |
'name' => $extendCompany->name,
|
|
|
134 |
'total' => 0,
|
|
|
135 |
'value' => 0
|
|
|
136 |
] ;
|
|
|
137 |
|
|
|
138 |
$reportsStudentsTotal['companies'][$extendCompany->id] = [
|
|
|
139 |
'name' => $extendCompany->name,
|
|
|
140 |
'total' => 0,
|
|
|
141 |
] ;
|
|
|
142 |
}
|
|
|
143 |
|
|
|
144 |
|
|
|
145 |
$companyMicrolearningExtendUserFunctionMapper = CompanyMicrolearningExtendUserFunctionMapper::getInstance($this->adapter);
|
|
|
146 |
$extendFunctions = $companyMicrolearningExtendUserFunctionMapper->fetchAllByCompanyId($currentCompany->id);
|
|
|
147 |
|
|
|
148 |
foreach($extendFunctions as $extendFunction)
|
|
|
149 |
{
|
|
|
150 |
$reportsLastWeek['functions'][$extendFunction->id] = [
|
|
|
151 |
'name' => $extendFunction->name,
|
|
|
152 |
'total' => 0,
|
|
|
153 |
'value' => 0
|
|
|
154 |
] ;
|
|
|
155 |
|
|
|
156 |
$reportsCapsuleResume['functions'][$extendFunction->id] = [
|
|
|
157 |
'name' => $extendFunction->name,
|
|
|
158 |
'total' => 0,
|
|
|
159 |
'value' => 0
|
|
|
160 |
] ;
|
|
|
161 |
|
|
|
162 |
$reportsStudentsTotal['functions'][$extendFunction->id] = [
|
|
|
163 |
'name' => $extendFunction->name,
|
|
|
164 |
'total' => 0,
|
|
|
165 |
] ;
|
|
|
166 |
}
|
|
|
167 |
|
|
|
168 |
$companyMicrolearningExtendUserGroupMapper = CompanyMicrolearningExtendUserGroupMapper::getInstance($this->adapter);
|
|
|
169 |
$extendGroups = $companyMicrolearningExtendUserGroupMapper->fetchAllByCompanyId($currentCompany->id);
|
|
|
170 |
|
|
|
171 |
foreach($extendGroups as $extendGroup)
|
|
|
172 |
{
|
|
|
173 |
$reportsLastWeek['groups'][$extendGroup->id] = [
|
|
|
174 |
'name' => $extendGroup->name,
|
|
|
175 |
'total' => 0,
|
|
|
176 |
'value' => 0
|
|
|
177 |
];
|
|
|
178 |
|
|
|
179 |
$reportsCapsuleResume['groups'][$extendGroup->id] = [
|
|
|
180 |
'name' => $extendFunction->name,
|
|
|
181 |
'total' => 0,
|
|
|
182 |
'value' => 0
|
|
|
183 |
] ;
|
|
|
184 |
|
|
|
185 |
$reportsStudentsTotal['groups'][$extendGroup->id] = [
|
|
|
186 |
'name' => $extendGroup->name,
|
|
|
187 |
'total' => 0,
|
|
|
188 |
];
|
|
|
189 |
|
|
|
190 |
|
|
|
191 |
}
|
|
|
192 |
|
|
|
193 |
|
|
|
194 |
$companyMicrolearningExtendUserInstitutionMapper = CompanyMicrolearningExtendUserInstitutionMapper::getInstance($this->adapter);
|
|
|
195 |
$extendInstitutions = $companyMicrolearningExtendUserInstitutionMapper->fetchAllByCompanyId($currentCompany->id);
|
|
|
196 |
|
|
|
197 |
foreach($extendInstitutions as $extendInstitution)
|
|
|
198 |
{
|
|
|
199 |
$reportsLastWeek['institutions'][$extendInstitution->id] = [
|
|
|
200 |
'name' => $extendInstitution->name,
|
|
|
201 |
'total' => 0,
|
|
|
202 |
'value' => 0
|
|
|
203 |
] ;
|
|
|
204 |
|
|
|
205 |
$reportsCapsuleResume['institutions'][$extendInstitution->id] = [
|
|
|
206 |
'name' => $extendInstitution->name,
|
|
|
207 |
'total' => 0,
|
|
|
208 |
'value' => 0
|
|
|
209 |
] ;
|
|
|
210 |
|
|
|
211 |
$reportsStudentsTotal['institutions'][$extendInstitution->id] = [
|
|
|
212 |
'name' => $extendInstitution->name,
|
|
|
213 |
'total' => 0,
|
|
|
214 |
] ;
|
|
|
215 |
}
|
|
|
216 |
|
|
|
217 |
|
|
|
218 |
$companyMicrolearningExtendUserProgramMapper = CompanyMicrolearningExtendUserProgramMapper::getInstance($this->adapter);
|
|
|
219 |
$extendPrograms = $companyMicrolearningExtendUserProgramMapper->fetchAllByCompanyId($currentCompany->id);
|
|
|
220 |
|
|
|
221 |
foreach($extendPrograms as $extendProgram)
|
|
|
222 |
{
|
|
|
223 |
$reportsLastWeek['programs'][$extendProgram->id] = [
|
|
|
224 |
'name' => $extendProgram->name,
|
|
|
225 |
'total' => 0,
|
|
|
226 |
'value' => 0
|
|
|
227 |
] ;
|
|
|
228 |
|
|
|
229 |
$reportsCapsuleResume['programs'][$extendProgram->id] = [
|
|
|
230 |
'name' => $extendProgram->name,
|
|
|
231 |
'total' => 0,
|
|
|
232 |
'value' => 0
|
|
|
233 |
] ;
|
|
|
234 |
|
|
|
235 |
$reportsStudentsTotal['programs'][$extendProgram->id] = [
|
|
|
236 |
'name' => $extendProgram->name,
|
|
|
237 |
'total' => 0,
|
|
|
238 |
|
|
|
239 |
] ;
|
|
|
240 |
}
|
|
|
241 |
|
|
|
242 |
|
|
|
243 |
$companyMicrolearningExtendUserPartnerMapper = CompanyMicrolearningExtendUserPartnerMapper::getInstance($this->adapter);
|
|
|
244 |
$extendPartners = $companyMicrolearningExtendUserPartnerMapper->fetchAllByCompanyId($currentCompany->id);
|
|
|
245 |
|
|
|
246 |
foreach($extendPartners as $extendPartner)
|
|
|
247 |
{
|
|
|
248 |
$reportsLastWeek['partners'][$extendPartner->id] = [
|
|
|
249 |
'name' => $extendPartner->name,
|
|
|
250 |
'total' => 0,
|
|
|
251 |
'value' => 0
|
|
|
252 |
] ;
|
|
|
253 |
|
|
|
254 |
$reportsCapsuleResume['partners'][$extendPartner->id] = [
|
|
|
255 |
'name' => $extendPartner->name,
|
|
|
256 |
'total' => 0,
|
|
|
257 |
'value' => 0
|
|
|
258 |
] ;
|
|
|
259 |
|
|
|
260 |
$reportsStudentsTotal['partners'][$extendPartner->id] = [
|
|
|
261 |
'name' => $extendPartner->name,
|
|
|
262 |
'total' => 0,
|
|
|
263 |
] ;
|
|
|
264 |
}
|
|
|
265 |
|
|
|
266 |
|
|
|
267 |
$companyMicrolearningExtendUserSectorMapper = CompanyMicrolearningExtendUserSectorMapper::getInstance($this->adapter);
|
|
|
268 |
$extendSectors = $companyMicrolearningExtendUserSectorMapper->fetchAllByCompanyId($currentCompany->id);
|
|
|
269 |
|
|
|
270 |
foreach($extendSectors as $extendSector)
|
|
|
271 |
{
|
|
|
272 |
$reportsLastWeek['sectors'][$extendSector->id] = [
|
|
|
273 |
'name' => $extendSector->name,
|
|
|
274 |
'total' => 0,
|
|
|
275 |
'value' => 0
|
|
|
276 |
] ;
|
|
|
277 |
|
|
|
278 |
$reportsCapsuleResume['sectors'][$extendSector->id] = [
|
|
|
279 |
'name' => $extendSector->name,
|
|
|
280 |
'total' => 0,
|
|
|
281 |
'value' => 0
|
|
|
282 |
] ;
|
|
|
283 |
|
|
|
284 |
$reportsStudentsTotal['sectors'][$extendSector->id] = [
|
|
|
285 |
'name' => $extendSector->name,
|
|
|
286 |
'total' => 0,
|
|
|
287 |
] ;
|
|
|
288 |
}
|
|
|
289 |
|
|
|
290 |
$companyMicrolearningExtendUserStudentTypeMapper = CompanyMicrolearningExtendUserStudentTypeMapper::getInstance($this->adapter);
|
|
|
291 |
$extendStudentTypes = $companyMicrolearningExtendUserStudentTypeMapper->fetchAllByCompanyId($currentCompany->id);
|
|
|
292 |
|
|
|
293 |
foreach($extendStudentTypes as $extendStudentType)
|
|
|
294 |
{
|
|
|
295 |
$reportsLastWeek['student_types'][$extendStudentType->id] = [
|
|
|
296 |
'name' => $extendStudentType->name,
|
|
|
297 |
'total' => 0,
|
|
|
298 |
'value' => 0
|
|
|
299 |
] ;
|
|
|
300 |
|
|
|
301 |
$reportsCapsuleResume['student_types'][$extendStudentType->id] = [
|
|
|
302 |
'name' => $extendStudentType->name,
|
|
|
303 |
'total' => 0,
|
|
|
304 |
'value' => 0
|
|
|
305 |
] ;
|
|
|
306 |
|
|
|
307 |
$reportsStudentsTotal['student_types'][$extendStudentType->id] = [
|
|
|
308 |
'name' => $extendStudentType->name,
|
|
|
309 |
'total' => 0,
|
|
|
310 |
] ;
|
|
|
311 |
}
|
|
|
312 |
|
|
|
313 |
$companyMicrolearningUserProgressMapper = CompanyMicrolearningUserProgressMapper::getInstance($this->adapter);
|
|
|
314 |
|
|
|
315 |
$minLastWeek = date('Y-m-d', strtotime(' -180 days'));
|
|
|
316 |
$maxLastWeek = date('Y-m-d');
|
|
|
317 |
$companyMicrolearningUserLogMapper = CompanyMicrolearningUserLogMapper::getInstance($this->adapter);
|
|
|
318 |
$companyUsersLogWithActivityLastWeek = $companyMicrolearningUserLogMapper->fetchAllUserIdsLastWeekByCompanyId($currentCompany->id, $minLastWeek, $maxLastWeek);
|
|
|
319 |
|
|
|
320 |
//header('Content-type: text/plain');
|
|
|
321 |
// print_r($companyUsersLogWithActivityLastWeek);
|
|
|
322 |
|
|
|
323 |
|
|
|
324 |
|
|
|
325 |
|
|
|
326 |
$date = date('Y-m-d');
|
|
|
327 |
|
|
|
328 |
$companyMicrolearningCapsuleUserMapper = CompanyMicrolearningCapsuleUserMapper::getInstance($this->adapter);
|
|
|
329 |
$user_ids = $companyMicrolearningCapsuleUserMapper->fetchAllDistinctUserIdActiveByCompanyIdAndDate($currentCompany->id, $date);
|
|
|
330 |
|
|
|
331 |
$studentsTotal = count($user_ids);
|
|
|
332 |
$studentsStarted = 0;
|
|
|
333 |
|
|
|
334 |
|
|
|
335 |
$userIdsWithAllCapsulesCompleted = [];
|
|
|
336 |
|
|
|
337 |
|
|
|
338 |
foreach($user_ids as $user_id)
|
|
|
339 |
{
|
|
|
340 |
$countSlides = $companyMicrolearningUserProgressMapper->fetchCountAllSlideCompletedByCompanyIdAndUserId($currentCompany->id, $user_id);
|
|
|
341 |
if($countSlides) {
|
|
|
342 |
$studentsStarted++;
|
|
|
343 |
}
|
|
|
344 |
|
|
|
345 |
$incompleted = false;
|
|
|
346 |
|
|
|
347 |
$capsuleUsers = $companyMicrolearningCapsuleUserMapper->fetchAllActiveByUserId($user_id);
|
|
|
348 |
foreach($capsuleUsers as $capsuleUser)
|
|
|
349 |
{
|
|
|
350 |
$userProgress = $companyMicrolearningUserProgressMapper->fetchOneByUseridAndCapsuleId($capsuleUser->user_id, $capsuleUser->capsule_id);
|
|
|
351 |
if($userProgress) {
|
|
|
352 |
if(!$userProgress->completed) {
|
|
|
353 |
$incompleted = true;
|
|
|
354 |
break;
|
|
|
355 |
}
|
|
|
356 |
} else {
|
|
|
357 |
$incompleted = true;
|
|
|
358 |
break;
|
|
|
359 |
}
|
|
|
360 |
|
|
|
361 |
|
|
|
362 |
|
|
|
363 |
}
|
|
|
364 |
|
|
|
365 |
if(!$incompleted) {
|
|
|
366 |
array_push($userIdsWithAllCapsulesCompleted, $user_id);
|
|
|
367 |
}
|
|
|
368 |
}
|
|
|
369 |
|
|
|
370 |
|
|
|
371 |
$studentsWithoutStarting = $studentsTotal - $studentsStarted;
|
|
|
372 |
$reportsLastWeek['general'] = ['total' => $studentsTotal, 'value' => count($companyUsersLogWithActivityLastWeek) ];
|
|
|
373 |
|
|
|
374 |
$reportsCapsuleResume['general'] = ['total' => $studentsTotal, 'value' => count($userIdsWithAllCapsulesCompleted) ];
|
|
|
375 |
|
|
|
376 |
|
|
|
377 |
$companyMicrolearningExtendUserMapper = CompanyMicrolearningExtendUserMapper::getInstance($this->adapter);
|
|
|
378 |
$records = $companyMicrolearningExtendUserMapper->fetchAllByCompanyId($currentCompany->id);
|
|
|
379 |
foreach($records as $record)
|
|
|
380 |
{
|
|
|
381 |
|
|
|
382 |
if($record->extend_company_id) {
|
|
|
383 |
$reportsLastWeek['companies'][$record->extend_company_id]['total'] += 1;
|
|
|
384 |
$reportsStudentsTotal['companies'][$record->extend_company_id]['total'] += 1;
|
|
|
385 |
|
|
|
386 |
if(in_array($record->user_id, $companyUsersLogWithActivityLastWeek )) {
|
|
|
387 |
$reportsLastWeek['companies'][$record->extend_company_id]['value'] += 1;
|
|
|
388 |
}
|
|
|
389 |
|
|
|
390 |
$reportsCapsuleResume['companies'][$record->extend_company_id]['total'] += 1;
|
|
|
391 |
|
|
|
392 |
if(in_array($record->user_id, $userIdsWithAllCapsulesCompleted )) {
|
|
|
393 |
$reportsCapsuleResume['companies'][$record->extend_company_id]['value'] += 1;
|
|
|
394 |
}
|
|
|
395 |
|
|
|
396 |
}
|
|
|
397 |
|
|
|
398 |
if($record->extend_function_id) {
|
|
|
399 |
$reportsLastWeek['functions'][$record->extend_function_id]['total'] += 1;
|
|
|
400 |
$reportsStudentsTotal['functions'][$record->extend_function_id]['total'] += 1;
|
|
|
401 |
|
|
|
402 |
if(in_array($record->user_id, $companyUsersLogWithActivityLastWeek )) {
|
|
|
403 |
$reportsLastWeek['functions'][$record->extend_function_id]['value'] += 1;
|
|
|
404 |
}
|
|
|
405 |
|
|
|
406 |
$reportsCapsuleResume['functions'][$record->extend_function_id]['total'] += 1;
|
|
|
407 |
if(in_array($record->user_id, $userIdsWithAllCapsulesCompleted )) {
|
|
|
408 |
$reportsCapsuleResume['functions'][$record->extend_function_id]['value'] += 1;
|
|
|
409 |
}
|
|
|
410 |
}
|
|
|
411 |
|
|
|
412 |
if($record->extend_group_id) {
|
|
|
413 |
$reportsLastWeek['groups'][$record->extend_group_id]['total'] += 1;
|
|
|
414 |
$reportsStudentsTotal['groups'][$record->extend_group_id]['total'] += 1;
|
|
|
415 |
if(in_array($record->user_id, $companyUsersLogWithActivityLastWeek )) {
|
|
|
416 |
$reportsLastWeek['groups'][$record->extend_group_id]['value'] += 1;
|
|
|
417 |
}
|
|
|
418 |
|
|
|
419 |
$reportsCapsuleResume['groups'][$record->extend_group_id]['total'] += 1;
|
|
|
420 |
if(in_array($record->user_id, $userIdsWithAllCapsulesCompleted )) {
|
|
|
421 |
$reportsCapsuleResume['groups'][$record->extend_group_id]['value'] += 1;
|
|
|
422 |
}
|
|
|
423 |
}
|
|
|
424 |
|
|
|
425 |
if($record->extend_institution_id) {
|
|
|
426 |
$reportsLastWeek['institutions'][$record->extend_institution_id]['total'] += 1;
|
|
|
427 |
$reportsStudentsTotal['institutions'][$record->extend_institution_id]['total'] += 1;
|
|
|
428 |
if(in_array($record->user_id, $companyUsersLogWithActivityLastWeek )) {
|
|
|
429 |
$reportsLastWeek['institutions'][$record->extend_institution_id]['value'] += 1;
|
|
|
430 |
}
|
|
|
431 |
|
|
|
432 |
$reportsCapsuleResume['institutions'][$record->extend_institution_id]['total'] += 1;
|
|
|
433 |
if(in_array($record->user_id, $userIdsWithAllCapsulesCompleted )) {
|
|
|
434 |
$reportsCapsuleResume['institutions'][$record->extend_institution_id]['value'] += 1;
|
|
|
435 |
}
|
|
|
436 |
}
|
|
|
437 |
|
|
|
438 |
if($record->extend_program_id) {
|
|
|
439 |
$reportsLastWeek['programs'][$record->extend_program_id]['total'] += 1;
|
|
|
440 |
$reportsStudentsTotal['programs'][$record->extend_program_id]['total'] += 1;
|
|
|
441 |
if(in_array($record->user_id, $companyUsersLogWithActivityLastWeek )) {
|
|
|
442 |
$reportsLastWeek['programs'][$record->extend_program_id]['value'] += 1;
|
|
|
443 |
}
|
|
|
444 |
|
|
|
445 |
$reportsCapsuleResume['programs'][$record->extend_program_id]['total'] += 1;
|
|
|
446 |
if(in_array($record->user_id, $userIdsWithAllCapsulesCompleted )) {
|
|
|
447 |
$reportsCapsuleResume['programs'][$record->extend_program_id]['value'] += 1;
|
|
|
448 |
}
|
|
|
449 |
}
|
|
|
450 |
|
|
|
451 |
if($record->extend_partner_id) {
|
|
|
452 |
$reportsLastWeek['partners'][$record->extend_partner_id]['total'] += 1;
|
|
|
453 |
$reportsStudentsTotal['partners'][$record->extend_partner_id]['total'] += 1;
|
|
|
454 |
if(in_array($record->user_id, $companyUsersLogWithActivityLastWeek )) {
|
|
|
455 |
$reportsLastWeek['partners'][$record->extend_partner_id]['value'] += 1;
|
|
|
456 |
}
|
|
|
457 |
|
|
|
458 |
$reportsCapsuleResume['partners'][$record->extend_partner_id]['total'] += 1;
|
|
|
459 |
if(in_array($record->user_id, $userIdsWithAllCapsulesCompleted )) {
|
|
|
460 |
$reportsCapsuleResume['partners'][$record->extend_partner_id]['value'] += 1;
|
|
|
461 |
}
|
|
|
462 |
}
|
|
|
463 |
|
|
|
464 |
if($record->extend_sector_id) {
|
|
|
465 |
$reportsLastWeek['sectors'][$record->extend_sector_id]['total'] += 1;
|
|
|
466 |
$reportsStudentsTotal['sectors'][$record->extend_sector_id]['total'] += 1;
|
|
|
467 |
if(in_array($record->user_id, $companyUsersLogWithActivityLastWeek )) {
|
|
|
468 |
$reportsLastWeek['sectors'][$record->extend_sector_id]['value'] += 1;
|
|
|
469 |
}
|
|
|
470 |
|
|
|
471 |
$reportsCapsuleResume['sectors'][$record->extend_sector_id]['total'] += 1;
|
|
|
472 |
if(in_array($record->user_id, $userIdsWithAllCapsulesCompleted )) {
|
|
|
473 |
$reportsCapsuleResume['sectors'][$record->extend_sector_id]['value'] += 1;
|
|
|
474 |
}
|
|
|
475 |
}
|
|
|
476 |
|
|
|
477 |
if($record->extend_student_type_id) {
|
|
|
478 |
$reportsLastWeek['student_types'][$record->extend_student_type_id]['total'] += 1;
|
|
|
479 |
$reportsStudentsTotal['student_types'][$record->extend_student_type_id]['total'] += 1;
|
|
|
480 |
if(in_array($record->user_id, $companyUsersLogWithActivityLastWeek )) {
|
|
|
481 |
$reportsLastWeek['student_types'][$record->extend_student_type_id]['value'] += 1;
|
|
|
482 |
}
|
|
|
483 |
|
|
|
484 |
$reportsCapsuleResume['student_types'][$record->extend_student_type_id]['total'] += 1;
|
|
|
485 |
if(in_array($record->user_id, $userIdsWithAllCapsulesCompleted )) {
|
|
|
486 |
$reportsCapsuleResume['student_types'][$record->extend_student_type_id]['value'] += 1;
|
|
|
487 |
}
|
|
|
488 |
}
|
|
|
489 |
}
|
|
|
490 |
|
|
|
491 |
|
|
|
492 |
/*
|
|
|
493 |
header('Content-type: text/plain');
|
|
|
494 |
print_r($reportsStudentsTotal); exit;
|
|
|
495 |
*/
|
|
|
496 |
|
|
|
497 |
|
|
|
498 |
$this->layout()->setTemplate('layout/layout-backend.phtml');
|
|
|
499 |
$viewModel = new ViewModel();
|
|
|
500 |
$viewModel->setTemplate('leaders-linked/microlearning-reports/overview.phtml');
|
|
|
501 |
$viewModel->setVariables([
|
|
|
502 |
'reportsLastWeek' => $reportsLastWeek,
|
|
|
503 |
'reportsCapsuleResume' => $reportsCapsuleResume,
|
|
|
504 |
'reportsStudentsTotal' => $reportsStudentsTotal,
|
|
|
505 |
'reportStudents' => [
|
|
|
506 |
'total' => $studentsTotal,
|
|
|
507 |
'started' => $studentsStarted,
|
|
|
508 |
'withoutStarting' => $studentsWithoutStarting,
|
|
|
509 |
]
|
|
|
510 |
|
|
|
511 |
]);
|
|
|
512 |
return $viewModel ;
|
|
|
513 |
}
|
|
|
514 |
|
|
|
515 |
return new JsonModel([
|
|
|
516 |
'success' => false,
|
|
|
517 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
518 |
]);
|
|
|
519 |
}
|
2126 |
efrain |
520 |
|
1 |
www |
521 |
|
187 |
efrain |
522 |
|
2 |
efrain |
523 |
public function progressAction()
|
1 |
www |
524 |
{
|
|
|
525 |
|
|
|
526 |
|
|
|
527 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
528 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
529 |
$currentCompany = $currentUserPlugin->getCompany();
|
|
|
530 |
|
|
|
531 |
|
|
|
532 |
$request = $this->getRequest();
|
|
|
533 |
if($request->isGet()) {
|
|
|
534 |
|
|
|
535 |
|
|
|
536 |
$headers = $request->getHeaders();
|
|
|
537 |
|
|
|
538 |
$isJson = false;
|
|
|
539 |
if($headers->has('Accept')) {
|
|
|
540 |
$accept = $headers->get('Accept');
|
|
|
541 |
|
|
|
542 |
$prioritized = $accept->getPrioritized();
|
|
|
543 |
|
|
|
544 |
foreach($prioritized as $key => $value) {
|
|
|
545 |
$raw = trim($value->getRaw());
|
|
|
546 |
|
|
|
547 |
if(!$isJson) {
|
|
|
548 |
$isJson = strpos($raw, 'json');
|
|
|
549 |
}
|
|
|
550 |
|
|
|
551 |
}
|
|
|
552 |
}
|
|
|
553 |
|
187 |
efrain |
554 |
|
2126 |
efrain |
555 |
|
1 |
www |
556 |
if($isJson) {
|
483 |
efrain |
557 |
|
1 |
www |
558 |
$queryMapper = QueryMapper::getInstance($this->adapter);
|
|
|
559 |
|
187 |
efrain |
560 |
$selectUsers = $queryMapper->getSql()->select();
|
|
|
561 |
$selectUsers->columns(['user_id' => new Expression('DISTINCT(user_id)')]);
|
|
|
562 |
$selectUsers->from(CompanyMicrolearningCapsuleUserMapper::_TABLE);
|
|
|
563 |
$selectUsers->where->equalTo('company_id', $currentCompany->id);
|
1 |
www |
564 |
|
187 |
efrain |
565 |
|
1 |
www |
566 |
|
187 |
efrain |
567 |
|
|
|
568 |
|
1 |
www |
569 |
$select = $queryMapper->getSql()->select();
|
|
|
570 |
$select->columns(['id' , 'uuid', 'first_name', 'last_name', 'email']);
|
187 |
efrain |
571 |
$select->from([ 'u' => UserMapper::_TABLE]);
|
1 |
www |
572 |
|
|
|
573 |
|
|
|
574 |
|
187 |
efrain |
575 |
$select->where->in('u.id', $selectUsers);
|
15386 |
efrain |
576 |
$select->where->equalTo('u.status', User::STATUS_ACTIVE);
|
483 |
efrain |
577 |
|
187 |
efrain |
578 |
$select->order(['u.first_name', 'u.last_name']);
|
|
|
579 |
|
|
|
580 |
// echo $select->getSqlString($this->adapter->platform); exit;
|
483 |
efrain |
581 |
|
187 |
efrain |
582 |
|
|
|
583 |
|
|
|
584 |
|
|
|
585 |
$companyMicrolearningProgressMapper = CompanyMicrolearningUserProgressMapper::getInstance($this->adapter);
|
|
|
586 |
$companyMicrolearningUserLogMapper = CompanyMicrolearningUserLogMapper::getInstance($this->adapter);
|
|
|
587 |
|
|
|
588 |
$companyMicrolearningCapsuleUserMapper = CompanyMicrolearningCapsuleUserMapper::getInstance($this->adapter);
|
|
|
589 |
|
|
|
590 |
// $companyMicrolearningSlideMapper = CompanyMicrolearningSlideMapper::getInstance($this->adapter);
|
|
|
591 |
|
|
|
592 |
|
|
|
593 |
|
|
|
594 |
$students = [];
|
|
|
595 |
|
1 |
www |
596 |
$records = $queryMapper->fetchAll($select);
|
187 |
efrain |
597 |
|
|
|
598 |
|
1 |
www |
599 |
foreach($records as $record)
|
|
|
600 |
{
|
187 |
efrain |
601 |
|
|
|
602 |
|
1 |
www |
603 |
$capsules = $companyMicrolearningCapsuleUserMapper->fetchAllActiveByUserId($record['id']);
|
187 |
efrain |
604 |
|
|
|
605 |
|
|
|
606 |
|
1 |
www |
607 |
$totalCapsules = count($capsules);
|
|
|
608 |
$totalCapsulesStarted = 0;
|
|
|
609 |
$totalCapsulesCompleted = 0;
|
|
|
610 |
|
|
|
611 |
|
187 |
efrain |
612 |
|
|
|
613 |
|
|
|
614 |
|
|
|
615 |
|
|
|
616 |
|
1 |
www |
617 |
foreach($capsules as $capsule)
|
|
|
618 |
{
|
|
|
619 |
$userProgress = $companyMicrolearningProgressMapper->fetchOneByUseridAndCapsuleId($capsule->user_id, $capsule->capsule_id);
|
187 |
efrain |
620 |
|
|
|
621 |
|
1 |
www |
622 |
if($userProgress) {
|
|
|
623 |
$totalCapsulesStarted++;
|
|
|
624 |
if($userProgress->completed) {
|
|
|
625 |
$totalCapsulesCompleted++;
|
187 |
efrain |
626 |
}
|
1 |
www |
627 |
}
|
187 |
efrain |
628 |
|
1 |
www |
629 |
|
|
|
630 |
|
|
|
631 |
}
|
|
|
632 |
|
187 |
efrain |
633 |
|
|
|
634 |
|
|
|
635 |
|
|
|
636 |
if($totalCapsulesCompleted > 0 && $totalCapsules > 0) {
|
|
|
637 |
$total_capsules_percentaje = intval ( ($totalCapsulesCompleted * 100 ) / $totalCapsules);
|
|
|
638 |
} else {
|
|
|
639 |
$total_capsules_percentaje = 0;
|
|
|
640 |
}
|
|
|
641 |
|
1 |
www |
642 |
|
187 |
efrain |
643 |
|
1 |
www |
644 |
$student = [
|
|
|
645 |
'uuid' => $record['uuid'],
|
|
|
646 |
'first_name' => $record['first_name'],
|
|
|
647 |
'last_name' => $record['last_name'],
|
187 |
efrain |
648 |
'email' => $record['email'],
|
|
|
649 |
|
1 |
www |
650 |
'total_capsules' => $totalCapsules,
|
187 |
efrain |
651 |
'total_capsules_incomplete' => ( $totalCapsules - $totalCapsulesCompleted ),
|
1 |
www |
652 |
'total_capsules_started' => $totalCapsulesStarted,
|
|
|
653 |
'total_capsules_completed' => $totalCapsulesCompleted,
|
187 |
efrain |
654 |
'total_capsules_percentaje' => $total_capsules_percentaje,
|
|
|
655 |
|
1 |
www |
656 |
'first_date' => '',
|
|
|
657 |
'first_time' => '',
|
|
|
658 |
'last_date' => '',
|
|
|
659 |
'last_time' => '',
|
|
|
660 |
];
|
187 |
efrain |
661 |
|
1 |
www |
662 |
$first_added_on = $companyMicrolearningUserLogMapper->fetchFirstDateByCompanyIdAndUserId($currentCompany->id, $record['id']);
|
|
|
663 |
if($first_added_on) {
|
|
|
664 |
$dt = \DateTime::createFromFormat('Y-m-d H:i:s', $first_added_on);
|
|
|
665 |
if($dt) {
|
|
|
666 |
$student['first_date'] = $dt->format('d/m/Y');
|
|
|
667 |
$student['first_time'] = $dt->format('h:i a');
|
|
|
668 |
}
|
|
|
669 |
}
|
|
|
670 |
|
|
|
671 |
$last_added_on = $companyMicrolearningUserLogMapper->fetchLastDateByCompanyIdAndUserId($currentCompany->id, $record['id']);
|
|
|
672 |
if($last_added_on) {
|
|
|
673 |
$dt = \DateTime::createFromFormat('Y-m-d H:i:s', $last_added_on);
|
|
|
674 |
if($dt) {
|
|
|
675 |
$student['last_date'] = $dt->format('d/m/Y');
|
|
|
676 |
$student['last_time'] = $dt->format('h:i a');
|
187 |
efrain |
677 |
}
|
1 |
www |
678 |
}
|
187 |
efrain |
679 |
|
1 |
www |
680 |
array_push($students, $student);
|
187 |
efrain |
681 |
|
1 |
www |
682 |
|
|
|
683 |
|
|
|
684 |
}
|
|
|
685 |
|
|
|
686 |
|
187 |
efrain |
687 |
//print_r($students);
|
1 |
www |
688 |
|
|
|
689 |
|
187 |
efrain |
690 |
|
1 |
www |
691 |
return new JsonModel([
|
187 |
efrain |
692 |
'success' => true,
|
1 |
www |
693 |
'data' => $students
|
|
|
694 |
|
187 |
efrain |
695 |
]);
|
1 |
www |
696 |
|
187 |
efrain |
697 |
} else {
|
1 |
www |
698 |
|
|
|
699 |
|
|
|
700 |
|
2126 |
efrain |
701 |
// $form = new ExtendUserMicrolearningForm($this->adapter, $currentCompany->id);
|
|
|
702 |
$form = new TopicCapsuleForm($this->adapter, $currentCompany->id, $topic_id = 0);
|
1 |
www |
703 |
|
|
|
704 |
|
|
|
705 |
$this->layout()->setTemplate('layout/layout-backend.phtml');
|
|
|
706 |
$viewModel = new ViewModel();
|
483 |
efrain |
707 |
$viewModel->setTemplate('leaders-linked/microlearning-reports/progress-for-capsule.phtml');
|
1 |
www |
708 |
$viewModel->setVariables([
|
|
|
709 |
'form' => $form
|
187 |
efrain |
710 |
]);
|
1 |
www |
711 |
return $viewModel ;
|
|
|
712 |
}
|
|
|
713 |
}
|
|
|
714 |
|
|
|
715 |
return new JsonModel([
|
|
|
716 |
'success' => false,
|
|
|
717 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
718 |
]);
|
|
|
719 |
}
|
2 |
efrain |
720 |
|
187 |
efrain |
721 |
|
2 |
efrain |
722 |
public function devicesAction()
|
|
|
723 |
{
|
|
|
724 |
|
|
|
725 |
|
|
|
726 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
727 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
728 |
$currentCompany = $currentUserPlugin->getCompany();
|
|
|
729 |
|
|
|
730 |
|
|
|
731 |
$request = $this->getRequest();
|
|
|
732 |
if($request->isGet()) {
|
|
|
733 |
|
|
|
734 |
|
|
|
735 |
$headers = $request->getHeaders();
|
|
|
736 |
|
|
|
737 |
$isJson = false;
|
|
|
738 |
if($headers->has('Accept')) {
|
|
|
739 |
$accept = $headers->get('Accept');
|
|
|
740 |
|
|
|
741 |
$prioritized = $accept->getPrioritized();
|
|
|
742 |
|
|
|
743 |
foreach($prioritized as $key => $value) {
|
|
|
744 |
$raw = trim($value->getRaw());
|
|
|
745 |
|
|
|
746 |
if(!$isJson) {
|
|
|
747 |
$isJson = strpos($raw, 'json');
|
|
|
748 |
}
|
|
|
749 |
|
|
|
750 |
}
|
|
|
751 |
}
|
|
|
752 |
|
|
|
753 |
if($isJson) {
|
|
|
754 |
|
129 |
efrain |
755 |
|
|
|
756 |
$company_id = filter_var($this->params()->fromQuery('company_id', ''), FILTER_SANITIZE_STRING);
|
|
|
757 |
$function_id = filter_var($this->params()->fromQuery('function_id', ''), FILTER_SANITIZE_STRING);
|
|
|
758 |
$group_id = filter_var($this->params()->fromQuery('group_id', ''), FILTER_SANITIZE_STRING);
|
|
|
759 |
$institution_id = filter_var($this->params()->fromQuery('institution_id', ''), FILTER_SANITIZE_STRING);
|
|
|
760 |
$program_id = filter_var($this->params()->fromQuery('program_id', ''), FILTER_SANITIZE_STRING);
|
|
|
761 |
$partner_id = filter_var($this->params()->fromQuery('partner_id', ''), FILTER_SANITIZE_STRING);
|
|
|
762 |
$sector_id = filter_var($this->params()->fromQuery('sector_id', ''), FILTER_SANITIZE_STRING);
|
|
|
763 |
$student_type_id = filter_var($this->params()->fromQuery('student_type_id', ''), FILTER_SANITIZE_STRING);
|
|
|
764 |
|
|
|
765 |
|
|
|
766 |
if($company_id) {
|
|
|
767 |
$extendUserCompanyMapper = CompanyMicrolearningExtendUserCompanyMapper::getInstance($this->adapter);
|
|
|
768 |
$extendUserCompany = $extendUserCompanyMapper->fetchOneByUuid($company_id);
|
|
|
769 |
|
|
|
770 |
if($extendUserCompany) {
|
|
|
771 |
$company_id = $extendUserCompany->id;
|
|
|
772 |
} else {
|
|
|
773 |
$company_id = 0;
|
|
|
774 |
}
|
|
|
775 |
}
|
|
|
776 |
|
|
|
777 |
if($function_id) {
|
|
|
778 |
$extendUserFunctionMapper = CompanyMicrolearningExtendUserFunctionMapper::getInstance($this->adapter);
|
|
|
779 |
$extendUserFunction = $extendUserFunctionMapper->fetchOneByUuid($function_id);
|
|
|
780 |
|
|
|
781 |
if($extendUserFunction) {
|
|
|
782 |
$function_id = $extendUserFunction->id;
|
|
|
783 |
} else {
|
|
|
784 |
$function_id = 0;
|
|
|
785 |
}
|
|
|
786 |
}
|
|
|
787 |
|
|
|
788 |
if($group_id) {
|
|
|
789 |
$extendUserGroupMapper = CompanyMicrolearningExtendUserGroupMapper::getInstance($this->adapter);
|
|
|
790 |
$extendUserGroup = $extendUserGroupMapper->fetchOneByUuid($group_id);
|
|
|
791 |
|
|
|
792 |
if($extendUserGroup) {
|
|
|
793 |
$group_id = $extendUserGroup->id;
|
|
|
794 |
} else {
|
|
|
795 |
$group_id = 0;
|
|
|
796 |
}
|
|
|
797 |
}
|
|
|
798 |
|
|
|
799 |
if($institution_id) {
|
|
|
800 |
$extendUserInstitutionMapper = CompanyMicrolearningExtendUserInstitutionMapper::getInstance($this->adapter);
|
|
|
801 |
$extendUserInstitution = $extendUserInstitutionMapper->fetchOneByUuid($institution_id);
|
|
|
802 |
if($extendUserInstitution) {
|
|
|
803 |
$institution_id = $extendUserInstitution->id;
|
|
|
804 |
} else {
|
|
|
805 |
$institution_id = 0;
|
|
|
806 |
}
|
|
|
807 |
}
|
|
|
808 |
|
|
|
809 |
if($program_id) {
|
|
|
810 |
$extendUserProgramMapper = CompanyMicrolearningExtendUserProgramMapper::getInstance($this->adapter);
|
|
|
811 |
$extendUserProgram = $extendUserProgramMapper->fetchOneByUuid($program_id);
|
|
|
812 |
|
|
|
813 |
if($extendUserProgram) {
|
|
|
814 |
$program_id = $extendUserProgram->id;
|
|
|
815 |
} else {
|
|
|
816 |
$program_id = 0;
|
|
|
817 |
}
|
|
|
818 |
|
|
|
819 |
|
|
|
820 |
}
|
|
|
821 |
|
|
|
822 |
if($partner_id) {
|
|
|
823 |
$extendUserPartnerMapper = CompanyMicrolearningExtendUserPartnerMapper::getInstance($this->adapter);
|
|
|
824 |
$extendUserPartner = $extendUserPartnerMapper->fetchOneByUuid($partner_id);
|
|
|
825 |
if($extendUserPartner) {
|
|
|
826 |
$partner_id = $extendUserPartner;
|
|
|
827 |
} else {
|
|
|
828 |
$partner_id = 0;
|
|
|
829 |
}
|
|
|
830 |
}
|
|
|
831 |
|
|
|
832 |
if($sector_id) {
|
|
|
833 |
$extendUserSectorMapper = CompanyMicrolearningExtendUserSectorMapper::getInstance($this->adapter);
|
|
|
834 |
$extendUserSector = $extendUserSectorMapper->fetchOneByUuid($sector_id);
|
|
|
835 |
if($extendUserSector) {
|
|
|
836 |
$sector_id = $extendUserSector->id;
|
|
|
837 |
} else {
|
|
|
838 |
$sector_id = 0;
|
|
|
839 |
}
|
|
|
840 |
}
|
|
|
841 |
|
|
|
842 |
if($student_type_id) {
|
|
|
843 |
$extendUserStudentTypeMapper = CompanyMicrolearningExtendUserStudentTypeMapper::getInstance($this->adapter);
|
|
|
844 |
$extendUserStudentType = $extendUserStudentTypeMapper->fetchOneByUuid($student_type_id);
|
|
|
845 |
|
|
|
846 |
if($extendUserStudentType) {
|
|
|
847 |
$student_type_id = $extendUserStudentType->id;
|
|
|
848 |
} else {
|
|
|
849 |
$student_type_id = 0;
|
|
|
850 |
}
|
|
|
851 |
}
|
|
|
852 |
|
|
|
853 |
|
|
|
854 |
|
|
|
855 |
/*
|
|
|
856 |
echo 'company_id 1 = '. $company_id . PHP_EOL;
|
|
|
857 |
echo 'function_id 1 = '. $function_id . PHP_EOL;
|
|
|
858 |
echo 'group_id 1 = '. $group_id . PHP_EOL;
|
|
|
859 |
echo 'institution_id 1 = '. $institution_id . PHP_EOL;
|
|
|
860 |
echo 'program_id 1 = '. $program_id . PHP_EOL;
|
|
|
861 |
echo 'partner_id 1 = '. $partner_id . PHP_EOL;
|
|
|
862 |
echo 'sector_id 1 = '. $sector_id . PHP_EOL;
|
|
|
863 |
echo 'student_type_id 1 = '. $student_type_id . PHP_EOL;
|
|
|
864 |
exit;
|
|
|
865 |
*/
|
|
|
866 |
|
|
|
867 |
|
2 |
efrain |
868 |
$date = date('Y-m-d');
|
|
|
869 |
$deviceMapper = DeviceMapper::getInstance($this->adapter);
|
|
|
870 |
|
|
|
871 |
|
|
|
872 |
$queryMapper = QueryMapper::getInstance($this->adapter);
|
|
|
873 |
|
|
|
874 |
$selectCapsuleUser = $queryMapper->getSql()->select();
|
|
|
875 |
$selectCapsuleUser->columns(['user_id' => new Expression('DISTINCT(user_id)') ]);
|
|
|
876 |
$selectCapsuleUser->from(CompanyMicrolearningCapsuleUserMapper::_TABLE);
|
|
|
877 |
$selectCapsuleUser->where->equalTo('company_id', $currentCompany->id);
|
|
|
878 |
$selectCapsuleUser->where->nest->equalTo('access', CompanyMicrolearningCapsuleUser::ACCESS_UNLIMITED)->or->nest()
|
|
|
879 |
->equalTo('access', CompanyMicrolearningCapsuleUser::ACCESS_PAY_PERIOD)
|
|
|
880 |
->and->lessThanOrEqualTo(new Expression('DATE(paid_from)'), $date)
|
|
|
881 |
->and->greaterThanOrEqualTo(new Expression('DATE(paid_to)'), $date )->unnest()->unnest();
|
|
|
882 |
|
|
|
883 |
//echo $select->getSqlString($this->adapter->platform); exit;
|
|
|
884 |
|
|
|
885 |
$select = $queryMapper->getSql()->select();
|
|
|
886 |
$select->columns(['id' , 'uuid', 'first_name', 'last_name', 'email']);
|
129 |
efrain |
887 |
$select->from([ 'u' => UserMapper::_TABLE]);
|
|
|
888 |
if( $company_id || $function_id || $group_id || $institution_id || $program_id || $partner_id || $sector_id || $student_type_id ) {
|
|
|
889 |
|
187 |
efrain |
890 |
$select->join(['e' => CompanyMicrolearningExtendUserMapper::_TABLE], 'e.user_id = u.id', []);
|
129 |
efrain |
891 |
|
|
|
892 |
}
|
2 |
efrain |
893 |
|
129 |
efrain |
894 |
$select->where->in('u.id', $selectCapsuleUser);
|
|
|
895 |
if($company_id) {
|
|
|
896 |
$select->where->equalTo('e.extend_company_id', $company_id);
|
|
|
897 |
}
|
2 |
efrain |
898 |
|
129 |
efrain |
899 |
if($function_id) {
|
|
|
900 |
$select->where->equalTo('e.extend_function_id', $function_id);
|
|
|
901 |
|
|
|
902 |
}
|
|
|
903 |
if($group_id) {
|
|
|
904 |
$select->where->equalTo('e.extend_group_id', $group_id);
|
|
|
905 |
}
|
2 |
efrain |
906 |
|
129 |
efrain |
907 |
if($institution_id) {
|
|
|
908 |
$select->where->equalTo('e.extend_institution_id', $institution_id);
|
|
|
909 |
}
|
|
|
910 |
|
|
|
911 |
if($program_id) {
|
|
|
912 |
$select->where->equalTo('e.extend_program_id', $program_id);
|
|
|
913 |
}
|
|
|
914 |
|
|
|
915 |
if($partner_id) {
|
|
|
916 |
$select->where->equalTo('e.extend_partner_id', $partner_id);
|
|
|
917 |
}
|
|
|
918 |
|
|
|
919 |
if($sector_id) {
|
|
|
920 |
$select->where->equalTo('e.extend_sector_id', $sector_id);
|
|
|
921 |
}
|
|
|
922 |
|
|
|
923 |
if($student_type_id) {
|
|
|
924 |
$select->where->equalTo('e.extend_student_type_id', $student_type_id);
|
|
|
925 |
}
|
15386 |
efrain |
926 |
|
|
|
927 |
$select->where->equalTo('u.status', User::STATUS_ACTIVE);
|
129 |
efrain |
928 |
$select->order(['u.first_name', 'u.last_name']);
|
|
|
929 |
|
|
|
930 |
|
|
|
931 |
|
2 |
efrain |
932 |
$students = [];
|
|
|
933 |
$records = $queryMapper->fetchAll($select);
|
|
|
934 |
foreach($records as $record)
|
|
|
935 |
{
|
|
|
936 |
|
|
|
937 |
|
|
|
938 |
$record_devices = $deviceMapper->fetchAllByUserId($record['id']);
|
|
|
939 |
|
|
|
940 |
$devices = [];
|
|
|
941 |
foreach($record_devices as $device)
|
|
|
942 |
{
|
|
|
943 |
/*if($device->application_id != Application::LEADERSLINKED) {
|
|
|
944 |
continue;
|
|
|
945 |
}*/
|
|
|
946 |
|
|
|
947 |
$dt = \DateTime::createFromFormat('Y-m-d H:i:s', $device->updated_on);
|
|
|
948 |
|
|
|
949 |
array_push($devices, [
|
|
|
950 |
'brand' => $device->brand,
|
|
|
951 |
'manufacturer' => $device->manufacturer,
|
|
|
952 |
'model' => $device->model,
|
|
|
953 |
'platform' => $device->platform,
|
|
|
954 |
'version' => $device->version,
|
|
|
955 |
'token' => $device->token ? 'LABEL_YES' : 'LABEL_NO',
|
|
|
956 |
'updated_on' => $dt->format('d/m/Y h:i a')
|
|
|
957 |
]);
|
|
|
958 |
}
|
|
|
959 |
|
187 |
efrain |
960 |
if(empty($devices)) {
|
|
|
961 |
continue;
|
|
|
962 |
|
|
|
963 |
}
|
|
|
964 |
|
2 |
efrain |
965 |
|
|
|
966 |
$student = [
|
|
|
967 |
'uuid' => $record['uuid'],
|
15387 |
efrain |
968 |
'first_name' => ucwords(strtolower($record['first_name'])),
|
|
|
969 |
'last_name' => ucwords(strtolower($record['last_name'])),
|
|
|
970 |
'email' => strtolower($record['email']),
|
2 |
efrain |
971 |
'devices' => $devices
|
|
|
972 |
];
|
|
|
973 |
|
|
|
974 |
array_push($students, $student);
|
|
|
975 |
|
|
|
976 |
|
|
|
977 |
}
|
|
|
978 |
|
|
|
979 |
|
|
|
980 |
|
|
|
981 |
|
|
|
982 |
return new JsonModel([
|
|
|
983 |
'success' => true,
|
129 |
efrain |
984 |
'data' => $students,
|
|
|
985 |
'sql' => $select->getSqlString($this->adapter->platform),
|
2 |
efrain |
986 |
|
|
|
987 |
]);
|
|
|
988 |
|
|
|
989 |
} else {
|
|
|
990 |
|
|
|
991 |
|
|
|
992 |
|
|
|
993 |
$form = new ExtendUserMicrolearningForm($this->adapter, $currentCompany->id);
|
|
|
994 |
|
|
|
995 |
|
|
|
996 |
$this->layout()->setTemplate('layout/layout-backend.phtml');
|
|
|
997 |
$viewModel = new ViewModel();
|
|
|
998 |
$viewModel->setTemplate('leaders-linked/microlearning-reports/devices.phtml');
|
|
|
999 |
$viewModel->setVariables([
|
|
|
1000 |
'form' => $form
|
|
|
1001 |
]);
|
|
|
1002 |
return $viewModel ;
|
|
|
1003 |
}
|
|
|
1004 |
}
|
|
|
1005 |
|
|
|
1006 |
return new JsonModel([
|
|
|
1007 |
'success' => false,
|
|
|
1008 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
1009 |
]);
|
|
|
1010 |
}
|
187 |
efrain |
1011 |
|
|
|
1012 |
|
|
|
1013 |
public function comentsForCapsulesAction()
|
|
|
1014 |
{
|
|
|
1015 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
1016 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
1017 |
$currentCompany = $currentUserPlugin->getCompany();
|
|
|
1018 |
|
|
|
1019 |
$request = $this->getRequest();
|
|
|
1020 |
|
|
|
1021 |
if($request->isGet())
|
|
|
1022 |
{
|
|
|
1023 |
|
|
|
1024 |
$headers = $request->getHeaders();
|
|
|
1025 |
|
|
|
1026 |
$isJson = false;
|
|
|
1027 |
if($headers->has('Accept')) {
|
|
|
1028 |
$accept = $headers->get('Accept');
|
|
|
1029 |
|
|
|
1030 |
$prioritized = $accept->getPrioritized();
|
|
|
1031 |
|
|
|
1032 |
foreach($prioritized as $key => $value) {
|
|
|
1033 |
$raw = trim($value->getRaw());
|
|
|
1034 |
|
|
|
1035 |
if(!$isJson) {
|
|
|
1036 |
$isJson = strpos($raw, 'json');
|
|
|
1037 |
}
|
|
|
1038 |
|
|
|
1039 |
}
|
|
|
1040 |
}
|
|
|
1041 |
|
|
|
1042 |
if($isJson) {
|
|
|
1043 |
$topic_uuid = filter_var($this->params()->fromQuery('topic_uuid'), FILTER_SANITIZE_STRING);
|
|
|
1044 |
$capsule_uuid = filter_var($this->params()->fromQuery('capsule_uuid'), FILTER_SANITIZE_STRING);
|
|
|
1045 |
|
|
|
1046 |
$data = [
|
|
|
1047 |
'items' => [] ,
|
|
|
1048 |
'total' => 0,
|
|
|
1049 |
|
|
|
1050 |
];
|
|
|
1051 |
|
|
|
1052 |
|
|
|
1053 |
if(!$topic_uuid) {
|
|
|
1054 |
return new JsonModel([
|
|
|
1055 |
'success' => true,
|
|
|
1056 |
'data' => $data
|
|
|
1057 |
]);
|
|
|
1058 |
|
|
|
1059 |
}
|
|
|
1060 |
|
|
|
1061 |
|
|
|
1062 |
$topicMapper = CompanyMicrolearningTopicMapper::getInstance($this->adapter);
|
|
|
1063 |
$topic = $topicMapper->fetchOneByUuid($topic_uuid);
|
|
|
1064 |
if(!$topic) {
|
|
|
1065 |
return new JsonModel([
|
|
|
1066 |
'success' => true,
|
|
|
1067 |
'data' => 'ERROR_TOPIC_NOT_FOUND'
|
|
|
1068 |
]);
|
|
|
1069 |
}
|
|
|
1070 |
|
|
|
1071 |
if($topic->company_id != $currentCompany->id) {
|
|
|
1072 |
return new JsonModel([
|
|
|
1073 |
'success' => true,
|
|
|
1074 |
'data' => 'ERROR_UNAUTHORIZED'
|
|
|
1075 |
]);
|
|
|
1076 |
}
|
|
|
1077 |
|
|
|
1078 |
|
|
|
1079 |
|
|
|
1080 |
if(!$capsule_uuid) {
|
|
|
1081 |
$capsuleMapper = CompanyMicrolearningCapsuleMapper::getInstance($this->adapter);
|
|
|
1082 |
$records = $capsuleMapper->fetchAllByCompanyIdAndTopicId($topic->company_id, $topic->id);
|
|
|
1083 |
|
|
|
1084 |
$capsules = [];
|
|
|
1085 |
foreach($records as $record)
|
|
|
1086 |
{
|
|
|
1087 |
if(!$capsule_uuid) {
|
|
|
1088 |
$capsule_uuid = $record->uuid;
|
|
|
1089 |
}
|
|
|
1090 |
|
|
|
1091 |
$capsules[ $record->uuid ] = $record->name;
|
|
|
1092 |
}
|
|
|
1093 |
|
|
|
1094 |
$data['capsules'] = $capsules;
|
|
|
1095 |
}
|
|
|
1096 |
|
|
|
1097 |
if(!$capsule_uuid) {
|
|
|
1098 |
return new JsonModel([
|
|
|
1099 |
'success' => true,
|
|
|
1100 |
'data' => $data
|
|
|
1101 |
]);
|
|
|
1102 |
|
|
|
1103 |
}
|
|
|
1104 |
|
|
|
1105 |
$capsuleMapper = CompanyMicrolearningCapsuleMapper::getInstance($this->adapter);
|
|
|
1106 |
$capsule = $capsuleMapper->fetchOneByUuid($capsule_uuid);
|
|
|
1107 |
|
|
|
1108 |
|
|
|
1109 |
|
|
|
1110 |
if(!$capsule) {
|
|
|
1111 |
return new JsonModel([
|
|
|
1112 |
'success' => true,
|
|
|
1113 |
'data' => 'ERROR_CAPSULE_NOT_FOUND'
|
|
|
1114 |
]);
|
|
|
1115 |
}
|
|
|
1116 |
|
|
|
1117 |
if($capsule->topic_id != $topic->id) {
|
|
|
1118 |
return new JsonModel([
|
|
|
1119 |
'success' => true,
|
|
|
1120 |
'data' => 'ERROR_UNAUTHORIZED'
|
|
|
1121 |
]);
|
|
|
1122 |
}
|
|
|
1123 |
|
|
|
1124 |
|
|
|
1125 |
$search = $this->params()->fromQuery('search', []);
|
|
|
1126 |
$search = empty($search['value']) ? '' : filter_var($search['value'], FILTER_SANITIZE_STRING);
|
|
|
1127 |
|
|
|
1128 |
$page = intval($this->params()->fromQuery('start', 1), 10);
|
|
|
1129 |
$records_x_page = intval($this->params()->fromQuery('length', 10), 10);
|
|
|
1130 |
$order = $this->params()->fromQuery('order', []);
|
|
|
1131 |
$order_field = empty($order[0]['column']) ? 99 : intval($order[0]['column'], 10);
|
|
|
1132 |
$order_direction = empty($order[0]['dir']) ? 'ASC' : strtoupper(filter_var( $order[0]['dir'], FILTER_SANITIZE_STRING));
|
|
|
1133 |
|
|
|
1134 |
$fields = ['uuid', 'first_name', 'last_name', 'email', 'rating', 'comment', 'added_on'];
|
|
|
1135 |
$order_field = isset($fields[$order_field]) ? $fields[$order_field] : 'added_on';
|
|
|
1136 |
|
|
|
1137 |
if(!in_array($order_direction, ['ASC', 'DESC'])) {
|
|
|
1138 |
$order_direction = 'DESC';
|
|
|
1139 |
}
|
|
|
1140 |
|
|
|
1141 |
|
|
|
1142 |
$queryMapper = QueryMapper::getInstance($this->adapter);
|
|
|
1143 |
$sql = $queryMapper->getSql();
|
|
|
1144 |
$select = $sql->select();
|
|
|
1145 |
$select->columns(['access', 'paid_from', 'paid_to', 'added_on', 'updated_on']);
|
|
|
1146 |
$select->from(['tb1' => CompanyMicrolearningCapsuleCommentMapper::_TABLE] );
|
|
|
1147 |
$select->join(['tb2' => UserMapper::_TABLE], 'tb1.user_id = tb2.id', ['uuid', 'first_name', 'last_name', 'email']);
|
|
|
1148 |
$select->where->equalTo('tb1.company_id', $capsule->company_id);
|
|
|
1149 |
$select->where->equalTo('tb1.topic_id', $capsule->topic_id);
|
|
|
1150 |
$select->where->equalTo('tb1.capsule_id', $capsule->id);
|
|
|
1151 |
|
|
|
1152 |
if($search) {
|
|
|
1153 |
$select->where->nest()
|
|
|
1154 |
->like('first_name', '%' . $search . '%')
|
|
|
1155 |
->or->like('last_name', '%' . $search . '%')
|
|
|
1156 |
->or->like('email', '%' . $search . '%')
|
|
|
1157 |
->unnest();
|
|
|
1158 |
|
|
|
1159 |
}
|
|
|
1160 |
|
|
|
1161 |
|
|
|
1162 |
$select->order($order_field . ' ' . $order_direction);
|
|
|
1163 |
|
|
|
1164 |
$hydrator = new ArraySerializableHydrator();
|
|
|
1165 |
$resultset = new HydratingResultSet($hydrator);
|
|
|
1166 |
|
|
|
1167 |
$adapter = new DbSelect($select, $sql, $resultset);
|
|
|
1168 |
$paginator = new Paginator($adapter);
|
|
|
1169 |
$paginator->setItemCountPerPage($records_x_page);
|
|
|
1170 |
$paginator->setCurrentPageNumber($page);
|
|
|
1171 |
|
|
|
1172 |
|
|
|
1173 |
$items = [ ];
|
|
|
1174 |
$records = $paginator->getCurrentItems();
|
|
|
1175 |
foreach($records as $record)
|
|
|
1176 |
{
|
|
|
1177 |
|
|
|
1178 |
|
|
|
1179 |
|
|
|
1180 |
$dt_added_on = \DateTime::createFromFormat('Y-m-d H:i:s', $record['added_on']);
|
|
|
1181 |
$added_on = $dt_added_on->format('d/m/Y h:i a');
|
|
|
1182 |
|
|
|
1183 |
|
|
|
1184 |
$item = [
|
|
|
1185 |
'uuid' => $record['uuid'],
|
15387 |
efrain |
1186 |
'first_name' => ucwords(strtolower($record['first_name'])),
|
|
|
1187 |
'last_name' => ucwords(strtolower($record['last_name'])),
|
|
|
1188 |
'email' => strtolower($record['email']),
|
187 |
efrain |
1189 |
'rating' => $record['rating'],
|
|
|
1190 |
'text' => $record['text'],
|
|
|
1191 |
'added_on' => $added_on,
|
|
|
1192 |
];
|
|
|
1193 |
|
|
|
1194 |
|
|
|
1195 |
array_push($items, $item);
|
|
|
1196 |
|
|
|
1197 |
|
|
|
1198 |
}
|
|
|
1199 |
|
|
|
1200 |
$data['items'] = $items;
|
|
|
1201 |
$data['total'] = $paginator->getTotalItemCount();
|
|
|
1202 |
|
|
|
1203 |
|
|
|
1204 |
return new JsonModel([
|
|
|
1205 |
'success' => true,
|
|
|
1206 |
'data' => $data
|
|
|
1207 |
]);
|
|
|
1208 |
} else {
|
|
|
1209 |
$topicMapper = CompanyMicrolearningTopicMapper::getInstance($this->adapter);
|
|
|
1210 |
$topics = $topicMapper->fetchAllByCompanyId($currentCompany->id);
|
|
|
1211 |
|
|
|
1212 |
if($topics) {
|
|
|
1213 |
$topic_id = $topics[0]->id;
|
|
|
1214 |
} else {
|
|
|
1215 |
$topic_id = 0;
|
|
|
1216 |
}
|
|
|
1217 |
|
|
|
1218 |
|
|
|
1219 |
$form = new TopicCapsuleForm($this->adapter, $currentCompany->id, $topic_id);
|
|
|
1220 |
|
|
|
1221 |
|
|
|
1222 |
|
|
|
1223 |
$this->layout()->setTemplate('layout/layout-backend');
|
|
|
1224 |
$viewModel = new ViewModel();
|
|
|
1225 |
$viewModel->setTemplate('leaders-linked/microlearning-reports/comments-for-capsule.phtml');
|
|
|
1226 |
$viewModel->setVariables([
|
|
|
1227 |
'form' => $form,
|
|
|
1228 |
]);
|
|
|
1229 |
|
|
|
1230 |
return $viewModel ;
|
|
|
1231 |
}
|
|
|
1232 |
|
|
|
1233 |
} else {
|
|
|
1234 |
return new JsonModel([
|
|
|
1235 |
'success' => false,
|
|
|
1236 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
1237 |
]);
|
|
|
1238 |
}
|
|
|
1239 |
}
|
|
|
1240 |
|
|
|
1241 |
|
|
|
1242 |
|
14612 |
efrain |
1243 |
public function progressForCapsuleAction()
|
483 |
efrain |
1244 |
{
|
|
|
1245 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
1246 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
1247 |
$currentCompany = $currentUserPlugin->getCompany();
|
|
|
1248 |
|
|
|
1249 |
$request = $this->getRequest();
|
|
|
1250 |
|
|
|
1251 |
if($request->isGet())
|
|
|
1252 |
{
|
|
|
1253 |
|
|
|
1254 |
$headers = $request->getHeaders();
|
|
|
1255 |
|
|
|
1256 |
$isJson = false;
|
|
|
1257 |
if($headers->has('Accept')) {
|
|
|
1258 |
$accept = $headers->get('Accept');
|
|
|
1259 |
|
|
|
1260 |
$prioritized = $accept->getPrioritized();
|
|
|
1261 |
|
|
|
1262 |
foreach($prioritized as $key => $value) {
|
|
|
1263 |
$raw = trim($value->getRaw());
|
|
|
1264 |
|
|
|
1265 |
if(!$isJson) {
|
|
|
1266 |
$isJson = strpos($raw, 'json');
|
|
|
1267 |
}
|
|
|
1268 |
|
|
|
1269 |
}
|
|
|
1270 |
}
|
14612 |
efrain |
1271 |
|
|
|
1272 |
|
483 |
efrain |
1273 |
if($isJson) {
|
15386 |
efrain |
1274 |
$acl = $this->getEvent()->getViewModel()->getVariable('acl');
|
|
|
1275 |
$allowDownload = $acl->isAllowed($currentUser->usertype_id, 'microlearning/reports/progress-for-capsule/excel');
|
14612 |
efrain |
1276 |
|
483 |
efrain |
1277 |
$topic_uuid = filter_var($this->params()->fromQuery('topic_uuid'), FILTER_SANITIZE_STRING);
|
|
|
1278 |
$capsule_uuid = filter_var($this->params()->fromQuery('capsule_uuid'), FILTER_SANITIZE_STRING);
|
15386 |
efrain |
1279 |
|
483 |
efrain |
1280 |
$topicMapper = CompanyMicrolearningTopicMapper::getInstance($this->adapter);
|
|
|
1281 |
$topic = $topicMapper->fetchOneByUuid($topic_uuid);
|
|
|
1282 |
if(!$topic) {
|
|
|
1283 |
return new JsonModel([
|
15386 |
efrain |
1284 |
'success' => false,
|
483 |
efrain |
1285 |
'data' => 'ERROR_TOPIC_NOT_FOUND'
|
|
|
1286 |
]);
|
|
|
1287 |
}
|
|
|
1288 |
|
|
|
1289 |
if($topic->company_id != $currentCompany->id) {
|
|
|
1290 |
return new JsonModel([
|
15386 |
efrain |
1291 |
'success' => false,
|
483 |
efrain |
1292 |
'data' => 'ERROR_UNAUTHORIZED'
|
|
|
1293 |
]);
|
|
|
1294 |
}
|
|
|
1295 |
|
14612 |
efrain |
1296 |
|
15386 |
efrain |
1297 |
$data = [
|
|
|
1298 |
|
|
|
1299 |
'items' => [],
|
|
|
1300 |
'link_download' => '',
|
|
|
1301 |
|
|
|
1302 |
];
|
483 |
efrain |
1303 |
|
|
|
1304 |
if(!$capsule_uuid) {
|
15386 |
efrain |
1305 |
|
|
|
1306 |
$data['capsules'] = [];
|
|
|
1307 |
|
483 |
efrain |
1308 |
$capsuleMapper = CompanyMicrolearningCapsuleMapper::getInstance($this->adapter);
|
|
|
1309 |
$records = $capsuleMapper->fetchAllByCompanyIdAndTopicId($topic->company_id, $topic->id);
|
|
|
1310 |
|
15386 |
efrain |
1311 |
|
483 |
efrain |
1312 |
foreach($records as $record)
|
|
|
1313 |
{
|
|
|
1314 |
if(!$capsule_uuid) {
|
|
|
1315 |
$capsule_uuid = $record->uuid;
|
|
|
1316 |
}
|
|
|
1317 |
|
15386 |
efrain |
1318 |
$data['capsules'][ $record->uuid ] = $record->name;
|
483 |
efrain |
1319 |
}
|
|
|
1320 |
|
15386 |
efrain |
1321 |
$data['capsule_selected'] = $capsule_uuid;
|
|
|
1322 |
|
|
|
1323 |
|
483 |
efrain |
1324 |
}
|
14612 |
efrain |
1325 |
|
|
|
1326 |
|
483 |
efrain |
1327 |
|
|
|
1328 |
$capsuleMapper = CompanyMicrolearningCapsuleMapper::getInstance($this->adapter);
|
|
|
1329 |
$capsule = $capsuleMapper->fetchOneByUuid($capsule_uuid);
|
|
|
1330 |
|
|
|
1331 |
|
|
|
1332 |
|
|
|
1333 |
if(!$capsule) {
|
|
|
1334 |
return new JsonModel([
|
|
|
1335 |
'success' => true,
|
|
|
1336 |
'data' => 'ERROR_CAPSULE_NOT_FOUND'
|
|
|
1337 |
]);
|
|
|
1338 |
}
|
|
|
1339 |
|
|
|
1340 |
if($capsule->topic_id != $topic->id) {
|
|
|
1341 |
return new JsonModel([
|
|
|
1342 |
'success' => true,
|
|
|
1343 |
'data' => 'ERROR_UNAUTHORIZED'
|
|
|
1344 |
]);
|
|
|
1345 |
}
|
|
|
1346 |
|
14612 |
efrain |
1347 |
|
15386 |
efrain |
1348 |
|
483 |
efrain |
1349 |
|
|
|
1350 |
|
|
|
1351 |
$queryMapper = QueryMapper::getInstance($this->adapter);
|
|
|
1352 |
$sql = $queryMapper->getSql();
|
|
|
1353 |
$select = $sql->select();
|
15386 |
efrain |
1354 |
$select->columns(['user_id']);
|
|
|
1355 |
$select->from(['tb1' => CompanyMicrolearningCapsuleUserMapper::_TABLE] );
|
483 |
efrain |
1356 |
$select->join(['tb2' => UserMapper::_TABLE], 'tb1.user_id = tb2.id', ['uuid', 'first_name', 'last_name', 'email']);
|
|
|
1357 |
$select->where->equalTo('tb1.company_id', $capsule->company_id);
|
|
|
1358 |
$select->where->equalTo('tb1.topic_id', $capsule->topic_id);
|
|
|
1359 |
$select->where->equalTo('tb1.capsule_id', $capsule->id);
|
15386 |
efrain |
1360 |
$select->where->equalTo('tb2.status', User::STATUS_ACTIVE);
|
14612 |
efrain |
1361 |
$select->order('first_name ASC, last_name ASC');
|
15386 |
efrain |
1362 |
|
|
|
1363 |
$user_ids = [];
|
|
|
1364 |
$records = $queryMapper->fetchAll($select);
|
|
|
1365 |
|
|
|
1366 |
foreach($records as $record)
|
|
|
1367 |
{
|
|
|
1368 |
$user_id = $record['user_id'];
|
|
|
1369 |
|
|
|
1370 |
if(in_array($user_id, $user_ids)) {
|
|
|
1371 |
continue;
|
|
|
1372 |
}
|
|
|
1373 |
|
|
|
1374 |
array_push($user_ids, $user_id);
|
|
|
1375 |
|
|
|
1376 |
$item = [
|
|
|
1377 |
'uuid' => $record['uuid'],
|
15387 |
efrain |
1378 |
'first_name' => ucwords(strtolower($record['first_name'])),
|
|
|
1379 |
'last_name' => ucwords(strtolower($record['last_name'])),
|
|
|
1380 |
'email' => strtolower($record['email']),
|
15386 |
efrain |
1381 |
'progress' => 0,
|
|
|
1382 |
'total_slides' => 0,
|
|
|
1383 |
'view_slides' => 0,
|
|
|
1384 |
'completed' => 0,
|
|
|
1385 |
'returning_after_completed' => 0,
|
|
|
1386 |
'added_on' => '',
|
|
|
1387 |
'updated_on' => ''
|
|
|
1388 |
|
|
|
1389 |
];
|
|
|
1390 |
|
|
|
1391 |
$items[ $user_id ] = $item;
|
|
|
1392 |
}
|
483 |
efrain |
1393 |
|
15386 |
efrain |
1394 |
|
|
|
1395 |
$select->columns(['user_id', 'progress', 'total_slides', 'view_slides', 'completed', 'returning_after_completed', 'added_on', 'updated_on']);
|
|
|
1396 |
$select->from(['tb1' => CompanyMicrolearningUserProgressMapper::_TABLE] );
|
|
|
1397 |
$select->where->equalTo('tb1.company_id', $capsule->company_id);
|
|
|
1398 |
$select->where->equalTo('tb1.type', CompanyMicrolearningUserProgress::TYPE_CAPSULE);
|
|
|
1399 |
$select->where->equalTo('tb1.topic_id', $capsule->topic_id);
|
|
|
1400 |
$select->where->equalTo('tb1.capsule_id', $capsule->id);
|
|
|
1401 |
$select->where->in('tb1.user_id', $user_ids);
|
|
|
1402 |
|
14612 |
efrain |
1403 |
|
|
|
1404 |
$records = $queryMapper->fetchAll($select);
|
483 |
efrain |
1405 |
foreach($records as $record)
|
|
|
1406 |
{
|
15386 |
efrain |
1407 |
$user_id = $record['user_id'];
|
483 |
efrain |
1408 |
|
|
|
1409 |
|
|
|
1410 |
$dt_added_on = \DateTime::createFromFormat('Y-m-d H:i:s', $record['added_on']);
|
|
|
1411 |
$added_on = $dt_added_on->format('d/m/Y h:i a');
|
|
|
1412 |
|
14612 |
efrain |
1413 |
$dt_updated_on = \DateTime::createFromFormat('Y-m-d H:i:s', $record['updated_on']);
|
|
|
1414 |
$updated_on = $dt_updated_on->format('d/m/Y h:i a');
|
483 |
efrain |
1415 |
|
14612 |
efrain |
1416 |
|
15386 |
efrain |
1417 |
$items[$user_id]['completed'] = $record['completed'];
|
|
|
1418 |
$items[$user_id]['progress'] = $record['progress'];
|
|
|
1419 |
$items[$user_id]['total_slides'] = $record['total_slides'];
|
|
|
1420 |
$items[$user_id]['view_slides'] = $record['view_slides'];
|
|
|
1421 |
$items[$user_id]['returning_after_completed'] = $record['returning_after_completed'];
|
|
|
1422 |
$items[$user_id]['added_on'] = $added_on;
|
|
|
1423 |
$items[$user_id]['updated_on'] = $updated_on;
|
483 |
efrain |
1424 |
|
|
|
1425 |
|
|
|
1426 |
|
|
|
1427 |
}
|
|
|
1428 |
|
15386 |
efrain |
1429 |
$data['items'] = array_values($items);
|
483 |
efrain |
1430 |
|
15386 |
efrain |
1431 |
if($allowDownload) {
|
|
|
1432 |
$data['link_download'] = $this->url()->fromRoute('microlearning/reports/progress-for-capsule/excel', [], ['query' => ['topic_uuid' => $topic->uuid, 'capsule_uuid' => $capsule->uuid] ]);
|
|
|
1433 |
}
|
483 |
efrain |
1434 |
|
15386 |
efrain |
1435 |
|
|
|
1436 |
|
483 |
efrain |
1437 |
return new JsonModel([
|
|
|
1438 |
'success' => true,
|
|
|
1439 |
'data' => $data
|
|
|
1440 |
]);
|
|
|
1441 |
} else {
|
|
|
1442 |
$topicMapper = CompanyMicrolearningTopicMapper::getInstance($this->adapter);
|
|
|
1443 |
$topics = $topicMapper->fetchAllByCompanyId($currentCompany->id);
|
|
|
1444 |
|
|
|
1445 |
if($topics) {
|
|
|
1446 |
$topic_id = $topics[0]->id;
|
|
|
1447 |
} else {
|
|
|
1448 |
$topic_id = 0;
|
|
|
1449 |
}
|
|
|
1450 |
|
|
|
1451 |
|
|
|
1452 |
$form = new TopicCapsuleForm($this->adapter, $currentCompany->id, $topic_id);
|
|
|
1453 |
|
|
|
1454 |
|
|
|
1455 |
|
|
|
1456 |
$this->layout()->setTemplate('layout/layout-backend');
|
|
|
1457 |
$viewModel = new ViewModel();
|
14612 |
efrain |
1458 |
$viewModel->setTemplate('leaders-linked/microlearning-reports/progress-for-capsule.phtml');
|
483 |
efrain |
1459 |
$viewModel->setVariables([
|
|
|
1460 |
'form' => $form,
|
|
|
1461 |
]);
|
|
|
1462 |
|
|
|
1463 |
return $viewModel ;
|
|
|
1464 |
}
|
|
|
1465 |
|
|
|
1466 |
} else {
|
|
|
1467 |
return new JsonModel([
|
|
|
1468 |
'success' => false,
|
|
|
1469 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
1470 |
]);
|
|
|
1471 |
}
|
|
|
1472 |
}
|
|
|
1473 |
|
15386 |
efrain |
1474 |
public function progressForCapsuleExcelAction()
|
|
|
1475 |
{
|
|
|
1476 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
1477 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
1478 |
$currentCompany = $currentUserPlugin->getCompany();
|
|
|
1479 |
|
|
|
1480 |
$request = $this->getRequest();
|
|
|
1481 |
|
|
|
1482 |
if($request->isGet())
|
|
|
1483 |
{
|
|
|
1484 |
|
|
|
1485 |
$topic_uuid = filter_var($this->params()->fromQuery('topic_uuid'), FILTER_SANITIZE_STRING);
|
|
|
1486 |
$capsule_uuid = filter_var($this->params()->fromQuery('capsule_uuid'), FILTER_SANITIZE_STRING);
|
|
|
1487 |
|
|
|
1488 |
|
|
|
1489 |
$topicMapper = CompanyMicrolearningTopicMapper::getInstance($this->adapter);
|
|
|
1490 |
$topic = $topicMapper->fetchOneByUuid($topic_uuid);
|
|
|
1491 |
if(!$topic) {
|
|
|
1492 |
return new JsonModel([
|
|
|
1493 |
'success' => false,
|
|
|
1494 |
'data' => 'ERROR_TOPIC_NOT_FOUND'
|
|
|
1495 |
]);
|
|
|
1496 |
}
|
|
|
1497 |
|
|
|
1498 |
if($topic->company_id != $currentCompany->id) {
|
|
|
1499 |
return new JsonModel([
|
|
|
1500 |
'success' => false,
|
|
|
1501 |
'data' => 'ERROR_UNAUTHORIZED'
|
|
|
1502 |
]);
|
|
|
1503 |
}
|
|
|
1504 |
|
|
|
1505 |
$capsuleMapper = CompanyMicrolearningCapsuleMapper::getInstance($this->adapter);
|
|
|
1506 |
$capsule = $capsuleMapper->fetchOneByUuid($capsule_uuid);
|
|
|
1507 |
|
|
|
1508 |
|
|
|
1509 |
|
|
|
1510 |
if(!$capsule) {
|
|
|
1511 |
return new JsonModel([
|
|
|
1512 |
'success' => false,
|
|
|
1513 |
'data' => 'ERROR_CAPSULE_NOT_FOUND'
|
|
|
1514 |
]);
|
|
|
1515 |
}
|
|
|
1516 |
|
|
|
1517 |
if($capsule->topic_id != $topic->id) {
|
|
|
1518 |
return new JsonModel([
|
|
|
1519 |
'success' => false,
|
|
|
1520 |
'data' => 'ERROR_UNAUTHORIZED'
|
|
|
1521 |
]);
|
|
|
1522 |
}
|
|
|
1523 |
|
|
|
1524 |
|
|
|
1525 |
|
|
|
1526 |
|
|
|
1527 |
$queryMapper = QueryMapper::getInstance($this->adapter);
|
|
|
1528 |
$sql = $queryMapper->getSql();
|
|
|
1529 |
$select = $sql->select();
|
|
|
1530 |
$select->columns(['user_id']);
|
|
|
1531 |
$select->from(['tb1' => CompanyMicrolearningCapsuleUserMapper::_TABLE] );
|
|
|
1532 |
$select->join(['tb2' => UserMapper::_TABLE], 'tb1.user_id = tb2.id', ['uuid', 'first_name', 'last_name', 'email']);
|
|
|
1533 |
$select->where->equalTo('tb1.company_id', $capsule->company_id);
|
|
|
1534 |
$select->where->equalTo('tb1.topic_id', $capsule->topic_id);
|
|
|
1535 |
$select->where->equalTo('tb1.capsule_id', $capsule->id);
|
|
|
1536 |
$select->where->equalTo('tb2.status', User::STATUS_ACTIVE);
|
|
|
1537 |
$select->order('first_name ASC, last_name ASC');
|
|
|
1538 |
|
|
|
1539 |
$user_ids = [];
|
|
|
1540 |
$records = $queryMapper->fetchAll($select);
|
|
|
1541 |
|
|
|
1542 |
foreach($records as $record)
|
|
|
1543 |
{
|
|
|
1544 |
$user_id = $record['user_id'];
|
|
|
1545 |
if(in_array($user_id, $user_ids)) {
|
|
|
1546 |
continue;
|
|
|
1547 |
}
|
|
|
1548 |
|
|
|
1549 |
array_push($user_ids, $user_id);
|
|
|
1550 |
|
|
|
1551 |
$item = [
|
|
|
1552 |
'uuid' => $record['uuid'],
|
|
|
1553 |
'first_name' => $record['first_name'],
|
|
|
1554 |
'last_name' => $record['last_name'],
|
|
|
1555 |
'email' => $record['email'],
|
|
|
1556 |
'progress' => 0,
|
|
|
1557 |
'total_slides' => 0,
|
|
|
1558 |
'view_slides' => 0,
|
|
|
1559 |
'completed' => 0,
|
|
|
1560 |
'returning_after_completed' => 0,
|
|
|
1561 |
'added_on' => '',
|
|
|
1562 |
'updated_on' => ''
|
|
|
1563 |
|
|
|
1564 |
];
|
|
|
1565 |
|
|
|
1566 |
$items[ $user_id ] = $item;
|
|
|
1567 |
}
|
|
|
1568 |
|
|
|
1569 |
|
|
|
1570 |
$select->columns(['user_id', 'progress', 'total_slides', 'view_slides', 'completed', 'returning_after_completed', 'added_on', 'updated_on']);
|
|
|
1571 |
$select->from(['tb1' => CompanyMicrolearningUserProgressMapper::_TABLE] );
|
|
|
1572 |
$select->where->equalTo('tb1.company_id', $capsule->company_id);
|
|
|
1573 |
$select->where->equalTo('tb1.type', CompanyMicrolearningUserProgress::TYPE_CAPSULE);
|
|
|
1574 |
$select->where->equalTo('tb1.topic_id', $capsule->topic_id);
|
|
|
1575 |
$select->where->equalTo('tb1.capsule_id', $capsule->id);
|
|
|
1576 |
$select->where->in('tb1.user_id', $user_ids);
|
|
|
1577 |
|
|
|
1578 |
|
|
|
1579 |
$records = $queryMapper->fetchAll($select);
|
|
|
1580 |
foreach($records as $record)
|
|
|
1581 |
{
|
|
|
1582 |
$user_id = $record['user_id'];
|
|
|
1583 |
|
|
|
1584 |
$dt_added_on = \DateTime::createFromFormat('Y-m-d H:i:s', $record['added_on']);
|
|
|
1585 |
$added_on = $dt_added_on->format('d/m/Y h:i a');
|
|
|
1586 |
|
|
|
1587 |
$dt_updated_on = \DateTime::createFromFormat('Y-m-d H:i:s', $record['updated_on']);
|
|
|
1588 |
$updated_on = $dt_updated_on->format('d/m/Y h:i a');
|
|
|
1589 |
|
|
|
1590 |
|
|
|
1591 |
$items[$user_id]['completed'] = $record['completed'];
|
|
|
1592 |
$items[$user_id]['progress'] = $record['progress'];
|
|
|
1593 |
$items[$user_id]['total_slides'] = $record['total_slides'];
|
|
|
1594 |
$items[$user_id]['view_slides'] = $record['view_slides'];
|
|
|
1595 |
$items[$user_id]['returning_after_completed'] = $record['returning_after_completed'];
|
|
|
1596 |
$items[$user_id]['added_on'] = $added_on;
|
|
|
1597 |
$items[$user_id]['updated_on'] = $updated_on;
|
|
|
1598 |
}
|
|
|
1599 |
|
|
|
1600 |
|
|
|
1601 |
$records = array_values($items);
|
|
|
1602 |
|
|
|
1603 |
$spreadsheet = new Spreadsheet();
|
|
|
1604 |
$spreadsheet->getProperties()->setTitle("Progreso por Cápsula");
|
|
|
1605 |
|
|
|
1606 |
|
|
|
1607 |
|
|
|
1608 |
$spreadsheet->setActiveSheetIndex(0);
|
|
|
1609 |
$spreadsheet->getActiveSheet()->SetCellValue('A1', 'Tópico:');
|
|
|
1610 |
$spreadsheet->getActiveSheet()->SetCellValue('A2', ucwords(trim(strtolower($topic->name))));
|
|
|
1611 |
|
|
|
1612 |
$spreadsheet->getActiveSheet()->SetCellValue('B1', ucwords('Cápsula:'));
|
|
|
1613 |
$spreadsheet->getActiveSheet()->SetCellValue('B2', ucwords(trim(strtolower($capsule->name))));
|
|
|
1614 |
|
|
|
1615 |
|
|
|
1616 |
$spreadsheet->getActiveSheet()->SetCellValue('C1', 'Fecha:');
|
|
|
1617 |
$spreadsheet->getActiveSheet()->SetCellValue('C2', date('d/m/Y h:i a'));
|
|
|
1618 |
|
|
|
1619 |
|
|
|
1620 |
|
|
|
1621 |
$spreadsheet->getActiveSheet()->SetCellValue('A4', 'Nombre');
|
|
|
1622 |
$spreadsheet->getActiveSheet()->SetCellValue('B4', 'Apellido');
|
|
|
1623 |
$spreadsheet->getActiveSheet()->SetCellValue('C4', 'Correo electrónico');
|
|
|
1624 |
$spreadsheet->getActiveSheet()->SetCellValue('D4', 'Progreso');
|
|
|
1625 |
$spreadsheet->getActiveSheet()->SetCellValue('E4', 'Diapositivas Totales');
|
|
|
1626 |
$spreadsheet->getActiveSheet()->SetCellValue('F4', 'Diapositivas Vistas');
|
|
|
1627 |
$spreadsheet->getActiveSheet()->SetCellValue('G4', 'Cápsula Completada');
|
|
|
1628 |
$spreadsheet->getActiveSheet()->SetCellValue('H4', 'Inicio');
|
|
|
1629 |
$spreadsheet->getActiveSheet()->SetCellValue('I4', 'Ultima vez');
|
|
|
1630 |
|
|
|
1631 |
|
|
|
1632 |
$i = 5;
|
|
|
1633 |
foreach($records as $record)
|
|
|
1634 |
{
|
|
|
1635 |
$spreadsheet->getActiveSheet()->SetCellValue('A' . $i, ucwords(strtolower(trim($record['first_name']))));
|
|
|
1636 |
$spreadsheet->getActiveSheet()->SetCellValue('B' . $i, ucwords(strtolower(trim($record['last_name']))));
|
|
|
1637 |
$spreadsheet->getActiveSheet()->SetCellValue('C' . $i, strtolower(trim($record['email'])));
|
|
|
1638 |
$spreadsheet->getActiveSheet()->SetCellValue('D' . $i, $record['progress']);
|
|
|
1639 |
$spreadsheet->getActiveSheet()->SetCellValue('E' . $i, $record['total_slides']);
|
|
|
1640 |
$spreadsheet->getActiveSheet()->SetCellValue('F' . $i, $record['view_slides']);
|
|
|
1641 |
$spreadsheet->getActiveSheet()->SetCellValue('G' . $i, $record['completed'] == 1 ? 'Si' : 'No');
|
|
|
1642 |
$spreadsheet->getActiveSheet()->SetCellValue('H' . $i, $record['added_on']);
|
|
|
1643 |
$spreadsheet->getActiveSheet()->SetCellValue('I' . $i, $record['updated_on']);
|
|
|
1644 |
$i++;
|
|
|
1645 |
}
|
|
|
1646 |
|
|
|
1647 |
|
|
|
1648 |
$fileName = 'reporte_progreso_por_capsula_' . time() . '.xls';
|
|
|
1649 |
|
|
|
1650 |
$tempFilename = tempnam(sys_get_temp_dir(), 'reporte_progreso_por_capsula_' . time());
|
|
|
1651 |
|
|
|
1652 |
|
|
|
1653 |
|
|
|
1654 |
|
|
|
1655 |
|
|
|
1656 |
$writer = IOFactory::createWriter($spreadsheet, 'Xls');
|
|
|
1657 |
$writer->save($tempFilename);
|
|
|
1658 |
|
|
|
1659 |
$content = file_get_contents($tempFilename);
|
|
|
1660 |
@unlink($tempFilename);
|
|
|
1661 |
|
|
|
1662 |
return new JsonModel([
|
|
|
1663 |
'success' => true,
|
|
|
1664 |
'data' => [
|
|
|
1665 |
'content' => base64_encode($content),
|
|
|
1666 |
'basename' => $fileName
|
|
|
1667 |
|
|
|
1668 |
]
|
|
|
1669 |
]);
|
|
|
1670 |
|
|
|
1671 |
|
|
|
1672 |
|
|
|
1673 |
|
|
|
1674 |
} else {
|
|
|
1675 |
return new JsonModel([
|
|
|
1676 |
'success' => false,
|
|
|
1677 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
1678 |
]);
|
|
|
1679 |
}
|
|
|
1680 |
}
|
|
|
1681 |
|
483 |
efrain |
1682 |
|
15386 |
efrain |
1683 |
public function progressForTopicAction()
|
|
|
1684 |
{
|
|
|
1685 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
1686 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
1687 |
$currentCompany = $currentUserPlugin->getCompany();
|
|
|
1688 |
|
|
|
1689 |
$request = $this->getRequest();
|
|
|
1690 |
|
|
|
1691 |
if($request->isGet())
|
|
|
1692 |
{
|
|
|
1693 |
|
|
|
1694 |
$headers = $request->getHeaders();
|
|
|
1695 |
|
|
|
1696 |
$isJson = false;
|
|
|
1697 |
if($headers->has('Accept')) {
|
|
|
1698 |
$accept = $headers->get('Accept');
|
|
|
1699 |
|
|
|
1700 |
$prioritized = $accept->getPrioritized();
|
|
|
1701 |
|
|
|
1702 |
foreach($prioritized as $key => $value) {
|
|
|
1703 |
$raw = trim($value->getRaw());
|
|
|
1704 |
|
|
|
1705 |
if(!$isJson) {
|
|
|
1706 |
$isJson = strpos($raw, 'json');
|
|
|
1707 |
}
|
|
|
1708 |
|
|
|
1709 |
}
|
|
|
1710 |
}
|
|
|
1711 |
|
|
|
1712 |
|
|
|
1713 |
if($isJson) {
|
|
|
1714 |
$acl = $this->getEvent()->getViewModel()->getVariable('acl');
|
|
|
1715 |
$allowDownload = $acl->isAllowed($currentUser->usertype_id, 'microlearning/reports/progress-for-topic/excel');
|
|
|
1716 |
|
|
|
1717 |
$topic_uuid = filter_var($this->params()->fromQuery('topic_uuid'), FILTER_SANITIZE_STRING);
|
|
|
1718 |
|
|
|
1719 |
$topicMapper = CompanyMicrolearningTopicMapper::getInstance($this->adapter);
|
|
|
1720 |
$topic = $topicMapper->fetchOneByUuid($topic_uuid);
|
|
|
1721 |
if(!$topic) {
|
|
|
1722 |
return new JsonModel([
|
|
|
1723 |
'success' => false,
|
|
|
1724 |
'data' => 'ERROR_TOPIC_NOT_FOUND'
|
|
|
1725 |
]);
|
|
|
1726 |
}
|
|
|
1727 |
|
|
|
1728 |
if($topic->company_id != $currentCompany->id) {
|
|
|
1729 |
return new JsonModel([
|
|
|
1730 |
'success' => false,
|
|
|
1731 |
'data' => 'ERROR_UNAUTHORIZED'
|
|
|
1732 |
]);
|
|
|
1733 |
}
|
|
|
1734 |
|
|
|
1735 |
|
|
|
1736 |
$data = [
|
|
|
1737 |
|
|
|
1738 |
'items' => [],
|
|
|
1739 |
'link_download' => '',
|
|
|
1740 |
|
|
|
1741 |
];
|
|
|
1742 |
|
|
|
1743 |
|
|
|
1744 |
|
|
|
1745 |
$queryMapper = QueryMapper::getInstance($this->adapter);
|
|
|
1746 |
$sql = $queryMapper->getSql();
|
|
|
1747 |
$select = $sql->select();
|
|
|
1748 |
$select->columns(['user_id' => new Expression('DISTINCT(user_id)') ]);
|
|
|
1749 |
$select->from(['tb1' => CompanyMicrolearningCapsuleUserMapper::_TABLE] );
|
|
|
1750 |
$select->join(['tb2' => UserMapper::_TABLE], 'tb1.user_id = tb2.id', ['uuid', 'first_name', 'last_name', 'email']);
|
|
|
1751 |
$select->where->equalTo('tb1.company_id', $topic->company_id);
|
|
|
1752 |
$select->where->equalTo('tb1.topic_id', $topic->id);
|
|
|
1753 |
$select->where->equalTo('tb2.status', User::STATUS_ACTIVE);
|
|
|
1754 |
$select->order('first_name ASC, last_name ASC');
|
|
|
1755 |
|
|
|
1756 |
$user_ids = [];
|
|
|
1757 |
$records = $queryMapper->fetchAll($select);
|
|
|
1758 |
|
|
|
1759 |
foreach($records as $record)
|
|
|
1760 |
{
|
|
|
1761 |
$user_id = $record['user_id'];
|
|
|
1762 |
|
|
|
1763 |
if(in_array($user_id, $user_ids)) {
|
|
|
1764 |
continue;
|
|
|
1765 |
}
|
|
|
1766 |
|
|
|
1767 |
array_push($user_ids, $user_id);
|
|
|
1768 |
|
|
|
1769 |
$item = [
|
|
|
1770 |
'uuid' => $record['uuid'],
|
15387 |
efrain |
1771 |
'first_name' => ucwords(strtolower($record['first_name'])),
|
|
|
1772 |
'last_name' => ucwords(strtolower($record['last_name'])),
|
|
|
1773 |
'email' => strtolower($record['email']),
|
15386 |
efrain |
1774 |
'progress' => 0,
|
|
|
1775 |
'total_capsules' => 0,
|
|
|
1776 |
'completed_capsules' => 0,
|
|
|
1777 |
'started_capsules' => 0,
|
|
|
1778 |
'pending_capsules' => 0,
|
|
|
1779 |
'added_on' => '',
|
|
|
1780 |
'updated_on' => ''
|
|
|
1781 |
|
|
|
1782 |
];
|
|
|
1783 |
|
|
|
1784 |
$items[ $user_id ] = $item;
|
|
|
1785 |
}
|
|
|
1786 |
|
|
|
1787 |
$select = $sql->select();
|
|
|
1788 |
$select->columns(['total' => new Expression('COUNT(*)'), 'user_id']);
|
|
|
1789 |
$select->from(CompanyMicrolearningCapsuleUserMapper::_TABLE);
|
|
|
1790 |
$select->where->equalTo('company_id', $topic->company_id);
|
|
|
1791 |
$select->where->equalTo('topic_id', $topic->id);
|
|
|
1792 |
$select->group('user_id');
|
|
|
1793 |
|
|
|
1794 |
$records = $queryMapper->fetchAll($select);
|
|
|
1795 |
foreach($records as $record)
|
|
|
1796 |
{
|
|
|
1797 |
$user_id = $record['user_id'];
|
|
|
1798 |
|
|
|
1799 |
$items[$user_id]['total_capsules'] = $record['total'];
|
|
|
1800 |
|
|
|
1801 |
}
|
|
|
1802 |
|
|
|
1803 |
|
|
|
1804 |
$select = $sql->select();
|
|
|
1805 |
$select->columns(['total' => new Expression('COUNT(*)'), 'user_id']);
|
|
|
1806 |
$select->from(CompanyMicrolearningUserProgressMapper::_TABLE);
|
|
|
1807 |
$select->where->equalTo('company_id', $topic->company_id);
|
|
|
1808 |
$select->where->equalTo('topic_id', $topic->id);
|
|
|
1809 |
$select->where->equalTo('type', CompanyMicrolearningUserProgress::TYPE_CAPSULE);
|
|
|
1810 |
$select->where->greaterThanOrEqualTo('progress', 100);
|
|
|
1811 |
$select->where->equalTo('completed', 1);
|
|
|
1812 |
$select->group('user_id');
|
|
|
1813 |
|
|
|
1814 |
//echo $select->getSqlString($this->adapter->platform); exit;
|
|
|
1815 |
|
|
|
1816 |
|
|
|
1817 |
$records = $queryMapper->fetchAll($select);
|
|
|
1818 |
foreach($records as $record)
|
|
|
1819 |
{
|
|
|
1820 |
$user_id = $record['user_id'];
|
|
|
1821 |
|
|
|
1822 |
$items[$user_id]['completed_capsules'] = $record['total'];
|
|
|
1823 |
|
|
|
1824 |
}
|
|
|
1825 |
|
|
|
1826 |
|
|
|
1827 |
$select = $sql->select();
|
|
|
1828 |
$select->columns(['total' => new Expression('COUNT(*)'), 'user_id']);
|
|
|
1829 |
$select->from(CompanyMicrolearningUserProgressMapper::_TABLE);
|
|
|
1830 |
$select->where->equalTo('company_id', $topic->company_id);
|
|
|
1831 |
$select->where->equalTo('topic_id', $topic->id);
|
|
|
1832 |
$select->where->equalTo('type', CompanyMicrolearningUserProgress::TYPE_CAPSULE);
|
|
|
1833 |
$select->where->lessThan('progress', 100);
|
|
|
1834 |
$select->where->equalTo('completed', 0);
|
|
|
1835 |
$select->group('user_id');
|
|
|
1836 |
|
|
|
1837 |
|
|
|
1838 |
$records = $queryMapper->fetchAll($select);
|
|
|
1839 |
foreach($records as $record)
|
|
|
1840 |
{
|
|
|
1841 |
$user_id = $record['user_id'];
|
|
|
1842 |
|
|
|
1843 |
$items[$user_id]['started_capsules'] = $record['total'];
|
|
|
1844 |
|
|
|
1845 |
}
|
|
|
1846 |
|
|
|
1847 |
$select = $sql->select();
|
|
|
1848 |
$select->columns(['added_on' => new Expression('MIN(added_on)'), 'updated_on' => new Expression('MAX(updated_on)'), 'user_id']);
|
|
|
1849 |
$select->from(CompanyMicrolearningUserProgressMapper::_TABLE);
|
|
|
1850 |
$select->where->equalTo('company_id', $topic->company_id);
|
|
|
1851 |
$select->where->equalTo('topic_id', $topic->id);
|
|
|
1852 |
$select->where->equalTo('type', CompanyMicrolearningUserProgress::TYPE_CAPSULE);
|
|
|
1853 |
$select->group('user_id');
|
|
|
1854 |
|
|
|
1855 |
|
|
|
1856 |
$records = $queryMapper->fetchAll($select);
|
|
|
1857 |
foreach($records as $record)
|
|
|
1858 |
{
|
|
|
1859 |
$user_id = $record['user_id'];
|
|
|
1860 |
|
|
|
1861 |
|
|
|
1862 |
$dt_added_on = \DateTime::createFromFormat('Y-m-d H:i:s', $record['added_on']);
|
|
|
1863 |
$added_on = $dt_added_on->format('d/m/Y h:i a');
|
|
|
1864 |
|
|
|
1865 |
$dt_updated_on = \DateTime::createFromFormat('Y-m-d H:i:s', $record['updated_on']);
|
|
|
1866 |
$updated_on = $dt_updated_on->format('d/m/Y h:i a');
|
|
|
1867 |
|
|
|
1868 |
|
|
|
1869 |
$items[$user_id]['added_on'] = $added_on;
|
|
|
1870 |
$items[$user_id]['updated_on'] = $updated_on;
|
|
|
1871 |
|
|
|
1872 |
if($items[$user_id]['completed_capsules']) {
|
|
|
1873 |
|
|
|
1874 |
$progress = ($items[$user_id]['completed_capsules'] * 100) / $items[$user_id]['total_capsules'];
|
|
|
1875 |
|
|
|
1876 |
$items[$user_id]['progress'] = number_format($progress, 2);
|
|
|
1877 |
}
|
|
|
1878 |
}
|
|
|
1879 |
|
|
|
1880 |
$data['items'] = array_values($items);
|
|
|
1881 |
|
|
|
1882 |
if($allowDownload) {
|
|
|
1883 |
$data['link_download'] = $this->url()->fromRoute('microlearning/reports/progress-for-topic/excel', [], ['query' => ['topic_uuid' => $topic->uuid] ]);
|
|
|
1884 |
}
|
|
|
1885 |
|
|
|
1886 |
|
|
|
1887 |
|
|
|
1888 |
return new JsonModel([
|
|
|
1889 |
'success' => true,
|
|
|
1890 |
'data' => $data
|
|
|
1891 |
]);
|
|
|
1892 |
} else {
|
|
|
1893 |
|
|
|
1894 |
|
|
|
1895 |
$form = new TopicReportForm($this->adapter, $currentCompany->id);
|
|
|
1896 |
|
|
|
1897 |
|
|
|
1898 |
|
|
|
1899 |
$this->layout()->setTemplate('layout/layout-backend');
|
|
|
1900 |
$viewModel = new ViewModel();
|
|
|
1901 |
$viewModel->setTemplate('leaders-linked/microlearning-reports/progress-for-topic.phtml');
|
|
|
1902 |
$viewModel->setVariables([
|
|
|
1903 |
'form' => $form,
|
|
|
1904 |
]);
|
|
|
1905 |
|
|
|
1906 |
return $viewModel ;
|
|
|
1907 |
}
|
|
|
1908 |
|
|
|
1909 |
} else {
|
|
|
1910 |
return new JsonModel([
|
|
|
1911 |
'success' => false,
|
|
|
1912 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
1913 |
]);
|
|
|
1914 |
}
|
|
|
1915 |
}
|
483 |
efrain |
1916 |
|
15386 |
efrain |
1917 |
public function progressForTopicExcelAction()
|
|
|
1918 |
{
|
|
|
1919 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
1920 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
1921 |
$currentCompany = $currentUserPlugin->getCompany();
|
|
|
1922 |
|
|
|
1923 |
$request = $this->getRequest();
|
|
|
1924 |
|
|
|
1925 |
if($request->isGet())
|
|
|
1926 |
{
|
|
|
1927 |
|
|
|
1928 |
$topic_uuid = filter_var($this->params()->fromQuery('topic_uuid'), FILTER_SANITIZE_STRING);
|
|
|
1929 |
|
|
|
1930 |
$topicMapper = CompanyMicrolearningTopicMapper::getInstance($this->adapter);
|
|
|
1931 |
$topic = $topicMapper->fetchOneByUuid($topic_uuid);
|
|
|
1932 |
if(!$topic) {
|
|
|
1933 |
return new JsonModel([
|
|
|
1934 |
'success' => false,
|
|
|
1935 |
'data' => 'ERROR_TOPIC_NOT_FOUND'
|
|
|
1936 |
]);
|
|
|
1937 |
}
|
|
|
1938 |
|
|
|
1939 |
if($topic->company_id != $currentCompany->id) {
|
|
|
1940 |
return new JsonModel([
|
|
|
1941 |
'success' => false,
|
|
|
1942 |
'data' => 'ERROR_UNAUTHORIZED'
|
|
|
1943 |
]);
|
|
|
1944 |
}
|
|
|
1945 |
|
|
|
1946 |
$queryMapper = QueryMapper::getInstance($this->adapter);
|
|
|
1947 |
$sql = $queryMapper->getSql();
|
|
|
1948 |
$select = $sql->select();
|
|
|
1949 |
$select->columns(['user_id' => new Expression('DISTINCT(user_id)') ]);
|
|
|
1950 |
$select->from(['tb1' => CompanyMicrolearningCapsuleUserMapper::_TABLE] );
|
|
|
1951 |
$select->join(['tb2' => UserMapper::_TABLE], 'tb1.user_id = tb2.id', ['uuid', 'first_name', 'last_name', 'email']);
|
|
|
1952 |
$select->where->equalTo('tb1.company_id', $topic->company_id);
|
|
|
1953 |
$select->where->equalTo('tb1.topic_id', $topic->id);
|
|
|
1954 |
$select->where->equalTo('tb2.status', User::STATUS_ACTIVE);
|
|
|
1955 |
$select->order('first_name ASC, last_name ASC');
|
|
|
1956 |
|
|
|
1957 |
$user_ids = [];
|
|
|
1958 |
$records = $queryMapper->fetchAll($select);
|
|
|
1959 |
|
|
|
1960 |
foreach($records as $record)
|
|
|
1961 |
{
|
|
|
1962 |
$user_id = $record['user_id'];
|
|
|
1963 |
|
|
|
1964 |
if(in_array($user_id, $user_ids)) {
|
|
|
1965 |
continue;
|
|
|
1966 |
}
|
|
|
1967 |
|
|
|
1968 |
array_push($user_ids, $user_id);
|
|
|
1969 |
|
|
|
1970 |
$item = [
|
|
|
1971 |
'uuid' => $record['uuid'],
|
|
|
1972 |
'first_name' => $record['first_name'],
|
|
|
1973 |
'last_name' => $record['last_name'],
|
|
|
1974 |
'email' => $record['email'],
|
|
|
1975 |
'progress' => 0,
|
|
|
1976 |
'total_capsules' => 0,
|
|
|
1977 |
'completed_capsules' => 0,
|
|
|
1978 |
'started_capsules' => 0,
|
|
|
1979 |
'pending_capsules' => 0,
|
|
|
1980 |
'added_on' => '',
|
|
|
1981 |
'updated_on' => ''
|
|
|
1982 |
|
|
|
1983 |
];
|
|
|
1984 |
|
|
|
1985 |
$items[ $user_id ] = $item;
|
|
|
1986 |
}
|
|
|
1987 |
|
|
|
1988 |
$select = $sql->select();
|
|
|
1989 |
$select->columns(['total' => new Expression('COUNT(*)'), 'user_id']);
|
|
|
1990 |
$select->from(CompanyMicrolearningCapsuleUserMapper::_TABLE);
|
|
|
1991 |
$select->where->equalTo('company_id', $topic->company_id);
|
|
|
1992 |
$select->where->equalTo('topic_id', $topic->id);
|
|
|
1993 |
$select->group('user_id');
|
|
|
1994 |
|
|
|
1995 |
$records = $queryMapper->fetchAll($select);
|
|
|
1996 |
foreach($records as $record)
|
|
|
1997 |
{
|
|
|
1998 |
$user_id = $record['user_id'];
|
|
|
1999 |
|
|
|
2000 |
$items[$user_id]['total_capsules'] = $record['total'];
|
|
|
2001 |
|
|
|
2002 |
}
|
|
|
2003 |
|
|
|
2004 |
|
|
|
2005 |
$select = $sql->select();
|
|
|
2006 |
$select->columns(['total' => new Expression('COUNT(*)'), 'user_id']);
|
|
|
2007 |
$select->from(CompanyMicrolearningUserProgressMapper::_TABLE);
|
|
|
2008 |
$select->where->equalTo('company_id', $topic->company_id);
|
|
|
2009 |
$select->where->equalTo('topic_id', $topic->id);
|
|
|
2010 |
$select->where->equalTo('type', CompanyMicrolearningUserProgress::TYPE_CAPSULE);
|
|
|
2011 |
$select->where->greaterThanOrEqualTo('progress', 100);
|
|
|
2012 |
$select->where->equalTo('completed', 1);
|
|
|
2013 |
$select->group('user_id');
|
|
|
2014 |
|
|
|
2015 |
//echo $select->getSqlString($this->adapter->platform); exit;
|
|
|
2016 |
|
|
|
2017 |
|
|
|
2018 |
$records = $queryMapper->fetchAll($select);
|
|
|
2019 |
foreach($records as $record)
|
|
|
2020 |
{
|
|
|
2021 |
$user_id = $record['user_id'];
|
|
|
2022 |
|
|
|
2023 |
$items[$user_id]['completed_capsules'] = $record['total'];
|
|
|
2024 |
|
|
|
2025 |
}
|
|
|
2026 |
|
|
|
2027 |
|
|
|
2028 |
$select = $sql->select();
|
|
|
2029 |
$select->columns(['total' => new Expression('COUNT(*)'), 'user_id']);
|
|
|
2030 |
$select->from(CompanyMicrolearningUserProgressMapper::_TABLE);
|
|
|
2031 |
$select->where->equalTo('company_id', $topic->company_id);
|
|
|
2032 |
$select->where->equalTo('topic_id', $topic->id);
|
|
|
2033 |
$select->where->equalTo('type', CompanyMicrolearningUserProgress::TYPE_CAPSULE);
|
|
|
2034 |
$select->where->lessThan('progress', 100);
|
|
|
2035 |
$select->where->equalTo('completed', 0);
|
|
|
2036 |
$select->group('user_id');
|
|
|
2037 |
|
|
|
2038 |
|
|
|
2039 |
$records = $queryMapper->fetchAll($select);
|
|
|
2040 |
foreach($records as $record)
|
|
|
2041 |
{
|
|
|
2042 |
$user_id = $record['user_id'];
|
|
|
2043 |
|
|
|
2044 |
$items[$user_id]['started_capsules'] = $record['total'];
|
|
|
2045 |
|
|
|
2046 |
}
|
|
|
2047 |
|
|
|
2048 |
$select = $sql->select();
|
|
|
2049 |
$select->columns(['added_on' => new Expression('MIN(added_on)'), 'updated_on' => new Expression('MAX(updated_on)'), 'user_id']);
|
|
|
2050 |
$select->from(CompanyMicrolearningUserProgressMapper::_TABLE);
|
|
|
2051 |
$select->where->equalTo('company_id', $topic->company_id);
|
|
|
2052 |
$select->where->equalTo('topic_id', $topic->id);
|
|
|
2053 |
$select->where->equalTo('type', CompanyMicrolearningUserProgress::TYPE_CAPSULE);
|
|
|
2054 |
$select->group('user_id');
|
|
|
2055 |
|
|
|
2056 |
|
|
|
2057 |
$records = $queryMapper->fetchAll($select);
|
|
|
2058 |
foreach($records as $record)
|
|
|
2059 |
{
|
|
|
2060 |
$user_id = $record['user_id'];
|
|
|
2061 |
|
|
|
2062 |
|
|
|
2063 |
$dt_added_on = \DateTime::createFromFormat('Y-m-d H:i:s', $record['added_on']);
|
|
|
2064 |
$added_on = $dt_added_on->format('d/m/Y h:i a');
|
|
|
2065 |
|
|
|
2066 |
$dt_updated_on = \DateTime::createFromFormat('Y-m-d H:i:s', $record['updated_on']);
|
|
|
2067 |
$updated_on = $dt_updated_on->format('d/m/Y h:i a');
|
|
|
2068 |
|
|
|
2069 |
|
|
|
2070 |
$items[$user_id]['added_on'] = $added_on;
|
|
|
2071 |
$items[$user_id]['updated_on'] = $updated_on;
|
|
|
2072 |
|
|
|
2073 |
if($items[$user_id]['completed_capsules']) {
|
|
|
2074 |
|
|
|
2075 |
$progress = ($items[$user_id]['completed_capsules'] * 100) / $items[$user_id]['total_capsules'];
|
|
|
2076 |
|
|
|
2077 |
$items[$user_id]['progress'] = number_format($progress, 2);
|
|
|
2078 |
}
|
15387 |
efrain |
2079 |
$items[$user_id]['pending_capsules'] = $items[$user_id]['total_capsules'] - ($items[$user_id]['completed_capsules' ] + $items[$user_id]['started_capsules']);
|
|
|
2080 |
|
15386 |
efrain |
2081 |
}
|
|
|
2082 |
|
|
|
2083 |
$records = array_values($items);
|
|
|
2084 |
|
|
|
2085 |
$spreadsheet = new Spreadsheet();
|
|
|
2086 |
$spreadsheet->getProperties()->setTitle("Progreso por Tópico");
|
|
|
2087 |
|
|
|
2088 |
|
|
|
2089 |
|
|
|
2090 |
$spreadsheet->setActiveSheetIndex(0);
|
|
|
2091 |
$spreadsheet->getActiveSheet()->SetCellValue('A1', 'Tópico:');
|
|
|
2092 |
$spreadsheet->getActiveSheet()->SetCellValue('A2', ucwords(trim(strtolower($topic->name))));
|
|
|
2093 |
|
|
|
2094 |
|
|
|
2095 |
|
|
|
2096 |
$spreadsheet->getActiveSheet()->SetCellValue('B1', 'Fecha:');
|
|
|
2097 |
$spreadsheet->getActiveSheet()->SetCellValue('N2', date('d/m/Y h:i a'));
|
|
|
2098 |
|
|
|
2099 |
|
|
|
2100 |
|
|
|
2101 |
$spreadsheet->getActiveSheet()->SetCellValue('A4', 'Nombre');
|
|
|
2102 |
$spreadsheet->getActiveSheet()->SetCellValue('B4', 'Apellido');
|
|
|
2103 |
$spreadsheet->getActiveSheet()->SetCellValue('C4', 'Correo electrónico');
|
|
|
2104 |
$spreadsheet->getActiveSheet()->SetCellValue('D4', 'Progreso');
|
|
|
2105 |
$spreadsheet->getActiveSheet()->SetCellValue('E4', 'Capsulas Totales');
|
|
|
2106 |
$spreadsheet->getActiveSheet()->SetCellValue('F4', 'Capsulas Completadas');
|
|
|
2107 |
$spreadsheet->getActiveSheet()->SetCellValue('G4', 'Capsulas en Progreso');
|
|
|
2108 |
$spreadsheet->getActiveSheet()->SetCellValue('H4', 'Capsulas sin Iniciar');
|
|
|
2109 |
$spreadsheet->getActiveSheet()->SetCellValue('I4', 'Inicio');
|
|
|
2110 |
$spreadsheet->getActiveSheet()->SetCellValue('J4', 'Ultima vez');
|
|
|
2111 |
|
|
|
2112 |
$i = 5;
|
|
|
2113 |
foreach($records as $record)
|
|
|
2114 |
{
|
|
|
2115 |
$spreadsheet->getActiveSheet()->SetCellValue('A' . $i, ucwords(strtolower(trim($record['first_name']))));
|
|
|
2116 |
$spreadsheet->getActiveSheet()->SetCellValue('B' . $i, ucwords(strtolower(trim($record['last_name']))));
|
|
|
2117 |
$spreadsheet->getActiveSheet()->SetCellValue('C' . $i, strtolower(trim($record['email'])));
|
|
|
2118 |
$spreadsheet->getActiveSheet()->SetCellValue('D' . $i, $record['progress']);
|
|
|
2119 |
$spreadsheet->getActiveSheet()->SetCellValue('E' . $i, $record['total_capsules']);
|
|
|
2120 |
$spreadsheet->getActiveSheet()->SetCellValue('F' . $i, $record['completed_capsules']);
|
|
|
2121 |
$spreadsheet->getActiveSheet()->SetCellValue('G' . $i, $record['started_capsules']);
|
|
|
2122 |
$spreadsheet->getActiveSheet()->SetCellValue('H' . $i, $record['pending_capsules']);
|
|
|
2123 |
$spreadsheet->getActiveSheet()->SetCellValue('I' . $i, $record['added_on']);
|
|
|
2124 |
$spreadsheet->getActiveSheet()->SetCellValue('J' . $i, $record['updated_on']);
|
|
|
2125 |
$i++;
|
|
|
2126 |
}
|
|
|
2127 |
|
|
|
2128 |
|
|
|
2129 |
$fileName = 'reporte_progreso_por_topico_' . time() . '.xls';
|
|
|
2130 |
|
|
|
2131 |
$tempFilename = tempnam(sys_get_temp_dir(), 'reporte_progreso_por_topico_' . time());
|
|
|
2132 |
|
|
|
2133 |
|
|
|
2134 |
|
|
|
2135 |
|
|
|
2136 |
|
|
|
2137 |
$writer = IOFactory::createWriter($spreadsheet, 'Xls');
|
|
|
2138 |
$writer->save($tempFilename);
|
|
|
2139 |
|
|
|
2140 |
$content = file_get_contents($tempFilename);
|
|
|
2141 |
@unlink($tempFilename);
|
|
|
2142 |
|
|
|
2143 |
return new JsonModel([
|
|
|
2144 |
'success' => true,
|
|
|
2145 |
'data' => [
|
|
|
2146 |
'content' => base64_encode($content),
|
|
|
2147 |
'basename' => $fileName
|
|
|
2148 |
|
|
|
2149 |
]
|
|
|
2150 |
]);
|
|
|
2151 |
|
|
|
2152 |
|
|
|
2153 |
|
|
|
2154 |
|
|
|
2155 |
} else {
|
|
|
2156 |
return new JsonModel([
|
|
|
2157 |
'success' => false,
|
|
|
2158 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
2159 |
]);
|
|
|
2160 |
}
|
|
|
2161 |
}
|
483 |
efrain |
2162 |
|
15386 |
efrain |
2163 |
|
|
|
2164 |
public function progressForStudentAction()
|
|
|
2165 |
{
|
|
|
2166 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
2167 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
2168 |
$currentCompany = $currentUserPlugin->getCompany();
|
|
|
2169 |
|
|
|
2170 |
$request = $this->getRequest();
|
|
|
2171 |
|
|
|
2172 |
if($request->isGet())
|
|
|
2173 |
{
|
|
|
2174 |
|
|
|
2175 |
$headers = $request->getHeaders();
|
|
|
2176 |
|
|
|
2177 |
$isJson = false;
|
|
|
2178 |
if($headers->has('Accept')) {
|
|
|
2179 |
$accept = $headers->get('Accept');
|
|
|
2180 |
|
|
|
2181 |
$prioritized = $accept->getPrioritized();
|
|
|
2182 |
|
|
|
2183 |
foreach($prioritized as $key => $value) {
|
|
|
2184 |
$raw = trim($value->getRaw());
|
|
|
2185 |
|
|
|
2186 |
if(!$isJson) {
|
|
|
2187 |
$isJson = strpos($raw, 'json');
|
|
|
2188 |
}
|
|
|
2189 |
|
|
|
2190 |
}
|
|
|
2191 |
}
|
|
|
2192 |
|
|
|
2193 |
|
|
|
2194 |
if($isJson) {
|
|
|
2195 |
|
|
|
2196 |
$acl = $this->getEvent()->getViewModel()->getVariable('acl');
|
|
|
2197 |
$allowDownload = $acl->isAllowed($currentUser->usertype_id, 'microlearning/reports/progress-for-student/excel');
|
|
|
2198 |
|
|
|
2199 |
$student_uuid = filter_var($this->params()->fromQuery('student_uuid'), FILTER_SANITIZE_STRING);
|
|
|
2200 |
|
|
|
2201 |
$userMapper = UserMapper::getInstance($this->adapter);
|
|
|
2202 |
$user = $userMapper->fetchOneByUuidAndNetworkId($student_uuid, $currentUser->network_id);
|
|
|
2203 |
|
|
|
2204 |
|
|
|
2205 |
if(!$user) {
|
|
|
2206 |
return new JsonModel([
|
|
|
2207 |
'success' => false,
|
|
|
2208 |
'data' => 'ERROR_USER_NOT_FOUND'
|
|
|
2209 |
]);
|
|
|
2210 |
}
|
|
|
2211 |
|
|
|
2212 |
|
|
|
2213 |
$companyMicrolearningCapsuleUserMapper = CompanyMicrolearningCapsuleUserMapper::getInstance($this->adapter);
|
|
|
2214 |
$count = $companyMicrolearningCapsuleUserMapper->fetchCountByCompanyIdAndUserId($currentCompany->id, $user->id);
|
|
|
2215 |
|
|
|
2216 |
|
|
|
2217 |
if(!$count) {
|
|
|
2218 |
return new JsonModel([
|
|
|
2219 |
'success' => false,
|
|
|
2220 |
'data' => 'ERROR_UNAUTHORIZED'
|
|
|
2221 |
]);
|
|
|
2222 |
}
|
|
|
2223 |
|
|
|
2224 |
|
|
|
2225 |
$data = [
|
|
|
2226 |
'items' => [],
|
|
|
2227 |
];
|
|
|
2228 |
|
|
|
2229 |
|
|
|
2230 |
|
|
|
2231 |
|
|
|
2232 |
|
|
|
2233 |
|
|
|
2234 |
|
|
|
2235 |
$queryMapper = QueryMapper::getInstance($this->adapter);
|
|
|
2236 |
$sql = $queryMapper->getSql();
|
|
|
2237 |
$select = $sql->select();
|
|
|
2238 |
$select->columns(['access', 'paid_from', 'paid_to' ]);
|
|
|
2239 |
$select->from(['tb1' => CompanyMicrolearningCapsuleUserMapper::_TABLE] );
|
|
|
2240 |
$select->join(['tb2' => CompanyMicrolearningTopicMapper::_TABLE], 'tb1.company_id = tb2.company_id AND tb1.topic_id = tb2.id', ['topic' => 'name']);
|
|
|
2241 |
$select->join(['tb3' => CompanyMicrolearningCapsuleMapper::_TABLE], 'tb1.company_id = tb3.company_id AND tb1.topic_id = tb3.topic_id AND tb1.capsule_id = tb3.id', ['capsule' => 'name']);
|
|
|
2242 |
$select->join(['tb4' => CompanyMicrolearningUserProgressMapper::_TABLE],
|
|
|
2243 |
'tb1.company_id = tb2.company_id AND tb1.topic_id = tb4.topic_id AND tb1.capsule_id = tb4.capsule_id AND tb1.user_id = tb4.user_id',
|
|
|
2244 |
['progress', 'total_slides' , 'view_slides', 'completed', 'added_on','updated_on'], Select::JOIN_RIGHT_OUTER);
|
|
|
2245 |
$select->where->equalTo('tb1.company_id', $currentCompany->id);
|
|
|
2246 |
$select->where->equalTo('tb1.user_id', $user->id);
|
|
|
2247 |
$select->where->equalTo('tb4.type', CompanyMicrolearningUserProgress::TYPE_CAPSULE);
|
|
|
2248 |
$select->order('tb2.name ASC, tb3.name ASC');
|
|
|
2249 |
|
|
|
2250 |
|
|
|
2251 |
$items = [];
|
|
|
2252 |
$records = $queryMapper->fetchAll($select);
|
|
|
2253 |
foreach($records as $record)
|
|
|
2254 |
{
|
|
|
2255 |
|
|
|
2256 |
|
|
|
2257 |
|
|
|
2258 |
$item = [
|
15387 |
efrain |
2259 |
'topic' => ucwords(strtolower($record['topic'])),
|
|
|
2260 |
'capsule' => ucwords(strtolower($record['capsule'])),
|
15386 |
efrain |
2261 |
'progress' => $record['progress'],
|
|
|
2262 |
'total_slides' => $record['total_slides'],
|
|
|
2263 |
'view_slides' => $record['view_slides'],
|
|
|
2264 |
'completed' => $record['completed'],
|
|
|
2265 |
'added_on' => $record['added_on'],
|
|
|
2266 |
'updated_on' => $record['updated_on'],
|
|
|
2267 |
|
|
|
2268 |
];
|
|
|
2269 |
|
|
|
2270 |
array_push($items, $item);
|
|
|
2271 |
}
|
|
|
2272 |
|
|
|
2273 |
|
|
|
2274 |
$data['items'] = array_values($items);
|
|
|
2275 |
|
|
|
2276 |
if($allowDownload) {
|
|
|
2277 |
$data['link_download'] = $this->url()->fromRoute('microlearning/reports/progress-for-student/excel', [], ['query' => ['student_uuid' => $user->uuid] ]);
|
|
|
2278 |
}
|
|
|
2279 |
|
|
|
2280 |
|
|
|
2281 |
|
|
|
2282 |
return new JsonModel([
|
|
|
2283 |
'success' => true,
|
|
|
2284 |
'data' => $data
|
|
|
2285 |
]);
|
|
|
2286 |
} else {
|
|
|
2287 |
|
|
|
2288 |
|
|
|
2289 |
$form = new StudentReportForm($this->adapter, $currentCompany->id);
|
|
|
2290 |
|
|
|
2291 |
|
|
|
2292 |
|
|
|
2293 |
$this->layout()->setTemplate('layout/layout-backend');
|
|
|
2294 |
$viewModel = new ViewModel();
|
|
|
2295 |
$viewModel->setTemplate('leaders-linked/microlearning-reports/progress-for-student.phtml');
|
|
|
2296 |
$viewModel->setVariables([
|
|
|
2297 |
'form' => $form,
|
|
|
2298 |
]);
|
|
|
2299 |
|
|
|
2300 |
return $viewModel ;
|
|
|
2301 |
}
|
|
|
2302 |
|
|
|
2303 |
} else {
|
|
|
2304 |
return new JsonModel([
|
|
|
2305 |
'success' => false,
|
|
|
2306 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
2307 |
]);
|
|
|
2308 |
}
|
|
|
2309 |
}
|
|
|
2310 |
|
|
|
2311 |
public function progressForStudentExcelAction()
|
|
|
2312 |
{
|
|
|
2313 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
2314 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
2315 |
$currentCompany = $currentUserPlugin->getCompany();
|
|
|
2316 |
|
|
|
2317 |
$request = $this->getRequest();
|
|
|
2318 |
|
|
|
2319 |
if($request->isGet())
|
|
|
2320 |
{
|
|
|
2321 |
|
|
|
2322 |
$student_uuid = filter_var($this->params()->fromQuery('student_uuid'), FILTER_SANITIZE_STRING);
|
|
|
2323 |
|
|
|
2324 |
$userMapper = UserMapper::getInstance($this->adapter);
|
|
|
2325 |
$user = $userMapper->fetchOneByUuidAndNetworkId($student_uuid, $currentUser->network_id);
|
|
|
2326 |
|
|
|
2327 |
|
|
|
2328 |
if(!$user) {
|
|
|
2329 |
return new JsonModel([
|
|
|
2330 |
'success' => false,
|
|
|
2331 |
'data' => 'ERROR_USER_NOT_FOUND'
|
|
|
2332 |
]);
|
|
|
2333 |
}
|
|
|
2334 |
|
|
|
2335 |
$companyMicrolearningCapsuleUserMapper = CompanyMicrolearningCapsuleUserMapper::getInstance($this->adapter);
|
|
|
2336 |
$count = $companyMicrolearningCapsuleUserMapper->fetchCountByCompanyIdAndUserId($currentCompany->id, $user->id);
|
|
|
2337 |
|
|
|
2338 |
|
|
|
2339 |
if(!$count) {
|
|
|
2340 |
return new JsonModel([
|
|
|
2341 |
'success' => false,
|
|
|
2342 |
'data' => 'ERROR_UNAUTHORIZED'
|
|
|
2343 |
]);
|
|
|
2344 |
}
|
|
|
2345 |
|
|
|
2346 |
|
|
|
2347 |
|
|
|
2348 |
|
|
|
2349 |
$queryMapper = QueryMapper::getInstance($this->adapter);
|
|
|
2350 |
$sql = $queryMapper->getSql();
|
|
|
2351 |
$select = $sql->select();
|
|
|
2352 |
$select->columns(['access', 'paid_from', 'paid_to' ]);
|
|
|
2353 |
$select->from(['tb1' => CompanyMicrolearningCapsuleUserMapper::_TABLE] );
|
|
|
2354 |
$select->join(['tb2' => CompanyMicrolearningTopicMapper::_TABLE], 'tb1.company_id = tb2.company_id AND tb1.topic_id = tb2.id', ['topic' => 'name']);
|
|
|
2355 |
$select->join(['tb3' => CompanyMicrolearningCapsuleMapper::_TABLE], 'tb1.company_id = tb3.company_id AND tb1.topic_id = tb3.topic_id AND tb1.capsule_id = tb3.id', ['capsule' => 'name']);
|
|
|
2356 |
$select->join(['tb4' => CompanyMicrolearningUserProgressMapper::_TABLE],
|
|
|
2357 |
'tb1.company_id = tb2.company_id AND tb1.topic_id = tb4.topic_id AND tb1.capsule_id = tb4.capsule_id AND tb1.user_id = tb4.user_id',
|
|
|
2358 |
['progress', 'total_slides' , 'view_slides', 'completed', 'added_on','updated_on'], Select::JOIN_RIGHT_OUTER);
|
|
|
2359 |
$select->where->equalTo('tb1.company_id', $currentCompany->id);
|
|
|
2360 |
$select->where->equalTo('tb1.user_id', $user->id);
|
|
|
2361 |
$select->where->equalTo('tb4.type', CompanyMicrolearningUserProgress::TYPE_CAPSULE);
|
|
|
2362 |
$select->order('tb2.name ASC, tb3.name ASC');
|
|
|
2363 |
|
|
|
2364 |
|
|
|
2365 |
$items = [];
|
|
|
2366 |
$records = $queryMapper->fetchAll($select);
|
|
|
2367 |
foreach($records as $record)
|
|
|
2368 |
{
|
|
|
2369 |
|
|
|
2370 |
|
|
|
2371 |
$item = [
|
|
|
2372 |
'topic' => $record['topic'],
|
|
|
2373 |
'capsule' => $record['capsule'],
|
|
|
2374 |
'progress' => $record['progress'],
|
|
|
2375 |
'total_slides' => $record['total_slides'],
|
|
|
2376 |
'view_slides' => $record['view_slides'],
|
|
|
2377 |
'completed' => $record['completed'],
|
|
|
2378 |
'added_on' => $record['added_on'],
|
|
|
2379 |
'updated_on' => $record['updated_on'],
|
|
|
2380 |
|
|
|
2381 |
];
|
|
|
2382 |
|
|
|
2383 |
array_push($items, $item);
|
|
|
2384 |
}
|
|
|
2385 |
|
|
|
2386 |
$records = $items;
|
|
|
2387 |
|
|
|
2388 |
|
|
|
2389 |
$spreadsheet = new Spreadsheet();
|
|
|
2390 |
$spreadsheet->getProperties()->setTitle("Progreso por Tópico");
|
|
|
2391 |
|
|
|
2392 |
|
|
|
2393 |
|
|
|
2394 |
$spreadsheet->setActiveSheetIndex(0);
|
|
|
2395 |
$spreadsheet->getActiveSheet()->SetCellValue('A1', 'Nombre:');
|
|
|
2396 |
$spreadsheet->getActiveSheet()->SetCellValue('A2', ucwords(trim(strtolower($user->first_name))));
|
|
|
2397 |
$spreadsheet->getActiveSheet()->SetCellValue('B1', 'Apellido:');
|
|
|
2398 |
$spreadsheet->getActiveSheet()->SetCellValue('B2', ucwords(trim(strtolower($user->last_name))));
|
|
|
2399 |
$spreadsheet->getActiveSheet()->SetCellValue('C1', 'Correo electrónco:');
|
|
|
2400 |
$spreadsheet->getActiveSheet()->SetCellValue('C2', trim(strtolower($user->email)));
|
|
|
2401 |
$spreadsheet->getActiveSheet()->SetCellValue('D1', 'Fecha:');
|
|
|
2402 |
$spreadsheet->getActiveSheet()->SetCellValue('D2', date('d/m/Y h:i a'));
|
|
|
2403 |
|
|
|
2404 |
|
|
|
2405 |
|
|
|
2406 |
$spreadsheet->getActiveSheet()->SetCellValue('A4', 'Tópico');
|
|
|
2407 |
$spreadsheet->getActiveSheet()->SetCellValue('B4', 'Cápsula');
|
|
|
2408 |
$spreadsheet->getActiveSheet()->SetCellValue('C4', 'Progreso');
|
|
|
2409 |
$spreadsheet->getActiveSheet()->SetCellValue('D4', 'Diapositivas Totales');
|
|
|
2410 |
$spreadsheet->getActiveSheet()->SetCellValue('E4', 'Diapositivas Vistas');
|
|
|
2411 |
$spreadsheet->getActiveSheet()->SetCellValue('F4', 'Cápsula Completada');
|
|
|
2412 |
$spreadsheet->getActiveSheet()->SetCellValue('G4', 'Inicio');
|
|
|
2413 |
$spreadsheet->getActiveSheet()->SetCellValue('H4', 'Ultima vez');
|
|
|
2414 |
|
|
|
2415 |
$i = 5;
|
|
|
2416 |
foreach($records as $record)
|
|
|
2417 |
{
|
|
|
2418 |
$spreadsheet->getActiveSheet()->SetCellValue('A' . $i, ucwords(strtolower(trim($record['topic']))));
|
|
|
2419 |
$spreadsheet->getActiveSheet()->SetCellValue('B' . $i, ucwords(strtolower(trim($record['capsule']))));
|
|
|
2420 |
$spreadsheet->getActiveSheet()->SetCellValue('C' . $i, $record['progress']);
|
|
|
2421 |
$spreadsheet->getActiveSheet()->SetCellValue('D' . $i, $record['total_slides']);
|
|
|
2422 |
$spreadsheet->getActiveSheet()->SetCellValue('E' . $i, $record['view_slides']);
|
|
|
2423 |
$spreadsheet->getActiveSheet()->SetCellValue('F' . $i, $record['completed'] == 1 ? 'Si' : 'No');
|
|
|
2424 |
$spreadsheet->getActiveSheet()->SetCellValue('G' . $i, $record['added_on']);
|
|
|
2425 |
$spreadsheet->getActiveSheet()->SetCellValue('H' . $i, $record['updated_on']);
|
|
|
2426 |
$i++;
|
|
|
2427 |
}
|
|
|
2428 |
|
|
|
2429 |
|
|
|
2430 |
$fileName = 'reporte_progreso_por_estudiante_' . time() . '.xls';
|
|
|
2431 |
|
|
|
2432 |
$tempFilename = tempnam(sys_get_temp_dir(), 'reporte_progreso_por_estudiante_' . time());
|
|
|
2433 |
|
|
|
2434 |
|
|
|
2435 |
|
|
|
2436 |
|
|
|
2437 |
|
|
|
2438 |
$writer = IOFactory::createWriter($spreadsheet, 'Xls');
|
|
|
2439 |
$writer->save($tempFilename);
|
|
|
2440 |
|
|
|
2441 |
$content = file_get_contents($tempFilename);
|
|
|
2442 |
@unlink($tempFilename);
|
|
|
2443 |
|
|
|
2444 |
return new JsonModel([
|
|
|
2445 |
'success' => true,
|
|
|
2446 |
'data' => [
|
|
|
2447 |
'content' => base64_encode($content),
|
|
|
2448 |
'basename' => $fileName
|
|
|
2449 |
|
|
|
2450 |
]
|
|
|
2451 |
]);
|
|
|
2452 |
|
|
|
2453 |
|
|
|
2454 |
|
|
|
2455 |
|
|
|
2456 |
} else {
|
|
|
2457 |
return new JsonModel([
|
|
|
2458 |
'success' => false,
|
|
|
2459 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
2460 |
]);
|
|
|
2461 |
}
|
|
|
2462 |
}
|
|
|
2463 |
|
|
|
2464 |
|
|
|
2465 |
}
|