Skip to content
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

improve version list generation #509

Merged
merged 1 commit into from
Jan 14, 2025
Merged
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
18 changes: 15 additions & 3 deletions includes/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,26 @@ function moosh_moodle_version($topdir, $default = 23) {
}

function moosh_generate_version_list($upto, $from = 19) {
// This function assumes that moodle main version is below 10 and subversions are below or equal to 20.

$upto = intval($upto);
$from = intval($from);
if (!($from && $upto) || $from > $upto) {
throw new Exception("Invalid from or upto value; they must both be > 0 and from must be <= upto");
}

$frommain = (int)(substr($from, 0, 1));
$fromsub = (int)(substr($from, 1));
$uptomain = (int)(substr($upto, 0, 1));
$uptosub = (int)(substr($upto, 1));

$versions = array();
foreach (range($from, $upto) as $no) {
$versions[] = 'Moodle' . $no;
foreach (range($frommain, $uptomain) as $nom) {
$frsub = ($nom == $frommain) ? $fromsub : 0;
$tosub = ($nom == $uptomain) ? $uptosub : 20;
foreach(range($frsub, $tosub) as $nos) {
$versions[] = 'Moodle' . $nom . $nos;
}
}
return $versions;
}
Expand Down Expand Up @@ -552,4 +564,4 @@ function string_ends_with($haystack, $needle) {
return true;
}
return substr( $haystack, -$length ) === $needle;
}
}
Loading