Skip to content

Commit

Permalink
Issue #71: Add number of attempts to Assessment dashboard - dayview
Browse files Browse the repository at this point in the history
  • Loading branch information
guillogo committed Mar 3, 2021
1 parent 536b979 commit 94c26e8
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 2 deletions.
48 changes: 48 additions & 0 deletions classes/frequency.php
Original file line number Diff line number Diff line change
Expand Up @@ -1120,6 +1120,48 @@ public function get_years_has_events(bool $cache=true): array {
return $years;
}

/**
* Get last trend during an assessment.
*
* @param int $assessid The assessment id.
* @param bool $cache Fetch events from cache.
* @return \stdClass $trend Last trend during an assessment.
*/
public function get_last_trend_by_assessid(int $assessid, bool $cache=true): \stdClass {
global $DB;
$trend = new \stdClass;
$cachekey = (string)$assessid;

// Try to get value from cache.
$trendcache = cache::make('local_assessfreq', 'trendassess');
$data = $trendcache->get($cachekey);

if ($data && (time() < $data->expiry) && $cache) { // Valid cache data.
$trend = $data->trend;
} else { // Not valid cache data.
$sql = "SELECT *
FROM {local_assessfreq_trend}
WHERE assessid = ?
ORDER BY id DESC
LIMIT 1";

$trend = $DB->get_record_sql($sql, [$assessid]);
}

// Update cache.
if (!empty($trend)) {
$expiry = time() + $this->expiryperiod;
$data = new \stdClass();
$data->expiry = $expiry;
$data->trend = $trend;
$trendcache->set($cachekey, $data);
} else {
$trend = new \stdClass;
}

return $trend;
}

/**
* Get all events on a particular day.
*
Expand Down Expand Up @@ -1163,6 +1205,12 @@ public function get_day_events(string $date, array $modules): array {
if ($event->module == 'quiz') {
$dashurl = new \moodle_url('/local/assessfreq/dashboard_quiz.php', array('id' => $event->instanceid));
$event->dashurl = $dashurl->out();

if ($attempts = $this->get_last_trend_by_assessid($event->instanceid)) {
$event->attempts = $attempts->inprogress + $attempts->finished;
}
} else {
$event->attempts = get_string('na', 'local_assessfreq');
}

$event->courseshortname = $course->shortname;
Expand Down
6 changes: 6 additions & 0 deletions db/caches.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,5 +80,11 @@
'simplekeys' => true,
'simpledata' => false
],
'trendassess' => [
'mode' => cache_store::MODE_APPLICATION,
'staticacceleration' => true,
'simplekeys' => true,
'simpledata' => false
],
];

1 change: 1 addition & 0 deletions lang/en/local_assessfreq.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
$string['assessbymonthstudents'] = 'Students with assessments due by month';
$string['assessheatmap'] = 'Assessment heatmap for year:';
$string['assessoverview'] = 'Assessment overviews for year:';
$string['attempts'] = 'Attempts';
$string['cachedef_eventsdueactivity'] = 'Events due by activity cache';
$string['cachedef_eventsduemonth'] = 'Events due by month cache';
$string['cachedef_eventusers'] = 'Users for month cache';
Expand Down
13 changes: 11 additions & 2 deletions templates/dayview.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
<col class="dayview-midcol">
<col class="dayview-midcol">
<col class="dayview-midcol">
<col class="dayview-midcol">
<col>
</colgroup>
<thead>
Expand All @@ -46,7 +47,12 @@
{{#pix}} i/calendareventtime, core{{/pix}}
</span>
</th>
<th scope="col" rowspan="2" class="text-center">
<th scope="col" rowspan="2" class="text-center">
<span data-toggle="tooltip" data-placement="top" title="{{#str}} attempts, local_assessfreq {{/str}}" data-offset="0,5">
{{#pix}} i/checked, core{{/pix}}
</span>
</th>
<th scope="col" rowspan="2" class="text-center">
<span data-toggle="tooltip" data-placement="top" title="{{#str}} dashboard, local_assessfreq {{/str}}" data-offset="0,5">
{{#pix}} i/report, core{{/pix}}
</span>
Expand Down Expand Up @@ -77,9 +83,12 @@
<th scope="row" class="text-center">
{{ usercount }}
</th>
<th scope="row" class="text-center">
<th scope="row" class="text-center">
{{ timelimit }}
</th>
<th scope="row" class="text-center">
{{ attempts }}
</th>
<th scope="row" class="text-center">
{{#dashurl}} <a href="{{dashurl}}">{{#pix}} i/report, core{{/pix}}</a> {{/dashurl}}
{{^dashurl}} {{#str}} na, local_assessfreq {{/str}} {{/dashurl}}
Expand Down

0 comments on commit 94c26e8

Please sign in to comment.