1380 |
ariadna |
1 |
<?php
|
|
|
2 |
defined('MOODLE_INTERNAL') || die();
|
|
|
3 |
|
|
|
4 |
// Incluir el archivo lib.php del tema padre
|
|
|
5 |
require_once($CFG->dirroot . '/theme/universe/lib.php');
|
|
|
6 |
|
|
|
7 |
function theme_universe_child_themedir()
|
|
|
8 |
{
|
|
|
9 |
global $CFG;
|
|
|
10 |
|
|
|
11 |
$teme_dir = '/theme';
|
|
|
12 |
|
|
|
13 |
if (isset($CFG->themedir)) {
|
|
|
14 |
$teme_dir = $CFG->themedir;
|
|
|
15 |
$teme_dir = str_replace($CFG->dirroot, '', $CFG->themedir);
|
|
|
16 |
}
|
|
|
17 |
|
|
|
18 |
return $teme_dir;
|
|
|
19 |
}
|
|
|
20 |
|
|
|
21 |
function theme_universe_child_get_setting($setting, $format = false)
|
|
|
22 |
{
|
|
|
23 |
$theme = theme_config::load('universe');
|
|
|
24 |
|
|
|
25 |
if (empty($theme->settings->$setting)) {
|
|
|
26 |
return false;
|
|
|
27 |
}
|
|
|
28 |
|
|
|
29 |
if (!$format) {
|
|
|
30 |
return $theme->settings->$setting;
|
|
|
31 |
}
|
|
|
32 |
|
|
|
33 |
if ($format === 'format_text') {
|
|
|
34 |
return format_text($theme->settings->$setting, FORMAT_PLAIN);
|
|
|
35 |
}
|
|
|
36 |
|
|
|
37 |
if ($format === 'format_html') {
|
|
|
38 |
return format_text($theme->settings->$setting, FORMAT_HTML, array('trusted' => true, 'noclean' => true));
|
|
|
39 |
}
|
|
|
40 |
|
|
|
41 |
return format_string($theme->settings->$setting);
|
|
|
42 |
}
|
|
|
43 |
|
|
|
44 |
function theme_universe_child_get_pre_scss($theme)
|
|
|
45 |
{
|
|
|
46 |
// Load the settings from the parent.
|
|
|
47 |
$theme = theme_config::load('universe');
|
|
|
48 |
// Call the parent themes get_pre_scss function.
|
|
|
49 |
return theme_universe_get_pre_scss($theme);
|
|
|
50 |
}
|
|
|
51 |
|
|
|
52 |
function theme_universe_child_get_main_scss_content($theme)
|
|
|
53 |
{
|
|
|
54 |
global $CFG;
|
|
|
55 |
return theme_universe_get_main_scss_content($theme);
|
|
|
56 |
}
|
|
|
57 |
|
|
|
58 |
/**
|
|
|
59 |
* Obtiene la pista de acceso para invitados al curso
|
|
|
60 |
* @param int $courseid ID del curso
|
|
|
61 |
* @return string HTML con la pista de acceso
|
|
|
62 |
*/
|
|
|
63 |
function theme_universe_child_get_course_guest_access_hint($courseid)
|
|
|
64 |
{
|
|
|
65 |
global $CFG;
|
|
|
66 |
require_once($CFG->dirroot . '/enrol/self/lib.php');
|
|
|
67 |
|
|
|
68 |
$html = '';
|
|
|
69 |
$instances = enrol_get_instances($courseid, true);
|
|
|
70 |
$plugins = enrol_get_plugins(true);
|
|
|
71 |
foreach ($instances as $instance) {
|
|
|
72 |
if (!isset($plugins[$instance->enrol])) {
|
|
|
73 |
continue;
|
|
|
74 |
}
|
|
|
75 |
$plugin = $plugins[$instance->enrol];
|
|
|
76 |
if ($plugin->show_enrolme_link($instance)) {
|
|
|
77 |
$html = html_writer::tag('div', get_string(
|
|
|
78 |
'showhintcourseguestaccesslink',
|
|
|
79 |
'theme_universe_child',
|
|
|
80 |
array('url' => $CFG->wwwroot . '/enrol/index.php?id=' . $courseid)
|
|
|
81 |
));
|
|
|
82 |
break;
|
|
|
83 |
}
|
|
|
84 |
}
|
|
|
85 |
|
|
|
86 |
return $html;
|
|
|
87 |
}
|
|
|
88 |
|
|
|
89 |
/**
|
|
|
90 |
* Obtiene los banners de información del curso
|
|
|
91 |
* @return string HTML con los banners de información
|
|
|
92 |
*/
|
|
|
93 |
function theme_universe_child_get_course_information_banners()
|
|
|
94 |
{
|
|
|
95 |
global $CFG, $COURSE, $PAGE, $USER, $OUTPUT;
|
|
|
96 |
|
|
|
97 |
// Require user library.
|
|
|
98 |
require_once($CFG->dirroot . '/user/lib.php');
|
|
|
99 |
|
|
|
100 |
// Initialize HTML code.
|
|
|
101 |
$html = '';
|
|
|
102 |
|
|
|
103 |
// Check if user is admin, teacher or editing teacher.
|
|
|
104 |
if (
|
|
|
105 |
user_has_role_assignment($USER->id, '1') ||
|
|
|
106 |
user_has_role_assignment($USER->id, '2') ||
|
|
|
107 |
user_has_role_assignment($USER->id, '3') ||
|
|
|
108 |
user_has_role_assignment($USER->id, '4')
|
|
|
109 |
) {
|
|
|
110 |
$allowtoshowhint = true;
|
|
|
111 |
} else {
|
|
|
112 |
$allowtoshowhint = false;
|
|
|
113 |
}
|
|
|
114 |
|
|
|
115 |
// Verificar acceso de invitados
|
|
|
116 |
if (
|
|
|
117 |
get_config('theme_universe_child', 'showhintcourseguestaccess') == 1
|
|
|
118 |
&& is_guest(\context_course::instance($COURSE->id), $USER->id)
|
|
|
119 |
&& $PAGE->has_set_url()
|
|
|
120 |
&& $PAGE->url->compare(new moodle_url('/course/view.php'), URL_MATCH_BASE)
|
|
|
121 |
&& !is_role_switched($COURSE->id)
|
|
|
122 |
) {
|
|
|
123 |
// Require self enrolment library.
|
|
|
124 |
require_once($CFG->dirroot . '/enrol/self/lib.php');
|
|
|
125 |
|
|
|
126 |
// Prepare template context.
|
|
|
127 |
$templatecontext = array(
|
|
|
128 |
'courseid' => $COURSE->id,
|
|
|
129 |
'role' => role_get_name(get_guest_role())
|
|
|
130 |
);
|
|
|
131 |
|
|
|
132 |
// Search for an available self enrolment link in this course.
|
|
|
133 |
$templatecontext['showselfenrollink'] = false;
|
|
|
134 |
$instances = enrol_get_instances($COURSE->id, true);
|
|
|
135 |
$plugins = enrol_get_plugins(true);
|
|
|
136 |
foreach ($instances as $instance) {
|
|
|
137 |
if (!isset($plugins[$instance->enrol])) {
|
|
|
138 |
continue;
|
|
|
139 |
}
|
|
|
140 |
$plugin = $plugins[$instance->enrol];
|
|
|
141 |
if ($plugin->show_enrolme_link($instance)) {
|
|
|
142 |
$templatecontext['showselfenrollink'] = true;
|
|
|
143 |
break;
|
|
|
144 |
}
|
|
|
145 |
}
|
|
|
146 |
|
|
|
147 |
// Render template and add it to HTML code.
|
|
|
148 |
$html .= $OUTPUT->render_from_template('theme_universe_child/course-hint-guestaccess', $templatecontext);
|
|
|
149 |
}
|
|
|
150 |
|
|
|
151 |
return $html;
|
|
|
152 |
}
|
|
|
153 |
|
|
|
154 |
/**
|
|
|
155 |
* Verifica si el usuario es invitado en el contexto del curso
|
|
|
156 |
* @param context_course $context Contexto del curso
|
|
|
157 |
* @param int $userid ID del usuario
|
|
|
158 |
* @return bool True si el usuario es invitado
|
|
|
159 |
*/
|
|
|
160 |
function theme_universe_child_is_guest_in_course($context, $userid)
|
|
|
161 |
{
|
|
|
162 |
return is_guest($context, $userid);
|
|
|
163 |
}
|
|
|
164 |
|
|
|
165 |
/**
|
|
|
166 |
* Get all parent theme settings
|
|
|
167 |
* @return array Array of parent theme settings
|
|
|
168 |
*/
|
|
|
169 |
function theme_universe_child_get_parent_settings()
|
|
|
170 |
{
|
|
|
171 |
global $CFG;
|
|
|
172 |
|
|
|
173 |
$settings = [];
|
|
|
174 |
$parent_settings_dir = $CFG->dirroot . '/theme/universe/settings/';
|
|
|
175 |
|
|
|
176 |
if (is_dir($parent_settings_dir)) {
|
|
|
177 |
$files = scandir($parent_settings_dir);
|
|
|
178 |
foreach ($files as $file) {
|
|
|
179 |
if (pathinfo($file, PATHINFO_EXTENSION) === 'php') {
|
|
|
180 |
$settings[] = $file;
|
|
|
181 |
}
|
|
|
182 |
}
|
|
|
183 |
}
|
|
|
184 |
|
|
|
185 |
return $settings;
|
|
|
186 |
}
|
|
|
187 |
|
|
|
188 |
/**
|
|
|
189 |
* Apply parent theme settings to child theme
|
|
|
190 |
* @param array $settings Array of settings to apply
|
|
|
191 |
*/
|
|
|
192 |
function theme_universe_child_apply_parent_settings($settings)
|
|
|
193 |
{
|
|
|
194 |
global $CFG;
|
|
|
195 |
|
|
|
196 |
foreach ($settings as $setting) {
|
|
|
197 |
$parent_setting = $CFG->dirroot . '/theme/universe/settings/' . $setting;
|
|
|
198 |
if (file_exists($parent_setting)) {
|
|
|
199 |
require_once($parent_setting);
|
|
|
200 |
}
|
|
|
201 |
}
|
|
|
202 |
}
|