How to make blocks visible in Moodle Mobile App?

How to make blocks visible in Moodle Mobile App?

by stefan weber -
Number of replies: 12
Picture of Plugin developers

I created a custom course overview block for our site, but it is not displayed in the Moodle Mobile App on the Dashboard.

I'm aware of this guide: https://docs.moodle.org/dev/Mobile_support_for_plugins, but I feel that there has to be a much simpler solution to get blocks to display, since ALL of the core blocks seem to display just fine, and none of them has a mobile.php file.

Any ideas how to get my block to show?

Average of ratings: -
In reply to stefan weber

Re: How to make blocks visible in Moodle Mobile App?

by Juan Leyva -
Picture of Core developers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
Hi Stefan,

we'll be creating soon some sample code and plugins repository in github so you can use it as an example for your block.

Meanwhile, could you check the example here?
In reply to Juan Leyva

Re: How to make blocks visible in Moodle Mobile App?

by Esther Saratha -

Hi Juan,

Any sample code has been created in git for blocks in mobile app?

The news block is again for the course view page and not for the dashboard.

It would be helpful if there are sample code for blocks in dashboard to be displayed in mobile.

In reply to Esther Saratha

Re: How to make blocks visible in Moodle Mobile App?

by Dani Palou -
Picture of Core developers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Hi Esther,

the Moodle code to display the block in the app is the same for course blocks and for dashboard blocks, so the news block example should work for dashboard blocks too.

Please notice that your Moodle site should be 3.6 or higher in order for this to work, otherwise the app has no way of knowing which blocks are in the dashboard. For course blocks, Moodle 3.3 or higher is required.

Cheers,
Dani
Average of ratings: Useful (1)
In reply to Dani Palou

Re: How to make blocks visible in Moodle Mobile App?

by Esther Saratha -
Hi Dani,

I'm getting an error saying "error connecting to server" and when I debugged it I found the following error "Can't find data record in database table external_functions". I have added the record in the table manually but still its showing the same error.

And do we have to insert the record every time manually? Or i'm missing out something here?
In reply to Esther Saratha

Re: How to make blocks visible in Moodle Mobile App?

by Dani Palou -
Picture of Core developers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Hi Esther,

that error is displayed when the app tries to call a WebService that doesn't exist or wasn't configured properly. Have you created a new WebService that your block uses? When is that error displayed exactly?

Cheers,
Dani
In reply to Dani Palou

Re: How to make blocks visible in Moodle Mobile App?

by Esther Saratha -
Hi Dani,

This is for the dashboard block. While loading the dashboard page its showing the error.

Following is the service.php file

$functions = array (
'block_mystatistics_get_mystatistics_data' => array (
'classname' => 'block_mystatistics_external',
'methodname' => 'get_mystatistics_data',
'classpath' => 'blocks/mystatistics/classes/external.php',
'description' => '',
'requiredcapability' => '',
'type' => 'read',
'services' => array(MOODLE_OFFICIAL_MOBILE_SERVICE)
)
);

external.php

defined('MOODLE_INTERNAL') || die;
require_once($CFG->libdir . '/externallib.php');
require_once($CFG->dirroot . '/blocks/mystatistics/utils.php');

class block_mystatistics_external extends external_api {


public static function get_mystatistics_data_parameters() {
return new external_function_parameters();
}

public static function get_mystatistics_data() {
global $USER;
$utilObj = new utils($USER->id);

$templateContext = $utilObj->fetch_required_data();
return $templateContext;
}

public static function get_mystatistics_data_returns() {
return new external_single_structure(array(
'flag' => new external_value(PARAM_INT,'Flag',VALUE_OPTIONAL),
'courseCount' => new external_value(PARAM_INT,'Course Count',VALUE_OPTIONAL),
'courseCompletion' => new external_value(PARAM_INT,'Course Completion',VALUE_OPTIONAL),
'courseRemaining' => new external_value(PARAM_INT,'Course Remaining',VALUE_OPTIONAL),
'courseCompletionPercentage' => new external_value(PARAM_FLOAT,'Course Completion Percentage',VALUE_OPTIONAL),
'mandatorydonut' => new external_value(PARAM_INT,'Mandatory Donut',VALUE_OPTIONAL),
'completedratio' => new external_value(PARAM_INT,'Completed Ratio',VALUE_OPTIONAL),
'activityCount' => new external_value(PARAM_INT,'Activity Count',VALUE_OPTIONAL),
'mandatoryactivityCount' => new external_value(PARAM_INT,'Mandatory Activity Count',VALUE_OPTIONAL),
'activityCompletion' => new external_value(PARAM_INT,'Activity Completion',VALUE_OPTIONAL),
'mandatoryactivityCompletion' => new external_value(PARAM_INT,'Mandatory Activity Completion',VALUE_OPTIONAL),
'activityProgress' => new external_value(PARAM_INT,'Activity Progress',VALUE_OPTIONAL),
'mandatoryactivityProgress' => new external_value(PARAM_INT,'Mandatory Activity Progress',VALUE_OPTIONAL),
'activityRemaining' => new external_value(PARAM_INT,'Activity Remaining',VALUE_OPTIONAL),
'mandatoryactivityRemaining' => new external_value(PARAM_INT,'Mandatory Activity Remaining',VALUE_OPTIONAL),
'progresslikelp' => new external_value(PARAM_TEXT,'Progress like LP',VALUE_OPTIONAL),
'activityCompletionPercentage' => new external_value(PARAM_FLOAT,'Activity Completion Percentage',VALUE_OPTIONAL),
'mandatoryactivitiesCompletionPercentage' => new external_value(PARAM_FLOAT,'Mandatory Activity Completion Percentage',VALUE_OPTIONAL),
'timespentid' => new external_value(PARAM_TEXT,'Time Spent ID',VALUE_OPTIONAL),
'timespent' => new external_value(PARAM_TEXT,'Time Spent',VALUE_OPTIONAL),
'Overallcompletionprogress' => new external_value(PARAM_INT,'Overall Completion Progress',VALUE_OPTIONAL),
'Remainingoverallcompletionprogress' => new external_value(PARAM_INT,'Remaining Overall Completion Progress',VALUE_OPTIONAL),
'recommended_completion' => new external_value(PARAM_TEXT,'Recommended Completion Progress',VALUE_OPTIONAL),
'recommended_completion' => new external_value(PARAM_TEXT,'Recommended Completion Progress',VALUE_OPTIONAL),
'overall_completion_data' => new external_value(PARAM_TEXT,'Overall Completion Progress',VALUE_OPTIONAL),
'xp' => new external_value(PARAM_INT,'XP Points',VALUE_OPTIONAL),
'milestone' => new external_value(PARAM_TEXT,'Milestone',VALUE_OPTIONAL),
'count' => new external_value(PARAM_INT,'Count',VALUE_OPTIONAL)
));
}
}

Cheers,
Esther
In reply to Esther Saratha

Re: How to make blocks visible in Moodle Mobile App?

by Dani Palou -
Picture of Core developers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Hi,

have you increased the version number of your block after creating the WebService? It is required to make Moodle "install" the WebService.

If you're using mdk you can use the following instruction to re-apply all WebServices without having to update the version number:

mdk run external_functions.php

Cheers,
Dani
Average of ratings: Useful (1)
In reply to Dani Palou

Re: How to make blocks visible in Moodle Mobile App?

by Esther Saratha -
Hi Dani,

Its working now, thanks for the response.

I have another issue for the dashboard block the header is not getting displayed.

Cheers,
Esther
In reply to Esther Saratha

Re: How to make blocks visible in Moodle Mobile App?

by Dani Palou -
Picture of Core developers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Hi Esther,

you should display the block header yourself, it should be inside your Mustache template. This is how the app usually renders blocks headers:

<ion-item-divider>
    <h2>{{ 'addon.block_activitymodules.pluginname' | translate }}</h2>
</ion-item-divider>

Cheers,
Dani
In reply to Dani Palou

Re: How to make blocks visible in Moodle Mobile App?

by Esther Saratha -
Hi Dani,

Thank you so much for the help.

Everything is working fine.

Follwing is the code from mobile.php of news block.

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

$addons = [
'block_news' => [ // Plugin identifier.
'handlers' => [ // Different places where the plugin will display content.
'newspage' => [
'delegate' => 'CoreCourseOptionsDelegate',
'method' => 'news_page',
'displaydata' => [
'title' => 'newsheading',
'class' => 'block_news'
],
'styles' => [
'url' => $CFG->wwwroot . '/blocks/news/mobile.css?v=2019062500',
'version' => 2019062500
],
'priority' => 60,
'init' => 'news_init'
],
'eventspage' => [
'delegate' => 'CoreCourseOptionsDelegate',
'method' => 'events_page',
'displaydata' => [
'title' => 'events',
'class' => 'block_news'
],
'priority' => 50,
'init' => 'events_init'
]
],
'lang' => [
['newsheading', 'block_news'],
['events', 'block_news'],
['eventsheading', 'block_news'],
['pasteventsheading', 'block_news'],
['nonewsyet', 'block_news'],
['noeventsyet', 'block_news'],
['nopastevents', 'block_news'],
['rendermsgextlink', 'block_news'],
['msgedithlpattach', 'block_news']
]
]
];

there are two handlers in the code mentioned. I would like to know which method will be invoked first or is it based on the priority attribute.

Cheers,
Esther
In reply to Esther Saratha

Re: How to make blocks visible in Moodle Mobile App?

by Dani Palou -
Picture of Core developers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Hi,

I'm glad the block is working fine! This discussion was opened to talk about displaying blocks in the app, and your new question is about course options, so if you have more questions about course options you should open a new discussion.

All course options are displayed at the same time when opening a course, and they're ordered by priority. The method isn't called until the user clicks to view the course option.

Cheers,
Dani
In reply to Dani Palou

Re: How to make blocks visible in Moodle Mobile App?

by Esther Saratha -
Hi Dani,

Thanks for the response.

For the dashboard plugin there will only one handler is it?

Cheers,
Esther