Skip to content

Commit d25648d

Browse files
committed
Plugin: ExerciseMonitoring: Move code to function - BT#21074
1 parent 8e397cf commit d25648d

File tree

1 file changed

+36
-31
lines changed

1 file changed

+36
-31
lines changed

plugin/exercisefocused/pages/export.php

Lines changed: 36 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
$em = Database::getManager();
2828
$focusedLogRepository = $em->getRepository(FocusedLog::class);
2929
$attempsRepository = $em->getRepository(TrackEAttempt::class);
30-
$monitoringLogRepository = $em->getRepository(MonitoringLog::class);
3130

3231
if (!$plugin->isEnabled(true)) {
3332
api_not_allowed(true);
@@ -85,23 +84,18 @@
8584
];
8685
$data[] = [];
8786

87+
$data[] = [
88+
$plugin->get_lang('LevelReached'),
89+
get_lang('DateExo'),
90+
get_lang('Score'),
91+
$plugin->get_lang('Outfocused'),
92+
$plugin->get_lang('Returns'),
93+
$monitoringPluginIsEnabled ? $monitoringPlugin->get_lang('Snapshots') : '',
94+
];
95+
8896
if (ONE_PER_PAGE === $quizType) {
8997
$questionList = explode(',', $trackExe->getDataTracking());
9098

91-
$row = [
92-
$plugin->get_lang('LevelReached'),
93-
get_lang('DateExo'),
94-
get_lang('Score'),
95-
$plugin->get_lang('Outfocused'),
96-
$plugin->get_lang('Returns'),
97-
];
98-
99-
if ($monitoringPluginIsEnabled) {
100-
$row[] = $monitoringPlugin->get_lang('Snapshots');
101-
}
102-
103-
$data[] = $row;
104-
10599
foreach ($questionList as $idx => $questionId) {
106100
$attempt = $attempsRepository->findOneBy(
107101
['exeId' => $trackExe->getExeId(), 'questionId' => $questionId],
@@ -130,24 +124,9 @@
130124
$result['score'].' / '.$result['weight'],
131125
$focusedLogRepository->countByActionAndLevel($trackExe, FocusedLog::TYPE_OUTFOCUSED, $questionId),
132126
$focusedLogRepository->countByActionAndLevel($trackExe, FocusedLog::TYPE_RETURN, $questionId),
127+
getSnapshotListForLevel($questionId, $trackExe),
133128
];
134129

135-
if ($monitoringPluginIsEnabled) {
136-
$monitoringLogsByQuestion = $monitoringLogRepository->findByLevelAndExe($questionId, $trackExe);
137-
$snapshotList = [];
138-
139-
/** @var MonitoringLog $logByQuestion */
140-
foreach ($monitoringLogsByQuestion as $logByQuestion) {
141-
$snapshotUrl = ExerciseMonitoringPlugin::generateSnapshotUrl(
142-
$user->getId(),
143-
$logByQuestion->getImageFilename()
144-
);
145-
$snapshotList[] = api_get_local_time($logByQuestion->getCreatedAt()).' '.$snapshotUrl;
146-
}
147-
148-
$row[] = implode(PHP_EOL, $snapshotList);
149-
}
150-
151130
$data[] = $row;
152131
}
153132
} elseif (ALL_ON_ONE_PAGE === $quizType) {
@@ -261,3 +240,29 @@ function findResults(array $formValues, EntityManagerInterface $em, ExerciseFocu
261240

262241
return $query->getResult();
263242
}
243+
244+
function getSnapshotListForLevel(int $level, TrackEExercises $trackExe): string
245+
{
246+
$monitoringPluginIsEnabled = ExerciseMonitoringPlugin::create()->isEnabled(true);
247+
248+
if (!$monitoringPluginIsEnabled) {
249+
return '';
250+
}
251+
252+
$user = api_get_user_entity($trackExe->getExeUserId());
253+
$monitoringLogRepository = Database::getManager()->getRepository(MonitoringLog::class);
254+
255+
$monitoringLogsByQuestion = $monitoringLogRepository->findByLevelAndExe($level, $trackExe);
256+
$snapshotList = [];
257+
258+
/** @var MonitoringLog $logByQuestion */
259+
foreach ($monitoringLogsByQuestion as $logByQuestion) {
260+
$snapshotUrl = ExerciseMonitoringPlugin::generateSnapshotUrl(
261+
$user->getId(),
262+
$logByQuestion->getImageFilename()
263+
);
264+
$snapshotList[] = api_get_local_time($logByQuestion->getCreatedAt()).' '.$snapshotUrl;
265+
}
266+
267+
return implode(PHP_EOL, $snapshotList);
268+
}

0 commit comments

Comments
 (0)