Skip to content

Commit

Permalink
MED-110: Improve library interface
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Thies committed Oct 14, 2024
1 parent 0386769 commit 79db736
Show file tree
Hide file tree
Showing 17 changed files with 199 additions and 61 deletions.
67 changes: 46 additions & 21 deletions classes/media_manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

namespace tool_mediatime;

use block_contents;
use context_system;
use core_tag_tag;
use core_tag_area;
Expand Down Expand Up @@ -104,6 +105,7 @@ public function __construct(string $source, ?stdClass $record = null, int $page
$this->media[] = $media;
}
}
$this->setup_page();

$rs->close();
}
Expand Down Expand Up @@ -133,40 +135,22 @@ public function export_for_template(renderer_base $output): array {
foreach ($this->media as $record) {
$resource = new output\media_resource($record);
$url = new moodle_url('/admin/tool/mediatime/index.php', ['id' => $record->id]);
$editurl = new moodle_url('/admin/tool/mediatime/index.php', ['edit' => $record->id]);
$removeurl = new moodle_url('/admin/tool/mediatime/index.php', ['delete' => $record->id]);
$media[] = [
'imageurl' => $resource->image_url($output),
'tags' => $resource->tags($output),
'url' => $url->out(),
'name' => $record->name,
'title' => $resource->get_title(),
'description' => shorten_text(json_decode($record->content)->description ?? '', 80),
'editurl' => $editurl->out(),
'removeurl' => $removeurl->out(),
];
}

$plugins = \core_plugin_manager::instance()->get_installed_plugins('mediatimesrc');

$options = [];
foreach (plugininfo\mediatimesrc::get_enabled_plugins() as $plugin) {
$options[$plugin] = get_string("pluginname", "mediatimesrc_$plugin");
}
if (!has_capability('tool/mediatime:manage', context_system::instance())) {
$action = '';
} else if (count($options) == 1) {
$button = new single_button(new moodle_url('/admin/tool/mediatime/index.php', [
'source' => array_keys($options)[0],
]), get_string('addnewcontent', 'tool_mediatime'));
$action = $output->render($button);
} else if (count($options)) {
$select = new single_select(new moodle_url('/admin/tool/mediatime/index.php'), 'source', $options);
$action = get_string('addnewcontent', 'tool_mediatime') . ' ' . $output->render($select);
} else {
$action = '';
}
return [
'action' => $action,
'media' => array_values($media),
'search' => $this->search->render(),
];
}

Expand Down Expand Up @@ -218,4 +202,45 @@ public static function search($filters = []) {
$order
);
}

/**
* Add the search block to default region
*
* @param stdClass $instance Video Time instance
* @param stdClass $cm The course module
*/
protected function setup_page() {
global $OUTPUT, $PAGE, $USER;

$bc = new block_contents();
$bc->title = get_string('sharedvideo', 'videotimeplugin_live');
$bc->attributes['class'] = 'block block_book_toc';

$plugins = \core_plugin_manager::instance()->get_installed_plugins('mediatimesrc');

$options = [];
foreach (plugininfo\mediatimesrc::get_enabled_plugins() as $plugin) {
$options[$plugin] = get_string("pluginname", "mediatimesrc_$plugin");
}
if (!has_capability('tool/mediatime:manage', context_system::instance())) {
$action = '';
} else if (count($options) == 1) {
$button = new single_button(new moodle_url('/admin/tool/mediatime/index.php', [
'source' => array_keys($options)[0],
]), get_string('addnewcontent', 'tool_mediatime'));
$action = $OUTPUT->render($button);
} else if (count($options)) {
$select = new single_select(new moodle_url('/admin/tool/mediatime/index.php'), 'source', $options);
$action = get_string('addnewcontent', 'tool_mediatime') . ' ' . $OUTPUT->render($select);
} else {
$action = '';
}
$bc->content = $OUTPUT->render_from_template('tool_mediatime/block_content', [
'action' => $action,
'search' => $this->search->render(),
]);

$defaultregion = $PAGE->blocks->get_default_region();
$PAGE->blocks->add_fake_block($bc, $defaultregion);
}
}
4 changes: 4 additions & 0 deletions classes/output/media_resource.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,14 @@ public function __construct(stdClass $record) {
public function export_for_template(renderer_base $output) {
global $DB, $USER;
$context = \context_system::instance();
$editurl = new moodle_url('/admin/tool/mediatime/index.php', ['edit' => $this->record->id]);
$removeurl = new moodle_url('/admin/tool/mediatime/index.php', ['delete' => $this->record->id]);

return [
'canedit' => has_capability('tool/mediatime:manage', $context) || ($USER->id == $this->record->usermodified),
'id' => $this->record->id,
'editurl' => $editurl->out(),
'removeurl' => $removeurl->out(),
'libraryhome' => new moodle_url('/admin/tool/mediatime/index.php'),
'resource' => $output->render($this->resource),
'tags' => $this->tags($output),
Expand Down
4 changes: 4 additions & 0 deletions lang/en/tool_mediatime.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@
defined('MOODLE_INTERNAL') || die();

$string['addnewcontent'] = 'Add new content';
$string['editresource'] = 'Edit resource';
$string['event_resource_created'] = 'Resource created';
$string['event_resource_deleted'] = 'Resource deleted';
$string['event_resource_updated'] = 'Resource updated';
$string['filelinks'] = 'File links';
$string['keyword'] = 'Keyword';
$string['library'] = 'Library';
$string['libraryhome'] = 'Back to library';
$string['managemediatimesrcplugins'] = 'Manage source plugins';
$string['mediatime:create'] = 'Create media in library';
$string['mediatime:manage'] = 'Manage media in library';
Expand All @@ -43,6 +45,8 @@
$string['privacy:metadata:tool_mediatime:timecreated'] = 'Time created';
$string['privacy:metadata:tool_mediatime:timemodified'] = 'Time modified';
$string['privacy:metadata:tool_mediatime:usermodified'] = 'User modified';
$string['removeresource'] = 'Remove resource';
$string['resourcemanagementoptions'] = 'Resource management options';
$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['subplugintype_mediatimesrc'] = 'Media Time source';
Expand Down
2 changes: 1 addition & 1 deletion settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
$pluginmanager = core_plugin_manager::instance();
$ADMIN->add('toolmediatime', new admin_category(
'mediatimesrcplugins',
new lang_string('subplugin_mediatimesrc_plural', 'tool_mediatime'),
new lang_string('subplugintype_mediatimesrc_plural', 'tool_mediatime'),
false
));
$temp = new admin_settingpage('managemediatimesrcplugins', new lang_string('managemediatimesrcplugins', 'tool_mediatime'));
Expand Down
5 changes: 5 additions & 0 deletions source/streamio/classes/form/edit_resource.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ public function definition_after_data() {
$context = context_system::instance();
if ($record) {
$content = json_decode($record->content);
$streamioid = $content->id;
$resource = new media_resource($record);

$videourl = $resource->video_url($OUTPUT);
Expand All @@ -117,6 +118,10 @@ public function definition_after_data() {
),
'name'
);
$mform->insertElementBefore(
$mform->createElement('static', 'vimeo_url', get_string('streamioid', 'mediatimesrc_streamio'), $streamioid),
'filesource'
);
$mform->removeElement('filesource');
} else {
if (has_capability('mediatimesrc/streamio:viewall', $context)) {
Expand Down
11 changes: 10 additions & 1 deletion source/streamio/classes/output/media_resource.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class media_resource implements renderable, templatable {
/** @var ?stdClass $content Media Time content object */
protected $content;

/** @var ?stdClass $record Media Time resource record */
protected $record;

Expand All @@ -51,6 +54,8 @@ class media_resource implements renderable, templatable {
*/
public function __construct(stdClass $record) {
$this->record = $record;
$this->content = json_decode($record->content);
$this->content->description = shorten_text($this->content->description, 300);
}

/**
Expand All @@ -63,6 +68,8 @@ public function export_for_template(renderer_base $output) {
global $DB, $USER;
$context = \context_system::instance();
$videourl = $this->video_url($output);
$editurl = new moodle_url('/admin/tool/mediatime/index.php', ['edit' => $this->record->id]);
$removeurl = new moodle_url('/admin/tool/mediatime/index.php', ['delete' => $this->record->id]);

$content = [
'elementid' => 'video-' . uniqid(),
Expand All @@ -82,8 +89,10 @@ public function export_for_template(renderer_base $output) {
return [
'canedit' => has_capability('tool/mediatime:manage', $context) || ($USER->id == $this->record->usermodified),
'id' => $this->record->id,
'editurl' => $editurl->out(),
'removeurl' => $removeurl->out(),
'libraryhome' => new moodle_url('/admin/tool/mediatime/index.php'),
'resource' => $content,
'resource' => $this->content,
'video' => $output->render_from_template('mediatimesrc_streamio/video', $content),
];
}
Expand Down
1 change: 1 addition & 0 deletions source/streamio/lang/en/mediatimesrc_streamio.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
$string['privacy:metadata'] = 'The Streamio plugin for Media Time does not store personal data. It does transmit files associated with educational video content that normally does not contain user data. If it is used for personal data, a separate agreement with the provider may be required.';
$string['removestreamiofiles'] = 'Remove Streamio files';
$string['selectexistingfile'] = 'Select existing file';
$string['streamioid'] = 'Streamio ID';
$string['streamio:upload'] = 'Upload files to Streamio';
$string['streamio:viewall'] = 'View all files available';
$string['streamiofileaction'] = 'Streamio file action';
Expand Down
19 changes: 1 addition & 18 deletions source/streamio/templates/media_resource.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,4 @@
}

}}
<div class="library-resource">
<form action="." method="post">
{{# canedit }}
<input type="hidden" name="source" value="streamio">
<button type="submit" name="edit" value="{{ id }}">{{# str }} edit {{/ str }}</button>
<button type="submit" name="delete" value="{{ id }}">{{# str }} delete {{/ str }}</button>
{{/ canedit }}
{{# libraryhome }}
<a href="{{ libraryhome }}">{{# str }}library, tool_mediatime {{/ str }}</a>
{{/ libraryhome }}
</form>
<div class="container-fluid">
<h3>{{ resource.name }}</h3>
<h4>{{ resource.title }}</h4>
{{{ video }}}
<p>{{ resource.description }}</p>
</div>
</div>
{{> tool_mediatime/media_resource }}
2 changes: 1 addition & 1 deletion source/streamio/templates/video.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
}

}}
<p>
<p class="col col-12 col-md-9 col-lg-8 col-xl-6 text-center">
<video
id="{{ elementid }}"
controls
Expand Down
5 changes: 5 additions & 0 deletions source/videotime/classes/output/media_resource.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class media_resource implements renderable, templatable {
/** @var ?stdClass $content Media Time content object */
protected $content;

/** @var $context System context */
protected $context = null;

Expand All @@ -61,6 +64,8 @@ class media_resource implements renderable, templatable {
public function __construct(stdClass $record) {
$this->record = $record;
$this->context = \context_system::instance();
$this->content = json_decode($record->content);
$this->content->description = shorten_text($this->content->description, 300);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion source/vimeo/classes/external/create_token.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public static function execute($description, $filesize, $name, $tags, $title): a
'tool_mediatime',
$id,
$context,
json_decode(htmlspecialchars_decode($params['tags']))
json_decode(htmlspecialchars_decode($params['tags'], ENT_COMPAT))
);
}

Expand Down
2 changes: 1 addition & 1 deletion source/vimeo/classes/manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ public function export_for_template(renderer_base $output) {
'name' => json_encode($data->name),
'description' => json_encode($data->description),
'title' => json_encode($data->title),
'tags' => htmlspecialchars(json_encode($data->tags)),
'tags' => htmlspecialchars(json_encode($data->tags), ENT_COMPAT),
]),
];
}
Expand Down
5 changes: 5 additions & 0 deletions source/vimeo/classes/output/media_resource.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class media_resource implements renderable, templatable {
/** @var ?stdClass $content Media Time content object */
protected $content;

/** @var $context System context */
protected $context = null;

Expand All @@ -50,6 +53,8 @@ class media_resource implements renderable, templatable {
*/
public function __construct(stdClass $record) {
$this->record = $record;
$this->content = json_decode($record->content);
$this->content->description = shorten_text($this->content->description, 300);
}

/**
Expand Down
40 changes: 40 additions & 0 deletions templates/block_content.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{{!
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/>.
}}
{{!
@template tool_mediatime/media_manager
This template will render the Media manager for media time
Variables required for this template:
Variables optional for this template:
Example context (json):
{
}

}}
<div class="container-fluid">
<div class="row">
<div class="col col-12 col-lg-3">
{{{ action }}}
</div>
<div class="col col-12{{# action }} col-lg-9{{/ action }}">
{{{ search }}}
</div>
</div>
</div>
40 changes: 40 additions & 0 deletions templates/dropdown.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{{!
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/>.
}}
{{!
@template tool_mediatime/dropdown
Simple dropdown for the tool_mediatime library page
Example context (json):
{
"editurl": "https://moodle.test/tool/admin/mediatime/index.php?edit=1",
"removeurl": "https://moodle.test/tool/admin/mediatime/index.php?delete=1"
}
}}
<div class="btn-group float-right">
<a href="#" class="btn btn-link btn-icon icon-size-3 rounded-circle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" title="{{# str }} resourcemanagementoptions, tool_mediatime {{/ str }}">
<i class="fa fa-ellipsis-v text-dark py-2" aria-hidden="true"></i>
</a>
<div class="dropdown-menu dropdown-menu-right">
{{# editurl }}
<a class="dropdown-item" href="{{ editurl }}">{{#str}} editresource , tool_mediatime {{/str}}</a>
{{/ editurl }}
{{# removeurl }}
<a class="dropdown-item" href="{{ removeurl }}">{{#str}} removeresource, tool_mediatime {{/str}}</a>
{{/ removeurl }}
</div>
</div>
Loading

0 comments on commit 79db736

Please sign in to comment.