Proyectos de Subversion Moodle

Rev

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