Proyectos de Subversion Moodle

Rev

Rev 1 | | Comparar con el anterior | 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_bigbluebuttonbn\output;
18
 
19
use core\check\result;
20
use core\output\notification;
21
use mod_bigbluebuttonbn\instance;
22
use mod_bigbluebuttonbn\local\config;
23
use mod_bigbluebuttonbn\local\proxy\bigbluebutton_proxy;
24
use mod_bigbluebuttonbn\meeting;
25
use renderable;
26
use renderer_base;
27
use stdClass;
28
use templatable;
29
use tool_task\check\cronrunning;
30
 
31
/**
32
 * View Page template renderable.
33
 *
34
 * @package   mod_bigbluebuttonbn
35
 * @copyright 2021 Andrew Lyons <andrew@nicols.co.uk>
36
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
37
 */
38
class view_page implements renderable, templatable {
39
 
40
    /** @var instance The instance being rendered */
41
    protected $instance;
42
 
43
    /**
44
     * Constructor for the View Page.
45
     *
46
     * @param instance $instance
47
     */
48
    public function __construct(instance $instance) {
49
        $this->instance = $instance;
50
    }
51
 
52
    /**
53
     * Export the content required to render the template.
54
     *
55
     * @param renderer_base $output
56
     * @return stdClass
57
     */
58
    public function export_for_template(renderer_base $output): stdClass {
59
        $pollinterval = bigbluebutton_proxy::get_poll_interval();
60
        $templatedata = (object) [
61
            'instanceid' => $this->instance->get_instance_id(),
62
            'pollinterval' => $pollinterval * 1000, // Javascript poll interval is in miliseconds.
63
            'groupselector' => $output->render_groups_selector($this->instance),
64
            'meetingname' => $this->instance->get_meeting_name(),
65
            'description' => $this->instance->get_meeting_description(true),
66
            'joinurl' => $this->instance->get_join_url(),
67
        ];
68
 
69
        $viewwarningmessage = config::get('general_warning_message');
70
        if ($this->show_view_warning() && !empty($viewwarningmessage)) {
71
            $templatedata->sitenotification = (object) [
72
                'message' => $viewwarningmessage,
73
                'type' => config::get('general_warning_box_type'),
74
                'icon' => [
75
                    'pix' => 'i/bullhorn',
76
                    'component' => 'core',
77
                ],
78
            ];
79
 
80
            if ($url = config::get('general_warning_button_href')) {
81
                $templatedata->sitenotification->actions = [[
82
                    'url' => $url,
83
                    'title' => config::get('general_warning_button_text'),
84
                ]];
85
            }
86
        }
87
 
88
        if ($this->instance->is_feature_enabled('showroom')) {
1441 ariadna 89
            $showpresentation = $this->instance->should_show_presentation();
1 efrain 90
            $roomdata = meeting::get_meeting_info_for_instance($this->instance);
91
            $roomdata->haspresentations = false;
1441 ariadna 92
            $roomdata->showpresentations = $showpresentation;
1 efrain 93
            if (!empty($roomdata->presentations)) {
94
                $roomdata->haspresentations = true;
95
            }
96
            $templatedata->room = $roomdata;
97
        }
98
 
99
        $templatedata->recordingwarnings = [];
100
        $check = new cronrunning();
101
        $result = $check->get_result();
102
        if ($result->get_status() != result::OK && $this->instance->is_moderator()) {
103
            $templatedata->recordingwarnings[] = (new notification(
104
                get_string('view_message_cron_disabled', 'mod_bigbluebuttonbn',
105
                    $result->get_summary()),
106
                notification::NOTIFY_ERROR,
107
                false
108
            ))->export_for_template($output);
109
        }
110
        if ($this->instance->is_feature_enabled('showrecordings') && $this->instance->is_recorded()) {
111
            $recordings = new recordings_session($this->instance);
112
            $templatedata->recordings = $recordings->export_for_template($output);
113
        } else if ($this->instance->is_type_recordings_only()) {
114
            $templatedata->recordingwarnings[] = (new notification(
115
                get_string('view_message_recordings_disabled', 'mod_bigbluebuttonbn'),
116
                notification::NOTIFY_WARNING,
117
                false
118
            ))->export_for_template($output);
119
        }
120
 
121
        return $templatedata;
122
    }
123
 
124
    /**
125
     * Whether to show the view warning.
126
     *
127
     * @return bool
128
     */
129
    protected function show_view_warning(): bool {
130
        if ($this->instance->is_admin()) {
131
            return true;
132
        }
133
 
134
        $generalwarningroles = explode(',', config::get('general_warning_roles'));
135
        $userroles = \mod_bigbluebuttonbn\local\helpers\roles::get_user_roles(
136
            $this->instance->get_context(),
137
            $this->instance->get_user_id()
138
        );
139
 
140
        foreach ($userroles as $userrole) {
141
            if (in_array($userrole->shortname, $generalwarningroles)) {
142
                return true;
143
            }
144
        }
145
 
146
        return false;
147
    }
148
 
149
}