Skip to content
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
6 changes: 4 additions & 2 deletions condition/activitystudentend/classes/observer.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,11 @@ public static function course_module_viewed(course_module_viewed $event) {

$pluginname = activitystudentend::NAME;

activitystudentend::set_activity_access($userid, $courseid, $cmid, $timecreated);

$conditions = notificationsagent::get_conditions_by_cm($pluginname, $courseid, $cmid);

if (!empty($conditions)) {
activitystudentend::set_activity_access($userid, $courseid, $cmid, $timecreated);
}

foreach ($conditions as $condition) {
$conditionid = $condition->id;
Expand Down
9 changes: 5 additions & 4 deletions condition/sessionstart/classes/observer.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,13 @@ public static function course_viewed(course_viewed $event) {
$timeaccess = $event->timecreated;
// Only triggered if is the first access to a course, otherwise return.
$firstaccess = sessionstart::get_first_course_access($userid, $courseid);
if (!$firstaccess) {
if (!empty($firstaccess)) {
// If the first access is not empty, it means that the user has already accessed the course.
// So we do not need to updatetrigger the conditions.
return null;
}

// We use this event to avoid querying the log_standard_log for a course firstaccess.
sessionstart::set_first_course_access($userid, $courseid, $timeaccess);
// If the first access is empty, it means that the user has not accessed the course yet.
// So we need to update the triggers of the conditions.

$pluginname = sessionstart::NAME;
$conditions = notificationsagent::get_conditions_by_course($pluginname, $courseid);
Expand Down
14 changes: 8 additions & 6 deletions condition/sessionstart/classes/sessionstart.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,21 +235,21 @@ public static function set_first_course_access($userid, $courseid, $timeaccess)

/**
* Get the first access time for a specific user and course.
*
* It checks the custom table first and if not found, it queries the logstore_standard_log table.
* It stores the first access time in the custom table for future fast access.
* @param int $userid user id
* @param int $courseid course id
*
* @return mixed return firstacces to a course
* @return mixed|null return firstacces to a course or null if not found.
*/
public static function get_first_course_access(int $userid, int $courseid) {
global $DB;
$firstaccess = null;
$crsefirstaccess = coursefirstaccess::get_record(['courseid' => $courseid, 'userid' => $userid]);
if (!empty($crsefirstaccess)) {
$firstaccess = $crsefirstaccess->get('firstaccess');
}

if (empty($firstaccess)) {
} else {
// If the first access is not set, we check the logstore_standard_log table.
$query = 'SELECT timecreated
FROM {logstore_standard_log}
WHERE courseid = :courseid
Expand All @@ -268,9 +268,11 @@ public static function get_first_course_access(int $userid, int $courseid) {
);

if (!$result) {
return $firstaccess;
return null;
}
$firstaccess = $result->timecreated;
// We record this time in custom table to avoid querying the log_standard_log for a course firstaccess.
sessionstart::set_first_course_access($userid, $courseid, $firstaccess);
}

return $firstaccess;
Expand Down