Proyectos de Subversion Moodle

Rev

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