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 3f8978d commit 151ecfd
Show file tree
Hide file tree
Showing 11 changed files with 167 additions and 51 deletions.
66 changes: 45 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,6 +135,7 @@ 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),
Expand All @@ -141,33 +144,13 @@ public function export_for_template(renderer_base $output): array {
'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 @@ -219,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
4 changes: 4 additions & 0 deletions source/streamio/classes/output/media_resource.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,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 @@ -87,6 +89,8 @@ 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' => $this->content,
'video' => $output->render_from_template('mediatimesrc_streamio/video', $content),
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/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
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>
6 changes: 4 additions & 2 deletions templates/media_manager.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,14 @@
</div>
<div class="card-footer">
{{# name }}
{{ name }}
<a href="{{ url }}" class="btn">
<i class="fa fa-play"></i> {{ name }}
</a>
{{/ name }}
{{^ name }}
{{ title }}
{{/ name }}
<a href="{{ removeurl }}" class="float-right"><i class="icon fa fa-trash"></i></a>
{{> tool_mediatime/dropdown }}
</div>
</div>
</div>
Expand Down
31 changes: 23 additions & 8 deletions templates/media_resource.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,31 @@
Example context (json):
{
"canedit": true,
"id": 2,
"resource": {
"title": "title",
"name": "name",
"description": "big and blue"
}
}

}}
<form action='.' method="post">
{{# canedit }}
<button type="submit" name="edit" value="{{ id }}">{{# str }} edit {{/ str }}</button>
<button type="submit" name="delete" value="{{ id }}">{{# str }} delete {{/ str }}</button>
{{/ canedit }}
<a href="{{ libraryhome }}">{{# str }}library, tool_mediatime {{/ str }}</a>
</form>
<div class="library-resource">
{{{ resource }}}
<form action="." method="post">
{{# canedit }}
{{> tool_mediatime/dropdown }}
{{/ canedit }}
{{# libraryhome }}
<button action="{{ libraryhome }}" class="float-right"><i class="fa fa-angle-double-left"></i>{{# str }}libraryhome, tool_mediatime {{/ str }}</button>
{{/ libraryhome }}
</form>
<div class="container-fluid">
{{$ resourcecontent }}
<h3>{{ resource.name }}</h3>
<h4>{{ resource.title }}</h4>
{{{ video }}}
<p>{{ resource.description }}</p>
{{/ resourcecontent }}
</div>
</div>

0 comments on commit 151ecfd

Please sign in to comment.