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 8472bbd..7efcc4c 100644 --- a/classes/structure.php +++ b/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; diff --git a/db/install.xml b/db/install.xml index bf40a99..df03af5 100644 --- a/db/install.xml +++ b/db/install.xml @@ -1,8 +1,8 @@ - + @@ -10,6 +10,9 @@ + + + @@ -30,7 +33,7 @@ - + @@ -102,4 +105,4 @@
-
\ No newline at end of file +
diff --git a/db/upgrade.php b/db/upgrade.php index 3494fde..4fe8d79 100644 --- a/db/upgrade.php +++ b/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; } diff --git a/lib.php b/lib.php index f484a6f..0b4cb8d 100644 --- a/lib.php +++ b/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. diff --git a/manage.php b/manage.php index 5623013..3a320d5 100644 --- a/manage.php +++ b/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); diff --git a/mod_form.php b/mod_form.php index 6cd15f7..450c181 100644 --- a/mod_form.php +++ b/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(); diff --git a/renderer.php b/renderer.php index 1c57c04..325ab87 100644 --- a/renderer.php +++ b/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); diff --git a/report.php b/report.php index a785ba5..5d2e0fa 100644 --- a/report.php +++ b/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(); diff --git a/version.php b/version.php index 4ed5a32..3fc82dd 100644 --- a/version.php +++ b/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'; 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();