Proyectos de Subversion Moodle

Rev

Rev 1326 | Rev 1372 | Ir a la última revisión | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
256 ariadna 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
 
1301 ariadna 17
namespace theme_universe_child\output;
256 ariadna 18
 
19
use html_writer;
20
use stdClass;
21
use moodle_url;
22
use context_course;
23
use context_system;
24
use core_course_list_element;
25
use custom_menu;
26
use action_menu_filler;
27
use action_menu_link_secondary;
28
use action_menu;
29
use action_link;
30
use core_text;
31
use coding_exception;
32
use navigation_node;
33
use context_header;
1301 ariadna 34
use core\oauth2\rest;
256 ariadna 35
use pix_icon;
36
use renderer_base;
37
use theme_config;
38
use get_string;
39
use core_course_category;
40
use theme_universe\util\user;
41
use theme_universe\util\course;
1301 ariadna 42
use core_completion\progress;
256 ariadna 43
 
1371 ariadna 44
require_once($CFG->dirroot . '/cesa/statics_blocks.php');
256 ariadna 45
 
46
/**
47
 * Renderers to align Moodle's HTML with that expected by Bootstrap
48
 *
1371 ariadna 49
 * @package    theme_universe_child
256 ariadna 50
 * @copyright  2023 Marcin Czaja (https://rosea.io)
51
 * @license    Commercial https://themeforest.net/licenses
52
 */
1371 ariadna 53
class core_renderer extends \theme_universe\output\core_renderer
1291 ariadna 54
{
1298 ariadna 55
    /**
1371 ariadna 56
     * Renderiza los bloques estáticos
1298 ariadna 57
     */
1301 ariadna 58
    public function render_statics_blocks($userid = null)
59
    {
60
        global $USER;
1298 ariadna 61
 
1301 ariadna 62
        if (!$userid) {
63
            $userid = $USER->id;
64
        }
65
 
66
        // Instanciamos StaticsBlocks para renderizar los bloques
67
        $statics_blocks = new \StaticsBlocks(
68
            'side-pre',
69
            ['messageteacher', 'comments', 'cesa_course_rating', 'cesa_notes']
70
        );
71
 
72
        $blocks = $statics_blocks->renderBlocks();
73
 
74
        return $blocks;
75
    }
76
 
1298 ariadna 77
    /**
1371 ariadna 78
     * Navegación de completitud del curso
1298 ariadna 79
     */
1301 ariadna 80
    public function cesa_navigation_course_completion()
81
    {
82
        global $COURSE, $PAGE, $USER, $CFG;
83
 
84
        if (empty($PAGE->cm->id) || empty($COURSE->enablecompletion)) {
85
            return '';
86
        }
87
 
88
        $course_context = context_course::instance($COURSE->id);
89
        $roles = get_user_roles($course_context, $USER->id, true);
90
 
91
        $completion_visible = true;
92
        foreach ($roles as $role) {
93
            if ($role->shortname != 'student') {
1371 ariadna 94
                $completion_visible = false;
1301 ariadna 95
            }
96
        }
97
 
98
        if (!$completion_visible) {
99
            return '';
100
        }
101
        $PAGE->requires->js(new \moodle_url($CFG->wwwroot . '/local/cesanavigation/javascript/terminacion.js'));
102
 
103
        $page_context = $PAGE->cm;
104
        $modules = get_fast_modinfo($COURSE->id)->get_cms();
105
        $mods = [];
106
        foreach ($modules as $module) {
107
            if (!$module->uservisible || $module->is_stealth() || empty($module->url)) {
108
                continue;
109
            }
110
            $mods[$module->id] = $module;
111
        }
112
 
113
        $nummods = count($mods);
114
        if ($nummods == 1) {
115
            return '';
116
        }
117
 
118
        $modids = array_keys($mods);
1371 ariadna 119
        $position = array_search($page_context->id, $modids);
1301 ariadna 120
        $currentmod = $mods[$modids[$position]];
121
 
122
        $completioninfo = new \completion_info($COURSE);
123
        $completiondata = $completioninfo->get_data($currentmod, true);
124
        if ($completiondata->completionstate != COMPLETION_COMPLETE && $completiondata->completionstate != COMPLETION_COMPLETE_PASS) {
125
            $url = new \moodle_url($CFG->wwwroot . '/local/cesanavigation/terminacion.php', ['courseid' => $COURSE->id, 'modid' =>  $currentmod->id]);
126
            return '<div class="containerr">
127
                        <input type="button" class="btn btn-primary d-block mx-auto btn-cesa-course-completion button-cesa vertical-center center" data-url="' . $url . '" value="Completar y continuar">
128
                    </div>';
129
        }
130
 
131
        return '';
132
    }
133
 
1371 ariadna 134
    /**
135
     * Menú lateral del curso
136
     */
1301 ariadna 137
    public function cesa_navigation_course_menu_lateral_output()
138
    {
139
        global $CFG, $COURSE, $PAGE, $DB, $OUTPUT;
140
 
141
        if (!$COURSE->id) {
142
            return '';
143
        }
144
 
145
        $course_id = $COURSE->id;
1371 ariadna 146
        $parent = optional_param('parent', 0, PARAM_INT);
1301 ariadna 147
        if (!$parent) {
1371 ariadna 148
            $parent = optional_param('amp;parent', 0, PARAM_INT);
1301 ariadna 149
        }
150
 
151
        if ($parent) {
1371 ariadna 152
            $sql = ' SELECT * FROM {subcourse} WHERE course = ' . $parent;
1301 ariadna 153
            $sql .= ' AND refcourse = ' . $course_id;
1371 ariadna 154
            $recordParentRefCourse = $DB->get_record_sql($sql);
1301 ariadna 155
            if ($recordParentRefCourse) {
156
                $course_id = $recordParentRefCourse->course;
157
            }
158
        }
159
 
160
        $course = get_course($course_id);
161
        $course_context = context_course::instance($course->id);
162
        $completioninfo = new \completion_info($course);
163
 
164
        $menu = [];
165
        $currentServerLink = strtolower(trim($_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']));
166
        $currentServerLink = html_entity_decode($currentServerLink);
167
        $currentServerLink = htmlentities($currentServerLink);
168
 
169
        $parts = explode('&', $currentServerLink);
170
        if (count($parts) > 1) {
171
            $currentServerLink = $parts[0];
172
        }
173
 
174
        $modules = get_fast_modinfo($course->id)->get_cms();
175
        $prevmod = null;
176
        $nextmod = null;
177
        $currentmod = new stdClass();
178
        $currentmod->name = "Sin Módulos";
179
        $mods = [];
180
        $menu = [];
181
        $numberOfTemary = 1;
182
        $prevlink = new \StdClass();
183
        $nextlink = new \StdClass();
184
        $prevlink->url = "#";
185
        $nextlink->url = "#";
186
 
187
        $isACoursePage = $course->id !== "1" ? true : false;
188
 
189
        $modules = get_fast_modinfo($COURSE->id)->get_cms();
190
        if (!empty($modules)) {
191
            foreach ($modules as $module) {
192
                if (!$module->uservisible || $module->is_stealth() || empty($module->url)) {
193
                    continue;
194
                }
195
                $mods[$module->id] = $module;
196
            }
197
 
198
            $nummods = count($mods);
199
            if ($nummods == 1) {
1371 ariadna 200
                return '';
1301 ariadna 201
            }
202
 
203
            $modids = array_keys($mods);
1371 ariadna 204
            $position = array_search($course_context->id, $modids);
1301 ariadna 205
            $currentmod = $mods[$modids[$position]];
206
 
207
            if ($position > 0) {
208
                $prevmod = $mods[$modids[$position - 1]];
209
            }
210
 
211
            if ($position < ($nummods - 1)) {
212
                $nextmod = $mods[$modids[$position + 1]];
213
            }
214
        }
215
 
216
        $modinfo = get_fast_modinfo($course);
1371 ariadna 217
        $records = $modinfo->get_section_info_all();
1301 ariadna 218
        $sections = [];
219
 
220
        foreach ($records as $record) {
221
            if (!$record->visible) {
222
                continue;
223
            }
224
 
225
            $section = new \stdClass();
226
            $section->id = $record->id;
227
            $section->section = $record->section;
228
            $section->name = $record->name;
229
            $section->parent = $record->parent;
230
            $section->visible = 1;
231
 
232
            array_push($sections, $section);
233
        }
234
 
235
        $openParent = 0;
236
        $maxSections = count($sections);
237
        for ($i = 0; $i < $maxSections; $i++) {
238
            $j = $i + 1;
239
            if ($j < $maxSections) {
240
                if ($sections[$j]->parent) {
241
                    $openParent = true;
242
                    $sections[$i]->close_section_parent = 0;
243
                    $sections[$i]->close_section = 0;
244
                } else {
245
                    $sections[$i]->close_section_parent = $openParent ? 1 : 0;
246
                    $sections[$i]->close_section = 1;
247
                }
248
            } else {
249
                $sections[$i]->close_section_parent = $openParent ? 1 : 0;
250
                $sections[$i]->close_section = 1;
251
            }
252
        }
253
 
1371 ariadna 254
        foreach ($sections as $key => $section) {
1301 ariadna 255
            if (!$section->visible) {
256
                continue;
257
            }
258
 
259
            $activities = [];
260
            $section_active = false;
261
 
262
            foreach ($modules as $module) {
1371 ariadna 263
                if ($module->section != $section->id) {
1301 ariadna 264
                    continue;
265
                }
266
 
267
                if (!$module->uservisible || $module->is_stealth()) {
268
                    continue;
269
                }
270
 
271
                $mods[$module->id] = $module;
272
 
273
                $duration = '';
274
                $type = '';
275
                $filepath = '';
276
 
1371 ariadna 277
                $sql = 'SELECT md.name, cm.instance FROM {modules} md ' .
278
                    'JOIN {course_modules} cm ON cm.module = md.id ' .
279
                    'WHERE cm.id = ' . $module->id . ' LIMIT 1';
1301 ariadna 280
 
281
                $record = $DB->get_record_sql($sql);
282
                if ($record) {
283
                    $type = $record->name;
284
 
285
                    if ($type == 'hvp') {
1371 ariadna 286
                        $instance = $record->instance;
1301 ariadna 287
                        $sql = 'SELECT json_content FROM {hvp} WHERE id = ' . $instance . ' LIMIT 1';
288
                        $record = $DB->get_record_sql($sql);
289
 
290
                        if ($record) {
291
                            $json_content = json_decode($record->json_content);
292
                            if (!empty($json_content->interactiveVideo->video->files[0]->path)) {
293
                                $filepath = trim($json_content->interactiveVideo->video->files[0]->path);
294
                                $filepath = trim(str_replace('#tmp', '', $filepath));
295
 
296
                                $arr = explode('/', $filepath);
297
                                if (count($arr) > 1) {
298
                                    $filename = $arr[count($arr) - 1];
299
                                } else {
300
                                    $filename = $arr[0];
301
                                }
302
 
1371 ariadna 303
                                $duration = $this->extractDurationFromVideo($record, $filename);
1301 ariadna 304
                            }
305
                        }
306
                    }
307
 
1371 ariadna 308
                    $activity = new \stdClass();
309
                    $activity->id = $module->id;
310
                    $activity->name = $this->substr_cesa_navigation_course_menu_name($module->name);
311
                    $activity->url = $module->url;
312
                    $activity->type = $type;
313
                    $activity->duration = $duration;
314
                    $activity->active = ($currentmod->id == $module->id);
1301 ariadna 315
 
1371 ariadna 316
                    array_push($activities, $activity);
317
                }
318
            }
1301 ariadna 319
 
1371 ariadna 320
            $section->activities = $activities;
321
            array_push($menu, $section);
322
        }
1301 ariadna 323
 
1371 ariadna 324
        $data = new \stdClass();
325
        $data->sections = $menu;
326
        $data->currentmod = $currentmod;
327
        $data->prevmod = $prevmod;
328
        $data->nextmod = $nextmod;
1301 ariadna 329
 
1371 ariadna 330
        return $this->render_from_template('theme_universe_child/course_menu_lateral', $data);
331
    }
1301 ariadna 332
 
1371 ariadna 333
    /**
334
     * Drawer del curso
335
     */
336
    public function universe_child_course_drawer(): string
337
    {
338
        global $COURSE, $PAGE, $OUTPUT;
1301 ariadna 339
 
1371 ariadna 340
        if (!$COURSE->id) {
341
            return '';
342
        }
1301 ariadna 343
 
1371 ariadna 344
        $course = get_course($COURSE->id);
345
        $course_context = context_course::instance($course->id);
1301 ariadna 346
 
1371 ariadna 347
        $drawer = new \stdClass();
348
        $drawer->course = $course;
349
        $drawer->context = $course_context;
350
        $drawer->output = $OUTPUT;
1301 ariadna 351
 
1371 ariadna 352
        return $this->render_from_template('theme_universe_child/course_drawer', $drawer);
353
    }
1301 ariadna 354
 
1371 ariadna 355
    /**
356
     * Funciones de imágenes de la barra de navegación
357
     */
358
    public function get_navbar_image_courses()
359
    {
360
        global $CFG;
1301 ariadna 361
 
1371 ariadna 362
        if (!empty($this->page->theme->settings->navbar_icon_courses)) {
363
            $url = $this->page->theme->setting_file_url('navbar_icon_courses', 'navbar_icon_courses');
364
            $relativebaseurl = preg_replace('|^https?://|i', '//', $CFG->wwwroot);
365
            $url = str_replace($relativebaseurl, '', $url);
366
            return new moodle_url($url);
367
        }
1301 ariadna 368
 
1371 ariadna 369
        return $CFG->wwwroot . '/theme/universe_child/pix/icon-catalog-white.png';
370
    }
1301 ariadna 371
 
1371 ariadna 372
    public function get_navbar_image_progress()
373
    {
374
        global $CFG;
1301 ariadna 375
 
1371 ariadna 376
        if (!empty($this->page->theme->settings->navbar_icon_progress)) {
377
            $url = $this->page->theme->setting_file_url('navbar_icon_progress', 'navbar_icon_progress');
378
            $relativebaseurl = preg_replace('|^https?://|i', '//', $CFG->wwwroot);
379
            $url = str_replace($relativebaseurl, '', $url);
380
            return new moodle_url($url);
1301 ariadna 381
        }
382
 
1371 ariadna 383
        return $CFG->wwwroot . '/theme/universe_child/pix/icon-progress-white.png';
384
    }
1301 ariadna 385
 
1371 ariadna 386
    public function get_navbar_image_forums()
387
    {
388
        global $CFG;
389
 
390
        if (!empty($this->page->theme->settings->navbar_icon_forums)) {
391
            $url = $this->page->theme->setting_file_url('navbar_icon_forums', 'navbar_icon_forums');
392
            $relativebaseurl = preg_replace('|^https?://|i', '//', $CFG->wwwroot);
393
            $url = str_replace($relativebaseurl, '', $url);
394
            return new moodle_url($url);
1301 ariadna 395
        }
396
 
1371 ariadna 397
        return $CFG->wwwroot . '/theme/universe_child/pix/icon-forum-white.png';
398
    }
1301 ariadna 399
 
1371 ariadna 400
    public function get_navbar_image_calendar()
401
    {
402
        global $CFG;
1301 ariadna 403
 
1371 ariadna 404
        if (!empty($this->page->theme->settings->navbar_icon_calendar)) {
405
            $url = $this->page->theme->setting_file_url('navbar_icon_calendar', 'navbar_icon_calendar');
406
            $relativebaseurl = preg_replace('|^https?://|i', '//', $CFG->wwwroot);
407
            $url = str_replace($relativebaseurl, '', $url);
408
            return new moodle_url($url);
409
        }
1301 ariadna 410
 
1371 ariadna 411
        return $CFG->wwwroot . '/theme/universe_child/pix/icon-calendar-white.png';
1301 ariadna 412
    }
413
 
1371 ariadna 414
    public function get_navbar_image_personal_area()
1300 ariadna 415
    {
1371 ariadna 416
        global $CFG;
1300 ariadna 417
 
1371 ariadna 418
        if (!empty($this->page->theme->settings->navbar_icon_personal_area)) {
419
            $url = $this->page->theme->setting_file_url('navbar_icon_personal_area', 'navbar_icon_personal_area');
420
            $relativebaseurl = preg_replace('|^https?://|i', '//', $CFG->wwwroot);
421
            $url = str_replace($relativebaseurl, '', $url);
422
            return new moodle_url($url);
1300 ariadna 423
        }
424
 
1371 ariadna 425
        return $CFG->wwwroot . '/theme/universe_child/pix/icon-personal-area-white.png';
426
    }
1300 ariadna 427
 
1371 ariadna 428
    public function get_navbar_image_messages()
429
    {
430
        global $CFG;
1300 ariadna 431
 
1371 ariadna 432
        if (!empty($this->page->theme->settings->navbar_icon_messages)) {
433
            $url = $this->page->theme->setting_file_url('navbar_icon_messages', 'navbar_icon_messages');
434
            $relativebaseurl = preg_replace('|^https?://|i', '//', $CFG->wwwroot);
435
            $url = str_replace($relativebaseurl, '', $url);
436
            return new moodle_url($url);
1300 ariadna 437
        }
438
 
1371 ariadna 439
        return $CFG->wwwroot . '/theme/universe_child/pix/icon-messages-white.png';
1300 ariadna 440
    }
1301 ariadna 441
 
1371 ariadna 442
    /**
443
     * Funciones de utilidad
444
     */
445
    private function extractDurationFromVideo($record, $filename)
1301 ariadna 446
    {
1371 ariadna 447
        global $DB;
1301 ariadna 448
 
1371 ariadna 449
        $sql = 'SELECT * FROM {files} WHERE filename = "' . $filename . '" AND component = "mod_hvp" AND filearea = "content" LIMIT 1';
450
        $file = $DB->get_record_sql($sql);
1301 ariadna 451
 
1371 ariadna 452
        if ($file) {
453
            $sql = 'SELECT * FROM {files} WHERE filename = "' . $filename . '" AND component = "mod_hvp" AND filearea = "content" AND id != ' . $file->id . ' LIMIT 1';
454
            $file2 = $DB->get_record_sql($sql);
455
 
456
            if ($file2) {
457
                $sql = 'SELECT * FROM {files} WHERE filename = "' . $filename . '" AND component = "mod_hvp" AND filearea = "content" AND id != ' . $file->id . ' AND id != ' . $file2->id . ' LIMIT 1';
458
                $file3 = $DB->get_record_sql($sql);
459
 
460
                if ($file3) {
461
                    return $file3->duration;
462
                }
463
            }
1301 ariadna 464
        }
465
 
1371 ariadna 466
        return '';
1301 ariadna 467
    }
1326 ariadna 468
 
1371 ariadna 469
    private function substr_cesa_navigation_course_menu_name($s, $l = 50)
1326 ariadna 470
    {
1371 ariadna 471
        return core_text::substr($s, 0, $l);
472
    }
1326 ariadna 473
 
1371 ariadna 474
    /**
475
     * Sobrescribe la función de acceso de invitados del tema padre
476
     */
477
    public function theme_universe_get_course_guest_access_hint($courseid)
478
    {
479
        return $this->theme_universe_child_get_course_guest_access_hint($courseid);
480
    }
1326 ariadna 481
 
1371 ariadna 482
    /**
483
     * Implementación específica del tema hijo para el acceso de invitados
484
     */
485
    public function theme_universe_child_get_course_guest_access_hint($courseid)
486
    {
487
        global $DB, $CFG;
1326 ariadna 488
 
1371 ariadna 489
        $html = '';
490
        $course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST);
491
        $context = context_course::instance($course->id);
1326 ariadna 492
 
1371 ariadna 493
        if (isguestuser() || !isloggedin()) {
494
            $html .= html_writer::start_tag('div', array('class' => 'courseguestaccess'));
495
            $html .= html_writer::tag('p', get_string('guestaccess', 'theme_universe_child'));
496
            $html .= html_writer::end_tag('div');
497
        }
1326 ariadna 498
 
1371 ariadna 499
        return $html;
1326 ariadna 500
    }
1291 ariadna 501
}