Skip to content

Commit

Permalink
Find last access when bringing up save points
Browse files Browse the repository at this point in the history
Fixes #65
  • Loading branch information
Syxton committed Feb 6, 2025
1 parent 20185c6 commit e1b0897
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 3 deletions.
10 changes: 10 additions & 0 deletions classes/processor.php
Original file line number Diff line number Diff line change
Expand Up @@ -1352,6 +1352,16 @@ public function get_list_of_admins_and_managers() {
return $adminsandmanagers;
}

/**
* Static method to get list of the userid's of admin and other users with course view capability
*
* @return string
*/
public static function get_list_of_admins_and_managers_static() {
$processor = new self(["mode" => self::MODE_COURSELIST, "data" => []]);
return $processor->get_list_of_admins_and_managers();
}

/**
* Get an HTML table listing courses to put in the email.
*
Expand Down
41 changes: 38 additions & 3 deletions classes/tracker.php
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ public function start() {
* @return void
*/
public function output($data, $info = false) {
global $CFG;
global $CFG, $DB;

$return = 1; // By default we are returning the a single process as finished.

Expand All @@ -441,9 +441,10 @@ public function output($data, $info = false) {
$cliicon = get_string('visible', 'tool_coursearchiver');
}
$empty = $this->empty ? ";" . get_string('empty', 'tool_coursearchiver') . " " : " ";
$date = get_string('never', 'tool_coursearchiver');
if (!empty($data->timeaccess)) {
$date = date("m/d/y", $data->timeaccess);
} else {
$date = $this->get_lastaccessed($data->id);
}
$this->buffer->output(sprintf($this->maskcourses,
$cliicon . $empty,
Expand Down Expand Up @@ -512,9 +513,10 @@ public function output($data, $info = false) {
}

$hiddenclass = empty($data->visible) ? 'coursearchiver_alreadyhidden' : '';
$date = get_string('never', 'tool_coursearchiver');
if (!empty($data->timeaccess)) {
$date = date("m/d/y", $data->timeaccess);
} else {
$date = $this->get_lastaccessed($data->id);
}
$this->mform->addElement('html',
html_writer::end_tag('td') .
Expand Down Expand Up @@ -721,4 +723,37 @@ protected function get_progressbar() {
</div>';
}
}

/**
* Gets latest course access date.
* @param int $courseid the course id.
* @return string
*/
protected function get_lastaccessed($courseid) {
global $DB;
$adminsandmanagers = tool_coursearchiver_processor::get_list_of_admins_and_managers_static();
$sql = "SELECT c.id, a.timeaccess
FROM {course} c
LEFT JOIN (
SELECT a.courseid, a.timeaccess
FROM {user_lastaccess} a
JOIN (
SELECT courseid, MAX(timeaccess) as timeaccess
FROM {user_lastaccess} b
WHERE b.userid NOT IN ($adminsandmanagers)
GROUP BY courseid
) b ON (
a.courseid = b.courseid
AND
a.timeaccess = b.timeaccess
)
) a ON c.id = a.courseid
WHERE c.id = :courseid
ORDER BY a.timeaccess LIMIT 1";

if (!$data = $DB->get_record_sql($sql, ['courseid' => $courseid])) {
return get_string('never', 'tool_coursearchiver');
}
return date("m/d/y", $data->timeaccess);
}
}

0 comments on commit e1b0897

Please sign in to comment.