Skip to content

Commit 14d5702

Browse files
author
Daniel Thies
committed
wip
1 parent 67550c2 commit 14d5702

17 files changed

Lines changed: 659 additions & 0 deletions

classes/vimeo_embed.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ public function export_for_template(renderer_base $output) {
109109
'cmid' => $cm->id,
110110
'haspro' => videotime_has_pro(),
111111
'interval' => $this->record->saveinterval ?? 5,
112+
'metadataurl' => $this->metadata_url(),
112113
'plugins' => file_exists($CFG->dirroot . '/mod/videotime/plugin/pro/templates/plugins.mustache'),
113114
'texttracks' => $this->text_tracks(),
114115
'uniqueid' => $this->get_uniqueid(),
@@ -150,4 +151,30 @@ public function text_tracks(): array {
150151

151152
return array_values($texttracks);
152153
}
154+
155+
/**
156+
* Get the urlfor metadata to be loaded
157+
*/
158+
public function metadata_url(): string {
159+
global $DB;
160+
161+
if (
162+
!videotime_has_pro()
163+
|| !get_config('videotimetab_interaction', 'enabled')
164+
|| !$DB->get_records('videotimetab_interaction_cue', ['videotime' => $this->record->id])
165+
|| !$settings = $DB->get_record('videotimetab_interaction', ['videotime' => $this->record->id])
166+
) {
167+
return '';
168+
}
169+
$context = context_module::instance($this->get_cm()->id);
170+
171+
return moodle_url::make_pluginfile_url(
172+
$context->id,
173+
'videotimeplugin_pro',
174+
'metadata',
175+
0,
176+
"/$settings->timemodified/",
177+
'metadata.vtt'
178+
)->out(false);
179+
}
153180
}

plugin/videojs/templates/video_embed.mustache

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@
6161
src="{{ url }}"
6262
/>
6363
{{/ visible }}{{/ url }}{{/ texttracks }}
64+
{{# metadataurl }}
65+
<track
66+
kind="metadata"
67+
src="{{ metadataurl }}"
68+
/>
69+
{{/ metadataurl }}
6470
</video>
6571
{{/ video }}
6672
{{^ video }}

tab/interaction/amd/build/interaction.min.js

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tab/interaction/amd/build/interaction.min.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Show selected text track
3+
*
4+
* @package mod_videotime
5+
* @module mod_videotime/interaction
6+
* @copyright 2021 bdecent gmbh <https://bdecent.de>
7+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
8+
*/
9+
10+
/**
11+
* Intialize listener for interaction
12+
*/
13+
export const initialize = () => {
14+
window.removeEventListener('interactionstart', showInteraction);
15+
window.addEventListener('interactionstart', showInteraction);
16+
};
17+
18+
/**
19+
* Form change event handler
20+
*
21+
* @param {event} e mouse event
22+
*/
23+
const showInteraction = (e) => {
24+
alert(e.detail);
25+
};
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
// This file is part of Moodle - https://moodle.org/
3+
//
4+
// Moodle is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// Moodle is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU General Public License
15+
// along with Moodle. If not, see <https://www.gnu.org/licenses/>.
16+
17+
namespace videotimetab_interaction\event;
18+
19+
/**
20+
* The interaction_viewed event class.
21+
*
22+
* @package videotimetab_interaction
23+
* @category event
24+
* @copyright 2026 bdecent gmbh <https://bdecent.de>
25+
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26+
*/
27+
class interaction_viewed extends base {
28+
// For more information about the Events API please visit {@link https://docs.moodle.org/dev/Events_API}.
29+
}

tab/interaction/classes/tab.php

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
<?php
2+
// This file is part of Moodle - http://moodle.org/
3+
//
4+
// Moodle is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// Moodle is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU General Public License
15+
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16+
17+
/**
18+
* Tab.
19+
*
20+
* @package videotimetab_interaction
21+
* @copyright 2026 bdecent gmbh <https://bdecent.de>
22+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23+
*/
24+
25+
namespace videotimetab_interaction;
26+
27+
use context_module;
28+
use mod_videotime\output\renderer;
29+
use mod_videotime\videotime_instance;
30+
use videotimeplugin_repository\video;
31+
use stdClass;
32+
33+
defined('MOODLE_INTERNAL') || die();
34+
35+
require_once("$CFG->dirroot/mod/videotime/lib.php");
36+
37+
/**
38+
* Tab.
39+
*
40+
* @package videotimetab_interaction
41+
*/
42+
class tab extends \mod_videotime\local\tabs\tab {
43+
/**
44+
* Get tab panel content
45+
*
46+
* @return string
47+
*/
48+
public function get_tab_content(): string {
49+
global $DB, $OUTPUT, $PAGE, $USER;
50+
51+
$instance = $this->get_instance();
52+
$data = [
53+
'contextid' => $instance->get_context()->id,
54+
'id' => $instance->id,
55+
'title' => $instance->name,
56+
];
57+
58+
return $OUTPUT->render_from_template(
59+
'videotimetab_interaction/tab',
60+
$data
61+
);
62+
}
63+
64+
/**
65+
* Defines the additional form fields.
66+
*
67+
* @param moodle_form $mform form to modify
68+
*/
69+
public static function add_form_fields($mform) {
70+
$mform->addElement(
71+
'advcheckbox',
72+
'enable_interaction',
73+
get_string('pluginname', 'videotimetab_interaction'),
74+
get_string('showtab', 'videotime')
75+
);
76+
$mform->setDefault('enable_interaction', get_config('videotimetab_interaction', 'default'));
77+
$mform->disabledIf('enable_interaction', 'enabletabs');
78+
79+
$options = [
80+
0 => get_string('none'),
81+
1 => get_string('all'),
82+
];
83+
$mform->addElement(
84+
'select',
85+
'interactiontype',
86+
'',
87+
$options
88+
);
89+
}
90+
91+
/**
92+
* Whether tab is enabled and visible
93+
*
94+
* @return bool
95+
*/
96+
public function is_visible(): bool {
97+
global $DB;
98+
99+
$record = $this->get_instance()->to_record();
100+
return $this->is_enabled() && $DB->record_exists('videotimetab_interaction', [
101+
'videotime' => $record->id,
102+
]);
103+
}
104+
105+
/**
106+
* Saves a settings in database
107+
*
108+
* @param stdClass $data Form data with values to save
109+
*/
110+
public static function save_settings(stdClass $data) {
111+
global $DB;
112+
113+
if (empty($data->enable_interaction)) {
114+
$DB->delete_records('videotimetab_interaction', [
115+
'videotime' => $data->id,
116+
]);
117+
} else {
118+
if (!$record = $DB->get_record('videotimetab_interaction', ['videotime' => $data->id])) {
119+
$DB->insert_record('videotimetab_interaction', [
120+
'videotime' => $data->id,
121+
]);
122+
}
123+
}
124+
}
125+
126+
/**
127+
* Delete settings in database
128+
*
129+
* @param int $id
130+
*/
131+
public static function delete_settings(int $id) {
132+
global $DB;
133+
134+
$DB->delete_records('videotimetab_interaction', [
135+
'videotime' => $id,
136+
]);
137+
}
138+
139+
/**
140+
* Prepares the form before data are set
141+
*
142+
* @param array $defaultvalues
143+
* @param int $instance
144+
*/
145+
public static function data_preprocessing(array &$defaultvalues, int $instance) {
146+
global $COURSE, $DB;
147+
148+
if (empty($instance)) {
149+
$defaultvalues['enable_interaction'] = get_config('videotimetab_interaction', 'default');
150+
} else if ($record = $DB->get_record('videotimetab_interaction', ['videotime' => $instance])) {
151+
$defaultvalues['enable_interaction'] = 1;
152+
} else {
153+
$defaultvalues['enable_interaction'] = 0;
154+
}
155+
}
156+
157+
/**
158+
* List of missing dependencies needed for plugin to be enabled
159+
*/
160+
public static function added_dependencies() {
161+
global $OUTPUT;
162+
if (videotime_has_pro()) {
163+
return '';
164+
}
165+
return $OUTPUT->render_from_template('videotimetab_interaction/upgrade', []);
166+
}
167+
}

tab/interaction/db/access.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
// This file is part of Moodle - https://moodle.org/
3+
//
4+
// Moodle is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// Moodle is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU General Public License
15+
// along with Moodle. If not, see <https://www.gnu.org/licenses/>.
16+
17+
/**
18+
* Plugin capabilities are defined here.
19+
*
20+
* @package videotimetab_interaction
21+
* @category access
22+
* @copyright 2026 bdecent gmbh <https://bdecent.de>
23+
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24+
*/
25+
26+
defined('MOODLE_INTERNAL') || die();
27+
28+
$capabilities = [
29+
30+
'videotimetab/interaction:interact' => [
31+
'captype' => 'write',
32+
'contextlevel' => CONTEXT_MODULE,
33+
'archetypes' => [
34+
'student' => CAP_ALLOW,
35+
],
36+
],
37+
38+
'videotimetab/interaction:edit' => [
39+
'captype' => 'write',
40+
'contextlevel' => CONTEXT_MODULE,
41+
'archetypes' => [
42+
'editingteacher' => CAP_ALLOW,
43+
],
44+
],
45+
];

tab/interaction/db/install.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
// This file is part of Moodle - https://moodle.org/
3+
//
4+
// Moodle is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// Moodle is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU General Public License
15+
// along with Moodle. If not, see <https://www.gnu.org/licenses/>.
16+
17+
/**
18+
* Code to be executed after the plugin's database scheme has been installed is defined here.
19+
*
20+
* @package videotimetab_interaction
21+
* @category upgrade
22+
* @copyright 2026 bdecent gmbh <https://bdecent.de>
23+
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24+
*/
25+
26+
/**
27+
* Custom code to be run on installing the plugin.
28+
*/
29+
function xmldb_videotimetab_interaction_install() {
30+
31+
return true;
32+
}

tab/interaction/db/install.xml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<XMLDB PATH="mod/videotime/tab/interaction/db" VERSION="20260323" COMMENT="XMLDB file for Moodle mod/videotime/tab/interaction"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:noNamespaceSchemaLocation="../../../../../lib/xmldb/xmldb.xsd"
5+
>
6+
<TABLES>
7+
<TABLE NAME="videotimetab_interaction" COMMENT="Default comment for videotimetab_interaction, please edit me">
8+
<FIELDS>
9+
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
10+
<FIELD NAME="videotime" TYPE="int" LENGTH="20" NOTNULL="true" SEQUENCE="false"/>
11+
<FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
12+
</FIELDS>
13+
<KEYS>
14+
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
15+
<KEY NAME="videotime" TYPE="foreign-unique" FIELDS="videotime" REFTABLE="videotime" REFFIELDS="id" COMMENT="Video time instance"/>
16+
</KEYS>
17+
</TABLE>
18+
<TABLE NAME="videotimetab_interaction_cue" COMMENT="The individual interaction cues">
19+
<FIELDS>
20+
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
21+
<FIELD NAME="videotime" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"/>
22+
<FIELD NAME="action" TYPE="char" LENGTH="40" NOTNULL="false" SEQUENCE="false"/>
23+
<FIELD NAME="data" TYPE="text" NOTNULL="false" SEQUENCE="false"/>
24+
<FIELD NAME="endtime" TYPE="char" LENGTH="20" NOTNULL="false" SEQUENCE="false"/>
25+
<FIELD NAME="starttime" TYPE="char" LENGTH="20" NOTNULL="false" SEQUENCE="false"/>
26+
</FIELDS>
27+
<KEYS>
28+
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
29+
<KEY NAME="videotime" TYPE="foreign" FIELDS="videotime" REFTABLE="videotime" REFFIELDS="id" COMMENT="Video time instance"/>
30+
</KEYS>
31+
</TABLE>
32+
</TABLES>
33+
</XMLDB>

0 commit comments

Comments
 (0)