diff --git a/course/editsection.php b/course/editsection.php index 092a3016ddd56..cc61e615061ee 100644 --- a/course/editsection.php +++ b/course/editsection.php @@ -48,7 +48,13 @@ $currenttext = file_prepare_draft_area($draftitemid, $context->id, 'course_section', $section->id, array('subdirs'=>true), $section->summary); $mform = new editsection_form(null, $course); -$data = array('id'=>$section->id, 'summary'=>array('text'=>$currenttext, 'format'=>FORMAT_HTML, 'itemid'=>$draftitemid)); +$data = array( + 'id'=>$section->id, + 'usedefaultname'=>(is_null($section->name)), + 'name'=>$section->name, + 'summary'=>array('text'=>$currenttext, 'format'=>FORMAT_HTML, 'itemid'=>$draftitemid) +); + $mform->set_data($data); // set defaults /// If data submitted, then process and store. @@ -56,9 +62,13 @@ redirect($CFG->wwwroot.'/course/view.php?id='.$course->id); } else if ($data = $mform->get_data()) { - - $text = file_save_draft_area_files($data->summary['itemid'], $context->id, 'course_section', $section->id, array('subdirs'=>true), $data->summary['text']); - $DB->set_field("course_sections", "summary", $text, array("id"=>$section->id)); + if (empty($data->usedefaultname)) { + $section->name = $data->name; + } else { + $section->name = null; + } + $section->summary = file_save_draft_area_files($data->summary['itemid'], $context->id, 'course_section', $section->id, array('subdirs'=>true), $data->summary['text']); + $DB->update_record('course_sections', $section); add_to_log($course->id, "course", "editsection", "editsection.php?id=$section->id", "$section->section"); redirect("view.php?id=$course->id"); } @@ -76,7 +86,6 @@ $PAGE->set_title($stredit); $PAGE->navbar->add($stredit); -$PAGE->set_focuscontrol('theform.summary'); echo $OUTPUT->header(); echo $OUTPUT->heading_with_help($strsummaryof, 'summaries'); diff --git a/course/editsection_form.php b/course/editsection_form.php index b517ec7f2498f..0958edbe4707e 100644 --- a/course/editsection_form.php +++ b/course/editsection_form.php @@ -10,6 +10,13 @@ function definition() { $mform = $this->_form; $course = $this->_customdata; + $mform->addElement('checkbox', 'usedefaultname', get_string('sectionusedefaultname')); + $mform->setDefault('usedefaultname', true); + + $mform->addElement('text', 'name', get_string('sectionname'), array('size'=>'30')); + $mform->setType('name', PARAM_TEXT); + $mform->disabledIf('name','usedefaultname','checked'); + $mform->addElement('editor', 'summary', get_string('summary'), null, array('changeformat'=>false, 'maxfiles'=>-1)); $mform->addElement('hidden', 'id'); diff --git a/course/format/scorm/lib.php b/course/format/scorm/lib.php index 09eba86d80758..663ceea92a5b1 100644 --- a/course/format/scorm/lib.php +++ b/course/format/scorm/lib.php @@ -39,7 +39,7 @@ function callback_scorm_definition() { * * @return string */ -function callback_scorm_request_keyscorm() { +function callback_scorm_request_key() { return 'scorm'; } diff --git a/course/format/social/lib.php b/course/format/social/lib.php index 7e19bce9dce6f..60a4bfa56ee38 100644 --- a/course/format/social/lib.php +++ b/course/format/social/lib.php @@ -33,8 +33,8 @@ * @param stdClass $modinfo The mod info object for the current course * @return bool Returns true */ -function load_course_format_social(&$navigation, $keys, $course) { - $navigation->add_course_section_generic($keys, $course, get_string('social'), 'social'); +function callback_social_load_content(&$navigation, $course, $coursenode) { + return $navigation->load_generic_course_sections($course, $coursenode, 'social'); } /** diff --git a/course/format/topics/lib.php b/course/format/topics/lib.php index b47a986c1796c..8bf95c1393b64 100644 --- a/course/format/topics/lib.php +++ b/course/format/topics/lib.php @@ -34,7 +34,7 @@ * @return bool Returns true */ function callback_topics_load_content(&$navigation, $course, $coursenode) { - return $navigation->load_generic_course_sections($course, $coursenode, get_string('topic'), 'topic', get_string('section0name', 'format_topics')); + return $navigation->load_generic_course_sections($course, $coursenode, 'topics'); } /** @@ -57,3 +57,13 @@ function callback_topics_request_key() { return 'topic'; } +function callback_topics_get_section_name($course, $section) { + // We can't add a node without any text + if (!is_empty($section->name)) { + return $section->name; + } else if ($section->section == 0) { + return get_string('section0name', 'format_topics'); + } else { + return get_string('topic').' '.$section->section; + } +} \ No newline at end of file diff --git a/course/format/weeks/format.php b/course/format/weeks/format.php index f1d0fa4c0fd37..0fd93d81539ec 100644 --- a/course/format/weeks/format.php +++ b/course/format/weeks/format.php @@ -87,6 +87,10 @@ echo '
 
'; echo '
'; + if (!empty($thissection->name)) { + echo html_writer::tag('h3', $thissection->name, 'sectionname'); + } + echo '
'; $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id); @@ -212,8 +216,11 @@ echo $OUTPUT->heading($currenttext.$weekperiod.' ('.get_string('notavailable').')', 3, 'weekdates'); } else { - echo $OUTPUT->heading($currenttext.$weekperiod, 3, 'weekdates'); - + if (!is_null($thissection->name)) { + echo $OUTPUT->heading($thissection->name, 3, 'weekdates'); + } else { + echo $OUTPUT->heading($currenttext.$weekperiod, 3, 'weekdates'); + } echo '
'; $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id); $summarytext = file_rewrite_pluginfile_urls($thissection->summary, 'pluginfile.php', $coursecontext->id, 'course_section', $thissection->id); diff --git a/course/format/weeks/lib.php b/course/format/weeks/lib.php index 4d541728ffd39..61c64e2e06d51 100644 --- a/course/format/weeks/lib.php +++ b/course/format/weeks/lib.php @@ -34,7 +34,7 @@ * @param stdClass $course The course we are loading the section for */ function callback_weeks_load_content(&$navigation, $course, $coursenode) { - return $navigation->load_generic_course_sections($course, $coursenode, get_string('week'), 'week', get_string('section0name', 'format_weeks')); + return $navigation->load_generic_course_sections($course, $coursenode, 'weeks'); } /** @@ -57,3 +57,27 @@ function callback_weeks_request_key() { return 'week'; } +function callback_weeks_get_section_name($course, $section, $sections) { + // We can't add a node without text + if (!empty($section->name)) { + // Return the name the user set + return $section->name; + } else if ($section->section == 0) { + // Return the section0name + return get_string('section0name', 'format_weeks'); + } else { + // Got to work out the date of the week so that we can show it + $weekdate = $course->startdate+7200; + foreach ($sections as $sec) { + if ($sec->id == $section->id) { + break; + } else if ($sec->visible && $sec->section != 0) { + $weekdate += 604800; + } + } + $strftimedateshort = ' '.get_string('strftimedateshort'); + $weekday = userdate($weekdate, $strftimedateshort); + $endweekday = userdate($weekdate+518400, $strftimedateshort); + return $weekday.' - '.$endweekday; + } +} diff --git a/course/lib.php b/course/lib.php index 1465f625548ab..62445a38a9e8f 100644 --- a/course/lib.php +++ b/course/lib.php @@ -1177,7 +1177,7 @@ function get_all_mods($courseid, &$mods, &$modnames, &$modnamesplural, &$modname function get_all_sections($courseid) { global $DB; return $DB->get_records("course_sections", array("course"=>"$courseid"), "section", - "section, id, course, summary, sequence, visible"); + "section, id, course, name, summary, sequence, visible"); } function course_set_display($courseid, $display=0) { diff --git a/lang/en/moodle.php b/lang/en/moodle.php index 59607e6825720..ca5ffb86e886f 100644 --- a/lang/en/moodle.php +++ b/lang/en/moodle.php @@ -1469,7 +1469,9 @@ $string['secretalreadyused'] = 'Change password confirmation link was already used, password was not changed.'; $string['secs'] = 'secs'; $string['section'] = 'Section'; +$string['sectionname'] = 'Section name'; $string['sections'] = 'Sections'; +$string['sectionusedefaultname'] = 'Use default section name'; $string['seealsostats'] = 'See also: stats'; $string['select'] = 'Select'; $string['selectacountry'] = 'Select a country'; diff --git a/lib/db/install.xml b/lib/db/install.xml index 1dc2f221d123b..559c3a5b99caa 100644 --- a/lib/db/install.xml +++ b/lib/db/install.xml @@ -243,8 +243,9 @@ - - + + + diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php index 2c10419cc8c28..b2c84a8b12512 100644 --- a/lib/db/upgrade.php +++ b/lib/db/upgrade.php @@ -3578,6 +3578,18 @@ function xmldb_main_upgrade($oldversion) { upgrade_main_savepoint($result, 2010042200); } + if ($result && $oldversion < 2010042301) { + + $table = new xmldb_table('course_sections'); + $field = new xmldb_field('name', XMLDB_TYPE_CHAR, '255', null, null, null, null, 'section'); + + if (!$dbman->field_exists($table, $field)) { + $dbman->add_field($table, $field); + } + + upgrade_main_savepoint($result, 2010042301); + } + return $result; } diff --git a/lib/navigationlib.php b/lib/navigationlib.php index e9d602f39a6b4..f7fe1b22848ee 100644 --- a/lib/navigationlib.php +++ b/lib/navigationlib.php @@ -1031,10 +1031,10 @@ protected function load_course_sections(stdClass $course, navigation_node $cours if (function_exists($structurefunc)) { return $structurefunc($this, $course, $coursenode); } else { - return $this->load_generic_course_sections($course, $coursenode, get_string('topic'), 'topic'); + return $this->load_generic_course_sections($course, $coursenode); } } else { - return $this->load_generic_course_sections($course, $coursenode, get_string('topic'), 'topic'); + return $this->load_generic_course_sections($course, $coursenode); } } @@ -1047,14 +1047,29 @@ protected function load_course_sections(stdClass $course, navigation_node $cours * @param string $activeparam The url used to identify the active section * @return array An array of course section nodes */ - public function load_generic_course_sections(stdClass $course, navigation_node $coursenode, $name, $activeparam, $section0name=null) { + public function load_generic_course_sections(stdClass $course, navigation_node $coursenode, $courseformat='unknown') { + global $DB, $USER; + $modinfo = get_fast_modinfo($course); $sections = array_slice(get_all_sections($course->id), 0, $course->numsections+1, true); $viewhiddensections = has_capability('moodle/course:viewhiddensections', $this->page->context); - if ($section0name === null) { - $section0name = get_string('general'); + if (isloggedin() && !isguestuser()) { + $activesection = $DB->get_field("course_display", "display", array("userid"=>$USER->id, "course"=>$course->id)); + } else { + $activesection = null; + } + + $namingfunction = 'callback_'.$courseformat.'_get_section_name'; + $namingfunctionexists = (function_exists($namingfunction)); + + $activeparamfunction = 'callback_'.$courseformat.'_request_key'; + if (function_exists($activeparamfunction)) { + $activeparam = $activeparamfunction(); + } else { + $activeparam = 'section'; } + foreach ($sections as &$section) { if ($course->id == SITEID) { $this->load_section_activities($coursenode, $section->section, $modinfo); @@ -1062,16 +1077,17 @@ public function load_generic_course_sections(stdClass $course, navigation_node $ if ((!$viewhiddensections && !$section->visible) || (!$this->showemptysections && !array_key_exists($section->section, $modinfo->sections))) { continue; } - if ($section->section == 0) { - $sectionname = $section0name; + if ($namingfunctionexists) { + $sectionname = $namingfunction($course, $section, $sections); } else { - $sectionname = $name.' '.$section->section; + $sectionname = get_string('section').' '.$section->section; } $url = new moodle_url('/course/view.php', array('id'=>$course->id, $activeparam=>$section->section)); $sectionnode = $coursenode->add($sectionname, $url, navigation_node::TYPE_SECTION, null, $section->id); $sectionnode->nodetype = navigation_node::NODETYPE_BRANCH; $sectionnode->hidden = (!$section->visible); - if ($sectionnode->isactive) { + if ($sectionnode->isactive || ($activesection != null && $section->section == $activesection)) { + $sectionnode->force_open(); $this->load_section_activities($sectionnode, $section->section, $modinfo); } $section->sectionnode = $sectionnode; diff --git a/version.php b/version.php index d806aa184f4d5..156463fab9f1e 100644 --- a/version.php +++ b/version.php @@ -6,7 +6,7 @@ // This is compared against the values stored in the database to determine // whether upgrades should be performed (see lib/db/*.php) - $version = 2010042300; // YYYYMMDD = date of the last version bump + $version = 2010042301; // YYYYMMDD = date of the last version bump // XX = daily increments $release = '2.0 dev (Build: 20100423)'; // Human-friendly version name