Proyectos de Subversion Moodle

Rev

Rev 1368 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
533 ariadna 1
<?php
2
// This file is part of Moodle - http://moodle.org/
3
//
4
// Moodle is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
8
//
9
// Moodle is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
// GNU General Public License for more details.
13
//
14
// You should have received a copy of the GNU General Public License
15
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
16
 
17
/**
18
 * A two column layout for the universe theme.
19
 *
20
 * @package   theme_universe
21
 * @copyright 2023 Marcin Czaja (https://rosea.io)
22
 * @license   Commercial https://themeforest.net/licenses
23
 */
24
 
1115 efrain 25
 
533 ariadna 26
defined('MOODLE_INTERNAL') || die();
27
 
1143 efrain 28
global $CFG, $PAGE, $OUTPUT, $USER;
1119 efrain 29
 
1143 efrain 30
 
533 ariadna 31
require_once($CFG->libdir . '/behat/lib.php');
32
require_once($CFG->dirroot . '/course/lib.php');
33
 
1126 efrain 34
 
1146 efrain 35
$searchURL = false;
36
$linkURL = '';
1303 ariadna 37
 
1368 ariadna 38
if (!empty($PAGE->course->id)) {
39
    $course = get_course($PAGE->course->id);
40
    $course_context = context_course::instance($course->id);
1167 ariadna 41
 
1368 ariadna 42
    $notifyeditingon  = empty($_GET['notifyeditingon']) ? 0 : intval($_GET['notifyeditingon'], 10);
43
 
44
    // Detectar si el usuario es invitado o está accediendo sin loguearse
45
    $isguestaccess = isguestuser() || !isloggedin();
46
 
1369 ariadna 47
    // Desactivar redirección para invitados y usuarios con permisos específicos
1368 ariadna 48
    if (
1369 ariadna 49
        $isguestaccess ||
1368 ariadna 50
        has_capability('moodle/course:manageactivities', $course_context, $USER->id) ||
51
        has_capability('moodle/course:viewhiddenactivities', $course_context, $USER->id) ||
1369 ariadna 52
        $notifyeditingon
1368 ariadna 53
    ) {
54
        $searchURL = false;
55
    } else {
1369 ariadna 56
        $searchURL = true;
1368 ariadna 57
    }
58
 
59
    if ($searchURL) {
60
        $completioninfo = new \completion_info($course);
61
        $modules = get_fast_modinfo($course->id)->get_cms();
62
 
63
        if (!empty($modules)) {
64
            foreach ($modules as $module) {
1369 ariadna 65
                // Simplificar la verificación de visibilidad para invitados
66
                if ($isguestaccess) {
1368 ariadna 67
                    if (!$module->uservisible || empty($module->url)) {
68
                        continue;
69
                    }
1369 ariadna 70
                    $linkURL = new \moodle_url($module->url, array('forceview' => 1));
71
                    break;
1368 ariadna 72
                } else {
1369 ariadna 73
                    // Mantener la lógica original para usuarios registrados
1368 ariadna 74
                    if (!$module->uservisible || $module->is_stealth() || empty($module->url)) {
75
                        continue;
76
                    }
77
 
1369 ariadna 78
                    $linkURL = new \moodle_url($module->url, array('forceview' => 1));
1368 ariadna 79
 
80
                    $completiondata = $completioninfo->get_data($module, true);
81
                    if (
82
                        $completiondata &&
1369 ariadna 83
                        ($completiondata->completionstate == COMPLETION_COMPLETE ||
84
                            $completiondata->completionstate == COMPLETION_COMPLETE_PASS)
1368 ariadna 85
                    ) {
86
                        continue;
87
                    }
1369 ariadna 88
                    break;
1368 ariadna 89
                }
90
            }
91
        }
92
    }
93
}
94
 
95
if (!empty($linkURL)) {
96
    redirect($linkURL);
97
    exit;
98
}
99
 
533 ariadna 100
$draweropenright = false;
101
$extraclasses = [];
102
 
103
$courseindexopen = false;
104
$blockdraweropen = false;
105
 
106
// Moodle 4. - Add block button in editing mode.
107
$addblockbutton = $OUTPUT->addblockbutton();
108
if (isloggedin()) {
109
    $courseindexopen = (get_user_preferences('drawer-open-index', true) == true);
110
    $blockdraweropen = (get_user_preferences('drawer-open-block') == true);
111
} else {
112
    $courseindexopen = false;
113
    $blockdraweropen = false;
114
}
115
 
116
if (defined('BEHAT_SITE_RUNNING')) {
117
    $blockdraweropen = true;
118
}
119
 
120
$extraclasses = ['uses-drawers'];
121
// End.
122
 
123
// Dark mode.
124
if (isloggedin()) {
125
    $navdraweropen = get_user_preferences('drawer-open-nav', true);
126
    $draweropenright = (get_user_preferences('sidepre-open', 'true') == 'true');
127
 
128
    if (theme_universe_get_setting('darkmodetheme') == '1') {
129
        $darkmodeon = get_user_preferences('darkmode-on');
130
        if ($darkmodeon) {
131
            $extraclasses[] = 'theme-dark';
132
        }
133
        $darkmodetheme = true;
134
    } else {
135
        $darkmodeon = false;
136
    }
137
} else {
138
    $navdraweropen = false;
139
}
140
 
141
if (theme_universe_get_setting('darkmodefirst') == '1') {
142
    $extraclasses[] = 'theme-dark';
143
    $darkmodetheme = false;
144
    $darkmodeon = true;
145
}
146
 
147
$siteurl = $CFG->wwwroot;
148
 
149
$blockshtml = $OUTPUT->blocks('side-pre');
150
$hasblocks = (strpos($blockshtml, 'data-block=') !== false || !empty($addblockbutton));
151
if (!$hasblocks) {
152
    $blockdraweropen = false;
153
}
154
 
155
if (theme_universe_get_setting('hidecourseindexnav') == true) {
156
    $hidecourseindexnav = true;
157
} else {
158
    $hidecourseindexnav = false;
159
}
160
 
161
if (theme_universe_get_setting('hidecourseindexnav') == false) {
162
    $courseindex = core_course_drawer();
163
    if (!$courseindex) {
164
        $courseindexopen = false;
165
    }
166
    if ($courseindexopen == false) {
167
        $extraclasses[] = 'drawer-open-index--closed';
168
    } else {
169
        $extraclasses[] = 'drawer-open-index--open';
170
    }
171
} else {
172
    $courseindex = false;
173
    $courseindexopen = false;
174
}
175
 
176
$sidecourseblocks = $OUTPUT->blocks('sidecourseblocks');
177
$hassidecourseblocks = strpos($sidecourseblocks, 'data-block=') !== false;
178
 
179
 
180
if ($draweropenright && $hasblocks) {
181
    $extraclasses[] = 'drawer-open-right';
182
}
183
 
184
$ctopbl = $OUTPUT->blocks('ctopbl');
185
$cbottombl = $OUTPUT->blocks('cbottombl');
186
$cstopbl = $OUTPUT->blocks('cstopbl');
187
$csbottombl = $OUTPUT->blocks('csbottombl');
188
$coursetab1 = $OUTPUT->blocks('coursetab-a');
189
$coursetab2 = $OUTPUT->blocks('coursetab-b');
190
$coursetab3 = $OUTPUT->blocks('coursetab-c');
191
$coursetab4 = $OUTPUT->blocks('coursetab-d');
192
$coursetab5 = $OUTPUT->blocks('coursetab-e');
193
 
194
// Moodle 4.
195
$forceblockdraweropen = $OUTPUT->firstview_fakeblocks();
196
 
197
$secondarynavigation = false;
198
$overflow = '';
199
if ($PAGE->has_secondary_navigation()) {
200
    $tablistnav = $PAGE->has_tablist_secondary_navigation();
201
    $moremenu = new \core\navigation\output\more_menu($PAGE->secondarynav, 'nav-tabs', true, $tablistnav);
202
    $secondarynavigation = $moremenu->export_for_template($OUTPUT);
203
    $overflowdata = $PAGE->secondarynav->get_overflow_menu_data();
204
    if (!is_null($overflowdata)) {
205
        $overflow = $overflowdata->export_for_template($OUTPUT);
206
    }
207
}
208
 
209
$primary = new core\navigation\output\primary($PAGE);
210
$renderer = $PAGE->get_renderer('core');
211
$primarymenu = $primary->export_for_template($renderer);
212
$buildregionmainsettings = !$PAGE->include_region_main_settings_in_header_actions() && !$PAGE->has_secondary_navigation();
213
// If the settings menu will be included in the header then don't add it here.
214
$regionmainsettingsmenu = $buildregionmainsettings ? $OUTPUT->region_main_settings_menu() : false;
215
 
216
$header = $PAGE->activityheader;
217
$headercontent = $header->export_for_template($renderer);
218
 
219
// RUI.
220
$iscoursepage = true;
221
 
222
if ($hassidecourseblocks) {
223
    $extraclasses[] = 'page-has-blocks';
224
}
225
 
226
if (!isloggedin() || isguestuser()) {
227
    $isnotloggedin = true;
228
} else {
229
    $isnotloggedin = false;
230
}
231
 
232
// Check if guest user.
233
if (isguestuser()) {
234
    $extraclasses[] = 'moodle-guest-user';
235
}
236
 
237
// Start - Course Image Position (theme settings).
238
$courseimage = theme_universe_get_setting('ipcourseimage');
239
 
240
if ($hassidecourseblocks) {
241
    $extraclasses[] = 'page-has-blocks';
242
}
243
 
244
if ($PAGE->course->enablecompletion == '1') {
245
    $extraclasses[] = 'rui-course--enablecompletion';
246
}
247
 
248
if ($PAGE->course->showactivitydates == '1') {
249
    $extraclasses[] = 'rui-course--showactivitydates';
250
}
251
 
252
if ($PAGE->course->visible == '1') {
253
    $extraclasses[] = 'rui-course--visible';
254
}
255
 
256
$iscoursepage = true;
257
 
258
if (theme_universe_get_setting('backtotop') == '1') {
259
    $extraclasses[] = 'back-to-top-on';
260
}
261
 
262
$bodyattributes = $OUTPUT->body_attributes($extraclasses);
263
 
264
$templatecontext = [
265
    'sitename' => format_string($SITE->shortname, true, ['context' => context_course::instance(SITEID), "escape" => false]),
266
    'output' => $OUTPUT,
267
    'bodyattributes' => $bodyattributes,
268
    'darkmodeon' => !empty($darkmodeon),
269
    'darkmodetheme' => !empty($darkmodetheme),
270
    'siteurl' => $siteurl,
271
    'sidepreblocks' => $blockshtml,
272
    'hasblocks' => $hasblocks,
273
    'navdraweropen' => $navdraweropen,
274
    'draweropenright' => $draweropenright,
275
    'isnotloggedin' => $isnotloggedin,
276
    'ctopbl' => $ctopbl,
277
    'cbottombl' => $cbottombl,
278
    'cstopbl' => $cstopbl,
279
    'csbottombl' => $csbottombl,
280
    'coursetab-a' => $coursetab1,
281
    'coursetab-b' => $coursetab2,
282
    'coursetab-c' => $coursetab3,
283
    'coursetab-d' => $coursetab4,
284
    'coursetab-e' => $coursetab5,
285
    'hasctopbl' => !empty($ctopbl),
286
    'hascbottombl' => !empty($cbottombl),
287
    'hascstopbl' => !empty($cstopbl),
288
    'hascsbottombl' => !empty($csbottombl),
289
    'sidecourseblocks' => $sidecourseblocks,
290
    'hassidecourseblocks' => $hassidecourseblocks,
291
    'ipcourseimage' => $courseimage,
292
    'iscoursepage' => $iscoursepage,
293
    // Moodle 4.
294
    'courseindexopen' => $courseindexopen,
295
    'blockdraweropen' => $blockdraweropen,
296
    'courseindex' => $courseindex,
297
    'primarymoremenu' => $primarymenu['moremenu'],
298
    'secondarymoremenu' => $secondarynavigation ?: false,
299
    'headercontent' => $headercontent,
300
    'forceblockdraweropen' => $forceblockdraweropen,
301
    'regionmainsettingsmenu' => $regionmainsettingsmenu,
302
    'hasregionmainsettingsmenu' => !empty($regionmainsettingsmenu),
303
    'overflow' => $overflow,
304
    'addblockbutton' => $addblockbutton,
305
    'hidecourseindexnav' => $hidecourseindexnav,
306
];
307
 
308
// Get and use the course page information banners HTML code, if any course page hints are configured.
309
$coursepageinformationbannershtml = theme_universe_get_course_information_banners();
310
if ($coursepageinformationbannershtml) {
311
    $templatecontext['coursepageinformationbanners'] = $coursepageinformationbannershtml;
312
}
313
// End.
314
 
315
// Load theme settings.
316
$themesettings = new \theme_universe\util\theme_settings();
317
 
318
$templatecontext = array_merge($templatecontext, $themesettings->global_settings());
319
$templatecontext = array_merge($templatecontext, $themesettings->course_settings());
320
 
544 ariadna 321
$PAGE->requires->js_call_amd('theme_universe/rui', 'init');
533 ariadna 322
if (theme_universe_get_setting('backtotop') == '1') {
544 ariadna 323
    $PAGE->requires->js_call_amd('theme_universe/backtotop', 'init');
533 ariadna 324
}
325
 
326
echo $OUTPUT->render_from_template('theme_universe_child/tmpl-course', $templatecontext);