From b79dac055f8912d76ab6b866f3f1cf0f120e955f Mon Sep 17 00:00:00 2001 From: Daniel Thee Roperto Date: Wed, 8 Mar 2017 16:32:33 +1100 Subject: [PATCH] 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. --- classes/header.php | 80 +++++++++++++++++++++++++++++++++++++++++++ classes/structure.php | 6 ++++ db/install.xml | 4 ++- db/upgrade.php | 19 ++++++++++ lib.php | 2 +- manage.php | 6 +++- mod_form.php | 2 ++ renderer.php | 17 +++++++++ report.php | 7 ++-- version.php | 4 +-- view.php | 2 ++ 11 files changed, 141 insertions(+), 8 deletions(-) create mode 100644 classes/header.php diff --git a/classes/header.php b/classes/header.php new file mode 100644 index 0000000..612e6a3 --- /dev/null +++ b/classes/header.php @@ -0,0 +1,80 @@ +. + +/** + * Class definition for mod_attendance_header + * + * @package mod_attendance + * @author Daniel Thee Roperto + * @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 + * @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); + } +} diff --git a/classes/structure.php b/classes/structure.php index e5386d2..4030a9e 100644 --- a/classes/structure.php +++ b/classes/structure.php @@ -56,6 +56,12 @@ class mod_attendance_structure { /** @var int last time attendance was modified - used for global search */ 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; diff --git a/db/install.xml b/db/install.xml index 5b8bf56..13d1b9e 100644 --- a/db/install.xml +++ b/db/install.xml @@ -1,5 +1,5 @@ - @@ -11,6 +11,8 @@ + + diff --git a/db/upgrade.php b/db/upgrade.php index 3c28bd4..804671f 100644 --- a/db/upgrade.php +++ b/db/upgrade.php @@ -214,5 +214,24 @@ function xmldb_attendance_upgrade($oldversion=0) { 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; } diff --git a/lib.php b/lib.php index f1cd0fc..c18ecc2 100644 --- a/lib.php +++ b/lib.php @@ -43,7 +43,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. diff --git a/manage.php b/manage.php index a85d711..c8b5514 100644 --- a/manage.php +++ b/manage.php @@ -82,10 +82,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); diff --git a/mod_form.php b/mod_form.php index 7ad84d0..dc1e9e7 100644 --- a/mod_form.php +++ b/mod_form.php @@ -52,6 +52,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(); diff --git a/renderer.php b/renderer.php index e7ce42d..5a5e8c5 100644 --- a/renderer.php +++ b/renderer.php @@ -697,6 +697,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); diff --git a/report.php b/report.php index d98f437..f0c5439 100644 --- a/report.php +++ b/report.php @@ -73,13 +73,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(); diff --git a/version.php b/version.php index fcbd108..dd0bd57 100644 --- a/version.php +++ b/version.php @@ -23,9 +23,9 @@ */ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2016121303; +$plugin->version = 2016121305; $plugin->requires = 2016111800; -$plugin->release = '3.2.4'; +$plugin->release = '3.2.5'; $plugin->maturity = MATURITY_STABLE; $plugin->cron = 0; $plugin->component = 'mod_attendance'; diff --git a/view.php b/view.php index 6225b87..97c05e7 100644 --- a/view.php +++ b/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();