Browse Source

Add caleventid index to attendance_sessions table (#485)

* Add caleventid index to attendance_sessions table

* Fix travis file for moodle 37

* Fix some coding guideline errors.

Co-authored-by: Dan Marsden <dan@danmarsden.com>
MOODLE_37_STABLE
kristian-94 4 years ago
committed by GitHub
parent
commit
26a71efe90
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 9
      .travis.yml
  2. 12
      db/upgrade.php
  3. 40
      renderer.php
  4. 17
      tests/externallib_test.php
  5. 2
      version.php

9
.travis.yml

@ -6,8 +6,7 @@ services:
- mysql - mysql
addons: addons:
firefox: "47.0.1" postgresql: "9.5"
postgresql: "9.4"
apt: apt:
packages: packages:
- openjdk-8-jre-headless - openjdk-8-jre-headless
@ -30,10 +29,10 @@ env:
before_install: before_install:
- phpenv config-rm xdebug.ini - phpenv config-rm xdebug.ini
- nvm install 8.9 - nvm install 14.0.0
- nvm use 8.9 - nvm use 14.0.0
- cd ../.. - cd ../..
- composer create-project -n --no-dev --prefer-dist blackboard-open-source/moodle-plugin-ci ci ^2 - composer create-project -n --no-dev --prefer-dist moodlehq/moodle-plugin-ci ci dev-master
- export PATH="$(cd ci/bin; pwd):$(cd ci/vendor/bin; pwd):$PATH" - export PATH="$(cd ci/bin; pwd):$(cd ci/vendor/bin; pwd):$PATH"
- PATH=$(echo "$PATH" | sed -e 's/:\/usr\/local\/lib\/jvm\/openjdk11\/bin//') JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-amd64 - PATH=$(echo "$PATH" | sed -e 's/:\/usr\/local\/lib\/jvm\/openjdk11\/bin//') JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-amd64

12
db/upgrade.php

@ -628,5 +628,17 @@ function xmldb_attendance_upgrade($oldversion=0) {
} }
if ($oldversion < 2019072403) {
$table = new xmldb_table('attendance_sessions');
// Conditionally launch add index caleventid.
$index = new xmldb_index('caleventid', XMLDB_INDEX_NOTUNIQUE, array('caleventid'));
if (!$dbman->index_exists($table, $index)) {
$dbman->add_index($table, $index);
}
// Attendance savepoint reached.
upgrade_mod_savepoint(true, 2019072403, 'attendance');
}
return $result; return $result;
} }

40
renderer.php

@ -633,7 +633,7 @@ class mod_attendance_renderer extends plugin_renderer_base {
* @return string * @return string
*/ */
protected function render_attendance_take_list(attendance_take_data $takedata) { protected function render_attendance_take_list(attendance_take_data $takedata) {
global $PAGE, $CFG; global $CFG;
$table = new html_table(); $table = new html_table();
$table->width = '0%'; $table->width = '0%';
$table->head = array( $table->head = array(
@ -658,7 +658,7 @@ class mod_attendance_renderer extends plugin_renderer_base {
$table->align[] = 'center'; $table->align[] = 'center';
$table->size[] = '20px'; $table->size[] = '20px';
// JS to select all radios of this status and prevent default behaviour of # link. // JS to select all radios of this status and prevent default behaviour of # link.
$PAGE->requires->js_amd_inline(" $this->page->requires->js_amd_inline("
require(['jquery'], function($) { require(['jquery'], function($) {
$('#checkstatus".$st->id."').click(function(e) { $('#checkstatus".$st->id."').click(function(e) {
if ($('select[name=\"setallstatus-select\"] option:selected').val() == 'all') { if ($('select[name=\"setallstatus-select\"] option:selected').val() == 'all') {
@ -700,7 +700,7 @@ class mod_attendance_renderer extends plugin_renderer_base {
); );
$row->cells[] = html_writer::empty_tag('input', $attribs); $row->cells[] = html_writer::empty_tag('input', $attribs);
// Select all radio buttons of the same status. // Select all radio buttons of the same status.
$PAGE->requires->js_amd_inline(" $this->page->requires->js_amd_inline("
require(['jquery'], function($) { require(['jquery'], function($) {
$('#radiocheckstatus".$st->id."').click(function(e) { $('#radiocheckstatus".$st->id."').click(function(e) {
if ($('select[name=\"setallstatus-select\"] option:selected').val() == 'all') { if ($('select[name=\"setallstatus-select\"] option:selected').val() == 'all') {
@ -760,7 +760,6 @@ class mod_attendance_renderer extends plugin_renderer_base {
* @return string * @return string
*/ */
protected function render_attendance_take_grid(attendance_take_data $takedata) { protected function render_attendance_take_grid(attendance_take_data $takedata) {
global $PAGE;
$table = new html_table(); $table = new html_table();
for ($i = 0; $i < $takedata->pageparams->gridcols; $i++) { for ($i = 0; $i < $takedata->pageparams->gridcols; $i++) {
$table->align[] = 'center'; $table->align[] = 'center';
@ -775,7 +774,7 @@ class mod_attendance_renderer extends plugin_renderer_base {
$head[] = html_writer::link("#", $st->acronym, array('id' => 'checkstatus'.$st->id, $head[] = html_writer::link("#", $st->acronym, array('id' => 'checkstatus'.$st->id,
'title' => get_string('setallstatusesto', 'attendance', $st->description))); 'title' => get_string('setallstatusesto', 'attendance', $st->description)));
// JS to select all radios of this status and prevent default behaviour of # link. // JS to select all radios of this status and prevent default behaviour of # link.
$PAGE->requires->js_amd_inline(" $this->page->requires->js_amd_inline("
require(['jquery'], function($) { require(['jquery'], function($) {
$('#checkstatus".$st->id."').click(function(e) { $('#checkstatus".$st->id."').click(function(e) {
if ($('select[name=\"setallstatus-select\"] option:selected').val() == 'unselected') { if ($('select[name=\"setallstatus-select\"] option:selected').val() == 'unselected') {
@ -1102,7 +1101,7 @@ class mod_attendance_renderer extends plugin_renderer_base {
* @return string * @return string
*/ */
private function construct_user_sessions_log(attendance_user_data $userdata) { private function construct_user_sessions_log(attendance_user_data $userdata) {
global $OUTPUT, $USER; global $USER;
$context = context_module::instance($userdata->filtercontrols->cm->id); $context = context_module::instance($userdata->filtercontrols->cm->id);
$shortform = false; $shortform = false;
@ -1197,7 +1196,7 @@ class mod_attendance_renderer extends plugin_renderer_base {
'sessionid' => $sess->id, 'sessionid' => $sess->id,
'grouptype' => $sess->groupid); 'grouptype' => $sess->groupid);
$url = new moodle_url('/mod/attendance/take.php', $params); $url = new moodle_url('/mod/attendance/take.php', $params);
$icon = $OUTPUT->pix_icon('redo', get_string('changeattendance', 'attendance'), 'attendance'); $icon = $this->output->pix_icon('redo', get_string('changeattendance', 'attendance'), 'attendance');
$row->cells[] = html_writer::link($url, $icon); $row->cells[] = html_writer::link($url, $icon);
} }
@ -1227,7 +1226,7 @@ class mod_attendance_renderer extends plugin_renderer_base {
* @return string * @return string
*/ */
protected function render_attendance_report_data(attendance_report_data $reportdata) { protected function render_attendance_report_data(attendance_report_data $reportdata) {
global $PAGE, $COURSE; global $COURSE;
// Initilise Javascript used to (un)check all checkboxes. // Initilise Javascript used to (un)check all checkboxes.
$this->page->requires->js_init_call('M.mod_attendance.init_manage'); $this->page->requires->js_init_call('M.mod_attendance.init_manage');
@ -1257,7 +1256,7 @@ class mod_attendance_renderer extends plugin_renderer_base {
$summaryrows = $this->get_summary_rows($reportdata, $startwithcontrast); $summaryrows = $this->get_summary_rows($reportdata, $startwithcontrast);
// Check if the user should be able to bulk send messages to other users on the course. // Check if the user should be able to bulk send messages to other users on the course.
$bulkmessagecapability = has_capability('moodle/course:bulkmessaging', $PAGE->context); $bulkmessagecapability = has_capability('moodle/course:bulkmessaging', $this->page->context);
// Extract rows from each part and collate them into one row each. // Extract rows from each part and collate them into one row each.
$sessiondetailsleft = $reportdata->pageparams->sessiondetailspos == 'left'; $sessiondetailsleft = $reportdata->pageparams->sessiondetailspos == 'left';
@ -1300,10 +1299,9 @@ class mod_attendance_renderer extends plugin_renderer_base {
* @return array Array of html_table_row objects * @return array Array of html_table_row objects
*/ */
protected function get_user_rows(attendance_report_data $reportdata) { protected function get_user_rows(attendance_report_data $reportdata) {
global $OUTPUT, $PAGE;
$rows = array(); $rows = array();
$bulkmessagecapability = has_capability('moodle/course:bulkmessaging', $PAGE->context); $bulkmessagecapability = has_capability('moodle/course:bulkmessaging', $this->page->context);
$extrafields = get_extra_user_fields($reportdata->att->context); $extrafields = get_extra_user_fields($reportdata->att->context);
$showextrauserdetails = $reportdata->pageparams->showextrauserdetails; $showextrauserdetails = $reportdata->pageparams->showextrauserdetails;
$params = $reportdata->pageparams->get_significant_params(); $params = $reportdata->pageparams->get_significant_params();
@ -1312,12 +1310,12 @@ class mod_attendance_renderer extends plugin_renderer_base {
if ($showextrauserdetails) { if ($showextrauserdetails) {
$params['showextrauserdetails'] = 0; $params['showextrauserdetails'] = 0;
$url = $reportdata->att->url_report($params); $url = $reportdata->att->url_report($params);
$text .= $OUTPUT->action_icon($url, new pix_icon('t/switch_minus', $text .= $this->output->action_icon($url, new pix_icon('t/switch_minus',
get_string('hideextrauserdetails', 'attendance')), null, null); get_string('hideextrauserdetails', 'attendance')), null, null);
} else { } else {
$params['showextrauserdetails'] = 1; $params['showextrauserdetails'] = 1;
$url = $reportdata->att->url_report($params); $url = $reportdata->att->url_report($params);
$text .= $OUTPUT->action_icon($url, new pix_icon('t/switch_plus', $text .= $this->output->action_icon($url, new pix_icon('t/switch_plus',
get_string('showextrauserdetails', 'attendance')), null, null); get_string('showextrauserdetails', 'attendance')), null, null);
$extrafields = array(); $extrafields = array();
} }
@ -1535,7 +1533,6 @@ class mod_attendance_renderer extends plugin_renderer_base {
* @return array Array of html_table_row objects * @return array Array of html_table_row objects
*/ */
protected function get_session_rows(attendance_report_data $reportdata, $startwithcontrast=false) { protected function get_session_rows(attendance_report_data $reportdata, $startwithcontrast=false) {
global $OUTPUT;
$rows = array(); $rows = array();
@ -1548,13 +1545,13 @@ class mod_attendance_renderer extends plugin_renderer_base {
if ($showsessiondetails) { if ($showsessiondetails) {
$params['showsessiondetails'] = 0; $params['showsessiondetails'] = 0;
$url = $reportdata->att->url_report($params); $url = $reportdata->att->url_report($params);
$text .= $OUTPUT->action_icon($url, new pix_icon('t/switch_minus', $text .= $this->output->action_icon($url, new pix_icon('t/switch_minus',
get_string('hidensessiondetails', 'attendance')), null, null); get_string('hidensessiondetails', 'attendance')), null, null);
$colspan = count($reportdata->sessions); $colspan = count($reportdata->sessions);
} else { } else {
$params['showsessiondetails'] = 1; $params['showsessiondetails'] = 1;
$url = $reportdata->att->url_report($params); $url = $reportdata->att->url_report($params);
$text .= $OUTPUT->action_icon($url, new pix_icon('t/switch_plus', $text .= $this->output->action_icon($url, new pix_icon('t/switch_plus',
get_string('showsessiondetails', 'attendance')), null, null); get_string('showsessiondetails', 'attendance')), null, null);
$colspan = 1; $colspan = 1;
} }
@ -1566,11 +1563,11 @@ class mod_attendance_renderer extends plugin_renderer_base {
if ($reportdata->pageparams->sessiondetailspos == 'left') { if ($reportdata->pageparams->sessiondetailspos == 'left') {
$params['sessiondetailspos'] = 'right'; $params['sessiondetailspos'] = 'right';
$url = $reportdata->att->url_report($params); $url = $reportdata->att->url_report($params);
$text .= $OUTPUT->action_icon($url, new pix_icon('t/right', get_string('moveright', 'attendance')), null, null); $text .= $this->output->action_icon($url, new pix_icon('t/right', get_string('moveright', 'attendance')), null, null);
} else { } else {
$params['sessiondetailspos'] = 'left'; $params['sessiondetailspos'] = 'left';
$url = $reportdata->att->url_report($params); $url = $reportdata->att->url_report($params);
$text = $OUTPUT->action_icon($url, new pix_icon('t/left', get_string('moveleft', 'attendance')), null, null) . $text; $text = $this->output->action_icon($url, new pix_icon('t/left', get_string('moveleft', 'attendance')), null, null) . $text;
} }
$row->cells[] = $this->build_header_cell($text, '', true, $colspan); $row->cells[] = $this->build_header_cell($text, '', true, $colspan);
@ -1919,23 +1916,22 @@ class mod_attendance_renderer extends plugin_renderer_base {
* @return string * @return string
*/ */
private function construct_preferences_actions_icons($st, $prefdata) { private function construct_preferences_actions_icons($st, $prefdata) {
global $OUTPUT;
$params = array('sesskey' => sesskey(), $params = array('sesskey' => sesskey(),
'statusid' => $st->id); 'statusid' => $st->id);
if ($st->visible) { if ($st->visible) {
$params['action'] = mod_attendance_preferences_page_params::ACTION_HIDE; $params['action'] = mod_attendance_preferences_page_params::ACTION_HIDE;
$showhideicon = $OUTPUT->action_icon( $showhideicon = $this->output->action_icon(
$prefdata->url($params), $prefdata->url($params),
new pix_icon("t/hide", get_string('hide'))); new pix_icon("t/hide", get_string('hide')));
} else { } else {
$params['action'] = mod_attendance_preferences_page_params::ACTION_SHOW; $params['action'] = mod_attendance_preferences_page_params::ACTION_SHOW;
$showhideicon = $OUTPUT->action_icon( $showhideicon = $this->output->action_icon(
$prefdata->url($params), $prefdata->url($params),
new pix_icon("t/show", get_string('show'))); new pix_icon("t/show", get_string('show')));
} }
if (empty($st->haslogs)) { if (empty($st->haslogs)) {
$params['action'] = mod_attendance_preferences_page_params::ACTION_DELETE; $params['action'] = mod_attendance_preferences_page_params::ACTION_DELETE;
$deleteicon = $OUTPUT->action_icon( $deleteicon = $this->output->action_icon(
$prefdata->url($params), $prefdata->url($params),
new pix_icon("t/delete", get_string('delete'))); new pix_icon("t/delete", get_string('delete')));
} else { } else {

17
tests/externallib_test.php

@ -354,25 +354,28 @@ class mod_attendance_external_testcase extends externallib_advanced_testcase {
$this->getDataGenerator()->enrol_user($teacher->id, $course->id, $teacherrole->id); $this->getDataGenerator()->enrol_user($teacher->id, $course->id, $teacherrole->id);
$this->setUser($teacher); $this->setUser($teacher);
// Create attendance. // Create attendance with no groups mode.
$attendance = mod_wsattendance_external::add_attendance($course->id, 'test', 'test', NOGROUPS); $attendancenogroups = mod_wsattendance_external::add_attendance($course->id, 'nogroups',
'test', NOGROUPS);
$attendancenogroups = external_api::clean_returnvalue(mod_wsattendance_external::add_attendance_returns(),
$attendancenogroups);
// Check attendance exist. // Check attendance exist.
$this->assertCount(1, $DB->get_records('attendance', ['course' => $course->id])); $this->assertCount(1, $DB->get_records('attendance', ['course' => $course->id]));
// Create session. // Create session.
$result0 = mod_wsattendance_external::add_session($attendance['attendanceid'], 'test0', time(), 3600, 0, false); $result0 = mod_wsattendance_external::add_session($attendancenogroups['attendanceid'], 'test0', time(), 3600, 0, false);
$result1 = mod_wsattendance_external::add_session($attendance['attendanceid'], 'test1', time(), 3600, 0, false); $result1 = mod_wsattendance_external::add_session($attendancenogroups['attendanceid'], 'test1', time(), 3600, 0, false);
$this->assertCount(2, $DB->get_records('attendance_sessions', ['attendanceid' => $attendance['attendanceid']])); $this->assertCount(2, $DB->get_records('attendance_sessions', ['attendanceid' => $attendancenogroups['attendanceid']]));
// Delete session 0. // Delete session 0.
mod_wsattendance_external::remove_session($result0['sessionid']); mod_wsattendance_external::remove_session($result0['sessionid']);
$this->assertCount(1, $DB->get_records('attendance_sessions', ['attendanceid' => $attendance['attendanceid']])); $this->assertCount(1, $DB->get_records('attendance_sessions', ['attendanceid' => $attendancenogroups['attendanceid']]));
// Delete session 1. // Delete session 1.
mod_wsattendance_external::remove_session($result1['sessionid']); mod_wsattendance_external::remove_session($result1['sessionid']);
$this->assertCount(0, $DB->get_records('attendance_sessions', ['attendanceid' => $attendance['attendanceid']])); $this->assertCount(0, $DB->get_records('attendance_sessions', ['attendanceid' => $attendancenogroups['attendanceid']]));
} }
public function test_add_session_creates_calendar_event() { public function test_add_session_creates_calendar_event() {

2
version.php

@ -23,7 +23,7 @@
*/ */
defined('MOODLE_INTERNAL') || die(); defined('MOODLE_INTERNAL') || die();
$plugin->version = 2019072402; $plugin->version = 2019072403;
$plugin->requires = 2019052000; // Requires 3.7. $plugin->requires = 2019052000; // Requires 3.7.
$plugin->release = '3.7.1'; $plugin->release = '3.7.1';
$plugin->maturity = MATURITY_STABLE; $plugin->maturity = MATURITY_STABLE;

Loading…
Cancel
Save