Skip to content

Commit

Permalink
WR422914 JS and visual fixes
Browse files Browse the repository at this point in the history
* Updated lib function to only return modules that are used on the report
* Clear caches when scheduled task runs to keep in sync
* CSS changes for dropdown items click and hover
* Missing lang string
* Activites in progress filter fixed
  • Loading branch information
SimonThornett committed Nov 11, 2024
1 parent 8e2704e commit 6c2a93d
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 18 deletions.
11 changes: 11 additions & 0 deletions classes/frequency.php
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,17 @@ public function delete_events(int $duedate): void {
}
}

// Clear the caches to prevent desync between caches and database.
cache::make('local_assessfreq', 'siteevents')->purge();
cache::make('local_assessfreq', 'userevents')->purge();
cache::make('local_assessfreq', 'courseevents')->purge();
cache::make('local_assessfreq', 'eventsduemonth')->purge();
cache::make('local_assessfreq', 'monthlyuser')->purge();
cache::make('local_assessfreq', 'eventsdueactivity')->purge();
cache::make('local_assessfreq', 'yearevents')->purge();
cache::make('local_assessfreq', 'usereventsallfrequencyarray')->purge();
cache::make('local_assessfreq', 'eventusers')->purge();

$transaction->allow_commit();
} catch (Exception $e) {
$transaction->rollback($e);
Expand Down
11 changes: 8 additions & 3 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,19 @@ function get_reports($ignoreenabled = false) : array {
* @param $ignoreenabled
* @return array
*/
function get_sources($ignoreenabled = false) : array {
function get_sources($ignoreenabled = false, $requiredmethod = '') : array {
$sources = [];
$pluginmanager = core_plugin_manager::instance();
foreach ($pluginmanager->get_plugins_of_type('assessfreqsource') as $subplugin) {
if ($subplugin->is_enabled() || $ignoreenabled) {
/* @var $class source_base */
$class = "assessfreqsource_{$subplugin->name}\\source";
$source = $class::get_instance();
if (!empty($requiredmethod)) {
if (!method_exists($source, $requiredmethod)) {
continue;
}
}
$sources[$subplugin->name] = $source;
}
}
Expand Down Expand Up @@ -151,9 +156,9 @@ function get_years($preference) : array {
*
* @return array $modules The enabled modules.
*/
function get_modules($preferences) : array {
function get_modules($preferences, $requiredmethod= '') : array {

$sources = get_sources();
$sources = get_sources(false, $requiredmethod);

// Get modules for filters and load into context.
$modules = [];
Expand Down
19 changes: 9 additions & 10 deletions report/activities_in_progress/classes/output/renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function render_report($data) {
]
);

// upcoming activities starting.
// Upcoming activities starting.
$labels = [];
$seriestitle = get_string('upcomingchart:activities', 'assessfreqreport_activities_in_progress');
$participantseries = get_string('upcomingchart:participants', 'assessfreqreport_activities_in_progress');
Expand Down Expand Up @@ -202,19 +202,18 @@ public function render_report($data) {
8 => 'hours8',
];

$preferencemodule = json_decode(
get_user_preferences('assessfreqreport_activities_in_progress_modules_preference', '["all"]'),
true
);
// Only get modules with the "get_inprogress_count" method as only these display on the report.
$modules = get_modules($preferencemodule, 'get_inprogress_count');

return $this->render_from_template(
'assessfreqreport_activities_in_progress/activities-in-progress',
[
'filters' => [
'modules' => get_modules(
json_decode(
get_user_preferences(
'assessfreqreport_activities_in_progress_modules_preference',
'["all"]'
),
true
)
),
'modules' => $modules,
'hoursahead' => [$hours[$preferencehoursahead] => 'true'],
'hoursbehind' => [$hours[$preferencehoursbehind] => 'true'],
],
Expand Down
1 change: 1 addition & 0 deletions report/heatmap/classes/output/renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public function render_report($preferenceyear, $preferencemodules, $preferenceme
$scalestable->data = [new html_table_row($scalecells)];

$modules = get_modules($preferencemodules);

$selectedmodules = [];
foreach ($modules as $module) {
if (isset($module['module']['active'])) {
Expand Down
18 changes: 16 additions & 2 deletions report/student_search/classes/output/user_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,9 @@ public function col_timeclose($row) {
* @return string html used to display the field.
*/
public function col_timelimit($row) {
if ($row->timelimit == '0') {
return '-';
}
$timelimit = format_time($row->timelimit);

if ($row->timelimit != $row->quiztimelimit) {
Expand Down Expand Up @@ -419,7 +422,7 @@ public function col_actions($row) {
* @param array $quizzes Array of quizzes to sort.
* @return array $quizzes the sorted quizzes.
*/
public function sort_quizzes(array $quizzes): array {
public function sort(array $quizzes): array {
// Comparisons are performed according to PHP's usual type comparison rules.
uasort($quizzes, function ($a, $b) {

Expand Down Expand Up @@ -571,7 +574,7 @@ public function query_db($pagesize, $useinitialsbar = false) {
}

if (!empty($this->get_sql_sort())) {
$allrecords = $this->sort_quizzes($allrecords);
$allrecords = $this->sort($allrecords);
}

$data = [];
Expand Down Expand Up @@ -610,4 +613,15 @@ public function query_db($pagesize, $useinitialsbar = false) {
$this->pagesize($pagesize, $offsetcount);
$this->rawdata = $data;
}

/**
* Override the table's show_hide_link method to prevent the show/hide links from rendering.
*
* @param string $column the column name, index into various names.
* @param int $index numerical index of the column.
* @return string HTML fragment.
*/
protected function show_hide_link($column, $index) {
return '';
}
}
50 changes: 50 additions & 0 deletions source/assign/classes/source.php
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,56 @@ public function get_inprogress_count(int $now, int $hoursahead, int $hoursbehind
return get_string('inprogress:assessments', 'assessfreqsource_assign', $counts);
}

/**
* Generate the markup for the summary chart,
* used in the in progress quizzes dashboard.
*
* @param int $now Timestamp to get chart data for.
* @return array With Generated chart object and chart data status.
*/
public function get_all_participants_inprogress_data(int $now, int $hoursahead, int $hoursbehind) : array {

// Get assignments for the supplied timestamp.
$assignments = $this->get_assign_summaries($now, $hoursahead, $hoursbehind);

$inprogressassignments = $assignments['inprogress'];
$upcomingassignments = $assignments['upcoming'];
$finishedassignments = $assignments['finished'];

foreach ($upcomingassignments as $upcomingassignment) {
foreach ($upcomingassignment as $timestampupcoming => $upcoming) {
$inprogressassignments[$timestampupcoming] = $upcoming;
}
}

foreach ($finishedassignments as $finishedassignment) {
foreach ($finishedassignment as $timestampfinished => $finished) {
$inprogressassignments[$timestampfinished] = $finished;
}
}

$notloggedin = 0;
$loggedin = 0;
$inprogress = 0;
$finished = 0;

foreach ($inprogressassignments as $inprogressassignment) {
if (!empty($inprogressassignment->tracking)) {
$notloggedin += $inprogressassignment->tracking->notloggedin;
$loggedin += $inprogressassignment->tracking->loggedin;
$inprogress += $inprogressassignment->tracking->inprogress;
$finished += $inprogressassignment->tracking->finished;
}
}

return [
'notloggedin' => $notloggedin,
'loggedin' => $loggedin,
'inprogress' => $inprogress,
'finished' => $finished,
];
}

/**
* Get data for all inprogress assignments.
*
Expand Down
4 changes: 1 addition & 3 deletions styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,7 @@ body #local-assessfreq-index {
min-height: calc(100vh - 250px);
}

#local-assessfreq-index .dropdown-menu .dropdown-item:active,
#local-assessfreq-index .dropdown-menu .dropdown-item:focus,
#local-assessfreq-index .dropdown-menu .dropdown-item:focus-within {
#local-assessfreq-index .dropdown-menu .dropdown-item.active {
outline: 0 !important;
background-color: #0176be !important;
color: #fff !important;
Expand Down

0 comments on commit 6c2a93d

Please sign in to comment.