From: mark-nielsen Date: Tue, 24 Jul 2007 05:23:54 +0000 (+0000) Subject: Implemented feature request MDL-10568 - lesson_print_overview() hook X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=4342dc32c55a94e84568d55d1f67e2145ce577a0;p=moodle.git Implemented feature request MDL-10568 - lesson_print_overview() hook --- diff --git a/lang/en_utf8/lesson.php b/lang/en_utf8/lesson.php index c860999fd2..f4394fcb2d 100644 --- a/lang/en_utf8/lesson.php +++ b/lang/en_utf8/lesson.php @@ -128,8 +128,10 @@ $string['leftduringtimed'] = 'You have left during a timed lesson.
Please c $string['leftduringtimednoretake'] = 'You have left during a timed lesson and you are
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.
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'; diff --git a/mod/lesson/lib.php b/mod/lesson/lib.php index 978c4529d2..af2b983609 100644 --- a/mod/lesson/lib.php +++ b/mod/lesson/lib.php @@ -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: wwwroot/mod/lesson/view.php?id=$lesson->coursemodule\">". + format_string($lesson->name).'', '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