Skip to content

Commit e04802b

Browse files
committed
Plugin: ExerciseFocused: Display motive in report with contextual style - refs BT#21074
1 parent c49cefd commit e04802b

File tree

3 files changed

+38
-18
lines changed

3 files changed

+38
-18
lines changed

plugin/exercisefocused/lang/english.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
$strings['SelectExercise'] = "Select exercise";
2525
$strings['UnselectExercise'] = "Unselect exercise";
2626
$strings['Returns'] = "Returns";
27-
$strings['MaxOutfocused'] = "Max Outfocused";
28-
$strings['TimeLimitReached'] = "Time Limit reached";
27+
$strings['MaxOutfocusedReached'] = "Max outfocused reached";
28+
$strings['TimeLimitReached'] = "Time limit reached";
2929
$strings['Outfocused'] = "Outfocused";
3030
$strings['Return'] = "Return";
3131
$strings['Motive'] = "Motive";

plugin/exercisefocused/src/ExerciseFocusedPlugin.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public function getActionTitle($action): string
113113
case Log::TYPE_RETURN:
114114
return $this->get_lang('Return');
115115
case Log::TYPE_OUTFOCUSED_LIMIT:
116-
return $this->get_lang('MaxOutfocused');
116+
return $this->get_lang('MaxOutfocusedReached');
117117
case Log::TYPE_TIME_LIMIT:
118118
return $this->get_lang('TimeLimitReached');
119119
}

plugin/exercisefocused/src/Traits/ReportingFilterTrait.php

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -149,20 +149,41 @@ protected function formatResults(array $queryResults): array
149149
$results = [];
150150

151151
foreach ($queryResults as $value) {
152+
$outfocusedCount = $this->logRepository->countByActionInExe($value['exe'], Log::TYPE_OUTFOCUSED);
153+
$returnCount = $this->logRepository->countByActionInExe($value['exe'], Log::TYPE_RETURN);
154+
$outfocusedLimitCount = $this->logRepository->countByActionInExe($value['exe'], Log::TYPE_OUTFOCUSED_LIMIT);
155+
$timeLimitCount = $this->logRepository->countByActionInExe($value['exe'], Log::TYPE_TIME_LIMIT);
156+
157+
$class = 'success';
158+
$motive = get_lang('ExerciseFinished');
159+
160+
if ($outfocusedCount > 0 || $returnCount > 0) {
161+
$class = 'warning';
162+
}
163+
164+
if ($outfocusedLimitCount > 0 || $timeLimitCount > 0) {
165+
$class = 'danger';
166+
167+
if ($outfocusedLimitCount > 0) {
168+
$motive = $this->plugin->get_lang('MaxOutfocusedReached');
169+
}
170+
171+
if ($timeLimitCount > 0) {
172+
$motive = $this->plugin->get_lang('TimeLimitReached');
173+
}
174+
}
175+
152176
$results[] = [
153177
'id' => $value['exe']->getExeId(),
154178
'quiz_title' => $value['title'],
155179
'username' => $value['username'],
156180
'user_fullname' => api_get_person_name($value['firstname'], $value['lastname']),
157181
'start_date' => $value['exe']->getStartDate(),
158182
'end_date' => $value['exe']->getExeDate(),
159-
'count_outfocused' => $this->logRepository->countByActionInExe($value['exe'], Log::TYPE_OUTFOCUSED),
160-
'count_return' => $this->logRepository->countByActionInExe($value['exe'], Log::TYPE_RETURN),
161-
'max_outfocused' => $this->logRepository->countByActionInExe(
162-
$value['exe'],
163-
Log::TYPE_OUTFOCUSED_LIMIT
164-
) > 0,
165-
'time_limit_reached' => $this->logRepository->countByActionInExe($value['exe'], Log::TYPE_TIME_LIMIT) > 0,
183+
'count_outfocused' => $outfocusedCount,
184+
'count_return' => $returnCount,
185+
'motive' => Display::span($motive, ['class' => "text-$class"]),
186+
'class' => $class,
166187
];
167188
}
168189

@@ -183,9 +204,8 @@ protected function createTable(array $tableData): HTML_Table
183204
$table->setHeaderContents(0, 4, get_lang('EndDate'));
184205
$table->setHeaderContents(0, 5, $this->plugin->get_lang('Outfocused'));
185206
$table->setHeaderContents(0, 6, $this->plugin->get_lang('Returns'));
186-
$table->setHeaderContents(0, 7, $this->plugin->get_lang('MaxOutfocused'));
187-
$table->setHeaderContents(0, 8, $this->plugin->get_lang('TimeLimitReached'));
188-
$table->setHeaderContents(0, 9, get_lang('Actions'));
207+
$table->setHeaderContents(0, 7, $this->plugin->get_lang('Motive'));
208+
$table->setHeaderContents(0, 8, get_lang('Actions'));
189209

190210
$row = 1;
191211

@@ -206,9 +226,10 @@ protected function createTable(array $tableData): HTML_Table
206226
$table->setCellContents($row, 4, api_get_local_time($result['end_date'], null, null, true, true, true));
207227
$table->setCellContents($row, 5, $result['count_outfocused']);
208228
$table->setCellContents($row, 6, $result['count_return']);
209-
$table->setCellContents($row, 7, $result['max_outfocused'] ? get_lang('Yes') : '');
210-
$table->setCellContents($row, 8, $result['time_limit_reached'] ? get_lang('Yes') : '');
211-
$table->setCellContents($row, 9, $url);
229+
$table->setCellContents($row, 7, $result['motive']);
230+
$table->setCellContents($row, 8, $url);
231+
232+
$table->setRowAttributes($row, ['class' => $result['class']], true);
212233

213234
$row++;
214235
}
@@ -218,8 +239,7 @@ protected function createTable(array $tableData): HTML_Table
218239
$table->setColAttributes(5, ['class' => 'text-right']);
219240
$table->setColAttributes(6, ['class' => 'text-right']);
220241
$table->setColAttributes(7, ['class' => 'text-center']);
221-
$table->setColAttributes(8, ['class' => 'text-center']);
222-
$table->setColAttributes(9, ['class' => 'text-right']);
242+
$table->setColAttributes(8, ['class' => 'text-right']);
223243

224244
return $table;
225245
}

0 commit comments

Comments
 (0)