Browse Source

Moodle 32 - Global Search issue with Database Schema (#248)

* Fixes #243 - Adds the fields '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_32_STABLE
Daniel Thee Roperto 8 years ago
committed by Dan Marsden
parent
commit
b79dac055f
  1. 80
      classes/header.php
  2. 6
      classes/structure.php
  3. 4
      db/install.xml
  4. 19
      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);
}
}

6
classes/structure.php

@ -56,6 +56,12 @@ class mod_attendance_structure {
/** @var int last time attendance was modified - used for global search */ /** @var int last time attendance was modified - used for global search */
public $timemodified; 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 */ /** current page parameters */
public $pageparams; public $pageparams;

4
db/install.xml

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?> <?xml version="1.0" encoding="UTF-8" ?>
<XMLDB PATH="mod/attendance/db" VERSION="20161107" 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" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd" xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd"
> >
@ -11,6 +11,8 @@
<FIELD NAME="name" TYPE="char" LENGTH="255" NOTNULL="false" 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="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="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."/>
<FIELD NAME="subnet" TYPE="char" LENGTH="255" NOTNULL="false" SEQUENCE="false" COMMENT="Restrict ability for students to mark by subnet."/> <FIELD NAME="subnet" TYPE="char" LENGTH="255" NOTNULL="false" SEQUENCE="false" COMMENT="Restrict ability for students to mark by subnet."/>
<FIELD NAME="sessiondetailspos" TYPE="char" LENGTH="5" NOTNULL="true" DEFAULT="left" SEQUENCE="false" COMMENT="Position for the session detail columns related to summary columns."/> <FIELD NAME="sessiondetailspos" TYPE="char" LENGTH="5" NOTNULL="true" DEFAULT="left" SEQUENCE="false" COMMENT="Position for the session detail columns related to summary columns."/>
<FIELD NAME="showsessiondetails" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="1" SEQUENCE="false" COMMENT="Define if session details should be shown in reports."/> <FIELD NAME="showsessiondetails" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="1" SEQUENCE="false" COMMENT="Define if session details should be shown in reports."/>

19
db/upgrade.php

@ -214,5 +214,24 @@ function xmldb_attendance_upgrade($oldversion=0) {
upgrade_mod_savepoint(true, 2016121300, 'attendance'); upgrade_mod_savepoint(true, 2016121300, 'attendance');
} }
if ($oldversion < 2016121305) {
// 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, 2016121305, 'attendance');
}
return $result; return $result;
} }

2
lib.php

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

6
manage.php

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

2
mod_form.php

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

17
renderer.php

@ -697,6 +697,23 @@ class mod_attendance_renderer extends plugin_renderer_base {
return $celldata; 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) { protected function render_attendance_user_data(attendance_user_data $userdata) {
$o = $this->render_user_report_tabs($userdata); $o = $this->render_user_report_tabs($userdata);

7
report.php

@ -73,13 +73,14 @@ $event->add_record_snapshot('course_modules', $cm);
$event->add_record_snapshot('attendance', $attrecord); $event->add_record_snapshot('attendance', $attrecord);
$event->trigger(); $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->header();
echo $output->heading(get_string('attendanceforthecourse', 'attendance').' :: ' .format_string($course->fullname)); echo $output->render($header);
echo $output->render($tabs); echo $output->render($tabs);
echo $output->render($filtercontrols); echo $output->render($filtercontrols);
echo $output->render($reportdata); echo $output->render($reportdata);
echo $output->footer(); echo $output->footer();

4
version.php

@ -23,9 +23,9 @@
*/ */
defined('MOODLE_INTERNAL') || die(); defined('MOODLE_INTERNAL') || die();
$plugin->version = 2016121303; $plugin->version = 2016121305;
$plugin->requires = 2016111800; $plugin->requires = 2016111800;
$plugin->release = '3.2.4'; $plugin->release = '3.2.5';
$plugin->maturity = MATURITY_STABLE; $plugin->maturity = MATURITY_STABLE;
$plugin->cron = 0; $plugin->cron = 0;
$plugin->component = 'mod_attendance'; $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); $userdata = new attendance_user_data($att, $userid);
$header = new mod_attendance_header($att);
echo $output->header(); echo $output->header();
echo $output->render($header);
echo $output->render($userdata); echo $output->render($userdata);
echo $output->footer(); echo $output->footer();

Loading…
Cancel
Save