mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 00:16:46 +02:00
MDL-35339 deprecate get_course_section() replace with course_create_sections_if_missing()
By passing course object instead of course id we ensure proper cache reset"
This commit is contained in:
parent
9796014660
commit
4ede27b253
9 changed files with 76 additions and 45 deletions
|
@ -61,8 +61,9 @@ class block_site_main_menu extends block_list {
|
||||||
|
|
||||||
/// slow & hacky editing mode
|
/// slow & hacky editing mode
|
||||||
$ismoving = ismoving($course->id);
|
$ismoving = ismoving($course->id);
|
||||||
$section = get_course_section(0, $course->id);
|
course_create_sections_if_missing($course, 0);
|
||||||
$modinfo = get_fast_modinfo($course);
|
$modinfo = get_fast_modinfo($course);
|
||||||
|
$section = $modinfo->get_section_info(0);
|
||||||
|
|
||||||
$groupbuttons = $course->groupmode;
|
$groupbuttons = $course->groupmode;
|
||||||
$groupbuttonslink = (!$course->groupmodeforce);
|
$groupbuttonslink = (!$course->groupmodeforce);
|
||||||
|
|
|
@ -45,12 +45,7 @@ if (($marker >=0) && has_capability('moodle/course:setcurrentsection', $context)
|
||||||
}
|
}
|
||||||
|
|
||||||
// make sure all sections are created
|
// make sure all sections are created
|
||||||
$modinfo = get_fast_modinfo($course);
|
course_create_sections_if_missing($course, range(0, $course->numsections));
|
||||||
for ($sectionnum = 0; $sectionnum <= $course->numsections; $sectionnum++) {
|
|
||||||
if (!$modinfo->get_section_info($sectionnum)) {
|
|
||||||
get_course_section($sectionnum, $course->id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$renderer = $PAGE->get_renderer('format_topics');
|
$renderer = $PAGE->get_renderer('format_topics');
|
||||||
|
|
||||||
|
|
|
@ -38,12 +38,7 @@ if ($week = optional_param('week', 0, PARAM_INT)) {
|
||||||
// End backwards-compatible aliasing..
|
// End backwards-compatible aliasing..
|
||||||
|
|
||||||
// make sure all sections are created
|
// make sure all sections are created
|
||||||
$modinfo = get_fast_modinfo($course);
|
course_create_sections_if_missing($course, range(0, $course->numsections));
|
||||||
for ($sectionnum = 0; $sectionnum <= $course->numsections; $sectionnum++) {
|
|
||||||
if (!$modinfo->get_section_info($sectionnum)) {
|
|
||||||
get_course_section($sectionnum, $course->id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$renderer = $PAGE->get_renderer('format_weeks');
|
$renderer = $PAGE->get_renderer('format_weeks');
|
||||||
|
|
||||||
|
|
|
@ -2691,27 +2691,37 @@ function add_course_module($mod) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns course section - creates new if does not exist yet
|
* Creates missing course section(s) and rebuilds course cache
|
||||||
*
|
*
|
||||||
* @param int $section relative section number (field course_sections.section)
|
* @param stdClass $course course object
|
||||||
* @param int $courseid
|
* @param int|array $sections list of relative section numbers to create
|
||||||
* @return stdClass record from table {course_sections}
|
* @return bool if there were any sections created
|
||||||
*/
|
*/
|
||||||
function get_course_section($section, $courseid) {
|
function course_create_sections_if_missing(&$course, $sections) {
|
||||||
global $DB;
|
global $DB;
|
||||||
|
if (!is_array($sections)) {
|
||||||
if ($cw = $DB->get_record("course_sections", array("section"=>$section, "course"=>$courseid))) {
|
$sections = array($sections);
|
||||||
return $cw;
|
|
||||||
}
|
}
|
||||||
$cw = new stdClass();
|
$existing = array_keys(get_fast_modinfo($course)->get_section_info_all());
|
||||||
$cw->course = $courseid;
|
$coursechanged = false;
|
||||||
$cw->section = $section;
|
foreach ($sections as $sectionnum) {
|
||||||
$cw->summary = "";
|
if (!in_array($sectionnum, $existing)) {
|
||||||
$cw->summaryformat = FORMAT_HTML;
|
$cw = new stdClass();
|
||||||
$cw->sequence = "";
|
$cw->course = $course->id;
|
||||||
$id = $DB->insert_record("course_sections", $cw);
|
$cw->section = $sectionnum;
|
||||||
rebuild_course_cache($courseid, true);
|
$cw->summary = '';
|
||||||
return $DB->get_record("course_sections", array("id"=>$id));
|
$cw->summaryformat = FORMAT_HTML;
|
||||||
|
$cw->sequence = '';
|
||||||
|
$id = $DB->insert_record("course_sections", $cw);
|
||||||
|
$coursechanged = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($coursechanged) {
|
||||||
|
rebuild_course_cache($course->id, true);
|
||||||
|
$course->modinfo = null;
|
||||||
|
$course->sectioncache = null;
|
||||||
|
}
|
||||||
|
return $coursechanged;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -2742,7 +2752,8 @@ function course_add_cm_to_section($courseorid, $modid, $sectionnum, $beforemod =
|
||||||
$course = $DB->get_record('course', array('id' => $courseorid), '*', MUST_EXIST);
|
$course = $DB->get_record('course', array('id' => $courseorid), '*', MUST_EXIST);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$section = get_course_section($sectionnum, $courseid);
|
course_create_sections_if_missing($course, $sectionnum);
|
||||||
|
$section = get_fast_modinfo($course)->get_section_info($sectionnum);
|
||||||
$modarray = explode(",", trim($section->sequence));
|
$modarray = explode(",", trim($section->sequence));
|
||||||
if (empty($modarray)) {
|
if (empty($modarray)) {
|
||||||
$newsequence = "$modid";
|
$newsequence = "$modid";
|
||||||
|
@ -3745,11 +3756,8 @@ function create_course($data, $editoroptions = NULL) {
|
||||||
// Setup the blocks
|
// Setup the blocks
|
||||||
blocks_add_default_course_blocks($course);
|
blocks_add_default_course_blocks($course);
|
||||||
|
|
||||||
$section = new stdClass();
|
// Create a default section.
|
||||||
$section->course = $course->id; // Create a default section.
|
course_create_sections_if_missing($course, 0);
|
||||||
$section->section = 0;
|
|
||||||
$section->summaryformat = FORMAT_HTML;
|
|
||||||
$DB->insert_record('course_sections', $section);
|
|
||||||
|
|
||||||
fix_course_sortorder();
|
fix_course_sortorder();
|
||||||
|
|
||||||
|
|
|
@ -59,7 +59,8 @@ if (!empty($add)) {
|
||||||
$context = context_course::instance($course->id);
|
$context = context_course::instance($course->id);
|
||||||
require_capability('moodle/course:manageactivities', $context);
|
require_capability('moodle/course:manageactivities', $context);
|
||||||
|
|
||||||
$cw = get_course_section($section, $course->id);
|
course_create_sections_if_missing($course, $section);
|
||||||
|
$cw = get_fast_modinfo($course)->get_section_info($section);
|
||||||
|
|
||||||
if (!course_allowed_module($course, $module->name)) {
|
if (!course_allowed_module($course, $module->name)) {
|
||||||
print_error('moduledisable');
|
print_error('moduledisable');
|
||||||
|
|
|
@ -243,7 +243,7 @@
|
||||||
echo html_writer::start_tag('div', array('class'=>'course-content'));
|
echo html_writer::start_tag('div', array('class'=>'course-content'));
|
||||||
|
|
||||||
// make sure that section 0 exists (this function will create one if it is missing)
|
// make sure that section 0 exists (this function will create one if it is missing)
|
||||||
$section0 = get_course_section(0, $course->id);
|
course_create_sections_if_missing($course, 0);
|
||||||
|
|
||||||
// get information about course modules and existing module types
|
// get information about course modules and existing module types
|
||||||
// format.php in course formats may rely on presence of these variables
|
// format.php in course formats may rely on presence of these variables
|
||||||
|
|
|
@ -434,11 +434,8 @@ function process_group_tag($tagcontents) {
|
||||||
$course = $DB->get_record('course', array('id' => $courseid));
|
$course = $DB->get_record('course', array('id' => $courseid));
|
||||||
blocks_add_default_course_blocks($course);
|
blocks_add_default_course_blocks($course);
|
||||||
|
|
||||||
$section = new stdClass();
|
// Create default 0-section
|
||||||
$section->course = $course->id; // Create a default section.
|
course_create_sections_if_missing($course, 0);
|
||||||
$section->section = 0;
|
|
||||||
$section->summaryformat = FORMAT_HTML;
|
|
||||||
$section->id = $DB->insert_record("course_sections", $section);
|
|
||||||
|
|
||||||
add_to_log(SITEID, "course", "new", "view.php?id=$course->id", "$course->fullname (ID $course->id)");
|
add_to_log(SITEID, "course", "new", "view.php?id=$course->id", "$course->fullname (ID $course->id)");
|
||||||
|
|
||||||
|
|
|
@ -109,8 +109,8 @@
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if ($editing) {
|
if ($editing) {
|
||||||
// make sure section with number 1 exists, this function will create section
|
// make sure section with number 1 exists
|
||||||
get_course_section(1, $SITE->id);
|
course_create_sections_if_missing($SITE, 1);
|
||||||
// re-request modinfo in case section was created
|
// re-request modinfo in case section was created
|
||||||
$modinfo = get_fast_modinfo($SITE);
|
$modinfo = get_fast_modinfo($SITE);
|
||||||
}
|
}
|
||||||
|
|
|
@ -3013,3 +3013,37 @@ function get_all_mods($courseid, &$mods, &$modnames, &$modnamesplural, &$modname
|
||||||
$mods = $modinfo->get_cms();
|
$mods = $modinfo->get_cms();
|
||||||
$modnamesused = $modinfo->get_used_module_names();
|
$modnamesused = $modinfo->get_used_module_names();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns course section - creates new if does not exist yet
|
||||||
|
*
|
||||||
|
* This function is deprecated. To create a course section call:
|
||||||
|
* course_create_sections_if_missing($course, $sections);
|
||||||
|
* to get the section call:
|
||||||
|
* get_fast_modinfo($course)->get_section_info($sectionnum);
|
||||||
|
*
|
||||||
|
* @see course_create_sections_if_missing()
|
||||||
|
* @see get_fast_modinfo()
|
||||||
|
* @deprecated since 2.4
|
||||||
|
*
|
||||||
|
* @param int $section relative section number (field course_sections.section)
|
||||||
|
* @param int $courseid
|
||||||
|
* @return stdClass record from table {course_sections}
|
||||||
|
*/
|
||||||
|
function get_course_section($section, $courseid) {
|
||||||
|
global $DB;
|
||||||
|
debugging('Function get_course_section() is deprecated. Please use course_create_sections_if_missing() and get_fast_modinfo() instead.', DEBUG_DEVELOPER);
|
||||||
|
|
||||||
|
if ($cw = $DB->get_record("course_sections", array("section"=>$section, "course"=>$courseid))) {
|
||||||
|
return $cw;
|
||||||
|
}
|
||||||
|
$cw = new stdClass();
|
||||||
|
$cw->course = $courseid;
|
||||||
|
$cw->section = $section;
|
||||||
|
$cw->summary = "";
|
||||||
|
$cw->summaryformat = FORMAT_HTML;
|
||||||
|
$cw->sequence = "";
|
||||||
|
$id = $DB->insert_record("course_sections", $cw);
|
||||||
|
rebuild_course_cache($courseid, true);
|
||||||
|
return $DB->get_record("course_sections", array("id"=>$id));
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue