From d603e34b38b88ab5bf7701dc3fc5a5b14d9b3f10 Mon Sep 17 00:00:00 2001 From: Daniel Thies Date: Tue, 15 Aug 2023 05:29:48 -0500 Subject: [PATCH] VID-686: Change videojs height width type --- classes/vimeo_embed.php | 12 ++++++- lib.php | 2 +- plugin/videojs/classes/form/options.php | 7 ++++ plugin/videojs/classes/video_embed.php | 23 ++++++++++++- .../lang/en/videotimeplugin_videojs.php | 2 ++ plugin/videojs/lib.php | 34 +++++++++++++------ plugin/videojs/settings.php | 14 ++++++++ plugin/videojs/templates/video_embed.mustache | 2 +- plugin/vimeo/lib.php | 5 +-- .../videotimeplugin_vimeo_settings.feature | 4 +-- tests/behat/videotime_notes.feature | 8 ++--- tests/behat/videotime_tab.feature | 2 +- 12 files changed, 92 insertions(+), 23 deletions(-) diff --git a/classes/vimeo_embed.php b/classes/vimeo_embed.php index 38e17a68..c51faf03 100644 --- a/classes/vimeo_embed.php +++ b/classes/vimeo_embed.php @@ -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 * @@ -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; } diff --git a/lib.php b/lib.php index 20ff8782..8f6c7339 100644 --- a/lib.php +++ b/lib.php @@ -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); } diff --git a/plugin/videojs/classes/form/options.php b/plugin/videojs/classes/form/options.php index 7d97686e..57e0b1d0 100644 --- a/plugin/videojs/classes/form/options.php +++ b/plugin/videojs/classes/form/options.php @@ -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)]); diff --git a/plugin/videojs/classes/video_embed.php b/plugin/videojs/classes/video_embed.php index ab265d53..8b0c8761 100644 --- a/plugin/videojs/classes/video_embed.php +++ b/plugin/videojs/classes/video_embed.php @@ -25,6 +25,7 @@ namespace videotimeplugin_videojs; use context_module; +use context_system; use core_component; use mod_videotime\vimeo_embed; use moodle_url; @@ -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, ]; diff --git a/plugin/videojs/lang/en/videotimeplugin_videojs.php b/plugin/videojs/lang/en/videotimeplugin_videojs.php index a69bcccc..e2d1a6a3 100644 --- a/plugin/videojs/lang/en/videotimeplugin_videojs.php +++ b/plugin/videojs/lang/en/videotimeplugin_videojs.php @@ -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'; diff --git a/plugin/videojs/lib.php b/plugin/videojs/lib.php index 9b7bb1db..2450f999 100644 --- a/plugin/videojs/lib.php +++ b/plugin/videojs/lib.php @@ -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; } @@ -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, @@ -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'); } } @@ -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; diff --git a/plugin/videojs/settings.php b/plugin/videojs/settings.php index d9f526a9..be419b7b 100644 --- a/plugin/videojs/settings.php +++ b/plugin/videojs/settings.php @@ -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 = [ diff --git a/plugin/videojs/templates/video_embed.mustache b/plugin/videojs/templates/video_embed.mustache index 5c9c48e5..9624cdac 100644 --- a/plugin/videojs/templates/video_embed.mustache +++ b/plugin/videojs/templates/video_embed.mustache @@ -58,9 +58,9 @@ {{^ video }} {{/ video }} diff --git a/plugin/vimeo/lib.php b/plugin/vimeo/lib.php index 687fa353..759276bc 100644 --- a/plugin/vimeo/lib.php +++ b/plugin/vimeo/lib.php @@ -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; } diff --git a/plugin/vimeo/tests/behat/videotimeplugin_vimeo_settings.feature b/plugin/vimeo/tests/behat/videotimeplugin_vimeo_settings.feature index a15ea06f..217ae956 100644 --- a/plugin/vimeo/tests/behat/videotimeplugin_vimeo_settings.feature +++ b/plugin/vimeo/tests/behat/videotimeplugin_vimeo_settings.feature @@ -18,8 +18,8 @@ Feature: Configure vimeo settings | student | C1 | student | And the following "activities" exist: | activity | name | course | vimeo_url | label_mode | section | controls | - | videotime | Video Time with controls | C1 | https://vimeo.com/253989945 | 0 | 1 | 1 | - | videotime | Video Time with no controls | C1 | https://vimeo.com/253989945 | 0 | 1 | 0 | + | videotime | Video Time with controls | C1 | https://vimeo.com/347119375 | 0 | 1 | 1 | + | videotime | Video Time with no controls | C1 | https://vimeo.com/347119375 | 0 | 1 | 0 | @javascript Scenario: Controls are available diff --git a/tests/behat/videotime_notes.feature b/tests/behat/videotime_notes.feature index a04b8ce6..2ce70f09 100644 --- a/tests/behat/videotime_notes.feature +++ b/tests/behat/videotime_notes.feature @@ -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 | diff --git a/tests/behat/videotime_tab.feature b/tests/behat/videotime_tab.feature index ced6e863..a7f4eb7c 100644 --- a/tests/behat/videotime_tab.feature +++ b/tests/behat/videotime_tab.feature @@ -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 |