From 48ea9e38a23f2e0466bc3d4421d3d78508757168 Mon Sep 17 00:00:00 2001 From: Dan Marsden Date: Tue, 15 Mar 2016 12:09:15 +1300 Subject: [PATCH] move date_selector into function to prevent copypaste detector error --- add_form.php | 18 +----------------- locallib.php | 21 +++++++++++++++++++++ update_form.php | 18 +----------------- 3 files changed, 23 insertions(+), 34 deletions(-) diff --git a/add_form.php b/add_form.php index be3cad8..f812dbb 100644 --- a/add_form.php +++ b/add_form.php @@ -102,23 +102,7 @@ class mod_attendance_add_form extends moodleform { } } - $mform->addElement('date_selector', 'sessiondate', get_string('sessiondate', 'attendance')); - - for ($i = 0; $i <= 23; $i++) { - $hours[$i] = sprintf("%02d", $i); - } - for ($i = 0; $i < 60; $i += 5) { - $minutes[$i] = sprintf("%02d", $i); - } - - $sesendtime = array(); - $sesendtime[] =& $mform->createElement('static', 'from', '', get_string('from', 'attendance')); - $sesendtime[] =& $mform->createElement('select', 'starthour', get_string('hour', 'form'), $hours, false, true); - $sesendtime[] =& $mform->createElement('select', 'startminute', get_string('minute', 'form'), $minutes, false, true); - $sesendtime[] =& $mform->createElement('static', 'to', '', get_string('to', 'attendance')); - $sesendtime[] =& $mform->createElement('select', 'endhour', get_string('hour', 'form'), $hours, false, true); - $sesendtime[] =& $mform->createElement('select', 'endminute', get_string('minute', 'form'), $minutes, false, true); - $mform->addGroup($sesendtime, 'sestime', get_string('time', 'attendance'), array(' '), true); + attendance_form_sessiondate_selector($mform); // Select which status set to use. $maxstatusset = attendance_get_max_statusset($this->_customdata['att']->id); diff --git a/locallib.php b/locallib.php index d1cd65b..e2310f3 100644 --- a/locallib.php +++ b/locallib.php @@ -1760,3 +1760,24 @@ function att_log_convert_url(moodle_url $fullurl) { return substr($fullurl->out(), strlen($baseurl)); } +// Helper function to add sessiondate_selector to form. +function attendance_form_sessiondate_selector (MoodleQuickForm $mform) { + + $mform->addElement('date_selector', 'sessiondate', get_string('sessiondate', 'attendance')); + + for ($i = 0; $i <= 23; $i++) { + $hours[$i] = sprintf("%02d", $i); + } + for ($i = 0; $i < 60; $i += 5) { + $minutes[$i] = sprintf("%02d", $i); + } + + $sesendtime = array(); + $sesendtime[] =& $mform->createElement('static', 'from', '', get_string('from', 'attendance')); + $sesendtime[] =& $mform->createElement('select', 'starthour', get_string('hour', 'form'), $hours, false, true); + $sesendtime[] =& $mform->createElement('select', 'startminute', get_string('minute', 'form'), $minutes, false, true); + $sesendtime[] =& $mform->createElement('static', 'to', '', get_string('to', 'attendance')); + $sesendtime[] =& $mform->createElement('select', 'endhour', get_string('hour', 'form'), $hours, false, true); + $sesendtime[] =& $mform->createElement('select', 'endminute', get_string('minute', 'form'), $minutes, false, true); + $mform->addGroup($sesendtime, 'sestime', get_string('time', 'attendance'), array(' '), true); +} \ No newline at end of file diff --git a/update_form.php b/update_form.php index fca1d84..ec6c6d3 100644 --- a/update_form.php +++ b/update_form.php @@ -80,23 +80,7 @@ class mod_attendance_update_form extends moodleform { $olddate = construct_session_full_date_time($sess->sessdate, $sess->duration); $mform->addElement('static', 'olddate', get_string('olddate', 'attendance'), $olddate); - $mform->addElement('date_selector', 'sessiondate', get_string('sessiondate', 'attendance')); - - for ($i = 0; $i <= 23; $i++) { - $hours[$i] = sprintf("%02d", $i); - } - for ($i = 0; $i < 60; $i += 5) { - $minutes[$i] = sprintf("%02d", $i); - } - - $sesendtime = array(); - $sesendtime[] =& $mform->createElement('static', 'from', '', get_string('from', 'attendance')); - $sesendtime[] =& $mform->createElement('select', 'starthour', get_string('hour', 'form'), $hours, false, true); - $sesendtime[] =& $mform->createElement('select', 'startminute', get_string('minute', 'form'), $minutes, false, true); - $sesendtime[] =& $mform->createElement('static', 'to', '', get_string('to', 'attendance')); - $sesendtime[] =& $mform->createElement('select', 'endhour', get_string('hour', 'form'), $hours, false, true); - $sesendtime[] =& $mform->createElement('select', 'endminute', get_string('minute', 'form'), $minutes, false, true); - $mform->addGroup($sesendtime, 'sestime', get_string('time', 'attendance'), array(' '), true); + attendance_form_sessiondate_selector($mform); // Show which status set is in use. $maxstatusset = attendance_get_max_statusset($this->_customdata['att']->id);