Why the Mobile plugin support code for Edwiser course format not reflecting as output in Moodle app?

46 Views Asked by At

By following the Creating mobile course format plugin development guide, I am developing a mobile plugin support of the Edwiser course format for the Moodle App. But after creating db/mobile.php, classes/output/mobile.php, templates/mobile_course.mustache as instructed in the guide, I am still getting the default course format in the mobile ie. the courseformat when the course format plugin isn't supported. But when I change the course format in the server to something like flexsections it works in my mobile app.

These are my files: moodle/course/format/remuiformat/db/mobile.php:

<?php

$addons = [
    'format_remuiformat' => [
        'handlers' => [ // Different places where the plugin will display content.
            'remuiformat' => [ // Handler unique name (alphanumeric).
                'delegate' => 'CoreCourseFormatDelegate', // Delegate (where to display the link to the plugin)
                'method' => 'mobile_course_view', // Main function in \format_remuiformat\output\mobile.
                'styles' => [
                    'url' => $CFG->wwwroot . '/course/format/remuiformat/mobile.css',
                    'version' => 2019041000
                ],
                'displaysectionselector' => true, // Set to false to disable the default section selector.
                'displayenabledownload' => true, // Set to false to hide the "Enable download" option in the course context menu.
                'init' => 'remuiformat_init'
            ]
    ]
    ]
];

moodle/course/format/remuiformat/classes/output/mobile.php:

<?php

class mobile {

    /**
     * Main course page.
     *
     * @param array $args Standard mobile web service arguments
     * @return array
     */
    public static function mobile_course_view($args) {
        global $OUTPUT, $CFG;

        $course = get_course($args['courseid']);
        require_login($course);
        $html = $OUTPUT->render_from_template('format_remuiformat/mobile_course', []);

        return [
            'templates' => [
                [
                    'id' => 'main',
                    'html' => $html
                ]
            ],
            'otherdata' => '',
        ];
    }
}

moodle/course/format/remuiformat/templates/mobile_course.mustache:

{{=<% %>=}}
<core-dynamic-component [component]="allSectionsComponent" [data]="data" class="format-myformat">
    <ng-container *ngFor="let section of sections">
        <h1>Test</h1>
        <ion-item-divider color="light">
            <core-format-text [text]="section.name"></core-format-text>
             <!-- Section download. -->
             <div *ngIf="section && downloadEnabled" class="core-button-spinner" float-end>
                <!-- Download button. -->
                <button *ngIf="section.showDownload && !section.isDownloading && !section.isCalculating" (click)="prefetch($event, section)" ion-button icon-only clear color="dark" [attr.aria-label]="'core.download' | translate">
                    <ion-icon name="cloud-download"></ion-icon>
                </button>
                <!-- Refresh button. -->
                <button *ngIf="section.showRefresh && !section.isDownloading && !section.isCalculating" (click)="prefetch($event, section)" ion-button icon-only clear color="dark" [attr.aria-label]="'core.refresh' | translate">
                    <ion-icon name="refresh"></ion-icon>
                </button>
                <!-- Download progress. -->
                <ion-badge class="core-course-download-section-progress" *ngIf="section.isDownloading && section.total > 0 && section.count < section.total">{{section.count}} / {{section.total}}</ion-badge>
                <!-- Spinner (downloading or calculating status). -->
                <ion-spinner *ngIf="(section.isDownloading && section.total > 0) || section.isCalculating"></ion-spinner>
            </div>
        </ion-item-divider>

        <ion-item text-wrap *ngIf="section.summary">
            <core-format-text [text]="section.summary"></core-format-text>
        </ion-item>

        <ng-container *ngFor="let module of section.modules">
            <ng-container *ngIf="module.visibleoncoursepage !== 0">
                <core-course-module text-wrap [module]="module" [courseId]="course.id" [downloadEnabled]="downloadEnabled" (completionChanged)="onCompletionChange($event)">
                </core-course-module>
            </ng-container>
        </ng-container>
    </ng-container>
</core-dynamic-component>

I have cleared my mobile app data by App Setting -> Space usage -> Delete all site download data and I have purged all the caches in my server still no luck.

Could someone please point out where I am wrong or what should I do? I am glad to provide more information required regarding this problem.

Thanks!

1

There are 1 best solutions below

0
DesignThala On BEST ANSWER

To moodle/course/format/remuiformat/classes/output/mobile.php I added:

namespace format_remuiformat\output;
defined('MOODLE_INTERNAL') || die();

By following Development Workflow of Moodle App Plugins Development Guide. I cleared the mobile app data, logged out and again logged in to my Moodle app, it worked!