Proyectos de Subversion Moodle

Rev

Rev 193 | Rev 198 | Ir a la última revisión | | 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 theme_universe\output;
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;
34
use pix_icon;
35
use renderer_base;
36
use theme_config;
37
use get_string;
38
use core_course_category;
39
use theme_universe\util\user;
40
use theme_universe\util\course;
41
 
191 ariadna 42
require_once($CFG->dirroot . '/cesa/cesa.php'); // Incluimos las clases de Cesa
43
require_once($CFG->dirroot . '/cesa/statics_blocks.php'); // Incluimos StaticsBlocks
187 ariadna 44
 
1 efrain 45
/**
46
 * Renderers to align Moodle's HTML with that expected by Bootstrap
47
 *
48
 * @package    theme_universe
49
 * @copyright  2023 Marcin Czaja (https://rosea.io)
50
 * @license    Commercial https://themeforest.net/licenses
51
 */
161 ariadna 52
class core_renderer extends \core_renderer
53
{
1 efrain 54
 
161 ariadna 55
    public function edit_button(moodle_url $url, string $method = 'post')
56
    {
1 efrain 57
        if ($this->page->theme->haseditswitch) {
58
            return;
59
        }
60
        $url->param('sesskey', sesskey());
61
        if ($this->page->user_is_editing()) {
62
            $url->param('edit', 'off');
63
            $editstring = get_string('turneditingoff');
64
        } else {
65
            $url->param('edit', 'on');
66
            $editstring = get_string('turneditingon');
67
        }
68
        $button = new \single_button($url, $editstring, 'post', ['class' => 'btn btn-primary']);
69
        return $this->render_single_button($button);
70
    }
71
 
72
    /**
73
     * The standard tags (meta tags, links to stylesheets and JavaScript, etc.)
74
     * that should be included in the <head> tag. Designed to be called in theme
75
     * layout.php files.
76
     *
77
     * @return string HTML fragment.
78
     */
161 ariadna 79
    public function standard_head_html()
80
    {
1 efrain 81
        $output = parent::standard_head_html();
82
        global $USER;
83
 
84
        $googleanalyticscode = "<script
85
                                    async
86
                                    src='https://www.googletagmanager.com/gtag/js?id=GOOGLE-ANALYTICS-CODE'>
87
                                </script>
88
                                <script>
89
                                    window.dataLayer = window.dataLayer || [];
90
                                    function gtag() {
91
                                        dataLayer.push(arguments);
92
                                    }
93
                                    gtag('js', new Date());
94
                                    gtag('config', 'GOOGLE-ANALYTICS-CODE');
95
                                </script>";
96
 
97
        $theme = theme_config::load('universe');
98
 
99
        if (!empty($theme->settings->googleanalytics) && isloggedin()) {
100
            $output .= str_replace(
101
                "GOOGLE-ANALYTICS-CODE",
102
                trim($theme->settings->googleanalytics),
103
                $googleanalyticscode
104
            );
105
        }
106
 
107
        return $output;
108
    }
109
 
110
    /*
111
    *
112
    * Method to get reference to $CFG->themedir variable
113
    *
114
    */
115
    function theme_universe_themedir()
116
    {
117
        global $CFG;
118
 
119
        $teme_dir = '/theme';
120
 
161 ariadna 121
        if (isset($CFG->themedir)) {
1 efrain 122
            $teme_dir = $CFG->themedir;
123
            $teme_dir = str_replace($CFG->dirroot, '', $CFG->themedir);
124
        }
125
 
126
        return $teme_dir;
127
    }
128
 
129
 
130
    /**
131
     *
132
     * Method to load theme element form 'layout/parts' folder
133
     *
134
     */
161 ariadna 135
    public function theme_part($name, $vars = array())
136
    {
1 efrain 137
 
138
        global $CFG;
139
 
140
        $element = $name . '.php';
141
        $candidate1 = $this->page->theme->dir . '/layout/parts/' . $element;
142
 
143
        // Require for child theme.
144
        if (file_exists($candidate1)) {
145
            $candidate = $candidate1;
146
        } else {
147
            $candidate = $CFG->dirroot . theme_universe_themedir() . '/universe/layout/parts/' . $element;
148
        }
149
 
150
        if (!is_readable($candidate)) {
151
            debugging("Could not include element $name.");
152
            return;
153
        }
154
 
155
        ob_start();
156
        include($candidate);
157
        $output = ob_get_clean();
158
        return $output;
159
    }
160
 
161
    /**
162
     * Renders the custom menu
163
     *
164
     * @param custom_menu $menu
165
     * @return mixed
166
     */
161 ariadna 167
    protected function render_custom_menu(custom_menu $menu)
168
    {
1 efrain 169
        if (!$menu->has_children()) {
170
            return '';
171
        }
172
 
173
        $content = '';
174
        foreach ($menu->get_children() as $item) {
175
            $context = $item->export_for_template($this);
176
            $content .= $this->render_from_template('core/moremenu_children', $context);
177
        }
178
 
179
        return $content;
180
    }
181
 
182
    /**
183
     * Outputs the favicon urlbase.
184
     *
185
     * @return string an url
186
     */
161 ariadna 187
    public function favicon()
188
    {
1 efrain 189
        global $CFG;
190
        $theme = theme_config::load('universe');
191
        $favicon = $theme->setting_file_url('favicon', 'favicon');
192
 
193
        if (!empty(($favicon))) {
194
            $urlreplace = preg_replace('|^https?://|i', '//', $CFG->wwwroot);
195
            $favicon = str_replace($urlreplace, '', $favicon);
196
 
197
            return new moodle_url($favicon);
198
        }
199
 
200
        return parent::favicon();
201
    }
202
 
161 ariadna 203
    public function render_lang_menu()
204
    {
1 efrain 205
        $langs = get_string_manager()->get_list_of_translations();
206
        $haslangmenu = $this->lang_menu() != '';
207
        $menu = new custom_menu;
208
 
209
        if ($haslangmenu) {
210
            $strlang = get_string('language');
211
            $currentlang = current_language();
212
            if (isset($langs[$currentlang])) {
213
                $currentlang = $langs[$currentlang];
214
            } else {
215
                $currentlang = $strlang;
216
            }
217
            $this->language = $menu->add($currentlang, new moodle_url('#'), $strlang, 10000);
218
            foreach ($langs as $langtype => $langname) {
219
                $this->language->add($langname, new moodle_url($this->page->url, array('lang' => $langtype)), $langname);
220
            }
221
            foreach ($menu->get_children() as $item) {
222
                $context = $item->export_for_template($this);
223
            }
224
 
225
            $context->currentlangname = array_search($currentlang, $langs);
226
 
227
            if (isset($context)) {
228
                return $this->render_from_template('theme_universe/lang_menu', $context);
229
            }
230
        }
231
    }
232
 
161 ariadna 233
    public function render_lang_menu_login()
234
    {
1 efrain 235
        $langs = get_string_manager()->get_list_of_translations();
236
        $haslangmenu = $this->lang_menu() != '';
237
        $menu = new custom_menu;
238
 
239
        if ($haslangmenu) {
240
            $strlang = get_string('language');
241
            $currentlang = current_language();
242
            if (isset($langs[$currentlang])) {
243
                $currentlang = $langs[$currentlang];
244
            } else {
245
                $currentlang = $strlang;
246
            }
247
            $this->language = $menu->add($currentlang, new moodle_url('#'), $strlang, 10000);
248
            foreach ($langs as $langtype => $langname) {
249
                $this->language->add($langname, new moodle_url($this->page->url, array('lang' => $langtype)), $langname);
250
            }
251
            foreach ($menu->get_children() as $item) {
252
                $context = $item->export_for_template($this);
253
            }
254
 
255
            $context->currentlangname = array_search($currentlang, $langs);
256
 
257
            if (isset($context)) {
258
                return $this->render_from_template('theme_universe/lang_menu_login', $context);
259
            }
260
        }
261
    }
262
 
161 ariadna 263
    public static function get_course_progress_count($course, $userid = 0)
264
    {
1 efrain 265
        global $USER;
266
 
267
        // Make sure we continue with a valid userid.
268
        if (empty($userid)) {
269
            $userid = $USER->id;
270
        }
271
 
272
        $completion = new \completion_info($course);
273
 
274
        // First, let's make sure completion is enabled.
275
        if (!$completion->is_enabled()) {
276
            return null;
277
        }
278
 
279
        if (!$completion->is_tracked_user($userid)) {
280
            return null;
281
        }
282
 
283
        // Before we check how many modules have been completed see if the course has.
284
        if ($completion->is_course_complete($userid)) {
285
            return 100;
286
        }
287
 
288
        // Get the number of modules that support completion.
289
        $modules = $completion->get_activities();
290
        $count = count($modules);
291
        if (!$count) {
292
            return null;
293
        }
294
 
295
        // Get the number of modules that have been completed.
296
        $completed = 0;
297
        foreach ($modules as $module) {
298
            $data = $completion->get_data($module, true, $userid);
299
            $completed += $data->completionstate == COMPLETION_INCOMPLETE ? 0 : 1;
300
        }
301
 
302
        return ($completed / $count) * 100;
303
    }
304
 
305
    /**
306
     *
307
     * Outputs the course progress if course completion is on.
308
     *
309
     * @return string Markup.
310
     */
161 ariadna 311
    protected function courseprogress($course)
312
    {
1 efrain 313
        global $USER;
314
        $theme = \theme_config::load('universe');
315
 
316
        $output = '';
317
        $courseformat = course_get_format($course);
318
 
319
        if (get_class($courseformat) != 'format_tiles') {
320
            $completion = new \completion_info($course);
321
 
322
            // Start Course progress count.
323
            // Make sure we continue with a valid userid.
324
            if (empty($userid)) {
325
                $userid = $USER->id;
326
            }
327
            $completion = new \completion_info($course);
328
 
329
            // Get the number of modules that support completion.
330
            $modules = $completion->get_activities();
331
            $count = count($modules);
332
            if (!$count) {
333
                return null;
334
            }
335
 
336
            // Get the number of modules that have been completed.
337
            $completed = 0;
338
            foreach ($modules as $module) {
339
                $data = $completion->get_data($module, true, $userid);
340
                $completed += $data->completionstate == COMPLETION_INCOMPLETE ? 0 : 1;
341
            }
342
            $progresscountc = $completed;
343
            $progresscounttotal = $count;
344
            // End progress count.
345
 
346
            if ($completion->is_enabled()) {
347
                $templatedata = new \stdClass;
348
                $templatedata->progress = \core_completion\progress::get_course_progress_percentage($course);
349
                $templatedata->progresscountc = $progresscountc;
350
                $templatedata->progresscounttotal = $progresscounttotal;
351
 
352
                if (!is_null($templatedata->progress)) {
353
                    $templatedata->progress = floor($templatedata->progress);
354
                } else {
355
                    $templatedata->progress = 0;
356
                }
357
                if (get_config('theme_universe', 'courseprogressbar') == 1) {
358
                    $progressbar = '<div class="rui-course-progresschart">' .
359
                        $this->render_from_template('theme_universe/progress-chart', $templatedata) .
360
                        '</div>';
361
                    if (has_capability('report/progress:view',  \context_course::instance($course->id))) {
362
                        $courseprogress = new \moodle_url('/report/progress/index.php');
363
                        $courseprogress->param('course', $course->id);
364
                        $courseprogress->param('sesskey', sesskey());
365
                        $output .= html_writer::link($courseprogress, $progressbar, array('class' => 'rui-course-progressbar border rounded px-3 pt-2 mb-3'));
366
                    } else {
367
                        $output .= $progressbar;
368
                    }
369
                }
370
            }
371
        }
372
 
373
        return $output;
374
    }
375
 
376
 
377
    /**
378
     *
379
     * Returns HTML to display course contacts.
380
     *
381
     */
161 ariadna 382
    public function course_teachers()
383
    {
1 efrain 384
        global $CFG, $COURSE, $DB;
385
        $course = $DB->get_record('course', ['id' => $COURSE->id]);
386
        $course = new core_course_list_element($course);
387
        $instructors = $course->get_course_contacts();
388
 
389
        if (!empty($instructors)) {
390
            $content = html_writer::start_div('course-teachers-box');
391
 
392
            foreach ($instructors as $key => $instructor) {
393
                $name = $instructor['username'];
394
                $role = $instructor['rolename'];
395
                $roleshortname = $instructor['role']->shortname;
396
 
397
                if ($instructor['role']->id == '3') {
398
                    $url = $CFG->wwwroot . '/user/profile.php?id=' . $key;
399
                    $user = $instructor['user'];
400
                    $userutil = new user($user->id);
401
                    $picture = $userutil->get_user_picture();
402
 
403
                    $content .= "<div class='course-contact-title-item'>
404
                        <a href='{$url}' 'title='{$name}'
405
                            class='course-contact rui-user-{$roleshortname}'>";
406
                    $content .= "<img src='{$picture}'
407
                        class='course-teacher-avatar' alt='{$name}'
408
                        title='{$name} - {$role}' data-toggle='tooltip'/>";
409
                    $content .= "<div class='course-teacher-content'>
410
                        <span class='course-teacher-role'>{$role}</span>
411
                        <h4 class='course-teacher-name'>{$name}</h4></div>";
412
                    $content .= "</a></div>";
413
                }
414
            }
415
 
416
            $content .= html_writer::end_div(); // End .teachers-box.
417
            return $content;
418
        }
419
    }
420
 
161 ariadna 421
    public function course_contacts()
422
    {
1 efrain 423
        global $CFG, $COURSE, $DB;
424
        $course = $DB->get_record('course', ['id' => $COURSE->id]);
425
        $course = new core_course_list_element($course);
426
        $instructors = $course->get_course_contacts();
427
 
428
        if (!empty($instructors)) {
429
            $content = html_writer::start_div('course-teachers-box w-100');
430
 
431
            foreach ($instructors as $key => $instructor) {
432
                $name = $instructor['username'];
433
                $role = $instructor['rolename'];
434
                $roleshortname = $instructor['role']->shortname;
435
 
436
                $url = $CFG->wwwroot . '/user/profile.php?id=' . $key;
437
                $user = $instructor['user'];
438
                $userutil = new user($user->id);
439
                $picture = $userutil->get_user_picture(384);
440
 
441
                $user = $DB->get_record('user', array('id' => $key));
442
                $desc = $user->description;
443
 
444
                $content .= "<div class='rui-block-team-item text-center text-md-left
445
                    d-inline-flex flex-wrap align-items-start align-items-md-center'>";
446
                $content .= "<div class='rui-card-team--img-smpl'><img src='{$picture}'
447
                    class='rui-card-team--img-smpl mr-3 mr-md-5'
448
                    alt='{$name}, {$role}'/></div>";
449
                $content .= "<div class='rui-course-teacher--item col px-0 text-left'>
450
                    <a href='{$url}' 'title='{$name}'
451
                        class='course-contact rui-user-{$roleshortname}'>
452
                        <h4 class='mb-0'>{$name}</h4></a>
453
                        <span class='rui-block-text--3 rui-block-text--light mb-3'>{$role}</span>";
454
                $content .= "<div class='rui-block-text--2 mt-2'>{$desc}</div></div></div>";
455
            }
456
            $content .= html_writer::end_div(); // End .teachers-box.
457
            return $content;
458
        }
459
    }
460
 
461
    /**
462
     *
463
     * Returns HTML to display course details.
464
     *
465
     */
161 ariadna 466
    protected function course_details()
467
    {
1 efrain 468
        global $CFG, $COURSE, $DB;
469
        $course = $DB->get_record('course', ['id' => $COURSE->id]);
470
        $course = new core_course_list_element($course);
471
        $content = '';
472
        $tempcourse = $DB->get_record('course_categories', ['id' => $COURSE->id]);
473
 
474
        $content .= html_writer::start_div('rui-course-details mt-4');
161 ariadna 475
        $content .= html_writer::start_div('rui-custom-field-box rui-course-startdate');
476
        $content .= html_writer::tag('span', get_string('startdate', 'moodle'), ['class' => 'rui-custom-field-name']);
477
        $content .= html_writer::tag('span', date("F j, Y", $COURSE->startdate), ['class' => 'rui-custom-field-value']);
478
        $content .= html_writer::end_div();
479
 
480
        // Course End date.
481
        $courseenddate = $COURSE->enddate;
482
        if ($courseenddate != '0') {
1 efrain 483
            $content .= html_writer::start_div('rui-custom-field-box rui-course-startdate');
161 ariadna 484
            $content .= html_writer::tag('span', get_string('enddate', 'moodle'), ['class' => 'rui-course-enddate-label rui-custom-field-name']);
485
            $content .= html_writer::tag('span', date("F j, Y", $courseenddate), ['class' => 'rui-course-enddate rui-custom-field-value']);
1 efrain 486
            $content .= html_writer::end_div();
161 ariadna 487
        }
1 efrain 488
        $content .= html_writer::end_div(); // .rui-course-details.
489
 
490
        return $content;
491
    }
492
 
493
    /**
494
     *
495
     * Returns HTML to display course summary.
496
     *
497
     */
161 ariadna 498
    protected function course_summary($courseid = 0, $content = '')
499
    {
1 efrain 500
        global $COURSE, $CFG;
501
        $output = '';
502
 
503
        require_once($CFG->libdir . '/filelib.php');
504
 
505
        $iscourseid = $courseid ? $courseid : $COURSE->id;
506
        $iscontent = $content ? $content : $COURSE->summary;
507
        $context = context_course::instance($iscourseid);
508
        $desc = file_rewrite_pluginfile_urls($iscontent, 'pluginfile.php', $context->id, 'course', 'summary', null);
509
 
510
        $output .= html_writer::start_div('rui-course-desc');
511
        $output .= format_text($desc, FORMAT_HTML);
512
        $output .= html_writer::end_div();
513
 
514
        return $output;
515
    }
516
 
517
    /**
518
     * Outputs the pix url base
519
     *
520
     * @return string an URL.
521
     */
161 ariadna 522
    public function get_pix_image_url_base()
523
    {
1 efrain 524
        global $CFG;
525
 
526
        return $CFG->wwwroot . "/theme/universe/pix";
527
    }
528
 
529
    /**
530
     *
531
     */
161 ariadna 532
    public function course_hero_url()
533
    {
1 efrain 534
        global $CFG, $COURSE, $DB;
535
 
536
        $course = $DB->get_record('course', ['id' => $COURSE->id]);
537
 
538
        $course = new core_course_list_element($course);
539
 
540
        $courseimage = '';
541
        $imageindex = 1;
542
        foreach ($course->get_course_overviewfiles() as $file) {
543
            $isimage = $file->is_valid_image();
544
 
545
            $url = new moodle_url("$CFG->wwwroot/pluginfile.php" . '/' .
546
                $file->get_contextid() . '/' . $file->get_component() . '/' .
547
                $file->get_filearea() .
548
                $file->get_filepath() .
549
                $file->get_filename(), ['forcedownload' => !$isimage]);
550
 
551
            if ($isimage) {
552
                $courseimage = $url;
553
            }
554
 
555
            if ($imageindex == 2) {
556
                break;
557
            }
558
 
559
            $imageindex++;
560
        }
561
 
562
        $html = '';
563
        // Create html for header.
564
        if (!empty($courseimage)) {
565
            $html .= $courseimage;
566
        }
567
        return $html;
568
    }
569
 
570
    /**
571
     * Returns HTML to display course hero.
572
     *
573
     */
161 ariadna 574
    public function course_hero()
575
    {
1 efrain 576
        global $CFG, $COURSE, $DB;
577
 
578
        $course = $DB->get_record('course', ['id' => $COURSE->id]);
579
 
580
        $course = new core_course_list_element($course);
581
 
582
        $courseimage = '';
583
 
584
        $courseutil = new course($course);
585
        $courseimage = $courseutil->get_summary_image(false); // Remove repeatable pattern on the course page.
586
 
587
        $html = '';
588
        // Create html for header.
589
        if (!empty($courseimage)) {
590
            $html .= $courseimage;
591
        }
592
        return $html;
593
    }
594
 
595
 
168 ariadna 596
 
597
 
1 efrain 598
    /**
599
     * Breadcrumbs
600
     *
601
     */
161 ariadna 602
    public function breadcrumbs()
603
    {
1 efrain 604
        global $USER, $COURSE, $CFG;
605
 
606
        $header = new stdClass();
607
        $header->hasnavbar = empty($this->page->layout_options['nonavbar']);
608
        $header->navbar = $this->navbar();
609
        $header->courseheader = $this->course_header();
610
        $html = $this->render_from_template('theme_universe/breadcrumbs', $header);
611
 
612
        return $html;
613
    }
614
 
615
 
616
    /**
617
     * Wrapper for header elements.
618
     *
619
     * @return string HTML to display the main header.
620
     */
161 ariadna 621
    public function simple_header()
622
    {
1 efrain 623
 
624
        global $USER, $COURSE, $CFG;
625
        $html = null;
626
 
627
        if (
628
            $this->page->include_region_main_settings_in_header_actions() &&
629
            !$this->page->blocks->is_block_present('settings')
630
        ) {
631
            // Only include the region main settings if the page has requested it and it doesn't already have
632
            // the settings block on it. The region main settings are included in the settings block and
633
            // duplicating the content causes behat failures.
634
            $this->page->add_header_action(html_writer::div(
635
                $this->region_main_settings_menu(),
636
                'd-print-none',
637
                ['id' => 'region-main-settings-menu']
638
            ));
639
        }
640
 
641
        $header = new stdClass();
642
        $header->settingsmenu = $this->context_header_settings_menu();
643
        $header->contextheader = $this->context_header();
644
        $header->hasnavbar = empty($this->page->layout_options['nonavbar']);
645
        $header->navbar = $this->navbar();
646
        $header->pageheadingbutton = $this->page_heading_button();
647
        $header->courseheader = $this->course_header();
648
        $header->headeractions = $this->page->get_header_actions();
649
 
650
        if ($this->page->pagelayout != 'admin') {
651
            $html .= $this->render_from_template('theme_universe/header', $header);
652
        }
653
 
654
        if ($this->page->pagelayout == 'admin') {
655
            $html .= $this->render_from_template('theme_universe/header_admin', $header);
656
        }
657
 
658
        return $html;
659
    }
660
 
187 ariadna 661
 
662
    public function render_statics_blocks($userid = null)
168 ariadna 663
    {
187 ariadna 664
        global $USER;
665
 
666
        if (!$userid) {
667
            $userid = $USER->id;
668
        }
669
 
670
        // Instanciamos StaticsBlocks para renderizar los bloques
193 ariadna 671
        $statics_blocks = new \StaticsBlocks($this->page->title);
187 ariadna 672
        return $statics_blocks->renderBlocks();
168 ariadna 673
    }
194 ariadna 674
 
161 ariadna 675
    public function display_course_progress()
676
    {
1 efrain 677
        $html = null;
678
        $html .= $this->courseprogress($this->page->course);
679
        return $html;
680
    }
681
 
682
    /**
683
     * Wrapper for header elements.
684
     *
685
     * @return string HTML to display the main header.
686
     */
161 ariadna 687
    public function full_header()
688
    {
1 efrain 689
        global $USER, $COURSE, $CFG;
690
        $theme = \theme_config::load('universe');
691
        $html = null;
692
        $pagetype = $this->page->pagetype;
693
        $homepage = get_home_page();
694
        $homepagetype = null;
695
        // Add a special case since /my/courses is a part of the /my subsystem.
696
        if ($homepage == HOMEPAGE_MY || $homepage == HOMEPAGE_MYCOURSES) {
697
            $homepagetype = 'my-index';
698
        } else if ($homepage == HOMEPAGE_SITE) {
699
            $homepagetype = 'site-index';
700
        }
701
        if (
702
            $this->page->include_region_main_settings_in_header_actions() &&
703
            !$this->page->blocks->is_block_present('settings')
704
        ) {
705
            // Only include the region main settings if the page has requested it and it doesn't already have
706
            // the settings block on it. The region main settings are included in the settings block and
707
            // duplicating the content causes behat failures.
708
            $this->page->add_header_action(html_writer::div(
709
                $this->region_main_settings_menu(),
710
                'd-print-none',
711
                ['id' => 'region-main-settings-menu']
712
            ));
713
        }
714
 
715
        $header = new stdClass();
716
        $header->settingsmenu = $this->context_header_settings_menu();
717
        $header->contextheader = $this->context_header();
718
        $header->hasnavbar = empty($this->page->layout_options['nonavbar']);
719
        $header->navbar = $this->navbar();
720
        $header->pageheadingbutton = $this->page_heading_button();
721
        $header->courseheader = $this->course_header();
722
        $header->headeractions = $this->page->get_header_actions();
723
 
724
        if ($this->page->theme->settings->ipcoursedetails == 1) {
725
            $html .= $this->course_details();
726
        }
727
 
728
        $html .= $this->render_from_template('theme_universe/header', $header);
729
        if ($this->page->theme->settings->ipcoursesummary == 1) {
730
            $html .= $this->course_summary();
731
        }
732
 
733
        $html .= html_writer::start_tag('div', array('class' => 'rui-course-header-color'));
734
        if ($this->page->theme->settings->cccteachers == 1) {
735
            $html .= $this->course_teachers();
736
        }
737
 
738
        $html .= html_writer::end_tag('div'); // End .rui-course-header.
739
 
740
        return $html;
741
    }
742
 
743
 
744
    /**
745
     * Wrapper for header elements.
746
     *
747
     * @return string HTML to display the main header.
748
     */
161 ariadna 749
    public function clean_header()
750
    {
1 efrain 751
        global $USER, $COURSE, $CFG;
752
        $theme = \theme_config::load('universe');
753
        $html = null;
754
        $pagetype = $this->page->pagetype;
755
        $homepage = get_home_page();
756
        $homepagetype = null;
757
        // Add a special case since /my/courses is a part of the /my subsystem.
758
        if ($homepage == HOMEPAGE_MY || $homepage == HOMEPAGE_MYCOURSES) {
759
            $homepagetype = 'my-index';
760
        } else if ($homepage == HOMEPAGE_SITE) {
761
            $homepagetype = 'site-index';
762
        }
763
        if (
764
            $this->page->include_region_main_settings_in_header_actions() &&
765
            !$this->page->blocks->is_block_present('settings')
766
        ) {
767
            // Only include the region main settings if the page has requested it and it doesn't already have
768
            // the settings block on it. The region main settings are included in the settings block and
769
            // duplicating the content causes behat failures.
770
            $this->page->add_header_action(html_writer::div(
771
                $this->region_main_settings_menu(),
772
                'd-print-none',
773
                ['id' => 'region-main-settings-menu']
774
            ));
775
        }
776
 
777
        $header = new stdClass();
778
        $header->courseheader = $this->course_header();
779
        $header->headeractions = $this->page->get_header_actions();
780
 
781
        $html .= $this->render_from_template('theme_universe/header', $header);
782
 
783
        return $html;
784
    }
785
 
786
 
787
    /**
788
     * Returns standard navigation between activities in a course.
789
     *
790
     * @return string the navigation HTML.
791
     */
161 ariadna 792
    public function activity_navigation()
793
    {
1 efrain 794
        // First we should check if we want to add navigation.
795
        $context = $this->page->context;
796
        if (($this->page->pagelayout !== 'incourse' && $this->page->pagelayout !== 'frametop')
797
            || $context->contextlevel != CONTEXT_MODULE
798
        ) {
799
            return '';
800
        }
801
        // If the activity is in stealth mode, show no links.
802
        if ($this->page->cm->is_stealth()) {
803
            return '';
804
        }
805
        $course = $this->page->cm->get_course();
806
        $courseformat = course_get_format($course);
807
 
808
        // Get a list of all the activities in the course.
809
        $modules = get_fast_modinfo($course->id)->get_cms();
810
        // Put the modules into an array in order by the position they are shown in the course.
811
        $mods = [];
812
        $activitylist = [];
813
        foreach ($modules as $module) {
814
            // Only add activities the user can access, aren't in stealth mode and have a url (eg. mod_label does not).
815
            if (!$module->uservisible || $module->is_stealth() || empty($module->url)) {
816
                continue;
817
            }
818
            $mods[$module->id] = $module;
819
            // No need to add the current module to the list for the activity dropdown menu.
820
            if ($module->id == $this->page->cm->id) {
821
                continue;
822
            }
823
            // Module name.
824
            $modname = $module->get_formatted_name();
825
            // Display the hidden text if necessary.
826
            if (!$module->visible) {
827
                $modname .= ' ' . get_string('hiddenwithbrackets');
828
            }
829
            // Module URL.
830
            $linkurl = new moodle_url($module->url, array('forceview' => 1));
831
            // Add module URL (as key) and name (as value) to the activity list array.
832
            $activitylist[$linkurl->out(false)] = $modname;
833
        }
834
        $nummods = count($mods);
835
        // If there is only one mod then do nothing.
836
        if ($nummods == 1) {
837
            return '';
838
        }
839
        // Get an array of just the course module ids used to get the cmid value based on their position in the course.
840
        $modids = array_keys($mods);
841
        // Get the position in the array of the course module we are viewing.
842
        $position = array_search($this->page->cm->id, $modids);
843
        $prevmod = null;
844
        $nextmod = null;
845
        // Check if we have a previous mod to show.
846
        if ($position > 0) {
847
            $prevmod = $mods[$modids[$position - 1]];
848
        }
849
        // Check if we have a next mod to show.
850
        if ($position < ($nummods - 1)) {
851
            $nextmod = $mods[$modids[$position + 1]];
852
        }
853
        $activitynav = new \core_course\output\activity_navigation($prevmod, $nextmod, $activitylist);
854
        $renderer = $this->page->get_renderer('core', 'course');
855
        return $renderer->render($activitynav);
856
    }
857
 
858
 
859
    /**
860
     * This is an optional menu that can be added to a layout by a theme. It contains the
861
     * menu for the course administration, only on the course main page.
862
     *
863
     * @return string
864
     */
161 ariadna 865
    public function context_header_settings_menu()
866
    {
1 efrain 867
        $context = $this->page->context;
868
        $menu = new action_menu();
869
 
870
        $items = $this->page->navbar->get_items();
871
        $currentnode = end($items);
872
 
873
        $showcoursemenu = false;
874
        $showfrontpagemenu = false;
875
        $showusermenu = false;
876
 
877
        // We are on the course home page.
878
        if (($context->contextlevel == CONTEXT_COURSE) &&
879
            !empty($currentnode) &&
880
            ($currentnode->type == navigation_node::TYPE_COURSE || $currentnode->type == navigation_node::TYPE_SECTION)
881
        ) {
882
            $showcoursemenu = true;
883
        }
884
 
885
        $courseformat = course_get_format($this->page->course);
886
        // This is a single activity course format, always show the course menu on the activity main page.
887
        if (
888
            $context->contextlevel == CONTEXT_MODULE &&
889
            !$courseformat->has_view_page()
890
        ) {
891
 
892
            $this->page->navigation->initialise();
893
            $activenode = $this->page->navigation->find_active_node();
894
            // If the settings menu has been forced then show the menu.
895
            if ($this->page->is_settings_menu_forced()) {
896
                $showcoursemenu = true;
897
            } else if (!empty($activenode) && ($activenode->type == navigation_node::TYPE_ACTIVITY ||
898
                $activenode->type == navigation_node::TYPE_RESOURCE)) {
899
 
900
                // We only want to show the menu on the first page of the activity. This means
901
                // the breadcrumb has no additional nodes.
902
                if ($currentnode && ($currentnode->key == $activenode->key && $currentnode->type == $activenode->type)) {
903
                    $showcoursemenu = true;
904
                }
905
            }
906
        }
907
 
908
        // This is the site front page.
909
        if (
910
            $context->contextlevel == CONTEXT_COURSE &&
911
            !empty($currentnode) &&
912
            $currentnode->key === 'home'
913
        ) {
914
            $showfrontpagemenu = true;
915
        }
916
 
917
        // This is the user profile page.
918
        if (
919
            $context->contextlevel == CONTEXT_USER &&
920
            !empty($currentnode) &&
921
            ($currentnode->key === 'myprofile')
922
        ) {
923
            $showusermenu = true;
924
        }
925
 
926
        if ($showfrontpagemenu) {
927
            $settingsnode = $this->page->settingsnav->find('frontpage', navigation_node::TYPE_SETTING);
928
            if ($settingsnode) {
929
                // Build an action menu based on the visible nodes from this navigation tree.
930
                $skipped = $this->build_action_menu_from_navigation($menu, $settingsnode, false, true);
931
 
932
                // We only add a list to the full settings menu if we didn't include every node in the short menu.
933
                if ($skipped) {
934
                    $text = get_string('morenavigationlinks');
935
                    $url = new moodle_url('/course/admin.php', array('courseid' => $this->page->course->id));
936
                    $link = new action_link($url, $text, null, null, new pix_icon('t/edit', $text));
937
                    $menu->add_secondary_action($link);
938
                }
939
            }
940
        } else if ($showcoursemenu) {
941
            $settingsnode = $this->page->settingsnav->find('courseadmin', navigation_node::TYPE_COURSE);
942
            if ($settingsnode) {
943
                // Build an action menu based on the visible nodes from this navigation tree.
944
                $skipped = $this->build_action_menu_from_navigation($menu, $settingsnode, false, true);
945
 
946
                // We only add a list to the full settings menu if we didn't include every node in the short menu.
947
                if ($skipped) {
948
                    $text = get_string('morenavigationlinks');
949
                    $url = new moodle_url('/course/admin.php', array('courseid' => $this->page->course->id));
950
                    $link = new action_link($url, $text, null, null, new pix_icon('t/edit', $text));
951
                    $menu->add_secondary_action($link);
952
                }
953
            }
954
        } else if ($showusermenu) {
955
            // Get the course admin node from the settings navigation.
956
            $settingsnode = $this->page->settingsnav->find('useraccount', navigation_node::TYPE_CONTAINER);
957
            if ($settingsnode) {
958
                // Build an action menu based on the visible nodes from this navigation tree.
959
                $this->build_action_menu_from_navigation($menu, $settingsnode);
960
            }
961
        }
962
 
963
        return $this->render($menu);
964
    }
965
 
161 ariadna 966
    public function customeditblockbtn()
967
    {
1 efrain 968
        $header = new stdClass();
969
        $header->settingsmenu = $this->context_header_settings_menu();
970
        $header->pageheadingbutton = $this->page_heading_button();
971
 
972
        $html = $this->render_from_template('theme_universe/header_settings_menu', $header);
973
 
974
        return $html;
975
    }
976
 
977
    /**
978
     * Renders the context header for the page.
979
     *
980
     * @param array $headerinfo Heading information.
981
     * @param int $headinglevel What 'h' level to make the heading.
982
     * @return string A rendered context header.
983
     */
161 ariadna 984
    public function context_header($headerinfo = null, $headinglevel = 1): string
985
    {
1 efrain 986
        global $DB, $USER, $CFG, $SITE;
987
        require_once($CFG->dirroot . '/user/lib.php');
988
        $context = $this->page->context;
989
        $heading = null;
990
        $imagedata = null;
991
        $subheader = null;
992
        $userbuttons = null;
993
 
994
        // Make sure to use the heading if it has been set.
995
        if (isset($headerinfo['heading'])) {
996
            $heading = $headerinfo['heading'];
997
        } else {
998
            $heading = $this->page->heading;
999
        }
1000
 
1001
        // The user context currently has images and buttons. Other contexts may follow.
1002
        if ((isset($headerinfo['user']) || $context->contextlevel == CONTEXT_USER) && $this->page->pagetype !== 'my-index') {
1003
            if (isset($headerinfo['user'])) {
1004
                $user = $headerinfo['user'];
1005
            } else {
1006
                // Look up the user information if it is not supplied.
1007
                $user = $DB->get_record('user', array('id' => $context->instanceid));
1008
            }
1009
 
1010
            // If the user context is set, then use that for capability checks.
1011
            if (isset($headerinfo['usercontext'])) {
1012
                $context = $headerinfo['usercontext'];
1013
            }
1014
 
1015
            // Only provide user information if the user is the current user, or a user which the current user can view.
1016
            // When checking user_can_view_profile(), either:
1017
            // If the page context is course, check the course context (from the page object) or;
1018
            // If page context is NOT course, then check across all courses.
1019
            $course = ($this->page->context->contextlevel == CONTEXT_COURSE) ? $this->page->course : null;
1020
 
1021
            if (user_can_view_profile($user, $course)) {
1022
                // Use the user's full name if the heading isn't set.
1023
                if (empty($heading)) {
1024
                    $heading = fullname($user);
1025
                }
1026
 
1027
                $imagedata = $this->user_picture($user, array('size' => 100));
1028
 
1029
                // Check to see if we should be displaying a message button.
1030
                if (!empty($CFG->messaging) && has_capability('moodle/site:sendmessage', $context)) {
1031
                    $userbuttons = array(
1032
                        'messages' => array(
1033
                            'buttontype' => 'message',
1034
                            'title' => get_string('message', 'message'),
1035
                            'url' => new moodle_url('/message/index.php', array('id' => $user->id)),
1036
                            'image' => 'message',
1037
                            'linkattributes' => \core_message\helper::messageuser_link_params($user->id),
1038
                            'page' => $this->page
1039
                        )
1040
                    );
1041
 
1042
                    if ($USER->id != $user->id) {
1043
                        $iscontact = \core_message\api::is_contact($USER->id, $user->id);
1044
                        $contacttitle = $iscontact ? 'removefromyourcontacts' : 'addtoyourcontacts';
1045
                        $contacturlaction = $iscontact ? 'removecontact' : 'addcontact';
1046
                        $contactimage = $iscontact ? 'removecontact' : 'addcontact';
1047
                        $userbuttons['togglecontact'] = array(
1048
                            'buttontype' => 'togglecontact',
1049
                            'title' => get_string($contacttitle, 'message'),
1050
                            'url' => new moodle_url(
1051
                                '/message/index.php',
1052
                                array(
1053
                                    'user1' => $USER->id,
1054
                                    'user2' => $user->id,
1055
                                    $contacturlaction => $user->id,
1056
                                    'sesskey' => sesskey()
1057
                                )
1058
                            ),
1059
                            'image' => $contactimage,
1060
                            'linkattributes' => \core_message\helper::togglecontact_link_params($user, $iscontact),
1061
                            'page' => $this->page
1062
                        );
1063
                    }
1064
 
1065
                    $this->page->requires->string_for_js('changesmadereallygoaway', 'moodle');
1066
                }
1067
            } else {
1068
                $heading = null;
1069
            }
1070
        }
1071
 
1072
        $prefix = null;
1073
        if ($context->contextlevel == CONTEXT_MODULE) {
1074
            if ($this->page->course->format === 'singleactivity') {
1075
                $heading = $this->page->course->fullname;
1076
            } else {
1077
                $heading = $this->page->cm->get_formatted_name();
1078
                $imagedata = $this->pix_icon('monologo', '', $this->page->activityname, ['class' => 'activityicon']);
1079
                $purposeclass = plugin_supports('mod', $this->page->activityname, FEATURE_MOD_PURPOSE);
1080
                $purposeclass .= ' activityiconcontainer';
1081
                $purposeclass .= ' modicon_' . $this->page->activityname;
1082
                $imagedata = html_writer::tag('div', $imagedata, ['class' => $purposeclass]);
1083
                $prefix = get_string('modulename', $this->page->activityname);
1084
            }
1085
        }
1086
 
1087
        $contextheader = new \context_header($heading, $headinglevel, $imagedata, $userbuttons, $prefix);
1088
        return $this->render_context_header($contextheader);
1089
    }
1090
 
1091
 
1092
    /**
1093
     * Construct a user menu, returning HTML that can be echoed out by a
1094
     * layout file.
1095
     *
1096
     * @param stdClass $user A user object, usually $USER.
1097
     * @param bool $withlinks true if a dropdown should be built.
1098
     * @return string HTML fragment.
1099
     */
161 ariadna 1100
    public function user_menu($user = null, $withlinks = null)
1101
    {
1 efrain 1102
        global $USER, $CFG;
1103
        require_once($CFG->dirroot . '/user/lib.php');
1104
 
1105
        if (is_null($user)) {
1106
            $user = $USER;
1107
        }
1108
 
1109
        // Note: this behaviour is intended to match that of core_renderer::login_info,
1110
        // but should not be considered to be good practice; layout options are
1111
        // intended to be theme-specific. Please don't copy this snippet anywhere else.
1112
        if (is_null($withlinks)) {
1113
            $withlinks = empty($this->page->layout_options['nologinlinks']);
1114
        }
1115
 
1116
        // Add a class for when $withlinks is false.
1117
        $usermenuclasses = 'usermenu';
1118
        if (!$withlinks) {
1119
            $usermenuclasses .= ' withoutlinks';
1120
        }
1121
 
1122
        $returnstr = "";
1123
 
1124
        // If during initial install, return the empty return string.
1125
        if (during_initial_install()) {
1126
            return $returnstr;
1127
        }
1128
 
1129
        $loginpage = $this->is_login_page();
1130
        $loginurl = get_login_url();
1131
        // If not logged in, show the typical not-logged-in string.
1132
        if (!isloggedin()) {
1133
            if (!$loginpage) {
1134
                $returnstr .= "<a class=\"rui-topbar-btn rui-login-btn\" href=\"$loginurl\"><span class=\"rui-login-btn-txt\">" .
1135
                    get_string('login') .
1136
                    '</span>
1137
                <svg class="ml-2" width="20" height="20" fill="none" viewBox="0 0 24 24">
1138
                <path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
1139
                d="M9.75 8.75L13.25 12L9.75 15.25"></path>
1140
                <path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
1141
                d="M9.75 4.75H17.25C18.3546 4.75 19.25 5.64543 19.25 6.75V17.25C19.25 18.3546 18.3546 19.25 17.25 19.25H9.75">
1142
                </path>
1143
                <path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 12H4.75"></path>
1144
                </svg></a>';
1145
            }
1146
            return html_writer::div(
1147
                html_writer::span(
1148
                    $returnstr,
1149
                    'login'
1150
                ),
1151
                $usermenuclasses
1152
            );
1153
        }
1154
 
1155
        // If logged in as a guest user, show a string to that effect.
1156
        if (isguestuser()) {
1157
            $icon = '<svg class="mr-2"
1158
                width="24"
1159
                height="24"
1160
                viewBox="0 0 24 24"
1161
                fill="none"
1162
                xmlns="http://www.w3.org/2000/svg">
1163
            <path d="M10 12C10 12.5523 9.55228 13 9 13C8.44772 13 8 12.5523 8
1164
            12C8 11.4477 8.44772 11 9 11C9.55228 11 10 11.4477 10 12Z"
1165
                fill="currentColor"
1166
                />
1167
            <path d="M15 13C15.5523 13 16 12.5523 16 12C16 11.4477 15.5523 11
1168
            15 11C14.4477 11 14 11.4477 14 12C14 12.5523 14.4477 13 15 13Z"
1169
                fill="currentColor"
1170
                />
1171
            <path fill-rule="evenodd"
1172
                clip-rule="evenodd"
1173
                d="M12.0244 2.00003L12 2C6.47715 2 2 6.47715 2 12C2 17.5228
1174
                6.47715 22 12 22C17.5228 22 22 17.5228 22 12C22 6.74235
1175
            17.9425 2.43237 12.788 2.03059L12.7886 2.0282C12.5329 2.00891
1176
            12.278 1.99961 12.0244 2.00003ZM12 20C16.4183 20 20 16.4183 20
1177
            12C20 11.3014 19.9105 10.6237 19.7422
1178
            9.97775C16.1597 10.2313 12.7359 8.52461 10.7605 5.60246C9.31322
1179
            7.07886 7.2982 7.99666 5.06879 8.00253C4.38902 9.17866 4 10.5439 4
1180
            12C4 16.4183 7.58172 20
1181
            12 20ZM11.9785 4.00003L12.0236 4.00003L12 4L11.9785 4.00003Z"
1182
                fill="currentColor"
1183
                /></svg>';
1184
            $returnstr = '<div class="rui-badge-guest">' . $icon . get_string('loggedinasguest') . '</div>';
1185
            if (!$loginpage && $withlinks) {
1186
                $returnstr .= "<a class=\"rui-topbar-btn rui-login-btn\"
1187
                    href=\"$loginurl\"><span class=\"rui-login-btn-txt\">" .
1188
                    get_string('login') .
1189
                    '</span>
1190
                <svg class="ml-2"
1191
                    width="20"
1192
                    height="20"
1193
                    fill="none"
1194
                    viewBox="0 0 24 24">
1195
                <path stroke="currentColor"
1196
                    stroke-linecap="round"
1197
                    stroke-linejoin="round"
1198
                    stroke-width="2"
1199
                    d="M9.75 8.75L13.25 12L9.75 15.25"></path>
1200
                <path stroke="currentColor"
1201
                    stroke-linecap="round"
1202
                    stroke-linejoin="round"
1203
                    stroke-width="2"
1204
                    d="M9.75 4.75H17.25C18.3546 4.75 19.25 5.64543 19.25
1205
                    6.75V17.25C19.25 18.3546 18.3546 19.25 17.25 19.25H9.75"></path>
1206
                    <path stroke="currentColor"
1207
                        stroke-linecap="round"
1208
                        stroke-linejoin="round"
1209
                        stroke-width="2"
1210
                        d="M13 12H4.75"></path></svg></a>';
1211
            }
1212
 
1213
            return html_writer::div(
1214
                html_writer::span(
1215
                    $returnstr,
1216
                    'login'
1217
                ),
1218
                $usermenuclasses
1219
            );
1220
        }
1221
 
1222
        // Get some navigation opts.
1223
        $opts = user_get_user_navigation_info($user, $this->page, array('avatarsize' => 56));
1224
 
1225
        $avatarclasses = "avatars";
1226
        $avatarcontents = html_writer::span($opts->metadata['useravatar'], 'avatar current');
1227
        $usertextcontents = '<span class="rui-fullname">' . $opts->metadata['userfullname'] . '</span>';
1228
        $usertextmail = $user->email;
1229
        $usernick = '<svg class="mr-1"
1230
            width="16"
1231
            height="16"
1232
            fill="none"
1233
            viewBox="0 0 24 24">
1234
        <path stroke="currentColor"
1235
            stroke-linecap="round"
1236
            stroke-linejoin="round"
1237
            stroke-width="2"
1238
            d="M12 13V15"></path>
1239
        <circle cx="12"
1240
            cy="9"
1241
            r="1"
1242
            fill="currentColor"></circle>
1243
        <circle cx="12"
1244
            cy="12"
1245
            r="7.25"
1246
            stroke="currentColor"
1247
            stroke-linecap="round"
1248
            stroke-linejoin="round"
1249
            stroke-width="1.5"></circle>
1250
        </svg>' . $user->username;
1251
 
1252
        // Other user.
1253
        $usermeta = '';
1254
        if (!empty($opts->metadata['asotheruser'])) {
1255
            $avatarcontents .= html_writer::span(
1256
                $opts->metadata['realuseravatar'],
1257
                'avatar realuser'
1258
            );
1259
            $usermeta .= $opts->metadata['realuserfullname'];
1260
            $usermeta .= html_writer::tag(
1261
                'span',
1262
                get_string(
1263
                    'loggedinas',
1264
                    'moodle',
1265
                    html_writer::span(
1266
                        $opts->metadata['userfullname'],
1267
                        'value'
1268
                    )
1269
                ),
1270
                array('class' => 'meta viewingas')
1271
            );
1272
        }
1273
 
1274
        // Role.
1275
        if (!empty($opts->metadata['asotherrole'])) {
1276
            $role = core_text::strtolower(preg_replace('#[ ]+#', '-', trim($opts->metadata['rolename'])));
1277
            $usermeta .= html_writer::span(
1278
                $opts->metadata['rolename'],
1279
                'meta role role-' . $role
1280
            );
1281
        }
1282
 
1283
        // User login failures.
1284
        if (!empty($opts->metadata['userloginfail'])) {
1285
            $usermeta .= html_writer::div(
1286
                '<svg class="mr-1"
1287
                width="16"
1288
                height="16"
1289
                fill="none"
1290
                viewBox="0 0 24 24"><path stroke="currentColor"
1291
                stroke-linecap="round"
1292
                stroke-linejoin="round"
1293
                stroke-width="1.5"
1294
                d="M4.9522 16.3536L10.2152 5.85658C10.9531 4.38481 13.0539
1295
                4.3852 13.7913 5.85723L19.0495 16.3543C19.7156 17.6841 18.7487
1296
                19.25 17.2613 19.25H6.74007C5.25234
1297
                19.25 4.2854 17.6835 4.9522 16.3536Z">
1298
                </path><path stroke="currentColor"
1299
                stroke-linecap="round"
1300
                stroke-linejoin="round"
1301
                stroke-width="2"
1302
                d="M12 10V12"></path>
1303
                <circle cx="12" cy="16" r="1" fill="currentColor"></circle></svg>' .
1304
                    $opts->metadata['userloginfail'],
1305
                'meta loginfailures'
1306
            );
1307
        }
1308
 
1309
        // MNet.
1310
        if (!empty($opts->metadata['asmnetuser'])) {
1311
            $mnet = strtolower(preg_replace('#[ ]+#', '-', trim($opts->metadata['mnetidprovidername'])));
1312
            $usermeta .= html_writer::span(
1313
                $opts->metadata['mnetidprovidername'],
1314
                'meta mnet mnet-' . $mnet
1315
            );
1316
        }
1317
 
1318
        $returnstr .= html_writer::span(
1319
            html_writer::span($avatarcontents, $avatarclasses),
1320
            'userbutton'
1321
        );
1322
 
1323
        // Create a divider (well, a filler).
1324
        $divider = new action_menu_filler();
1325
        $divider->primary = false;
1326
 
1327
        $am = new action_menu();
1328
        $am->set_menu_trigger(
1329
            $returnstr
1330
        );
1331
        $am->set_action_label(get_string('usermenu'));
1332
        $am->set_nowrap_on_items();
1333
 
1334
        if ($CFG->enabledashboard) {
1335
            $dashboardlink = '<div class="dropdown-item-wrapper"><a class="dropdown-item" href="' .
1336
                new moodle_url('/my/') .
1337
                '" data-identifier="dashboard,moodle" title="dashboard,moodle">' .
1338
                get_string('myhome', 'moodle') .
1339
                '</a></div>';
1340
        } else {
1341
            $dashboardlink = null;
1342
        }
1343
 
1344
        $am->add(
1345
            '<div class="dropdown-user-wrapper"><div class="dropdown-user">' . $usertextcontents  . '</div>'
1346
                . '<div class="dropdown-user-mail text-truncate" title="' . $usertextmail . '">' . $usertextmail . '</div>'
1347
                . '<span class="dropdown-user-nick w-100">' . $usernick . '</span>'
1348
                . '<div class="dropdown-user-meta"><span class="badge-xs badge-sq badge-warning flex-wrap">' .
1349
                $usermeta . '</span></div>'
1350
                . '</div><div class="dropdown-divider dropdown-divider-user"></div>' . $dashboardlink
1351
        );
1352
 
1353
        if ($withlinks) {
1354
            $navitemcount = count($opts->navitems);
1355
            $idx = 0;
1356
            foreach ($opts->navitems as $key => $value) {
1357
 
1358
                switch ($value->itemtype) {
1359
                    case 'divider':
1360
                        // If the nav item is a divider, add one and skip link processing.
1361
                        $am->add($divider);
1362
                        break;
1363
 
1364
                    case 'invalid':
1365
                        // Silently skip invalid entries (should we post a notification?).
1366
                        break;
1367
 
1368
                    case 'link':
1369
                        $al = '<a class="dropdown-item" href="' .
1370
                            $value->url .
1371
                            '" data-identifier="' .
1372
                            $value->titleidentifier .
1373
                            '" title="' .
1374
                            $value->titleidentifier .
1375
                            '">' .
1376
                            $value->title . '</a>';
1377
                        $am->add($al);
1378
                        break;
1379
                }
1380
 
1381
                $idx++;
1382
 
1383
                // Add dividers after the first item and before the last item.
1384
                if ($idx == 1 || $idx == $navitemcount - 1) {
1385
                    $am->add($divider);
1386
                }
1387
            }
1388
        }
1389
 
1390
        return html_writer::div(
1391
            $this->render($am),
1392
            $usermenuclasses
1393
        );
1394
    }
1395
 
1396
 
1397
    /**
1398
     * Returns standard main content placeholder.
1399
     * Designed to be called in theme layout.php files.
1400
     *
1401
     * @return string HTML fragment.
1402
     */
161 ariadna 1403
    public function main_content()
1404
    {
1 efrain 1405
        // This is here because it is the only place we can inject the "main" role over the entire main content area
1406
        // without requiring all theme's to manually do it, and without creating yet another thing people need to
1407
        // remember in the theme.
1408
        // This is an unfortunate hack. DO NO EVER add anything more here.
1409
        // DO NOT add classes.
1410
        // DO NOT add an id.
1411
        return '<div class="main-content" role="main">' . $this->unique_main_content_token . '</div>';
1412
    }
1413
 
1414
    /**
1415
     * Outputs a heading
1416
     *
1417
     * @param string $text The text of the heading
1418
     * @param int $level The level of importance of the heading. Defaulting to 2
1419
     * @param string $classes A space-separated list of CSS classes. Defaulting to null
1420
     * @param string $id An optional ID
1421
     * @return string the HTML to output.
1422
     */
161 ariadna 1423
    public function heading($text, $level = 2, $classes = null, $id = null)
1424
    {
1 efrain 1425
        $level = (int) $level;
1426
        if ($level < 1 || $level > 6) {
1427
            throw new coding_exception('Heading level must be an integer between 1 and 6.');
1428
        }
1429
        return html_writer::tag('div', html_writer::tag('h' .
1430
            $level, $text, array('id' => $id, 'class' => renderer_base::prepare_classes($classes) .
1431
            ' rui-main-content-title rui-main-content-title--h' .
1432
            $level)), array('class' => 'rui-title-container'));
1433
    }
1434
 
1435
 
161 ariadna 1436
    public function headingwithavatar($text, $level = 2, $classes = null, $id = null)
1437
    {
1 efrain 1438
        $level = (int) $level;
1439
        if ($level < 1 || $level > 6) {
1440
            throw new coding_exception('Heading level must be an integer between 1 and 6.');
1441
        }
1442
        return html_writer::tag('div', html_writer::tag('h' .
1443
            $level, $text, array('id' => $id, 'class' => renderer_base::prepare_classes($classes) .
1444
            ' rui-main-content-title-with-avatar')), array('class' => 'rui-title-container-with-avatar'));
1445
    }
1446
 
1447
    /**
1448
     * Renders the login form.
1449
     *
1450
     * @param \core_auth\output\login $form The renderable.
1451
     * @return string
1452
     */
161 ariadna 1453
    public function render_login(\core_auth\output\login $form)
1454
    {
1 efrain 1455
        global $CFG, $SITE;
1456
 
1457
        $context = $form->export_for_template($this);
1458
 
1459
        // Override because rendering is not supported in template yet.
1460
        if ($CFG->rememberusername == 0) {
1461
            $context->cookieshelpiconformatted = $this->help_icon('cookiesenabledonlysession');
1462
        } else {
1463
            $context->cookieshelpiconformatted = $this->help_icon('cookiesenabled');
1464
        }
1465
        $context->errorformatted = $this->error_text($context->error);
1466
        $url = $this->get_logo_url();
1467
        if ($url) {
1468
            $url = $url->out(false);
1469
        }
1470
        $context->logourl = $url;
1471
        $context->sitename = format_string(
1472
            $SITE->fullname,
1473
            true,
1474
            ['context' => context_course::instance(SITEID), "escape" => false]
1475
        );
1476
 
1477
        if ($this->page->theme->settings->setloginlayout == 1) {
1478
            $context->loginlayout1 = 1;
1479
        } else if ($this->page->theme->settings->setloginlayout == 2) {
1480
            $context->loginlayout2 = 1;
1481
            if (isset($this->page->theme->settings->loginbg)) {
1482
                $context->loginlayoutimg = 1;
1483
            }
1484
        } else if ($this->page->theme->settings->setloginlayout == 3) {
1485
            $context->loginlayout3 = 1;
1486
            if (isset($this->page->theme->settings->loginbg)) {
1487
                $context->loginlayoutimg = 1;
1488
            }
1489
        } else if ($this->page->theme->settings->setloginlayout == 4) {
1490
            $context->loginlayout4 = 1;
1491
        } else if ($this->page->theme->settings->setloginlayout == 5) {
1492
            $context->loginlayout5 = 1;
1493
        }
1494
 
1495
        if (isset($this->page->theme->settings->loginlogooutside)) {
1496
            $context->loginlogooutside = $this->page->theme->settings->loginlogooutside;
1497
        }
1498
 
1499
        if (isset($this->page->theme->settings->customsignupoutside)) {
1500
            $context->customsignupoutside = $this->page->theme->settings->customsignupoutside;
1501
        }
1502
 
1503
        if (isset($this->page->theme->settings->loginidprovtop)) {
1504
            $context->loginidprovtop = $this->page->theme->settings->loginidprovtop;
1505
        }
1506
 
1507
        if (isset($this->page->theme->settings->stringca)) {
1508
            $context->stringca = format_text(($this->page->theme->settings->stringca),
1509
                FORMAT_HTML,
1510
                array('noclean' => true)
1511
            );
1512
        }
1513
 
1514
        if (isset($this->page->theme->settings->stringca)) {
1515
            $context->stringca = format_text(($this->page->theme->settings->stringca),
1516
                FORMAT_HTML,
1517
                array('noclean' => true)
1518
            );
1519
        }
1520
 
1521
        if (isset($this->page->theme->settings->loginhtmlcontent1)) {
1522
            $context->loginhtmlcontent1 = format_text(($this->page->theme->settings->loginhtmlcontent1),
1523
                FORMAT_HTML,
1524
                array('noclean' => true)
1525
            );
1526
        }
1527
 
1528
        if (isset($this->page->theme->settings->loginhtmlcontent2)) {
1529
            $context->loginhtmlcontent2 = format_text(($this->page->theme->settings->loginhtmlcontent2),
1530
                FORMAT_HTML,
1531
                array('noclean' => true)
1532
            );
1533
        }
1534
 
1535
        if (isset($this->page->theme->settings->loginhtmlcontent3)) {
1536
            $context->loginhtmlcontent3 = format_text(($this->page->theme->settings->loginhtmlcontent3),
1537
                FORMAT_HTML,
1538
                array('noclean' => true)
1539
            );
1540
        }
1541
 
1542
        if (isset($this->page->theme->settings->loginhtmlcontent2)) {
1543
            $context->loginhtmlcontent2 = format_text(($this->page->theme->settings->loginhtmlcontent2),
1544
                FORMAT_HTML,
1545
                array('noclean' => true)
1546
            );
1547
        }
1548
 
1549
        if (isset($this->page->theme->settings->logincustomfooterhtml)) {
1550
            $context->logincustomfooterhtml = format_text(($this->page->theme->settings->logincustomfooterhtml),
1551
                FORMAT_HTML,
1552
                array('noclean' => true)
1553
            );
1554
        }
1555
 
1556
        if (isset($this->page->theme->settings->loginhtmlblockbottom)) {
1557
            $context->loginhtmlblockbottom = format_text(($this->page->theme->settings->loginhtmlblockbottom),
1558
                FORMAT_HTML,
1559
                array('noclean' => true)
1560
            );
1561
        }
1562
 
1563
        if (isset($this->page->theme->settings->loginfootercontent)) {
1564
            $context->loginfootercontent = format_text(($this->page->theme->settings->loginfootercontent),
1565
                FORMAT_HTML,
1566
                array('noclean' => true)
1567
            );
1568
        }
1569
 
1570
        if (isset($this->page->theme->settings->footercopy)) {
1571
            $context->footercopy = format_text(($this->page->theme->settings->footercopy),
1572
                FORMAT_HTML,
1573
                array('noclean' => true)
1574
            );
1575
        }
1576
 
1577
        if (isset($this->page->theme->settings->loginintrotext)) {
1578
            $context->loginintrotext = format_text(($this->page->theme->settings->loginintrotext),
1579
                FORMAT_HTML,
1580
                array('noclean' => true)
1581
            );
1582
        }
1583
 
1584
        if (isset($this->page->theme->settings->loginintrotext)) {
1585
            $context->loginintrotext = format_text(($this->page->theme->settings->loginintrotext),
1586
                FORMAT_HTML,
1587
                array('noclean' => true)
1588
            );
1589
        }
1590
 
1591
        if (isset($this->page->theme->settings->customloginlogo)) {
1592
            $context->customloginlogo = $this->page->theme->setting_file_url('customloginlogo', 'customloginlogo');
1593
        }
1594
 
1595
        if (isset($this->page->theme->settings->loginbg)) {
1596
            $context->loginbg = $this->page->theme->setting_file_url('loginbg', 'loginbg');
1597
        }
1598
 
1599
        if (isset($this->page->theme->settings->hideforgotpassword)) {
1600
            $context->hideforgotpassword = $this->page->theme->settings->hideforgotpassword == 1;
1601
        }
1602
 
1603
        if (isset($this->page->theme->settings->logininfobox)) {
1604
            $context->logininfobox = format_text(($this->page->theme->settings->logininfobox),
1605
                FORMAT_HTML,
1606
                array('noclean' => true)
1607
            );
1608
        }
1609
 
1610
        return $this->render_from_template('core/loginform', $context);
1611
    }
1612
 
1613
    /**
1614
     * Render the login signup form into a nice template for the theme.
1615
     *
1616
     * @param mform $form
1617
     * @return string
1618
     */
161 ariadna 1619
    public function render_login_signup_form($form)
1620
    {
1 efrain 1621
        global $SITE;
1622
 
1623
        $context = $form->export_for_template($this);
1624
        $url = $this->get_logo_url();
1625
        if ($url) {
1626
            $url = $url->out(false);
1627
        }
1628
        $context['logourl'] = $url;
1629
        $context['sitename'] = format_string(
1630
            $SITE->fullname,
1631
            true,
1632
            ['context' => context_course::instance(SITEID), "escape" => false]
1633
        );
1634
 
1635
        if ($this->page->theme->settings->setloginlayout == 1) {
1636
            $context['loginlayout1'] = 1;
1637
        } else if ($this->page->theme->settings->setloginlayout == 2) {
1638
            $context['loginlayout2'] = 1;
1639
            if (isset($this->page->theme->settings->loginbg)) {
1640
                $context['loginlayoutimg'] = 1;
1641
            }
1642
        } else if ($this->page->theme->settings->setloginlayout == 3) {
1643
            $context['loginlayout3'] = 1;
1644
            if (isset($this->page->theme->settings->loginbg)) {
1645
                $context['loginlayoutimg'] = 1;
1646
            }
1647
        } else if ($this->page->theme->settings->setloginlayout == 4) {
1648
            $context['loginlayout4'] = 1;
1649
        } else if ($this->page->theme->settings->setloginlayout == 5) {
1650
            $context['loginlayout5'] = 1;
1651
        }
1652
 
1653
        if (isset($this->page->theme->settings->loginlogooutside)) {
1654
            $context['loginlogooutside'] = $this->page->theme->settings->loginlogooutside;
1655
        }
1656
 
1657
        if (isset($this->page->theme->settings->stringbacktologin)) {
1658
            $context['stringbacktologin'] = format_text(($this->page->theme->settings->stringbacktologin),
1659
                FORMAT_HTML,
1660
                array('noclean' => true)
1661
            );
1662
        }
1663
        if (isset($this->page->theme->settings->signupintrotext)) {
1664
            $context['signupintrotext'] = format_text(($this->page->theme->settings->signupintrotext),
1665
                FORMAT_HTML,
1666
                array('noclean' => true)
1667
            );
1668
        }
1669
        if (isset($this->page->theme->settings->signuptext)) {
1670
            $context['signuptext'] = format_text(($this->page->theme->settings->signuptext),
1671
                FORMAT_HTML,
1672
                array('noclean' => true)
1673
            );
1674
        }
1675
 
1676
        if (!empty($this->page->theme->settings->customloginlogo)) {
1677
            $url = $this->page->theme->setting_file_url('customloginlogo', 'customloginlogo');
1678
            $context['customloginlogo'] = $url;
1679
        }
1680
 
1681
        if (!empty($this->page->theme->settings->loginbg)) {
1682
            $url = $this->page->theme->setting_file_url('loginbg', 'loginbg');
1683
            $context['loginbg'] = $url;
1684
        }
1685
 
1686
        if (isset($this->page->theme->settings->loginfootercontent)) {
1687
            $context['loginfootercontent'] = format_text(($this->page->theme->settings->loginfootercontent),
1688
                FORMAT_HTML,
1689
                array('noclean' => true)
1690
            );
1691
        }
1692
 
1693
        return $this->render_from_template('core/signup_form_layout', $context);
1694
    }
1695
 
1696
 
1697
    /**
1698
     * Renders the header bar.
1699
     *
1700
     * @param context_header $contextheader Header bar object.
1701
     * @return string HTML for the header bar.
1702
     */
161 ariadna 1703
    protected function render_context_header(\context_header $contextheader)
1704
    {
1 efrain 1705
        $heading = null;
1706
        $imagedata = null;
1707
        $html = null;
1708
 
1709
        // Generate the heading first and before everything else as we might have to do an early return.
1710
        if (!isset($contextheader->heading)) {
1711
            $heading = $this->heading($this->page->heading, $contextheader->headinglevel);
1712
        } else {
1713
            $heading = $this->heading($contextheader->heading, $contextheader->headinglevel);
1714
        }
1715
 
1716
        // All the html stuff goes here.
1717
        $html = html_writer::start_div('page-context-header d-flex align-items-center flex-wrap');
1718
 
1719
        // Image data.
1720
        if (isset($contextheader->imagedata)) {
1721
            // Header specific image.
1722
            $html .= html_writer::div($contextheader->imagedata, 'page-header-image');
1723
        }
1724
 
1725
        // Headings.
1726
        if (isset($contextheader->prefix)) {
1727
            $prefix = html_writer::div($contextheader->prefix, 'text-muted text-uppercase small line-height-3');
1728
            $heading = $prefix . $heading;
1729
        }
1730
 
1731
        if (!isset($contextheader->heading)) {
1732
            $html .= html_writer::tag('h3', $heading, array('class' => 'rui-page-title rui-page-title--page'));
1733
        } else if (isset($contextheader->imagedata)) {
1734
            $html .= html_writer::tag(
1735
                'div',
1736
                $this->heading($contextheader->heading, 4),
1737
                array('class' => 'rui-page-title rui-page-title--icon')
1738
            );
1739
        } else {
1740
            $html .= html_writer::tag('h2', $heading, array('class' => 'page-header-headings
1741
                rui-page-title rui-page-title--context'));
1742
        }
1743
 
1744
        // Buttons.
1745
        if (isset($contextheader->additionalbuttons)) {
1746
            $html .= html_writer::start_div('btn-group header-button-group my-2 my-lg-0 ml-lg-4');
1747
            foreach ($contextheader->additionalbuttons as $button) {
1748
                if (!isset($button->page)) {
1749
                    // Include js for messaging.
1750
                    if ($button['buttontype'] === 'togglecontact') {
1751
                        \core_message\helper::togglecontact_requirejs();
1752
                    }
1753
                    if ($button['buttontype'] === 'message') {
1754
                        \core_message\helper::messageuser_requirejs();
1755
                    }
1756
                    $image = $this->pix_icon($button['formattedimage'], $button['title'], 'moodle', array(
1757
                        'class' => 'iconsmall',
1758
                        'role' => 'presentation'
1759
                    ));
1760
                    $image .= html_writer::span($button['title'], 'header-button-title');
1761
                } else {
1762
                    $image = html_writer::empty_tag('img', array(
1763
                        'src' => $button['formattedimage'],
1764
                        'role' => 'presentation'
1765
                    ));
1766
                }
1767
                $html .= html_writer::link($button['url'], html_writer::tag('span', $image), $button['linkattributes']);
1768
            }
1769
            $html .= html_writer::end_div();
1770
        }
1771
        $html .= html_writer::end_div();
1772
 
1773
        return $html;
1774
    }
1775
 
161 ariadna 1776
    public function header()
1777
    {
1 efrain 1778
        global $USER, $COURSE;
1779
        $theme = theme_config::load('universe');
1780
 
1781
        $context = context_course::instance($COURSE->id);
1782
        $roles = get_user_roles($context, $USER->id, true);
1783
 
1784
        if (is_array($roles) && !empty($roles)) {
1785
            foreach ($roles as $role) {
1786
                $this->page->add_body_class('role-' . $role->shortname);
1787
            }
1788
        } else {
1789
            $this->page->add_body_class('role-none');
1790
        }
1791
 
1792
        if ($theme->settings->topbareditmode == '1') {
1793
            $this->page->add_body_class('rui-editmode--top');
1794
        } else {
1795
            $this->page->add_body_class('rui-editmode--footer');
1796
        }
1797
 
1798
        return parent::header();
1799
    }
1800
 
1801
 
1802
    /**
1803
     * See if this is the first view of the current cm in the session if it has fake blocks.
1804
     *
1805
     * (We track up to 100 cms so as not to overflow the session.)
1806
     * This is done for drawer regions containing fake blocks so we can show blocks automatically.
1807
     *
1808
     * @return boolean true if the page has fakeblocks and this is the first visit.
1809
     */
161 ariadna 1810
    public function firstview_fakeblocks(): bool
1811
    {
1 efrain 1812
        global $SESSION;
1813
 
1814
        $firstview = false;
1815
        if ($this->page->cm) {
1816
            if (!$this->page->blocks->region_has_fakeblocks('side-pre')) {
1817
                return false;
1818
            }
1819
            if (!property_exists($SESSION, 'firstview_fakeblocks')) {
1820
                $SESSION->firstview_fakeblocks = [];
1821
            }
1822
            if (array_key_exists($this->page->cm->id, $SESSION->firstview_fakeblocks)) {
1823
                $firstview = false;
1824
            } else {
1825
                $SESSION->firstview_fakeblocks[$this->page->cm->id] = true;
1826
                $firstview = true;
1827
                if (count($SESSION->firstview_fakeblocks) > 100) {
1828
                    array_shift($SESSION->firstview_fakeblocks);
1829
                }
1830
            }
1831
        }
1832
        return $firstview;
1833
    }
1834
 
1835
 
1836
    /**
1837
     * Build the guest access hint HTML code.
1838
     *
1839
     * @param int $courseid The course ID.
1840
     * @return string.
1841
     */
161 ariadna 1842
    public function theme_universe_get_course_guest_access_hint($courseid)
1843
    {
1 efrain 1844
        global $CFG;
1845
        require_once($CFG->dirroot . '/enrol/self/lib.php');
1846
 
1847
        $html = '';
1848
        $instances = enrol_get_instances($courseid, true);
1849
        $plugins = enrol_get_plugins(true);
1850
        foreach ($instances as $instance) {
1851
            if (!isset($plugins[$instance->enrol])) {
1852
                continue;
1853
            }
1854
            $plugin = $plugins[$instance->enrol];
1855
            if ($plugin->show_enrolme_link($instance)) {
1856
                $html = html_writer::tag('div', get_string(
1857
                    'showhintcourseguestaccesssettinglink',
1858
                    'theme_universe',
1859
                    array('url' => $CFG->wwwroot . '/enrol/index.php?id=' . $courseid)
1860
                ));
1861
                break;
1862
            }
1863
        }
1864
 
1865
        return $html;
1866
    }
1867
 
1868
 
1869
    /**
1870
     * Color Customization
1871
     * @return string HTML fragment.
1872
     */
161 ariadna 1873
    public function additional_head_html()
1874
    {
1 efrain 1875
        global $SITE, $DB, $CFG, $COURSE, $PAGE;
1876
 
1877
        $output = null;
1878
 
1879
        if ($PAGE->pagelayout == 'course' || $PAGE->pagelayout == 'incourse') {
1880
            if ($DB->record_exists('customfield_field', array('shortname' => 'maincolor1'), 'id')) {
1881
                // Get custom field by name
1882
                $customfieldid1 = $DB->get_record('customfield_field', array('shortname' => 'maincolor1'));
1883
                // Get value
1884
                $mainthemecolor = $DB->get_record('customfield_data', array('fieldid' => $customfieldid1->id, 'instanceid' => $COURSE->id));
1885
            } else {
1886
                $mainthemecolor = null;
1887
            }
1888
 
1889
            if ($DB->record_exists('customfield_field', array('shortname' => 'maincolor2'), 'id')) {
1890
                $customfieldid2 = $DB->get_record('customfield_field', array('shortname' => 'maincolor2'));
1891
                $mainthemecolor2 = $DB->get_record('customfield_data', array('fieldid' => $customfieldid2->id, 'instanceid' => $COURSE->id));
1892
            }
1893
 
1894
            if ($DB->record_exists('customfield_field', array('shortname' => 'topbarcolor'), 'id')) {
1895
                // Get custom field by name
1896
                $customfieldid3 = $DB->get_record('customfield_field', array('shortname' => 'topbarcolor'));
1897
                // Get value
1898
                $topbarcolor = $DB->get_record('customfield_data', array('fieldid' => $customfieldid3->id, 'instanceid' => $COURSE->id));
1899
            }
1900
 
1901
            if ($DB->record_exists('customfield_field', array('shortname' => 'dmtopbarcolor'), 'id')) {
1902
                // Get custom field by name
1903
                $customfieldid3 = $DB->get_record('customfield_field', array('shortname' => 'dmtopbarcolor'));
1904
                // Get value
1905
                $dmtopbarcolor = $DB->get_record('customfield_data', array('fieldid' => $customfieldid3->id, 'instanceid' => $COURSE->id));
1906
            } else {
1907
                $dmtopbarcolor = null;
1908
            }
1909
 
1910
 
1911
            if ($DB->record_exists('customfield_field', array('shortname' => 'footerbgcolor'), 'id')) {
1912
                // Get custom field by name
1913
                $customfieldid4 = $DB->get_record('customfield_field', array('shortname' => 'footerbgcolor'));
1914
                // Get value
1915
                $footercolor = $DB->get_record('customfield_data', array('fieldid' => $customfieldid4->id, 'instanceid' => $COURSE->id));
1916
            } else {
1917
                $footercolor = null;
1918
            }
1919
 
1920
 
1921
            $css = '';
1922
 
1923
            $css .= ':root { ';
1924
            if ($DB->record_exists('customfield_field', array('shortname' => 'maincolor1'), 'id')) {
1925
                if ($mainthemecolor != null) {
1926
                    $css .= '--main-theme-color: ' . $mainthemecolor->value . '; ';
1927
                    $css .= '--primary-color-100: ' . $mainthemecolor->value . '30; ';
1928
                    $css .= '--primary-color-300: ' . $mainthemecolor->value . '70; ';
1929
                    $css .= '--main-theme-color-gradient: ' . $mainthemecolor->value . '; ';
1930
                    $css .= '--btn-primary-color-bg: ' . $mainthemecolor->value . '; ';
1931
                    $css .= '--btn-primary-color-bg-hover: ' . $mainthemecolor->value . '95; ';
1932
 
1933
                    if ($DB->record_exists('customfield_field', array('shortname' => 'maincolor2'), 'id')) {
1934
                        if ($mainthemecolor2 != null) {
1935
                            $css .= '--main-theme-color-gradient-2: ' . $mainthemecolor2->value . '; ';
1936
                        } else {
1937
                            $css .= '--main-theme-color-gradient-2: ' . $mainthemecolor->value . '30; ';
1938
                        }
1939
                    }
1940
                }
1941
            }
1942
 
1943
            if ($DB->record_exists('customfield_field', array('shortname' => 'topbarcolor'), 'id')) {
1944
                if ($topbarcolor != null) {
1945
                    $css .= '--topbar-color: ' . $topbarcolor->value . '; ';
1946
                    if ($dmtopbarcolor != null) {
1947
                        $css .= '--dm-topbar-color: ' . $dmtopbarcolor->value . '; ';
1948
                    } else {
1949
                        $css .= '--dm-topbar-color: ' . $topbarcolor->value . '; ';
1950
                    }
1951
                }
1952
            }
1953
 
1954
            if ($DB->record_exists('customfield_field', array('shortname' => 'footerbgcolor'), 'id')) {
1955
                if ($footercolor != null) {
1956
                    $css .= '--footer-color: ' . $footercolor->value . '; ';
1957
                }
1958
            }
1959
 
1960
            $css .= '}';
1961
 
1962
            if ($css) {
1963
                $output .= '<style>' . $css . '</style>';
1964
            }
1965
        }
1966
 
1967
        return $output;
1968
    }
1969
 
161 ariadna 1970
    public function custom_course_logo()
1971
    {
1 efrain 1972
        global $DB, $CFG, $COURSE, $PAGE;
1973
 
1974
        $output = null;
1975
 
1976
        if ($PAGE->pagelayout == 'course' || $PAGE->pagelayout == 'incourse') {
1977
            if ($DB->record_exists('customfield_field', array('shortname' => 'customcourselogo'))) {
1978
                // Get custom field ID
1979
                $customfieldpic = $DB->get_record('customfield_field', array('shortname' => 'customcourselogo'));
1980
                $customfieldpicid = $customfieldpic->id;
1981
                // Get value
1982
                $customlogo = $DB->get_record(
1983
                    'customfield_data',
1984
                    array('fieldid' => $customfieldpicid, 'instanceid' => $COURSE->id)
1985
                );
1986
 
1987
                $customlogoid = $customlogo->id;
1988
                $contextid = $customlogo->contextid;
1989
 
1990
                if ($customfieldpic != null) {
1991
                    $files = get_file_storage()->get_area_files(
1992
                        $contextid,
1993
                        'customfield_picture',
1994
                        'file',
1995
                        $customlogoid,
1996
                        '',
1997
                        false
1998
                    );
1999
 
2000
                    if (empty($files)) {
2001
                        return null;
2002
                    }
2003
 
2004
                    $file = reset($files);
2005
                    $fileurl = moodle_url::make_pluginfile_url(
2006
                        $file->get_contextid(),
2007
                        $file->get_component(),
2008
                        $file->get_filearea(),
2009
                        $file->get_itemid(),
2010
                        $file->get_filepath(),
2011
                        $file->get_filename()
2012
                    );
2013
 
2014
                    $output .= $fileurl;
2015
                }
2016
            }
2017
        }
2018
 
2019
        return $output;
2020
    }
2021
 
161 ariadna 2022
    public function custom_course_dmlogo()
2023
    {
1 efrain 2024
        global $DB, $CFG, $COURSE, $PAGE;
2025
 
2026
        $output = null;
2027
 
2028
        if ($PAGE->pagelayout == 'course' || $PAGE->pagelayout == 'incourse') {
2029
            if ($DB->record_exists('customfield_field', array('shortname' => 'customcoursedmlogo'))) {
2030
                // Get custom field ID
2031
                $customfieldpic = $DB->get_record('customfield_field', array('shortname' => 'customcoursedmlogo'));
2032
                $customfieldpicid = $customfieldpic->id;
2033
                // Get value
2034
                $customlogo = $DB->get_record(
2035
                    'customfield_data',
2036
                    array('fieldid' => $customfieldpicid, 'instanceid' => $COURSE->id)
2037
                );
2038
 
2039
                $customlogoid = $customlogo->id;
2040
                $contextid = $customlogo->contextid;
2041
 
2042
                if ($customfieldpic != null) {
2043
                    $files = get_file_storage()->get_area_files(
2044
                        $contextid,
2045
                        'customfield_picture',
2046
                        'file',
2047
                        $customlogoid,
2048
                        '',
2049
                        false
2050
                    );
2051
 
2052
                    if (empty($files)) {
2053
                        return null;
2054
                    }
2055
 
2056
                    $file = reset($files);
2057
                    $fileurl = moodle_url::make_pluginfile_url(
2058
                        $file->get_contextid(),
2059
                        $file->get_component(),
2060
                        $file->get_filearea(),
2061
                        $file->get_itemid(),
2062
                        $file->get_filepath(),
2063
                        $file->get_filename()
2064
                    );
2065
 
2066
                    $output .= $fileurl;
2067
                }
2068
            }
2069
        }
2070
 
2071
        return $output;
2072
    }
2073
 
161 ariadna 2074
    public function custom_course_favicon()
2075
    {
1 efrain 2076
        global $DB, $CFG, $COURSE, $PAGE;
2077
 
2078
        $output = null;
2079
 
2080
        if ($PAGE->pagelayout == 'course' || $PAGE->pagelayout == 'incourse') {
2081
            if ($DB->record_exists('customfield_field', array('shortname' => 'customcoursefavicon'))) {
2082
                // Get custom field ID
2083
                $customfieldpic = $DB->get_record('customfield_field', array('shortname' => 'customcoursefavicon'));
2084
                $customfieldpicid = $customfieldpic->id;
2085
                // Get value
2086
                $customfavicon = $DB->get_record(
2087
                    'customfield_data',
2088
                    array('fieldid' => $customfieldpicid, 'instanceid' => $COURSE->id)
2089
                );
2090
 
2091
                $customfaviconid = $customfavicon->id;
2092
                $contextid = $customfavicon->contextid;
2093
 
2094
                if ($customfieldpic != null) {
2095
                    $files = get_file_storage()->get_area_files(
2096
                        $contextid,
2097
                        'customfield_picture',
2098
                        'file',
2099
                        $customfaviconid,
2100
                        '',
2101
                        false
2102
                    );
2103
 
2104
                    if (empty($files)) {
2105
                        return null;
2106
                    }
2107
 
2108
                    $file = reset($files);
2109
                    $fileurl = moodle_url::make_pluginfile_url(
2110
                        $file->get_contextid(),
2111
                        $file->get_component(),
2112
                        $file->get_filearea(),
2113
                        $file->get_itemid(),
2114
                        $file->get_filepath(),
2115
                        $file->get_filename()
2116
                    );
2117
 
2118
                    $output .= $fileurl;
2119
                }
2120
            }
2121
        }
2122
 
2123
        return $output;
2124
    }
2125
 
161 ariadna 2126
    public function custom_course_name()
2127
    {
1 efrain 2128
        global $DB, $CFG, $COURSE, $PAGE;
2129
 
2130
        $output = null;
2131
 
2132
        if ($PAGE->pagelayout == 'course' || $PAGE->pagelayout == 'incourse') {
2133
            if ($DB->record_exists('customfield_field', array('shortname' => 'customcoursename'), 'id')) {
2134
                // Get custom field by name
2135
                $customfieldid = $DB->get_record('customfield_field', array('shortname' => 'customcoursename'));
2136
                // Get value
2137
                $customcoursename = $DB->get_record('customfield_data', array('fieldid' => $customfieldid->id, 'instanceid' => $COURSE->id));
2138
                if (!empty($customcoursename)) {
2139
                    $output .= $customcoursename->value;
2140
                }
2141
            } else {
2142
                $customcoursename = null;
2143
            }
2144
        }
2145
 
2146
        return $output;
2147
    }
2148
 
161 ariadna 2149
    /**
1 efrain 2150
     * Get the course pattern datauri to show on a course card.
2151
     *
2152
     * The datauri is an encoded svg that can be passed as a url.
2153
     * @param int $id Id to use when generating the pattern
2154
     * @return string datauri
2155
     */
161 ariadna 2156
    public function get_generated_image_for_id($id)
2157
    {
1 efrain 2158
        global $CFG;
2159
 
2160
        $theme = \theme_config::load('universe');
2161
        // Add custom course cover.
2162
        $customcover = $theme->setting_file_url('defaultcourseimg', 'defaultcourseimg');
2163
 
2164
        if (!empty(($customcover))) {
2165
            $urlreplace = preg_replace('|^https?://|i', '//', $CFG->wwwroot);
2166
            $customcover = str_replace($urlreplace, '', $customcover);
2167
            $txt = new moodle_url($customcover);
2168
            return strval($txt);
2169
        } else {
2170
            $color = $this->get_generated_color_for_id($id);
2171
            $pattern = new \core_geopattern();
2172
            $pattern->setColor($color);
2173
            $pattern->patternbyid($id);
2174
            return $pattern->datauri();
2175
        }
2176
    }
161 ariadna 2177
 
2178
    public function moremenu_group_item()
2179
    {
1 efrain 2180
        global $CFG, $COURSE;
2181
 
2182
        $theme = \theme_config::load('universe');
2183
        $courseid = $COURSE->id;
2184
        $sitehomeurl = new moodle_url('/');
2185
 
2186
        if ($this->page->theme->settings->secnavgroupitem == 1) {
2187
            if (has_capability('moodle/course:managegroups', \context_course::instance($COURSE->id))) {
2188
                $html = $sitehomeurl . "group/index.php?id=" . $courseid;
2189
                return $html;
2190
            }
2191
        }
2192
    }
2193
 
161 ariadna 2194
    public function moremenu_custom_items()
2195
    {
1 efrain 2196
        global $CFG, $COURSE, $USER;
2197
 
2198
        $theme = \theme_config::load('universe');
2199
        $html = '';
2200
        $secnavcount = theme_universe_get_setting('secnavitemscount');
2201
 
2202
        // Get current user role ID.
2203
        $context = context_course::instance($COURSE->id);
2204
        $roles = get_user_roles($context, $USER->id, true);
2205
        $role = 999;
2206
        $roleid = 999;
2207
        $role = key($roles);
2208
        if ($role != null) {
2209
            $roleid = $roles[$role]->roleid;
2210
        }
2211
 
2212
        // End.
2213
 
2214
        if ($this->page->theme->settings->secnavitems == 1) {
2215
 
2216
            $secnav = new stdClass();
2217
            for ($i = 1; $i <= $secnavcount; $i++) {
2218
                $secnav->title = theme_universe_get_setting("secnavcustomnavlabel" . $i);
2219
 
2220
                $url = theme_universe_get_setting("secnavcustomnavurl" . $i);
2221
                $courseid = $COURSE->id;
2222
                $newurl = str_replace("{{courseID}}", $courseid, $url);
161 ariadna 2223
 
1 efrain 2224
                // User role restriction.
2225
                $selectrole = theme_universe_get_setting("secnavuserroles" . $i);
161 ariadna 2226
 
2227
                if ($roleid == $selectrole) {
1 efrain 2228
                    $secnav->url = $newurl;
2229
                    $html .= $this->render_from_template('theme_universe/custom_sec_nav_item', $secnav);
161 ariadna 2230
                }
2231
                if ($roleid != $selectrole) {
1 efrain 2232
                    $secnav->url = $newurl;
2233
                }
161 ariadna 2234
                if ($selectrole == 0) {
1 efrain 2235
                    $secnav->url = $newurl;
2236
                    $html .= $this->render_from_template('theme_universe/custom_sec_nav_item', $secnav);
161 ariadna 2237
                }
1 efrain 2238
                // End.
2239
 
2240
            }
2241
        }
2242
        return $html;
2243
    }
2244
}