From b1b60fdf6a3fe4f7169d876ca4ca8ae75c890982 Mon Sep 17 00:00:00 2001 From: Andrew Hancox Date: Fri, 9 Jul 2021 15:19:31 +0100 Subject: [PATCH] Mobile app support --- classes/output/mobile.php | 86 ++++++++++++++++++++++++++++ db/mobile.php | 40 +++++++++++++ templates/mobile_block_view.mustache | 11 ++++ version.php | 2 +- 4 files changed, 138 insertions(+), 1 deletion(-) create mode 100644 classes/output/mobile.php create mode 100644 db/mobile.php create mode 100644 templates/mobile_block_view.mustache diff --git a/classes/output/mobile.php b/classes/output/mobile.php new file mode 100644 index 0000000..bb36a44 --- /dev/null +++ b/classes/output/mobile.php @@ -0,0 +1,86 @@ +. + +/** + * HTML (on cohorts) - Mobile provider + * + * @package block_cohortspecifichtml + * @copyright 2021 Andrew Hancox + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace block_cohortspecifichtml\output; + +defined('MOODLE_INTERNAL') || die(); + +/** + * Mobile output functions. + */ +class mobile { + + /** + * Returns the SC document view page for the mobile app. + * + * @param array $args Arguments from tool_mobile_get_content WS + * @return array HTML, javascript and otherdata + */ + public static function mobile_block_view(array $args) : array { + global $CFG, $DB, $PAGE, $OUTPUT; + + require_once("$CFG->dirroot/lib/blocklib.php"); + require_once("$CFG->dirroot/lib/filelib.php"); + $block = block_instance('cohortspecifichtml', + $DB->get_record('block_instances', ['id' => $args['blockid']]), + $PAGE + ); + + $data = new \stdClass(); + if (block_cohortspecifichtml_show_block($block) && $block->config->text) { + $blockcontext = \context_block::instance($args['blockid']); + $contenttext = file_rewrite_pluginfile_urls($block->config->text, 'pluginfile.php', $blockcontext->id, + 'block_cohortspecifichtml', 'content', null); + // Default to FORMAT_HTML which is what will have been used before the editor was properly + // implemented for the block. + $format = FORMAT_HTML; + // Check to see if the format has been properly set on the config. + if (isset($block->config->format)) { + $format = $block->config->format; + } + + $filteropt = new \stdClass; + $filteropt->overflowdiv = true; + if ($block->content_is_trusted()) { + // Fancy html allowed only on course, category and system blocks. + $filteropt->noclean = true; + } + + $data->content = format_text($contenttext, $format, $filteropt); + } + $data->blockid = $block->$args['blockid']; + $data->title = $block->title; + return [ + 'templates' => [ + [ + 'id' => 'main', + 'html' => $OUTPUT->render_from_template('block_cohortspecifichtml/mobile_block_view', $data), + ], + ], + 'javascript' => '', + 'otherdata' => [], + 'files' => [] + ]; + } +} diff --git a/db/mobile.php b/db/mobile.php new file mode 100644 index 0000000..48424b4 --- /dev/null +++ b/db/mobile.php @@ -0,0 +1,40 @@ +. + +/** + * HTML (on cohorts) - Mobile provider + * + * @package block_cohortspecifichtml + * @copyright 2021 Andrew Hancox + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die(); + +$addons = [ + 'block_cohortspecifichtml' => [ + 'handlers' => [ + 'blockcohortspecifichtmlview' => [ + 'delegate' => 'CoreBlockDelegate', + 'method' => 'mobile_block_view', + 'displaydata' => [] + ], + ], + 'lang' => [ + ['pluginname', 'block_cohortspecifichtml'] + ] + ] +]; diff --git a/templates/mobile_block_view.mustache b/templates/mobile_block_view.mustache new file mode 100644 index 0000000..707d2f1 --- /dev/null +++ b/templates/mobile_block_view.mustache @@ -0,0 +1,11 @@ +{{=<% %>=}} +<%#content%> + +

<%{title}%>

+
+ + + + + +<%/content%> diff --git a/version.php b/version.php index 25c1fb6..82a647a 100644 --- a/version.php +++ b/version.php @@ -25,7 +25,7 @@ defined('MOODLE_INTERNAL') || die(); $plugin->component = 'block_cohortspecifichtml'; -$plugin->version = 2021010600; +$plugin->version = 2021010602; $plugin->release = 'v3.9-r2'; $plugin->requires = 2020061500; $plugin->supported = [39, 39];