Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mobile app support #5

Open
wants to merge 1 commit into
base: MOODLE_310_STABLE
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 86 additions & 0 deletions classes/output/mobile.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?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/>.

/**
* HTML (on cohorts) - Mobile provider
*
* @package block_cohortspecifichtml
* @copyright 2021 Andrew Hancox <[email protected]>
* @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' => []
];
}
}
40 changes: 40 additions & 0 deletions db/mobile.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?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/>.

/**
* HTML (on cohorts) - Mobile provider
*
* @package block_cohortspecifichtml
* @copyright 2021 Andrew Hancox <[email protected]>
* @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']
]
]
];
11 changes: 11 additions & 0 deletions templates/mobile_block_view.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{{=<% %>=}}
<%#content%>
<ion-item-divider>
<h2><%{title}%></h2>
</ion-item-divider>
<ion-card>
<ion-card-content>
<core-format-text text="<% content %>" component="block_cohortspecifichtml" componentId="<% blockid %>"></core-format-text>
</ion-card-content>
</ion-card>
<%/content%>
2 changes: 1 addition & 1 deletion version.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
defined('MOODLE_INTERNAL') || die();

$plugin->component = 'block_cohortspecifichtml';
$plugin->version = 2021010900;
$plugin->version = 2021010901;
$plugin->release = 'v3.10-r1';
$plugin->requires = 2020110900;
$plugin->supported = [310, 310];
Expand Down