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

Migrate legacy libphp callbacks to hooks #136

Merged
merged 11 commits into from
Aug 7, 2024
13 changes: 4 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Moodle Plugin CI
# Based on version gha.dist.yml version 4.1.2
# Based on version gha.dist.yml version 4.5.2

on:
push:
Expand Down Expand Up @@ -37,13 +37,13 @@ jobs:
strategy:
fail-fast: false
matrix:
php: ['8.0', '8.1', '8.2']
moodle-branch: ['MOODLE_403_STABLE']
php: ['8.1', '8.2']
moodle-branch: ['MOODLE_404_STABLE']
database: [pgsql, mariadb]

steps:
- name: Check out repository code
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
path: plugin

Expand Down Expand Up @@ -77,11 +77,6 @@ jobs:
if: ${{ !cancelled() }}
run: moodle-plugin-ci phplint

- name: PHP Copy/Paste Detector
continue-on-error: true # This step will show errors but will not fail
if: ${{ !cancelled() }}
run: moodle-plugin-ci phpcpd

# For now, assume this succeeds.
- name: PHP Mess Detector
continue-on-error: true # This step will show errors but will not fail
Expand Down
76 changes: 76 additions & 0 deletions classes/form/changepassword_form.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php
// This file is part of Moodle - https://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/>.

/**
* MoodleBox change password form definition.
*
* @package tool_moodlebox
* @copyright 2018 onwards Nicolas Martignoni {@link mailto:[email protected]}
* @copyright 2024 onwards Patrick Lemaire
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

namespace tool_moodlebox\form;
use moodleform;
defined('MOODLE_INTERNAL') || die();
require_once($CFG->libdir . '/formslib.php');

/**
* Class changepassword_form
*
* Form class to change MoodleBox password.
*
* @package tool_moodlebox
* @copyright 2016 onwards Nicolas Martignoni {@link mailto:[email protected]}
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class changepassword_form extends moodleform {

/**
* Define the form.
*/
public function definition() {
$mform = $this->_form;

$mform->addElement('passwordunmask', 'newpassword1', get_string('newpassword'));
$mform->addRule('newpassword1', get_string('required'), 'required', null, 'client');
$mform->setType('newpassword1', PARAM_RAW_TRIMMED);

$mform->addElement('passwordunmask', 'newpassword2', get_string('newpassword').' ('.get_string('again').')');
$mform->addRule('newpassword2', get_string('required'), 'required', null, 'client');
$mform->setType('newpassword2', PARAM_RAW_TRIMMED);

$this->add_action_buttons(false, get_string('changepassword'));
}

/**
* Validate the form.
*
* @param array $data submitted data
* @param array $files not used
* @return array errors
*/
public function validation($data, $files) {
$errors = parent::validation($data, $files);

if ($data['newpassword1'] <> $data['newpassword2']) {
$errors['newpassword1'] = get_string('passwordsdiffer');
$errors['newpassword2'] = get_string('passwordsdiffer');
}

return $errors;
}
}
59 changes: 59 additions & 0 deletions classes/form/datetimeset_form.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php
// This file is part of Moodle - https://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/>.

/**
* MoodleBox set time and date form definition.
*
* @package tool_moodlebox
* @copyright 2018 onwards Nicolas Martignoni {@link mailto:[email protected]}
* @copyright 2024 onwards Patrick Lemaire
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

namespace tool_moodlebox\form;
use moodleform;
defined('MOODLE_INTERNAL') || die();
require_once($CFG->libdir . '/formslib.php');

/**
* Class datetimeset_form
*
* Form class to set time and date.
*
* @package tool_moodlebox
* @copyright 2016 onwards Nicolas Martignoni {@link mailto:[email protected]}
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class datetimeset_form extends moodleform {

/**
* Define the form.
*/
public function definition() {
$mform = $this->_form;
$mform->addElement('date_time_selector', 'currentdatetime', get_string('datetime', 'tool_moodlebox'),
[
'startyear' => date("Y") - 2,
'stopyear' => date("Y") + 2,
'timezone' => 99,
'step' => 1,
'optional' => true,
]);
$mform->addHelpButton('currentdatetime', 'datetime', 'tool_moodlebox');

$this->add_action_buttons(false, get_string('datetimeset', 'tool_moodlebox'));
}
}
53 changes: 53 additions & 0 deletions classes/form/resizepartition_form.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php
// This file is part of Moodle - https://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/>.

/**
* MoodleBox resize partition form definition.
*
* @package tool_moodlebox
* @copyright 2018 onwards Nicolas Martignoni {@link mailto:[email protected]}
* @copyright 2024 onwards Patrick Lemaire
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

namespace tool_moodlebox\form;
use moodleform;
defined('MOODLE_INTERNAL') || die();
require_once($CFG->libdir . '/formslib.php');

/**
* Class resizepartition_form
*
* Form class to resize the partition of the MoodleBox.
*
* @package tool_moodlebox
* @copyright 2018 onwards Nicolas Martignoni {@link mailto:[email protected]}
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class resizepartition_form extends moodleform {

/**
* Define the form.
*/
public function definition() {
$mform = $this->_form;
$buttonarray = [];
$buttonarray[] = & $mform->createElement('submit', 'resizepartitionbutton',
get_string('resizepartition', 'tool_moodlebox'));
$mform->addGroup($buttonarray, 'buttonar', '', [' '], false);
$mform->closeHeaderBefore('buttonar');
}
}
55 changes: 55 additions & 0 deletions classes/form/restartshutdown_form.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php
// This file is part of Moodle - https://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/>.

/**
* MoodleBox restart and shutdown password form definition.
*
* @package tool_moodlebox
* @copyright 2018 onwards Nicolas Martignoni {@link mailto:[email protected]}
* @copyright 2024 onwards Patrick Lemaire
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

namespace tool_moodlebox\form;
use moodleform;
defined('MOODLE_INTERNAL') || die();
require_once($CFG->libdir . '/formslib.php');

/**
* Class restartshutdown_form
*
* Form class to restart and shutdown the MoodleBox.
*
* @package tool_moodlebox
* @copyright 2016 onwards Nicolas Martignoni {@link mailto:[email protected]}
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class restartshutdown_form extends moodleform {

/**
* Define the form.
*/
public function definition() {
$mform = $this->_form;
$buttonarray = [];
$buttonarray[] = & $mform->createElement('submit', 'restartbutton',
get_string('restart', 'tool_moodlebox'));
$buttonarray[] = & $mform->createElement('submit', 'shutdownbutton',
get_string('shutdown', 'tool_moodlebox'));
$mform->addGroup($buttonarray, 'buttonar', '', [' '], false);
$mform->closeHeaderBefore('buttonar');
}
}
Loading