--- /Users/sbourget/Desktop/MDL/moodle 1.9 CLEAN/mod/lesson/lib.php 2007-06-21 10:02:56.000000000 -0400 +++ /Applications/MAMP/htdocs/moodle19/mod/lesson/lib.php 2007-07-22 11:09:02.000000000 -0400 @@ -558,4 +558,67 @@ return array('end','start', 'update grade attempt'); } +/** + * Prints lesson summaries on MyMoodle Page + * + */ +function lesson_print_overview($courses, &$htmlarray) { + global $USER, $CFG; +// These next 6 Lines are constant in all modules (just change module name) + if (empty($courses) || !is_array($courses) || count($courses) == 0) { + return array(); + } + + if (!$lessons = get_all_instances_in_courses('lesson',$courses)) { + return; + } +// Get Necessary Sirings + $strlesson = get_string('modulename', 'lesson'); + $strlessoncloses = get_string('lessoncloses', 'lesson'); + $strlessonopens = get_string('lessonopens', 'lesson'); + $strattempts = get_string('attempts', 'lesson'); + $strnotattempted = get_string('nolessonattempts', 'lesson'); + $strattempted = get_string('attempted', 'lesson'); + + foreach ($lessons as $lesson) { + if ($lesson->deadline != 0) { // A lesson is scheduled + $str = '
'. + $strlesson.': visible?'':' class="dimmed"'). + ' href="'.$CFG->wwwroot.'/mod/lesson/view.php?id='.$lesson->coursemodule.'">'. + $lesson->name.'
'; + if($lesson->deadline != 0) { + $str .= '
'.$strlessoncloses.': '.userdate($lesson->deadline).'
'; + } else { + $str .= '
'.$strlessonopens.'
'; + } + // Count attempts (most of this code is from mod/lesson/report.php) + $context = get_context_instance(CONTEXT_MODULE, $lesson->coursemodule); + if (has_capability('mod/lesson:manage', $context)) { + if ($a->attemptnum = count_records('lesson_attempts', 'lessonid', $lesson->id)) { + } else { + $a->attemptnum = 0; + } + $str .= '
'. $a->attemptnum .' ' .$strattempts. '
'; // Number of student attempts + } else { // Student + if (isset($USER->id)) { + $numattempts = count_records('lesson_attempts', 'lessonid', $lesson->id, 'userid', $USER->id); + if($numattempts == 0){ + $str .= '
'.$strnotattempted.'
'; + } else { + $str .= '
'.$strattempted.'
'; + } + } + } + $str .='
'; + // Echo String to Screen + if (empty($htmlarray[$lesson->course]['lesson'])) { + $htmlarray[$lesson->course]['lesson'] = $str; + } else { + $htmlarray[$lesson->course]['lesson'] .= $str; + } + } + } +} + + ?>