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 #6

Open
wants to merge 3 commits into
base: main
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
105 changes: 105 additions & 0 deletions .github/workflows/moodle-plugin-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
name: Moodle Plugin CI

on: [push, pull_request]

jobs:
test:
runs-on: ubuntu-18.04

services:
postgres:
image: postgres:9.6
env:
POSTGRES_USER: 'postgres'
POSTGRES_HOST_AUTH_METHOD: 'trust'
ports:
- 5432:5432
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 3
mariadb:
image: mariadb:10
env:
MYSQL_USER: 'root'
MYSQL_ALLOW_EMPTY_PASSWORD: "true"
ports:
- 3306:3306
options: --health-cmd="mysqladmin ping" --health-interval 10s --health-timeout 5s --health-retries 3

strategy:
fail-fast: false
matrix:
php: ['7.2', '7.3', '7.4']
moodle-branch: ['MOODLE_39_STABLE']
database: [pgsql, mariadb]

steps:
- name: Check out repository code
uses: actions/checkout@v2
with:
path: plugin

- name: Setup PHP ${{ matrix.php }}
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
coverage: none

- name: Initialise moodle-plugin-ci
run: |
composer create-project -n --no-dev --prefer-dist moodlehq/moodle-plugin-ci ci ^3
echo $(cd ci/bin; pwd) >> $GITHUB_PATH
echo $(cd ci/vendor/bin; pwd) >> $GITHUB_PATH
sudo locale-gen en_AU.UTF-8
echo "NVM_DIR=$HOME/.nvm" >> $GITHUB_ENV

- name: Install moodle-plugin-ci
run: |
moodle-plugin-ci install --plugin ./plugin --db-host=127.0.0.1
env:
DB: ${{ matrix.database }}
MOODLE_BRANCH: ${{ matrix.moodle-branch }}

- name: PHP Lint
if: ${{ always() }}
run: moodle-plugin-ci phplint

- name: PHP Copy/Paste Detector
continue-on-error: true # This step will show errors but will not fail
if: ${{ always() }}
run: moodle-plugin-ci phpcpd

- name: PHP Mess Detector
continue-on-error: true # This step will show errors but will not fail
if: ${{ always() }}
run: moodle-plugin-ci phpmd

- name: Moodle Code Checker
if: ${{ always() }}
run: moodle-plugin-ci codechecker --max-warnings 0

- name: Moodle PHPDoc Checker
if: ${{ always() }}
run: moodle-plugin-ci phpdoc

- name: Validating
if: ${{ always() }}
run: moodle-plugin-ci validate

- name: Check upgrade savepoints
if: ${{ always() }}
run: moodle-plugin-ci savepoints

- name: Mustache Lint
if: ${{ always() }}
run: moodle-plugin-ci mustache

- name: Grunt
if: ${{ always() }}
run: moodle-plugin-ci grunt --max-lint-warnings 0

- name: PHPUnit tests
if: ${{ always() }}
run: moodle-plugin-ci phpunit

- name: Behat features
if: ${{ always() }}
run: moodle-plugin-ci behat --profile chrome
48 changes: 0 additions & 48 deletions .travis.yml

This file was deleted.

4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ Changes

### Unreleased

* 2021-02-05 - Move Moodle Plugin CI from Travis CI to Github actions

### Release v3.9-r2

* 2021-01-06 - Change in Moodle release support:
For the time being, this plugin is maintained for the most recent LTS release of Moodle as well as the most recent major release of Moodle.
Bugfixes are backported to the LTS release. However, new features and improvements are not necessarily backported to the LTS release.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
moodle-block_cohortspecifichtml
===============================

[![Build Status](https://travis-ci.com/moodleuulm/moodle-block_cohortspecifichtml.svg?branch=master)](https://travis-ci.com/moodleuulm/moodle-block_cohortspecifichtml)
[![Moodle Plugin CI](https://github.com/moodleuulm/moodle-block_cohortspecifichtml/workflows/Moodle%20Plugin%20CI/badge.svg?branch=MOODLE_39_STABLE)](https://github.com/moodleuulm/moodle-block_cohortspecifichtml/actions?query=workflow%3A%22Moodle+Plugin+CI%22+branch%3AMOODLE_39_STABLE)

This HTML block provides the possibility to selectively display the block to members of specific cohorts.

Expand Down
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%>
4 changes: 2 additions & 2 deletions version.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
defined('MOODLE_INTERNAL') || die();

$plugin->component = 'block_cohortspecifichtml';
$plugin->version = 2020071600;
$plugin->release = 'v3.9-r1';
$plugin->version = 2021010602;
$plugin->release = 'v3.9-r2';
$plugin->requires = 2020061500;
$plugin->supported = [39, 39];
$plugin->maturity = MATURITY_STABLE;
Expand Down