MDL-80460 format_topics: Replace name from "Topic X" with "New section"

From now on, the default section name for the topics course format is
"New section" instead of "Topic x" (where x was the section number).
A new item, initsections, has been added to the create_course() function
in the testing_data_generator class, to let the generator rename the
sections to "Section X"

AMOS BEGIN
  CPY [sectionname,format_topics],[legacysectionname,format_topics]
AMOS END
This commit is contained in:
Sara Arjona
2024-03-06 15:25:22 +01:00
parent b2fa19f45d
commit 076aead150
9 changed files with 102 additions and 24 deletions
+32 -11
View File
@@ -14,15 +14,6 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Data generator.
*
* @package core
* @category test
* @copyright 2012 Petr Skoda {@link http://skodak.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
/**
@@ -357,9 +348,10 @@ EOD;
/**
* Create a test course
* @param array|stdClass $record
* @param array|stdClass $record Apart from the course information, the following can be also set:
* 'initsections' => bool for section name initialization, renaming them to "Section X". Default value is 0 (false).
* @param array $options with keys:
* 'createsections'=>bool precreate all sections
* 'createsections' => bool precreate all sections
* @return stdClass course record
*/
public function create_course($record=null, array $options=null) {
@@ -427,12 +419,41 @@ EOD;
}
}
$initsections = !empty($record['initsections']);
unset($record['initsections']);
$course = create_course((object)$record);
if ($initsections) {
$this->init_sections($course);
}
context_course::instance($course->id);
return $course;
}
/**
* Initializes sections for a specified course, such as configuring section names for courses using 'Section X'.
*
* @param stdClass $course The course object.
*/
private function init_sections(stdClass $course): void {
global $DB;
$sections = $DB->get_records('course_sections', ['course' => $course->id], 'section');
foreach ($sections as $section) {
if ($section->section != 0) {
$DB->set_field(
table: 'course_sections',
newfield: 'name',
newvalue: get_string('section', 'core') . ' ' . $section->section,
conditions: [
'id' => $section->id,
],
);
}
}
}
/**
* Create course section if does not exist yet
* @param array|stdClass $record must contain 'course' and 'section' attributes