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 - http://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
namespace mod_hvp\output;
18
 
19
defined('MOODLE_INTERNAL') || die();
20
 
21
use context_module;
22
use mod_hvp;
23
 
24
class mobile {
25
 
26
    public static function mobile_course_view($args) {
27
        global $DB, $CFG, $OUTPUT, $USER;
28
 
29
        $cmid = $args['cmid'];
30
        if (!$CFG->allowframembedding) {
31
            $context = \context_system::instance();
32
            if (has_capability('moodle/site:config', $context)) {
33
                $template = 'mod_hvp/iframe_embedding_disabled';
34
            } else {
35
                $template = 'mod_hvp/contact_site_administrator';
36
            }
37
            return array(
38
                'templates' => array(
39
                    array(
40
                        'id' => 'noiframeembedding',
41
                        'html' => $OUTPUT->render_from_template($template, [])
42
                    )
43
                )
44
            );
45
        }
46
 
47
        // Verify course context.
48
        $cm = get_coursemodule_from_id('hvp', $cmid);
49
        if (!$cm) {
50
            print_error('invalidcoursemodule');
51
        }
52
        $course = $DB->get_record('course', array('id' => $cm->course));
53
        if (!$course) {
54
            print_error('coursemisconf');
55
        }
56
        require_course_login($course, false, $cm, true, true);
57
        $context = context_module::instance($cm->id);
58
        require_capability('mod/hvp:view', $context);
59
 
60
        list($token, $secret) = mod_hvp\mobile_auth::create_embed_auth_token();
61
 
62
        // Store secret in database.
63
        $auth             = $DB->get_record('hvp_auth', array(
64
            'user_id' => $USER->id,
65
        ));
66
        $currenttimestamp = time();
67
        if ($auth) {
68
            $DB->update_record('hvp_auth', array(
69
                'id'         => $auth->id,
70
                'secret'     => $token,
71
                'created_at' => $currenttimestamp,
72
            ));
73
        } else {
74
            $DB->insert_record('hvp_auth', array(
75
                'user_id'    => $USER->id,
76
                'secret'     => $token,
77
                'created_at' => $currenttimestamp
78
            ));
79
        }
80
 
81
        $data = [
82
            'cmid'    => $cmid,
83
            'wwwroot' => $CFG->wwwroot,
84
            'user_id' => $USER->id,
85
            'secret'  => urlencode($secret)
86
        ];
87
 
88
        return array(
89
            'templates'  => array(
90
                array(
91
                    'id'   => 'main',
92
                    'html' => $OUTPUT->render_from_template('mod_hvp/mobile_view_page', $data),
93
                ),
94
            ),
95
            'javascript' => file_get_contents($CFG->dirroot . '/mod/hvp/library/js/h5p-resizer.js'),
96
        );
97
    }
98
}