Skip to content

Commit

Permalink
Implemented the dash 1.7.
Browse files Browse the repository at this point in the history
  • Loading branch information
Nithy1anand committed Aug 7, 2023
1 parent 79e06d2 commit 6095bba
Show file tree
Hide file tree
Showing 9 changed files with 110 additions and 11 deletions.
2 changes: 1 addition & 1 deletion amd/build/videotime.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion amd/build/videotime.min.js.map

Large diffs are not rendered by default.

16 changes: 14 additions & 2 deletions amd/src/videotime.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ define([
this.resumeTime = null;
this.session = null;
this.instance = instance;
this.duration = 0;

this.played = false;

Expand Down Expand Up @@ -106,6 +107,15 @@ define([
}

this.addListeners();
var self = this;
setTimeout(function() {
if (self.duration == 0) {
self.getDuration().then((duration) => {
self.duration = duration;
});
}
}, 1000, self);


for (let i = 0; i < this.plugins.length; i++) {
const plugin = this.plugins[i];
Expand Down Expand Up @@ -186,7 +196,6 @@ define([
if (!this.instance.resume_playback || this.instance.resume_time <= 0) {
return true;
}

return this.getDuration().then((duration) => {
let resumeTime = this.instance.resume_time;
// Duration is often a little greater than a resume time at the end of the video.
Expand All @@ -201,6 +210,7 @@ define([
}
Log.debug("VIDEO_TIME duration is " + duration);
Log.debug("VIDEO_TIME resuming at " + resumeTime);
this.duration = duration;
this.setCurrentPosition(resumeTime);
return true;
}).fail(Notification.exception);
Expand Down Expand Up @@ -363,6 +373,7 @@ define([
data.set('moodlewsrestformat', 'json');
data.set('wsfunction', 'videotimeplugin_pro_set_session_current_time');
data.set('current_time', currentTime);
data.set('duration', this.duration);
data.set('session_id', sessionId);
return fetch(url).then((response) => {
if (!response.ok) {
Expand All @@ -373,11 +384,12 @@ define([
}
return Ajax.call([{
methodname: 'videotimeplugin_pro_set_session_current_time',
args: {"session_id": sessionId, "current_time": currentTime},
args: {"session_id": sessionId, "current_time": currentTime, "duration" : this.duration},
fail: Notification.exception
}])[0];
};


/**
* Set video watch percentage for session.
*
Expand Down
64 changes: 64 additions & 0 deletions classes/local/block_dash/attribute/completion_status_attribute.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?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/>.

/**
* Transforms data to average view time.
*
* @package mod_videotime
* @copyright 2020 bdecent gmbh <https://bdecent.de>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

namespace mod_videotime\local\block_dash\attribute;

use block_dash\local\data_grid\field\attribute\abstract_field_attribute;
use mod_videotime\videotime_instance;

defined('MOODLE_INTERNAL') || die();

require_once($CFG->libdir.'/completionlib.php');

/**
* Transforms data to average view time.
*
* @package mod_videotime
* @copyright 2020 bdecent gmbh <https://bdecent.de>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class completion_status_attribute extends abstract_field_attribute {

/**
* After records are relieved from database each field has a chance to transform the data.
* Example: Convert unix timestamp into a human readable date format
*
* @param int $data
* @param \stdClass $record Entire row
* @return mixed
* @throws \moodle_exception
*/
public function transform_data($data, \stdClass $record) {
global $DB;
if ($data == COMPLETION_COMPLETE) {
return get_string("completed", "mod_videotime");
} else if ($data == COMPLETION_COMPLETE_PASS) {
return get_string("passed", "mod_videotime");
} else if ($data == COMPLETION_COMPLETE_FAIL) {
return get_string("failed", "mod_videotime");
} else {
return get_string("incomplete", "mod_videotime");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function get_query_template(): builder {
->select('vts.id', 'vts_id')
->from('videotime', 'vt')
->join('course_modules', 'cm', 'instance', 'vt.id', join::TYPE_INNER_JOIN, ['cm.module' => $module])
->join('videotime_pro_session', 'vts', 'module_id', 'cm.id')
->join('videotimeplugin_pro_session', 'vts', 'module_id', 'cm.id')
->join('user', 'u', 'id', 'vts.user_id')
->join('course', 'c', 'id', 'vt.course')
->join('course_categories', 'cc', 'id', 'c.category')
Expand Down
21 changes: 19 additions & 2 deletions classes/local/dash_framework/structure/videotime_session_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
use mod_videotime\local\block_dash\attribute\video_created_attribute;
use mod_videotime\local\block_dash\attribute\video_preview_attribute;
use mod_videotime\local\block_dash\attribute\views_attribute;
use mod_videotime\local\block_dash\attribute\completion_status_attribute;
use moodle_url;

defined('MOODLE_INTERNAL') || die();
Expand Down Expand Up @@ -83,7 +84,7 @@ public function get_title(): string {
* @return field_interface[]
*/
public function get_fields(): array {
return [
$fields = [
new field('id', new lang_string('pluginname', 'videotime'), $this, null, [
new identifier_attribute()
]),
Expand All @@ -101,7 +102,23 @@ public function get_fields(): array {
]),
new field('current_watch_time', new lang_string('currentwatchtime', 'videotime'), $this, 'MAX(current_watch_time)', [
new time_attribute()
])
]),
];

if (videotime_has_repository()) {
$addfields = [
new field('watched_time', new lang_string('watchedtime', 'videotime'), $this, 'MAX(watched_time)', [
new time_attribute()
]),
new field('time_left', new lang_string('timeleft', 'videotime'), $this, 'MAX(time_left)', [
new time_attribute()
]),
new field('status', new lang_string('activitystatus', 'videotime'), $this, 'MAX(status)', [
new completion_status_attribute()
])
];
$fields = array_merge($fields, $addfields);
}
return $fields;
}
}
7 changes: 7 additions & 0 deletions lang/en/videotime.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@
$string['confirmation'] = 'Confirmation';
$string['create_vimeo_app'] = 'Create Vimeo App';
$string['currentwatchtime'] = 'Current watch time';
$string['watchedtime'] = "Time watched";
$string['timeleft'] = "Time Left";
$string['activitystatus'] = "Activity completion status";
$string['datasource:videotime_sessions_data_source'] = 'Video Time sessions';
$string['datasource:videotime_stats_data_source'] = 'Video Time stats';
$string['default'] = 'Default';
Expand Down Expand Up @@ -322,3 +325,7 @@
$string['completiondetail:_on_view_time'] = 'View for time {$a}';
$string['completiondetail:_on_finish'] = 'Finish video';
$string['completiondetail:_on_percent'] = 'Finish watching {$a} percent';
$string['completed'] = "Completed";
$string['passed'] = "Passed";
$string['failed'] = "Failed";
$string['incomplete'] = "Incomplete";
5 changes: 2 additions & 3 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -645,8 +645,7 @@ function videotime_cm_info_view(cm_info $cm) {
}

/**
* Add a get_coursemodule_info function in case any forum type wants to add 'extra' information
* for the course (see resource).
* Add a get_coursemodule_info function to add description and completion information
*
* Given a course_module object, this function returns any "extra" information that may be needed
* when printing this activity in a course listing. See get_array_of_activities() in course/lib.php.
Expand All @@ -668,7 +667,7 @@ function videotime_get_coursemodule_info($coursemodule) {

if ($coursemodule->showdescription) {
// Convert intro to html. Do not filter cached version, filters run at display time.
$result->content = format_module_intro('forum', $instance, $coursemodule->id, false);
$result->content = format_module_intro('videotime', $instance, $coursemodule->id, false);
}

// Populate the custom completion rules as key => value pairs, but only if the completion mode is 'automatic'.
Expand Down
2 changes: 1 addition & 1 deletion version.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

$plugin->component = 'mod_videotime';
$plugin->release = '1.7.2';
$plugin->version = 2023011206;
$plugin->version = 2023080700;
$plugin->incompatible = 402;
$plugin->requires = 2015111610;
$plugin->maturity = MATURITY_STABLE;

0 comments on commit 6095bba

Please sign in to comment.