mirror of
https://github.com/moodle/moodle.git
synced 2025-04-22 08:55:15 +02:00
course MDL-20628 Added the ability to name a course section, thanks Michael for the initial patch
This commit is contained in:
parent
6438c34f36
commit
0f4ab67d84
@ -48,7 +48,13 @@ $draftitemid = file_get_submitted_draft_itemid('summary');
|
||||
$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 @@ if ($mform->is_cancelled()){
|
||||
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 @@ if ($course->format == 'site') {
|
||||
|
||||
$PAGE->set_title($stredit);
|
||||
$PAGE->navbar->add($stredit);
|
||||
$PAGE->set_focuscontrol('theform.summary');
|
||||
echo $OUTPUT->header();
|
||||
|
||||
echo $OUTPUT->heading_with_help($strsummaryof, 'summaries');
|
||||
|
@ -10,6 +10,13 @@ class editsection_form extends moodleform {
|
||||
$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');
|
||||
|
@ -39,7 +39,7 @@ function callback_scorm_definition() {
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function callback_scorm_request_keyscorm() {
|
||||
function callback_scorm_request_key() {
|
||||
return 'scorm';
|
||||
}
|
||||
|
||||
|
@ -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');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
@ -87,6 +87,10 @@
|
||||
echo '<div class="right side" > </div>';
|
||||
echo '<div class="content">';
|
||||
|
||||
if (!empty($thissection->name)) {
|
||||
echo html_writer::tag('h3', $thissection->name, 'sectionname');
|
||||
}
|
||||
|
||||
echo '<div class="summary">';
|
||||
|
||||
$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 '<div class="summary">';
|
||||
$coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
|
||||
$summarytext = file_rewrite_pluginfile_urls($thissection->summary, 'pluginfile.php', $coursecontext->id, 'course_section', $thissection->id);
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -1469,7 +1469,9 @@ $string['secondstotime86400'] = '1 day';
|
||||
$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';
|
||||
|
@ -243,8 +243,9 @@
|
||||
<FIELDS>
|
||||
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" NEXT="course"/>
|
||||
<FIELD NAME="course" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="id" NEXT="section"/>
|
||||
<FIELD NAME="section" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="course" NEXT="summary"/>
|
||||
<FIELD NAME="summary" TYPE="text" LENGTH="small" NOTNULL="false" SEQUENCE="false" PREVIOUS="section" NEXT="sequence"/>
|
||||
<FIELD NAME="section" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="course" NEXT="name"/>
|
||||
<FIELD NAME="name" TYPE="char" LENGTH="255" NOTNULL="false" SEQUENCE="false" PREVIOUS="section" NEXT="summary"/>
|
||||
<FIELD NAME="summary" TYPE="text" LENGTH="small" NOTNULL="false" SEQUENCE="false" PREVIOUS="name" NEXT="sequence"/>
|
||||
<FIELD NAME="sequence" TYPE="text" LENGTH="small" NOTNULL="false" SEQUENCE="false" PREVIOUS="summary" NEXT="visible"/>
|
||||
<FIELD NAME="visible" TYPE="int" LENGTH="1" NOTNULL="true" UNSIGNED="false" DEFAULT="1" SEQUENCE="false" PREVIOUS="sequence"/>
|
||||
</FIELDS>
|
||||
|
@ -3578,6 +3578,18 @@ WHERE gradeitemid IS NOT NULL AND grademax IS NOT NULL");
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -1031,10 +1031,10 @@ class global_navigation extends navigation_node {
|
||||
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 @@ class global_navigation extends navigation_node {
|
||||
* @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 @@ class global_navigation extends 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;
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user