Skip to content

Commit

Permalink
VID-686: Change videojs height width type
Browse files Browse the repository at this point in the history
  • Loading branch information
dthies committed Aug 14, 2023
1 parent 69befc8 commit abc8f93
Show file tree
Hide file tree
Showing 11 changed files with 90 additions and 21 deletions.
12 changes: 11 additions & 1 deletion classes/vimeo_embed.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@
*/
class vimeo_embed implements \renderable, \templatable {

/**
* @var $cm Course module
*/
protected $cm = null;

/**
* @var $record Instance rocord
*/
protected $record = null;

/**
* Constructor
*
Expand All @@ -61,7 +71,7 @@ public function __construct(\stdClass $instancerecord) {
*/
public function get_cm() {
if (is_null($this->cm)) {
$this->cm = get_coursemodule_from_instance('videotime', $this->id);
$this->cm = get_coursemodule_from_instance('videotime', $this->record->id);
}
return $this->cm;
}
Expand Down
2 changes: 1 addition & 1 deletion lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ function videotime_update_instance($moduleinstance, $mform = null) {

videotime_grade_item_update($moduleinstance);

if (videotime_has_repository()) {
if (videotime_has_repository() && !empty($moduleinstance->vimeo_url)) {
\videotimeplugin_repository\video::add_adhoc($moduleinstance->vimeo_url);
}

Expand Down
7 changes: 7 additions & 0 deletions plugin/videojs/classes/form/options.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,13 @@ public function definition() {
$mform->setDefault('speed', get_config('videotime', 'speed'));
self::create_additional_field_form_elements('speed', $mform);

$mform->addElement('filemanager', 'poster', get_string('poster', 'videotimeplugin_videojs'), null, [
'subdirs' => 0,
'maxfiles' => 1,
'accepted_types' => ['image'],
]);
$mform->addHelpButton('poster', 'poster', 'videotimeplugin_videojs');

// Add fields from extensions.
foreach (array_keys(core_component::get_plugin_list('videotimeplugin')) as $name) {
component_callback("videotimeplugin_$name", 'add_form_fields', [$mform, get_class($this)]);
Expand Down
23 changes: 22 additions & 1 deletion plugin/videojs/classes/video_embed.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
namespace videotimeplugin_videojs;

use context_module;
use context_system;
use core_component;
use mod_videotime\vimeo_embed;
use moodle_url;
Expand Down Expand Up @@ -71,9 +72,29 @@ public function export_for_template(renderer_base $output) {
)->out(false);
}
}

$isvideo = !file_mimetype_in_typegroup($mimetype, ['web_audio']);
if (empty($poster) && !$isvideo) {
$poster = $output->image_url('f/audio-256', 'core');
$files = $fs->get_area_files(context_system::instance()->id, 'videotimeplugin_videojs', 'audioimage', 0);
foreach ($files as $file) {
if (!$file->is_directory()) {
$poster = moodle_url::make_pluginfile_url(
$file->get_contextid(),
$file->get_component(),
$file->get_filearea(),
null,
$file->get_filepath(),
$file->get_filename(),
false
);
}
}
}

$context = parent::export_for_template($output) + [
'mimetype' => $mimetype,
'video' => !file_mimetype_in_typegroup($mimetype, ['web_audio']),
'video' => $isvideo,
'poster' => $poster ?? false,
];

Expand Down
2 changes: 2 additions & 0 deletions plugin/videojs/lang/en/videotimeplugin_videojs.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

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

$string['audioimage'] = 'Default audio image';
$string['audioimage_desc'] = 'Default image to display for audio files when no poster image is provided for activity in embed options';
$string['mediafile'] = 'Media file';
$string['mediafile_help'] = 'Upload an audio or video file to use';
$string['pluginname'] = 'Video Time VideoJS Player';
Expand Down
34 changes: 24 additions & 10 deletions plugin/videojs/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ function videotimeplugin_videojs_update_instance($moduleinstance, $mform = null)
global $DB;

if (
mod_videotime_get_vimeo_id_from_link($moduleinstance->vimeo_url)
|| empty(get_config('videotimeplugin_videojs', 'enabled'))
empty(get_config('videotimeplugin_videojs', 'enabled'))
|| !empty($moduleinstance->vimeo_url)
&& mod_videotime_get_vimeo_id_from_link($moduleinstance->vimeo_url)
) {
return;
}
Expand All @@ -71,7 +72,7 @@ function videotimeplugin_videojs_update_instance($moduleinstance, $mform = null)
0,
['subdirs' => 0, 'maxfiles' => 1]
);
} else {
} else if (!empty($data->mediafile)) {
file_save_draft_area_files(
$data->mediafile,
$context->id,
Expand Down Expand Up @@ -236,13 +237,6 @@ function videotimeplugin_videojs_add_form_fields($mform, $formclass) {
'name'
);
$mform->addHelpButton('mediafile', 'mediafile', 'videotimeplugin_videojs');
} else {
$mform->addElement('filemanager', 'poster', get_string('poster', 'videotimeplugin_videojs'), null, [
'subdirs' => 0,
'maxfiles' => 1,
'accepted_types' => ['image'],
]);
$mform->addHelpButton('poster', 'poster', 'videotimeplugin_videojs');
}
}

Expand Down Expand Up @@ -293,6 +287,26 @@ function videotimeplugin_videojs_data_preprocessing(array &$defaultvalues, int $
* @return bool false if the file was not found, just send the file otherwise and do not return anything
*/
function videotimeplugin_videojs_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options=array()) {
if ($context->contextlevel == CONTEXT_SYSTEM && $filearea == 'audioimage' ) {

// Extract the filename / filepath from the $args array.
$filename = array_pop($args);
if (!$args) {
$filepath = '/';
} else {
$filepath = '/' . implode('/', $args) . '/';
}

// Retrieve the file from the Files API.
$itemid = 0;
$fs = get_file_storage();
$file = $fs->get_file($context->id, 'videotimeplugin_videojs', $filearea, $itemid, $filepath, $filename);
if (!$file) {
return false; // The file does not exist.
}

send_stored_file($file, null, 0, $forcedownload, $options);
}

if ($context->contextlevel != CONTEXT_MODULE) {
return false;
Expand Down
14 changes: 14 additions & 0 deletions plugin/videojs/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,20 @@
'videotimeplugin_videojs/speed', get_string('option_speed', 'videotime'),
get_string('option_speed_help', 'videotime'), '1'));

$options = [
'accepted_types' => [
'.png', '.jpg', '.gif', '.webp', '.tiff', '.svg'
],
];
$settings->add(new admin_setting_configstoredfile(
'videotimeplugin_videojs/audioimage',
new lang_string('audioimage', 'videotimeplugin_videojs'),
new lang_string('audioimage_desc', 'videotimeplugin_videojs'),
'audioimage',
0,
$options
));

$settings->add(new admin_setting_heading('forcedhdr', get_string('forcedsettings', 'videotime'), ''));

$options = [
Expand Down
2 changes: 1 addition & 1 deletion plugin/videojs/templates/video_embed.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@
{{^ video }}
<audio class="video-js"
id="vimeo-embed-{{uniqueid}}"
{{# poster }} poster="{{ poster }}" {{/ poster }}
controls {{# playsinline }} playsinline {{/ playsinline }}
>
<source src="{{ vimeo_url }}" type="{{ mimetype }}" />
</audio>
{{/ video }}
</div>
Expand Down
5 changes: 3 additions & 2 deletions plugin/vimeo/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ function videotimeplugin_vimeo_update_instance($moduleinstance, $mform = null) {
global $DB;

if (
!mod_videotime_get_vimeo_id_from_link($moduleinstance->vimeo_url)
|| empty(get_config('videotimeplugin_vimeo', 'enabled'))
empty(get_config('videotimeplugin_vimeo', 'enabled'))
|| empty($moduleinstance->vimeo_url)
|| !mod_videotime_get_vimeo_id_from_link($moduleinstance->vimeo_url)
) {
return;
}
Expand Down
8 changes: 4 additions & 4 deletions tests/behat/videotime_notes.feature
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ Feature: Video Time notes
| student | C1 | student |
And the following "activities" exist:
| activity | name | intro | course | vimeo_url | label_mode | section | enabletabs | video_description | show_description_in_player |
| videotime | Video Time without tabs | This video has information | C1 | https://vimeo.com/253989945 | 0 | 1 | 0 | The world is round | 0 |
| videotime | Video Time with tabs | This video has information | C1 | https://vimeo.com/253989945 | 0 | 1 | 1 | The world is round | 1 |
| videotime | Video Time with info | This video has information | C1 | https://vimeo.com/253989945 | 0 | 1 | 0 | The world is round | 1 |
| videotime | Video Time with no info | This video has information | C1 | https://vimeo.com/253989945 | 0 | 1 | 1 | The world is round | 0 |
| videotime | Video Time without tabs | This video has information | C1 | https://vimeo.com/347119375 | 0 | 1 | 0 | The world is round | 0 |
| videotime | Video Time with tabs | This video has information | C1 | https://vimeo.com/347119375 | 0 | 1 | 1 | The world is round | 1 |
| videotime | Video Time with info | This video has information | C1 | https://vimeo.com/347119375 | 0 | 1 | 0 | The world is round | 1 |
| videotime | Video Time with no info | This video has information | C1 | https://vimeo.com/347119375 | 0 | 1 | 1 | The world is round | 0 |
And I am on the "Video Time with tabs" "videotime activity editing" page logged in as "teacher"
And I set the following fields to these values:
| Video Time Information tab | 1 |
Expand Down
2 changes: 1 addition & 1 deletion tests/behat/videotime_tab.feature
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Feature: Configure videotime tabs
| student | C1 | student |
And the following "activities" exist:
| activity | name | intro | course | vimeo_url | label_mode | section | enabletabs |
| videotime | Video Time with information | This video has information | C1 | https://vimeo.com/253989945 | 0 | 1 | 1 |
| videotime | Video Time with information | This video has information | C1 | https://vimeo.com/347119375 | 0 | 1 | 1 |
And I am on the "Video Time with information" "videotime activity editing" page logged in as "teacher"
And I set the following fields to these values:
| Video Time Information tab | 1 |
Expand Down

0 comments on commit abc8f93

Please sign in to comment.