MDL-67795 contentbank: delete content API
[moodle.git] / contentbank / contenttype / h5p / classes / contenttype.php
CommitLineData
2867550e
AA
1<?php
2// This file is part of Moodle - http://moodle.org/
3//
4// Moodle is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// Moodle is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16
17/**
18 * H5P content type manager class
19 *
20 * @package contenttype_h5p
21 * @copyright 2020 Amaia Anabitarte <amaia@moodle.com>
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23 */
24
25namespace contenttype_h5p;
26
27use stdClass;
28use html_writer;
29
30/**
31 * H5P content bank manager class
32 *
33 * @package contenttype_h5p
34 * @copyright 2020 Amaia Anabitarte <amaia@moodle.com>
35 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
36 */
37class contenttype extends \core_contentbank\contenttype {
38
c0d615e8
SA
39 /**
40 * Delete this content from the content_bank and remove all the H5P related information.
41 *
42 * @param content $content The content to delete.
43 * @return boolean true if the content has been deleted; false otherwise.
44 */
45 public function delete_content(\core_contentbank\content $content): bool {
46 // Delete the H5P content.
47 $factory = new \core_h5p\factory();
48 \core_h5p\api::delete_content_from_pluginfile_url($content->get_file_url(), $factory);
49
50 // Delete the content from the content_bank.
51 return parent::delete_content($content);
52 }
53
2867550e
AA
54 /**
55 * Returns the HTML content to add to view.php visualizer.
56 *
57 * @param stdClass $record Th content to be displayed.
58 * @return string HTML code to include in view.php.
59 */
60 public function get_view_content(\stdClass $record): string {
61 $content = new content($record);
62 $fileurl = $content->get_file_url();
63 $html = html_writer::tag('h2', $content->get_name());
64 $html .= \core_h5p\player::display($fileurl, new \stdClass(), true);
65 return $html;
66 }
67
68 /**
69 * Returns the HTML code to render the icon for H5P content types.
70 *
71 * @param string $contentname The contentname to add as alt value to the icon.
72 * @return string HTML code to render the icon
73 */
74 public function get_icon(string $contentname): string {
75 global $OUTPUT;
76 return $OUTPUT->pix_icon('f/h5p-64', $contentname, 'moodle', ['class' => 'iconsize-big']);
77 }
78
79 /**
80 * Return an array of implemented features by this plugin.
81 *
82 * @return array
83 */
84 protected function get_implemented_features(): array {
85 return [self::CAN_UPLOAD];
86 }
87
88 /**
89 * Return an array of extensions this contenttype could manage.
90 *
91 * @return array
92 */
93 public function get_manageable_extensions(): array {
94 return ['.h5p'];
95 }
96
97 /**
98 * Returns user has access capability for the content itself.
99 *
100 * @return bool True if content could be accessed. False otherwise.
101 */
102 protected function is_access_allowed(): bool {
103 return true;
104 }
105}