Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #71: Add number of attempts to Assessment dashboard - dayview #89

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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