]> git.mjollnir.org Git - moodle.git/commitdiff
Implemented feature request MDL-10568 - lesson_print_overview() hook
authormark-nielsen <mark-nielsen>
Tue, 24 Jul 2007 05:23:54 +0000 (05:23 +0000)
committermark-nielsen <mark-nielsen>
Tue, 24 Jul 2007 05:23:54 +0000 (05:23 +0000)
lang/en_utf8/lesson.php
mod/lesson/lib.php

index c860999fd2791571b5cc9ed022681537e95a04c4..f4394fcb2d596d81b98bd2880f75e7051d58dcaf 100644 (file)
@@ -128,8 +128,10 @@ $string['leftduringtimed'] = 'You have left during a timed lesson.<br />Please c
 $string['leftduringtimednoretake'] = 'You have left during a timed lesson and you are<br />not allowed to retake or continue the lesson.';
 $string['lesson:edit'] = 'Edit a lesson activity';
 $string['lesson:manage'] = 'Manage a lesson activity';
+$string['lessonattempted'] = 'Lesson attempted';
 $string['lessonclosed'] = 'This lesson closed on $a.';
 $string['lessoncloses'] = 'Lesson closes';
+$string['lessoncloseson'] = 'Lesson closes on $a';
 $string['lessondefault'] = 'Use this lesson\'s settings as defaults';
 $string['lessonformating'] = 'Lesson formating';
 $string['lessonmenu'] = 'Lesson menu';
@@ -291,6 +293,7 @@ $string['whatdofirst'] = 'What would you like to do first?';
 $string['wronganswerjump'] = 'Wrong answer jump';
 $string['wronganswerscore'] = 'Wrong answer score';
 $string['wrongresponse'] = 'Wrong response';
+$string['xattempts'] = '$a attempts';
 $string['youhaveseen'] = 'You have seen more than one page of this lesson already.<br />Do you want to start at the last page you saw?';
 $string['youmadehighscore'] = 'You made it on the top $a high scores list.';
 $string['youranswer'] = 'Your answer';
index 978c4529d2c78e8542b56e572bca7ca747169d81..af2b983609a2f5638cc324bd4b023d125781e0ec 100644 (file)
@@ -386,6 +386,70 @@ function lesson_print_recent_activity($course, $isteacher, $timestart) {
     return false;  //  True if anything was printed, otherwise false
 }
 
+/**
+ * Prints lesson summaries on MyMoodle Page
+ *
+ * Prints lesson name, due date and attempt information on
+ * lessons that have a deadline that has not already passed
+ * and it is available for taking.
+ *
+ * @param array $courses An array of course objects to get lesson instances from
+ * @param array $htmlarray Store overview output array( course ID => 'lesson' => HTML output )
+ */
+function lesson_print_overview($courses, &$htmlarray) {
+    global $USER, $CFG;
+
+    if (!$lessons = get_all_instances_in_courses('lesson', $courses)) {
+        return;
+    }
+
+/// Get Necessary Strings
+    $strlesson       = get_string('modulename', 'lesson');
+    $strnotattempted = get_string('nolessonattempts', 'lesson');
+    $strattempted    = get_string('lessonattempted', 'lesson');
+
+    $now = time();
+    foreach ($lessons as $lesson) {
+        if ($lesson->deadline != 0                                         // The lesson has a deadline
+            and $lesson->deadline >= $now                                  // And it is before the deadline has been met
+            and ($lesson->available == 0 or $lesson->available <= $now)) { // And the lesson is available
+
+            // Lesson name
+            if (!$lesson->visible) {
+                $class = ' class="dimmed"';
+            } else {
+                $class = '';
+            }
+            $str = print_box("$strlesson: <a$class href=\"$CFG->wwwroot/mod/lesson/view.php?id=$lesson->coursemodule\">".
+                             format_string($lesson->name).'</a>', 'name', '', true);
+
+            // Deadline
+            $str .= print_box(get_string('lessoncloseson', 'lesson', userdate($lesson->deadline)), 'info', '', true);
+
+            // Attempt information
+            if (has_capability('mod/lesson:manage', get_context_instance(CONTEXT_MODULE, $lesson->coursemodule))) {
+                // Number of user attempts
+                $attempts = count_records('lesson_attempts', 'lessonid', $lesson->id);
+                $str     .= print_box(get_string('xattempts', 'lesson', $attempts), 'info', '', true);
+            } else {
+                // Determine if the user has attempted the lesson or not
+                if (count_records('lesson_attempts', 'lessonid', $lesson->id, 'userid', $USER->id)) {
+                    $str .= print_box($strattempted, 'info', '', true);
+                } else {
+                    $str .= print_box($strnotattempted, 'info', '', true);
+                }
+            }
+            $str = print_box($str, 'lesson overview', '', true);
+
+            if (empty($htmlarray[$lesson->course]['lesson'])) {
+                $htmlarray[$lesson->course]['lesson'] = $str;
+            } else {
+                $htmlarray[$lesson->course]['lesson'] .= $str;
+            }
+        }
+    }
+}
+
 /*******************************************************************/
 function lesson_cron () {
 /// Function to be run periodically according to the moodle cron