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

Add moodle mobile app support #6

Merged
merged 3 commits into from
Aug 10, 2022
Merged
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
97 changes: 97 additions & 0 deletions classes/output/mobile.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<?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/>.

/**
* Provides {@see \mod_externalcontent\output\mobile} class.
*
* @package mod_externalcontent
* @copyright 2019-2022 LushOnline
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

namespace mod_externalcontent\output;

defined('MOODLE_INTERNAL') || die();

require_once($CFG->dirroot . '/mod/externalcontent/lib.php');

/**
* Controls the display of the plugin in the Mobile App.
*
* @package mod_externalcontent
* @copyright 2019-2022 LushOnline
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class mobile {

/**
* Return the data for the CoreCourseModuleDelegate delegate.
*
* @param object $args
* @return array HTML, javascript and otherdata
* @throws \required_capability_exception
* @throws \coding_exception
* @throws \require_login_exception
* @throws \moodle_exception
*/
public static function mobile_course_view($args) {
global $OUTPUT, $DB;

$args = (object) $args;
$versionname = $args->appversioncode >= 3950 ? 'latest' : 'ionic3';
$cm = get_coursemodule_from_id('externalcontent', $args->cmid);

require_login($args->courseid, false, $cm, true, true);

$context = \context_module::instance($cm->id);
require_capability('mod/externalcontent:view', $context);

$externalcontent = $DB->get_record('externalcontent', array('id' => $cm->instance));
$course = get_course($cm->course);

// Mark the externalcontent as viewed.
externalcontent_view($externalcontent, $course, $cm, $context);

// Pre-format some strings for mobile app.
$externalcontent->name = format_string($externalcontent->name);
list($externalcontent->content, $externalcontent->contentformat) =
external_format_text(
$externalcontent->content,
$externalcontent->contentformat,
$context->id,
'mod_externalcontent',
'content'
);

$data = [
'cmid' => $cm->id,
'courseid' => $course->id,
'instance' => $externalcontent
];

return [
'templates' => [
[
'id' => 'main',
'html' => $OUTPUT->render_from_template('mod_externalcontent/mobile_view_' . $versionname, $data),
],
],
'javascript' => '',
'otherdata' => '',
'files' => [],
];
}
}
47 changes: 47 additions & 0 deletions db/mobile.php
Original file line number Diff line number Diff line change
@@ -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/>.

/**
* Declares the Mobile App addons provided by this plugin.
*
* @package mod_externalcontent
* @copyright 2019-2022 LushOnline
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

defined('MOODLE_INTERNAL') || die();

$addons = [
'mod_externalcontent' => [
'handlers' => [
'externalcontent' => [
'displaydata' => [
'icon' => $CFG->wwwroot . '/mod/externalcontent/pix/icon.svg',
'class' => '',
],
'delegate' => 'CoreCourseModuleDelegate',
'method' => 'mobile_course_view',
'coursepagemethod' => 'mobile_course_view',
'offlinefunctions' => [
'mobile_course_view' => [],
],
],
],
'lang' => [
['pluginname', 'externalcontent'],
],
],
];
53 changes: 53 additions & 0 deletions templates/mobile_view_ionic3.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{{!
This file is part of Moodle - https://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 mod_externalcontent/mobile_view_ionic3

Render the main view for the mobile app.

Classes required for JS:
* none

Data attributes required for JS:
* none

Context variables required for this template:
* cmid - [int] Course module identifier.
* courseid - [int] Course identifier.
* instance - [object] Externalcontent object.
* instance.id - [int] Identifier.
* instance.intro - [string] Formatted activity description.
* instance.content - [string] Formatted content.

Example context (json):
{
"cmid": 3,
"courseid": 3,
"instance": {
"id": 1,
"intro": "Language: en-US<br>Type: Book<br>Author: Suchi Paharia, Sudhanshu Hate<br>Publisher: CRC Press<br>Copyright: 2012<br>ISBN: 9781439862933<br><br>Detailing a step-by-step approach for real-life implementation, this book supplies in-depth coverage of the various server-side features of Microsoft .NET Framework 4 that can be leveraged in Enterprise Application development.<br>",
"content": "<a href=\"https:\/\/share.percipio.com\/cd\/cvm9KtF3M8jM\" target=\"_blank\"><img src=\"https:\/\/cdn2.percipio.com\/public\/c\/books\/46427\/cover-images\/262cd6b1-84b9-4e4b-a294-99b4730f960a\/modality\/262cd6b1-84b9-4e4b-a294-99b4730f960a.jpg\" alt=\".NET 4 for Enterprise Architects and Developers\" style=\"max-width: 400px\" class=\"img-responsive\"><\/a><br><br>Language: en-US<br>Type: Book<br>Author: Suchi Paharia, Sudhanshu Hate<br>Publisher: CRC Press<br>Copyright: 2012<br>ISBN: 9781439862933<br><br>Detailing a step-by-step approach for real-life implementation, this book supplies in-depth coverage of the various server-side features of Microsoft .NET Framework 4 that can be leveraged in Enterprise Application development.<br><br><br><a href=\"https:\/\/share.percipio.com\/cd\/cvm9KtF3M8jM\" target=\"_blank\" class=\"btn btn-primary\">Launch<\/a>"
}
}
}}
{{#instance}}
<ion-list>
<ion-item>
<ion-label>{{{ content }}}</ion-label>
</ion-item>
</ion-list>
{{/instance}}
53 changes: 53 additions & 0 deletions templates/mobile_view_latest.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{{!
This file is part of Moodle - https://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 mod_externalcontent/mobile_view_latest

Render the main view for the mobile app.

Classes required for JS:
* none

Data attributes required for JS:
* none

Context variables required for this template:
* cmid - [int] Course module identifier.
* courseid - [int] Course identifier.
* instance - [object] Externalcontent object.
* instance.id - [int] Identifier.
* instance.intro - [string] Formatted activity description.
* instance.content - [string] Formatted content.

Example context (json):
{
"cmid": 3,
"courseid": 3,
"instance": {
"id": 1,
"intro": "Language: en-US<br>Type: Book<br>Author: Suchi Paharia, Sudhanshu Hate<br>Publisher: CRC Press<br>Copyright: 2012<br>ISBN: 9781439862933<br><br>Detailing a step-by-step approach for real-life implementation, this book supplies in-depth coverage of the various server-side features of Microsoft .NET Framework 4 that can be leveraged in Enterprise Application development.<br>",
"content": "<a href=\"https:\/\/share.percipio.com\/cd\/cvm9KtF3M8jM\" target=\"_blank\"><img src=\"https:\/\/cdn2.percipio.com\/public\/c\/books\/46427\/cover-images\/262cd6b1-84b9-4e4b-a294-99b4730f960a\/modality\/262cd6b1-84b9-4e4b-a294-99b4730f960a.jpg\" alt=\".NET 4 for Enterprise Architects and Developers\" style=\"max-width: 400px\" class=\"img-responsive\"><\/a><br><br>Language: en-US<br>Type: Book<br>Author: Suchi Paharia, Sudhanshu Hate<br>Publisher: CRC Press<br>Copyright: 2012<br>ISBN: 9781439862933<br><br>Detailing a step-by-step approach for real-life implementation, this book supplies in-depth coverage of the various server-side features of Microsoft .NET Framework 4 that can be leveraged in Enterprise Application development.<br><br><br><a href=\"https:\/\/share.percipio.com\/cd\/cvm9KtF3M8jM\" target=\"_blank\" class=\"btn btn-primary\">Launch<\/a>"
}
}
}}
{{#instance}}
<ion-card>
<ion-card-content>
<ion-label>{{{ content }}}</ion-label>
</ion-card-content>
</ion-card>
{{/instance}}
2 changes: 1 addition & 1 deletion version.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

defined('MOODLE_INTERNAL') || die();

$plugin->version = 2022072800;
$plugin->version = 2022081000;
$plugin->requires = 2021051700; // Requires this Moodle version v3.11 see https://docs.moodle.org/dev/Releases.
$plugin->component = 'mod_externalcontent';
$plugin->maturity = MATURITY_STABLE;
Expand Down