From ea8acbabb1c3ad33bda395a093a9ed554a592d0e Mon Sep 17 00:00:00 2001 From: Dan Marsden Date: Mon, 7 Sep 2020 12:29:02 +1200 Subject: [PATCH] Move forms into auto-loaded classes folder. --- attendance.php | 6 +++--- add_form.php => classes/form/addsession.php | 11 ++++++++--- classes/{add_warning_form.php => form/addwarning.php} | 11 ++++++++--- duration_form.php => classes/form/duration.php | 9 ++++++--- export_form.php => classes/form/export.php | 5 +++-- .../form/studentattendance.php | 10 +++++----- tempmerge_form.php => classes/form/tempmerge.php | 9 ++++----- temp_form.php => classes/form/tempuser.php | 11 +++++------ tempedit_form.php => classes/form/tempuseredit.php | 8 +++----- update_form.php => classes/form/updatesession.php | 7 ++++--- export.php | 4 ++-- sessions.php | 10 ++++------ tempedit.php | 6 ++---- tempmerge.php | 6 ++---- tempusers.php | 5 ++--- warnings.php | 2 +- 16 files changed, 62 insertions(+), 58 deletions(-) rename add_form.php => classes/form/addsession.php (98%) rename classes/{add_warning_form.php => form/addwarning.php} (96%) rename duration_form.php => classes/form/duration.php (92%) rename export_form.php => classes/form/export.php (98%) rename student_attendance_form.php => classes/form/studentattendance.php (92%) rename tempmerge_form.php => classes/form/tempmerge.php (94%) rename temp_form.php => classes/form/tempuser.php (92%) rename tempedit_form.php => classes/form/tempuseredit.php (93%) rename update_form.php => classes/form/updatesession.php (98%) diff --git a/attendance.php b/attendance.php index 2784aa5..c1c1003 100644 --- a/attendance.php +++ b/attendance.php @@ -24,7 +24,7 @@ require_once(dirname(__FILE__).'/../../config.php'); require_once(dirname(__FILE__).'/locallib.php'); -require_once(dirname(__FILE__).'/student_attendance_form.php'); +require_once($CFG->libdir.'/formslib.php'); $pageparams = new mod_attendance_sessions_page_params(); @@ -156,11 +156,11 @@ $PAGE->set_url($att->url_sessions()); // Create the form. if ($attforsession->rotateqrcode == 1) { - $mform = new mod_attendance_student_attendance_form(null, + $mform = new mod_attendance\form\studentattendance(null, array('course' => $course, 'cm' => $cm, 'modcontext' => $PAGE->context, 'session' => $attforsession, 'attendance' => $att, 'password' => $attforsession->studentpassword)); } else { - $mform = new mod_attendance_student_attendance_form(null, + $mform = new mod_attendance\form\studentattendance(null, array('course' => $course, 'cm' => $cm, 'modcontext' => $PAGE->context, 'session' => $attforsession, 'attendance' => $att, 'password' => $qrpass)); } diff --git a/add_form.php b/classes/form/addsession.php similarity index 98% rename from add_form.php rename to classes/form/addsession.php index 0419e97..43dda86 100644 --- a/add_form.php +++ b/classes/form/addsession.php @@ -15,16 +15,21 @@ // along with Moodle. If not, see . /** - * This file contains the forms to add + * This file contains the forms to add session. * * @package mod_attendance * @copyright 2011 Artem Andreev * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +namespace mod_attendance\form; defined('MOODLE_INTERNAL') || die(); -require_once($CFG->libdir.'/formslib.php'); +use moodleform; +use mod_attendance_structure; +use DateTime; +use DateInterval; +use DatePeriod; /** * class for displaying add form. @@ -32,7 +37,7 @@ require_once($CFG->libdir.'/formslib.php'); * @copyright 2011 Artem Andreev * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class mod_attendance_add_form extends moodleform { +class addsession extends moodleform { /** * Called to define this moodle form diff --git a/classes/add_warning_form.php b/classes/form/addwarning.php similarity index 96% rename from classes/add_warning_form.php rename to classes/form/addwarning.php index 0b9c238..45a63f5 100644 --- a/classes/add_warning_form.php +++ b/classes/form/addwarning.php @@ -15,23 +15,28 @@ // along with Moodle. If not, see . /** - * Contains class mod_attendance_add_warning_form + * Contains class addwarning * * @package mod_attendance * @copyright 2017 Dan Marsden * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +namespace mod_attendance\form; + defined('MOODLE_INTERNAL') || die(); +use moodleform; +use context_course; + /** - * Class mod_attendance_add_warning_form + * Class addwarning * * @package mod_attendance * @copyright 2017 Dan Marsden * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class mod_attendance_add_warning_form extends moodleform { +class addwarning extends moodleform { /** * Form definition */ diff --git a/duration_form.php b/classes/form/duration.php similarity index 92% rename from duration_form.php rename to classes/form/duration.php index 53bb563..f6efd66 100644 --- a/duration_form.php +++ b/classes/form/duration.php @@ -22,8 +22,11 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +namespace mod_attendance\form; + defined('MOODLE_INTERNAL') || die(); -require_once($CFG->libdir.'/formslib.php'); + +use moodleform; /** * class for displaying duration form. @@ -31,7 +34,7 @@ require_once($CFG->libdir.'/formslib.php'); * @copyright 2011 Artem Andreev * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class mod_attendance_duration_form extends moodleform { +class duration extends moodleform { /** * Called to define this moodle form @@ -62,7 +65,7 @@ class mod_attendance_duration_form extends moodleform { $mform->setType('ids', PARAM_ALPHANUMEXT); $mform->addElement('hidden', 'id', $cm->id); $mform->setType('id', PARAM_INT); - $mform->addElement('hidden', 'action', mod_attendance_sessions_page_params::ACTION_CHANGE_DURATION); + $mform->addElement('hidden', 'action', \mod_attendance_sessions_page_params::ACTION_CHANGE_DURATION); $mform->setType('action', PARAM_INT); $mform->setDefaults(array('durtime' => array('hours' => 0, 'minutes' => 0))); diff --git a/export_form.php b/classes/form/export.php similarity index 98% rename from export_form.php rename to classes/form/export.php index 51bdb7b..d707699 100644 --- a/export_form.php +++ b/classes/form/export.php @@ -22,8 +22,9 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +namespace mod_attendance\form; + defined('MOODLE_INTERNAL') || die(); -require_once($CFG->libdir.'/formslib.php'); /** * class for displaying export form. @@ -31,7 +32,7 @@ require_once($CFG->libdir.'/formslib.php'); * @copyright 2011 Artem Andreev * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class mod_attendance_export_form extends moodleform { +class export extends \moodleform { /** * Called to define this moodle form diff --git a/student_attendance_form.php b/classes/form/studentattendance.php similarity index 92% rename from student_attendance_form.php rename to classes/form/studentattendance.php index 80d8ec2..eba5302 100644 --- a/student_attendance_form.php +++ b/classes/form/studentattendance.php @@ -21,17 +21,17 @@ * @copyright 2011 Artem Andreev * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +namespace mod_attendance\form; defined('MOODLE_INTERNAL') || die(); -require_once($CFG->libdir.'/formslib.php'); /** - * Class mod_attendance_student_attendance_form + * Class studentattendance * * @copyright 2011 Artem Andreev * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class mod_attendance_student_attendance_form extends moodleform { +class studentattendance extends \moodleform { /** * Called to define this moodle form * @@ -89,11 +89,11 @@ class mod_attendance_student_attendance_form extends moodleform { // Create radio buttons for setting the attendance status. $radioarray = array(); foreach ($statuses as $status) { - $name = html_writer::span($status->description, 'statusdesc'); + $name = \html_writer::span($status->description, 'statusdesc'); $radioarray[] =& $mform->createElement('radio', 'status', '', $name, $status->id, array()); } if ($disabledduetotime) { - $warning = html_writer::span(get_string('somedisabledstatus', 'attendance'), 'somedisabledstatus'); + $warning = \html_writer::span(get_string('somedisabledstatus', 'attendance'), 'somedisabledstatus'); $radioarray[] =& $mform->createElement('static', '', '', $warning); } // Add the radio buttons as a control with the user's name in front. diff --git a/tempmerge_form.php b/classes/form/tempmerge.php similarity index 94% rename from tempmerge_form.php rename to classes/form/tempmerge.php index d25c4f8..8f24c92 100644 --- a/tempmerge_form.php +++ b/classes/form/tempmerge.php @@ -22,10 +22,9 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -defined('MOODLE_INTERNAL') || die(); +namespace mod_attendance\form; -global $CFG; -require_once($CFG->libdir.'/formslib.php'); +defined('MOODLE_INTERNAL') || die(); /** * Temp merge form class. @@ -34,7 +33,7 @@ require_once($CFG->libdir.'/formslib.php'); * @copyright 2013 Davo Smith, Synergy Learning * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class tempmerge_form extends moodleform { +class tempmerge extends \moodleform { /** * Called to define this moodle form * @@ -43,7 +42,7 @@ class tempmerge_form extends moodleform { public function definition() { global $COURSE; - $context = context_course::instance($COURSE->id); + $context = \context_course::instance($COURSE->id); $namefields = get_all_user_name_fields(true, 'u'); $students = get_enrolled_users($context, 'mod/attendance:canbelisted', 0, 'u.id,'.$namefields.',u.email', 'u.lastname, u.firstname', 0, 0, true); diff --git a/temp_form.php b/classes/form/tempuser.php similarity index 92% rename from temp_form.php rename to classes/form/tempuser.php index 87b2a0b..4b81181 100644 --- a/temp_form.php +++ b/classes/form/tempuser.php @@ -22,17 +22,16 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -defined('MOODLE_INTERNAL') || die(); +namespace mod_attendance\form; -global $CFG; -require_once($CFG->libdir.'/formslib.php'); +defined('MOODLE_INTERNAL') || die(); /** - * Class temp_form + * Class tempuser * @copyright 2013 Davo Smith, Synergy Learning * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class temp_form extends moodleform { +class tempuser extends \moodleform { /** * Define form. */ @@ -74,7 +73,7 @@ class temp_form extends moodleform { public function validation($data, $files) { $errors = parent::validation($data, $files); - if ($err = mod_attendance_structure::check_existing_email($data['temail'])) { + if ($err = \mod_attendance_structure::check_existing_email($data['temail'])) { $errors['temail'] = $err; } diff --git a/tempedit_form.php b/classes/form/tempuseredit.php similarity index 93% rename from tempedit_form.php rename to classes/form/tempuseredit.php index ef4d79b..307f1f8 100644 --- a/tempedit_form.php +++ b/classes/form/tempuseredit.php @@ -21,19 +21,17 @@ * @copyright 2013 Davo Smith, Synergy Learning * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +namespace mod_attendance\form; defined('MOODLE_INTERNAL') || die(); -global $CFG; -require_once($CFG->libdir.'/formslib.php'); - /** * class for displaying tempedit form. * * @copyright 2013 Davo Smith, Synergy Learning * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class tempedit_form extends moodleform { +class tempuseredit extends \moodleform { /** * Called to define this moodle form @@ -83,7 +81,7 @@ class tempedit_form extends moodleform { public function validation($data, $files) { $errors = parent::validation($data, $files); - if ($err = mod_attendance_structure::check_existing_email($data['temail'], $data['userid'])) { + if ($err = \mod_attendance_structure::check_existing_email($data['temail'], $data['userid'])) { $errors['temail'] = $err; } return $errors; diff --git a/update_form.php b/classes/form/updatesession.php similarity index 98% rename from update_form.php rename to classes/form/updatesession.php index 05bd34f..0dcaf11 100644 --- a/update_form.php +++ b/classes/form/updatesession.php @@ -22,16 +22,17 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +namespace mod_attendance\form; + defined('MOODLE_INTERNAL') || die(); -require_once($CFG->libdir.'/formslib.php'); /** - * class for displaying update form. + * class for displaying update session form. * * @copyright 2011 Artem Andreev * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class mod_attendance_update_form extends moodleform { +class updatesession extends \moodleform { /** * Called to define this moodle form diff --git a/export.php b/export.php index 661c976..1495ce8 100644 --- a/export.php +++ b/export.php @@ -26,9 +26,9 @@ define('NO_OUTPUT_BUFFERING', true); require_once(dirname(__FILE__).'/../../config.php'); require_once(dirname(__FILE__).'/locallib.php'); -require_once(dirname(__FILE__).'/export_form.php'); require_once(dirname(__FILE__).'/renderables.php'); require_once(dirname(__FILE__).'/renderhelpers.php'); +require_once($CFG->libdir.'/formslib.php'); $id = required_param('id', PARAM_INT); @@ -51,7 +51,7 @@ $PAGE->set_cacheable(true); $PAGE->navbar->add(get_string('export', 'attendance')); $formparams = array('course' => $course, 'cm' => $cm, 'modcontext' => $context); -$mform = new mod_attendance_export_form($att->url_export(), $formparams); +$mform = new mod_attendance\form\export($att->url_export(), $formparams); if ($formdata = $mform->get_data()) { diff --git a/sessions.php b/sessions.php index cfbea98..091c7bb 100644 --- a/sessions.php +++ b/sessions.php @@ -24,9 +24,7 @@ require_once(dirname(__FILE__).'/../../config.php'); require_once(dirname(__FILE__).'/locallib.php'); -require_once(dirname(__FILE__).'/add_form.php'); -require_once(dirname(__FILE__).'/update_form.php'); -require_once(dirname(__FILE__).'/duration_form.php'); +require_once($CFG->dirroot.'/lib/formslib.php'); $pageparams = new mod_attendance_sessions_page_params(); @@ -67,7 +65,7 @@ $formparams = array('course' => $course, 'cm' => $cm, 'modcontext' => $context, switch ($att->pageparams->action) { case mod_attendance_sessions_page_params::ACTION_ADD: $url = $att->url_sessions(array('action' => mod_attendance_sessions_page_params::ACTION_ADD)); - $mform = new mod_attendance_add_form($url, $formparams); + $mform = new \mod_attendance\form\addsession($url, $formparams); if ($mform->is_cancelled()) { redirect($att->url_manage()); @@ -93,7 +91,7 @@ switch ($att->pageparams->action) { $url = $att->url_sessions(array('action' => mod_attendance_sessions_page_params::ACTION_UPDATE, 'sessionid' => $sessionid)); $formparams['sessionid'] = $sessionid; - $mform = new mod_attendance_update_form($url, $formparams); + $mform = new \mod_attendance\form\updatesession($url, $formparams); if ($mform->is_cancelled()) { redirect($att->url_manage()); @@ -179,7 +177,7 @@ switch ($att->pageparams->action) { $url = $att->url_sessions(array('action' => mod_attendance_sessions_page_params::ACTION_CHANGE_DURATION)); $formparams['ids'] = $slist; - $mform = new mod_attendance_duration_form($url, $formparams); + $mform = new mod_attendance\form\duration($url, $formparams); if ($mform->is_cancelled()) { redirect($att->url_manage()); diff --git a/tempedit.php b/tempedit.php index 6f93301..d4fc287 100644 --- a/tempedit.php +++ b/tempedit.php @@ -23,10 +23,8 @@ */ require_once(dirname(__FILE__).'/../../config.php'); - -global $CFG, $DB, $PAGE, $OUTPUT; +require_once($CFG->libdir.'/formslib.php'); require_once($CFG->dirroot.'/mod/attendance/locallib.php'); -require_once($CFG->dirroot.'/mod/attendance/tempedit_form.php'); $id = required_param('id', PARAM_INT); $userid = required_param('userid', PARAM_INT); @@ -90,7 +88,7 @@ $formdata->tname = $tempuser->fullname; $formdata->userid = $tempuser->id; $formdata->temail = $tempuser->email; -$mform = new tempedit_form(); +$mform = new \mod_attendance\form\tempuseredit(); $mform->set_data($formdata); if ($mform->is_cancelled()) { diff --git a/tempmerge.php b/tempmerge.php index 8815fca..b983d1a 100644 --- a/tempmerge.php +++ b/tempmerge.php @@ -23,10 +23,8 @@ */ require_once(dirname(__FILE__).'/../../config.php'); - -global $CFG, $DB, $PAGE, $OUTPUT; +require_once($CFG->libdir.'/formslib.php'); require_once($CFG->dirroot.'/mod/attendance/locallib.php'); -require_once($CFG->dirroot.'/mod/attendance/tempmerge_form.php'); $id = required_param('id', PARAM_INT); $userid = required_param('userid', PARAM_INT); @@ -55,7 +53,7 @@ $formdata = (object)array( $custom = array( 'description' => format_string($tempuser->fullname).' ('.format_string($tempuser->email).')', ); -$mform = new tempmerge_form(null, $custom); +$mform = new mod_attendance\form\tempmerge(null, $custom); $mform->set_data($formdata); if ($mform->is_cancelled()) { diff --git a/tempusers.php b/tempusers.php index 4a856d3..93cb336 100644 --- a/tempusers.php +++ b/tempusers.php @@ -23,9 +23,8 @@ */ require_once(dirname(__FILE__).'/../../config.php'); -global $CFG, $DB, $OUTPUT, $PAGE, $COURSE; +require_once($CFG->libdir.'/formslib.php'); require_once($CFG->dirroot.'/mod/attendance/locallib.php'); -require_once($CFG->dirroot.'/mod/attendance/temp_form.php'); $id = required_param('id', PARAM_INT); @@ -52,7 +51,7 @@ $tabs = new attendance_tabs($att, attendance_tabs::TAB_TEMPORARYUSERS); $formdata = (object)array( 'id' => $cm->id, ); -$mform = new temp_form(); +$mform = new mod_attendance\form\tempuser(); $mform->set_data($formdata); if ($data = $mform->get_data()) { diff --git a/warnings.php b/warnings.php index eeb1e87..bfb1ab8 100644 --- a/warnings.php +++ b/warnings.php @@ -70,7 +70,7 @@ if (empty($id)) { } -$mform = new mod_attendance_add_warning_form($url, array('notid' => $notid, 'id' => $id)); +$mform = new mod_attendance\form\addwarning($url, array('notid' => $notid, 'id' => $id)); if ($data = $mform->get_data()) { if (empty($data->notid)) {