Browse Source

Moodle 31 - Global Search issue with Database Schema (#247)

* Fixes #216 and #243 - Adds the fields 'timemodified', 'intro' and 'introformat' in the attendance table.

This is done according to https://docs.moodle.org/dev/Activity_modules#install.xml

* Added 'intro' field. If not empty it will add a header (title + intro) in the view page and will be displayed in manage and report pages.
MOODLE_31_STABLE
Daniel Thee Roperto 8 years ago
committed by Dan Marsden
parent
commit
15792f7646
  1. 80
      classes/header.php
  2. 9
      classes/structure.php
  3. 9
      db/install.xml
  4. 29
      db/upgrade.php
  5. 2
      lib.php
  6. 6
      manage.php
  7. 2
      mod_form.php
  8. 17
      renderer.php
  9. 7
      report.php
  10. 4
      version.php
  11. 2
      view.php

80
classes/header.php

@ -0,0 +1,80 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Class definition for mod_attendance_header
*
* @package mod_attendance
* @author Daniel Thee Roperto <daniel.roperto@catalyst-au.net>
* @copyright 2017 Catalyst IT Australia {@link http://www.catalyst-au.net}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
/**
* Used to render the page header.
*
* @package mod_attendance
* @author Daniel Thee Roperto <daniel.roperto@catalyst-au.net>
* @copyright 2017 Catalyst IT Australia {@link http://www.catalyst-au.net}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class mod_attendance_header implements renderable {
/** @var mod_attendance_structure */
private $attendance;
/** @var string */
private $title;
/**
* mod_attendance_header constructor.
*
* @param mod_attendance_structure $attendance
* @param null $title
*/
public function __construct(mod_attendance_structure $attendance, $title = null) {
$this->attendance = $attendance;
$this->title = $title;
}
/**
* Gets the attendance data.
*
* @return mod_attendance_structure
*/
public function get_attendance() {
return $this->attendance;
}
/**
* Gets the title. If title was not provided, use the module name.
*
* @return string
*/
public function get_title() {
return is_null($this->title) ? $this->attendance->name : $this->title;
}
/**
* Checks if the header should be rendered.
*
* @return bool
*/
public function should_render() {
return !is_null($this->title) || !empty($this->attendance->intro);
}
}

9
classes/structure.php

@ -52,6 +52,15 @@ class mod_attendance_structure {
/** @var float number (10, 5) unsigned, the maximum grade for attendance */
public $grade;
/** @var int when was this module last modified */
public $timemodified;
/** @var string required field for activity modules and searching */
public $intro;
/** @var int format of the intro (see above) */
public $introformat;
/** current page parameters */
public $pageparams;

9
db/install.xml

@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8" ?>
<XMLDB PATH="mod/attendance/db" VERSION="20130704" COMMENT="XMLDB file for Moodle mod/attendance"
<XMLDB PATH="mod/attendance/db" VERSION="20170307" COMMENT="XMLDB file for Moodle mod/attendance"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd"
>
>
<TABLES>
<TABLE NAME="attendance" COMMENT="Attendance module table">
<FIELDS>
@ -10,6 +10,9 @@
<FIELD NAME="course" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="name" TYPE="char" LENGTH="255" NOTNULL="false" SEQUENCE="false"/>
<FIELD NAME="grade" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="100" SEQUENCE="false" COMMENT="This is maximum grade for instance"/>
<FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="The time the settings for this attendance instance were last modified."/>
<FIELD NAME="intro" TYPE="text" NOTNULL="false" SEQUENCE="false" COMMENT="This field is a requirement for activity modules."/>
<FIELD NAME="introformat" TYPE="int" LENGTH="4" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="This field is a requirement for activity modules."/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id" COMMENT="Primary key for attendance"/>
@ -30,7 +33,7 @@
<FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false"/>
<FIELD NAME="description" TYPE="text" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="descriptionformat" TYPE="int" LENGTH="2" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="studentscanmark" TYPE="int" LENGTH="1" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="studentscanmark" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="statusset" TYPE="int" LENGTH="5" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="Which set of statuses to use"/>
<FIELD NAME="caleventid" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
</FIELDS>

29
db/upgrade.php

@ -177,5 +177,34 @@ function xmldb_attendance_upgrade($oldversion=0) {
upgrade_mod_savepoint(true, 2016052202, 'attendance');
}
if ($oldversion < 2016052203) {
// Define field timemodified to be added to attendance.
$table = new xmldb_table('attendance');
$field = new xmldb_field('timemodified', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'grade');
// Conditionally launch add field timemodified.
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
// Define field timemodified to be added to attendance.
$table = new xmldb_table('attendance');
$fields = [];
$fields[] = new xmldb_field('intro', XMLDB_TYPE_TEXT, null, null, null, null, null, 'timemodified');
$fields[] = new xmldb_field('introformat', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, 0, 'intro');
// Conditionally launch add field.
foreach ($fields as $field) {
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
}
// Attendance savepoint reached.
upgrade_mod_savepoint(true, 2016052203, 'attendance');
}
return $result;
}

2
lib.php

@ -42,7 +42,7 @@ function attendance_supports($feature) {
case FEATURE_GROUPMEMBERSONLY:
return true;
case FEATURE_MOD_INTRO:
return false;
return true;
case FEATURE_BACKUP_MOODLE2:
return true;
// Artem Andreev: AFAIK it's not tested.

6
manage.php

@ -83,10 +83,14 @@ $tabs = new attendance_tabs($att, attendance_tabs::TAB_SESSIONS);
$filtercontrols = new attendance_filter_controls($att);
$sesstable = new attendance_manage_data($att);
$title = get_string('attendanceforthecourse', 'attendance').' :: ' .format_string($course->fullname);
$header = new mod_attendance_header($att, $title);
// Output starts here.
echo $output->header();
echo $output->heading(get_string('attendanceforthecourse', 'attendance').' :: ' .format_string($course->fullname));
echo $output->render($header);
mod_attendance_notifyqueue::show();
echo $output->render($tabs);
echo $output->render($filtercontrols);

2
mod_form.php

@ -51,6 +51,8 @@ class mod_attendance_mod_form extends moodleform_mod {
$mform->addRule('name', null, 'required', null, 'client');
$mform->setDefault('name', get_string('modulename', 'attendance'));
$this->standard_intro_elements();
// Grade settings.
$this->standard_grading_coursemodule_elements();

17
renderer.php

@ -696,6 +696,23 @@ class mod_attendance_renderer extends plugin_renderer_base {
return $celldata;
}
protected function render_mod_attendance_header(mod_attendance_header $header) {
if (!$header->should_render()) {
return '';
}
$attendance = $header->get_attendance();
$heading = format_string($header->get_title(), false, ['context' => $attendance->context]);
$o = $this->output->heading($heading);
$o .= $this->output->box_start('generalbox boxaligncenter', 'intro');
$o .= format_module_intro('attendance', $attendance, $attendance->cm->id);
$o .= $this->output->box_end();
return $o;
}
protected function render_attendance_user_data(attendance_user_data $userdata) {
$o = $this->render_user_report_tabs($userdata);

7
report.php

@ -71,13 +71,14 @@ $event->add_record_snapshot('course_modules', $cm);
$event->add_record_snapshot('attendance', $attrecord);
$event->trigger();
// Output starts here.
$title = get_string('attendanceforthecourse', 'attendance').' :: ' .format_string($course->fullname);
$header = new mod_attendance_header($att, $title);
// Output starts here.
echo $output->header();
echo $output->heading(get_string('attendanceforthecourse', 'attendance').' :: ' .format_string($course->fullname));
echo $output->render($header);
echo $output->render($tabs);
echo $output->render($filtercontrols);
echo $output->render($reportdata);
echo $output->footer();

4
version.php

@ -22,9 +22,9 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$plugin->version = 2016052202;
$plugin->version = 2016052203;
$plugin->requires = 2016052300;
$plugin->release = '3.1.1.0';
$plugin->release = '3.1.1.3';
$plugin->maturity = MATURITY_STABLE;
$plugin->cron = 0;
$plugin->component = 'mod_attendance';

2
view.php

@ -78,9 +78,11 @@ if (isset($pageparams->studentid) && $USER->id != $pageparams->studentid) {
}
$userdata = new attendance_user_data($att, $userid);
$header = new mod_attendance_header($att);
echo $output->header();
echo $output->render($header);
echo $output->render($userdata);
echo $output->footer();

Loading…
Cancel
Save