From 1e54d10bd0eb96eb29a616538976342e3297d8b4 Mon Sep 17 00:00:00 2001 From: Dan Marsden Date: Tue, 15 Mar 2016 10:25:20 +1300 Subject: [PATCH] Fix behat/coding guideline issues. --- calendar.js | 10 +- db/upgrade.php | 2 +- export_form.php | 5 +- locallib.php | 4 +- renderer.php | 14 +-- tests/behat/attendance_mod.feature | 6 +- tests/behat/attendance_taken_by_student.php | 104 -------------------- tests/behat/extra_features.feature | 18 ++-- 8 files changed, 29 insertions(+), 134 deletions(-) delete mode 100644 tests/behat/attendance_taken_by_student.php diff --git a/calendar.js b/calendar.js index 0c50310..42a2771 100644 --- a/calendar.js +++ b/calendar.js @@ -26,7 +26,7 @@ YUI().use('yui2-container', 'yui2-calendar', function(Y) { // until the first time the button is clicked. if (!dialog) { - // Hide Calendar if we click anywhere in the document other than the calendar + // Hide Calendar if we click anywhere in the document other than the calendar. Event.on(document, "click", function(e) { var el = Event.getTarget(e); var dialogEl = dialog.element; @@ -51,7 +51,7 @@ YUI().use('yui2-container', 'yui2-calendar', function(Y) { if (YAHOO.env.ua.ie) { // Since we're hiding the table using yui-overlay-hidden, we // want to let the dialog know that the content size has changed, when - // shown + // shown. dialog.fireEvent("changeContent"); } }); @@ -62,7 +62,7 @@ YUI().use('yui2-container', 'yui2-calendar', function(Y) { calendar = new YAHOO.widget.Calendar("cal", { iframe:false, // Turn iframe off, since container has iframe support. - hide_blank_weeks:true // Enable, to demonstrate how we handle changing height, using changeContent + hide_blank_weeks:true // Enable, to demonstrate how we handle changing height, using changeContent. }); calendar.cfg.setProperty("start_weekday", M.attendance.cal_start_weekday); @@ -83,7 +83,7 @@ YUI().use('yui2-container', 'yui2-calendar', function(Y) { calendar.renderEvent.subscribe(function() { // Tell Dialog it's contents have changed, which allows - // container to redraw the underlay (for IE6/Safari2) + // container to redraw the underlay (for IE6/Safari2). dialog.fireEvent("changeContent"); }); } @@ -91,7 +91,7 @@ YUI().use('yui2-container', 'yui2-calendar', function(Y) { var seldate = calendar.getSelectedDates(); if (seldate.length > 0) { - // Set the pagedate to show the selected date if it exists + // Set the pagedate to show the selected date if it exists. calendar.cfg.setProperty("pagedate", seldate[0]); calendar.render(); } diff --git a/db/upgrade.php b/db/upgrade.php index 5617bcd..20ae691 100644 --- a/db/upgrade.php +++ b/db/upgrade.php @@ -29,7 +29,7 @@ */ function xmldb_attendance_upgrade($oldversion=0) { - global $CFG, $THEME, $DB; + global $DB; $dbman = $DB->get_manager(); // Loads ddl manager and xmldb classes. $result = true; diff --git a/export_form.php b/export_form.php index c53ff71..0cf5b87 100644 --- a/export_form.php +++ b/export_form.php @@ -38,10 +38,8 @@ class mod_attendance_export_form extends moodleform { * @return void */ public function definition() { - global $USER, $DB, $PAGE; $mform =& $this->_form; - $course = $this->_customdata['course']; $cm = $this->_customdata['cm']; $modcontext = $this->_customdata['modcontext']; @@ -130,8 +128,7 @@ class mod_attendance_export_form extends moodleform { $mform->addElement('select', 'format', get_string('format'), array('excel' => get_string('downloadexcel', 'attendance'), 'ooo' => get_string('downloadooo', 'attendance'), - 'text' => get_string('downloadtext', 'attendance') - )); + 'text' => get_string('downloadtext', 'attendance'))); $submitstring = get_string('ok'); $this->add_action_buttons(false, $submitstring); diff --git a/locallib.php b/locallib.php index 3e35287..d1cd65b 100644 --- a/locallib.php +++ b/locallib.php @@ -756,8 +756,8 @@ class attendance { print_error('No such session in this course'); } - $sesstarttime = $formdata->sestime['starthour']*HOURSECS + $formdata->sestime['startminute'] * MINSECS; - $sesendtime = $formdata->sestime['endhour']*HOURSECS + $formdata->sestime['endminute'] * MINSECS; + $sesstarttime = $formdata->sestime['starthour'] * HOURSECS + $formdata->sestime['startminute'] * MINSECS; + $sesendtime = $formdata->sestime['endhour'] * HOURSECS + $formdata->sestime['endminute'] * MINSECS; $sess->sessdate = $formdata->sessiondate + $sesstarttime; $sess->duration = $sesendtime - $sesstarttime; diff --git a/renderer.php b/renderer.php index 0ab4105..3849f2f 100644 --- a/renderer.php +++ b/renderer.php @@ -234,8 +234,8 @@ class mod_attendance_renderer extends plugin_renderer_base { $dta = $this->construct_date_time_actions($sessdata, $sess); $table->data[$sess->id][] = $i; - $table->data[$sess->id][] = $sess->groupid ? get_string('group') . ': ' . $sessdata->groups[$sess->groupid]->name : - get_string('commonsession', 'attendance'); + $table->data[$sess->id][] = $sess->groupid ? get_string('group') . ': ' . $sessdata->groups[$sess->groupid]->name + : get_string('commonsession', 'attendance'); $table->data[$sess->id][] = $dta['date']; $table->data[$sess->id][] = $dta['time']; $table->data[$sess->id][] = $sess->description; @@ -770,8 +770,8 @@ class mod_attendance_renderer extends plugin_renderer_base { $row = new html_table_row(); $row->cells[] = $i; - $sessiontypeshort = $sess->groupid ? get_string('group') . ': ' . $userdata->groups[$sess->groupid]->name : - get_string('commonsession', 'attendance'); + $sessiontypeshort = $sess->groupid ? get_string('group') . ': ' . $userdata->groups[$sess->groupid]->name + : get_string('commonsession', 'attendance'); $row->cells[] = html_writer::tag('nobr', $sessiontypeshort); $row->cells[] = userdate($sess->sessdate, get_string('strftimedmyw', 'attendance')); $row->cells[] = $this->construct_time($sess->sessdate, $sess->duration); @@ -850,7 +850,8 @@ class mod_attendance_renderer extends plugin_renderer_base { $sesstext = html_writer::link($reportdata->url_take($sess->id, $sess->groupid), $sesstext); } $sesstext .= html_writer::empty_tag('br'); - $sesstext .= $sess->groupid ? get_string('group') . ': ' . $reportdata->groups[$sess->groupid]->name : get_string('commonsession', 'attendance'); + $sesstext .= $sess->groupid ? get_string('group') . ': ' . $reportdata->groups[$sess->groupid]->name + : get_string('commonsession', 'attendance'); $table->head[] = $sesstext; $table->align[] = 'center'; @@ -899,7 +900,8 @@ class mod_attendance_renderer extends plugin_renderer_base { } if ($bulkmessagecapability) { // Create the checkbox for bulk messaging. - $row->cells[] = html_writer::checkbox('user'.$user->id, 'on', false, '', array('class' => 'attendancesesscheckbox')); + $row->cells[] = html_writer::checkbox('user'.$user->id, 'on', false, '', + array('class' => 'attendancesesscheckbox')); } $table->data[] = $row; diff --git a/tests/behat/attendance_mod.feature b/tests/behat/attendance_mod.feature index 1c0ae60..3c955bf 100644 --- a/tests/behat/attendance_mod.feature +++ b/tests/behat/attendance_mod.feature @@ -38,7 +38,7 @@ Feature: Teachers and Students can record session attendance And I follow "Add" And I set the field "Allow students to record own attendance" to "1" And I set the following fields to these values: - | id_sessiondate_hour | 23 | + | id_sestime_starthour | 23 | And I click on "id_submitbutton" "button" And I log out When I log in as "student1" @@ -62,7 +62,7 @@ Feature: Teachers and Students can record session attendance And I follow "Attendance" And I follow "Add" And I set the following fields to these values: - | id_sessiondate_hour | 01 | + | id_sestime_starthour | 01 | And I click on "id_submitbutton" "button" And I follow "Report" And I follow "Low grade" @@ -81,7 +81,7 @@ Feature: Teachers and Students can record session attendance And I follow "Attendance" And I follow "Add" And I set the following fields to these values: - | id_sessiondate_hour | 01 | + | id_sestime_starthour | 01 | And I click on "id_submitbutton" "button" And I follow "Export" Then the field "id_ident_idnumber" matches value "" diff --git a/tests/behat/attendance_taken_by_student.php b/tests/behat/attendance_taken_by_student.php deleted file mode 100644 index fdf55c1..0000000 --- a/tests/behat/attendance_taken_by_student.php +++ /dev/null @@ -1,104 +0,0 @@ -. - -/** - * This file contains an event for when an attendance is taken. - * - * @package mod_attendance - * @copyright 2014 onwards Dan Marsden - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -namespace mod_attendance\event; -defined('MOODLE_INTERNAL') || die(); - -/** - * Event for when an attendance is taken. - * - * @property-read array $other { - * Extra information about event properties. - * - * string mode Mode of the report viewed. - * } - * @package mod_attendance - * @since Moodle 2.7 - * @copyright 2013 onwards Dan Marsden - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ -class attendance_taken_by_student extends \core\event\base { - - /** - * Init method. - */ - protected function init() { - $this->data['crud'] = 'r'; - $this->data['edulevel'] = self::LEVEL_TEACHING; - $this->data['objecttable'] = 'attendance'; - } - - /** - * Returns non-localised description of what happened. - * - * @return string - */ - public function get_description() { - return 'Student with id ' . $this->userid . ' took attendance with instanceid ' . - $this->objectid; - } - - /** - * Returns localised general event name. - * - * @return string - */ - public static function get_name() { - return get_string('eventtakenbystudent', 'mod_attendance'); - } - - /** - * Get URL related to the action - * - * @return \moodle_url - */ - public function get_url() { - return new \moodle_url('/mod/attendance/take.php', array('id' => $this->contextinstanceid, - 'sessionid' => $this->other['sessionid'], - 'grouptype' => $this->other['grouptype'])); - } - - /** - * Replace add_to_log() statement. - * - * @return array of parameters to be passed to legacy add_to_log() function. - */ - protected function get_legacy_logdata() { - return array($this->courseid, 'attendance', 'taken', $this->get_url(), - '', $this->contextinstanceid); - } - - /** - * Custom validation. - * - * @throws \coding_exception - * @return void - */ - protected function validate_data() { - if (empty($this->other['sessionid'])) { - throw new \coding_exception('The event mod_attendance\\event\\attendance_taken must specify sessionid.'); - } - parent::validate_data(); - } -} diff --git a/tests/behat/extra_features.feature b/tests/behat/extra_features.feature index 4eb467f..8f9599a 100644 --- a/tests/behat/extra_features.feature +++ b/tests/behat/extra_features.feature @@ -74,7 +74,7 @@ Feature: Test the various new features in the attendance module And I follow "Add" And I set the following fields to these values: - | Create multiple sessions | 0 | + | id_addmultiply | 0 | And I click on "submitbutton" "button" When I follow "Take attendance" @@ -127,7 +127,7 @@ Feature: Test the various new features in the attendance module And I follow "Test attendance" And I follow "Add" And I set the following fields to these values: - | Create multiple sessions | 0 | + | id_addmultiply | 0 | And I click on "submitbutton" "button" And I follow "Export" @@ -166,17 +166,17 @@ Feature: Test the various new features in the attendance module And I follow "Add" And I set the following fields to these values: - | Create multiple sessions | 0 | + | id_addmultiply | 0 | | Use status set | Status set 1 (P L E A) | - | id_sessiondate_hour | 10 | - | id_sessiondate_minute | 0 | + | id_sestime_starthour | 10 | + | id_sestime_startminute | 0 | And I click on "submitbutton" "button" And I follow "Add" And I set the following fields to these values: - | Create multiple sessions | 0 | + | id_addmultiply | 0 | | Use status set | Status set 2 (G O B) | - | id_sessiondate_hour | 11 | - | id_sessiondate_minute | 0 | + | id_sestime_starthour | 11 | + | id_sestime_startminute | 0 | And I click on "submitbutton" "button" When I click on "Take attendance" "link" in the "10:00" "table_row" @@ -197,7 +197,7 @@ Feature: Test the various new features in the attendance module And I follow "Test attendance" And I follow "Add" And I set the following fields to these values: - | Create multiple sessions | 0 | + | id_addmultiply | 0 | And I click on "submitbutton" "button" And I click on "Take attendance" "link"