Skip to content

Commit

Permalink
Support PHP 8.2 WIP 1
Browse files Browse the repository at this point in the history
  • Loading branch information
james-cnz committed Oct 9, 2023
1 parent 7752cde commit dda1d1f
Show file tree
Hide file tree
Showing 13 changed files with 400 additions and 297 deletions.
10 changes: 8 additions & 2 deletions .github/workflows/moodle-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,18 @@ jobs:
database: pgsql
plugin-ci: ^4
# extensions: xmlrpc-beta
# Moodle master, PHP 8.1, MariaDB
# Moodle 4.3, PHP 8.1, MariaDB
- php: '8.1'
moodle-branch: 'master'
moodle-branch: 'MOODLE_403_STABLE'
database: mariadb
plugin-ci: ^4
# extensions: xmlrpc-beta
# Moodle master, PHP 8.2, PostgreSQL
- php: '8.2'
moodle-branch: 'master'
database: pgsql
plugin-ci: ^4
# extensions: xmlrpc-beta

steps:
- name: Check out repository code
Expand Down
11 changes: 6 additions & 5 deletions _course_editsection.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@
require_capability('moodle/course:update', $context);

// Get section_info object with all availability options.
$sectioninfo = course_get_format($course)->fmt_get_section($section); // CHANGED: Use custom function, pass section info.
$sectioninfo = get_fast_modinfo($course)->get_section_info($sectionnum);
$sectioninfoextra = course_get_format($course)->fmt_get_section_extra($sectioninfo); // ADDED.

// Deleting the section.
if ($deletesection) {
Expand All @@ -65,10 +66,10 @@
// ADDED.
// If section was topic level, return to page, else return to previous section.
$sectionreturn = new \stdClass();
if ($sectioninfo->levelsan >= FORMAT_MULTITOPIC_SECTION_LEVEL_TOPIC) {
$sectionreturn->id = $sectioninfo->parentid;
if ($sectioninfoextra->levelsan >= FORMAT_MULTITOPIC_SECTION_LEVEL_TOPIC) {
$sectionreturn->id = $sectioninfoextra->parentid;
} else {
$sectionreturn->id = $sectioninfo->prevupid;
$sectionreturn->id = $sectioninfoextra->prevupid;
}
// END ADDED.
$courseurl = course_get_url($course, $sectionreturn); // CHANGED: Use sectionreturn defined above.
Expand Down Expand Up @@ -110,7 +111,7 @@
];

$courseformat = course_get_format($course);
$defaultsectionname = $courseformat->get_default_section_name($sectioninfo); // CHANGED: Use custom section info.
$defaultsectionname = $courseformat->get_default_section_name($sectioninfo); // CHANGED: Use section info.

$customdata = [
'cs' => $sectioninfo,
Expand Down
48 changes: 24 additions & 24 deletions classes/courseformat/stateactions.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ public function section_move(
$this->validate_sections($course, [$targetsectionid], __FUNCTION__);

$format = course_get_format($course->id);
$allsections = $format->fmt_get_sections();
$draggedoriginsection = $allsections[$ids[0]];
$allsectionsextra = $format->fmt_get_sections_extra();
$draggedoriginsection = $allsectionsextra[$ids[0]];
if (method_exists($this, 'sort_section_ids_by_section_number')) {
$ids = $this->sort_section_ids_by_section_number($course, $ids, false);
}
Expand All @@ -78,15 +78,15 @@ public function section_move(
$origins = [];
$subids = [];
foreach ($ids as $id) {
$origin = $allsections[$id];
$origin = $allsectionsextra[$id];
$origins[] = $origin;
for ($originsub = $origin; /* ... */
$originsub && ($originsub->id == $origin->id || $originsub->levelsan > $origin->levelsan); /* ... */
$originsub = $originsub->nextanyid ? $allsections[$originsub->nextanyid] : null) {
$originsub = $originsub->nextanyid ? $allsectionsextra[$originsub->nextanyid] : null) {
$subids[] = $originsub->id;
}
}
$targetsection = $allsections[$targetsectionid];
$targetsection = $allsectionsextra[$targetsectionid];
if ($targetsection->section > $draggedoriginsection->section) {
$destination = (object)['prevupid' => $targetsectionid];
} else {
Expand All @@ -105,12 +105,12 @@ public function section_move(
$this->section_state($updates, $course, $subids, $targetsectionid);

// All course sections can be renamed because of the resort.
foreach ($allsections as $section) {
foreach ($allsectionsextra as $sectionextra) {
// Ignore the affected sections because they are already in the updates.
if (isset($affectedsections[$section->id])) {
if (isset($affectedsections[$sectionextra->id])) {
continue;
}
$updates->add_section_put($section->id);
$updates->add_section_put($sectionextra->id);
}
// The section order is at a course level.
$updates->add_course_put();
Expand Down Expand Up @@ -146,7 +146,7 @@ public function section_move_after(
$this->validate_sections($course, [$targetsectionid], __FUNCTION__);

$format = course_get_format($course->id);
$allsections = $format->fmt_get_sections();
$allsectionsextra = $format->fmt_get_sections_extra();
if (method_exists($this, 'sort_section_ids_by_section_number')) {
$ids = $this->sort_section_ids_by_section_number($course, $ids, false);
}
Expand All @@ -155,11 +155,11 @@ public function section_move_after(
$origins = [];
$subids = [];
foreach ($ids as $id) {
$origin = $allsections[$id];
$origin = $allsectionsextra[$id];
$origins[] = $origin;
for ($originsub = $origin; /* ... */
$originsub && ($originsub->id == $origin->id || $originsub->levelsan > $origin->levelsan); /* ... */
$originsub = $originsub->nextanyid ? $allsections[$originsub->nextanyid] : null) {
$originsub = $originsub->nextanyid ? $allsectionsextra[$originsub->nextanyid] : null) {
$subids[] = $originsub->id;
}
}
Expand All @@ -177,12 +177,12 @@ public function section_move_after(
$this->section_state($updates, $course, $subids, $targetsectionid);

// All course sections can be renamed because of the resort.
foreach ($allsections as $section) {
foreach ($allsectionsextra as $sectionextra) {
// Ignore the affected sections because they are already in the updates.
if (isset($affectedsections[$section->id])) {
if (isset($affectedsections[$sectionextra->id])) {
continue;
}
$updates->add_section_put($section->id);
$updates->add_section_put($sectionextra->id);
}
// The section order is at a course level.
$updates->add_course_put();
Expand Down Expand Up @@ -218,7 +218,7 @@ public function fmt_section_move_into(
$this->validate_sections($course, [$targetsectionid], __FUNCTION__);

$format = course_get_format($course->id);
$allsections = $format->fmt_get_sections();
$allsectionsextra = $format->fmt_get_sections_extra();
if (method_exists($this, 'sort_section_ids_by_section_number')) {
$ids = $this->sort_section_ids_by_section_number($course, $ids, false);
}
Expand All @@ -227,11 +227,11 @@ public function fmt_section_move_into(
$origins = [];
$subids = [];
foreach ($ids as $id) {
$origin = $allsections[$id];
$origin = $allsectionsextra[$id];
$origins[] = $origin;
for ($originsub = $origin; /* ... */
$originsub && ($originsub->id == $origin->id || $originsub->levelsan > $origin->levelsan); /* ... */
$originsub = $originsub->nextanyid ? $allsections[$originsub->nextanyid] : null) {
$originsub = $originsub->nextanyid ? $allsectionsextra[$originsub->nextanyid] : null) {
$subids[] = $originsub->id;
}
}
Expand All @@ -249,12 +249,12 @@ public function fmt_section_move_into(
$this->section_state($updates, $course, $subids, $targetsectionid);

// All course sections can be renamed because of the resort.
foreach ($allsections as $section) {
foreach ($allsectionsextra as $sectionextra) {
// Ignore the affected sections because they are already in the updates.
if (isset($affectedsections[$section->id])) {
if (isset($affectedsections[$sectionextra->id])) {
continue;
}
$updates->add_section_put($section->id);
$updates->add_section_put($sectionextra->id);
}
// The section order is at a course level.
$updates->add_course_put();
Expand All @@ -279,12 +279,12 @@ protected function set_section_visibility (
require_all_capabilities(['moodle/course:update', 'moodle/course:sectionvisibility'], $coursecontext);

$format = course_get_format($course->id);
$allsections = $format->fmt_get_sections();
$allsectionsextra = $format->fmt_get_sections_extra();

foreach ($ids as $sectionid) {
$section = $allsections[$sectionid];
if (!$visible && $section->section || $visible && $section->parentvisiblesan) {
course_update_section($course, $section, ['visible' => $visible]);
$sectionextra = $allsectionsextra[$sectionid];
if (!$visible && $sectionextra->section || $visible && $sectionextra->parentvisiblesan) {
course_update_section($course, $sectionextra->sectionbase, ['visible' => $visible]);
}
}
$this->section_state($updates, $course, $ids);
Expand Down
5 changes: 3 additions & 2 deletions classes/global_navigation_wrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,15 @@ protected function generate_sections_and_activities(\stdClass $course) : array {
require_once($CFG->dirroot . '/course/lib.php');

$modinfo = get_fast_modinfo($course);
$sections = course_get_format($course)->fmt_get_sections(); // CHANGED: Use custom call.
$sections = $modinfo->get_section_info_all();

// For course formats using 'numsections' trim the sections list.
// REMOVED.

$activities = [];

foreach ($sections as $key => $section) {
foreach ($sections as $number => $section) { // CHANGED.
$key = $section->id; // ADDED.
// Clone and unset summary to prevent $SESSION bloat (MDL-31802).
$sections[$key] = clone($section);
unset($sections[$key]->summary);
Expand Down
59 changes: 26 additions & 33 deletions classes/output/courseformat/content.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
*/
class content extends content_base {

/** @var \section_info[] course sections */
protected $fmtsections;
/** @var \format_multitopic\section_info_extra[] course sections */
protected $fmtsectionsextra;

/**
* Export this data so it can be used as the context for a mustache template (core/inplace_editable).
Expand All @@ -60,18 +60,18 @@ public function export_for_template(\renderer_base $output) {

// ADDED.
$course = $format->get_course();
$sections = $this->format->fmt_get_sections();
$this->fmtsections = $sections;
$sectionsextra = $this->format->fmt_get_sections_extra();
$this->fmtsectionsextra = $sectionsextra;
$maxsections = $format->get_max_sections();
$canaddmore = $maxsections > $format->get_last_section_number();
$displaysection = $sections[$this->format->singlesectionid];
$displaysection = $sectionsextra[$this->format->singlesectionid];
$activesectionids = [];
for ($activesn = $displaysection; /* ... */
$activesn; /* ... */
$activesn = (($activesn->parentid
&& ($activesn->levelsan > FORMAT_MULTITOPIC_SECTION_LEVEL_ROOT + 1
|| $activesn->parentid != $format->fmtrootsectionid))
? $sections[$activesn->parentid] : null)) {
? $sectionsextra[$activesn->parentid] : null)) {
$activesectionids[$activesn->id] = true;
}
$sectionpreferencesarray = $format->get_sections_preferences();
Expand Down Expand Up @@ -120,10 +120,11 @@ public function export_for_template(\renderer_base $output) {
$sectionatlevel = array_fill(FORMAT_MULTITOPIC_SECTION_LEVEL_ROOT,
FORMAT_MULTITOPIC_SECTION_LEVEL_TOPIC - FORMAT_MULTITOPIC_SECTION_LEVEL_ROOT, null);

foreach ($sections as $thissection) {
foreach ($sectionsextra as $thissectionextra) {
$thissection = $thissectionextra->sectionbase;

for ($level = $thissection->levelsan; $level < FORMAT_MULTITOPIC_SECTION_LEVEL_TOPIC; $level++) {
$sectionatlevel[$level] = $thissection;
for ($level = $thissectionextra->levelsan; $level < FORMAT_MULTITOPIC_SECTION_LEVEL_TOPIC; $level++) {
$sectionatlevel[$level] = $thissectionextra;
}

// Show the section if the user is permitted to access it, OR if it's not available
Expand All @@ -134,7 +135,7 @@ public function export_for_template(\renderer_base $output) {
&& ($thissection->available || !empty($thissection->availableinfo));

// Make and add tabs for visible pages.
if ($thissection->levelsan < FORMAT_MULTITOPIC_SECTION_LEVEL_TOPIC && $showsection) {
if ($thissectionextra->levelsan < FORMAT_MULTITOPIC_SECTION_LEVEL_TOPIC && $showsection) {

$sectionname = get_section_name($course, $thissection);

Expand All @@ -143,17 +144,17 @@ public function export_for_template(\renderer_base $output) {
// REMOVED: marker.

// Include main tab, and index tabs for pages with sub-pages.
for ($level = max(FORMAT_MULTITOPIC_SECTION_LEVEL_ROOT + 1, $thissection->levelsan); /* ... */
$level <= $thissection->pagedepthdirect
for ($level = max(FORMAT_MULTITOPIC_SECTION_LEVEL_ROOT + 1, $thissectionextra->levelsan); /* ... */
$level <= $thissectionextra->pagedepthdirect
+ ($format->show_editor()
&& $thissection->pagedepthdirect < FORMAT_MULTITOPIC_SECTION_LEVEL_PAGE_USE ? 1 : 0); /* ... */
&& $thissectionextra->pagedepthdirect < FORMAT_MULTITOPIC_SECTION_LEVEL_PAGE_USE ? 1 : 0); /* ... */
$level++) {

// Make tab.
$newtab = new \tabobject("tab_id_{$thissection->id}_l{$level}", $url,
\html_writer::tag('div', $sectionname, ['class' =>
'tab_content'
. ($thissection->currentnestedlevel >= $level ? ' marker' : '')
. ($thissectionextra->currentnestedlevel >= $level ? ' marker' : '')
. ((!$thissection->visible || !$thissection->available) && ($thissection->section != 0)
|| $level > $thissection->pagedepthdirect ? ' dimmed' : ''),
'data-itemid' => $thissection->id,
Expand All @@ -177,17 +178,17 @@ public function export_for_template(\renderer_base $output) {

// Disable tabs for hidden sections.
if (!$thissection->uservisible && ($thissection->section != 0)) {
$inactivetabs[] = "tab_id_{$thissection->id}_l{$thissection->levelsan}";
$inactivetabs[] = "tab_id_{$thissection->id}_l{$thissectionextra->levelsan}";
}

}

// Include "add" sub-tabs if editing.
if ($thissection->nextanyid == $thissection->nextpageid
if ($thissectionextra->nextanyid == $thissectionextra->nextpageid
&& $format->show_editor()) {

// Include "add" sub-tabs for each level of page finished.
$nextsectionlevel = $thissection->nextpageid ? $sections[$thissection->nextpageid]->levelsan
$nextsectionlevel = $thissectionextra->nextpageid ? $sectionsextra[$thissectionextra->nextpageid]->levelsan
: FORMAT_MULTITOPIC_SECTION_LEVEL_ROOT;
for ($level = min($sectionatlevel[FORMAT_MULTITOPIC_SECTION_LEVEL_TOPIC - 1]->pagedepthdirect + 1,
FORMAT_MULTITOPIC_SECTION_LEVEL_PAGE_USE); /* ... */
Expand Down Expand Up @@ -305,36 +306,28 @@ protected function export_sections(\renderer_base $output): array {
$course = $format->get_course();
$modinfo = $this->format->get_modinfo();

$sectionatlevel = array_fill(FORMAT_MULTITOPIC_SECTION_LEVEL_ROOT, // ADDED.
FORMAT_MULTITOPIC_SECTION_LEVEL_TOPIC - FORMAT_MULTITOPIC_SECTION_LEVEL_ROOT, null);

// Generate section list.
$sectionseft = [];
// REMOVED stealthsections and numsections.
foreach ($this->get_sections_to_display($modinfo) as $thissection) {
foreach ($this->get_sections_to_display_extra($modinfo) as $thissectionextra) {
// The course/view.php check the section existence but the output can be called
// from other parts so we need to check it.
if (!$thissection) {
if (!$thissectionextra) {
throw new \moodle_exception('unknowncoursesection', 'error', course_get_url($course),
format_string($course->fullname));
}
$thissection = $thissectionextra->sectionbase;

$section = new $this->sectionclass($format, $thissection);

// ADDED.
for ($level = $thissection->levelsan; $level < FORMAT_MULTITOPIC_SECTION_LEVEL_TOPIC; $level++) {
$sectionatlevel[$level] = $thissection;
}
// END ADDED.

// REMOVED: numsections.

if (!$format->is_section_visible($thissection)) {
continue;
}

$pageid = ($thissection->levelsan < FORMAT_MULTITOPIC_SECTION_LEVEL_TOPIC) ? $thissection->id
: $thissection->parentid;
$pageid = ($thissectionextra->levelsan < FORMAT_MULTITOPIC_SECTION_LEVEL_TOPIC) ? $thissection->id
: $thissectionextra->parentid;
$onpage = ($pageid == $format->singlesectionid);
if ($onpage || $format->show_editor()) {
$sectionseft[] = $section->export_for_template($output);
Expand All @@ -352,10 +345,10 @@ protected function export_sections(\renderer_base $output): array {
* or a list of them.
*
* @param \course_modinfo $modinfo the current course modinfo object
* @return \section_info[] an array of section_info to display
* @return \format_multitopic\section_info_extra[] an array of section_info to display
*/
private function get_sections_to_display(\course_modinfo $modinfo): array {
return $this->fmtsections;
private function get_sections_to_display_extra(\course_modinfo $modinfo): array {
return $this->fmtsectionsextra;
}

}
Loading

0 comments on commit dda1d1f

Please sign in to comment.