Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 16 additions & 18 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,14 @@ jobs:
fail-fast: false
matrix:
include:
- php: '7.4'
moodle-branch: 'master'
database: 'pgsql'
- php: '7.4'
moodle-branch: 'MOODLE_311_STABLE'
database: 'mariadb'
- { php: '8.1', moodle-branch: MOODLE_404_STABLE, database: pgsql }
- { php: '8.2', moodle-branch: MOODLE_405_STABLE, database: mariadb }
- { php: '8.3', moodle-branch: MOODLE_500_STABLE, database: pgsql }
- { php: '8.3', moodle-branch: main, database: pgsql }

services:
postgres:
image: postgres
image: postgres:14
env:
POSTGRES_USER: 'postgres'
POSTGRES_HOST_AUTH_METHOD: 'trust'
Expand All @@ -30,7 +28,7 @@ jobs:
- 5432:5432

mariadb:
image: mariadb
image: mariadb:10
env:
MYSQL_USER: 'root'
MYSQL_ALLOW_EMPTY_PASSWORD: "true"
Expand All @@ -49,25 +47,25 @@ jobs:
with:
node-version: '14.15.0'

- name: Setup PHP
- name: Setup PHP ${{ matrix.php }}
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: mbstring, pgsql, mysqli
# tools: phpunit
# coverage: none
extensions: ${{ matrix.extensions }}
ini-values: max_input_vars=5000
coverage: none

- name: Deploy moodle-plugin-ci
- name: Initialise moodle-plugin-ci
run: |
composer create-project -n --no-dev --prefer-dist moodlehq/moodle-plugin-ci ci ^3
# Add dirs to $PATH
composer create-project -n --no-dev --prefer-dist moodlehq/moodle-plugin-ci ci ^4
echo $(cd ci/bin; pwd) >> $GITHUB_PATH
echo $(cd ci/vendor/bin; pwd) >> $GITHUB_PATH
# PHPUnit depends on en_AU.UTF-8 locale
sudo locale-gen en_AU.UTF-8
echo "NVM_DIR=$HOME/.nvm" >> $GITHUB_ENV

- name: Install Moodle
run: moodle-plugin-ci install --plugin ./plugin --db-host=127.0.0.1
- name: Install moodle-plugin-ci
run: |
moodle-plugin-ci install --plugin ./plugin --db-host=127.0.0.1
env:
DB: ${{ matrix.database }}
MOODLE_BRANCH: ${{ matrix.moodle-branch }}
Expand Down
14 changes: 9 additions & 5 deletions backup/moodle2/backup_qtype_oumultiresponse_plugin.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Backup plugin for the OU multiple response question type.
*
* @package qtype_oumultiresponse
* @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
Expand Down Expand Up @@ -47,18 +49,19 @@ protected function define_question_plugin_structure() {
$this->add_question_question_answers($pluginwrapper);

// Now create the qtype own structures.
$oumultiresponse = new backup_nested_element('oumultiresponse', array('id'), array(
$oumultiresponse = new backup_nested_element('oumultiresponse', ['id'], [
'shuffleanswers', 'correctfeedback', 'correctfeedbackformat',
'partiallycorrectfeedback', 'partiallycorrectfeedbackformat',
'incorrectfeedback', 'incorrectfeedbackformat', 'answernumbering',
'shownumcorrect', 'showstandardinstruction'));
'shownumcorrect', 'showstandardinstruction',
]);

// Now the own qtype tree.
$pluginwrapper->add_child($oumultiresponse);

// Set source to populate the data.
$oumultiresponse->set_source_table('question_oumultiresponse',
array('questionid' => backup::VAR_PARENTID));
['questionid' => backup::VAR_PARENTID]);

// Don't need to annotate ids nor files.

Expand All @@ -72,9 +75,10 @@ protected function define_question_plugin_structure() {
* files to be processed both in backup and restore.
*/
public static function get_qtype_fileareas() {
return array(
return [
'correctfeedback' => 'question_created',
'partiallycorrectfeedback' => 'question_created',
'incorrectfeedback' => 'question_created');
'incorrectfeedback' => 'question_created',
];
}
}
11 changes: 7 additions & 4 deletions backup/moodle2/restore_qtype_oumultiresponse_plugin.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Restore plugin class for the OU multiple response question type.
*
* @package qtype_oumultiresponse
* @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
Expand All @@ -34,7 +36,7 @@ class restore_qtype_oumultiresponse_plugin extends restore_qtype_plugin {
*/
protected function define_question_plugin_structure() {

$paths = array();
$paths = [];

// This qtype uses question_answers, add them.
$this->add_question_question_answers($paths);
Expand Down Expand Up @@ -74,6 +76,7 @@ public function process_oumultiresponse($data) {
}
}

#[\Override]
public function recode_response($questionid, $sequencenumber, array $response) {
if (array_key_exists('_order', $response)) {
$response['_order'] = $this->recode_choice_order($response['_order']);
Expand All @@ -87,7 +90,7 @@ public function recode_response($questionid, $sequencenumber, array $response) {
* @return string the recoded order.
*/
protected function recode_choice_order($order) {
$neworder = array();
$neworder = [];
foreach (explode(',', $order) as $id) {
if ($newid = $this->get_mappingid('question_answer', $id)) {
$neworder[] = $newid;
Expand All @@ -101,9 +104,9 @@ protected function recode_choice_order($order) {
*/
public static function define_decode_contents() {

$contents = array();
$contents = [];

$fields = array('correctfeedback', 'partiallycorrectfeedback', 'incorrectfeedback');
$fields = ['correctfeedback', 'partiallycorrectfeedback', 'incorrectfeedback'];
$contents[] = new restore_decode_content('question_oumultiresponse',
$fields, 'question_oumultiresponse');

Expand Down
10 changes: 10 additions & 0 deletions changes.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Change log for the OU Multi-response question type

## Changes in 2.5
* This version works with Moodle 5.0.
* Automation test failures are fixed.
* Cherry-picked commits since february 2024 till now:
* Update btn to "Save preview options and start again"
* Fix backup and restore tests to run synchronously M4.4
* Choice Tiny Editor disrupts the theme column layout on edit question page
* Add required for answer field when user not submit an answer
* Upgrade the CI to support Moodle 5.0 (PHP 8.3), and update the branch to support branch MOODLE_405_STABLE, and MOODLE_500_STABLE.

## Changes in 2.4

* This version works with Moodle 4.0.
Expand Down
7 changes: 5 additions & 2 deletions classes/output/mobile.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
*/
class mobile {

/**
* Returns the mobile output for the oumultiresponse question type.
*/
public static function oumr_view() {
global $CFG;
// General notes:
Expand All @@ -35,9 +38,9 @@ public static function oumr_view() {
return [
'templates' => [[
'id' => 'main',
'html' => file_get_contents($CFG->dirroot . '/question/type/oumultiresponse/mobile/oumr.html')
'html' => file_get_contents($CFG->dirroot . '/question/type/oumultiresponse/mobile/oumr.html'),
]],
'javascript' => file_get_contents($CFG->dirroot . '/question/type/oumultiresponse/mobile/oumr.js')
'javascript' => file_get_contents($CFG->dirroot . '/question/type/oumultiresponse/mobile/oumr.js'),
];
}
}
9 changes: 5 additions & 4 deletions classes/privacy/provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Privacy Subsystem implementation for qtype_oumultiresponse.
*
Expand All @@ -22,10 +23,10 @@
*/
namespace qtype_oumultiresponse\privacy;

use \core_privacy\local\metadata\collection;
use \core_privacy\local\request\transform;
use \core_privacy\local\request\user_preference_provider;
use \core_privacy\local\request\writer;
use core_privacy\local\metadata\collection;
use core_privacy\local\request\transform;
use core_privacy\local\request\user_preference_provider;
use core_privacy\local\request\writer;

/**
* Privacy Subsystem for qtype_oumultiresponse implementing user_preference_provider.
Expand Down
104 changes: 104 additions & 0 deletions classes/utils.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Utility functions for the oumultiresponse question type.
*
* @package qtype_oumultiresponse
* @copyright 2025 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

namespace qtype_oumultiresponse;

/**
* Class that holds utility functions used by the oumultiresponse question type.
*
* @package qtype_oumultiresponse
* @copyright 2025 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class utils {

/** @var string - Less than operator */
const OP_LT = "<";
/** @var string - equal operator */
const OP_E = "=";
/** @var string - greater than operator */
const OP_GT = ">";

/**
* Conveniently compare the current moodle version to a provided version in branch format. This function will
* inflate version numbers to a three digit number before comparing them. This way moodle minor versions greater
* than 9 can be correctly and easily compared.
*
* Examples:
* utils::moodle_version_is("<", "39");
* utils::moodle_version_is("<=", "310");
* utils::moodle_version_is(">", "39");
* utils::moodle_version_is(">=", "38");
* utils::moodle_version_is("=", "41");
*
* CFG reference:
* $CFG->branch = "311", "310", "39", "38", ...
* $CFG->release = "3.11+ (Build: 20210604)", ...
* $CFG->version = "2021051700.04", ...
*
* @param string $operator for the comparison
* @param string $version to compare to
* @return boolean
*/
public static function moodle_version_is(string $operator, string $version): bool {
global $CFG;

if (strlen($version) == 2) {
$version = $version[0]."0".$version[1];
}

$current = $CFG->branch;
if (strlen($current) == 2) {
$current = $current[0]."0".$current[1];
}

$from = intval($current);
$to = intval($version);
$ops = str_split($operator);

foreach ($ops as $op) {
switch ($op) {
case self::OP_LT:
if ($from < $to) {
return true;
}
break;
case self::OP_E:
if ($from == $to) {
return true;
}
break;
case self::OP_GT:
if ($from > $to) {
return true;
}
break;
default:
throw new \coding_exception('invalid operator '.$op);
}
}

return false;
}
}
Loading
Loading