Skip to content

Commit

Permalink
Merge pull request #220 from lucaboesch/fixci
Browse files Browse the repository at this point in the history
Fix Moodle Plugin CI integration.
  • Loading branch information
hgeorgsch committed May 11, 2023
2 parents 8b248f4 + f506db6 commit 42710f6
Show file tree
Hide file tree
Showing 42 changed files with 168 additions and 146 deletions.
75 changes: 29 additions & 46 deletions .github/workflows/moodle-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,54 +8,42 @@ jobs:
fail-fast: false
matrix:
include:
- php: '7.4'
moodle-branch: 'MOODLE_310_STABLE'
- php: '8.1'
moodle-branch: 'MOODLE_402_STABLE'
database: 'mariadb'
node: '14.15.0'
- php: '7.3'
moodle-branch: 'MOODLE_310_STABLE'
- php: '8.1'
moodle-branch: 'MOODLE_402_STABLE'
database: 'mariadb'
node: '14.15.0'
- php: '7.2'
moodle-branch: 'MOODLE_310_STABLE'
- php: '8.0'
moodle-branch: 'MOODLE_402_STABLE'
database: 'mariadb'
- php: '8.0'
moodle-branch: 'MOODLE_402_STABLE'
database: 'mariadb'
- php: '8.1'
moodle-branch: 'MOODLE_401_STABLE'
database: 'mariadb'
- php: '8.1'
moodle-branch: 'MOODLE_401_STABLE'
database: 'mariadb'
- php: '8.0'
moodle-branch: 'MOODLE_401_STABLE'
database: 'mariadb'
- php: '8.0'
moodle-branch: 'MOODLE_401_STABLE'
database: 'mariadb'
node: '14.15.0'
- php: '7.4'
moodle-branch: 'MOODLE_310_STABLE'
database: 'pgsql'
node: '14.15.0'
- php: '7.3'
moodle-branch: 'MOODLE_310_STABLE'
database: 'pgsql'
node: '14.15.0'
- php: '7.2'
moodle-branch: 'MOODLE_310_STABLE'
database: 'pgsql'
node: '14.15.0'
- php: '7.4'
moodle-branch: 'MOODLE_39_STABLE'
moodle-branch: 'MOODLE_401_STABLE'
database: 'mariadb'
node: '14.15.0'
- php: '7.3'
moodle-branch: 'MOODLE_39_STABLE'
- php: '7.4'
moodle-branch: 'MOODLE_401_STABLE'
database: 'mariadb'
node: '14.15.0'
- php: '7.2'
moodle-branch: 'MOODLE_39_STABLE'
- php: '7.4'
moodle-branch: 'MOODLE_400_STABLE'
database: 'mariadb'
node: '14.15.0'
- php: '7.4'
moodle-branch: 'MOODLE_39_STABLE'
database: 'pgsql'
node: '14.15.0'
- php: '7.3'
moodle-branch: 'MOODLE_39_STABLE'
database: 'pgsql'
node: '14.15.0'
- php: '7.2'
moodle-branch: 'MOODLE_39_STABLE'
database: 'pgsql'
node: '14.15.0'
moodle-branch: 'MOODLE_400_STABLE'
database: 'mariadb'

services:
postgres:
Expand All @@ -82,15 +70,10 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
path: plugin

- name: Install node
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node }}

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
Expand Down
2 changes: 0 additions & 2 deletions backup/moodle2/backup_capquiz_stepslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

// REDUNDANT: defined('MOODLE_INTERNAL') || die();

/**
* Define the complete choice structure for backup, with file and id annotations.
*
Expand Down
2 changes: 0 additions & 2 deletions backup/moodle2/restore_capquiz_stepslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

// REDUNDANT: defined('MOODLE_INTERNAL') || die();

/**
* Structure step to restore one assignment activity
*
Expand Down
19 changes: 17 additions & 2 deletions classes/bank/add_action_column.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
*
* This class is copied to CAPQuiz from the Core Quiz, without
* modification (as of Fri 9 Sep 08:29:48 UTC 2022 ).
*
* @package mod_capquiz/mod_quiz
*
* @package mod_capquiz
* @category question
* @copyright 2009 Tim Hunt
* @author 2021 Safat Shahin <[email protected]>
Expand All @@ -33,15 +33,30 @@ class add_action_column extends \core_question\local\bank\action_column_base {
/** @var string caches a lang string used repeatedly. */
protected $stradd;

/**
* A chance for subclasses to initialise themselves, for example to load lang strings,
* without having to override the constructor.
*/
public function init(): void {
parent::init();
$this->stradd = get_string('addtoquiz', 'quiz');
}

/**
* Get the internal name for this column. Used as a CSS class name,
* and to store information about the current sort. Must match PARAM_ALPHA.
*
* @return string column name.
*/
public function get_name() {
return 'addtoquizaction';
}

/**
* Output the contents of this column.
* @param object $question the row from the $question table, augmented with extra information.
* @param string $rowclasses CSS class names that should be applied to this row of output.
*/
protected function display_content($question, $rowclasses) {
if (!question_has_capability_on($question, 'use')) {
return;
Expand Down
20 changes: 15 additions & 5 deletions classes/bank/question_bank_view.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@
use mod_capquiz\local\capquiz_urls;
use mod_capquiz\bank\add_action_column;

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

/**
* Class question_bank_view
*
Expand All @@ -58,13 +56,20 @@ class question_bank_view extends \core_question\local\bank\view {
/**
* URL of add to quiz.
*
* @param $questionid
* @param int $questionid the question id
* @return \moodle_url
* @throws \coding_exception
* @throws \moodle_exception
*/
public function add_to_quiz_url($questionid) {
return \mod_capquiz\capquiz_urls::add_question_to_list_url( $questionid ) ;
return \mod_capquiz\capquiz_urls::add_question_to_list_url($questionid);
}


/**
* Get the list of qbank plugins with available objects for features.
*
* @return array
*/
protected function get_question_bank_plugins(): array {
$questionbankclasscolumns = [];
$corequestionbankcolumns = [
Expand Down Expand Up @@ -129,6 +134,11 @@ protected function get_question_bank_plugins(): array {
return $questionbankclasscolumns;
}

/**
* Specify the column heading
*
* @return string Column name for the heading
*/
protected function heading_column(): string {
return 'mod_capquiz\\bank\\question_name_text_column';
}
Expand Down
45 changes: 43 additions & 2 deletions classes/bank/question_name_column.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
*
* This class is copied to CAPQuiz from the Core Quiz, without
* modification (as of Fri 9 Sep 08:29:48 UTC 2022 ).
*
* @package mod_capquiz/mod_quiz
*
* @package mod_capquiz
* @category question
* @copyright 2009 Tim Hunt
* @author 2021 Safat Shahin <[email protected]>
Expand All @@ -37,14 +37,31 @@ class question_name_column extends \core_question\local\bank\column_base {
*/
protected $checkboxespresent = null;

/**
* Get the internal name for this column. Used as a CSS class name,
* and to store information about the current sort. Must match PARAM_ALPHA.
*
* @return string column name.
*/
public function get_name(): string {
return 'questionname';
}

/**
* Title for this column. Not used if is_sortable returns an array.
*
* @return string column title.
*/
public function get_title(): string {
return get_string('question');
}

/**
* Lable for this column.
*
* @param object $question the row from the $question table, augmented with extra information.
* @return string column label.
*/
protected function label_for($question): string {
if (is_null($this->checkboxespresent)) {
$this->checkboxespresent = $this->qbank->has_column('core_question\local\bank\checkbox_column');
Expand All @@ -56,6 +73,11 @@ protected function label_for($question): string {
}
}

/**
* Output the contents of this column.
* @param object $question the row from the $question table, augmented with extra information.
* @param string $rowclasses CSS class names that should be applied to this row of output.
*/
protected function display_content($question, $rowclasses): void {
$labelfor = $this->label_for($question);
if ($labelfor) {
Expand All @@ -67,10 +89,29 @@ protected function display_content($question, $rowclasses): void {
}
}

/**
* Use table alias 'q' for the question table, or one of the
* ones from get_extra_joins. Every field requested must specify a table prefix.
*
* @return array fields required.
*/
public function get_required_fields(): array {
return ['q.id', 'q.name'];
}

/**
* Can this column be sorted on? You can return either:
* + false for no (the default),
* + a field name, if sorting this column corresponds to sorting on that datbase field.
* + an array of subnames to sort on as follows
* return [
* 'firstname' => ['field' => 'uc.firstname', 'title' => get_string('firstname')],
* 'lastname' => ['field' => 'uc.lastname', 'title' => get_string('lastname')],
* ];
* As well as field, and field, you can also add 'revers' => 1 if you want the default sort
* order to be DESC.
* @return mixed as above.
*/
public function is_sortable() {
return 'q.name';
}
Expand Down
37 changes: 32 additions & 5 deletions classes/bank/question_name_text_column.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
/**
* A column type for the name followed by the start of the question text.
*
* This class is copied to CAPQuiz from the Core Quiz, with the addition of
* This class is copied to CAPQuiz from the Core Quiz, with the addition of
* the `quiz_question_tostring` method copied from Core Quiz' locallib.
*
*
* @package mod_capquiz
* @package mod_capquiz
* @category question
Expand All @@ -34,6 +34,12 @@
*/
class question_name_text_column extends question_name_column {

/**
* Get the internal name for this column. Used as a CSS class name,
* and to store information about the current sort. Must match PARAM_ALPHA.
*
* @return string column name.
*/
public function get_name(): string {
return 'questionnametext';
}
Expand Down Expand Up @@ -69,7 +75,7 @@ protected function quiz_question_tostring($question, $showicon = false, $showque
html_writer::span(get_string('idnumber', 'question'), 'accesshide') .
' ' . s($question->idnumber), 'badge badge-primary');
}

// Question tags.
if (is_array($showtags)) {
$tags = $showtags;
Expand All @@ -81,7 +87,7 @@ protected function quiz_question_tostring($question, $showicon = false, $showque
if ($tags) {
$result .= $OUTPUT->tag_list($tags, null, 'd-inline', 0, null, true);
}

// Question text.
if ($showquestiontext) {
$questiontext = \question_utils::to_plain_text($question->questiontext,
Expand All @@ -91,9 +97,15 @@ protected function quiz_question_tostring($question, $showicon = false, $showque
$result .= ' ' . html_writer::span(s($questiontext), 'questiontext');
}
}

return $result;
}

/**
* Output the contents of this column.
* @param object $question the row from the $question table, augmented with extra information.
* @param string $rowclasses CSS class names that should be applied to this row of output.
*/
protected function display_content($question, $rowclasses): void {
echo \html_writer::start_tag('div');
$labelfor = $this->label_for($question);
Expand All @@ -107,6 +119,12 @@ protected function display_content($question, $rowclasses): void {
echo \html_writer::end_tag('div');
}

/**
* Use table alias 'q' for the question table, or one of the
* ones from get_extra_joins. Every field requested must specify a table prefix.
*
* @return array fields required.
*/
public function get_required_fields(): array {
$fields = parent::get_required_fields();
$fields[] = 'q.questiontext';
Expand All @@ -115,6 +133,15 @@ public function get_required_fields(): array {
return $fields;
}

/**
* If this column needs extra data (e.g. tags) then load that here.
*
* The extra data should be added to the question object in the array.
* Probably a good idea to check that another column has not already
* loaded the data you want.
*
* @param \stdClass[] $questions the questions that will be displayed.
*/
public function load_additional_data(array $questions) {
parent::load_additional_data($questions);
parent::load_question_tags($questions);
Expand Down
2 changes: 0 additions & 2 deletions classes/capquiz_matchmaking_strategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@

namespace mod_capquiz;

// REDUNDANT: defined('MOODLE_INTERNAL') || die();

/**
* Class capquiz_matchmaking_strategy
*
Expand Down
Loading

0 comments on commit 42710f6

Please sign in to comment.