Proyectos de Subversion Moodle

Rev

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