mirror of
https://github.com/moodle/moodle.git
synced 2025-01-17 21:49:15 +01:00
MDL-67060 core_h5p: Improvements to Manage H5P setting page
Co-authored by: Adrian Greeve <adrian@moodle.com> AMOS BEGIN CPY [description,moodle],[description,core_h5p] CPY [status,moodle],[status,core_h5p] AMOS END
This commit is contained in:
parent
d3ee08dba3
commit
4e7a035f68
@ -25,5 +25,7 @@
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
// Settings page.
|
||||
$ADMIN->add('h5p', new admin_externalpage('h5poverview', get_string('h5poverview', 'core_h5p'),
|
||||
new moodle_url('/h5p/overview.php'), ['moodle/site:config']));
|
||||
$ADMIN->add('h5p', new admin_externalpage('h5psettings', get_string('h5pmanage', 'core_h5p'),
|
||||
new moodle_url('/h5p/libraries.php'), ['moodle/site:config', 'moodle/h5p:updatelibraries']));
|
||||
|
@ -180,4 +180,81 @@ class helper {
|
||||
return $fs->create_file_from_pathname($filerecord, $filepath);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get information about different H5P tools and their status.
|
||||
*
|
||||
* @return array Data to render by the template
|
||||
*/
|
||||
public static function get_h5p_tools_info(): array {
|
||||
$tools = array();
|
||||
|
||||
// Getting information from available H5P tools one by one because their enabled/disabled options are totally different.
|
||||
// Check the atto button status.
|
||||
$link = \editor_atto\plugininfo\atto::get_manage_url();
|
||||
$status = strpos(get_config('editor_atto', 'toolbar'), 'h5p') > -1;
|
||||
$tools[] = self::convert_info_into_array('atto_h5p', $link, $status);
|
||||
|
||||
// Check the Display H5P filter status.
|
||||
$link = \core\plugininfo\filter::get_manage_url();
|
||||
$status = filter_get_active_state('displayh5p', \context_system::instance()->id);
|
||||
$tools[] = self::convert_info_into_array('filter_displayh5p', $link, $status);
|
||||
|
||||
// Check H5P scheduled task.
|
||||
$link = '';
|
||||
$status = 0;
|
||||
$statusaction = '';
|
||||
if ($task = \core\task\manager::get_scheduled_task('\core\task\h5p_get_content_types_task')) {
|
||||
$status = !$task->get_disabled();
|
||||
$link = new \moodle_url(
|
||||
'/admin/tool/task/scheduledtasks.php',
|
||||
array('action' => 'edit', 'task' => get_class($task))
|
||||
);
|
||||
if ($status && \tool_task\run_from_cli::is_runnable() && get_config('tool_task', 'enablerunnow')) {
|
||||
$statusaction = \html_writer::link(
|
||||
new \moodle_url('/admin/tool/task/schedule_task.php',
|
||||
array('task' => get_class($task))),
|
||||
get_string('runnow', 'tool_task'));
|
||||
}
|
||||
}
|
||||
$tools[] = self::convert_info_into_array('task_h5p', $link, $status, $statusaction);
|
||||
|
||||
return $tools;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert information into needed mustache template data array
|
||||
* @param string $tool The name of the tool
|
||||
* @param \moodle_url $link The URL to management page
|
||||
* @param int $status The current status of the tool
|
||||
* @param string $statusaction A link to 'Run now' option for the task
|
||||
* @return array
|
||||
*/
|
||||
static private function convert_info_into_array(string $tool,
|
||||
\moodle_url $link,
|
||||
int $status,
|
||||
string $statusaction = ''): array {
|
||||
|
||||
$statusclasses = array(
|
||||
TEXTFILTER_DISABLED => 'badge badge-danger',
|
||||
TEXTFILTER_OFF => 'badge badge-warning',
|
||||
0 => 'badge badge-danger',
|
||||
TEXTFILTER_ON => 'badge badge-success',
|
||||
);
|
||||
|
||||
$statuschoices = array(
|
||||
TEXTFILTER_DISABLED => get_string('disabled', 'admin'),
|
||||
TEXTFILTER_OFF => get_string('offbutavailable', 'core_filters'),
|
||||
0 => get_string('disabled', 'admin'),
|
||||
1 => get_string('enabled', 'admin'),
|
||||
);
|
||||
|
||||
return [
|
||||
'tool' => get_string($tool, 'h5p'),
|
||||
'tool_description' => get_string($tool . '_description', 'h5p'),
|
||||
'link' => $link,
|
||||
'status' => $statuschoices[$status],
|
||||
'status_class' => $statusclasses[$status],
|
||||
'status_action' => $statusaction,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
47
h5p/overview.php
Normal file
47
h5p/overview.php
Normal file
@ -0,0 +1,47 @@
|
||||
<?php
|
||||
// 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/>.
|
||||
|
||||
/**
|
||||
* Manage H5P tools status overview page.
|
||||
*
|
||||
* @package core_h5p
|
||||
* @copyright 2019 Amaia Anabitarte <amaia@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
require_once(__DIR__ . '/../config.php');
|
||||
|
||||
require_login(null, false);
|
||||
|
||||
$context = context_system::instance();
|
||||
require_capability('moodle/site:config', $context);
|
||||
|
||||
$pagetitle = get_string('h5poverview', 'core_h5p');
|
||||
$url = new \moodle_url("/h5p/overview.php");
|
||||
|
||||
$PAGE->set_context($context);
|
||||
$PAGE->set_url($url);
|
||||
$PAGE->set_pagelayout('admin');
|
||||
$PAGE->set_title("$SITE->shortname: " . $pagetitle);
|
||||
$PAGE->set_heading($SITE->fullname);
|
||||
|
||||
echo $OUTPUT->header();
|
||||
echo $OUTPUT->heading($pagetitle);
|
||||
|
||||
$tools = \core_h5p\helper::get_h5p_tools_info();
|
||||
echo $OUTPUT->render_from_template('core_h5p/h5ptoolsoverview', array('tools' => $tools));
|
||||
|
||||
echo $OUTPUT->footer();
|
62
h5p/templates/h5ptoolsoverview.mustache
Normal file
62
h5p/templates/h5ptoolsoverview.mustache
Normal file
@ -0,0 +1,62 @@
|
||||
{{!
|
||||
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 core_h5p/h5ptoolsoverview
|
||||
|
||||
Example context (json):
|
||||
{
|
||||
"tools": [
|
||||
{
|
||||
"tool": "h5ptasks",
|
||||
"tool_description": "h5ptasks_description",
|
||||
"link": "https://example.com/admin/tool/task/scheduledtasks.php",
|
||||
"status": "On",
|
||||
"status_class": "bade badge-success",
|
||||
"status_action": "<a href=\"admin/tool/task/schedule_task.php?task=core_task_h5p_get_content_types_task\">Run now</a>"
|
||||
},
|
||||
{
|
||||
"tool": "h5ptasks",
|
||||
"tool_description": "h5ptasks_description",
|
||||
"link": "https://example.com/admin/filters.php",
|
||||
"status": "Off",
|
||||
"status_class": "bade badge-danger"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
}}
|
||||
<table class="admintable generaltable" id="h5ptools">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>{{#str}} feature, h5p {{/str}}</th>
|
||||
<th class="text-center">{{#str}} status, h5p {{/str}}</th>
|
||||
<th>{{#str}} description, h5p {{/str}}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{{#tools}}
|
||||
<tr class="">
|
||||
<td><a href="{{{ link }}}" title="{{#str}} settings {{/str}}">{{{ tool }}}</a></td>
|
||||
<td class="text-center">
|
||||
<div class="{{{ status_class }}}">{{{ status }}}</div>
|
||||
{{#status_action}}<div>{{{ status_action }}}</div>{{/status_action}}
|
||||
</td>
|
||||
<td>{{{ tool_description }}}</td>
|
||||
</tr>
|
||||
{{/tools}}
|
||||
</tbody>
|
||||
</table>
|
@ -480,6 +480,7 @@ $string['devicedetectregex_desc'] = '<p>By default, Moodle can detect devices of
|
||||
$string['devicedetectregexexpression'] = 'Regular expression';
|
||||
$string['devicedetectregexvalue'] = 'Return value';
|
||||
$string['devicetype'] = 'Device type';
|
||||
$string['disabled'] = 'Disabled';
|
||||
$string['disableuserimages'] = 'Disable user profile images';
|
||||
$string['displayerrorswarning'] = 'Enabling the PHP setting <em>display_errors</em> is not recommended on production sites because some error messages may reveal sensitive information about your server.';
|
||||
$string['displayloginfailures'] = 'Display login failures';
|
||||
|
@ -30,6 +30,8 @@ $string['addedandupdatedss'] = 'Added {$a->%new} new H5P library and updated {$a
|
||||
$string['addednewlibraries'] = 'Added {$a->%new} new H5P libraries.';
|
||||
$string['addednewlibrary'] = 'Added {$a->%new} new H5P library.';
|
||||
$string['additionallicenseinfo'] = 'Any additional information about the license';
|
||||
$string['atto_h5p'] = 'Insert H5P button';
|
||||
$string['atto_h5p_description'] = 'The Insert H5P button in the Atto editor enables users to insert H5P content by either entering a URL or embed code, or by uploading an H5P file.';
|
||||
$string['author'] = 'Author';
|
||||
$string['authorcomments'] = 'Author comments';
|
||||
$string['authorcommentsdescription'] = 'Comments for the editor of the content. (This text will not be published as a part of the copyright info.)';
|
||||
@ -65,6 +67,7 @@ $string['couldNotParseJSONFromZip'] = 'Unable to parse JSON from the package: {$
|
||||
$string['couldNotReadFileFromZip'] = 'Unable to read file from the package: {$a->%fileName}';
|
||||
$string['creativecommons'] = 'Creative Commons';
|
||||
$string['date'] = 'Date';
|
||||
$string['description'] = 'Description';
|
||||
$string['disablefullscreen'] = 'Disable fullscreen';
|
||||
$string['download'] = 'Download';
|
||||
$string['downloadtitle'] = 'Download this content as a H5P file.';
|
||||
@ -73,8 +76,11 @@ $string['embed'] = 'Embed';
|
||||
$string['embedtitle'] = 'View the embed code for this content.';
|
||||
$string['eventh5pviewed'] = 'H5P content viewed';
|
||||
$string['eventh5pdeleted'] = 'H5P deleted';
|
||||
$string['feature'] = 'Feature';
|
||||
$string['fetchtypesfailure'] = 'No information could be obtained on the H5P content types available. H5P repository connection failure';
|
||||
$string['fileExceedsMaxSize'] = 'One of the files inside the package exceeds the maximum file size allowed. ({$a->%file} {$a->%used} > {$a->%max})';
|
||||
$string['filter_displayh5p'] = 'Display H5P filter';
|
||||
$string['filter_displayh5p_description'] = 'The Display H5P filter converts URLs into embedded H5P content.';
|
||||
$string['fullscreen'] = 'Fullscreen';
|
||||
$string['gpl'] = 'General Public License v3';
|
||||
$string['h5p'] = 'H5P';
|
||||
@ -83,6 +89,7 @@ $string['h5pfilenotfound'] = 'H5P file not found';
|
||||
$string['h5pinvalidurl'] = 'Invalid H5P content URL.';
|
||||
$string['h5pprivatefile'] = 'This H5P content can\'t be displayed because you don\'t have access to the .h5p file.';
|
||||
$string['h5pmanage'] = 'Manage H5P content types';
|
||||
$string['h5poverview'] = 'H5P overview';
|
||||
$string['h5ppackage'] = 'H5P content type';
|
||||
$string['h5ppackage_help'] = 'An H5P content type is a file with an H5P or ZIP extension containing all libraries required to display the content.';
|
||||
$string['hideadvanced'] = 'Hide advanced';
|
||||
@ -157,10 +164,13 @@ $string['reuseDescription'] = 'Reuse this content.';
|
||||
$string['showadvanced'] = 'Show advanced';
|
||||
$string['showless'] = 'Show less';
|
||||
$string['showmore'] = 'Show more';
|
||||
$string['status'] = 'Status';
|
||||
$string['size'] = 'Size';
|
||||
$string['source'] = 'Source';
|
||||
$string['startingover'] = 'You\'ll be starting over.';
|
||||
$string['sublevel'] = 'Sublevel';
|
||||
$string['task_h5p'] = 'H5P scheduled task';
|
||||
$string['task_h5p_description'] = 'The H5P scheduled task downloads available H5P content types from h5p.org.';
|
||||
$string['thumbnail'] = 'Thumbnail';
|
||||
$string['title'] = 'Title';
|
||||
$string['undisclosed'] = 'Undisclosed';
|
||||
|
@ -709,6 +709,35 @@ function filter_set_global_state($filtername, $state, $move = 0) {
|
||||
$transaction->allow_commit();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the active state for a filter in the given context.
|
||||
*
|
||||
* @param string $filtername The filter name, for example 'tex'.
|
||||
* @param integer $contextid The id of the context to get the data for.
|
||||
* @return int value of active field for the given filter.
|
||||
*/
|
||||
function filter_get_active_state(string $filtername, $contextid = null): int {
|
||||
global $DB;
|
||||
|
||||
if ($contextid === null) {
|
||||
$contextid = context_system::instance()->id;
|
||||
}
|
||||
if (is_object($contextid)) {
|
||||
$contextid = $contextid->id;
|
||||
}
|
||||
|
||||
if (strpos($filtername, 'filter/') === 0) {
|
||||
$filtername = substr($filtername, 7);
|
||||
} else if (strpos($filtername, '/') !== false) {
|
||||
throw new coding_exception("Invalid filter name '$filtername' used in filter_is_enabled()");
|
||||
}
|
||||
if ($active = $DB->get_field('filter_active', 'active', array('filter' => $filtername, 'contextid' => $contextid))) {
|
||||
return $active;
|
||||
}
|
||||
|
||||
return TEXTFILTER_DISABLED;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $filtername The filter name, for example 'tex'.
|
||||
* @return boolean is this filter allowed to be used on this site. That is, the
|
||||
|
@ -782,6 +782,61 @@ class core_filterlib_testcase extends advanced_testcase {
|
||||
$this->assertInstanceOf('performance_measuring_filter_manager', $filterman);
|
||||
}
|
||||
|
||||
public function test_filter_get_active_state_contextid_parameter() {
|
||||
$this->resetAfterTest();
|
||||
|
||||
filter_set_global_state('glossary', TEXTFILTER_ON);
|
||||
// Using system context by default.
|
||||
$active = filter_get_active_state('glossary');
|
||||
$this->assertEquals($active, TEXTFILTER_ON);
|
||||
|
||||
$systemcontext = context_system::instance();
|
||||
// Passing $systemcontext object.
|
||||
$active = filter_get_active_state('glossary', $systemcontext);
|
||||
$this->assertEquals($active, TEXTFILTER_ON);
|
||||
|
||||
// Passing $systemcontext id.
|
||||
$active = filter_get_active_state('glossary', $systemcontext->id);
|
||||
$this->assertEquals($active, TEXTFILTER_ON);
|
||||
|
||||
// Not system context.
|
||||
filter_set_local_state('glossary', '123', TEXTFILTER_ON);
|
||||
$active = filter_get_active_state('glossary', '123');
|
||||
$this->assertEquals($active, TEXTFILTER_ON);
|
||||
}
|
||||
|
||||
public function test_filter_get_active_state_filtername_parameter() {
|
||||
$this->resetAfterTest();
|
||||
|
||||
filter_set_global_state('glossary', TEXTFILTER_ON);
|
||||
// Using full filtername.
|
||||
$active = filter_get_active_state('filter/glossary');
|
||||
$this->assertEquals($active, TEXTFILTER_ON);
|
||||
|
||||
// Wrong filtername.
|
||||
$this->expectException('coding_exception');
|
||||
$active = filter_get_active_state('mod/glossary');
|
||||
}
|
||||
|
||||
public function test_filter_get_active_state_after_change() {
|
||||
$this->resetAfterTest();
|
||||
|
||||
filter_set_global_state('glossary', TEXTFILTER_ON);
|
||||
$systemcontextid = context_system::instance()->id;
|
||||
$active = filter_get_active_state('glossary', $systemcontextid);
|
||||
$this->assertEquals($active, TEXTFILTER_ON);
|
||||
|
||||
filter_set_global_state('glossary', TEXTFILTER_OFF);
|
||||
$systemcontextid = context_system::instance()->id;
|
||||
$active = filter_get_active_state('glossary', $systemcontextid);
|
||||
$this->assertEquals($active, TEXTFILTER_OFF);
|
||||
|
||||
filter_set_global_state('glossary', TEXTFILTER_DISABLED);
|
||||
$systemcontextid = context_system::instance()->id;
|
||||
$active = filter_get_active_state('glossary', $systemcontextid);
|
||||
$this->assertEquals($active, TEXTFILTER_DISABLED);
|
||||
}
|
||||
|
||||
public function test_filter_get_globally_enabled_default() {
|
||||
$this->resetAfterTest();
|
||||
$enabledfilters = filter_get_globally_enabled();
|
||||
|
@ -29,7 +29,7 @@
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$version = 2020020700.00; // YYYYMMDD = weekly release date of this DEV branch.
|
||||
$version = 2020020700.01; // YYYYMMDD = weekly release date of this DEV branch.
|
||||
// RR = release increments - 00 in DEV branches.
|
||||
// .XX = incremental changes.
|
||||
$release = '3.9dev (Build: 20200207)'; // Human-friendly version name
|
||||
|
Loading…
x
Reference in New Issue
Block a user