Skip to content

Commit

Permalink
First step to enable moodle mobile Wunderbyte-GmbH#134
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelpollak committed Jul 7, 2020
1 parent 4e42dd0 commit b42dcba
Show file tree
Hide file tree
Showing 4 changed files with 174 additions and 0 deletions.
91 changes: 91 additions & 0 deletions classes/output/mobile.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<?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/>.

namespace mod_datalynx\output;

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

use context_module;

/**
* Mobile output class for datalynx based on mod_certificate.
*
* @package mod_datalynx
* @copyright 2020 Michael Pollak
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class mobile {

/**
* Returns the certificate course view for the mobile app.
* @param array $args Arguments from tool_mobile_get_content WS
*
* @return array HTML, javascript and otherdata
*/
public static function mobile_course_view($args) {
global $OUTPUT, $USER, $DB;

$args = (object) $args;
$cm = get_coursemodule_from_id('datalynx', $args->cmid);

// Capabilities check.
require_login($args->courseid , false , $cm, true, true);
$context = context_module::instance($cm->id);
require_capability ('mod/datalynx:viewentry', $context);
if ($args->userid != $USER->id) {
require_capability('mod/datalynx:manageentries', $context);
}

$datalynx = $DB->get_record('datalynx', array('id' => $cm->instance));

$entries = self::get_entries(7);

$data['intro'] = $datalynx->intro;
$data['cmid'] = $cm->id;
$data['entries'] = $entries;
$data['courseid'] = $args->courseid;

return [
'templates' => [
[
'id' => 'main',
'html' => $OUTPUT->render_from_template('mod_datalynx/mobile_view_page', $data),
],
],
'javascript' => '',
'otherdata' => '',
];
}

public static function get_entries($id) {
global $DB;

$sql = "SELECT {datalynx_contents}.id, entryid, fieldid, content FROM {datalynx_entries}
JOIN {datalynx_contents} ON {datalynx_entries}.id = entryid WHERE dataid = $id";
$tempentries = $DB->get_records_sql($sql);

// Create a format that mustache can handle.
foreach ($tempentries as $entry) {
$entryid = $entry->entryid;
$entries[$entryid]['id'] = $entryid;
$entries[$entryid]['contents'][]['content'] = $entry->content;
$entries[$entryid]['contents'][]['fieldid'] = $entry->content;
}

// Set keys to start at 0, does not work otherwhise.
return array_values($entries);
}
}
39 changes: 39 additions & 0 deletions db/mobile.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php
// This file is part of mod_datalynx for Moodle - http://moodle.org/
//
// It 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.
//
// It 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/>.

/**
* Defines message providers (types of messages being sent)
*
* @package mod_datalynx
* @copyright 2020 Michael Pollak <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') or die();

$addons = [
'mod_datalynx' => [ // Plugin identifier
'handlers' => [ // Different places where the plugin will display content.
'datalynx' => [ // Handler unique name (alphanumeric).
'displaydata' => [
'icon' => $CFG->wwwroot . '/mod/datalynx/pix/icon.png',
'class' => '',
],
'delegate' => 'CoreCourseModuleDelegate', // Delegate (where to display the link to the plugin)
'method' => 'mobile_course_view', // Main function in \mod_certificate\output\mobile
],
],
],
];
25 changes: 25 additions & 0 deletions db/services.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?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/>.

/**
* Database external functions and service definitions.
*
* @package mod_datalynx
* @copyright 2020 Michael Pollak <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

$functions = array();
19 changes: 19 additions & 0 deletions templates/mobile_view_page.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{{=<% %>=}}
<div>
<core-course-module-description description="<% intro %>" component="mod_datalynx" componentId="<% cmid %>"></core-course-module-description>

<ion-list>

<%#entries%>
<ion-item>
<h2>Entry <% id %></h2>
<p>
<%#contents%>
<% content %>;
<%/contents%>
</p>
</ion-item>
<%/entries%>

</ion-list>
</div>

0 comments on commit b42dcba

Please sign in to comment.