Skip to content

Commit

Permalink
Addressing GHA issues #1
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthias Opitz committed Nov 16, 2022
1 parent ea54ba4 commit 02dd3ef
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 42 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/moodle-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ jobs:
if: ${{ always() }}
run: moodle-plugin-ci grunt --max-lint-warnings 6

- name: PHPUnit tests
if: ${{ always() }}
run: moodle-plugin-ci phpunit --fail-on-warning

- name: Behat features
if: ${{ always() }}
run: moodle-plugin-ci behat --profile chrome
45 changes: 20 additions & 25 deletions classes/output/courseformat/content.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,14 @@
use core_courseformat\base as base;
use core_courseformat\output\local\content as content_base;

/**
* The content class.
*
* @package format_topics2
* @copyright 2022, Matthias Opitz <opitz@gmx.de>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class content extends content_base {

/**
* Returns the output class template path.
*
Expand All @@ -51,27 +57,12 @@ public function export_for_template(\renderer_base $output) {
return $data;
}

public function get_tabs0() {
global $COURSE;

$format = $this->format;
// $foptions = $this->get_format_options();
$formatoptions = $this->get_formatoptions($COURSE->id);
$tabs = [];
$maxtabs = 5;

for ($i = 0; $i < $maxtabs; $i++) {
$tab = new \stdClass();
$tab->tabno = $i + 1;
$tab->id = 'tab_' . $tab->tabno;
$tab->title = 'Tab ' . $tab->tabno;
$tab->sections = '';

$tabs[] = $tab;
}

return $tabs;
}
/**
* Get the tabs.
*
* @return array
* @throws \coding_exception
*/
public function get_tabs() {

$format = $this->format;
Expand Down Expand Up @@ -117,15 +108,19 @@ public function get_tabs() {
$formatoptions['tab' . $i . '_title'] != '' ? $formatoptions['tab' . $i . '_title'] : $tab->generic_title);
$tab->sections = $tabsections;
$tab->section_nums = $tabsectionnums;
// $tabs[$tab->id] = $tab;
$tabs[] = $tab;
}
}
// $this->tabs = $tabs;

return $tabs;
}

/**
* Get the format options for a course.
*
* @param int $courseid
* @return array
* @throws \dml_exception
*/
public function get_formatoptions($courseid) {
global $DB;
$options = $DB->get_records('course_format_options', array('courseid' => $courseid));
Expand Down
12 changes: 11 additions & 1 deletion classes/output/courseformat/content/section.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,24 @@

use core_courseformat\output\local\content\section as section_base;

/**
* The section class.
*
* @package format_topics2
* @copyright 2022, Matthias Opitz <opitz@gmx.de>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class section extends section_base {

/**
* Returns the output class template path.
*
* This method redirects the default template when the course section is rendered.
*
* @param \renderer_base $renderer
* @return string
*/
public function get_template_name(\renderer_base $renderer): string {
return 'format_topics2/local/content/section';
}
}
}
12 changes: 11 additions & 1 deletion classes/output/courseformat/content/section/cmitem.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,24 @@

use core_courseformat\output\local\content\section\cmitem as cmitem_base;

/**
* The content module item class.
*
* @package format_topics2
* @copyright 2022, Matthias Opitz <opitz@gmx.de>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class cmitem extends cmitem_base {

/**
* Returns the output class template path.
*
* This method redirects the default template when the section activity item is rendered.
*
* @param \renderer_base $renderer
* @return string
*/
public function get_template_name(\renderer_base $renderer): string {
return 'format_topics2/local/content/section/cmitem';
}
}
}
38 changes: 25 additions & 13 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,19 @@
* Class format_topics2
*
* @package format_topics2
* @copyright 2020 Matthias Opitz
* @copyright 2018-22 Matthias Opitz
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

defined('MOODLE_INTERNAL') || die();
defined('COURSE_DISPLAY_COLLAPSE') || define('COURSE_DISPLAY_COLLAPSE', 2); // Legacy support - no longer used.
defined('COURSE_DISPLAY_NOCOLLAPSE') || define('COURSE_DISPLAY_NOCOLLAPSE', 3);
//require_once($CFG->dirroot. '/course/format/topics/lib.php');

/**
* Main class for the topics2 course format with added tab-ability
*
* @package format_topics2
* @copyright 2018 Matthias Opitz
* @copyright 2018-22 Matthias Opitz
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class format_topics2 extends core_courseformat\base {
Expand All @@ -45,10 +44,20 @@ public function uses_sections(): bool {
return true;
}

/**
* Uses course index
*
* @return bool
*/
public function uses_course_index(): bool {
return true;
}

/**
* Uses indentation.
*
* @return bool
*/
public function uses_indentation(): bool {
return false;
}
Expand Down Expand Up @@ -83,9 +92,8 @@ public function get_section_name($section) {
*/
public function get_default_section_name($section) {
if ($section->section == 0) {
// Return the general section with no title.
// return get_string('section0name', 'format_topics');
return "";
// Return the general section.
return get_string('section0name', 'format_topics');
} else {
// Use course_format::get_default_section_name implementation which
// will display the section name in "Topic n" format.
Expand Down Expand Up @@ -163,6 +171,11 @@ public function supports_ajax() {
return $ajaxsupport;
}

/**
* Supporting components.
*
* @return bool
*/
public function supports_components() {
return true;
}
Expand Down Expand Up @@ -277,7 +290,7 @@ public function course_format_options($foreditform = false) {
'type' => PARAM_INT,
],
];
// The topic tabs
// The topic tabs.
for ($i = 0; $i < $maxtabs; $i++) {
$courseformatoptions['tab'.$i.'_title'] = array(
'type' => PARAM_TEXT,
Expand Down Expand Up @@ -367,7 +380,6 @@ public function course_format_options($foreditform = false) {
'element_type' => 'advcheckbox',
);


// Now add the tabs but don't show them as we only need the DB records...
$courseformatoptions['tab0_title'] = array(
'default' => get_string('tabzero_title',
Expand Down Expand Up @@ -438,11 +450,11 @@ public function create_edit_form_elements(&$mform, $forsection = false) {
/**
* Updates format options for a course.
*
* In case if course format was changed to 'topics2', we try to copy options
* In case the course format was changed to 'topics2', we try to copy options
* 'coursedisplay' and 'hiddensections' from the previous format.
*
* @param stdClass|array $data return value from {@link moodleform::get_data()} or array with data
* @param stdClass $oldcourse if this function is called from {@link update_course()}
* @param stdClass|array $data return value from moodleform::get_data() or array with data
* @param stdClass $oldcourse if this function is called from update_course()
* this object contains information about the course before update
* @return bool whether there were any changes to the options values
*/
Expand All @@ -465,9 +477,9 @@ public function update_course_format_options($data, $oldcourse = null) {
/**
* Whether this format allows to delete sections.
*
* Do not call this function directly, instead use {@link course_can_delete_section()}
* Do not call this function directly, instead use course_can_delete_section()
*
* @param int|stdClass|section_info $section
* @param stdClass $section
* @return bool
*/
public function can_delete_section($section) {
Expand Down
2 changes: 0 additions & 2 deletions renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,3 @@
* @copyright 2022 Matthias Opitz <opitz@gmx.de>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

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

0 comments on commit 02dd3ef

Please sign in to comment.