Merge branch 'MDL-83561-main' of https://github.com/laurentdavid/moodle
This commit is contained in:
@@ -170,4 +170,20 @@ class format_social extends core_courseformat\base {
|
||||
// Social ony uses one section.
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns if a specific section is visible to the current user.
|
||||
*
|
||||
* Formats can override this method to implement any special section logic.
|
||||
* Social format does not use any other sections than section 0 and
|
||||
* used this method to hide all other sections from the Move section activity.
|
||||
*
|
||||
* @param section_info $section the section modinfo
|
||||
* @return bool;
|
||||
*/
|
||||
#[\Override]
|
||||
public function is_section_visible(section_info $section): bool {
|
||||
$visible = parent::is_section_visible($section);
|
||||
return $visible && $section->section == 0;
|
||||
}
|
||||
}
|
||||
|
||||
+9
-5
@@ -86,7 +86,7 @@ final class get_state_test extends \externallib_advanced_testcase {
|
||||
|
||||
// Create a course.
|
||||
$numsections = 6;
|
||||
$visiblesections = $numsections + 1; // Include topic 0.
|
||||
|
||||
$course = $this->getDataGenerator()->create_course(['numsections' => $numsections, 'format' => $format]);
|
||||
$hiddensections = [4, 6];
|
||||
foreach ($hiddensections as $section) {
|
||||
@@ -99,16 +99,20 @@ final class get_state_test extends \externallib_advanced_testcase {
|
||||
if ($isadmin) {
|
||||
$this->setAdminUser();
|
||||
} else {
|
||||
if (!$canedit) {
|
||||
// User won't see the hidden sections. Remove them from the total.
|
||||
$visiblesections = $visiblesections - count($hiddensections);
|
||||
}
|
||||
$user = $this->getDataGenerator()->create_user();
|
||||
if ($role != 'unenroled') {
|
||||
$this->getDataGenerator()->enrol_user($user->id, $course->id, $role);
|
||||
}
|
||||
$this->setUser($user);
|
||||
}
|
||||
$visiblesections = $numsections + 1; // We include topic 0.
|
||||
if (!$canedit) {
|
||||
// User won't see the hidden sections. Remove them from the total.
|
||||
$visiblesections = $visiblesections - count($hiddensections);
|
||||
}
|
||||
if ($format == 'social') {
|
||||
$visiblesections = 1; // But Social format has one section visible.
|
||||
}
|
||||
|
||||
// Social course format automatically creates a forum activity.
|
||||
if (course_get_format($course)->get_format() === 'social') {
|
||||
|
||||
@@ -111,8 +111,8 @@ final class state_test extends \advanced_testcase {
|
||||
$sections = $modinfo->get_section_info_all();
|
||||
|
||||
foreach ($sections as $key => $section) {
|
||||
$this->assertEquals($section->id, $result->course->sectionlist[$key]);
|
||||
if (!$issocialformat || $format == 'theunittest') {
|
||||
$this->assertEquals($section->id, $result->course->sectionlist[$key]);
|
||||
if (!empty($section->uservisible)) {
|
||||
$sectionstate = new $sectionclass($courseformat, $section);
|
||||
$result->section[$key] = $sectionstate->export_for_template($renderer);
|
||||
|
||||
@@ -318,10 +318,14 @@ final class stateactions_test extends \advanced_testcase {
|
||||
$expectedexception = ($format === 'singleactivity');
|
||||
|
||||
$cms = ['cm0', 'cm1', 'cm2', 'cm3'];
|
||||
// All sections and cms that the user can access to.
|
||||
$usersections = ['section0', 'section1', 'section2', 'section3'];
|
||||
|
||||
$studentcms = ['cm0'];
|
||||
if ($format === 'social') {
|
||||
$cms = ['initialcm0', 'cm0', 'cm1', 'cm2', 'cm3'];
|
||||
$studentcms = ['initialcm0', 'cm0'];
|
||||
$usersections = ['section0']; // Social format only uses section 0 (for all users).
|
||||
}
|
||||
|
||||
return [
|
||||
@@ -335,7 +339,7 @@ final class stateactions_test extends \advanced_testcase {
|
||||
],
|
||||
'expectedresults' => [
|
||||
'course' => ['course'],
|
||||
'section' => ['section0', 'section1', 'section2', 'section3'],
|
||||
'section' => array_intersect($usersections, ['section0', 'section1', 'section2', 'section3']),
|
||||
'cm' => $cms,
|
||||
],
|
||||
'expectedexception' => $expectedexception,
|
||||
@@ -349,7 +353,7 @@ final class stateactions_test extends \advanced_testcase {
|
||||
],
|
||||
'expectedresults' => [
|
||||
'course' => ['course'],
|
||||
'section' => ['section0', 'section1', 'section2', 'section3'],
|
||||
'section' => array_intersect($usersections, ['section0', 'section1', 'section2', 'section3']),
|
||||
'cm' => $cms,
|
||||
],
|
||||
'expectedexception' => $expectedexception,
|
||||
@@ -363,7 +367,7 @@ final class stateactions_test extends \advanced_testcase {
|
||||
],
|
||||
'expectedresults' => [
|
||||
'course' => ['course'],
|
||||
'section' => ['section0', 'section1', 'section3'],
|
||||
'section' => array_intersect($usersections, ['section0', 'section1', 'section3']),
|
||||
'cm' => $studentcms,
|
||||
],
|
||||
'expectedexception' => $expectedexception,
|
||||
@@ -392,6 +396,7 @@ final class stateactions_test extends \advanced_testcase {
|
||||
}
|
||||
if ($format === 'social') {
|
||||
$usercms = ['initialcm0', ...$usercms];
|
||||
$usersections = ['section0']; // Social format only uses section 0 (for all users).
|
||||
}
|
||||
|
||||
return [
|
||||
@@ -519,6 +524,7 @@ final class stateactions_test extends \advanced_testcase {
|
||||
}
|
||||
if ($format === 'social') {
|
||||
$usercms = ['initialcm0', ...$usercms];
|
||||
$usersections = ['section0']; // Social format only uses section 0 (for all users).
|
||||
}
|
||||
|
||||
return [
|
||||
|
||||
Reference in New Issue
Block a user