diff --git a/classes/event/report_viewed.php b/classes/event/report_viewed.php new file mode 100644 index 0000000000000000000000000000000000000000..5be03c79f68bdb0b0f0425560c5472ffb20ef407 --- /dev/null +++ b/classes/event/report_viewed.php @@ -0,0 +1,39 @@ +<?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/>. + +/** + * The report_viewed event. + * + * @package learning_analytics + * @copyright 2014 YOUR NAME + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +namespace local_learning_analytics\event; +defined('MOODLE_INTERNAL') || die(); +class report_viewed extends \core\event\base { + + protected function init() { + $this->data['crud'] = 'r'; + $this->data['edulevel'] = self::LEVEL_OTHER; + $this->data['objecttable'] = 'local_learning_analytics_rep'; + } + + protected function validate_data() { + if (!isset($this->data['objecttable'])) { + throw new \coding_exception('The objecttable must be set in $data.'); + } + } +} \ No newline at end of file diff --git a/classes/router.php b/classes/router.php index 0cc289ed71d6fb368b76322aed0c07bad0da0a39..f6a8a138a31456c0caf25d825244bcd93dd3612b 100644 --- a/classes/router.php +++ b/classes/router.php @@ -28,6 +28,7 @@ namespace local_learning_analytics; use moodle_url; use core_component; use html_writer; +use local_learning_analytics\event\report_viewed; defined('MOODLE_INTERNAL') || die; @@ -40,6 +41,7 @@ class router { string $pagename = null ) : string { global $PAGE; + global $DB; $outputs = $instance->run($params); @@ -61,6 +63,15 @@ class router { $renderer = $PAGE->get_renderer('local_learning_analytics'); $ret .= $renderer->render_output_list($outputs); $ret .= "</div>"; + + $objectid = $DB->get_record_select('local_learning_analytics_rep', "reportname='{$reportname}'")->id; + $event = report_viewed::create(array( + 'contextid' => $PAGE->context->id, + 'objectid' => $objectid + )); + $event->add_record_snapshot('course', $PAGE->course); + $event->trigger(); + return $ret; } diff --git a/db/install.php b/db/install.php new file mode 100644 index 0000000000000000000000000000000000000000..220dfb6dede331eac46818d5a2c5d6a184649832 --- /dev/null +++ b/db/install.php @@ -0,0 +1,46 @@ +<?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/>. + + /** + * Main entry point for Learning Analytics UI + * + * @package local_learning_analytics + * @copyright Lehr- und Forschungsgebiet Ingenieurhydrologie - RWTH Aachen University + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + + //define('CLI_SCRIPT', true); + + global $DB; + $datas = $DB->get_records('local_learning_analytics_rep'); + $dataarray = array(); + foreach($datas as $data){ + array_push($dataarray, $data->reportname); + } + $insertarray = array(); + $reports = array('coursedashboard', 'activities', 'learners', 'browser_os'); + foreach($reports as $report) { + if(!in_array($report, $dataarray)) { + array_push($insertarray, set_entry($report)); + } + } + $DB->insert_records('local_learning_analytics_rep', $insertarray); + + function set_entry($report) { + $entr = new \stdClass(); + $entr->reportname = $report; + return $entr; + } \ No newline at end of file diff --git a/db/install.xml b/db/install.xml index 090781a01f87e0a247a920806480532b5c55ef9a..3f167ade03aabf2ff9d5fd948544f3dc463448c8 100644 --- a/db/install.xml +++ b/db/install.xml @@ -17,5 +17,15 @@ <INDEX NAME="courseid_prevcourseid_idx" UNIQUE="true" FIELDS="courseid, prevcourseid"/> </INDEXES> </TABLE> + + <TABLE NAME="local_learning_analytics_rep" COMMENT="Previous course"> + <FIELDS> + <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/> + <FIELD NAME="reportname" TYPE="text" NOTNULL="true" SEQUENCE="false"/> + </FIELDS> + <KEYS> + <KEY NAME="primary" TYPE="primary" FIELDS="id"/> + </KEYS> + </TABLE> </TABLES> -</XMLDB> +</XMLDB> \ No newline at end of file diff --git a/index.php b/index.php index 4de0c0c1395b8b375bd7bfe874f58e0e6872a059..ce4f9398f77a28989115b026e774536a58fc708f 100644 --- a/index.php +++ b/index.php @@ -61,7 +61,6 @@ $PAGE->requires->css('/local/learning_analytics/static/styles.css'); $mainoutput = $output->render_from_template('local_learning_analytics/course', [ 'content' => $resultinghtml ]); - echo $output->header(); echo $mainoutput; echo $output->footer(); diff --git a/version.php b/version.php index 02104012efd50065563840af22ddd807e5b933a0..61cc42073b659bc8679cbadaa6c0d7722a1a1b62 100644 --- a/version.php +++ b/version.php @@ -26,7 +26,7 @@ defined('MOODLE_INTERNAL') || die; $plugin->component = 'local_learning_analytics'; -$plugin->version = 2020030601; +$plugin->version = 2020032000; $plugin->release = 'v0.1.0-dev'; $plugin->maturity = MATURITY_ALPHA;