Skip to content

Commit d9deba2

Browse files
authored
Merge pull request #6 from lushonline/5-add-moodle-mobile-app-support
Add moodle mobile app support
2 parents 58e5c58 + 68fb54a commit d9deba2

File tree

5 files changed

+251
-1
lines changed

5 files changed

+251
-1
lines changed

classes/output/mobile.php

+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
<?php
2+
// This file is part of Moodle - http://moodle.org/
3+
//
4+
// Moodle is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// Moodle is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU General Public License
15+
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16+
17+
/**
18+
* Provides {@see \mod_externalcontent\output\mobile} class.
19+
*
20+
* @package mod_externalcontent
21+
* @copyright 2019-2022 LushOnline
22+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23+
*/
24+
25+
namespace mod_externalcontent\output;
26+
27+
defined('MOODLE_INTERNAL') || die();
28+
29+
require_once($CFG->dirroot . '/mod/externalcontent/lib.php');
30+
31+
/**
32+
* Controls the display of the plugin in the Mobile App.
33+
*
34+
* @package mod_externalcontent
35+
* @copyright 2019-2022 LushOnline
36+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
37+
*/
38+
class mobile {
39+
40+
/**
41+
* Return the data for the CoreCourseModuleDelegate delegate.
42+
*
43+
* @param object $args
44+
* @return array HTML, javascript and otherdata
45+
* @throws \required_capability_exception
46+
* @throws \coding_exception
47+
* @throws \require_login_exception
48+
* @throws \moodle_exception
49+
*/
50+
public static function mobile_course_view($args) {
51+
global $OUTPUT, $DB;
52+
53+
$args = (object) $args;
54+
$versionname = $args->appversioncode >= 3950 ? 'latest' : 'ionic3';
55+
$cm = get_coursemodule_from_id('externalcontent', $args->cmid);
56+
57+
require_login($args->courseid, false, $cm, true, true);
58+
59+
$context = \context_module::instance($cm->id);
60+
require_capability('mod/externalcontent:view', $context);
61+
62+
$externalcontent = $DB->get_record('externalcontent', array('id' => $cm->instance));
63+
$course = get_course($cm->course);
64+
65+
// Mark the externalcontent as viewed.
66+
externalcontent_view($externalcontent, $course, $cm, $context);
67+
68+
// Pre-format some strings for mobile app.
69+
$externalcontent->name = format_string($externalcontent->name);
70+
list($externalcontent->content, $externalcontent->contentformat) =
71+
external_format_text(
72+
$externalcontent->content,
73+
$externalcontent->contentformat,
74+
$context->id,
75+
'mod_externalcontent',
76+
'content'
77+
);
78+
79+
$data = [
80+
'cmid' => $cm->id,
81+
'courseid' => $course->id,
82+
'instance' => $externalcontent
83+
];
84+
85+
return [
86+
'templates' => [
87+
[
88+
'id' => 'main',
89+
'html' => $OUTPUT->render_from_template('mod_externalcontent/mobile_view_' . $versionname, $data),
90+
],
91+
],
92+
'javascript' => '',
93+
'otherdata' => '',
94+
'files' => [],
95+
];
96+
}
97+
}

db/mobile.php

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
// This file is part of Moodle - http://moodle.org/
3+
//
4+
// Moodle is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// Moodle is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU General Public License
15+
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16+
17+
/**
18+
* Declares the Mobile App addons provided by this plugin.
19+
*
20+
* @package mod_externalcontent
21+
* @copyright 2019-2022 LushOnline
22+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23+
*/
24+
25+
defined('MOODLE_INTERNAL') || die();
26+
27+
$addons = [
28+
'mod_externalcontent' => [
29+
'handlers' => [
30+
'externalcontent' => [
31+
'displaydata' => [
32+
'icon' => $CFG->wwwroot . '/mod/externalcontent/pix/icon.svg',
33+
'class' => '',
34+
],
35+
'delegate' => 'CoreCourseModuleDelegate',
36+
'method' => 'mobile_course_view',
37+
'coursepagemethod' => 'mobile_course_view',
38+
'offlinefunctions' => [
39+
'mobile_course_view' => [],
40+
],
41+
],
42+
],
43+
'lang' => [
44+
['pluginname', 'externalcontent'],
45+
],
46+
],
47+
];

templates/mobile_view_ionic3.mustache

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
{{!
2+
This file is part of Moodle - https://moodle.org/
3+
4+
Moodle is free software: you can redistribute it and/or modify
5+
it under the terms of the GNU General Public License as published by
6+
the Free Software Foundation, either version 3 of the License, or
7+
(at your option) any later version.
8+
9+
Moodle is distributed in the hope that it will be useful,
10+
but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
GNU General Public License for more details.
13+
14+
You should have received a copy of the GNU General Public License
15+
along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16+
}}
17+
{{!
18+
@template mod_externalcontent/mobile_view_ionic3
19+
20+
Render the main view for the mobile app.
21+
22+
Classes required for JS:
23+
* none
24+
25+
Data attributes required for JS:
26+
* none
27+
28+
Context variables required for this template:
29+
* cmid - [int] Course module identifier.
30+
* courseid - [int] Course identifier.
31+
* instance - [object] Externalcontent object.
32+
* instance.id - [int] Identifier.
33+
* instance.intro - [string] Formatted activity description.
34+
* instance.content - [string] Formatted content.
35+
36+
Example context (json):
37+
{
38+
"cmid": 3,
39+
"courseid": 3,
40+
"instance": {
41+
"id": 1,
42+
"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>",
43+
"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>"
44+
}
45+
}
46+
}}
47+
{{#instance}}
48+
<ion-list>
49+
<ion-item>
50+
<ion-label>{{{ content }}}</ion-label>
51+
</ion-item>
52+
</ion-list>
53+
{{/instance}}

templates/mobile_view_latest.mustache

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
{{!
2+
This file is part of Moodle - https://moodle.org/
3+
4+
Moodle is free software: you can redistribute it and/or modify
5+
it under the terms of the GNU General Public License as published by
6+
the Free Software Foundation, either version 3 of the License, or
7+
(at your option) any later version.
8+
9+
Moodle is distributed in the hope that it will be useful,
10+
but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
GNU General Public License for more details.
13+
14+
You should have received a copy of the GNU General Public License
15+
along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16+
}}
17+
{{!
18+
@template mod_externalcontent/mobile_view_latest
19+
20+
Render the main view for the mobile app.
21+
22+
Classes required for JS:
23+
* none
24+
25+
Data attributes required for JS:
26+
* none
27+
28+
Context variables required for this template:
29+
* cmid - [int] Course module identifier.
30+
* courseid - [int] Course identifier.
31+
* instance - [object] Externalcontent object.
32+
* instance.id - [int] Identifier.
33+
* instance.intro - [string] Formatted activity description.
34+
* instance.content - [string] Formatted content.
35+
36+
Example context (json):
37+
{
38+
"cmid": 3,
39+
"courseid": 3,
40+
"instance": {
41+
"id": 1,
42+
"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>",
43+
"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>"
44+
}
45+
}
46+
}}
47+
{{#instance}}
48+
<ion-card>
49+
<ion-card-content>
50+
<ion-label>{{{ content }}}</ion-label>
51+
</ion-card-content>
52+
</ion-card>
53+
{{/instance}}

version.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

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

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

0 commit comments

Comments
 (0)