From: moodler Date: Sat, 26 Apr 2003 12:17:30 +0000 (+0000) Subject: Cleaned up definition of constant COURSE_* values in course/lib.php X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=3d89198946fcc6ff88d042ec3a8c1b2d09745f7e;p=moodle.git Cleaned up definition of constant COURSE_* values in course/lib.php Moved COURSE_TEACHER_COLOR out to style sheets where it belongs (.teacheronly) Added some efficiency when printing recent activity - don't print more than one weeks worth of updates - don't keep re-parsing logs once they've been used --- diff --git a/course/lib.php b/course/lib.php index c869bc0561..46c2776aa7 100644 --- a/course/lib.php +++ b/course/lib.php @@ -2,17 +2,17 @@ // Library of useful functions -if (isset($COURSE_MAX_LOG_DISPLAY)) { // Being included again - should never happen!! +if (defined('COURSE_MAX_LOG_DISPLAY')) { // Being included again - should never happen!! return; } -$COURSE_MAX_LOG_DISPLAY = 150; // days +define('COURSE_MAX_LOG_DISPLAY', 150); // days -$COURSE_MAX_LOGS_PER_PAGE = 1000; // records +define('COURSE_MAX_LOGS_PER_PAGE', 1000); // records -$COURSE_TEACHER_COLOR = "#990000"; // To hilight certain items that are teacher-only +define('COURSE_LIVELOG_REFRESH', 60); // Seconds -$COURSE_LIVELOG_REFRESH = 60; // Seconds +define('COURSE_MAX_RECENT_PERIOD', 60480); // A week, in seconds @@ -118,7 +118,7 @@ function print_log($course, $user=0, $date=0, $order="ORDER BY l.time ASC") { // It is assumed that $date is the GMT time of midnight for that day, // and so the next 86400 seconds worth of logs are printed. - global $CFG, $COURSE_MAX_LOGS_PER_PAGE; + global $CFG; if ($course->category) { $selector = "WHERE l.course='$course->id' AND l.userid = u.id"; @@ -150,8 +150,8 @@ function print_log($course, $user=0, $date=0, $order="ORDER BY l.time ASC") { $count=0; $tt = getdate(time()); $today = mktime (0, 0, 0, $tt["mon"], $tt["mday"], $tt["year"]); - if (($totalcountlogs = count($logs)) > $COURSE_MAX_LOGS_PER_PAGE) { - $totalcountlogs = "$COURSE_MAX_LOGS_PER_PAGE/$totalcountlogs"; + if (($totalcountlogs = count($logs)) > COURSE_MAX_LOGS_PER_PAGE) { + $totalcountlogs = COURSE_MAX_LOGS_PER_PAGE."/$totalcountlogs"; } $strftimedatetime = get_string("strftimedatetime"); @@ -166,7 +166,7 @@ function print_log($course, $user=0, $date=0, $order="ORDER BY l.time ASC") { $countlogs++; - if ($countlogs > $COURSE_MAX_LOGS_PER_PAGE) { + if ($countlogs > COURSE_MAX_LOGS_PER_PAGE) { break; } @@ -302,18 +302,23 @@ function print_recent_activity($course) { // This function trawls through the logs looking for // anything new since the user's last login - global $CFG, $USER, $COURSE_TEACHER_COLOR; + global $CFG, $USER; if (! $USER->lastlogin ) { - echo "

"; + echo "

"; print_string("welcometocourse", "", $course->shortname); - echo "

"; + echo "

"; return; } else { - echo "

"; + echo "

"; echo get_string("yourlastlogin").":
"; echo userdate($USER->lastlogin, get_string("strftimerecentfull")); - echo "

"; + echo "

"; + } + + $timestart = $USER->lastlogin; + if (time() - $timestart > COURSE_MAX_RECENT_PERIOD) { + $timestart = time() - COURSE_MAX_RECENT_PERIOD; } if (! $logs = get_records_select("log", "time > '$USER->lastlogin' AND course = '$course->id'", "time ASC")) { @@ -325,7 +330,7 @@ function print_recent_activity($course) { $heading = false; $content = false; - foreach ($logs as $log) { + foreach ($logs as $key => $log) { if ($log->module == "course" and $log->action == "enrol") { if (! $heading) { print_headline(get_string("newusers").":"); @@ -334,14 +339,19 @@ function print_recent_activity($course) { } $user = get_record("user", "id", $log->info); if (isstudent($course->id, $user->id)) { - echo "

id&course=$course->id\">$user->firstname $user->lastname

"; + echo "

id&course=$course->id\">$user->firstname $user->lastname

"; } + unset($logs[$key]); // No further need for it } } + if (! $logs) { + return; + } + // Next, have there been any changes to the course structure? - foreach ($logs as $log) { + foreach ($logs as $key => $log) { if ($log->module == "course") { if ($log->action == "add mod" or $log->action == "update mod" or $log->action == "delete mod") { $info = split(" ", $log->info); @@ -377,6 +387,7 @@ function print_recent_activity($course) { } } } + unset($logs[$key]); // No further need for it } } @@ -390,11 +401,14 @@ function print_recent_activity($course) { print_headline(get_string("courseupdates").":"); $content = true; foreach ($changes as $changeinfo => $change) { - echo "

".$change["text"]."

"; + echo "

".$change["text"]."

"; } } } + if (! $logs) { + return; + } // Now display new things from each module @@ -403,7 +417,7 @@ function print_recent_activity($course) { foreach ($mods as $mod) { include_once("$CFG->dirroot/mod/$mod/lib.php"); $print_recent_activity = $mod."_print_recent_activity"; - if (function_exists($print_recent_activity)) { + if ($logs and function_exists($print_recent_activity)) { $modcontent = $print_recent_activity($logs, isteacher($course->id)); if ($modcontent) { $content = true; @@ -411,9 +425,8 @@ function print_recent_activity($course) { } } - if (! $content) { - echo "".get_string("nothingnew").""; + echo "".get_string("nothingnew").""; } } diff --git a/course/loggraph.php b/course/loggraph.php index ca050de71c..83c3a88e2f 100644 --- a/course/loggraph.php +++ b/course/loggraph.php @@ -34,9 +34,9 @@ switch ($type) { case "usercourse.png": - $COURSE_MAX_LOG_DISPLAY = $COURSE_MAX_LOG_DISPLAY * 3600 * 24; // seconds - if ($timenow - $course->startdate > $COURSE_MAX_LOG_DISPLAY) { - $course->startdate = $timenow - $COURSE_MAX_LOG_DISPLAY; + $maxseconds = COURSE_MAX_LOG_DISPLAY * 3600 * 24; // seconds + if ($timenow - $course->startdate > $maxseconds) { + $course->startdate = $timenow - $maxseconds; } $timestart = $coursestart = usergetmidnight($course->startdate); diff --git a/course/loglive.php b/course/loglive.php index fd9f8191ec..d2a8354760 100644 --- a/course/loglive.php +++ b/course/loglive.php @@ -15,10 +15,10 @@ } $strlivelogs = get_string("livelogs"); - $strupdatesevery = get_string("updatesevery", "moodle", $COURSE_LIVELOG_REFRESH); + $strupdatesevery = get_string("updatesevery", "moodle", COURSE_LIVELOG_REFRESH); print_header("$strlivelogs ($strupdatesevery)", "$strlivelogs", "", "", - ""); + ""); $user=0; $date=time() - 3600; diff --git a/mod/assignment/lib.php b/mod/assignment/lib.php index 5ad21cf880..b5e68c8673 100644 --- a/mod/assignment/lib.php +++ b/mod/assignment/lib.php @@ -184,7 +184,7 @@ function assignment_cron () { } function assignment_print_recent_activity(&$logs, $isteacher=false) { - global $CFG, $COURSE_TEACHER_COLOR; + global $CFG; $content = false; $assignments = NULL; diff --git a/mod/forum/lib.php b/mod/forum/lib.php index 2559d5cd43..967a3f10f6 100644 --- a/mod/forum/lib.php +++ b/mod/forum/lib.php @@ -297,7 +297,7 @@ function forum_user_complete($course, $user, $mod, $forum) { } function forum_print_recent_activity(&$logs, $isteacher=false) { - global $CFG, $COURSE_TEACHER_COLOR; + global $CFG; $heading = false; $content = false; @@ -322,7 +322,7 @@ function forum_print_recent_activity(&$logs, $isteacher=false) { if ($forum = get_record("forum", "id", $post->forum) ) { if ($forum->type == "teacher") { if ($isteacher) { - $teacherpost = "COLOR=$COURSE_TEACHER_COLOR"; + $teacheronly = "class=\"teacheronly\""; } else { continue; } @@ -334,14 +334,14 @@ function forum_print_recent_activity(&$logs, $isteacher=false) { $content = true; } $date = userdate($post->modified, $strftimerecent); - echo "

$date - $post->firstname $post->lastname
"; - echo "\"wwwroot/mod/forum/$log->url\">"; + echo "

$date - $post->firstname $post->lastname
"; + echo "\"
wwwroot/mod/forum/$log->url\">"; if ($log->action == "add") { - echo "$post->subject"; + echo "$post->subject"; } else { echo "$post->subject"; } - echo "\"

"; + echo "\"

"; } } } diff --git a/mod/journal/lib.php b/mod/journal/lib.php index 67ed4d4027..0be5d42d71 100644 --- a/mod/journal/lib.php +++ b/mod/journal/lib.php @@ -120,7 +120,7 @@ function journal_cron () { } function journal_print_recent_activity(&$logs, $isteacher=false) { - global $CFG, $COURSE_TEACHER_COLOR; + global $CFG; $content = false; $journals = NULL; diff --git a/mod/quiz/lib.php b/mod/quiz/lib.php index 5c108b46aa..aefe826e69 100644 --- a/mod/quiz/lib.php +++ b/mod/quiz/lib.php @@ -193,7 +193,7 @@ function quiz_print_recent_activity(&$logs, $isteacher=false) { /// If isteacher is true then perhaps additional information is printed. /// This function is called from course/lib.php: print_recent_activity() - global $CFG, $COURSE_TEACHER_COLOR; + global $CFG; $content = ""; diff --git a/mod/survey/lib.php b/mod/survey/lib.php index 5d8143e28c..83b865288c 100644 --- a/mod/survey/lib.php +++ b/mod/survey/lib.php @@ -101,7 +101,7 @@ function survey_user_complete($course, $user, $mod, $survey) { } function survey_print_recent_activity(&$logs, $isteacher=false) { - global $CFG, $COURSE_TEACHER_COLOR; + global $CFG; $content = false; $surveys = NULL;