Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
<?php
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
 * Provides {@see \mod_subcourse\output\mobile} class.
19
 *
20
 * @copyright   2020 David Mudrák <david@moodle.com>
21
 * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
22
 */
23
 
24
namespace mod_subcourse\output;
25
 
26
defined('MOODLE_INTERNAL') || die();
27
 
28
require_once($CFG->dirroot . '/mod/subcourse/locallib.php');
29
 
30
/**
31
 * Controls the display of the plugin in the Mobile App.
32
 *
33
 * @package   mod_subcourse
34
 * @category  output
35
 * @copyright 2020 David Mudrák <david@moodle.com>
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 object
45
     */
46
    public static function main_view($args) {
47
        global $OUTPUT, $USER, $DB;
48
 
49
        $args = (object) $args;
50
        $versionname = $args->appversioncode >= 3950 ? 'latest' : 'ionic3';
51
        $cm = get_coursemodule_from_id('subcourse', $args->cmid);
52
        $context = \context_module::instance($cm->id);
53
 
54
        require_login($args->courseid, false, $cm, true, true);
55
        require_capability('mod/subcourse:view', $context);
56
 
57
        $subcourse = $DB->get_record('subcourse', ['id' => $cm->instance], '*', MUST_EXIST);
58
 
59
        $warning = null;
60
        $progress = null;
61
 
62
        if (empty($subcourse->refcourse)) {
63
            $refcourse = false;
64
 
65
            if (has_capability('mod/subcourse:fetchgrades', $context)) {
66
                $warning = get_string('refcoursenull', 'subcourse');
67
            }
68
 
69
        } else {
70
            $refcourse = $DB->get_record('course', ['id' => $subcourse->refcourse], 'id, fullname', IGNORE_MISSING);
71
        }
72
 
73
        if ($refcourse) {
74
            $refcourse->fullname = \core_external\util::format_string($refcourse->fullname, $context);
75
            $refcourse->url = new \moodle_url('/course/view.php', ['id' => $refcourse->id]);
76
            $progress = \core_completion\progress::get_course_progress_percentage($refcourse);
77
        }
78
 
79
        $currentgrade = subcourse_get_current_grade($subcourse, $USER->id);
80
 
81
        // Pre-format some of the texts for the mobile app.
82
        $subcourse->name = \core_external\util::format_string($subcourse->name, $context);
83
        [$subcourse->intro, $subcourse->introformat] = \core_external\util::format_text($subcourse->intro, $subcourse->introformat, $context,
84
            'mod_subcourse', 'intro');
85
 
86
        $data = [
87
            'cmid' => $cm->id,
88
            'subcourse' => $subcourse,
89
            'refcourse' => $refcourse,
90
            'progress' => $progress,
91
            'hasprogress' => isset($progress),
92
            'currentgrade' => $currentgrade,
93
            'hasgrade' => isset($currentgrade),
94
            'warning' => $warning,
95
        ];
96
 
97
        return [
98
            'templates' => [
99
                [
100
                    'id' => 'main',
101
                    'html' => $OUTPUT->render_from_template("mod_subcourse/mobile_view_$versionname", $data),
102
                ],
103
            ],
104
            'javascript' => '',
105
            'otherdata' => '',
106
            'files' => [],
107
        ];
108
    }
109
}