Skip to content
Browse files

New usergetmidnight function and use in finding today's logs

  • Loading branch information...
1 parent 8c0de43 commit edf7fe8c19aff6a5b0c6246ec1c14d7d87b6c06b martin committed Jun 10, 2002
Showing with 19 additions and 6 deletions.
  1. +1 −3 course/lib.php
  2. +16 −0 lib/moodlelib.php
  3. +2 −3 user/index.php
View
4 course/lib.php
@@ -38,9 +38,7 @@ function print_log_selector_form($course, $selecteduser=0, $selecteddate="today"
$timenow = time(); // GMT
// What day is it now for the user, and when is midnight that day (in GMT).
- $date = usergetdate($timenow);
- $timemidnight = gmmktime (0, 0, 0, $date["mon"], $date["mday"], $date["year"]);
- $timemidnight = usertime($timemidnight); // Time of midnight of this user's day, in GMT
+ $timemidnight = usergetmidnight($timenow);
// Put today up the top of the list
$dates = array("$timemidnight" => "Today, ".userdate($timenow, "j F Y") );
View
16 lib/moodlelib.php
@@ -246,6 +246,22 @@ function usertime($date, $timezone=99) {
return $date - (int)($timezone * 3600);
}
+function usergetmidnight($date, $timezone=99) {
+// Given a time, return the GMT timestamp of the most recent midnight
+// for the current user.
+
+ global $USER;
+
+ if ($timezone == 99) {
+ $timezone = (float)$USER->timezone;
+ }
+
+ $userdate = usergetdate($date, $timezone);
+ $timemidnight = gmmktime (0, 0, 0, $userdate["mon"], $userdate["mday"], $userdate["year"]);
+ return usertime($timemidnight, $timezone); // Time of midnight of this user's day, in GMT
+
+}
+
function usertimezone($timezone=99) {
// returns a string that prints the user's timezone
global $USER;
View
5 user/index.php
@@ -75,10 +75,9 @@ function print_user($user, $course, $teacherlinks) {
echo "<FONT SIZE=1>";
if ($teacherlinks) {
- $tt = usergetdate(time());
- $today = mktime (0, 0, 0, $tt["mon"], $tt["mday"], $tt["year"]);
+ $timemidnight = usergetmidnight(time());
echo "<A HREF=\"../course/user.php?id=$course->id&user=$user->id\">Contributions</A><BR>";
- echo "<A HREF=\"../course/log.php?id=$course->id&user=$user->id&date=$today\">Today's logs</A><BR>";
+ echo "<A HREF=\"../course/log.php?id=$course->id&user=$user->id&date=$timemidnight\">Today's logs</A><BR>";
echo "<A HREF=\"../course/log.php?id=$course->id&user=$user->id\">All logs</A><BR>";
if (isstudent($course->id, $user->id)) {
echo "<A HREF=\"../course/loginas.php?id=$course->id&user=$user->id\">Login as</A><BR>";

0 comments on commit edf7fe8

Please sign in to comment.
Something went wrong with that request. Please try again.