for recording the last access to the COURSE.
This is updated at the same time as add_to_log and is now used instead
of user->lastaccess when course user listings are required.
This means course listings now show what you expect and open up the way
for a "current users" listing and instant messaging etc ...
$users = array();
if ($course->category) {
- $courseusers = get_course_users($course->id, "u.lastaccess DESC");
+ $courseusers = get_course_users($course->id);
} else {
$courseusers = get_site_users("u.lastaccess DESC", "u.id, u.firstname, u.lastname");
}
/**
* Returns list of all students in this course
*
-* if courseid = 0 then return ALL students in all courses
-*
* @param type description
*/
-function get_course_students($courseid, $sort="u.lastaccess", $dir="", $page=0, $recordsperpage=99999) {
+function get_course_students($courseid, $sort="s.timeaccess", $dir="", $page=0, $recordsperpage=99999) {
global $CFG;
}
return get_records_sql("SELECT u.id, u.username, u.firstname, u.lastname, u.maildisplay, u.mailformat,
- u.email, u.city, u.country, u.lastaccess, u.lastlogin, u.picture
+ u.email, u.city, u.country, u.lastlogin, u.picture, s.timeaccess as lastaccess
FROM {$CFG->prefix}user u,
{$CFG->prefix}user_students s
WHERE s.course = '$courseid' AND s.userid = u.id AND u.deleted = '0'
/**
* Returns list of all teachers in this course
*
-* if courseid = 0 then return ALL teachers in all courses
-*
* @param type description
*/
function get_course_teachers($courseid, $sort="t.authority ASC") {
global $CFG;
- return get_records_sql("SELECT u.*,t.authority,t.role,t.editall
+ return get_records_sql("SELECT u.id, u.username, u.firstname, u.lastname, u.maildisplay, u.mailformat,
+ u.email, u.city, u.country, u.lastlogin, u.picture,
+ t.authority,t.role,t.editall,t.timeaccess as lastaccess
FROM {$CFG->prefix}user u,
{$CFG->prefix}user_teachers t
WHERE t.course = '$courseid' AND t.userid = u.id AND u.deleted = '0'
*
* @param type description
*/
-function get_course_users($courseid, $sort="u.lastaccess DESC") {
+function get_course_users($courseid, $sort="timeaccess DESC") {
$site = get_site();
* @param string $url the file and parameters used to see the results of the action
* @param string $info additional description information
*/
-function add_to_log($course, $module, $action, $url="", $info="") {
+function add_to_log($courseid, $module, $action, $url="", $info="") {
global $db, $CFG, $USER, $REMOTE_ADDR;
info)
VALUES ('$timenow',
'$userid',
- '$course',
+ '$courseid',
'$REMOTE_ADDR',
'$module',
'$action',
if (!$result and ($CFG->debug > 7)) {
echo "<P>Error: Could not insert a new entry to the Moodle log</P>"; // Don't throw an error
}
+
+ if (isstudent($courseid)) {
+ $db->Execute("UPDATE {$CFG->prefix}user_students SET timeaccess = '$timenow' ".
+ "WHERE course = '$courseid' AND userid = '$userid'");
+ }
+
+ if (isteacher($courseid, false, false)) {
+ $db->Execute("UPDATE {$CFG->prefix}user_teachers SET timeaccess = '$timenow' ".
+ "WHERE course = '$courseid' AND userid = '$userid'");
+ }
}
function main_upgrade($oldversion=0) {
- global $CFG, $THEME;
+ global $CFG, $THEME, $db;
$result = true;
table_column("course", "", "maxbytes", "integer", "10", "unsigned", "0", "", "marker");
}
+ if ($oldversion < 2003102700) {
+ table_column("user_students", "", "timeaccess", "integer", "10", "unsigned", "0", "", "time");
+ table_column("user_teachers", "", "timeaccess", "integer", "10", "unsigned", "0", "", "timemodified");
+
+ $users = get_records_select("user", "id > 0", "", "id, lastaccess");
+
+ $db->debug = false;
+ foreach ($users as $user) {
+ execute_sql("UPDATE {$CFG->prefix}user_students SET timeaccess = '$user->lastaccess' WHERE userid = '$user->id'", false);
+ execute_sql("UPDATE {$CFG->prefix}user_teachers SET timeaccess = '$user->lastaccess' WHERE userid = '$user->id'", false);
+ }
+ $db->debug = true;
+ }
+
return $result;
}
`timestart` int(10) unsigned NOT NULL default '0',
`timeend` int(10) unsigned NOT NULL default '0',
`time` int(10) unsigned NOT NULL default '0',
+ `timeaccess` int(10) unsigned NOT NULL default '0',
PRIMARY KEY (`id`),
UNIQUE KEY `id` (`id`),
KEY `courseuserid` (course,userid)
`role` varchar(40) NOT NULL default '',
`editall` int(1) unsigned NOT NULL default '1',
`timemodified` int(10) unsigned NOT NULL default '0',
+ `timeaccess` int(10) unsigned NOT NULL default '0',
PRIMARY KEY (`id`),
UNIQUE KEY `id` (`id`),
KEY `courseuserid` (course,userid)
function main_upgrade($oldversion=0) {
- global $CFG, $THEME;
+ global $CFG, $THEME, $db;
$result = true;
table_column("course", "", "maxbytes", "integer", "10", "unsigned", "0", "", "marker");
}
+ if ($oldversion < 2003102700) {
+ table_column("user_students", "", "timeaccess", "integer", "10", "unsigned", "0", "", "time");
+ table_column("user_teachers", "", "timeaccess", "integer", "10", "unsigned", "0", "", "timemodified");
+
+ $users = get_records_select("user", "id > 0", "", "id, lastaccess");
+
+ $db->debug = false;
+ foreach ($users as $user) {
+ execute_sql("UPDATE {$CFG->prefix}user_students SET timeaccess = '$user->lastaccess' WHERE userid = '$user->id'", false);
+ execute_sql("UPDATE {$CFG->prefix}user_teachers SET timeaccess = '$user->lastaccess' WHERE userid = '$user->id'", false);
+ }
+ $db->debug = true;
+ }
+
+
return $result;
}
?>
course integer NOT NULL default '0',
timestart integer NOT NULL default '0',
timeend integer NOT NULL default '0',
- time integer NOT NULL default '0'
+ time integer NOT NULL default '0',
+ timeaccess integer NOT NULL default '0'
);
CREATE INDEX prefix_user_students_courseuserid_idx ON prefix_user_students (course,userid);
authority integer NOT NULL default '3',
role varchar(40) NOT NULL default '',
editall integer NOT NULL default '1',
- timemodified integer NOT NULL default '0'
+ timemodified integer NOT NULL default '0',
+ timeaccess integer NOT NULL default '0'
);
CREATE INDEX prefix_user_teachers_courseuserid_idx ON prefix_user_teachers (course,userid);
}
}
- $dsort = "u.$sort";
+ if ($sort = lastaccess) {
+ $dsort = "s.timeaccess";
+ } else {
+ $dsort = "u.$sort";
+ }
$totalcount = count_records("user_students", "course", $course->id);
// database to determine whether upgrades should
// be performed (see lib/db/*.php)
-$version = 2003102200; // The current version is a date (YYYYMMDDXX)
+$version = 2003102700; // The current version is a date (YYYYMMDDXX)
$release = "1.2 development"; // User-friendly version number