-
Notifications
You must be signed in to change notification settings - Fork 23
Wip898002 #22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Wip898002 #22
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
9135f31
M4.3 Behat:Update btn to 'Save preview options and start again' #772704
AnupamaSarjoshi a47a12b
Behat: Fix backup and restore tests to run synchronously M4.4 #821458
AnupamaSarjoshi 82eedf5
Combined/multi response: Choice Tiny Editor disrupts the theme column…
96a8f2c
Combined: Add required for answer field when user not submit an answe…
0aa10e0
Fix CI file
38049c4
Fix PHPUnit
96d1ab0
Fix code checker issue
ef0e18f
Upgrade version and documentation
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.