Merge branch 'MDL-51250-master' of git://github.com/junpataleta/moodle
This commit is contained in:
@@ -220,6 +220,21 @@ class core_backup_moodle2_course_format_testcase extends advanced_testcase {
|
||||
* Test course format that has 1 option.
|
||||
*/
|
||||
class format_test_cs_options extends format_topics {
|
||||
/**
|
||||
* Override method format_topics::get_default_section_name to prevent PHPUnit errors related to the nonexistent
|
||||
* format_test_cs_options lang file.
|
||||
*
|
||||
* @param stdClass $section The section in question.
|
||||
* @return string The section's name for display.
|
||||
*/
|
||||
public function get_default_section_name($section) {
|
||||
if ($section->section == 0) {
|
||||
return parent::get_default_section_name($section);
|
||||
} else {
|
||||
return get_string('sectionname', 'format_topics') . ' ' . $section->section;
|
||||
}
|
||||
}
|
||||
|
||||
public function section_format_options($foreditform = false) {
|
||||
return array(
|
||||
'numdaystocomplete' => array(
|
||||
|
||||
+11
-2
@@ -80,8 +80,17 @@ if ($deletesection) {
|
||||
}
|
||||
|
||||
$editoroptions = array('context'=>$context ,'maxfiles' => EDITOR_UNLIMITED_FILES, 'maxbytes'=>$CFG->maxbytes, 'trusttext'=>false, 'noclean'=>true);
|
||||
$mform = course_get_format($course->id)->editsection_form($PAGE->url,
|
||||
array('cs' => $sectioninfo, 'editoroptions' => $editoroptions));
|
||||
|
||||
$courseformat = course_get_format($course);
|
||||
$defaultsectionname = $courseformat->get_default_section_name($section);
|
||||
|
||||
$customdata = array(
|
||||
'cs' => $sectioninfo,
|
||||
'editoroptions' => $editoroptions,
|
||||
'defaultsectionname' => $defaultsectionname
|
||||
);
|
||||
$mform = $courseformat->editsection_form($PAGE->url, $customdata);
|
||||
|
||||
// set current value, make an editable copy of section_info object
|
||||
// this will retrieve all format-specific options as well
|
||||
$initialdata = convert_to_array($sectioninfo);
|
||||
|
||||
@@ -25,7 +25,16 @@ class editsection_form extends moodleform {
|
||||
|
||||
$elementgroup = array();
|
||||
$elementgroup[] = $mform->createElement('text', 'name', '', array('size' => '30', 'maxlength' => '255'));
|
||||
$elementgroup[] = $mform->createElement('checkbox', 'usedefaultname', '', get_string('sectionusedefaultname'));
|
||||
|
||||
// Get default section name.
|
||||
$defaultsectionname = $this->_customdata['defaultsectionname'];
|
||||
if ($defaultsectionname) {
|
||||
$defaultsectionname = ' [' . $defaultsectionname . ']';
|
||||
}
|
||||
|
||||
$elementgroup[] = $mform->createElement('checkbox', 'usedefaultname', '',
|
||||
get_string('sectionusedefaultname') . $defaultsectionname);
|
||||
|
||||
$mform->addGroup($elementgroup, 'name_group', get_string('sectionname'), ' ', false);
|
||||
$mform->addGroupRule('name_group', array('name' => array(array(get_string('maximumchars', '', 255), 'maxlength', 255))));
|
||||
|
||||
@@ -103,7 +112,7 @@ class editsection_form extends moodleform {
|
||||
$data = parent::get_data();
|
||||
if ($data !== null) {
|
||||
$editoroptions = $this->_customdata['editoroptions'];
|
||||
if (!empty($data->usedefaultname)) {
|
||||
if (!empty($data->usedefaultname) || empty(trim($data->name))) {
|
||||
$data->name = null;
|
||||
}
|
||||
$data = file_postupdate_standard_editor($data, 'summary', $editoroptions,
|
||||
|
||||
+17
-1
@@ -350,7 +350,23 @@ abstract class format_base {
|
||||
} else {
|
||||
$sectionnum = $section;
|
||||
}
|
||||
return get_string('sectionname', 'format_'.$this->format) . ' ' . $sectionnum;
|
||||
|
||||
if (get_string_manager()->string_exists('sectionname', 'format_' . $this->format)) {
|
||||
return get_string('sectionname', 'format_' . $this->format) . ' ' . $sectionnum;
|
||||
}
|
||||
|
||||
// Return an empty string if there's no available section name string for the given format.
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the default section using format_base's implementation of get_section_name.
|
||||
*
|
||||
* @param int|stdClass $section Section object from database or just field course_sections section
|
||||
* @return string The default value for the section name based on the given course format.
|
||||
*/
|
||||
public function get_default_section_name($section) {
|
||||
return self::get_section_name($section);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -57,10 +57,29 @@ class format_topics extends format_base {
|
||||
if ((string)$section->name !== '') {
|
||||
return format_string($section->name, true,
|
||||
array('context' => context_course::instance($this->courseid)));
|
||||
} else if ($section->section == 0) {
|
||||
} else {
|
||||
return $this->get_default_section_name($section);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the default section name for the topics course format.
|
||||
*
|
||||
* If the section number is 0, it will use the string with key = section0name from the course format's lang file.
|
||||
* If the section number is not 0, the base implementation of format_base::get_default_section_name which uses
|
||||
* the string with the key = 'sectionname' from the course format's lang file + the section number will be used.
|
||||
*
|
||||
* @param stdClass $section Section object from database or just field course_sections section
|
||||
* @return string The default value for the section name.
|
||||
*/
|
||||
public function get_default_section_name($section) {
|
||||
if ($section->section == 0) {
|
||||
// Return the general section.
|
||||
return get_string('section0name', 'format_topics');
|
||||
} else {
|
||||
return get_string('topic').' '.$section->section;
|
||||
// Use format_base::get_default_section_name implementation which
|
||||
// will display the section name in "Topic n" format.
|
||||
return parent::get_default_section_name($section);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -24,6 +24,22 @@ Feature: Sections can be edited and deleted in topics format
|
||||
And I follow "Course 1"
|
||||
And I turn editing mode on
|
||||
|
||||
Scenario: View the default name of the general section in topics format
|
||||
When I click on "Edit section" "link" in the "li#section-0" "css_element"
|
||||
Then I should see "Use default section name [General]"
|
||||
|
||||
Scenario: Edit the default name of the general section in topics format
|
||||
When I click on "Edit section" "link" in the "li#section-0" "css_element"
|
||||
And I set the following fields to these values:
|
||||
| Use default section name | 0 |
|
||||
| name | This is the general section |
|
||||
And I press "Save changes"
|
||||
Then I should see "This is the general section" in the "li#section-0" "css_element"
|
||||
|
||||
Scenario: View the default name of the second section in topics format
|
||||
When I click on "Edit topic" "link" in the "li#section-2" "css_element"
|
||||
Then I should see "Use default section name [Topic 2]"
|
||||
|
||||
Scenario: Edit section summary in topics format
|
||||
When I edit the section "2"
|
||||
And I set the following fields to these values:
|
||||
|
||||
@@ -61,4 +61,89 @@ class format_topics_testcase extends advanced_testcase {
|
||||
$this->assertEquals(8, count(get_fast_modinfo($course)->get_section_info_all()));
|
||||
$this->assertEquals(6, course_get_format($course)->get_course()->numsections);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests for format_topics::get_section_name method with default section names.
|
||||
*/
|
||||
public function test_get_section_name() {
|
||||
global $DB;
|
||||
$this->resetAfterTest(true);
|
||||
|
||||
// Generate a course with 5 sections.
|
||||
$generator = $this->getDataGenerator();
|
||||
$numsections = 5;
|
||||
$course = $generator->create_course(array('numsections' => $numsections, 'format' => 'topics'),
|
||||
array('createsections' => true));
|
||||
|
||||
// Get section names for course.
|
||||
$coursesections = $DB->get_records('course_sections', array('course' => $course->id));
|
||||
|
||||
// Test get_section_name with default section names.
|
||||
$courseformat = course_get_format($course);
|
||||
foreach ($coursesections as $section) {
|
||||
// Assert that with unmodified section names, get_section_name returns the same result as get_default_section_name.
|
||||
$this->assertEquals($courseformat->get_default_section_name($section), $courseformat->get_section_name($section));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests for format_topics::get_section_name method with modified section names.
|
||||
*/
|
||||
public function test_get_section_name_customised() {
|
||||
global $DB;
|
||||
$this->resetAfterTest(true);
|
||||
|
||||
// Generate a course with 5 sections.
|
||||
$generator = $this->getDataGenerator();
|
||||
$numsections = 5;
|
||||
$course = $generator->create_course(array('numsections' => $numsections, 'format' => 'topics'),
|
||||
array('createsections' => true));
|
||||
|
||||
// Get section names for course.
|
||||
$coursesections = $DB->get_records('course_sections', array('course' => $course->id));
|
||||
|
||||
// Modify section names.
|
||||
$customname = "Custom Section";
|
||||
foreach ($coursesections as $section) {
|
||||
$section->name = "$customname $section->section";
|
||||
$DB->update_record('course_sections', $section);
|
||||
}
|
||||
|
||||
// Requery updated section names then test get_section_name.
|
||||
$coursesections = $DB->get_records('course_sections', array('course' => $course->id));
|
||||
$courseformat = course_get_format($course);
|
||||
foreach ($coursesections as $section) {
|
||||
// Assert that with modified section names, get_section_name returns the modified section name.
|
||||
$this->assertEquals($section->name, $courseformat->get_section_name($section));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests for format_topics::get_default_section_name.
|
||||
*/
|
||||
public function test_get_default_section_name() {
|
||||
global $DB;
|
||||
$this->resetAfterTest(true);
|
||||
|
||||
// Generate a course with 5 sections.
|
||||
$generator = $this->getDataGenerator();
|
||||
$numsections = 5;
|
||||
$course = $generator->create_course(array('numsections' => $numsections, 'format' => 'topics'),
|
||||
array('createsections' => true));
|
||||
|
||||
// Get section names for course.
|
||||
$coursesections = $DB->get_records('course_sections', array('course' => $course->id));
|
||||
|
||||
// Test get_default_section_name with default section names.
|
||||
$courseformat = course_get_format($course);
|
||||
foreach ($coursesections as $section) {
|
||||
if ($section->section == 0) {
|
||||
$sectionname = get_string('section0name', 'format_topics');
|
||||
$this->assertEquals($sectionname, $courseformat->get_default_section_name($section));
|
||||
} else {
|
||||
$sectionname = get_string('sectionname', 'format_topics') . ' ' . $section->section;
|
||||
$this->assertEquals($sectionname, $courseformat->get_default_section_name($section));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,10 @@ Overview of this plugin type at http://docs.moodle.org/dev/Course_formats
|
||||
renderable menu or array of links. Plugin calls to section_edit_controls will now include the section edit control in the returned array.
|
||||
* The section name is now wrapped in a new span (.sectionname > span), process_sections method in format.js should be updated so .sectionname
|
||||
DOM node's wraps the section title in a span. You can look at how to implement the change in course/format/topics/format.js or MDL-48947.
|
||||
* New method format_base::get_default_section_name retrieves the default section name for the given course format. The base
|
||||
implementation basically uses the implementation of format_base::get_section_name. The method can be overridden in
|
||||
format_base subclasses that use sections (i.e. format_topics, format_weeks). In relation to the changes made for the default
|
||||
section name, the default section name is now being shown when editing the section information.
|
||||
|
||||
=== 2.9 ===
|
||||
* Course formats may support deleting sections, see MDL-10405 for more details.
|
||||
|
||||
@@ -55,7 +55,22 @@ class format_weeks extends format_base {
|
||||
if ((string)$section->name !== '') {
|
||||
// Return the name the user set.
|
||||
return format_string($section->name, true, array('context' => context_course::instance($this->courseid)));
|
||||
} else if ($section->section == 0) {
|
||||
} else {
|
||||
return $this->get_default_section_name($section);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the default section name for the weekly course format.
|
||||
*
|
||||
* If the section number is 0, it will use the string with key = section0name from the course format's lang file.
|
||||
* Otherwise, the default format of "[start date] - [end date]" will be returned.
|
||||
*
|
||||
* @param stdClass $section Section object from database or just field course_sections section
|
||||
* @return string The default value for the section name.
|
||||
*/
|
||||
public function get_default_section_name($section) {
|
||||
if ($section->section == 0) {
|
||||
// Return the general section.
|
||||
return get_string('section0name', 'format_weeks');
|
||||
} else {
|
||||
|
||||
@@ -24,6 +24,22 @@ Feature: Sections can be edited and deleted in weeks format
|
||||
And I follow "Course 1"
|
||||
And I turn editing mode on
|
||||
|
||||
Scenario: View the default name of the general section in weeks format
|
||||
When I click on "Edit section" "link" in the "li#section-0" "css_element"
|
||||
Then I should see "Use default section name [General]"
|
||||
|
||||
Scenario: Edit the default name of the general section in weeks format
|
||||
When I click on "Edit section" "link" in the "li#section-0" "css_element"
|
||||
And I set the following fields to these values:
|
||||
| Use default section name | 0 |
|
||||
| name | This is the general section |
|
||||
And I press "Save changes"
|
||||
Then I should see "This is the general section" in the "li#section-0" "css_element"
|
||||
|
||||
Scenario: View the default name of the second section in weeks format
|
||||
When I click on "Edit week" "link" in the "li#section-2" "css_element"
|
||||
Then I should see "Use default section name [8 May - 14 May]"
|
||||
|
||||
Scenario: Edit section summary in weeks format
|
||||
When I click on "Edit week" "link" in the "li#section-2" "css_element"
|
||||
And I set the following fields to these values:
|
||||
|
||||
@@ -61,4 +61,95 @@ class format_weeks_testcase extends advanced_testcase {
|
||||
$this->assertEquals(8, count(get_fast_modinfo($course)->get_section_info_all()));
|
||||
$this->assertEquals(6, course_get_format($course)->get_course()->numsections);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests for format_weeks::get_section_name method with default section names.
|
||||
*/
|
||||
public function test_get_section_name() {
|
||||
global $DB;
|
||||
$this->resetAfterTest(true);
|
||||
|
||||
// Generate a course with 5 sections.
|
||||
$generator = $this->getDataGenerator();
|
||||
$numsections = 5;
|
||||
$course = $generator->create_course(array('numsections' => $numsections, 'format' => 'weeks'),
|
||||
array('createsections' => true));
|
||||
|
||||
// Get section names for course.
|
||||
$coursesections = $DB->get_records('course_sections', array('course' => $course->id));
|
||||
|
||||
// Test get_section_name with default section names.
|
||||
$courseformat = course_get_format($course);
|
||||
foreach ($coursesections as $section) {
|
||||
// Assert that with unmodified section names, get_section_name returns the same result as get_default_section_name.
|
||||
$this->assertEquals($courseformat->get_default_section_name($section), $courseformat->get_section_name($section));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests for format_weeks::get_section_name method with modified section names.
|
||||
*/
|
||||
public function test_get_section_name_customised() {
|
||||
global $DB;
|
||||
$this->resetAfterTest(true);
|
||||
|
||||
// Generate a course with 5 sections.
|
||||
$generator = $this->getDataGenerator();
|
||||
$numsections = 5;
|
||||
$course = $generator->create_course(array('numsections' => $numsections, 'format' => 'weeks'),
|
||||
array('createsections' => true));
|
||||
|
||||
// Get section names for course.
|
||||
$coursesections = $DB->get_records('course_sections', array('course' => $course->id));
|
||||
|
||||
// Modify section names.
|
||||
$customname = "Custom Section";
|
||||
foreach ($coursesections as $section) {
|
||||
$section->name = "$customname $section->section";
|
||||
$DB->update_record('course_sections', $section);
|
||||
}
|
||||
|
||||
// Requery updated section names then test get_section_name.
|
||||
$coursesections = $DB->get_records('course_sections', array('course' => $course->id));
|
||||
$courseformat = course_get_format($course);
|
||||
foreach ($coursesections as $section) {
|
||||
// Assert that with modified section names, get_section_name returns the modified section name.
|
||||
$this->assertEquals($section->name, $courseformat->get_section_name($section));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests for format_weeks::get_default_section_name.
|
||||
*/
|
||||
public function test_get_default_section_name() {
|
||||
global $DB;
|
||||
$this->resetAfterTest(true);
|
||||
|
||||
// Generate a course with 5 sections.
|
||||
$generator = $this->getDataGenerator();
|
||||
$numsections = 5;
|
||||
$course = $generator->create_course(array('numsections' => $numsections, 'format' => 'weeks'),
|
||||
array('createsections' => true));
|
||||
|
||||
// Get section names for course.
|
||||
$coursesections = $DB->get_records('course_sections', array('course' => $course->id));
|
||||
|
||||
// Test get_default_section_name with default section names.
|
||||
$courseformat = course_get_format($course);
|
||||
foreach ($coursesections as $section) {
|
||||
if ($section->section == 0) {
|
||||
$sectionname = get_string('section0name', 'format_weeks');
|
||||
$this->assertEquals($sectionname, $courseformat->get_default_section_name($section));
|
||||
} else {
|
||||
$dates = $courseformat->get_section_dates($section);
|
||||
$dates->end = ($dates->end - 86400);
|
||||
$dateformat = get_string('strftimedateshort');
|
||||
$weekday = userdate($dates->start, $dateformat);
|
||||
$endweekday = userdate($dates->end, $dateformat);
|
||||
$sectionname = $weekday.' - '.$endweekday;
|
||||
|
||||
$this->assertEquals($sectionname, $courseformat->get_default_section_name($section));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user