-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from lushonline/5-add-moodle-mobile-app-support
Add moodle mobile app support
- Loading branch information
Showing
5 changed files
with
251 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' => [], | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'], | ||
], | ||
], | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters