From 7487c85699d6f80108ebba92fae29ab99444efaa Mon Sep 17 00:00:00 2001 From: Sam Hemelryk Date: Tue, 8 Jun 2010 06:21:25 +0000 Subject: [PATCH] course formats MDL-22647 Course format names are now properly supported and used. Big thanks to Brandon Turner for the patch. --- course/editsection.php | 13 +-- .../format/topics/lang/en/format_topics.php | 2 +- course/format/topics/lib.php | 10 +++ course/format/weeks/lang/en/format_weeks.php | 2 +- course/format/weeks/lib.php | 20 ++++- course/lib.php | 85 +++++++++++++++++-- course/modedit.php | 8 +- course/recent.php | 17 ++-- course/recent_form.php | 9 +- course/report/outline/index.php | 10 +-- course/resources.php | 20 ++--- course/user.php | 8 +- lib/navigationlib.php | 14 +-- mod/assignment/index.php | 33 +++---- mod/assignment/type/online/all.php | 19 +---- mod/chat/index.php | 21 ++--- mod/choice/index.php | 33 ++++--- mod/data/index.php | 21 +++-- mod/feedback/index.php | 26 +++--- mod/folder/index.php | 19 +++-- mod/forum/discuss.php | 11 +-- mod/forum/index.php | 15 ++-- mod/glossary/index.php | 35 ++++---- mod/hotpot/index.php | 24 +++--- mod/imscp/index.php | 19 +++-- mod/lesson/index.php | 19 +++-- mod/page/index.php | 19 +++-- mod/quiz/index.php | 8 +- mod/resource/index.php | 19 +++-- mod/scorm/index.php | 21 ++--- mod/survey/index.php | 39 +++++---- mod/url/index.php | 18 ++-- mod/wiki/index.php | 23 ++--- mod/workshop/index.php | 21 ++--- 34 files changed, 374 insertions(+), 307 deletions(-) diff --git a/course/editsection.php b/course/editsection.php index b44072de309..bde6b8994c6 100644 --- a/course/editsection.php +++ b/course/editsection.php @@ -66,16 +66,9 @@ if ($mform->is_cancelled()){ redirect("view.php?id=$course->id"); } -/// Inelegant hack for bug 3408 -if ($course->format == 'site') { - $sectionname = get_string('site'); - $stredit = get_string('edita', '', " $sectionname"); - $strsummaryof = get_string('summaryof', '', " $sectionname"); -} else { - $sectionname = get_section_name($course->format); - $stredit = get_string('edita', '', " $sectionname $section->section"); - $strsummaryof = get_string('summaryof', '', " $sectionname $section->section"); -} +$sectionname = get_section_name($course, $section); +$stredit = get_string('edita', '', " $sectionname"); +$strsummaryof = get_string('summaryof', '', " $sectionname"); $PAGE->set_title($stredit); $PAGE->set_heading($course->fullname); diff --git a/course/format/topics/lang/en/format_topics.php b/course/format/topics/lang/en/format_topics.php index 3afe91789ee..48941682ee3 100644 --- a/course/format/topics/lang/en/format_topics.php +++ b/course/format/topics/lang/en/format_topics.php @@ -23,6 +23,6 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -$string['sectionname'] = 'topic'; +$string['sectionname'] = 'Topic'; $string['pluginname'] = 'Topics format'; $string['section0name'] = 'General'; \ No newline at end of file diff --git a/course/format/topics/lib.php b/course/format/topics/lib.php index 804b0ecff00..418522c797d 100644 --- a/course/format/topics/lib.php +++ b/course/format/topics/lib.php @@ -23,6 +23,16 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ + +/** + * Indicates this format uses sections. + * + * @return bool Returns true + */ +function callback_topics_uses_sections() { + return true; +} + /** * Used to display the course structure for a course where format=topic * diff --git a/course/format/weeks/lang/en/format_weeks.php b/course/format/weeks/lang/en/format_weeks.php index fcdedba1a91..55d63a5baf6 100644 --- a/course/format/weeks/lang/en/format_weeks.php +++ b/course/format/weeks/lang/en/format_weeks.php @@ -23,6 +23,6 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -$string['sectionname'] = 'week'; +$string['sectionname'] = 'Week'; $string['pluginname'] = 'Weekly format'; $string['section0name'] = 'General'; diff --git a/course/format/weeks/lib.php b/course/format/weeks/lib.php index 61c64e2e06d..ba4462ed48e 100644 --- a/course/format/weeks/lib.php +++ b/course/format/weeks/lib.php @@ -23,6 +23,16 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ + +/** + * Indicates this format uses sections. + * + * @return bool Returns true + */ +function callback_weeks_uses_sections() { + return true; +} + /** * Used to display the course structure for a course where format=weeks * @@ -57,7 +67,14 @@ function callback_weeks_request_key() { return 'week'; } -function callback_weeks_get_section_name($course, $section, $sections) { +/** + * Gets the name for the provided section. + * + * @param stdClass $course + * @param stdClass $section + * @return string + */ +function callback_weeks_get_section_name($course, $section) { // We can't add a node without text if (!empty($section->name)) { // Return the name the user set @@ -67,6 +84,7 @@ function callback_weeks_get_section_name($course, $section, $sections) { return get_string('section0name', 'format_weeks'); } else { // Got to work out the date of the week so that we can show it + $sections = get_all_sections($course->id); $weekdate = $course->startdate+7200; foreach ($sections as $sec) { if ($sec->id == $section->id) { diff --git a/course/lib.php b/course/lib.php index 52fb7d4701b..8ed00f612c0 100644 --- a/course/lib.php +++ b/course/lib.php @@ -1174,11 +1174,25 @@ function get_all_mods($courseid, &$mods, &$modnames, &$modnamesplural, &$modname } } - +/** + * Returns an array of sections for the requested course id + * + * This function stores the sections against the course id within a staticvar encase + * of subsequent requests. This is used all over + in some standard libs and course + * format callbacks so subsequent requests are a reality. + * + * @staticvar array $coursesections + * @param int $courseid + * @return array Array of sections + */ function get_all_sections($courseid) { global $DB; - return $DB->get_records("course_sections", array("course"=>"$courseid"), "section", - "section, id, course, name, summary, summaryformat, sequence, visible"); + static $coursesections = array(); + if (!array_key_exists($courseid, $coursesections)) { + $coursesections[$courseid] = $DB->get_records("course_sections", array("course"=>"$courseid"), "section", + "section, id, course, name, summary, summaryformat, sequence, visible"); + } + return $coursesections[$courseid]; } function course_set_display($courseid, $display=0) { @@ -3243,11 +3257,68 @@ function move_category($category, $newparentcat) { } /** - * @param string $format Course format ID e.g. 'weeks' - * @return Name that the course format prefers for sections + * Returns the display name of the given section that the course prefers. + * + * This function utilizes a callback that can be implemented within the course + * formats lib.php file to customize the display name that is used to reference + * the section. + * + * By default (if callback is not defined) the method + * {@see get_numeric_section_name} is called instead. + * + * @param stdClass $course The course to get the section name for + * @param stdClass $section Section object from database + * @return Display name that the course format prefers, e.g. "Week 2" + * + * @see get_generic_section_name */ -function get_section_name($format) { - return get_string('sectionname', "format_$format"); +function get_section_name(stdClass $course, stdClass $section) { + global $CFG; + + /// Inelegant hack for bug 3408 + if ($course->format == 'site') { + return get_string('site'); + } + + // Use course formatter callback if it exists + $namingfile = $CFG->dirroot.'/course/format/'.$course->format.'/lib.php'; + $namingfunction = 'callback_'.$course->format.'_get_section_name'; + if (!function_exists($namingfunction) && file_exists($namingfile)) { + require_once $namingfile; + } + if (function_exists($namingfunction)) { + return $namingfunction($course, $section); + } + + // else, default behavior: + return get_generic_section_name($course->format, $section); +} + +/** + * Gets the generic section name for a courses section. + * + * @param string $format Course format ID e.g. 'weeks' $course->format + * @param stdClass $section Section object from database + * @return Display name that the course format prefers, e.g. "Week 2" + */ +function get_generic_section_name($format, stdClass $section) { + return get_string('sectionname', "format_$format") . ' ' . $section->section; +} + + +function course_format_uses_sections($format) { + global $CFG; + + $featurefile = $CFG->dirroot.'/course/format/'.$format.'/lib.php'; + $featurefunction = 'callback_'.$format.'_uses_sections'; + if (!function_exists($featurefunction) && file_exists($featurefile)) { + require_once $featurefile; + } + if (function_exists($featurefunction)) { + return $featurefunction(); + } + + return false; } /** diff --git a/course/modedit.php b/course/modedit.php index fbf5c217e1c..d4e88595f78 100644 --- a/course/modedit.php +++ b/course/modedit.php @@ -87,13 +87,13 @@ if (!empty($add)) { $data->type = $type; } - $sectionname = get_section_name($course->format); + $sectionname = get_section_name($course, $cw); $fullmodulename = get_string('modulename', $module->name); if ($data->section && $course->format != 'site') { $heading = new object(); $heading->what = $fullmodulename; - $heading->to = "$sectionname $data->section"; + $heading->to = $sectionname; $pageheading = get_string('addinganewto', 'moodle', $heading); } else { $pageheading = get_string('addinganew', 'moodle', $fullmodulename); @@ -172,13 +172,13 @@ if (!empty($add)) { } } - $sectionname = get_section_name($course->format); + $sectionname = get_section_name($course, $cw); $fullmodulename = get_string('modulename', $module->name); if ($data->section && $course->format != 'site') { $heading = new object(); $heading->what = $fullmodulename; - $heading->in = "$sectionname $cw->section"; + $heading->in = $sectionname; $pageheading = get_string('updatingain', 'moodle', $heading); } else { $pageheading = get_string('updatinga', 'moodle', $fullmodulename); diff --git a/course/recent.php b/course/recent.php index fc056193efc..7c8b7d97723 100644 --- a/course/recent.php +++ b/course/recent.php @@ -91,12 +91,10 @@ if (has_capability('moodle/course:viewhiddensections', $context)) { $hiddenfilter = "AND cs.visible = 1"; } $sections = array(); -if ($ss = $DB->get_records_sql("SELECT cs.id, cs.section, cs.sequence, cs.summary, cs.visible - FROM {course_sections} cs - WHERE cs.course = ? AND cs.section <= ? - $hiddenfilter - ORDER BY section", array($course->id, $course->numsections))) { - foreach ($ss as $section) { +$rawsections = array_slice(get_all_sections($course->id), 0, $course->numsections+1, true); +$canviewhidden = has_capability('moodle/course:viewhiddensections', $context); +foreach ($rawsections as $section) { + if ($canviewhidden || !empty($section->visible)) { $sections[$section->section] = $section; } } @@ -122,11 +120,6 @@ if ($param->modid === 'all') { $sections = array($section->sequence=>$section); } -switch ($course->format) { - case 'weeks': $sectiontitle = get_string('week'); break; - case 'topics': $sectiontitle = get_string('topic'); break; - default: $sectiontitle = get_string('section'); break; -} if (is_null($modinfo->groups)) { $modinfo->groups = groups_get_user_groups($course->id); // load all my groups and cache it in modinfo @@ -140,7 +133,7 @@ foreach ($sections as $section) { $activity = new object(); $activity->type = 'section'; if ($section->section > 0) { - $activity->name = $sectiontitle.' '.$section->section; + $activity->name = get_section_name($course, $section); } else { $activity->name = ''; } diff --git a/course/recent_form.php b/course/recent_form.php index 9424263f6b4..bae31093d7e 100644 --- a/course/recent_form.php +++ b/course/recent_form.php @@ -36,6 +36,7 @@ class recent_form extends moodleform { $mform =& $this->_form; $context = get_context_instance(CONTEXT_COURSE, $COURSE->id); $modinfo = get_fast_modinfo($COURSE); + $sections = get_all_sections($COURSE->id); $mform->addElement('header', 'filters', get_string('managefilters')); //TODO: add better string @@ -70,11 +71,7 @@ class recent_form extends moodleform { $mform->setAdvanced('user'); } - switch ($COURSE->format) { - case 'weeks': $sectiontitle = get_string('week'); break; - case 'topics': $sectiontitle = get_string('topic'); break; - default: $sectiontitle = get_string('section'); break; - } + $sectiontitle = get_string('sectionname', 'format_'.$COURSE->format); $options = array(''=>get_string('allactivities')); $modsused = array(); @@ -102,7 +99,7 @@ class recent_form extends moodleform { } foreach ($modinfo->sections as $section=>$cmids) { - $options["section/$section"] = "-- $sectiontitle $section --"; + $options["section/$section"] = "-- ".get_section_name($COURSE, $sections[$section])." --"; foreach ($cmids as $cmid) { $cm = $modinfo->cms[$cmid]; if (empty($modsused[$cm->modname]) or !$cm->uservisible) { diff --git a/course/report/outline/index.php b/course/report/outline/index.php index eef520c61b9..4db31c37a03 100644 --- a/course/report/outline/index.php +++ b/course/report/outline/index.php @@ -60,6 +60,7 @@ } $modinfo = get_fast_modinfo($course); + $sections = get_all_sections($course->id); $sql = "SELECT cm.id, COUNT('x') AS numviews, MAX(time) AS lasttime FROM {course_modules} cm @@ -85,14 +86,9 @@ $sectioncell = new html_table_cell(); $sectioncell->colspan = count($outlinetable->head); - $sectiontitle = ''; - switch ($course->format) { - case 'weeks': $sectiontitle = get_string('week'); break; - case 'topics': $sectiontitle = get_string('topic'); break; - default: $sectiontitle = get_string('section'); break; - } + $sectiontitle = get_section_name($course, $sections[$sectionnum]); - $sectioncell->text = $OUTPUT->heading($sectiontitle . ' ' . $sectionnum, 3); + $sectioncell->text = $OUTPUT->heading($sectiontitle, 3); $sectionrow->cells[] = $sectioncell; $outlinetable->data[] = $sectionrow; diff --git a/course/resources.php b/course/resources.php index db1f4b1730d..65c5bc77218 100644 --- a/course/resources.php +++ b/course/resources.php @@ -29,7 +29,7 @@ require_once("$CFG->libdir/resourcelib.php"); $id = required_param('id', PARAM_INT); // course id $course = $DB->get_record('course', array('id'=>$id), '*', MUST_EXIST); - +$PAGE->set_pagelayout('course'); require_course_login($course, true); // get list of all resource-like modules @@ -52,8 +52,7 @@ foreach ($allmodules as $key=>$module) { } $strresources = get_string('resources'); -$strweek = get_string('week'); -$strtopic = get_string('topic'); +$strsectionname = get_string('sectionname', 'format_'.$course->format); $strname = get_string('name'); $strintro = get_string('moduleintro'); $strlastmodified = get_string('lastmodified'); @@ -65,6 +64,10 @@ $PAGE->navbar->add($strresources); echo $OUTPUT->header(); $modinfo = get_fast_modinfo($course); +$usesections = course_format_uses_sections($course->format); +if ($usesections) { + $sections = get_all_sections($course->id); +} $cms = array(); $resources = array(); foreach ($modinfo->cms as $cm) { @@ -91,11 +94,8 @@ if (!$cms) { $table = new html_table(); $table->attributes['class'] = 'generaltable mod_index'; -if ($course->format == 'weeks') { - $table->head = array ($strweek, $strname, $strintro); - $table->align = array ('center', 'left', 'left'); -} else if ($course->format == 'topics') { - $table->head = array ($strtopic, $strname, $strintro); +if ($usesections) { + $table->head = array ($strsectionname, $strname, $strintro); $table->align = array ('center', 'left', 'left'); } else { $table->head = array ($strlastmodified, $strname, $strintro); @@ -108,11 +108,11 @@ foreach ($cms as $cm) { continue; } $resource = $resources[$cm->modname][$cm->instance]; - if ($course->format == 'weeks' or $course->format == 'topics') { + if ($usesections) { $printsection = ''; if ($cm->sectionnum !== $currentsection) { if ($cm->sectionnum) { - $printsection = $cm->sectionnum; + $printsection = get_section_name($course, $sections[$cm->sectionnum]); } if ($currentsection !== '') { $table->data[] = 'hr'; diff --git a/course/user.php b/course/user.php index 24821d9e518..c29f089237a 100644 --- a/course/user.php +++ b/course/user.php @@ -280,12 +280,8 @@ switch ($mode) { 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 get_section_name($course, $section); + echo ""; echo '
'; diff --git a/lib/navigationlib.php b/lib/navigationlib.php index 607fdc04e9b..e99a73c8056 100644 --- a/lib/navigationlib.php +++ b/lib/navigationlib.php @@ -1320,8 +1320,9 @@ class global_navigation extends navigation_node { } else { $activeparam = 'section'; } - - foreach ($sections as &$section) { + $navigationsections = array(); + foreach ($sections as $sectionid=>$section) { + $section = clone($section); if ($course->id == SITEID) { $this->load_section_activities($coursenode, $section->section, $modinfo); } else { @@ -1342,9 +1343,10 @@ class global_navigation extends navigation_node { $this->load_section_activities($sectionnode, $section->section, $modinfo); } $section->sectionnode = $sectionnode; + $navigationsections[$sectionid] = $section; } } - return $sections; + return $navigationsections; } /** * Loads all of the activities for a section into the navigation structure. @@ -2580,10 +2582,8 @@ class settings_navigation extends navigation_node { $formatstring = get_string('topic'); $formatidentifier = optional_param('topic', 0, PARAM_INT); } - if (!$this->cache->cached('coursesections'.$course->id)) { - $this->cache->{'coursesections'.$course->id} = get_all_sections($course->id); - } - $sections = $this->cache->{'coursesections'.$course->id}; + + $sections = get_all_sections($course->id); $addresource = $this->add(get_string('addresource')); $addactivity = $this->add(get_string('addactivity')); diff --git a/mod/assignment/index.php b/mod/assignment/index.php index e4668637a3f..467bcbaee0d 100644 --- a/mod/assignment/index.php +++ b/mod/assignment/index.php @@ -18,8 +18,7 @@ add_to_log($course->id, "assignment", "view all", "index.php?id=$course->id", "" $strassignments = get_string("modulenameplural", "assignment"); $strassignment = get_string("modulename", "assignment"); $strassignmenttype = get_string("assignmenttype", "assignment"); -$strweek = get_string("week"); -$strtopic = get_string("topic"); +$strsectionname = get_string('sectionname', 'format_'.$course->format); $strname = get_string("name"); $strduedate = get_string("duedate", "assignment"); $strsubmitted = get_string("submitted", "assignment"); @@ -37,15 +36,17 @@ if (!$cms = get_coursemodules_in_course('assignment', $course->id, 'cm.idnumber, die; } +$usesections = course_format_uses_sections($course->format); +if ($usesections) { + $sections = get_all_sections($course->id); +} + $timenow = time(); $table = new html_table(); -if ($course->format == "weeks") { - $table->head = array ($strweek, $strname, $strassignmenttype, $strduedate, $strsubmitted, $strgrade); - $table->align = array ("center", "left", "left", "left", "right"); -} else if ($course->format == "topics") { - $table->head = array ($strtopic, $strname, $strassignmenttype, $strduedate, $strsubmitted, $strgrade); +if ($usesections) { + $table->head = array ($strsectionname, $strname, $strassignmenttype, $strduedate, $strsubmitted, $strgrade); $table->align = array ("center", "left", "left", "left", "right"); } else { $table->head = array ($strname, $strassignmenttype, $strduedate, $strsubmitted, $strgrade); @@ -72,14 +73,16 @@ foreach ($modinfo->instances['assignment'] as $cm) { $link = "id\">".format_string($cm->name).""; $printsection = ""; - if ($cm->sectionnum !== $currentsection) { - if ($cm->sectionnum) { - $printsection = $cm->sectionnum; + if ($usesections) { + if ($cm->sectionnum !== $currentsection) { + if ($cm->sectionnum) { + $printsection = get_section_name($course, $sections[$cm->sectionnum]); + } + if ($currentsection !== "") { + $table->data[] = 'hr'; + } + $currentsection = $cm->sectionnum; } - if ($currentsection !== "") { - $table->data[] = 'hr'; - } - $currentsection = $cm->sectionnum; } if (!file_exists($CFG->dirroot.'/mod/assignment/type/'.$cm->assignmenttype.'/assignment.class.php')) { @@ -111,7 +114,7 @@ foreach ($modinfo->instances['assignment'] as $cm) { $due = $cm->timedue ? userdate($cm->timedue) : '-'; - if ($course->format == "weeks" or $course->format == "topics") { + if ($usesections) { $table->data[] = array ($printsection, $link, $type, $due, $submitted, $grade); } else { $table->data[] = array ($link, $type, $due, $submitted, $grade); diff --git a/mod/assignment/type/online/all.php b/mod/assignment/type/online/all.php index 3c8a6702a1f..d2861bee2f3 100644 --- a/mod/assignment/type/online/all.php +++ b/mod/assignment/type/online/all.php @@ -40,8 +40,6 @@ $str->emptysubmission = get_string('emptysubmission','assignment'); $str->noassignments = get_string('noassignments','assignment'); $str->onlinetext = get_string('typeonline','assignment'); $str->submitted = get_string('submitted','assignment'); -$str->topic = get_string('topic'); -$str->week = get_string('week'); $PAGE->navbar->add($str->assignments, new moodle_url('/mod/assignment/index.php', array('id'=>$id))); $PAGE->navbar->add($str->onlinetext); @@ -49,16 +47,7 @@ $PAGE->navbar->add($str->onlinetext); // get all the assignments in the course $assignments = get_all_instances_in_course('assignment',$course, $USER->id ); -// get correct text for course type -if ($course->format=='weeks') { - $courseformat = $str->week; - -} else if ($course->format=='topics') { - $courseformat = $str->topic; - -} else { - $courseformat = ''; -} +$sections = get_all_sections($course->id); // array to hold display data $views = array(); @@ -109,11 +98,7 @@ foreach( $assignments as $assignment ) { $view = new stdClass; // start to build view object - if (!empty($courseformat)) { - $view->section = "$courseformat {$assignment->section}"; - } else { - $view->section = ''; - } + $view->section = get_section_name($course, $sections[$assignment->section]); $view->name = $assignment->name; $view->submitted = $submitted; diff --git a/mod/chat/index.php b/mod/chat/index.php index 2a773c108b4..c3c70c75f64 100644 --- a/mod/chat/index.php +++ b/mod/chat/index.php @@ -19,6 +19,7 @@ add_to_log($course->id, 'chat', 'view all', "index.php?id=$course->id", ''); /// Get all required strings +$strsectionname = get_string('sectionname', 'format_'.$course->format); $strchats = get_string('modulenameplural', 'chat'); $strchat = get_string('modulename', 'chat'); @@ -35,24 +36,24 @@ if (! $chats = get_all_instances_in_course('chat', $course)) { die(); } +$usesections = course_format_uses_sections($course->format); +if ($usesections) { + $sections = get_all_sections($course->id); +} + /// Print the list of instances (your module will probably extend this) $timenow = time(); $strname = get_string('name'); -$strweek = get_string('week'); -$strtopic = get_string('topic'); $table = new html_table(); -if ($course->format == 'weeks') { - $table->head = array ($strweek, $strname); +if ($usesections) { + $table->head = array ($strsectionname, $strname); $table->align = array ('center', 'left'); -} else if ($course->format == 'topics') { - $table->head = array ($strtopic, $strname); - $table->align = array ('center', 'left', 'left', 'left'); } else { $table->head = array ($strname); - $table->align = array ('left', 'left', 'left'); + $table->align = array ('left'); } $currentsection = ''; @@ -67,14 +68,14 @@ foreach ($chats as $chat) { $printsection = ''; if ($chat->section !== $currentsection) { if ($chat->section) { - $printsection = $chat->section; + $printsection = get_section_name($course, $sections[$chat->section]); } if ($currentsection !== '') { $table->data[] = 'hr'; } $currentsection = $chat->section; } - if ($course->format == 'weeks' or $course->format == 'topics') { + if ($usesection) { $table->data[] = array ($printsection, $link); } else { $table->data[] = array ($link); diff --git a/mod/choice/index.php b/mod/choice/index.php index e3917594ce2..b0a3dd65ae8 100644 --- a/mod/choice/index.php +++ b/mod/choice/index.php @@ -18,6 +18,7 @@ $strchoice = get_string("modulename", "choice"); $strchoices = get_string("modulenameplural", "choice"); + $strsectionname = get_string('sectionname', 'format_'.$course->format); $PAGE->set_title($strchoices); $PAGE->navbar->add($strchoices); echo $OUTPUT->header(); @@ -26,6 +27,11 @@ notice(get_string('thereareno', 'moodle', $strchoices), "../../course/view.php?id=$course->id"); } + $usesections = course_format_uses_sections($course->format); + if ($usesections) { + $sections = get_all_sections($course->id); + } + $sql = "SELECT cha.* FROM {choice} ch, {choice_answers} cha WHERE cha.choiceid = ch.id AND @@ -44,11 +50,8 @@ $table = new html_table(); - if ($course->format == "weeks") { - $table->head = array (get_string("week"), get_string("question"), get_string("answer")); - $table->align = array ("center", "left", "left"); - } else if ($course->format == "topics") { - $table->head = array (get_string("topic"), get_string("question"), get_string("answer")); + if ($usesections) { + $table->head = array ($strsectionname, get_string("question"), get_string("answer")); $table->align = array ("center", "left", "left"); } else { $table->head = array (get_string("question"), get_string("answer")); @@ -68,15 +71,17 @@ } else { $aa = ""; } - $printsection = ""; - if ($choice->section !== $currentsection) { - if ($choice->section) { - $printsection = $choice->section; + if ($usesections) { + $printsection = ""; + if ($choice->section !== $currentsection) { + if ($choice->section) { + $printsection = get_section_name($course, $sections[$choice->section]); + } + if ($currentsection !== "") { + $table->data[] = 'hr'; + } + $currentsection = $choice->section; } - if ($currentsection !== "") { - $table->data[] = 'hr'; - } - $currentsection = $choice->section; } //Calculate the href @@ -87,7 +92,7 @@ //Show normal if the mod is visible $tt_href = "coursemodule\">".format_string($choice->name,true).""; } - if ($course->format == "weeks" || $course->format == "topics") { + if ($usesections) { $table->data[] = array ($printsection, $tt_href, $aa); } else { $table->data[] = array ($tt_href, $aa); diff --git a/mod/data/index.php b/mod/data/index.php index 00178570847..a6914970bf3 100755 --- a/mod/data/index.php +++ b/mod/data/index.php @@ -41,8 +41,7 @@ $context = get_context_instance(CONTEXT_COURSE, $course->id); add_to_log($course->id, "data", "view all", "index.php?id=$course->id", ""); -$strweek = get_string('week'); -$strtopic = get_string('topic'); +$strsectionname = get_string('sectionname', 'format_'.$course->format); $strname = get_string('name'); $strdata = get_string('modulename','data'); $strdataplural = get_string('modulenameplural','data'); @@ -56,21 +55,21 @@ if (! $datas = get_all_instances_in_course("data", $course)) { notice(get_string('thereareno', 'moodle',$strdataplural) , "$CFG->wwwroot/course/view.php?id=$course->id"); } +$usesections = course_format_uses_sections($course->format); +if ($usesections) { + $sections = get_all_sections($course->id); +} + $timenow = time(); $strname = get_string('name'); -$strweek = get_string('week'); -$strtopic = get_string('topic'); $strdescription = get_string("description"); $strentries = get_string('entries', 'data'); $strnumnotapproved = get_string('numnotapproved', 'data'); $table = new html_table(); -if ($course->format == 'weeks') { - $table->head = array ($strweek, $strname, $strdescription, $strentries, $strnumnotapproved); - $table->align = array ('center', 'center', 'center', 'center', 'center'); -} else if ($course->format == 'topics') { - $table->head = array ($strtopic, $strname, $strdescription, $strentries, $strnumnotapproved); +if ($usesections) { + $table->head = array ($strsectionname, $strname, $strdescription, $strentries, $strnumnotapproved); $table->align = array ('center', 'center', 'center', 'center', 'center'); } else { $table->head = array ($strname, $strdescription, $strentries, $strnumnotapproved); @@ -118,10 +117,10 @@ foreach ($datas as $data) { $rsslink = rss_get_link($context->id, $USER->id, 'data', $data->id, 'RSS'); } - if ($course->format == 'weeks' or $course->format == 'topics') { + if ($usesections) { if ($data->section !== $currentsection) { if ($data->section) { - $printsection = $data->section; + $printsection = get_section_name($course, $sections[$data->section]); } if ($currentsection !== '') { $table->data[] = 'hr'; diff --git a/mod/feedback/index.php b/mod/feedback/index.php index 1e9ab624bab..6794825df47 100644 --- a/mod/feedback/index.php +++ b/mod/feedback/index.php @@ -47,30 +47,26 @@ if (! $feedbacks = get_all_instances_in_course("feedback", $course)) { die; } +$usesections = course_format_uses_sections($course->format); +if ($usesections) { + $sections = get_all_sections($course->id); +} + /// Print the list of instances (your module will probably extend this) $timenow = time(); $strname = get_string("name"); -$strweek = get_string("week"); -$strtopic = get_string("topic"); +$strsectionname = get_string('sectionname', 'format_'.$course->format); $strresponses = get_string('responses', 'feedback'); $table = new html_table(); -if ($course->format == "weeks") { +if ($usesections) { if(has_capability('mod/feedback:viewreports', $context)) { - $table->head = array ($strweek, $strname, $strresponses); + $table->head = array ($strsectionname, $strname, $strresponses); $table->align = array ("center", "left", 'center'); }else{ - $table->head = array ($strweek, $strname); - $table->align = array ("center", "left"); - } -} else if ($course->format == "topics") { - if(has_capability('mod/feedback:viewreports', $context)) { - $table->head = array ($strtopic, $strname, $strresponses); - $table->align = array ("center", "left", "center"); - }else{ - $table->head = array ($strtopic, $strname); + $table->head = array ($strsectionname, $strname); $table->align = array ("center", "left"); } } else { @@ -95,8 +91,8 @@ foreach ($feedbacks as $feedback) { $dimmedclass = $feedback->visible ? '' : 'class="dimmed"'; $link = ''.$feedback->name.''; - if ($course->format == "weeks" or $course->format == "topics") { - $tabledata = array ($feedback->section, $link); + if ($usesections) { + $tabledata = array (get_section_name($course, $sections[$feedback->section]), $link); } else { $tabledata = array ($link); } diff --git a/mod/folder/index.php b/mod/folder/index.php index 6e5a418e39f..9a54a501eb8 100644 --- a/mod/folder/index.php +++ b/mod/folder/index.php @@ -36,8 +36,7 @@ add_to_log($course->id, 'folder', 'view all', "index.php?id=$course->id", ''); $strfolder = get_string('modulename', 'folder'); $strfolders = get_string('modulenameplural', 'folder'); -$strweek = get_string('week'); -$strtopic = get_string('topic'); +$strsectionname = get_string('sectionname', 'format_'.$course->format); $strname = get_string('name'); $strintro = get_string('moduleintro'); $strlastmodified = get_string('lastmodified'); @@ -53,14 +52,16 @@ if (!$folders = get_all_instances_in_course('folder', $course)) { exit; } +$usesections = course_format_uses_sections($course->format); +if ($usesections) { + $sections = get_all_sections($course->id); +} + $table = new html_table(); $table->attributes['class'] = 'generaltable mod_index'; -if ($course->format == 'weeks') { - $table->head = array ($strweek, $strname, $strintro); - $table->align = array ('center', 'left', 'left'); -} else if ($course->format == 'topics') { - $table->head = array ($strtopic, $strname, $strintro); +if ($usesections) { + $table->head = array ($strsectionname, $strname, $strintro); $table->align = array ('center', 'left', 'left'); } else { $table->head = array ($strlastmodified, $strname, $strintro); @@ -71,11 +72,11 @@ $modinfo = get_fast_modinfo($course); $currentsection = ''; foreach ($folders as $folder) { $cm = $modinfo->cms[$folder->coursemodule]; - if ($course->format == 'weeks' or $course->format == 'topics') { + if ($usesections) { $printsection = ''; if ($folder->section !== $currentsection) { if ($folder->section) { - $printsection = $folder->section; + $printsection = get_section_name($course, $sections[$folder->section]); } if ($currentsection !== '') { $table->data[] = 'hr'; diff --git a/mod/forum/discuss.php b/mod/forum/discuss.php index e6dd2ea5fcb..e38b6057227 100644 --- a/mod/forum/discuss.php +++ b/mod/forum/discuss.php @@ -231,12 +231,8 @@ // single discussion forum can't be moved. $modinfo = get_fast_modinfo($course); if (isset($modinfo->instances['forum'])) { - if ($course->format == 'weeks') { - $strsection = get_string("week"); - } else { - $strsection = get_string("topic"); - } $forummenu = array(); + $sections = get_all_sections($course->id); foreach ($modinfo->instances['forum'] as $forumcm) { if (!$forumcm->uservisible || !has_capability('mod/forum:startdiscussion', get_context_instance(CONTEXT_MODULE,$forumcm->id))) { @@ -244,12 +240,13 @@ } $section = $forumcm->sectionnum; + $sectionname = get_section_name($course, $sections[$section]); if (empty($forummenu[$section])) { - $forummenu[$section] = array("$strsection $section" => array()); + $forummenu[$section] = array($sectionname => array()); } if ($forumcm->instance != $forum->id) { $url = "/mod/forum/discuss.php?d=$discussion->id&move=$forumcm->instance&sesskey=".sesskey(); - $forummenu[$section]["$strsection $section"][$url] = format_string($forumcm->name); + $forummenu[$section][$sectionname][$url] = format_string($forumcm->name); } } if (!empty($forummenu)) { diff --git a/mod/forum/index.php b/mod/forum/index.php index a09e7804577..07d442fb5ae 100644 --- a/mod/forum/index.php +++ b/mod/forum/index.php @@ -67,8 +67,7 @@ $strunsubscribe = get_string('unsubscribe', 'forum'); $stryes = get_string('yes'); $strno = get_string('no'); $strrss = get_string('rss'); -$strweek = get_string('week'); -$strsection = get_string('section'); +$strsectionname = get_string('sectionname', 'format_'.$course->format); $searchform = forum_search_form($course); @@ -103,6 +102,10 @@ if ($show_rss = (($can_subscribe || $course->id == SITEID) && $generaltable->align[] = 'center'; } +$usesections = course_format_uses_sections($course->format); +$sections = get_all_sections($course->id); + +$table = new html_table(); // Parse and organise all the forums. Most forums are course modules but // some special ones are not. These get placed in the general forums @@ -295,11 +298,7 @@ if ($show_rss = (($can_subscribe || $course->id == SITEID) && if ($course->id != SITEID) { // Only real courses have learning forums // Add extra field for section number, at the front - if ($course->format == 'weeks' or $course->format == 'weekscss') { - array_unshift($learningtable->head, $strweek); - } else { - array_unshift($learningtable->head, $strsection); - } + array_unshift($learningtable->head, $strsectionname); array_unshift($learningtable->align, 'center'); @@ -344,7 +343,7 @@ if ($course->id != SITEID) { // Only real courses have learning forums $forum->intro = shorten_text(format_module_intro('forum', $forum, $cm->id), $CFG->forum_shortpost); if ($cm->sectionnum != $currentsection) { - $printsection = $cm->sectionnum; + $printsection = get_section_name($course, $sections[$cm->sectionnum]); if ($currentsection) { $learningtable->data[] = 'hr'; } diff --git a/mod/glossary/index.php b/mod/glossary/index.php index ce511268d8f..7c5dfe1dccc 100644 --- a/mod/glossary/index.php +++ b/mod/glossary/index.php @@ -43,24 +43,25 @@ if (! $glossarys = get_all_instances_in_course("glossary", $course)) { die; } +$usesections = course_format_uses_sections($course->format); +if ($usesections) { + $sections = get_all_sections($course->id); +} + /// Print the list of instances (your module will probably extend this) $timenow = time(); +$strsectionname = get_string('sectionname', 'format_'.$course->format); $strname = get_string("name"); -$strweek = get_string("week"); -$strtopic = get_string("topic"); $strentries = get_string("entries", "glossary"); $table = new html_table(); -if ($course->format == "weeks") { - $table->head = array ($strweek, $strname, $strentries); - $table->align = array ("CENTER", "LEFT", "CENTER"); -} else if ($course->format == "topics") { - $table->head = array ($strtopic, $strname, $strentries); +if ($usesections) { + $table->head = array ($strsectionname, $strname, $strintro); $table->align = array ("CENTER", "LEFT", "CENTER"); } else { - $table->head = array ($strname, $strentries); + $table->head = array ($strname, $strintro); $table->align = array ("LEFT", "CENTER"); } @@ -84,14 +85,16 @@ foreach ($glossarys as $glossary) { continue; } $printsection = ""; - if ($glossary->section !== $currentsection) { - if ($glossary->section) { - $printsection = $glossary->section; + if ($usesections) { + if ($glossary->section !== $currentsection) { + if ($glossary->section) { + $printsection = get_section_name($course, $sections[$glossary->section]); + } + if ($currentsection !== "") { + $table->data[] = 'hr'; + } + $currentsection = $glossary->section; } - if ($currentsection !== "") { - $table->data[] = 'hr'; - } - $currentsection = $glossary->section; } // TODO: count only approved if not allowed to see them @@ -114,7 +117,7 @@ foreach ($glossarys as $glossary) { } } - if ($course->format == "weeks" or $course->format == "topics") { + if ($usesections) { $linedata = array ($printsection, $link, $count); } else { $linedata = array ($link, $count); diff --git a/mod/hotpot/index.php b/mod/hotpot/index.php index a44c5fd9e73..ed471d0aa6f 100644 --- a/mod/hotpot/index.php +++ b/mod/hotpot/index.php @@ -27,6 +27,7 @@ // get message strings for titles $strmodulenameplural = get_string("modulenameplural", "hotpot"); $strmodulename = get_string("modulename", "hotpot"); + $strsectionname = get_string('sectionname', 'format_'.$course->format); // string translation array for single and double quotes $quotes = array("'"=>"\'", '"'=>'"'); @@ -73,6 +74,11 @@ } $hotpotids = implode(',', array_keys($hotpots)); + $usesections = course_format_uses_sections($course->format); + if ($usesections) { + $sections = get_all_sections($course->id); + } + if (has_capability('mod/hotpot:grade', $sitecontext)) { // array of hotpots to be regraded @@ -264,17 +270,7 @@ print '

'.sprintf("%0.3f", microtime_diff($start, microtime())).' secs'."

\n"; } - switch ($course->format) { - case 'weeks' : - $title = get_string("week"); - break; - case 'topics' : - $title = get_string("topic"); - break; - default : - $title = ''; - break; - } + $title = $strsectionname; if ($title) { array_push($table->head, $title); array_push($table->align, "center"); @@ -303,8 +299,8 @@ $printsection = ""; if ($hotpot->section != $currentsection) { if ($hotpot->section) { - $printsection = $hotpot->section; - if ($course->format=='weeks' || $course->format=='topics') { + if ($usesections) { + $printsection = get_section_name($course, $sections[$hotpot->section]); // Show the zoom boxes if ($displaysection==$hotpot->section) { $strshowall = get_string('showall'.$course->format); @@ -358,7 +354,7 @@ $data = array (); - if ($course->format=="weeks" || $course->format=="topics") { + if ($usesections) { array_push($data, $printsection); } diff --git a/mod/imscp/index.php b/mod/imscp/index.php index c6e59dd3788..de43f382f45 100644 --- a/mod/imscp/index.php +++ b/mod/imscp/index.php @@ -36,8 +36,7 @@ add_to_log($course->id, 'imscp', 'view all', "index.php?id=$course->id", ''); $strimscp = get_string('modulename', 'imscp'); $strimscps = get_string('modulenameplural', 'imscp'); -$strweek = get_string('week'); -$strtopic = get_string('topic'); +$strsectionname = get_string('sectionname', 'format_'.$course->format); $strname = get_string('name'); $strintro = get_string('moduleintro'); $strlastmodified = get_string('lastmodified'); @@ -53,14 +52,16 @@ if (!$imscps = get_all_instances_in_course('imscp', $course)) { exit; } +$usesections = course_format_uses_sections($course->format); +if ($usesections) { + $sections = get_all_sections($course->id); +} + $table = new html_table(); $table->attributes['class'] = 'generaltable mod_index'; -if ($course->format == 'weeks') { - $table->head = array ($strweek, $strname, $strintro); - $table->align = array ('center', 'left', 'left'); -} else if ($course->format == 'topics') { - $table->head = array ($strtopic, $strname, $strintro); +if ($usesections) { + $table->head = array ($strsectionname, $strname, $strintro); $table->align = array ('center', 'left', 'left'); } else { $table->head = array ($strlastmodified, $strname, $strintro); @@ -71,11 +72,11 @@ $modinfo = get_fast_modinfo($course); $currentsection = ''; foreach ($imscps as $imscp) { $cm = $modinfo->cms[$imscp->coursemodule]; - if ($course->format == 'weeks' or $course->format == 'topics') { + if ($usesections) { $printsection = ''; if ($imscp->section !== $currentsection) { if ($imscp->section) { - $printsection = $imscp->section; + $printsection = get_section_name($course, $sections[$imscp->section]); } if ($currentsection !== '') { $table->data[] = 'hr'; diff --git a/mod/lesson/index.php b/mod/lesson/index.php index 6f87d2bde02..21faf9f6366 100644 --- a/mod/lesson/index.php +++ b/mod/lesson/index.php @@ -60,22 +60,23 @@ if (! $lessons = get_all_instances_in_course("lesson", $course)) { die; } +$usesections = course_format_uses_sections($course->format); +if ($usesections) { + $sections = get_all_sections($course->id); +} + /// Print the list of instances (your module will probably extend this) $timenow = time(); +$strsectionname = get_string('sectionname', 'format_'.$course->format); $strname = get_string("name"); $strgrade = get_string("grade"); $strdeadline = get_string("deadline", "lesson"); -$strweek = get_string("week"); -$strtopic = get_string("topic"); $strnodeadline = get_string("nodeadline", "lesson"); $table = new html_table(); -if ($course->format == "weeks") { - $table->head = array ($strweek, $strname, $strgrade, $strdeadline); - $table->align = array ("center", "left", "center", "center"); -} else if ($course->format == "topics") { - $table->head = array ($strtopic, $strname, $strgrade, $strdeadline); +if ($usesections) { + $table->head = array ($strsectionname, $strname, $strgrade, $strdeadline); $table->align = array ("center", "left", "center", "center"); } else { $table->head = array ($strname, $strgrade, $strdeadline); @@ -101,7 +102,7 @@ foreach ($lessons as $lesson) { $due = "".userdate($lesson->deadline).""; } - if ($course->format == "weeks" or $course->format == "topics") { + if ($usesections) { if (has_capability('mod/lesson:manage', $context)) { $grade_value = $lesson->grade; } else { @@ -111,7 +112,7 @@ foreach ($lessons as $lesson) { $grade_value = $return[$USER->id]->rawgrade; } } - $table->data[] = array ($lesson->section, $link, $grade_value, $due); + $table->data[] = array (get_section_name($course, $sections[$lesson->section]), $link, $grade_value, $due); } else { $table->data[] = array ($link, $lesson->grade, $due); } diff --git a/mod/page/index.php b/mod/page/index.php index 391e63b69b0..df24f84aa5a 100644 --- a/mod/page/index.php +++ b/mod/page/index.php @@ -36,8 +36,7 @@ add_to_log($course->id, 'page', 'view all', "index.php?id=$course->id", ''); $strpage = get_string('modulename', 'page'); $strpages = get_string('modulenameplural', 'page'); -$strweek = get_string('week'); -$strtopic = get_string('topic'); +$strsectionname = get_string('sectionname', 'format_'.$course->format); $strname = get_string('name'); $strintro = get_string('moduleintro'); $strlastmodified = get_string('lastmodified'); @@ -53,14 +52,16 @@ if (!$pages = get_all_instances_in_course('page', $course)) { exit; } +$usesections = course_format_uses_sections($course->format); +if ($usesections) { + $sections = get_all_sections($course->id); +} + $table = new html_table(); $table->attributes['class'] = 'generaltable mod_index'; -if ($course->format == 'weeks') { - $table->head = array ($strweek, $strname, $strintro); - $table->align = array ('center', 'left', 'left'); -} else if ($course->format == 'topics') { - $table->head = array ($strtopic, $strname, $strintro); +if ($usesections) { + $table->head = array ($strsectionname, $strname, $strintro); $table->align = array ('center', 'left', 'left'); } else { $table->head = array ($strlastmodified, $strname, $strintro); @@ -71,11 +72,11 @@ $modinfo = get_fast_modinfo($course); $currentsection = ''; foreach ($pages as $page) { $cm = $modinfo->cms[$page->coursemodule]; - if ($course->format == 'weeks' or $course->format == 'topics') { + if ($usesections) { $printsection = ''; if ($page->section !== $currentsection) { if ($page->section) { - $printsection = $page->section; + $printsection = get_section_name($course, $sections[$page->section]); } if ($currentsection !== '') { $table->data[] = 'hr'; diff --git a/mod/quiz/index.php b/mod/quiz/index.php index cf5dbbd43c4..125eac406d9 100644 --- a/mod/quiz/index.php +++ b/mod/quiz/index.php @@ -44,6 +44,7 @@ notice(get_string('thereareno', 'moodle', $strquizzes), "../../course/view.php?id=$course->id"); die; } + $sections = get_all_sections($course->id); // Check if we need the closing date header $showclosingheader = false; @@ -69,11 +70,7 @@ array_push($align, 'left'); } - if ($course->format == 'weeks' or $course->format == 'weekscss') { - array_unshift($headings, get_string('week')); - } else { - array_unshift($headings, get_string('section')); - } + array_unshift($headings, get_string('sectionname', 'format_'.$course->format)); array_unshift($align, 'center'); $showing = ''; // default @@ -115,6 +112,7 @@ if ($quiz->section != $currentsection) { if ($quiz->section) { $strsection = $quiz->section; + $strsection = get_section_name($course, $sections[$quiz->section]); } if ($currentsection) { $learningtable->data[] = 'hr'; diff --git a/mod/resource/index.php b/mod/resource/index.php index fe937b90a00..a8963ebccd3 100644 --- a/mod/resource/index.php +++ b/mod/resource/index.php @@ -36,8 +36,7 @@ add_to_log($course->id, 'resource', 'view all', "index.php?id=$course->id", ''); $strresource = get_string('modulename', 'resource'); $strresources = get_string('modulenameplural', 'resource'); -$strweek = get_string('week'); -$strtopic = get_string('topic'); +$strsectionname = get_string('sectionname', 'format_'.$course->format); $strname = get_string('name'); $strintro = get_string('moduleintro'); $strlastmodified = get_string('lastmodified'); @@ -53,14 +52,16 @@ if (!$resources = get_all_instances_in_course('resource', $course)) { exit; } +$usesections = course_format_uses_sections($course->format); +if ($usesections) { + $sections = get_all_sections($course->id); +} + $table = new html_table(); $table->attributes['class'] = 'generaltable mod_index'; -if ($course->format == 'weeks') { - $table->head = array ($strweek, $strname, $strintro); - $table->align = array ('center', 'left', 'left'); -} else if ($course->format == 'topics') { - $table->head = array ($strtopic, $strname, $strintro); +if ($usesections) { + $table->head = array ($strsectionname, $strname, $strintro); $table->align = array ('center', 'left', 'left'); } else { $table->head = array ($strlastmodified, $strname, $strintro); @@ -71,11 +72,11 @@ $modinfo = get_fast_modinfo($course); $currentsection = ''; foreach ($resources as $resource) { $cm = $modinfo->cms[$resource->coursemodule]; - if ($course->format == 'weeks' or $course->format == 'topics') { + if ($usesections) { $printsection = ''; if ($resource->section !== $currentsection) { if ($resource->section) { - $printsection = $resource->section; + $printsection = get_section_name($course, $sections[$resource->section]); } if ($currentsection !== '') { $table->data[] = 'hr'; diff --git a/mod/scorm/index.php b/mod/scorm/index.php index ab97cc04039..3d16f2a06ab 100755 --- a/mod/scorm/index.php +++ b/mod/scorm/index.php @@ -22,8 +22,7 @@ $strscorm = get_string("modulename", "scorm"); $strscorms = get_string("modulenameplural", "scorm"); - $strweek = get_string("week"); - $strtopic = get_string("topic"); + $strsectionname = get_string('sectionname', 'format_'.$course->format); $strname = get_string("name"); $strsummary = get_string("summary"); $strreport = get_string("report",'scorm'); @@ -34,7 +33,12 @@ $PAGE->navbar->add($strscorms); echo $OUTPUT->header(); - if ($course->format == "weeks" or $course->format == "topics") { + $usesections = course_format_uses_sections($course->format); + if ($usesections) { + $sections = get_all_sections($course->id); + } + + if ($usesections) { $sortorder = "cw.section ASC"; } else { $sortorder = "m.timemodified DESC"; @@ -47,11 +51,8 @@ $table = new html_table(); - if ($course->format == "weeks") { - $table->head = array ($strweek, $strname, $strsummary, $strreport); - $table->align = array ("center", "left", "left", "left"); - } else if ($course->format == "topics") { - $table->head = array ($strtopic, $strname, $strsummary, $strreport); + if ($usesections) { + $table->head = array ($strsectionname, $strname, $strsummary, $strreport); $table->align = array ("center", "left", "left", "left"); } else { $table->head = array ($strlastmodified, $strname, $strsummary, $strreport); @@ -62,9 +63,9 @@ $context = get_context_instance(CONTEXT_MODULE,$scorm->coursemodule); $tt = ""; - if ($course->format == "weeks" or $course->format == "topics") { + if ($usesections) { if ($scorm->section) { - $tt = "$scorm->section"; + $tt = get_section_name($course, $sections[$scorm->section]); } } else { $tt = userdate($scorm->timemodified); diff --git a/mod/survey/index.php b/mod/survey/index.php index 55cbbe108f0..5e017ef6594 100644 --- a/mod/survey/index.php +++ b/mod/survey/index.php @@ -17,8 +17,7 @@ add_to_log($course->id, "survey", "view all", "index.php?id=$course->id", ""); $strsurveys = get_string("modulenameplural", "survey"); - $strweek = get_string("week"); - $strtopic = get_string("topic"); + $strsectionname = get_string('sectionname', 'format_'.$course->format); $strname = get_string("name"); $strstatus = get_string("status"); $strdone = get_string("done", "survey"); @@ -33,17 +32,19 @@ notice(get_string('thereareno', 'moodle', $strsurveys), "../../course/view.php?id=$course->id"); } + $usesections = course_format_uses_sections($course->format); + if ($usesections) { + $sections = get_all_sections($course->id); + } + $table = new html_table(); - if ($course->format == "weeks") { - $table->head = array ($strweek, $strname, $strstatus); - $table->align = array ("CENTER", "LEFT", "LEFT"); - } else if ($course->format == "topics") { - $table->head = array ($strtopic, $strname, $strstatus); - $table->align = array ("CENTER", "LEFT", "LEFT"); + if ($usesections) { + $table->head = array ($strsectionname, $strname, $strintro); + $table->align = array ('CENTER', 'LEFT', 'LEFT'); } else { - $table->head = array ($strname, $strstatus); - $table->align = array ("LEFT", "LEFT"); + $table->head = array ($strname, $strintro); + $table->align = array ('LEFT', 'LEFT'); } $currentsection = ''; @@ -55,14 +56,16 @@ $ss = $strnotdone; } $printsection = ""; - if ($survey->section !== $currentsection) { - if ($survey->section) { - $printsection = $survey->section; + if ($usesections) { + if ($survey->section !== $currentsection) { + if ($survey->section) { + $printsection = get_section_name($course, $sections[$survey->section]); + } + if ($currentsection !== "") { + $table->data[] = 'hr'; + } + $currentsection = $survey->section; } - if ($currentsection !== "") { - $table->data[] = 'hr'; - } - $currentsection = $survey->section; } //Calculate the href if (!$survey->visible) { @@ -73,7 +76,7 @@ $tt_href = "coursemodule\">".format_string($survey->name,true).""; } - if ($course->format == "weeks" or $course->format == "topics") { + if ($usesections) { $table->data[] = array ($printsection, $tt_href, "coursemodule\">$ss"); } else { $table->data[] = array ($tt_href, "coursemodule\">$ss"); diff --git a/mod/url/index.php b/mod/url/index.php index ed1774e459f..9db9c346016 100644 --- a/mod/url/index.php +++ b/mod/url/index.php @@ -36,8 +36,6 @@ add_to_log($course->id, 'url', 'view all', "index.php?id=$course->id", ''); $strurl = get_string('modulename', 'url'); $strurls = get_string('modulenameplural', 'url'); -$strweek = get_string('week'); -$strtopic = get_string('topic'); $strname = get_string('name'); $strintro = get_string('moduleintro'); $strlastmodified = get_string('lastmodified'); @@ -53,14 +51,16 @@ if (!$urls = get_all_instances_in_course('url', $course)) { exit; } +$usesections = course_format_uses_sections($course->format); +if ($usesections) { + $sections = get_all_sections($course->id); +} + $table = new html_table(); $table->attributes['class'] = 'generaltable mod_index'; -if ($course->format == 'weeks') { - $table->head = array ($strweek, $strname, $strintro); - $table->align = array ('center', 'left', 'left'); -} else if ($course->format == 'topics') { - $table->head = array ($strtopic, $strname, $strintro); +if ($usesections) { + $table->head = array ($strsectionname, $strname, $strintro); $table->align = array ('center', 'left', 'left'); } else { $table->head = array ($strlastmodified, $strname, $strintro); @@ -71,11 +71,11 @@ $modinfo = get_fast_modinfo($course); $currentsection = ''; foreach ($urls as $url) { $cm = $modinfo->cms[$url->coursemodule]; - if ($course->format == 'weeks' or $course->format == 'topics') { + if ($usesections) { $printsection = ''; if ($url->section !== $currentsection) { if ($url->section) { - $printsection = $url->section; + $printsection = get_section_name($course, $sections[$url->section]); } if ($currentsection !== '') { $table->data[] = 'hr'; diff --git a/mod/wiki/index.php b/mod/wiki/index.php index a8653baf2b4..3ef412810d7 100644 --- a/mod/wiki/index.php +++ b/mod/wiki/index.php @@ -64,22 +64,23 @@ if (!$wikis = get_all_instances_in_course("wiki", $course)) { die; } +$usesections = course_format_uses_sections($course->format); +if ($usesections) { + $sections = get_all_sections($course->id); +} + /// Print the list of instances (your module will probably extend this) $timenow = time(); +$strsectionname = get_string('sectionname', 'format_'.$course->format); $strname = get_string("name"); -$strweek = get_string("week"); -$strtopic = get_string("topic"); -if ($course->format == "weeks") { - $table->head = array($strweek, $strname); +if ($usesections) { + $table->head = array ($strsectionname, $strname); $table->align = array("center", "left"); -} else if ($course->format == "topics") { - $table->head = array($strtopic, $strname); - $table->align = array("center", "left", "left", "left"); } else { - $table->head = array($strname); - $table->align = array("left", "left", "left"); + $table->head = array ($strname); + $table->align = array("left"); } foreach ($wikis as $wiki) { @@ -91,8 +92,8 @@ foreach ($wikis as $wiki) { $link = "coursemodule\">$wiki->name"; } - if ($course->format == "weeks" or $course->format == "topics") { - $table->data[] = array($wiki->section, $link); + if ($usesections) { + $table->data[] = array(get_section_name($course, $sections[$wiki->section]), $link); } else { $table->data[] = array($link); } diff --git a/mod/workshop/index.php b/mod/workshop/index.php index c2bd9079c5d..172bd0e3098 100644 --- a/mod/workshop/index.php +++ b/mod/workshop/index.php @@ -59,22 +59,23 @@ if (! $workshops = get_all_instances_in_course('workshop', $course)) { die(); } +$usesections = course_format_uses_sections($course->format); +if ($usesections) { + $sections = get_all_sections($course->id); +} + /// Print the list of instances (your module will probably extend this) $timenow = time(); +$strsectionname = get_string('sectionname', 'format_'.$course->format); $strname = get_string('name'); -$strweek = get_string('week'); -$strtopic = get_string('topic'); -if ($course->format == 'weeks') { - $table->head = array ($strweek, $strname); +if ($usesections) { + $table->head = array ($strsectionname, $strname); $table->align = array ('center', 'left'); -} else if ($course->format == 'topics') { - $table->head = array ($strtopic, $strname); - $table->align = array ('center', 'left', 'left', 'left'); } else { $table->head = array ($strname); - $table->align = array ('left', 'left', 'left'); + $table->align = array ('left'); } foreach ($workshops as $workshop) { @@ -86,8 +87,8 @@ foreach ($workshops as $workshop) { $link = "coursemodule\">$workshop->name"; } - if ($course->format == 'weeks' or $course->format == 'topics') { - $table->data[] = array ($workshop->section, $link); + if ($usesections) { + $table->data[] = array (get_section_name($course, $sections[$workshop->section]), $link); } else { $table->data[] = array ($link); }