Skip to content

Commit

Permalink
Fixed: Duplication of activitiy in section 0 #154
Browse files Browse the repository at this point in the history
  • Loading branch information
davidherney committed May 15, 2024
1 parent c78376a commit 276123c
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 22 deletions.
8 changes: 3 additions & 5 deletions classes/header.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ public function __construct(\format_onetopic $format) {
/**
* Export this data so it can be used as the context for a mustache template (core/inplace_editable).
*
* @param renderer_base $output typically, the renderer that's calling this function
* @param \renderer_base $output typically, the renderer that's calling this function
* @return stdClass data context for a mustache template
*/
public function export_for_template(\renderer_base $output) {
global $COURSE, $PAGE, $CFG, $OUTPUT;
global $PAGE, $CFG, $OUTPUT;

$format = $this->format;
$course = $this->format->get_course();
Expand Down Expand Up @@ -170,7 +170,6 @@ public function export_for_template(\renderer_base $output) {
* @return \format_onetopic\tabs an object with tabs information
*/
private function get_tabs(course_modinfo $modinfo, \renderer_base $output): \format_onetopic\tabs {
global $PAGE;

$course = $this->format->get_course();
$sections = $modinfo->get_section_info_all();
Expand Down Expand Up @@ -240,7 +239,7 @@ private function get_tabs(course_modinfo $modinfo, \renderer_base $output): \for
}

if ($section == 0) {
$url = new \moodle_url('/course/view.php', array('id' => $course->id, 'section' => 0));
$url = new \moodle_url('/course/view.php', ['id' => $course->id, 'section' => 0]);
} else {
$url = course_get_url($course, $section);
}
Expand All @@ -261,7 +260,6 @@ private function get_tabs(course_modinfo $modinfo, \renderer_base $output): \for
// Check if display available message is required.
$availablemessage = null;
if ($course->hiddensections == 2) {
$sectiontpl = new content_base\section($this->format, $thissection);
$availabilityclass = $this->format->get_output_classname('content\\section\\availability');
$availability = new $availabilityclass($this->format, $thissection);
$availabledata = $availability->export_for_template($output);
Expand Down
18 changes: 15 additions & 3 deletions classes/output/courseformat/content.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function get_template_name(\renderer_base $renderer): string {
/**
* Export this data so it can be used as the context for a mustache template (core/inplace_editable).
*
* @param renderer_base $output typically, the renderer that's calling this function
* @param \renderer_base $output typically, the renderer that's calling this function
* @return stdClass data context for a mustache template
*/
public function export_for_template(\renderer_base $output) {
Expand Down Expand Up @@ -123,7 +123,7 @@ public function export_for_template(\renderer_base $output) {
/**
* Export sections array data.
*
* @param renderer_base $output typically, the renderer that's calling this function
* @param \renderer_base $output typically, the renderer that's calling this function
* @return array data context for a mustache template
*/
protected function export_sections(\renderer_base $output): array {
Expand All @@ -132,18 +132,28 @@ protected function export_sections(\renderer_base $output): array {
$course = $format->get_course();
$modinfo = $this->format->get_modinfo();

$realcoursedisplay = property_exists($course, 'realcoursedisplay') ? $course->realcoursedisplay : false;
$firstsectionastab = ($realcoursedisplay == COURSE_DISPLAY_MULTIPAGE) ? 1 : 0;

// Generate section list.
$sections = [];
$stealthsections = [];
$numsections = $format->get_last_section_number();
foreach ($this->get_sections_to_display($modinfo) as $sectionnum => $thissection) {

foreach ($this->get_sections_to_display($modinfo) as $thissection) {

// 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) {
throw new \moodle_exception('unknowncoursesection', 'error', course_get_url($course), s($course->fullname));
}

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

if ($sectionnum === 0 && $firstsectionastab) {
continue;
}

if ($sectionnum > $numsections) {
// Activities inside this section are 'orphaned', this section will be printed as 'stealth' below.
Expand All @@ -159,9 +169,11 @@ protected function export_sections(\renderer_base $output): array {

$sections[] = $section->export_for_template($output);
}

if (!empty($stealthsections)) {
$sections = array_merge($sections, $stealthsections);
}

return $sections;
}

Expand Down
13 changes: 11 additions & 2 deletions classes/output/courseformat/content/section.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ class section extends section_base {
/**
* Export this data so it can be used as the context for a mustache template.
*
* @param renderer_base $output typically, the renderer that's calling this function
* @param \renderer_base $output typically, the renderer that's calling this function
* @return array data context for a mustache template
*/
public function export_for_template(\renderer_base $output): stdClass {
global $USER, $PAGE;
global $PAGE;

$format = $this->format;
$course = $format->get_course();
Expand Down Expand Up @@ -76,4 +76,13 @@ public function export_for_template(\renderer_base $output): stdClass {

return $data;
}

/**
* Get the section number.
*
* @return int
*/
public function get_section_number() {
return $this->section->section;
}
}
20 changes: 10 additions & 10 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,28 +186,25 @@ protected function __construct($format, $courseid) {
}

if ($course->realcoursedisplay == COURSE_DISPLAY_MULTIPAGE && $realsection === 0 && $numsections >= 1) {
$realsection = 1;
$realsection = null;
}

// Can view the hidden sections in current course?
$canviewhidden = has_capability('moodle/course:viewhiddensections', $context);

$modinfo = get_fast_modinfo($course);
$sections = $modinfo->get_section_info_all();

// Check if the display section is available.
if ((!$canviewhidden && (!$sections[$realsection]->uservisible || !$sections[$realsection]->available))) {
if ($realsection === null || !$sections[$realsection]->uservisible) {

self::$formatmsgs[] = get_string('hidden_message', 'format_onetopic', $this->get_section_name($realsection));
if ($realsection) {
self::$formatmsgs[] = get_string('hidden_message', 'format_onetopic', $this->get_section_name($realsection));
}

$valid = false;
$k = $course->realcoursedisplay ? 1 : 0;

do {
$formatoptions = $this->get_format_options($k);
if ($formatoptions['level'] == 0
&& ($sections[$k]->available && $sections[$k]->uservisible)
|| $canviewhidden) {
if ($formatoptions['level'] == 0 && $sections[$k]->uservisible) {
$valid = true;
break;
}
Expand All @@ -219,7 +216,10 @@ protected function __construct($format, $courseid) {
$realsection = $valid ? $k : 0;
}

$realsection = $realsection ?? 0;
// The $section var is a global var, we need to set it to the real section.
$section = $realsection;
$this->set_section_number($section);
$USER->display[$course->id] = $realsection;
$urlparams['section'] = $realsection;
$PAGE->set_url('/course/view.php', $urlparams);
Expand Down Expand Up @@ -989,7 +989,7 @@ public function fot_get_sections_extra() {
}

$course = $this->get_course();
$realcoursedisplay = property_exists($course, 'coursedisplay') ? $course->coursedisplay : false;
$realcoursedisplay = property_exists($course, 'realcoursedisplay') ? $course->realcoursedisplay : false;
$firstsection = ($realcoursedisplay == COURSE_DISPLAY_MULTIPAGE) ? 1 : 0;
$sections = $this->get_sections();
$parentsections = [];
Expand Down
2 changes: 2 additions & 0 deletions styles.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

define('NO_MOODLE_COOKIES', true);

// Require_login is not needed here.
// phpcs:disable moodle.Files.RequireLogin.Missing
require_once('../../../config.php');
Expand Down
4 changes: 2 additions & 2 deletions version.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@

defined('MOODLE_INTERNAL') || die();

$plugin->version = 2022081611; // The current plugin version (Date: YYYYMMDDXX).
$plugin->version = 2022081612; // The current plugin version (Date: YYYYMMDDXX).
$plugin->requires = 2022041902; // Requires this Moodle version.
$plugin->component = 'format_onetopic'; // Full name of the plugin (used for diagnostics).
$plugin->maturity = MATURITY_STABLE;
$plugin->release = '4.1.11(PiedrasTeherán)';
$plugin->release = '4.1.12(PiedrasTeherán)';
$plugin->dependencies = ['format_topics' => 2022041900];

0 comments on commit 276123c

Please sign in to comment.