From 7468bf014f86934aa817d564e25d5a52cdaf7e1b Mon Sep 17 00:00:00 2001 From: martin Date: Tue, 23 Jul 2002 16:24:12 +0000 Subject: [PATCH] Part of "contributions" overhaul in course/user.php --- course/lib.php | 27 ++++++++++ course/topics.php | 8 +-- course/user.php | 96 +++++++++++++++++++++++++----------- course/view.php | 19 ++----- course/weeks.php | 9 +--- lang/en/strings.php | 3 ++ mod/journal/user.php | 115 ++++++++++++++++++++++++------------------- 7 files changed, 168 insertions(+), 109 deletions(-) diff --git a/course/lib.php b/course/lib.php index 492edc4933..88d3061a78 100644 --- a/course/lib.php +++ b/course/lib.php @@ -397,4 +397,31 @@ function enrol_student_in_course($user, $course) { } } +function get_all_mods($courseid, &$mods, &$modtype) { + + $mods = NULL; + $modtype = NULL; + + if ( $rawmods = get_records_sql("SELECT cm.*, m.name as modname, m.fullname as modfullname + FROM modules m, course_modules cm + WHERE cm.course = '$courseid' + AND cm.deleted = '0' + AND cm.module = m.id") ) { + foreach($rawmods as $mod) { // Index the mods + $mods[$mod->id] = $mod; + $modtype[$mod->modname] = $mod->modfullname; + } + ksort($modtype); + } + +} + +function get_all_sections($courseid) { + + return get_records_sql("SELECT section, id, course, summary, sequence + FROM course_sections + WHERE course = '$courseid' + ORDER BY section"); +} + ?> diff --git a/course/topics.php b/course/topics.php index 7863037505..ba4df90bd1 100644 --- a/course/topics.php +++ b/course/topics.php @@ -8,19 +8,15 @@ include("../mod/forum/lib.php"); - if (! $rawsections = get_records("course_sections", "course", $course->id) ) { + if (! $sections = get_all_sections($course->id) ) { $section->course = $course->id; // Create a default section. $section->section = 0; $section->id = insert_record("course_sections", $section); - if (! $rawsections = get_records("course_sections", "course", $course->id) ) { + if (! $sections = get_all_sections($course->id) ) { error("Error finding or creating section structures for this course"); } } - foreach($rawsections as $cw) { //Index the sections - $sections[$cw->section] = $cw; - } - if (isset($topic)) { if ($topic == "all") { unset($USER->topic); diff --git a/course/user.php b/course/user.php index 86f89c77f6..0cdb92572a 100644 --- a/course/user.php +++ b/course/user.php @@ -1,9 +1,11 @@ id&course=$course->id\">$user->firstname $user->lastname -> Full Report", ""); - if ( $rawmods = get_records_sql("SELECT cm.*, m.name as modname, m.fullname as modfullname - FROM modules m, course_modules cm - WHERE cm.course = '$course->id' - AND cm.deleted = '0' - AND cm.module = m.id") ) { + get_all_mods($course->id, $mods, $modtype); - foreach($rawmods as $mod) { // Index the mods - $mods[$mod->id] = $mod; - $modtype[$mod->modname] = $mod->modfullname; - } - } + switch ($mode) { + case "summary" : + echo "

Not supported yet

"; + break; + case "outline" : + case "complete" : + default: + $sections = get_all_sections($course->id); - // Replace all the following with a better log-based method. - if ($course->format == "weeks") { - if ($sections = get_records_sql("SELECT * FROM course_sections WHERE course = '$course->id' ORDER BY section")) { - foreach ($sections as $www) { - $section = (object)$www; - echo "

Week $section->section

"; - if ($section->sequence) { - $sectionmods = explode(",", $section->sequence); - foreach ($sectionmods as $sectionmod) { - $mod = $mods[$sectionmod]; - $instance = get_record("$mod->modname", "id", "$mod->instance"); - $userfile = "$CFG->dirroot/mod/$mod->name/user.php"; - include($userfile); - } + for ($i=0; $i<=$course->numsections; $i++) { + + if (isset($sections[$i])) { // should always be true + + $section = $sections[$i]; + + if ($section->sequence) { + echo "
"; + echo "

"; + switch ($course->format) { + case "weeks": print_string("week"); break; + case "topics": print_string("topic"); break; + default: print_string("section"); break; + } + echo " $i

"; + + echo ""; - } else { - echo "

No modules

"; + } } } - } - } else { - echo "

Not implemented yet

"; + break; } + print_footer($course); + +function print_outline_row($mod, $instance, $info) { + $image = "modname/icon.gif\" HEIGHT=16 WIDTH=16 ALT=\"$mod->modfullname\">"; + echo "$image"; + echo ""; + echo "modfullname\""; + echo " HREF=\"../mod/$mod->modname/view.php?id=$mod->id\">$instance->name"; + echo "   "; + echo "$info"; +} + ?> diff --git a/course/view.php b/course/view.php index a3f0fa69d8..47380fadfa 100644 --- a/course/view.php +++ b/course/view.php @@ -40,21 +40,10 @@ error("No modules are installed!"); } - if ( $rawmods = get_records_sql("SELECT cm.*, m.name as modname, m.fullname as modfullname - FROM modules m, course_modules cm - WHERE cm.course = '$course->id' - AND cm.deleted = '0' - AND cm.module = m.id") ) { - - foreach($rawmods as $mod) { // Index the mods - $mods[$mod->id] = $mod; - $modtype[$mod->modname] = $mod->modfullname; - } - if (isset($modtype["forum"]) and isset($modtype["discuss"])) { - // We only need one of them - unset($modtype["discuss"]); - } - ksort($modtype); + get_all_mods($course->id, $mods, $modtype); + + if (isset($modtype["forum"]) and isset($modtype["discuss"])) { // Only need to display one + unset($modtype["discuss"]); } switch ($course->format) { diff --git a/course/weeks.php b/course/weeks.php index 00a0d55621..2fb3834d03 100644 --- a/course/weeks.php +++ b/course/weeks.php @@ -4,18 +4,14 @@ include("../mod/forum/lib.php"); - if (! $rawsections = get_records("course_sections", "course", $course->id) ) { + if (! $sections = get_all_sections($course->id, $course->numsections) ) { $section->course = $course->id; // Create a default section. $section->section = 0; $section->id = insert_record("course_sections", $section); - if (! $rawsections = get_records("course_sections", "course", $course->id) ) { + if (! $sections = get_all_sections($course->id, $course->numsections) ) { error("Error finding or creating section structures for this course"); } } - - foreach($rawsections as $cw) { //Index the sections - $sections[$cw->section] = $cw; - } if (isset($week)) { if ($week == "all") { @@ -26,7 +22,6 @@ } - // Layout the whole page as three big columns. echo ""; echo "
"; diff --git a/lang/en/strings.php b/lang/en/strings.php index ae05a28a6d..535e4dbe96 100644 --- a/lang/en/strings.php +++ b/lang/en/strings.php @@ -160,6 +160,7 @@ $string[passwordsenttext] = " $string[personalprofile] = "Personal profile"; $string[phone] = "Phone"; $string[returningtosite] = "Returning to this web site?"; +$string[section] = "Section"; $string[selectacountry] = "Select a country"; $string[senddetails] = "Send my details via email"; $string[serverlocaltime] = "Server's local time"; @@ -177,6 +178,7 @@ $string[textformat] = "Plain text format"; $string[timezone] = "Timezone"; $string[thanks] = "Thanks"; $string[todaylogs] = "Today's logs"; +$string[topic] = "Topic"; $string[unenrol] = "Unenrol"; $string[unenrolme] = "Unenrol me from \$a"; $string[update] = "Update"; @@ -187,6 +189,7 @@ $string[username] = "Username"; $string[usernameexists] = "This username already exists, choose another"; $string[userprofilefor] = "User profile for \$a"; $string[webpage] = "Web page"; +$string[week] = "Week"; $string[welcometocourse] = "Welcome to \$a"; $string[welcometocoursetext] = "Welcome to \$a->coursename! diff --git a/mod/journal/user.php b/mod/journal/user.php index 51c4928f08..84a37f6e1d 100644 --- a/mod/journal/user.php +++ b/mod/journal/user.php @@ -1,70 +1,81 @@ dirroot/mod/journal/lib.php"); +require_once("$CFG->dirroot/mod/journal/lib.php"); - if (! $journals = get_all_instances_in_course("journal", $course->id)) { - notify("There are no journals"); - die; - } +switch ($mode) { + case "summary": + return user_journal_summary($course, $user, $mod, $instance); + break; + case "outline": + return user_journal_outline($course, $user, $mod, $instance); + break; + case "complete": + return user_journal_complete($course, $user, $mod, $instance); + break; +} + +function user_journal_summary($course, $user, $mod, $journal) { + global $CFG; +} + + +function user_journal_outline($course, $user, $mod, $journal) { + if ($entry = get_record_sql("SELECT * FROM journal_entries + WHERE user='$user->id' AND journal='$journal->id'")) { - if (! $teachers = get_records_sql("SELECT u.* FROM user u, user_teachers t - WHERE t.course = '$course->id' AND t.user = u.id - ORDER BY u.lastaccess DESC")) { - notify("No teachers"); - die; + $numwords = count(preg_split("/\w\b/", $entry->text)) - 1; + + return "$numwords words, last edited ".userdate($entry->modified); + + } else { + return "No entry"; } +} - $timenow = time(); - echo ""; - echo ""; - foreach ($journals as $journal) { +function user_journal_complete($course, $user, $mod, $journal) { + global $CFG, $THEME; - $journal->timestart = $course->startdate + (($journal->section - 1) * 608400); - if ($journal->daysopen) { - $journal->timefinish = $journal->timestart + (3600 * 24 * $journal->daysopen); - } else { - $journal->timefinish = 9999999999; - } + echo "

Journal: wwwroot/mod/journal/view.php?id=$mod->id\">$journal->name

"; + echo "
    "; - $entry = get_record_sql("SELECT * FROM journal_entries - WHERE user='$user->id' AND journal='$journal->id'"); + if ($entry = get_record_sql("SELECT * FROM journal_entries + WHERE user='$user->id' AND journal='$journal->id'")) { + print_simple_box_start(); + if ($entry->modified) { + echo "

    Last edited: ".userdate($entry->modified)."

    "; + } if ($entry->text) { - echo "
"; - $journalopen = ($journal->timestart < $timenow && $timenow < $journal->timefinish); - if ($journalopen) { - echo ""; - echo "
WeekJournal
cellheading2\">"; - } else { - echo "cellheading\">"; - } - echo "$journal->sectioncellcontent\">"; - echo "

wwwroot/mod/journal/view.php?id=$journal->coursemodule\">$journal->name

"; - if ($entry->modified) { - echo "

Last edited: ".userdate($entry->modified)."

"; - } echo text_to_html($entry->text); - if ($entry->teacher) { - echo "\n
"; - echo "
"; - print_user_picture($entry->teacher, $course->id, $teachers[$entry->teacher]->picture); - echo "cellheading\">".$RATING[$entry->rating]; - if ($entry->timemarked) { - echo "  ".userdate($entry->timemarked).""; - } - echo "
"; - echo text_to_html($entry->comment); - echo "
"; - echo "
"; + } + if ($entry->teacher) { + $teacher = get_record("user", "id", $entry->teacher); + + echo "\n
"; + echo ""; + echo ""; + echo "
"; + echo text_to_html($entry->comment); + echo "
"; + echo "
"; + print_user_picture($entry->teacher, $course->id, $teacher->picture); + echo "cellheading\">".$RATING[$entry->rating]; + if ($entry->timemarked) { + echo "  ".userdate($entry->timemarked).""; } - echo "
"; } + print_simple_box_end(); + + } else { + echo "No entry"; } - echo "
"; - + echo ""; +} + ?> -- 2.39.5