diff --git a/filter/kaltura/classes/event/kaltura_media_viewed.php b/filter/kaltura/classes/event/kaltura_media_viewed.php
new file mode 100644
index 00000000..3e395419
--- /dev/null
+++ b/filter/kaltura/classes/event/kaltura_media_viewed.php
@@ -0,0 +1,92 @@
+.
+
+/**
+ * Kaltura media viewed.
+ *
+ * @package filter_kaltura
+ * @copyright 2021 The Open University
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+namespace filter_kaltura\event;
+
+defined('MOODLE_INTERNAL') || die();
+
+/**
+ * View kaltura media in filter
+ *
+ * @property-read array $other {
+ * Extra information about event.
+ * - string sourceurl: (required) source media url.
+ * }
+ *
+ * @package filter_kaltura
+ * @copyright 2021 The Open University
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class kaltura_media_viewed extends \core\event\base {
+
+ /**
+ * Init method.
+ */
+ protected function init() {
+ $this->data['crud'] = 'r';
+ $this->data['edulevel'] = self::LEVEL_PARTICIPATING;
+ }
+
+ /**
+ * Returns localised general event name.
+ *
+ * @return string
+ */
+ public static function get_name() {
+ return get_string('kalturamediaviewed', 'filter_kaltura');
+ }
+
+ /**
+ * Returns description of what happened.
+ *
+ * @return string
+ */
+ public function get_description() {
+ return 'The user with id ' . $this->userid . ' viewed video with source url' . $this->other['sourceurl']
+ . 'embed in context ' . $this->contextid;
+ }
+
+ protected function validate_data() {
+ if (empty($this->other['sourceurl'])) {
+ throw new \coding_exception('Missing source url');
+ }
+ }
+
+ /**
+ * Gets data for use when logging to old log table.
+ *
+ * @return array Data to be passed to the legacy add_to_log function
+ */
+ public function get_legacy_logdata() {
+ $context = $this->get_context();
+
+ $info = $this->userid . ':' . $this->other['sourceurl'] . ':' .
+ $this->context->id;
+ if (\core_text::strlen($info) > 255) {
+ $info = \core_text::substr($info, 0, 255);
+ }
+ return [$context->id, 'filter_kaltura', 'kalturamediaviewed',
+ $this->other['sourceurl'], $info, $context->instanceid];
+ }
+}
diff --git a/filter/kaltura/db/access.php b/filter/kaltura/db/access.php
new file mode 100644
index 00000000..8d318257
--- /dev/null
+++ b/filter/kaltura/db/access.php
@@ -0,0 +1,33 @@
+.
+
+/**
+ * @package filter_kaltura
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+$capabilities = [
+ 'filter/kaltura:view' => [
+ 'captype' => 'read',
+ 'contextlevel' => CONTEXT_COURSE,
+ 'archetypes' => [
+ 'student' => CAP_ALLOW,
+ 'editingteacher' => CAP_ALLOW,
+ 'teacher' => CAP_ALLOW,
+ 'manager' => CAP_ALLOW
+ ]
+ ]
+];
diff --git a/filter/kaltura/filter.php b/filter/kaltura/filter.php
index a78209a7..3800178c 100644
--- a/filter/kaltura/filter.php
+++ b/filter/kaltura/filter.php
@@ -128,29 +128,6 @@ public function filter($text, array $options = array()) {
$kafuri = str_replace(array('http://', 'https://', '.', '/'), array('https?://', 'https?://', '\.', '\/'), $kafuri);
$search = $search = '/]*href="(((https?:\/\/'.KALTURA_URI_TOKEN.')|('.$kafuri.')))\/browseandembed\/index\/media\/entryid\/([\d]+_[a-z0-9]+)(\/([a-zA-Z0-9]+\/[a-zA-Z0-9]+\/)*)"[^>]*>([^>]*)<\/a>/is';
-
- if (!empty($CFG->filter_kaltura_uris)) {
- $altkafuriconfig = $CFG->filter_kaltura_uris;
- $altkafuris = explode(PHP_EOL, $altkafuriconfig);
-
- $search = $search = '/]*href="(((https?:\/\/'.KALTURA_URI_TOKEN.')|('.$kafuri.')';
-
- foreach ($altkafuris as $altkafuri) {
- $altkafuri = rtrim($altkafuri);
- if ($altkafuri != '') {
- // If a https url is needed for kaf_uri it should be entered into the kaf_uri setting as https://.
- if (!preg_match('#^https?://#', $altkafuri)) {
- $altkafuri = 'http://' . $altkafuri;
- }
-
- $altkafuri = str_replace(array('http://', 'https://', '.', '/'), array('https?://', 'https?://', '\.', '\/'), $altkafuri);
- $search .= '|('.$altkafuri.')';
- }
- }
-
- $search .= '))\/browseandembed\/index\/media\/entryid\/([\d]+_[a-z0-9]+)(\/([a-zA-Z0-9]+\/[a-zA-Z0-9]+\/)*)"[^>]*>([^>]*)<\/a>/is';
- }
-
$newtext = preg_replace_callback($search, 'filter_kaltura_callback', $newtext);
if (empty($newtext) || $newtext === $text) {
@@ -169,6 +146,7 @@ public function filter($text, array $options = array()) {
* @return string Kaltura embed video markup.
*/
function filter_kaltura_callback($link) {
+ global $PAGE;
$width = filter_kaltura::$defaultwidth;
$height = filter_kaltura::$defaultheight;
$source = '';
@@ -200,8 +178,8 @@ function filter_kaltura_callback($link) {
'height' => $height,
'width' => $width,
'withblocks' => 0,
- 'source' => $source
-
+ 'source' => $source,
+ 'embedcontextid' => $PAGE->context->id
);
$url = new moodle_url('/filter/kaltura/lti_launch.php', $params);
diff --git a/filter/kaltura/filtersettings.php b/filter/kaltura/filtersettings.php
index 482cb33e..500b53a1 100644
--- a/filter/kaltura/filtersettings.php
+++ b/filter/kaltura/filtersettings.php
@@ -28,7 +28,7 @@
if ($ADMIN->fulltree) {
$settings->add(new admin_setting_configcheckbox('filter_kaltura_enable', get_string('enable', 'filter_kaltura'), get_string('enable_help', 'filter_kaltura'), 1));
- $settings->add(new admin_setting_configtextarea('filter_kaltura_uris',
- get_string('uris', 'filter_kaltura'),
- get_string('uris_help', 'filter_kaltura'), ''));
+ $adminsetting = new admin_setting_configcheckbox('enable_moodle_logging', get_string('moodle_trace_log', 'filter_kaltura'),
+ get_string('moodle_trace_log_desc', 'filter_kaltura'), 0);
+ $settings->add($adminsetting);
}
\ No newline at end of file
diff --git a/filter/kaltura/lang/en/filter_kaltura.php b/filter/kaltura/lang/en/filter_kaltura.php
index 83a169e7..48dcbc87 100644
--- a/filter/kaltura/lang/en/filter_kaltura.php
+++ b/filter/kaltura/lang/en/filter_kaltura.php
@@ -24,9 +24,14 @@
*/
$string['filtername'] = 'Kaltura Media';
+$string['pluginname'] = 'Kaltura Media Filter';
$string['enable'] = 'Embed Kaltura Video Links';
$string['enable_help'] = 'Convert Kaltura video links to embed code';
+$string['moodle_trace_log'] = 'Enable moodle trace logging';
+$string['moodle_trace_log_desc'] = 'If enabled, all requests and responses to and from Kaltura are logged into Moodle logging system.';
+$string['kalturamediaviewed'] = 'Kaltura media viewed';
$string['uris'] = 'Alternate KAF URIs';
$string['uris_help'] = 'Enter alternate KAF URIs to filter, one per line';
$string['unable'] = 'Unable to convert video at this time';
$string['privacy:metadata'] = 'The Kaltura Media filter does not store any personal data.';
+$string['kaltura:view'] = 'Permission for user can filter Embed Kaltura Video Links';
diff --git a/filter/kaltura/lti_launch.php b/filter/kaltura/lti_launch.php
index 9df539c9..8e948861 100644
--- a/filter/kaltura/lti_launch.php
+++ b/filter/kaltura/lti_launch.php
@@ -35,6 +35,7 @@
$width = required_param('width', PARAM_INT);
$withblocks = optional_param('withblocks', 0, PARAM_INT);
$source = optional_param('source', '', PARAM_URL);
+$embedcontextid = optional_param('embedcontextid', 0, PARAM_INT);
// If a course id of zero is passed, then we must be in the system context.
if (0 != $courseid) {
@@ -47,8 +48,8 @@
if ($context instanceof context_course) {
$course = get_course($courseid);
- // Check if the user has the capability to view comments in Moodle.
- if (!has_capability('moodle/comment:view', $context)) {
+ // Check if the user has the capability to view kaltura media.
+ if (!has_capability('filter/kaltura:view', $context)) {
echo get_string('nocapabilitytousethisservice', 'error');
die();
}
@@ -76,6 +77,12 @@
if (local_kaltura_validate_browseembed_required_params($launch)) {
$content = local_kaltura_request_lti_launch($launch, $withblocks);
echo $content;
+ // Check if Moodle logging is enabled.
+ $enablemoodlelogging = get_config(KALTURA_PLUGIN_NAME, 'enable_moodle_logging');
+ if (!empty($enablemoodlelogging) && $embedcontextid) {
+ $event = filter_kaltura\event\kaltura_media_viewed::create(['sourceurl' => $source, 'contextid' => $embedcontextid]);
+ $event->trigger();
+ }
} else {
echo get_string('invalid_launch_parameters', 'mod_kalvidres');
-}
\ No newline at end of file
+}
diff --git a/filter/kaltura/tests/events_test.php b/filter/kaltura/tests/events_test.php
new file mode 100644
index 00000000..1136612e
--- /dev/null
+++ b/filter/kaltura/tests/events_test.php
@@ -0,0 +1,67 @@
+.
+
+/**
+ * Contains the event tests for the plugin.
+ *
+ * @package filter_kaltura
+ * @copyright 2021 The Open University
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+defined('MOODLE_INTERNAL') || die();
+
+global $CFG;
+
+/**
+ * Contains the event tests for the plugin.
+ *
+ * @package filter_kaltura
+ * @copyright 2021 The Open University
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class filter_kaltura_events_testcase extends advanced_testcase {
+
+ /**
+ * Tests (media_gallery_viewed)
+ */
+ public function test_media_gallery_viewed() {
+ $this->resetAfterTest();
+ $generator = $this->getDataGenerator();
+ $user = $generator->create_user();
+ $course = $generator->create_course();
+ $this->setUser($user);
+
+ $context = context_course::instance($course->id);
+
+ // Create a basic event.
+ $event = \local_kalturamediagallery\event\media_gallery_viewed::create([
+ 'context' => $context,
+ 'other' => [
+ 'coursename' => $course->fullname,
+ 'courseid' => $course->id,
+ ]]);
+
+ // Check name (generic).
+ $this->assertEquals(get_string('eventviewmediagallry', 'local_kalturamediagallery'), $event->get_name());
+ $this->assertEquals('The user with id ' . $user->id . ' viewed ' . $course->fullname . ' media gallery in context ' . $context->id
+ . ' with courseid ' . $course->id, $event->get_description());
+ $info = $user->id . ':' . $course->fullname . ':' . $context->id . ':' . $course->id;
+ $this->assertEquals([$context->id, 'local_kalturamediagallery', 'eventviewmediagallry',
+ 'local/kalturamediagallery/index.php?courseid=' . $course->id, $info, $context->instanceid], $event->get_legacy_logdata());
+ }
+
+}
diff --git a/lib/editor/atto/plugins/kalturamedia/lang/en/atto_kalturamedia.php b/lib/editor/atto/plugins/kalturamedia/lang/en/atto_kalturamedia.php
index 9021aef7..38cc855f 100644
--- a/lib/editor/atto/plugins/kalturamedia/lang/en/atto_kalturamedia.php
+++ b/lib/editor/atto/plugins/kalturamedia/lang/en/atto_kalturamedia.php
@@ -27,3 +27,4 @@
$string['embedbuttontext'] = 'Embed';
$string['browse_and_embed'] = 'Browse and Embed';
$string['privacy:metadata'] = 'The atto_kalturamedia plugin does not store any personal data.';
+$string['kalturamedia:view'] = 'Permission to use Embed Kaltura Media atto plugin';
diff --git a/lib/editor/atto/plugins/kalturamedia/lib.php b/lib/editor/atto/plugins/kalturamedia/lib.php
index b40b177a..8491f30a 100644
--- a/lib/editor/atto/plugins/kalturamedia/lib.php
+++ b/lib/editor/atto/plugins/kalturamedia/lib.php
@@ -39,8 +39,11 @@ function atto_kalturamedia_params_for_js($elementid, $options, $fpoptions) {
if (!$context) {
$context = context_system::instance();
}
-
+
+ $active = has_capability('atto/kalturamedia:view', $context);
+
return array(
+ 'active' => $active,
'contextid' => $context->id,
'kafuri' => local_kaltura_get_config()->kaf_uri
);
diff --git a/lib/editor/atto/plugins/kalturamedia/version.php b/lib/editor/atto/plugins/kalturamedia/version.php
index ebb6728a..d25f5ffa 100644
--- a/lib/editor/atto/plugins/kalturamedia/version.php
+++ b/lib/editor/atto/plugins/kalturamedia/version.php
@@ -24,7 +24,7 @@
defined('MOODLE_INTERNAL') || die();
-$plugin->version = 2021051701; // The current plugin version (Date: YYYYMMDDXX).
+$plugin->version = 2021051702; // The current plugin version (Date: YYYYMMDDXX).
$plugin->release = 'Kaltura release 4.3.1';
$plugin->requires = 2018120300; // Requires this Moodle version.
$plugin->component = 'atto_kalturamedia'; // Full name of the plugin (used for diagnostics).
diff --git a/lib/editor/atto/plugins/kalturamedia/yui/build/moodle-atto_kalturamedia-button/moodle-atto_kalturamedia-button-debug.js b/lib/editor/atto/plugins/kalturamedia/yui/build/moodle-atto_kalturamedia-button/moodle-atto_kalturamedia-button-debug.js
index 2d22a45c..2d4b233e 100644
--- a/lib/editor/atto/plugins/kalturamedia/yui/build/moodle-atto_kalturamedia-button/moodle-atto_kalturamedia-button-debug.js
+++ b/lib/editor/atto/plugins/kalturamedia/yui/build/moodle-atto_kalturamedia-button/moodle-atto_kalturamedia-button-debug.js
@@ -1,155 +1,166 @@
YUI.add('moodle-atto_kalturamedia-button', function (Y, NAME) {
-// 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 .
-
-/*
- * @package atto_kalturamedia
- * @copyright 2Kaltura
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
-/**
- * @module moodle-atto_kalturamedia-button
- */
-
-/**
- * Atto text editor kalturamedia plugin.
- *
- * @namespace M.atto_kalturamedia
- * @class button
- * @extends M.editor_atto.EditorPlugin
- */
-
-var COMPONENTNAME = 'atto_kalturamedia',
- CSS = {
- URLINPUT: 'atto_kalturamedia_urlentry',
- NAMEINPUT: 'atto_kalturamedia_nameentry'
- },
- SELECTORS = {
- URLINPUT: '.' + CSS.URLINPUT,
- NAMEINPUT: '.' + CSS.NAMEINPUT
- };
-
-Y.namespace('M.atto_kalturamedia').Button = Y.Base.create('button', Y.M.editor_atto.EditorPlugin, [], {
- _currentSelection: null,
- embedWindow: null,
-
- initializer: function() {
- this.addButton({
- icon: 'icon',
- iconComponent: COMPONENTNAME,
- callback: this._kalturamedia
- });
- },
- _kalturamedia: function() {
- this._currentSelection = this.get('host').getSelection();
- if (this._currentSelection === false) {
- return;
- }
-
- var w = 1200;
- var h = 700;
- var dualScreenLeft = window.screenLeft != undefined ? window.screenLeft : screen.left;
- var dualScreenTop = window.screenTop != undefined ? window.screenTop : screen.top;
-
- var width = window.innerWidth ? window.innerWidth : document.documentElement.clientWidth ? document.documentElement.clientWidth : screen.width;
- var height = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight ? document.documentElement.clientHeight : screen.height;
-
- var left = ((width / 2) - (w / 2)) + dualScreenLeft;
- var top = ((height / 2) - (h / 2)) + dualScreenTop;
- var newWindow = window.open(this._getIframeURL(), M.util.get_string("browse_and_embed", COMPONENTNAME), 'scrollbars=no, width=' + w + ', height=' + h + ', top=' + top + ', left=' + left);
-
- window.buttonJs = this;
-
- if (window.focus) {
- newWindow.focus();
- }
-
- this.embedWindow = newWindow;
- },
-
- _getIframeURL: function() {
-
- var args = Y.mix({
- elementid: this.get('host').get('elementid'),
- contextid: this.get('contextid'),
- height: '600px',
- width: '1112px'
- },
- this.get('area'));
- return M.cfg.wwwroot + '/lib/editor/atto/plugins/kalturamedia/ltibrowse_container.php?' +
- Y.QueryString.stringify(args);
- },
-
- _getCourseId: function() {
- var courseId;
- var bodyClasses = document.getElementsByTagName('body')[0].className;
- var classes = bodyClasses.split(' ');
- for(i in classes)
- {
- if(classes[i].indexOf('course-') > -1)
- {
- var parts = classes[i].split('-');
- courseId = parts[1];
- }
- }
-
- return courseId;
- },
-
- _removeProtocolFromUrl: function(fullUrl) {
- return fullUrl.replace(/^https?:\/\//,'');
- },
-
- embedItem: function(what, data) {
- var sourceUrl = data.url;
- var url = this._removeProtocolFromUrl(sourceUrl);
- var parser = document.createElement('a');
- parser.href = sourceUrl;
- url += parser.search;
-
- var content = 'tinymce-kalturamedia-embed||'+data.title+'||'+data.width+'||'+data.height+'';
-
- host = this.get('host');
- host.setSelection(this._currentSelection);
- host.insertContentAtFocusPoint(content);
- this.markUpdated();
- this.embedWindow.close();
- }
-
- } , {
- ATTRS: {
- /**
- * The contextid to use when generating this preview.
- *
- * @attribute contextid
- * @type String
- */
- contextid: {
- value: null
- },
-
- /**
- * The KAF URI, as configured in Kaltura's plugin settings.
- */
- kafuri: {
- value: null
- }
- }}
-);
+// 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 .
+
+/*
+ * @package atto_kalturamedia
+ * @copyright 2Kaltura
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+/**
+ * @module moodle-atto_kalturamedia-button
+ */
+
+/**
+ * Atto text editor kalturamedia plugin.
+ *
+ * @namespace M.atto_kalturamedia
+ * @class button
+ * @extends M.editor_atto.EditorPlugin
+ */
+
+var COMPONENTNAME = 'atto_kalturamedia',
+ CSS = {
+ URLINPUT: 'atto_kalturamedia_urlentry',
+ NAMEINPUT: 'atto_kalturamedia_nameentry'
+ },
+ SELECTORS = {
+ URLINPUT: '.' + CSS.URLINPUT,
+ NAMEINPUT: '.' + CSS.NAMEINPUT
+ };
+
+Y.namespace('M.atto_kalturamedia').Button = Y.Base.create('button', Y.M.editor_atto.EditorPlugin, [], {
+ _currentSelection: null,
+ embedWindow: null,
+
+ initializer: function() {
+ if (this.get('active')) {
+ this.addButton({
+ icon: 'icon',
+ iconComponent: COMPONENTNAME,
+ callback: this._kalturamedia
+ });
+ }
+ },
+ _kalturamedia: function() {
+ this._currentSelection = this.get('host').getSelection();
+ if (this._currentSelection === false) {
+ return;
+ }
+
+ var w = 1200;
+ var h = 700;
+ var dualScreenLeft = window.screenLeft != undefined ? window.screenLeft : screen.left;
+ var dualScreenTop = window.screenTop != undefined ? window.screenTop : screen.top;
+
+ var width = window.innerWidth ? window.innerWidth : document.documentElement.clientWidth ? document.documentElement.clientWidth : screen.width;
+ var height = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight ? document.documentElement.clientHeight : screen.height;
+
+ var left = ((width / 2) - (w / 2)) + dualScreenLeft;
+ var top = ((height / 2) - (h / 2)) + dualScreenTop;
+ var newWindow = window.open(this._getIframeURL(), M.util.get_string("browse_and_embed", COMPONENTNAME), 'scrollbars=no, width=' + w + ', height=' + h + ', top=' + top + ', left=' + left);
+
+ window.buttonJs = this;
+
+ if (window.focus) {
+ newWindow.focus();
+ }
+
+ this.embedWindow = newWindow;
+ },
+
+ _getIframeURL: function() {
+
+ var args = Y.mix({
+ elementid: this.get('host').get('elementid'),
+ contextid: this.get('contextid'),
+ height: '600px',
+ width: '1112px'
+ },
+ this.get('area'));
+ return M.cfg.wwwroot + '/lib/editor/atto/plugins/kalturamedia/ltibrowse_container.php?' +
+ Y.QueryString.stringify(args);
+ },
+
+ _getCourseId: function() {
+ var courseId;
+ var bodyClasses = document.getElementsByTagName('body')[0].className;
+ var classes = bodyClasses.split(' ');
+ for(i in classes)
+ {
+ if(classes[i].indexOf('course-') > -1)
+ {
+ var parts = classes[i].split('-');
+ courseId = parts[1];
+ }
+ }
+
+ return courseId;
+ },
+
+ _removeProtocolFromUrl: function(fullUrl) {
+ return fullUrl.replace(/^https?:\/\//,'');
+ },
+
+ embedItem: function(what, data) {
+ var sourceUrl = data.url;
+ var url = this._removeProtocolFromUrl(sourceUrl);
+ var parser = document.createElement('a');
+ parser.href = sourceUrl;
+ url += parser.search;
+
+ var content = 'tinymce-kalturamedia-embed||'+data.title+'||'+data.width+'||'+data.height+'';
+
+ host = this.get('host');
+ host.setSelection(this._currentSelection);
+ host.insertContentAtFocusPoint(content);
+ this.markUpdated();
+ this.embedWindow.close();
+ }
+
+ } , {
+ ATTRS: {
+ /**
+ * Whether the button should be active.
+ *
+ * @attribute active
+ * @type Boolean
+ */
+ active: {
+ value: false
+ },
+ /**
+ * The contextid to use when generating this preview.
+ *
+ * @attribute contextid
+ * @type String
+ */
+ contextid: {
+ value: null
+ },
+
+ /**
+ * The KAF URI, as configured in Kaltura's plugin settings.
+ */
+ kafuri: {
+ value: null
+ }
+ }}
+);
}, '@VERSION@', {"requires": ["moodle-editor_atto-plugin"]});
diff --git a/lib/editor/atto/plugins/kalturamedia/yui/build/moodle-atto_kalturamedia-button/moodle-atto_kalturamedia-button-min.js b/lib/editor/atto/plugins/kalturamedia/yui/build/moodle-atto_kalturamedia-button/moodle-atto_kalturamedia-button-min.js
index 196c77e7..d7e4d614 100644
--- a/lib/editor/atto/plugins/kalturamedia/yui/build/moodle-atto_kalturamedia-button/moodle-atto_kalturamedia-button-min.js
+++ b/lib/editor/atto/plugins/kalturamedia/yui/build/moodle-atto_kalturamedia-button/moodle-atto_kalturamedia-button-min.js
@@ -1 +1 @@
-YUI.add("moodle-atto_kalturamedia-button",function(e,t){var n="atto_kalturamedia",r={URLINPUT:"atto_kalturamedia_urlentry",NAMEINPUT:"atto_kalturamedia_nameentry"},s={URLINPUT:"."+r.URLINPUT,NAMEINPUT:"."+r.NAMEINPUT};e.namespace("M.atto_kalturamedia").Button=e.Base.create("button",e.M.editor_atto.EditorPlugin,[],{_currentSelection:null,embedWindow:null,initializer:function(){this.addButton({icon:"icon",iconComponent:n,callback:this._kalturamedia})},_kalturamedia:function(){this._currentSelection=this.get("host").getSelection();if(this._currentSelection===!1)return;var e=1200,t=700,r=window.screenLeft!=undefined?window.screenLeft:screen.left,i=window.screenTop!=undefined?window.screenTop:screen.top,s=window.innerWidth?window.innerWidth:document.documentElement.clientWidth?document.documentElement.clientWidth:screen.width,o=window.innerHeight?window.innerHeight:document.documentElement.clientHeight?document.documentElement.clientHeight:screen.height,u=s/2-e/2+r,a=o/2-t/2+i,f=window.open(this._getIframeURL(),M.util.get_string("browse_and_embed",n),"scrollbars=no, width="+e+", height="+t+", top="+a+", left="+u);window.buttonJs=this,window.focus&&f.focus(),this.embedWindow=f},_getIframeURL:function(){var t=e.mix({elementid:this.get("host").get("elementid"),contextid:this.get("contextid"),height:"600px",width:"1112px"},this.get("area"));return M.cfg.wwwroot+"/lib/editor/atto/plugins/kalturamedia/ltibrowse_container.php?"+e.QueryString.stringify(t)},_getCourseId:function(){var e,t=document.getElementsByTagName("body")[0].className,n=t.split(" ");for(i in n)if(n[i].indexOf("course-")>-1){var r=n[i].split("-");e=r[1]}return e},_removeProtocolFromUrl:function(e){return e.replace(/^https?:\/\//,"")},embedItem:function(e,t){var n=t.url,r=this._removeProtocolFromUrl(n),i=document.createElement("a");i.href=n,r+=i.search;var s='tinymce-kalturamedia-embed||'+t.title+"||"+t.width+"||"+t.height+"";host=this.get("host"),host.setSelection(this._currentSelection),host.insertContentAtFocusPoint(s),this.markUpdated(),this.embedWindow.close()}},{ATTRS:{contextid:{value:null},kafuri:{value:null}}})},"@VERSION@",{requires:["moodle-editor_atto-plugin"]});
+YUI.add("moodle-atto_kalturamedia-button",function(t,e){var a="atto_kalturamedia";t.namespace("M.atto_kalturamedia").Button=t.Base.create("button",t.M.editor_atto.EditorPlugin,[],{_currentSelection:null,embedWindow:null,initializer:function(){this.get("active")&&this.addButton({icon:"icon",iconComponent:a,callback:this._kalturamedia})},_kalturamedia:function(){var e,t,i,n,o,r,d;this._currentSelection=this.get("host").getSelection(),!1!==this._currentSelection&&(e=1200,t=700,i=window.screenLeft!=undefined?window.screenLeft:screen.left,n=window.screenTop!=undefined?window.screenTop:screen.top,o=(window.innerWidth?window.innerWidth:document.documentElement.clientWidth?document.documentElement.clientWidth:screen.width)/2-e/2+i,r=(window.innerHeight?window.innerHeight:document.documentElement.clientHeight?document.documentElement.clientHeight:screen.height)/2-t/2+n,d=window.open(this._getIframeURL(),M.util.get_string("browse_and_embed",a),"scrollbars=no, width="+e+", height="+t+", top="+r+", left="+o),window.buttonJs=this,window.focus&&d.focus(),this.embedWindow=d)},_getIframeURL:function(){var e=t.mix({elementid:this.get("host").get("elementid"),contextid:this.get("contextid"),height:"600px",width:"1112px"},this.get("area"));return M.cfg.wwwroot+"/lib/editor/atto/plugins/kalturamedia/ltibrowse_container.php?"+t.QueryString.stringify(e)},_getCourseId:function(){var e,t=document.getElementsByTagName("body")[0].className,n=t.split(" ");for(i in n)-1tinymce-kalturamedia-embed||'+t.title+"||"+t.width+"||"+t.height+"",host=this.get("host"),host.setSelection(this._currentSelection),host.insertContentAtFocusPoint(i),this.markUpdated(),this.embedWindow.close()}},{ATTRS:{active:{value:!1},contextid:{value:null},kafuri:{value:null}}})},"@VERSION@",{requires:["moodle-editor_atto-plugin"]});
\ No newline at end of file
diff --git a/lib/editor/atto/plugins/kalturamedia/yui/build/moodle-atto_kalturamedia-button/moodle-atto_kalturamedia-button.js b/lib/editor/atto/plugins/kalturamedia/yui/build/moodle-atto_kalturamedia-button/moodle-atto_kalturamedia-button.js
index 2d22a45c..2d4b233e 100644
--- a/lib/editor/atto/plugins/kalturamedia/yui/build/moodle-atto_kalturamedia-button/moodle-atto_kalturamedia-button.js
+++ b/lib/editor/atto/plugins/kalturamedia/yui/build/moodle-atto_kalturamedia-button/moodle-atto_kalturamedia-button.js
@@ -1,155 +1,166 @@
YUI.add('moodle-atto_kalturamedia-button', function (Y, NAME) {
-// 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 .
-
-/*
- * @package atto_kalturamedia
- * @copyright 2Kaltura
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
-/**
- * @module moodle-atto_kalturamedia-button
- */
-
-/**
- * Atto text editor kalturamedia plugin.
- *
- * @namespace M.atto_kalturamedia
- * @class button
- * @extends M.editor_atto.EditorPlugin
- */
-
-var COMPONENTNAME = 'atto_kalturamedia',
- CSS = {
- URLINPUT: 'atto_kalturamedia_urlentry',
- NAMEINPUT: 'atto_kalturamedia_nameentry'
- },
- SELECTORS = {
- URLINPUT: '.' + CSS.URLINPUT,
- NAMEINPUT: '.' + CSS.NAMEINPUT
- };
-
-Y.namespace('M.atto_kalturamedia').Button = Y.Base.create('button', Y.M.editor_atto.EditorPlugin, [], {
- _currentSelection: null,
- embedWindow: null,
-
- initializer: function() {
- this.addButton({
- icon: 'icon',
- iconComponent: COMPONENTNAME,
- callback: this._kalturamedia
- });
- },
- _kalturamedia: function() {
- this._currentSelection = this.get('host').getSelection();
- if (this._currentSelection === false) {
- return;
- }
-
- var w = 1200;
- var h = 700;
- var dualScreenLeft = window.screenLeft != undefined ? window.screenLeft : screen.left;
- var dualScreenTop = window.screenTop != undefined ? window.screenTop : screen.top;
-
- var width = window.innerWidth ? window.innerWidth : document.documentElement.clientWidth ? document.documentElement.clientWidth : screen.width;
- var height = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight ? document.documentElement.clientHeight : screen.height;
-
- var left = ((width / 2) - (w / 2)) + dualScreenLeft;
- var top = ((height / 2) - (h / 2)) + dualScreenTop;
- var newWindow = window.open(this._getIframeURL(), M.util.get_string("browse_and_embed", COMPONENTNAME), 'scrollbars=no, width=' + w + ', height=' + h + ', top=' + top + ', left=' + left);
-
- window.buttonJs = this;
-
- if (window.focus) {
- newWindow.focus();
- }
-
- this.embedWindow = newWindow;
- },
-
- _getIframeURL: function() {
-
- var args = Y.mix({
- elementid: this.get('host').get('elementid'),
- contextid: this.get('contextid'),
- height: '600px',
- width: '1112px'
- },
- this.get('area'));
- return M.cfg.wwwroot + '/lib/editor/atto/plugins/kalturamedia/ltibrowse_container.php?' +
- Y.QueryString.stringify(args);
- },
-
- _getCourseId: function() {
- var courseId;
- var bodyClasses = document.getElementsByTagName('body')[0].className;
- var classes = bodyClasses.split(' ');
- for(i in classes)
- {
- if(classes[i].indexOf('course-') > -1)
- {
- var parts = classes[i].split('-');
- courseId = parts[1];
- }
- }
-
- return courseId;
- },
-
- _removeProtocolFromUrl: function(fullUrl) {
- return fullUrl.replace(/^https?:\/\//,'');
- },
-
- embedItem: function(what, data) {
- var sourceUrl = data.url;
- var url = this._removeProtocolFromUrl(sourceUrl);
- var parser = document.createElement('a');
- parser.href = sourceUrl;
- url += parser.search;
-
- var content = 'tinymce-kalturamedia-embed||'+data.title+'||'+data.width+'||'+data.height+'';
-
- host = this.get('host');
- host.setSelection(this._currentSelection);
- host.insertContentAtFocusPoint(content);
- this.markUpdated();
- this.embedWindow.close();
- }
-
- } , {
- ATTRS: {
- /**
- * The contextid to use when generating this preview.
- *
- * @attribute contextid
- * @type String
- */
- contextid: {
- value: null
- },
-
- /**
- * The KAF URI, as configured in Kaltura's plugin settings.
- */
- kafuri: {
- value: null
- }
- }}
-);
+// 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 .
+
+/*
+ * @package atto_kalturamedia
+ * @copyright 2Kaltura
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+/**
+ * @module moodle-atto_kalturamedia-button
+ */
+
+/**
+ * Atto text editor kalturamedia plugin.
+ *
+ * @namespace M.atto_kalturamedia
+ * @class button
+ * @extends M.editor_atto.EditorPlugin
+ */
+
+var COMPONENTNAME = 'atto_kalturamedia',
+ CSS = {
+ URLINPUT: 'atto_kalturamedia_urlentry',
+ NAMEINPUT: 'atto_kalturamedia_nameentry'
+ },
+ SELECTORS = {
+ URLINPUT: '.' + CSS.URLINPUT,
+ NAMEINPUT: '.' + CSS.NAMEINPUT
+ };
+
+Y.namespace('M.atto_kalturamedia').Button = Y.Base.create('button', Y.M.editor_atto.EditorPlugin, [], {
+ _currentSelection: null,
+ embedWindow: null,
+
+ initializer: function() {
+ if (this.get('active')) {
+ this.addButton({
+ icon: 'icon',
+ iconComponent: COMPONENTNAME,
+ callback: this._kalturamedia
+ });
+ }
+ },
+ _kalturamedia: function() {
+ this._currentSelection = this.get('host').getSelection();
+ if (this._currentSelection === false) {
+ return;
+ }
+
+ var w = 1200;
+ var h = 700;
+ var dualScreenLeft = window.screenLeft != undefined ? window.screenLeft : screen.left;
+ var dualScreenTop = window.screenTop != undefined ? window.screenTop : screen.top;
+
+ var width = window.innerWidth ? window.innerWidth : document.documentElement.clientWidth ? document.documentElement.clientWidth : screen.width;
+ var height = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight ? document.documentElement.clientHeight : screen.height;
+
+ var left = ((width / 2) - (w / 2)) + dualScreenLeft;
+ var top = ((height / 2) - (h / 2)) + dualScreenTop;
+ var newWindow = window.open(this._getIframeURL(), M.util.get_string("browse_and_embed", COMPONENTNAME), 'scrollbars=no, width=' + w + ', height=' + h + ', top=' + top + ', left=' + left);
+
+ window.buttonJs = this;
+
+ if (window.focus) {
+ newWindow.focus();
+ }
+
+ this.embedWindow = newWindow;
+ },
+
+ _getIframeURL: function() {
+
+ var args = Y.mix({
+ elementid: this.get('host').get('elementid'),
+ contextid: this.get('contextid'),
+ height: '600px',
+ width: '1112px'
+ },
+ this.get('area'));
+ return M.cfg.wwwroot + '/lib/editor/atto/plugins/kalturamedia/ltibrowse_container.php?' +
+ Y.QueryString.stringify(args);
+ },
+
+ _getCourseId: function() {
+ var courseId;
+ var bodyClasses = document.getElementsByTagName('body')[0].className;
+ var classes = bodyClasses.split(' ');
+ for(i in classes)
+ {
+ if(classes[i].indexOf('course-') > -1)
+ {
+ var parts = classes[i].split('-');
+ courseId = parts[1];
+ }
+ }
+
+ return courseId;
+ },
+
+ _removeProtocolFromUrl: function(fullUrl) {
+ return fullUrl.replace(/^https?:\/\//,'');
+ },
+
+ embedItem: function(what, data) {
+ var sourceUrl = data.url;
+ var url = this._removeProtocolFromUrl(sourceUrl);
+ var parser = document.createElement('a');
+ parser.href = sourceUrl;
+ url += parser.search;
+
+ var content = 'tinymce-kalturamedia-embed||'+data.title+'||'+data.width+'||'+data.height+'';
+
+ host = this.get('host');
+ host.setSelection(this._currentSelection);
+ host.insertContentAtFocusPoint(content);
+ this.markUpdated();
+ this.embedWindow.close();
+ }
+
+ } , {
+ ATTRS: {
+ /**
+ * Whether the button should be active.
+ *
+ * @attribute active
+ * @type Boolean
+ */
+ active: {
+ value: false
+ },
+ /**
+ * The contextid to use when generating this preview.
+ *
+ * @attribute contextid
+ * @type String
+ */
+ contextid: {
+ value: null
+ },
+
+ /**
+ * The KAF URI, as configured in Kaltura's plugin settings.
+ */
+ kafuri: {
+ value: null
+ }
+ }}
+);
}, '@VERSION@', {"requires": ["moodle-editor_atto-plugin"]});
diff --git a/lib/editor/atto/plugins/kalturamedia/yui/src/button/js/button.js b/lib/editor/atto/plugins/kalturamedia/yui/src/button/js/button.js
index 146ce934..80fcdd7c 100644
--- a/lib/editor/atto/plugins/kalturamedia/yui/src/button/js/button.js
+++ b/lib/editor/atto/plugins/kalturamedia/yui/src/button/js/button.js
@@ -46,11 +46,13 @@ Y.namespace('M.atto_kalturamedia').Button = Y.Base.create('button', Y.M.editor_a
embedWindow: null,
initializer: function() {
- this.addButton({
- icon: 'icon',
- iconComponent: COMPONENTNAME,
- callback: this._kalturamedia
- });
+ if (this.get('active')) {
+ this.addButton({
+ icon: 'icon',
+ iconComponent: COMPONENTNAME,
+ callback: this._kalturamedia
+ });
+ }
},
_kalturamedia: function() {
this._currentSelection = this.get('host').getSelection();
@@ -130,6 +132,15 @@ Y.namespace('M.atto_kalturamedia').Button = Y.Base.create('button', Y.M.editor_a
} , {
ATTRS: {
+ /**
+ * Whether the button should be active.
+ *
+ * @attribute active
+ * @type Boolean
+ */
+ active: {
+ value: false
+ },
/**
* The contextid to use when generating this preview.
*
diff --git a/local/kaltura/db/access.php b/local/kaltura/db/access.php
index e1b21b00..2ca1a6fa 100644
--- a/local/kaltura/db/access.php
+++ b/local/kaltura/db/access.php
@@ -36,4 +36,27 @@
'manager' => CAP_ALLOW,
)
),
-);
\ No newline at end of file
+ 'local/kaltura:lti_admin_role' => [
+ 'captype' => 'read',
+ 'contextlevel' => CONTEXT_COURSE,
+ 'archetypes' => [
+ 'manager' => CAP_ALLOW,
+ ]
+ ],
+ 'local/kaltura:lti_instructor_role' => [
+ 'captype' => 'read',
+ 'contextlevel' => CONTEXT_COURSE,
+ 'archetypes' => [
+ 'editingteacher' => CAP_ALLOW,
+ ],
+ 'clonepermissionsfrom' => 'moodle/course:manageactivities'
+ ],
+ 'local/kaltura:lti_learner_role' => [
+ 'captype' => 'read',
+ 'contextlevel' => CONTEXT_COURSE,
+ 'archetypes' => [
+ 'teacher' => CAP_ALLOW,
+ 'student' => CAP_ALLOW,
+ ]
+ ],
+);
diff --git a/local/kaltura/db/upgrade.php b/local/kaltura/db/upgrade.php
index 45c16d63..23d9a558 100644
--- a/local/kaltura/db/upgrade.php
+++ b/local/kaltura/db/upgrade.php
@@ -73,6 +73,5 @@ function xmldb_local_kaltura_upgrade($oldversion) {
// Kaltura savepoint reached.
upgrade_plugin_savepoint(true, 2016120130, 'local', 'kaltura');
}
-
return true;
-}
\ No newline at end of file
+}
diff --git a/local/kaltura/lang/en/local_kaltura.php b/local/kaltura/lang/en/local_kaltura.php
index 89c505be..9369bbbb 100644
--- a/local/kaltura/lang/en/local_kaltura.php
+++ b/local/kaltura/lang/en/local_kaltura.php
@@ -90,3 +90,6 @@
$string['privacy:metadata:module'] = 'The name of the module the user is accessing the LTI Consumer from';
$string['privacy:metadata:source'] = 'The source URL of the media entry of the user accessing the LTI Consumer';
$string['privacy:metadata:custompublishdata'] = 'The courses the user is enrolled in and the LTI roles the user has in the course';
+$string['kaltura:lti_admin_role'] = 'Admin permission for Kaltura LTI intergration';
+$string['kaltura:lti_instructor_role'] = 'Instructor permission for Kaltura LTI intergration';
+$string['kaltura:lti_learner_role'] = 'Learner permission for Kaltura LTI intergration';
diff --git a/local/kaltura/locallib.php b/local/kaltura/locallib.php
index ec8d15db..e23b4594 100644
--- a/local/kaltura/locallib.php
+++ b/local/kaltura/locallib.php
@@ -338,7 +338,7 @@ function local_kaltura_strip_querystring($endpoint, $params) {
* @return string Returns HTML required to initiate an LTI launch.
*/
function local_kaltura_request_lti_launch($ltirequest, $withblocks = true, $editor = null) {
- global $CFG, $USER;
+ global $CFG, $USER, $SESSION;
if(is_null($editor))
{
@@ -387,7 +387,13 @@ function local_kaltura_request_lti_launch($ltirequest, $withblocks = true, $edit
$requestparams['lis_outcome_service_url'] = $serviceurl->out(false);
// Add custom parameters
- $requestparams['custom_publishdata'] = local_kaltura_get_kaf_publishing_data();
+ // Add json course data $SESSION for performance.
+ if (!empty($SESSION->local_kaltura_custom_publishdata)) {
+ $requestparams['custom_publishdata'] = $SESSION->local_kaltura_custom_publishdata;
+ } else {
+ $requestparams['custom_publishdata'] = local_kaltura_get_kaf_publishing_data();
+ $SESSION->local_kaltura_custom_publishdata = $requestparams['custom_publishdata'];
+ }
$requestparams['custom_publishdata_encoded'] = '1';
$requestparams['custom_moodle_plugin_version'] = local_kaltura_get_config()->version;
@@ -465,42 +471,54 @@ function local_kaltura_format_uri($uri) {
/**
* This function creates a JSON string of the courses the user is enrolled in and the LTI roles the user has in the course.
* The JSON string is cached in the user's session global for efficiency purposes.
+ * @throws \coding_exception
* @return string A JSON data structure outlining the user's LTI roles in all of their enroled courses.
*/
function local_kaltura_get_kaf_publishing_data() {
- global $USER, $SITE;
+ global $USER, $SITE, $COURSE;
- $role = is_siteadmin($USER->id) ? KALTURA_LTI_ADMIN_ROLE : KALTURA_LTI_INSTRUCTOR_ROLE;
$json = new stdClass();
$json->courses = array();
- $hascap = false;
-
- // If the user is not an admin then retrieve all of the user's enroled courses.
- if (KALTURA_LTI_ADMIN_ROLE != $role) {
- $courses = enrol_get_users_courses($USER->id, true, 'id,fullname,shortname', 'fullname ASC');
- } else {
- // Calling refactored code that allows for a limit on the number of courses returned.
- $courses = local_kaltura_get_user_capability_course('moodle/course:manageactivities', $USER->id, true, 'id,fullname,shortname', 'fullname ASC');
+ $courses = [];
+
+ $capabilities = [
+ KALTURA_LTI_ADMIN_ROLE => 'local/kaltura:lti_admin_role',
+ KALTURA_LTI_INSTRUCTOR_ROLE => 'local/kaltura:lti_instructor_role',
+ KALTURA_LTI_LEARNER_ROLE => 'local/kaltura:lti_learner_role',
+ ];
+ foreach ($capabilities as $capability) {
+ if ($coursebycapability = get_user_capability_course($capability, $USER->id, false, 'id,fullname,shortname,timemodified', 'id DESC,timemodified DESC', 200)) {
+ $courses = array_merge($courses, $coursebycapability);
+ }
}
+ $courses = array_unique($courses, SORT_REGULAR);
+ usort($courses, function($a, $b) {
+ return $a->id < $b->id ? 1 : -1;
+ });
+ $courses = array_splice($courses, 0, 200);
+ array_unshift($courses, $COURSE);
foreach ($courses as $course) {
if ($course->id === $SITE->id) {
// Don't want to include the site id in this list
continue;
}
-
- if (KALTURA_LTI_ADMIN_ROLE != $role) {
- // Check if the user has the manage capability in the course.
- $hascap = has_capability('moodle/course:manageactivities', context_course::instance($course->id), $USER->id, false);
- $role = $hascap ? KALTURA_LTI_INSTRUCTOR_ROLE : KALTURA_LTI_LEARNER_ROLE;
+ $courserole = '';
+ foreach ($capabilities as $role => $capability) {
+ if (has_capability($capability, context_course::instance($course->id), $USER->id, false)) {
+ $courserole = $role;
+ break;
+ }
+ }
+ if (empty($courserole)) {
+ continue;
}
-
// The properties must be nameed "courseId", "courseName" and "roles".
$data = new stdClass();
$data->courseId = $course->id;
$data->courseName = $course->fullname;
$data->courseShortName = $course->shortname;
- $data->roles = $role;
+ $data->roles = $courserole;
$json->courses[$course->id] = $data;
}
diff --git a/local/kaltura/tests/locallib_test.php b/local/kaltura/tests/locallib_test.php
index 70682990..d9cc799f 100644
--- a/local/kaltura/tests/locallib_test.php
+++ b/local/kaltura/tests/locallib_test.php
@@ -977,7 +977,7 @@ public function test_local_kaltura_get_kaf_publishing_data_for_non_admin() {
);
$coursetwo = $this->getDataGenerator()->create_course($coursedata);
- $this->getDataGenerator()->enrol_user($user->id, $coursetwo->id, $role['student']->id, 'manual');
+ $this->getDataGenerator()->enrol_user($user->id, $coursetwo->id, $role['teacher']->id, 'manual');
$coursedata = array(
'fullname' => 'Test 3',
@@ -998,9 +998,9 @@ public function test_local_kaltura_get_kaf_publishing_data_for_non_admin() {
$result = local_kaltura_get_kaf_publishing_data();
- $json = '{"courses":[{"courseId":"'.$courseone->id.'","courseName":"'.$courseone->fullname.'","courseShortName":"'.$courseone->shortname.'","roles":"Instructor"}';
+ $json = '{"courses":[{"courseId":"'.$coursefour->id.'","courseName":"'.$coursefour->fullname.'","courseShortName":"'.$coursefour->shortname.'","roles":"Instructor"}';
$json .= ',{"courseId":"'.$coursetwo->id.'","courseName":"'.$coursetwo->fullname.'","courseShortName":"'.$coursetwo->shortname.'","roles":"Learner"}';
- $json .= ',{"courseId":"'.$coursefour->id.'","courseName":"'.$coursefour->fullname.'","courseShortName":"'.$coursefour->shortname.'","roles":"Instructor"}]}';
+ $json .= ',{"courseId":"'.$courseone->id.'","courseName":"'.$courseone->fullname.'","courseShortName":"'.$courseone->shortname.'","roles":"Instructor"}]}';
$this->assertEquals(base64_encode($json), $result);
}
@@ -1041,10 +1041,7 @@ public function test_local_kaltura_get_kaf_publishing_data_for_admin() {
$result = local_kaltura_get_kaf_publishing_data();
- $json = '{"courses":[{"courseId":"'.$courseone->id.'","courseName":"'.$courseone->fullname.'","courseShortName":"'.$courseone->shortname.'","roles":"urn:lti:sysrole:ims\/lis\/Administrator"}';
- $json .= ',{"courseId":"'.$coursetwo->id.'","courseName":"'.$coursetwo->fullname.'","courseShortName":"'.$coursetwo->shortname.'","roles":"urn:lti:sysrole:ims\/lis\/Administrator"}';
- $json .= ',{"courseId":"'.$coursethree->id.'","courseName":"'.$coursethree->fullname.'","courseShortName":"'.$coursethree->shortname.'","roles":"urn:lti:sysrole:ims\/lis\/Administrator"}';
- $json .= ',{"courseId":"'.$coursefour->id.'","courseName":"'.$coursefour->fullname.'","courseShortName":"'.$coursefour->shortname.'","roles":"urn:lti:sysrole:ims\/lis\/Administrator"}]}';
+ $json = '{"courses":[]}';
$this->assertEquals(base64_encode($json), $result);
}
diff --git a/local/kalturamediagallery/classes/event/media_gallery_viewed.php b/local/kalturamediagallery/classes/event/media_gallery_viewed.php
new file mode 100644
index 00000000..4ff9fe16
--- /dev/null
+++ b/local/kalturamediagallery/classes/event/media_gallery_viewed.php
@@ -0,0 +1,96 @@
+.
+
+/**
+ * View media gallery
+ *
+ * @package local_kalturamediagallery
+ * @copyright 2021 The Open University
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+namespace local_kalturamediagallery\event;
+
+defined('MOODLE_INTERNAL') || die();
+
+/**
+ * View my media
+ *
+ * @property-read array $other {
+ * Extra information about event.
+ * - string coursename: (required) course name.
+ * - int courseid : (required) course id.
+ * }
+ *
+ * @package local_kalturamediagallery
+ * @copyright 2021 The Open University
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class media_gallery_viewed extends \core\event\base {
+
+ /**
+ * Init method.
+ */
+ protected function init() {
+ $this->data['crud'] = 'r';
+ $this->data['edulevel'] = self::LEVEL_OTHER;
+ }
+
+ /**
+ * Returns localised general event name.
+ *
+ * @return string
+ */
+ public static function get_name() {
+ return get_string('eventviewmediagallry', 'local_kalturamediagallery');
+ }
+
+ /**
+ * Returns description of what happened.
+ *
+ * @return string
+ */
+ public function get_description() {
+ return 'The user with id ' . $this->userid . ' viewed ' . $this->other['coursename'] . ' media gallery in context ' . $this->contextid
+ . ' with courseid ' . $this->other['courseid'];
+ }
+
+ protected function validate_data() {
+ if (empty($this->other['coursename'])) {
+ throw new \coding_exception('Missing course name');
+ }
+ if (empty($this->other['courseid'])) {
+ throw new \coding_exception('Missing course id');
+ }
+ }
+
+ /**
+ * Gets data for use when logging to old log table.
+ *
+ * @return array Data to be passed to the legacy add_to_log function
+ */
+ public function get_legacy_logdata() {
+ $context = $this->get_context();
+
+ $info = $this->userid . ':' . $this->other['coursename'] . ':' .
+ $this->context->id . ':' . $this->other['courseid'];
+ if (\core_text::strlen($info) > 255) {
+ $info = \core_text::substr($info, 0, 255);
+ }
+ return [$context->id, 'local_kalturamediagallery', 'eventviewmediagallry',
+ 'local/kalturamediagallery/index.php?courseid=' . $this->other['courseid'], $info, $context->instanceid];
+ }
+}
diff --git a/local/kalturamediagallery/index.php b/local/kalturamediagallery/index.php
index 525b4062..ec4b6ba4 100644
--- a/local/kalturamediagallery/index.php
+++ b/local/kalturamediagallery/index.php
@@ -69,5 +69,14 @@
);
$PAGE->requires->yui_module('moodle-local_kaltura-lticontainer', 'M.local_kaltura.init', array($params), null, true);
$PAGE->requires->js(new moodle_url('/local/kaltura/js/kea_resize.js'));
-
+$event = \local_kalturamediagallery\event\media_gallery_viewed::create(
+ [
+ 'context' => $context,
+ 'other' => [
+ 'coursename' => $course->fullname,
+ 'courseid' => $courseid
+ ]
+ ]
+);
+$event->trigger();
echo $OUTPUT->footer();
\ No newline at end of file
diff --git a/local/kalturamediagallery/lang/en/local_kalturamediagallery.php b/local/kalturamediagallery/lang/en/local_kalturamediagallery.php
index 2b8ab26a..6868bea9 100644
--- a/local/kalturamediagallery/lang/en/local_kalturamediagallery.php
+++ b/local/kalturamediagallery/lang/en/local_kalturamediagallery.php
@@ -34,3 +34,4 @@
$string['link_location_navigation'] = 'Navigation block';
$string['link_location_course_settings'] = 'Course settings';
$string['privacy:metadata'] = 'Kaltura media gallery plugin does not store any personal data.';
+$string['eventviewmediagallry'] = 'Media gallery viewed';
diff --git a/local/kalturamediagallery/tests/events_test.php b/local/kalturamediagallery/tests/events_test.php
new file mode 100644
index 00000000..7750391f
--- /dev/null
+++ b/local/kalturamediagallery/tests/events_test.php
@@ -0,0 +1,65 @@
+.
+
+/**
+ * Contains the event tests for the plugin.
+ *
+ * @package local_kalturamediagallery
+ * @copyright 2021 The Open University
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+defined('MOODLE_INTERNAL') || die();
+
+global $CFG;
+
+/**
+ * Contains the event tests for the plugin.
+ *
+ * @package local_kalturamediagallery
+ * @copyright 2021 The Open University
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class local_kalturamediagallery_events_testcase extends advanced_testcase {
+
+ /**
+ * Tests (kaltura_media_viewed)
+ */
+ public function test_kaltura_media_viewed() {
+ $this->resetAfterTest();
+ $generator = $this->getDataGenerator();
+ $user = $generator->create_user();
+ $course = $generator->create_course();
+ $this->setUser($user);
+
+ $context = context_course::instance($course->id);
+ $sourceurlsample = 'sourcevideotest.test';
+ // Create a basic event.
+ $event = \local_kalturamediagallery\event\media_gallery_viewed::create([
+ 'sourceurl' => $sourceurlsample,
+ 'contextid' => $context->id
+ ]);
+
+ // Check name (generic).
+ $this->assertEquals(get_string('kalturamediaviewed', 'filter_kaltura'), $event->get_name());
+ $this->assertEquals('The user with id ' . $user->id . ' viewed video with source url' . $sourceurlsample
+ . 'embed in context ' . $context->id, $event->get_description());
+ $info = $user->id . ':' . $sourceurlsample . ':' . $context->id;
+ $this->assertEquals([$context->id, 'filter_kaltura', 'kalturamediaviewed',
+ $sourceurlsample, $info, $context->instanceid], $event->get_legacy_logdata());
+ }
+
+}
diff --git a/local/mymedia/lang/en/local_mymedia.php b/local/mymedia/lang/en/local_mymedia.php
index 0ecd5e60..829e6977 100644
--- a/local/mymedia/lang/en/local_mymedia.php
+++ b/local/mymedia/lang/en/local_mymedia.php
@@ -29,3 +29,4 @@
$string['nav_mymedia'] = 'My Media';
$string['pluginname'] = 'My Media';
$string['privacy:metadata'] = 'My Media plugin does not store any personal data.';
+$string['eventviewmymedia'] = 'My media viewed';
diff --git a/local/mymedia/mymedia.php b/local/mymedia/mymedia.php
index 3df74624..ebc65058 100644
--- a/local/mymedia/mymedia.php
+++ b/local/mymedia/mymedia.php
@@ -65,5 +65,13 @@
);
$PAGE->requires->yui_module('moodle-local_kaltura-lticontainer', 'M.local_kaltura.init', array($params), null, true);
$PAGE->requires->js(new moodle_url('/local/kaltura/js/kea_resize.js'));
-
+$event = \local_mymedia\event\mymedia_viewed::create(
+ [
+ 'context' => \context_system::instance(),
+ 'other' => [
+ 'page' => get_string('heading_mymedia', 'local_mymedia'),
+ ]
+ ]
+);
+$event->trigger();
echo $OUTPUT->footer();
diff --git a/local/mymedia/tests/events_test.php b/local/mymedia/tests/events_test.php
new file mode 100644
index 00000000..9fcad784
--- /dev/null
+++ b/local/mymedia/tests/events_test.php
@@ -0,0 +1,63 @@
+.
+
+/**
+ * Contains the event tests for the plugin.
+ *
+ * @package local_mymedia
+ * @copyright 2021 The Open University
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+defined('MOODLE_INTERNAL') || die();
+
+global $CFG;
+
+/**
+ * Contains the event tests for the plugin.
+ *
+ * @package local_mymedia
+ * @copyright 2021 The Open University
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class local_mymedia_events_testcase extends advanced_testcase {
+
+ /**
+ * Tests (mymedia_viewed)
+ */
+ public function test_mymedia_viewed() {
+ $this->resetAfterTest();
+ $user = $this->getDataGenerator()->create_user();
+ $this->setUser($user);
+
+ $context = context_system::instance();
+
+ // Create a basic event.
+ $event = \local_mymedia\event\mymedia_viewed::create([
+ 'context' => $context,
+ 'other' => [
+ 'page' => get_string('heading_mymedia', 'local_mymedia')
+ ]]);
+
+ // Check name (generic).
+ $this->assertEquals(get_string('eventviewmymedia', 'local_mymedia'), $event->get_name());
+ $this->assertEquals('The user with id ' . $user->id . ' viewed My Media in context 1', $event->get_description());
+ $info = $user->id . ':' . get_string('heading_mymedia', 'local_mymedia') . ':' . $context->id;
+ $this->assertEquals([$context->id, 'local_mymedia', 'viewmymedia',
+ 'local/mymedia/mymedia.php', $info, $context->instanceid], $event->get_legacy_logdata());
+ }
+
+}