Skip to content

Commit

Permalink
MED-100: Cleanup code
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Thies committed Apr 19, 2024
1 parent 5313179 commit 1f4ac98
Show file tree
Hide file tree
Showing 19 changed files with 75 additions and 65 deletions.
45 changes: 30 additions & 15 deletions classes/admin/manage_mediatimesrc_plugins_page.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,17 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class manage_mediatimesrc_plugins_page extends \admin_setting {

/**
* Class manage_mediatimesrc_plugins_page constructor.
*/
public function __construct() {
$this->nosave = true;
parent::__construct('managemediatimesrc',
new \lang_string('managemediatimesrcplugins', 'tool_mediatime'), '', '');
parent::__construct(
'managemediatimesrc',
new \lang_string('managemediatimesrcplugins', 'tool_mediatime'),
'',
''
);
}

/**
Expand Down Expand Up @@ -82,8 +85,10 @@ public function is_related($query): bool {
}
$types = \core_plugin_manager::instance()->get_plugins_of_type('mediatimesrc');
foreach ($types as $type) {
if (strpos($type->component, $query) !== false ||
strpos(\core_text::strtolower($type->displayname), $query) !== false) {
if (
strpos($type->component, $query) !== false ||
strpos(\core_text::strtolower($type->displayname), $query) !== false
) {
return true;
}
}
Expand Down Expand Up @@ -131,20 +136,26 @@ public function output_html($data, $query = ''): string {
]);

$class = '';
if ($pluginmanager->get_plugin_info('mediatimesrc_'.$type->name)->get_status() ===
\core_plugin_manager::PLUGIN_STATUS_MISSING) {
$strtypename = $type->displayname.' ('.get_string('missingfromdisk').')';
if (
$pluginmanager->get_plugin_info('mediatimesrc_' . $type->name)->get_status() ===
\core_plugin_manager::PLUGIN_STATUS_MISSING
) {
$strtypename = $type->displayname . ' (' . get_string('missingfromdisk') . ')';
} else {
$strtypename = $type->displayname;
}

if ($type->is_enabled()) {
$hideshow = \html_writer::link($url->out(false, ['action' => 'disable']),
$OUTPUT->pix_icon('t/hide', $txt->disable, 'moodle', ['class' => 'iconsmall']));
$hideshow = \html_writer::link(
$url->out(false, ['action' => 'disable']),
$OUTPUT->pix_icon('t/hide', $txt->disable, 'moodle', ['class' => 'iconsmall'])
);
} else {
$class = 'dimmed_text';
$hideshow = \html_writer::link($url->out(false, ['action' => 'enable']),
$OUTPUT->pix_icon('t/show', $txt->enable, 'moodle', ['class' => 'iconsmall']));
$hideshow = \html_writer::link(
$url->out(false, ['action' => 'enable']),
$OUTPUT->pix_icon('t/show', $txt->enable, 'moodle', ['class' => 'iconsmall'])
);
}

$settings = '';
Expand All @@ -153,8 +164,12 @@ public function output_html($data, $query = ''): string {
}

$uninstall = '';
if ($uninstallurl = \core_plugin_manager::instance()->get_uninstall_url(
'mediatimesrc_'.$type->name, 'manage')) {
if (
$uninstallurl = \core_plugin_manager::instance()->get_uninstall_url(
'mediatimesrc_' . $type->name,
'manage'
)
) {
$uninstall = \html_writer::link($uninstallurl, $txt->uninstall);
}

Expand All @@ -167,7 +182,7 @@ public function output_html($data, $query = ''): string {
}

// Sort table data.
usort($table->data, function($a, $b) {
usort($table->data, function ($a, $b) {
$aid = $a->cells[0]->text;
$bid = $b->cells[0]->text;

Expand Down
1 change: 0 additions & 1 deletion classes/event/resource_created.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class resource_created extends base {

// For more information about the Events API please visit {@link https://docs.moodle.org/dev/Events_API}.

/**
Expand Down
1 change: 0 additions & 1 deletion classes/event/resource_deleted.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class resource_deleted extends base {

// For more information about the Events API please visit {@link https://docs.moodle.org/dev/Events_API}.

/**
Expand Down
1 change: 0 additions & 1 deletion classes/event/resource_updated.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class resource_updated extends base {

// For more information about the Events API please visit {@link https://docs.moodle.org/dev/Events_API}.

/**
Expand Down
1 change: 0 additions & 1 deletion classes/form/delete_resource.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class delete_resource extends moodleform {

/**
* Definition
*/
Expand Down
1 change: 0 additions & 1 deletion classes/form/edit_resource.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class edit_resource extends moodleform {

/**
* Definition
*/
Expand Down
1 change: 0 additions & 1 deletion classes/form/search.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class search extends moodleform {

/**
* Definition
*/
Expand Down
4 changes: 2 additions & 2 deletions classes/media_manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ public static function search($filters = []) {
if (!$sources = plugininfo\mediatimesrc::get_enabled_plugins()) {
return $result;
}
list($sql, $params) = $DB->get_in_or_equal($sources, SQL_PARAMS_NAMED);
[$sql, $params] = $DB->get_in_or_equal($sources, SQL_PARAMS_NAMED);

$sql = "source $sql";
$order = 'timecreated DESC';
Expand All @@ -205,7 +205,7 @@ public static function search($filters = []) {
$tags = core_tag_tag::get_by_name_bulk($tagcollid, $tags);
$tags = array_column($tags, 'id');
if (!empty($tags)) {
list($tagsql, $tagparams) = $DB->get_in_or_equal($tags, SQL_PARAMS_NAMED, 'tagparams');
[$tagsql, $tagparams] = $DB->get_in_or_equal($tags, SQL_PARAMS_NAMED, 'tagparams');
$sql .= " AND id IN (SELECT itemid FROM {tag_instance} WHERE tagid $tagsql)";
$params += $tagparams;
}
Expand Down
9 changes: 6 additions & 3 deletions classes/plugininfo/mediatimesrc.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class mediatimesrc extends base {

/**
* Allow uninstall
*
Expand Down Expand Up @@ -67,8 +66,12 @@ public function load_settings(\part_of_admin_tree $adminroot, $parentnodename, $
return;
}
$section = $this->get_settings_section_name();
$settings = new \admin_settingpage($section, $this->displayname,
'moodle/site:config', $this->is_enabled() === false);
$settings = new \admin_settingpage(
$section,
$this->displayname,
'moodle/site:config',
$this->is_enabled() === false
);

include($this->full_path('settings.php')); // This may also set $settings to null.

Expand Down
21 changes: 7 additions & 14 deletions classes/privacy/provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,16 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class provider implements
// The Plenary meeting module stores user provided data.
\core_privacy\local\metadata\provider,

// This plugin is a core_user_data_provider.
\core_privacy\local\request\plugin\provider,

\core_privacy\local\request\core_userlist_provider {

\core_privacy\local\request\core_userlist_provider,
\core_privacy\local\metadata\provider,
\core_privacy\local\request\plugin\provider {
/**
* Returns meta data about this system.
*
* @param collection $collection
* @return collection
*/
public static function get_metadata(collection $collection) : collection {
public static function get_metadata(collection $collection): collection {

return $collection->add_database_table(
'tool_mediatime',
Expand All @@ -76,7 +71,7 @@ public static function get_metadata(collection $collection) : collection {
* @param int $userid The user to search.
* @return contextlist $contextlist The contextlist containing the list of contexts used in this plugin.
*/
public static function get_contexts_for_userid(int $userid) : contextlist {
public static function get_contexts_for_userid(int $userid): contextlist {
$sql = "SELECT c.id
FROM {tool_mediatime} m
JOIN {context} c ON c.contextlevel = :contextlevel
Expand Down Expand Up @@ -121,7 +116,7 @@ public static function export_user_data(approved_contextlist $contextlist) {
global $DB;

// Remove contexts different from CONTEXT_SYSTEM.
$contexts = array_reduce($contextlist->get_contexts(), function($carry, $context) {
$contexts = array_reduce($contextlist->get_contexts(), function ($carry, $context) {
if ($context->contextlevel == CONTEXT_SYSTEM) {
$carry[] = $context->id;
}
Expand All @@ -135,7 +130,7 @@ public static function export_user_data(approved_contextlist $contextlist) {
$user = $contextlist->get_user();
$userid = $user->id;
// Get motion data.
list($insql, $inparams) = $DB->get_in_or_equal($contexts, SQL_PARAMS_NAMED);
[$insql, $inparams] = $DB->get_in_or_equal($contexts, SQL_PARAMS_NAMED);
$sql = "SELECT m.id,
m.name,
m.content,
Expand Down Expand Up @@ -194,7 +189,6 @@ public static function delete_data_for_users(approved_userlist $userlist) {
if (!$context instanceof \context_system) {
return;
}

}

/**
Expand All @@ -206,6 +200,5 @@ public static function delete_data_for_user(approved_contextlist $contextlist) {
global $DB;

return;

}
}
9 changes: 4 additions & 5 deletions lang/en/tool_mediatime.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,18 @@

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

$string['pluginname'] = 'Media Time';
$string['addnewcontent'] = 'Add new content';
$string['event_resource_created'] = 'Resource created';
$string['event_resource_deleted'] = 'Resource deleted';
$string['event_resource_updated'] = 'Resource updated';
$string['filelinks'] = 'File links';
$string['library'] = 'Library';
$string['keyword'] = 'Keyword';
$string['library'] = 'Library';
$string['managemediatimesrcplugins'] = 'Manage source plugins';
$string['mediatime:create'] = 'Create media in library';
$string['mediatime:manage'] = 'Manage media in library';
$string['mediatime:view'] = 'View media in library';
$string['pluginname'] = 'Media Time';
$string['privacy:metadata:tool_mediatime'] = 'The Media Time plugin stores and transmits data that is not normally private, but does record the last user to modify it.';
$string['privacy:metadata:tool_mediatime:content'] = 'Media content';
$string['privacy:metadata:tool_mediatime:name'] = 'Media name';
Expand All @@ -44,10 +45,8 @@
$string['privacy:metadata:tool_mediatime:usermodified'] = 'User modified';
$string['resourcename'] = 'Resource name';
$string['resourcename_help'] = 'The name for a resource is used internally in the library to identify the resource, but not displayed when it is used.';
$string['managemediatimesrcplugins'] = 'Manage source plugins';
$string['subplugin_mediatimesrc_plural'] = 'Media sources';
$string['subplugintype_mediatimesrc_plural'] = 'Media Time sources';
$string['tagarea_tool_mediatime'] = 'Media resources';
$string['title'] = 'Title';
$string['title_help'] = 'The title may be displayed by the video player when used';
$string['subplugintype_mediatimesrc_plural'] = 'Media Time sources';
$string['filelinks'] = 'File links';
8 changes: 5 additions & 3 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,18 @@
* @param array $options additional options affecting the file serving
* @return bool false if the file was not found, just send the file otherwise and do not return anything
*/
function tool_mediatime_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options=[]) {
function tool_mediatime_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options = []) {
if ($context->contextlevel != CONTEXT_SYSTEM) {
return false;
}

require_login();

if (in_array($filearea, [
if (
in_array($filearea, [
'm3u8',
])) {
])
) {
$itemid = array_shift($args);

$relativepath = implode('/', $args);
Expand Down
12 changes: 5 additions & 7 deletions settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,11 @@
if ($hassiteconfig) {
$settings = new admin_settingpage('tool_mediatime_settings', new lang_string('pluginname', 'tool_mediatime'));

// phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedIf
if ($ADMIN->fulltree) {
// TODO: Define actual plugin settings page and add it to the tree - {@link https://docs.moodle.org/dev/Admin_settings}.
}

$ADMIN->add('tools', new admin_category('toolmediatime',
new lang_string('pluginname', 'tool_mediatime'), false));
$ADMIN->add('tools', new admin_category(
'toolmediatime',
new lang_string('pluginname', 'tool_mediatime'),
false
));

$pluginmanager = core_plugin_manager::instance();
$ADMIN->add('toolmediatime', new admin_category(
Expand Down
4 changes: 2 additions & 2 deletions source/streamio/templates/file_upload.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@
<input type="hidden" name="tags" value="{{ tags }}" >
<div class="container-fluid">
<fieldset class="w-100 m-0 p-0 border-0">
<input type="file" name="streamiofile">
<input type="file" name="streamiofile" accept="video/*">
</fieldset>
<div class="col bg-secondary p-0 m-3">
<div class="progress bg-primary" style="width: 0%; height: 1em;"></div>
</div>
<div class="p-3">
<button name="upload" type="button" class="btn btn-primary" accept="video/*">{{# str }} upload {{/ str }}</button>
<button name="upload" type="button" class="btn btn-primary">{{# str }} upload {{/ str }}</button>
<button name="cancel" value="true" class="btn btn-secondary">{{# str }} cancel {{/ str }}</button>
</div>
</div>
Expand Down
3 changes: 1 addition & 2 deletions source/vimeo/classes/external/create_token.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,8 @@ public static function execute_parameters(): external_function_parameters {
/**
* Create place holder
*
* @param int $filesize Video file size
* @param string $description Name of resource
* @param string $filesize Video file size
* @param int $filesize Video file size
* @param string $name Name of resource
* @param string $tags Name of resource
* @param string $title Name of resource
Expand Down
5 changes: 4 additions & 1 deletion source/vimeo/templates/file_upload.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
Example context (json):
{
name: "Donald",
title: "DucK",
description: "Quack, quack, quack"
}

}}
Expand All @@ -51,6 +54,6 @@
</form>
{{# js }}
require(['mediatimesrc_vimeo/file_upload'], function(FileUpload) {
FileUpload.init('{{ filesize }}');
FileUpload.init();
});
{{/ js }}
5 changes: 5 additions & 0 deletions source/vimeo/templates/media_resource.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,13 @@
"canedit": true,
"id": 2,
"resource": {
"id": 1,
"title": "title",
"name": "name",
"resource": {
"name": "Happy",
"link": "https://vimeo.com/30208324"
},
"description": "big and blue"
}
}
Expand Down
7 changes: 3 additions & 4 deletions source/vimeo/templates/video.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,9 @@
Example context (json):
{
"id": "324lk32sK",
"screenshot": {
"normal": "example.com/image.jpg"
}
"uniqueid": "324lk32sK",
"interval": 0,
"instance": "{}"
}

}}
Expand Down
Loading

0 comments on commit 1f4ac98

Please sign in to comment.