Proyectos de Subversion Moodle

Rev

Rev 1365 | Rev 1367 | Ir a la última revisión | | 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
 
1146 efrain 38
if (!empty($PAGE->course->id)) {
1126 efrain 39
    $course = get_course($PAGE->course->id);
40
    $course_context = context_course::instance($course->id);
1167 ariadna 41
 
1221 ariadna 42
    $notifyeditingon  = empty($_GET['notifyeditingon']) ? 0 : intval($_GET['notifyeditingon'], 10);
1167 ariadna 43
 
1303 ariadna 44
    // Detectar si el usuario es invitado o está accediendo sin loguearse
45
    $isguestaccess = isguestuser() || !isloggedin();
1302 ariadna 46
 
1366 ariadna 47
    // Solo activar redirección si NO es docente, admin, ni invitado anónimo
1302 ariadna 48
    if (
49
        has_capability('moodle/course:manageactivities', $course_context, $USER->id) ||
50
        has_capability('moodle/course:viewhiddenactivities', $course_context, $USER->id) ||
1303 ariadna 51
        $notifyeditingon ||
1366 ariadna 52
        $isguestaccess
1302 ariadna 53
    ) {
1233 ariadna 54
        $searchURL = false;
55
    } else {
1366 ariadna 56
        // Solo aplicar redirección si NO es un usuario invitado
57
        if (!isguestuser()) {
58
            $searchURL = true;
59
        } else {
60
            $searchURL = false;
61
        }
1146 efrain 62
    }
1167 ariadna 63
 
64
    if ($searchURL) {
1146 efrain 65
        $completioninfo = new \completion_info($course);
1303 ariadna 66
        $modules = get_fast_modinfo($course->id)->get_cms();
1167 ariadna 67
 
1146 efrain 68
        if (!empty($modules)) {
69
            foreach ($modules as $module) {
1366 ariadna 70
                // Para invitados, solo verificar visibilidad básica
1365 ariadna 71
                if (isguestuser()) {
72
                    if (!$module->uservisible || empty($module->url)) {
73
                        continue;
74
                    }
75
                } else {
1366 ariadna 76
                    // Para usuarios normales, mantener la lógica original
1365 ariadna 77
                    if (!$module->uservisible || $module->is_stealth() || empty($module->url)) {
78
                        continue;
79
                    }
1146 efrain 80
                }
1303 ariadna 81
 
1146 efrain 82
                $linkURL = new \moodle_url($module->url, array('forceview' => 1));
1167 ariadna 83
 
1366 ariadna 84
                // Solo verificar completitud para usuarios no invitados
85
                if (!isguestuser()) {
86
                    $completiondata = $completioninfo->get_data($module, true);
87
                    if (
88
                        $completiondata &&
89
                        ($completiondata->completionstate == COMPLETION_COMPLETE || $completiondata->completionstate == COMPLETION_COMPLETE_PASS)
90
                    ) {
91
                        continue;
92
                    }
1146 efrain 93
                }
1303 ariadna 94
 
1146 efrain 95
                break;
1139 ariadna 96
            }
1119 efrain 97
        }
1146 efrain 98
    }
1126 efrain 99
}
1119 efrain 100
 
1165 efrain 101
if (!empty($linkURL)) {
102
    redirect($linkURL);
1126 efrain 103
    exit;
1167 ariadna 104
}
1116 efrain 105
 
533 ariadna 106
$draweropenright = false;
107
$extraclasses = [];
108
 
109
$courseindexopen = false;
110
$blockdraweropen = false;
111
 
112
// Moodle 4. - Add block button in editing mode.
113
$addblockbutton = $OUTPUT->addblockbutton();
114
if (isloggedin()) {
115
    $courseindexopen = (get_user_preferences('drawer-open-index', true) == true);
116
    $blockdraweropen = (get_user_preferences('drawer-open-block') == true);
117
} else {
118
    $courseindexopen = false;
119
    $blockdraweropen = false;
120
}
121
 
122
if (defined('BEHAT_SITE_RUNNING')) {
123
    $blockdraweropen = true;
124
}
125
 
126
$extraclasses = ['uses-drawers'];
127
// End.
128
 
129
// Dark mode.
130
if (isloggedin()) {
131
    $navdraweropen = get_user_preferences('drawer-open-nav', true);
132
    $draweropenright = (get_user_preferences('sidepre-open', 'true') == 'true');
133
 
134
    if (theme_universe_get_setting('darkmodetheme') == '1') {
135
        $darkmodeon = get_user_preferences('darkmode-on');
136
        if ($darkmodeon) {
137
            $extraclasses[] = 'theme-dark';
138
        }
139
        $darkmodetheme = true;
140
    } else {
141
        $darkmodeon = false;
142
    }
143
} else {
144
    $navdraweropen = false;
145
}
146
 
147
if (theme_universe_get_setting('darkmodefirst') == '1') {
148
    $extraclasses[] = 'theme-dark';
149
    $darkmodetheme = false;
150
    $darkmodeon = true;
151
}
152
 
153
$siteurl = $CFG->wwwroot;
154
 
155
$blockshtml = $OUTPUT->blocks('side-pre');
156
$hasblocks = (strpos($blockshtml, 'data-block=') !== false || !empty($addblockbutton));
157
if (!$hasblocks) {
158
    $blockdraweropen = false;
159
}
160
 
161
if (theme_universe_get_setting('hidecourseindexnav') == true) {
162
    $hidecourseindexnav = true;
163
} else {
164
    $hidecourseindexnav = false;
165
}
166
 
167
if (theme_universe_get_setting('hidecourseindexnav') == false) {
168
    $courseindex = core_course_drawer();
169
    if (!$courseindex) {
170
        $courseindexopen = false;
171
    }
172
    if ($courseindexopen == false) {
173
        $extraclasses[] = 'drawer-open-index--closed';
174
    } else {
175
        $extraclasses[] = 'drawer-open-index--open';
176
    }
177
} else {
178
    $courseindex = false;
179
    $courseindexopen = false;
180
}
181
 
182
$sidecourseblocks = $OUTPUT->blocks('sidecourseblocks');
183
$hassidecourseblocks = strpos($sidecourseblocks, 'data-block=') !== false;
184
 
185
 
186
if ($draweropenright && $hasblocks) {
187
    $extraclasses[] = 'drawer-open-right';
188
}
189
 
190
$ctopbl = $OUTPUT->blocks('ctopbl');
191
$cbottombl = $OUTPUT->blocks('cbottombl');
192
$cstopbl = $OUTPUT->blocks('cstopbl');
193
$csbottombl = $OUTPUT->blocks('csbottombl');
194
$coursetab1 = $OUTPUT->blocks('coursetab-a');
195
$coursetab2 = $OUTPUT->blocks('coursetab-b');
196
$coursetab3 = $OUTPUT->blocks('coursetab-c');
197
$coursetab4 = $OUTPUT->blocks('coursetab-d');
198
$coursetab5 = $OUTPUT->blocks('coursetab-e');
199
 
200
// Moodle 4.
201
$forceblockdraweropen = $OUTPUT->firstview_fakeblocks();
202
 
203
$secondarynavigation = false;
204
$overflow = '';
205
if ($PAGE->has_secondary_navigation()) {
206
    $tablistnav = $PAGE->has_tablist_secondary_navigation();
207
    $moremenu = new \core\navigation\output\more_menu($PAGE->secondarynav, 'nav-tabs', true, $tablistnav);
208
    $secondarynavigation = $moremenu->export_for_template($OUTPUT);
209
    $overflowdata = $PAGE->secondarynav->get_overflow_menu_data();
210
    if (!is_null($overflowdata)) {
211
        $overflow = $overflowdata->export_for_template($OUTPUT);
212
    }
213
}
214
 
215
$primary = new core\navigation\output\primary($PAGE);
216
$renderer = $PAGE->get_renderer('core');
217
$primarymenu = $primary->export_for_template($renderer);
218
$buildregionmainsettings = !$PAGE->include_region_main_settings_in_header_actions() && !$PAGE->has_secondary_navigation();
219
// If the settings menu will be included in the header then don't add it here.
220
$regionmainsettingsmenu = $buildregionmainsettings ? $OUTPUT->region_main_settings_menu() : false;
221
 
222
$header = $PAGE->activityheader;
223
$headercontent = $header->export_for_template($renderer);
224
 
225
// RUI.
226
$iscoursepage = true;
227
 
228
if ($hassidecourseblocks) {
229
    $extraclasses[] = 'page-has-blocks';
230
}
231
 
232
if (!isloggedin() || isguestuser()) {
233
    $isnotloggedin = true;
234
} else {
235
    $isnotloggedin = false;
236
}
237
 
238
// Check if guest user.
239
if (isguestuser()) {
240
    $extraclasses[] = 'moodle-guest-user';
241
}
242
 
243
// Start - Course Image Position (theme settings).
244
$courseimage = theme_universe_get_setting('ipcourseimage');
245
 
246
if ($hassidecourseblocks) {
247
    $extraclasses[] = 'page-has-blocks';
248
}
249
 
250
if ($PAGE->course->enablecompletion == '1') {
251
    $extraclasses[] = 'rui-course--enablecompletion';
252
}
253
 
254
if ($PAGE->course->showactivitydates == '1') {
255
    $extraclasses[] = 'rui-course--showactivitydates';
256
}
257
 
258
if ($PAGE->course->visible == '1') {
259
    $extraclasses[] = 'rui-course--visible';
260
}
261
 
262
$iscoursepage = true;
263
 
264
if (theme_universe_get_setting('backtotop') == '1') {
265
    $extraclasses[] = 'back-to-top-on';
266
}
267
 
268
$bodyattributes = $OUTPUT->body_attributes($extraclasses);
269
 
270
$templatecontext = [
271
    'sitename' => format_string($SITE->shortname, true, ['context' => context_course::instance(SITEID), "escape" => false]),
272
    'output' => $OUTPUT,
273
    'bodyattributes' => $bodyattributes,
274
    'darkmodeon' => !empty($darkmodeon),
275
    'darkmodetheme' => !empty($darkmodetheme),
276
    'siteurl' => $siteurl,
277
    'sidepreblocks' => $blockshtml,
278
    'hasblocks' => $hasblocks,
279
    'navdraweropen' => $navdraweropen,
280
    'draweropenright' => $draweropenright,
281
    'isnotloggedin' => $isnotloggedin,
282
    'ctopbl' => $ctopbl,
283
    'cbottombl' => $cbottombl,
284
    'cstopbl' => $cstopbl,
285
    'csbottombl' => $csbottombl,
286
    'coursetab-a' => $coursetab1,
287
    'coursetab-b' => $coursetab2,
288
    'coursetab-c' => $coursetab3,
289
    'coursetab-d' => $coursetab4,
290
    'coursetab-e' => $coursetab5,
291
    'hasctopbl' => !empty($ctopbl),
292
    'hascbottombl' => !empty($cbottombl),
293
    'hascstopbl' => !empty($cstopbl),
294
    'hascsbottombl' => !empty($csbottombl),
295
    'sidecourseblocks' => $sidecourseblocks,
296
    'hassidecourseblocks' => $hassidecourseblocks,
297
    'ipcourseimage' => $courseimage,
298
    'iscoursepage' => $iscoursepage,
299
    // Moodle 4.
300
    'courseindexopen' => $courseindexopen,
301
    'blockdraweropen' => $blockdraweropen,
302
    'courseindex' => $courseindex,
303
    'primarymoremenu' => $primarymenu['moremenu'],
304
    'secondarymoremenu' => $secondarynavigation ?: false,
305
    'headercontent' => $headercontent,
306
    'forceblockdraweropen' => $forceblockdraweropen,
307
    'regionmainsettingsmenu' => $regionmainsettingsmenu,
308
    'hasregionmainsettingsmenu' => !empty($regionmainsettingsmenu),
309
    'overflow' => $overflow,
310
    'addblockbutton' => $addblockbutton,
311
    'hidecourseindexnav' => $hidecourseindexnav,
312
];
313
 
314
// Get and use the course page information banners HTML code, if any course page hints are configured.
315
$coursepageinformationbannershtml = theme_universe_get_course_information_banners();
316
if ($coursepageinformationbannershtml) {
317
    $templatecontext['coursepageinformationbanners'] = $coursepageinformationbannershtml;
318
}
319
// End.
320
 
321
// Load theme settings.
322
$themesettings = new \theme_universe\util\theme_settings();
323
 
324
$templatecontext = array_merge($templatecontext, $themesettings->global_settings());
325
$templatecontext = array_merge($templatecontext, $themesettings->course_settings());
326
 
544 ariadna 327
$PAGE->requires->js_call_amd('theme_universe/rui', 'init');
533 ariadna 328
if (theme_universe_get_setting('backtotop') == '1') {
544 ariadna 329
    $PAGE->requires->js_call_amd('theme_universe/backtotop', 'init');
533 ariadna 330
}
331
 
332
echo $OUTPUT->render_from_template('theme_universe_child/tmpl-course', $templatecontext);