diff --git a/badges/alignment.php b/badges/alignment.php
index cfd4a460fa8..425bc372c90 100644
--- a/badges/alignment.php
+++ b/badges/alignment.php
@@ -13,18 +13,21 @@
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
+
/**
* List alignments, skills, or standards are targeted by a BadgeClass.
*
- * @package core
+ * @package core_badges
* @subpackage badges
* @copyright 2018 Tung Thai
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @author Tung Thai
*/
+
+use core_badges\form\alignment;
+
require_once(__DIR__ . '/../config.php');
require_once($CFG->libdir . '/badgeslib.php');
-require_once($CFG->dirroot . '/badges/alignment_form.php');
$badgeid = required_param('id', PARAM_INT);
$alignmentid = optional_param('alignmentid', 0, PARAM_INT);
@@ -37,7 +40,7 @@ if (empty($CFG->enablebadges)) {
}
$badge = new badge($badgeid);
$context = $badge->get_context();
-$navurl = new moodle_url('/badges/index.php', array('type' => $badge->type));
+$navurl = new moodle_url('/badges/index.php', ['type' => $badge->type]);
require_capability('moodle/badges:configuredetails', $context);
if ($badge->type == BADGE_TYPE_COURSE) {
@@ -47,7 +50,7 @@ if ($badge->type == BADGE_TYPE_COURSE) {
require_login($badge->courseid);
$course = get_course($badge->courseid);
$heading = format_string($course->fullname, true, ['context' => $context]);
- $navurl = new moodle_url('/badges/index.php', array('type' => $badge->type, 'id' => $badge->courseid));
+ $navurl = new moodle_url('/badges/index.php', ['type' => $badge->type, 'id' => $badge->courseid]);
$PAGE->set_pagelayout('standard');
navigation_node::override_active_url($navurl);
} else {
@@ -56,7 +59,7 @@ if ($badge->type == BADGE_TYPE_COURSE) {
navigation_node::override_active_url($navurl, true);
}
-$currenturl = new moodle_url('/badges/alignment.php', array('id' => $badge->id));
+$currenturl = new moodle_url('/badges/alignment.php', ['id' => $badge->id]);
$PAGE->set_context($context);
$PAGE->set_url($currenturl);
$PAGE->set_heading($heading);
@@ -66,8 +69,8 @@ $PAGE->navbar->add($badge->name);
$output = $PAGE->get_renderer('core', 'badges');
$msg = optional_param('msg', '', PARAM_TEXT);
$emsg = optional_param('emsg', '', PARAM_TEXT);
-$url = new moodle_url('/badges/alignment.php', array('id' => $badge->id, 'action' => $action, 'alignmentid' => $alignmentid));
-$mform = new alignment_form($url, array('badge' => $badge, 'action' => $action, 'alignmentid' => $alignmentid));
+$url = new moodle_url('/badges/alignment.php', ['id' => $badge->id, 'action' => $action, 'alignmentid' => $alignmentid]);
+$mform = new alignment($url, ['badge' => $badge, 'action' => $action, 'alignmentid' => $alignmentid]);
if ($mform->is_cancelled()) {
redirect($currenturl);
} else if ($mform->is_submitted() && $mform->is_validated() && ($data = $mform->get_data())) {
@@ -98,7 +101,7 @@ if ($alignmentid || $action == 'add' || $action == 'edit') {
$mform->display();
} else if (empty($action)) {
if (!$badge->is_active() && !$badge->is_locked()) {
- $urlbutton = new moodle_url('/badges/alignment.php', array('id' => $badge->id, 'action' => 'add'));
+ $urlbutton = new moodle_url('/badges/alignment.php', ['id' => $badge->id, 'action' => 'add']);
echo $OUTPUT->box($OUTPUT->single_button($urlbutton, get_string('addalignment', 'badges')), 'clearfix mdl-align');
}
$alignments = $badge->get_alignments();
diff --git a/badges/alignment_form.php b/badges/classes/form/alignment.php
similarity index 84%
rename from badges/alignment_form.php
rename to badges/classes/form/alignment.php
index 9de0bf77fc1..e70149f62d7 100644
--- a/badges/alignment_form.php
+++ b/badges/classes/form/alignment.php
@@ -13,15 +13,11 @@
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * Form alignment for editing.
- *
- * @package core
- * @subpackage badges
- * @copyright 2018 Tung Thai
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- * @author Tung Thai
- */
+
+namespace core_badges\form;
+use moodleform;
+use stdClass;
+
defined('MOODLE_INTERNAL') || die();
require_once($CFG->libdir . '/formslib.php');
require_once($CFG->libdir . '/badgeslib.php');
@@ -29,12 +25,12 @@ require_once($CFG->libdir . '/badgeslib.php');
/**
* Form to edit alignment.
*
+ * @package core_badges
* @copyright 2018 Tung Thai
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @author Tung Thai
*/
-class alignment_form extends moodleform {
-
+class alignment extends moodleform {
/**
* Defines the form.
*/
@@ -45,21 +41,21 @@ class alignment_form extends moodleform {
$action = $this->_customdata['action'];
$alignmentid = $this->_customdata['alignmentid'];
$mform->addElement('header', 'alignment', get_string('alignment', 'badges'));
- $mform->addElement('text', 'targetname', get_string('targetname', 'badges'), array('size' => '70'));
+ $mform->addElement('text', 'targetname', get_string('targetname', 'badges'), ['size' => '70']);
$mform->setType('targetname', PARAM_TEXT);
$mform->addRule('targetname', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
$mform->addRule('targetname', null, 'required');
$mform->addHelpButton('targetname', 'targetname', 'badges');
- $mform->addElement('text', 'targeturl', get_string('targeturl', 'badges'), array('size' => '70'));
+ $mform->addElement('text', 'targeturl', get_string('targeturl', 'badges'), ['size' => '70']);
$mform->setType('targeturl', PARAM_URL);
$mform->addRule('targeturl', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
$mform->addRule('targeturl', null, 'required');
$mform->addHelpButton('targeturl', 'targeturl', 'badges');
- $mform->addElement('text', 'targetframework', get_string('targetframework', 'badges'), array('size' => '70'));
+ $mform->addElement('text', 'targetframework', get_string('targetframework', 'badges'), ['size' => '70']);
$mform->setType('targetframework', PARAM_TEXT);
$mform->addRule('targetframework', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
$mform->addHelpButton('targetframework', 'targetframework', 'badges');
- $mform->addElement('text', 'targetcode', get_string('targetcode', 'badges'), array('size' => '70'));
+ $mform->addElement('text', 'targetcode', get_string('targetcode', 'badges'), ['size' => '70']);
$mform->setType('targetcode', PARAM_TEXT);
$mform->addRule('targetcode', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
$mform->addHelpButton('targetcode', 'targetcode', 'badges');
@@ -68,11 +64,11 @@ class alignment_form extends moodleform {
$this->add_action_buttons();
if ($action == 'edit' || $alignmentid) {
$alignment = new stdClass();
- $alignment = $DB->get_record_select('badge_alignment', 'id = ?', array($alignmentid));
+ $alignment = $DB->get_record_select('badge_alignment', 'id = ?', [$alignmentid]);
$this->set_data($alignment);
// Freeze all elements if badge is active or locked.
if ($badge->is_active() || $badge->is_locked()) {
- $mform->hardFreezeAllVisibleExcept(array());
+ $mform->hardFreezeAllVisibleExcept([]);
}
}
}
@@ -80,8 +76,8 @@ class alignment_form extends moodleform {
/**
* Validate the data from the form.
*
- * @param array $data form data
- * @param array $files form files
+ * @param array $data form data
+ * @param array $files form files
* @return array An array of error messages.
*/
public function validation($data, $files) {
diff --git a/badges/endorsement_form.php b/badges/classes/form/endorsement.php
similarity index 86%
rename from badges/endorsement_form.php
rename to badges/classes/form/endorsement.php
index 532420dd2fa..2852ac34559 100644
--- a/badges/endorsement_form.php
+++ b/badges/classes/form/endorsement.php
@@ -13,26 +13,25 @@
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * Form endorsement for editing.
- *
- * @package core
- * @subpackage badges
- * @copyright 2018 Tung Thai
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- * @author Tung Thai
- */
+
+namespace core_badges\form;
+
+use moodleform;
+use stdClass;
+
defined('MOODLE_INTERNAL') || die();
require_once($CFG->libdir . '/formslib.php');
require_once($CFG->libdir . '/badgeslib.php');
+
/**
- * Form to edit endorsement.
+ * Form endorsement for editing.
*
+ * @package core_badges
* @copyright 2018 Tung Thai
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @author Tung Thai
*/
-class endorsement_form extends moodleform {
+class endorsement extends moodleform {
/**
* Defines the form.
@@ -41,22 +40,22 @@ class endorsement_form extends moodleform {
$mform = $this->_form;
$badge = $this->_customdata['badge'];
$mform->addElement('header', 'endorsement', get_string('issuerdetails', 'badges'));
- $mform->addElement('text', 'issuername', get_string('issuername_endorsement', 'badges'), array('size' => '70'));
+ $mform->addElement('text', 'issuername', get_string('issuername_endorsement', 'badges'), ['size' => '70']);
$mform->setType('issuername', PARAM_TEXT);
$mform->addRule('issuername', null, 'required');
$mform->addHelpButton('issuername', 'issuername_endorsement', 'badges');
- $mform->addElement('text', 'issueremail', get_string('issueremail', 'badges'), array('size' => '70'));
+ $mform->addElement('text', 'issueremail', get_string('issueremail', 'badges'), ['size' => '70']);
$mform->addRule('issueremail', null, 'required');
$mform->setType('issueremail', PARAM_RAW);
$mform->addHelpButton('issueremail', 'issueremail', 'badges');
- $mform->addElement('text', 'issuerurl', get_string('issuerurl', 'badges'), array('size' => '70'));
+ $mform->addElement('text', 'issuerurl', get_string('issuerurl', 'badges'), ['size' => '70']);
$mform->setType('issuerurl', PARAM_URL);
$mform->addRule('issuerurl', null, 'required');
$mform->addHelpButton('issuerurl', 'issuerurl', 'badges');
$mform->addElement('date_time_selector', 'dateissued',
- get_string('dateawarded', 'badges'));
+ get_string('dateawarded', 'badges'));
$mform->addElement('header', 'claim', get_string('claim', 'badges'));
- $mform->addElement('text', 'claimid', get_string('claimid', 'badges'), array('size' => '70'));
+ $mform->addElement('text', 'claimid', get_string('claimid', 'badges'), ['size' => '70']);
$mform->setType('claimid', PARAM_URL);
$mform->addRule('claimid', null, 'required');
$mform->addElement('textarea', 'claimcomment', get_string('claimcomment', 'badges'), 'wrap="virtual" rows="8" cols="70"');
@@ -70,7 +69,7 @@ class endorsement_form extends moodleform {
$this->add_action_buttons();
// Freeze all elements if badge is active or locked.
if ($badge->is_active() || $badge->is_locked()) {
- $mform->hardFreezeAllVisibleExcept(array());
+ $mform->hardFreezeAllVisibleExcept([]);
}
}
@@ -94,4 +93,4 @@ class endorsement_form extends moodleform {
}
return $errors;
}
-}
\ No newline at end of file
+}
diff --git a/badges/preferences_form.php b/badges/classes/form/preferences.php
similarity index 84%
rename from badges/preferences_form.php
rename to badges/classes/form/preferences.php
index 7bfe8f83b2b..5bbac37c02d 100644
--- a/badges/preferences_form.php
+++ b/badges/classes/form/preferences.php
@@ -14,23 +14,27 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * Form class for editing badges preferences.
- *
- * @package core
- * @subpackage badges
- * @copyright 2013 onwards Totara Learning Solutions Ltd {@link http://www.totaralms.com/}
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- * @author Yuliya Bozhko
- */
+namespace core_badges\form;
-if (!defined('MOODLE_INTERNAL')) {
- die('Direct access to this script is forbidden.');
-}
+use moodleform;
+
+defined('MOODLE_INTERNAL') || die();
require_once($CFG->libdir . '/formslib.php');
-class badges_preferences_form extends moodleform {
+/**
+ * Form class for editing badges preferences.
+ *
+ * @package core_badges
+ * @copyright 2018 Tung Thai
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ * @author Yuliya Bozhko
+ * @author Tung Thai
+ */
+class preferences extends moodleform {
+ /**
+ * Defines the form.
+ */
public function definition() {
global $USER, $CFG;
diff --git a/badges/related_form.php b/badges/classes/form/related.php
similarity index 86%
rename from badges/related_form.php
rename to badges/classes/form/related.php
index 31d74f4cd40..c2f4818b8e6 100644
--- a/badges/related_form.php
+++ b/badges/classes/form/related.php
@@ -13,15 +13,11 @@
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * Form related badges.
- *
- * @package core
- * @subpackage badges
- * @copyright 2018 Tung Thai
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- * @author Tung Thai
- */
+
+namespace core_badges\form;
+
+use moodleform;
+
defined('MOODLE_INTERNAL') || die();
require_once($CFG->libdir . '/formslib.php');
require_once($CFG->libdir . '/badgeslib.php');
@@ -29,11 +25,12 @@ require_once($CFG->libdir . '/badgeslib.php');
/**
* Form to edit badge details.
*
+ * @package core_badges
* @copyright 2018 Tung Thai
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @author Tung Thai
*/
-class edit_relatedbadge_form extends moodleform {
+class related extends moodleform {
/**
* Defines the form.
@@ -44,10 +41,10 @@ class edit_relatedbadge_form extends moodleform {
$badgesarray = $this->get_badges_option($badge);
$mform->addElement('header', 'alignment', get_string('relatedbages', 'badges'));
if (!$badgesarray) {
- $badgesarray = array(get_string('none'));
- $attributes = array('size' => '3', 'disabled' => true, 'style' => 'min-width: 200px');
+ $badgesarray = [get_string('none')];
+ $attributes = ['size' => '3', 'disabled' => true, 'style' => 'min-width: 200px'];
} else {
- $attributes = array('size' => '10');
+ $attributes = ['size' => '10'];
}
$mform->addElement('select', 'relatedbadgeids', get_string('relatedbages', 'badges'), $badgesarray, $attributes);
$mform->getElement('relatedbadgeids')->setMultiple(true);
@@ -55,7 +52,7 @@ class edit_relatedbadge_form extends moodleform {
// Freeze all elements if badge is active or locked.
if ($badge->is_active() || $badge->is_locked()) {
- $mform->hardFreezeAllVisibleExcept(array());
+ $mform->hardFreezeAllVisibleExcept([]);
}
}
@@ -96,7 +93,7 @@ class edit_relatedbadge_form extends moodleform {
$records = $DB->get_records_sql($sql, $params);
$languages = get_string_manager()->get_list_of_languages();
- $options = array();
+ $options = [];
foreach ($records as $record) {
$language = isset($languages[$record->language]) ? $languages[$record->language] : '';
$options[$record->id] = $record->name .
diff --git a/badges/endorsement.php b/badges/endorsement.php
index c5abd12cbc9..604dde0d461 100644
--- a/badges/endorsement.php
+++ b/badges/endorsement.php
@@ -13,18 +13,21 @@
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
+
/**
* Endorsement information
*
- * @package core
+ * @package core_badges
* @subpackage badges
* @copyright 2018 Tung Thai
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @author Tung Thai
*/
+
+use core_badges\form\endorsement;
+
require_once(__DIR__ . '/../config.php');
require_once($CFG->libdir . '/badgeslib.php');
-require_once($CFG->dirroot . '/badges/endorsement_form.php');
$badgeid = required_param('id', PARAM_INT);
@@ -36,7 +39,7 @@ if (empty($CFG->enablebadges)) {
$badge = new badge($badgeid);
$context = $badge->get_context();
-$navurl = new moodle_url('/badges/index.php', array('type' => $badge->type));
+$navurl = new moodle_url('/badges/index.php', ['type' => $badge->type]);
require_capability('moodle/badges:configuredetails', $context);
if ($badge->type == BADGE_TYPE_COURSE) {
@@ -46,7 +49,7 @@ if ($badge->type == BADGE_TYPE_COURSE) {
require_login($badge->courseid);
$course = get_course($badge->courseid);
$heading = format_string($course->fullname, true, ['context' => $context]);
- $navurl = new moodle_url('/badges/index.php', array('type' => $badge->type, 'id' => $badge->courseid));
+ $navurl = new moodle_url('/badges/index.php', ['type' => $badge->type, 'id' => $badge->courseid]);
$PAGE->set_pagelayout('standard');
navigation_node::override_active_url($navurl);
} else {
@@ -55,7 +58,7 @@ if ($badge->type == BADGE_TYPE_COURSE) {
navigation_node::override_active_url($navurl, true);
}
-$currenturl = new moodle_url('/badges/endorsement.php', array('id' => $badgeid));
+$currenturl = new moodle_url('/badges/endorsement.php', ['id' => $badgeid]);
$PAGE->set_context($context);
$PAGE->set_url($currenturl);
$PAGE->set_heading($heading);
@@ -78,9 +81,9 @@ echo $output->render_tertiary_navigation($actionbar);
echo $OUTPUT->heading(print_badge_image($badge, $context, 'small') . ' ' . $badge->name);
echo $output->print_badge_status_box($badge);
-$form = new endorsement_form($currenturl, array('badge' => $badge));
+$form = new endorsement($currenturl, ['badge' => $badge]);
if ($form->is_cancelled()) {
- redirect(new moodle_url('/badges/overview.php', array('id' => $badgeid)));
+ redirect(new moodle_url('/badges/overview.php', ['id' => $badgeid]));
} else if ($form->is_submitted() && $form->is_validated() && ($data = $form->get_data())) {
$endorsement = new stdClass();
$endorsement->badgeid = $badgeid;
diff --git a/badges/preferences.php b/badges/preferences.php
index 834386656c4..e21856b2f1e 100644
--- a/badges/preferences.php
+++ b/badges/preferences.php
@@ -17,7 +17,7 @@
/**
* Badges user preferences page.
*
- * @package core
+ * @package core_badges
* @subpackage badges
* @copyright 2013 onwards Totara Learning Solutions Ltd {@link http://www.totaralms.com/}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
@@ -25,8 +25,9 @@
*/
require_once(__DIR__ . '/../config.php');
-require_once('preferences_form.php');
-require_once($CFG->dirroot.'/user/editlib.php');
+require_once($CFG->dirroot . '/user/editlib.php');
+
+use core_badges\form\preferences;
$url = new moodle_url('/badges/preferences.php');
@@ -39,8 +40,8 @@ if (empty($CFG->enablebadges)) {
throw new \moodle_exception('badgesdisabled', 'badges');
}
-$mform = new badges_preferences_form();
-$mform->set_data(array('badgeprivacysetting' => get_user_preferences('badgeprivacysetting')));
+$mform = new preferences();
+$mform->set_data(['badgeprivacysetting' => get_user_preferences('badgeprivacysetting')]);
if (!$mform->is_cancelled() && $data = $mform->get_data()) {
useredit_update_user_preference(['id' => $USER->id,
diff --git a/badges/related.php b/badges/related.php
index 37beb69593e..fb7d48bc632 100644
--- a/badges/related.php
+++ b/badges/related.php
@@ -17,16 +17,17 @@
/**
* Related badges information
*
- * @package core
+ * @package core_badges
* @subpackage badges
* @copyright 2018 Tung Thai
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @author Tung Thai
*/
+use core_badges\form\related;
+
require_once(__DIR__ . '/../config.php');
require_once($CFG->libdir . '/badgeslib.php');
-require_once($CFG->dirroot . '/badges/related_form.php');
$badgeid = required_param('id', PARAM_INT);
$action = optional_param('action', null, PARAM_TEXT);
@@ -40,7 +41,7 @@ if (empty($CFG->enablebadges)) {
$badge = new badge($badgeid);
$context = $badge->get_context();
-$navurl = new moodle_url('/badges/index.php', array('type' => $badge->type));
+$navurl = new moodle_url('/badges/index.php', ['type' => $badge->type]);
require_capability('moodle/badges:configuredetails', $context);
if ($badge->type == BADGE_TYPE_COURSE) {
@@ -51,7 +52,7 @@ if ($badge->type == BADGE_TYPE_COURSE) {
$course = get_course($badge->courseid);
$heading = format_string($course->fullname, true, ['context' => $context]);
- $navurl = new moodle_url('/badges/index.php', array('type' => $badge->type, 'id' => $badge->courseid));
+ $navurl = new moodle_url('/badges/index.php', ['type' => $badge->type, 'id' => $badge->courseid]);
$PAGE->set_pagelayout('standard');
navigation_node::override_active_url($navurl);
} else {
@@ -60,7 +61,7 @@ if ($badge->type == BADGE_TYPE_COURSE) {
navigation_node::override_active_url($navurl, true);
}
-$currenturl = new moodle_url('/badges/related.php', array('id' => $badge->id));
+$currenturl = new moodle_url('/badges/related.php', ['id' => $badge->id]);
$PAGE->set_context($context);
$PAGE->set_url($currenturl);
$PAGE->set_heading($heading);
@@ -69,9 +70,9 @@ $PAGE->navbar->add($badge->name);
$output = $PAGE->get_renderer('core', 'badges');
$msg = optional_param('msg', '', PARAM_TEXT);
$emsg = optional_param('emsg', '', PARAM_TEXT);
-$url = new moodle_url('/badges/related.php', array('id' => $badge->id, 'action' => 'add'));
+$url = new moodle_url('/badges/related.php', ['id' => $badge->id, 'action' => 'add']);
-$mform = new edit_relatedbadge_form($url, array('badge' => $badge));
+$mform = new related($url, ['badge' => $badge]);
if ($mform->is_cancelled()) {
redirect($currenturl);
} else if ($mform->is_submitted() && $mform->is_validated() && ($data = $mform->get_data())) {