Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 1441
Línea 16... Línea 16...
16
 
16
 
17
/**
17
/**
18
 * Course class utility class
18
 * Course class utility class
19
 *
19
 *
20
 * @package   theme_universe
20
 * @package   theme_universe
21
 * @copyright 2023 Marcin Czaja (https://rosea.io)
21
 * @copyright 2024 Marcin Czaja (https://rosea.io)
22
 * @license   Commercial https://themeforest.net/licenses
22
 * @license   Commercial https://themeforest.net/licenses
Línea 23... Línea 23...
23
 */
23
 */
Línea 28... Línea 28...
28
use core_course_list_element;
28
use core_course_list_element;
29
use coursecat_helper;
29
use coursecat_helper;
30
use core_course_category;
30
use core_course_category;
31
use html_writer;
31
use html_writer;
32
use context_course;
32
use context_course;
-
 
33
use theme_config;
Línea 33... Línea 34...
33
 
34
 
34
/**
35
/**
35
 * Course class utility class
36
 * Course class utility class
36
 *
37
 *
37
 * @package   theme_universe
38
 * @package   theme_universe
38
 * @copyright 2023 Marcin Czaja (https://rosea.io)
39
 * @copyright 2024 Marcin Czaja (https://rosea.io)
39
 * @license   Commercial https://themeforest.net/licenses
40
 * @license   Commercial https://themeforest.net/licenses
40
 */
41
 */
41
class course {
42
class course {
42
    /**
43
    /**
Línea 57... Línea 58...
57
    /**
58
    /**
58
     * Returns the first course's summary image url
59
     * Returns the first course's summary image url
59
     *
60
     *
60
     * @return string
61
     * @return string
61
     */
62
     */
62
    public function get_summary_image() {
63
    public function get_summary_image($returngeneratedimageifnone = true) {
63
        global $CFG, $OUTPUT;
64
        global $CFG, $OUTPUT;
Línea 64... Línea 65...
64
 
65
 
65
        foreach ($this->course->get_course_overviewfiles() as $file) {
66
        foreach ($this->course->get_course_overviewfiles() as $file) {
-
 
67
            if ($file->is_valid_image()) {
66
            if ($file->is_valid_image()) {
68
                $url = moodle_url::make_file_url(
67
                $url = moodle_url::make_file_url("$CFG->wwwroot/pluginfile.php",
69
                    "$CFG->wwwroot/pluginfile.php",
68
                    '/' . $file->get_contextid() . '/' . $file->get_component() . '/' .
70
                    '/' . $file->get_contextid() . '/' . $file->get_component() . '/' .
69
                    $file->get_filearea() . $file->get_filepath() . $file->get_filename(), !$file->is_valid_image());
-
 
-
 
71
                        $file->get_filearea() . $file->get_filepath() . $file->get_filename(),
-
 
72
                    !$file->is_valid_image()
70
 
73
                );
71
                return $url->out();
74
                return $url->out();
72
            }
75
            }
Línea -... Línea 76...
-
 
76
        }
-
 
77
 
-
 
78
        if (!$returngeneratedimageifnone) {
-
 
79
            return '';
73
        }
80
        }
74
 
81
 
Línea 75... Línea 82...
75
        return $OUTPUT->get_generated_image_for_id($this->course->id);
82
        return $OUTPUT->get_generated_image_for_id($this->course->id);
76
    }
83
    }
Línea 102... Línea 109...
102
 
109
 
103
        return $contacts;
110
        return $contacts;
Línea 104... Línea 111...
104
    }
111
    }
105
 
112
 
106
    /**
-
 
107
     * Returns HTML to display course category name.
-
 
108
     *
113
    /**
109
     * @return string
114
     * Returns HTML to display course contacts for filter.
110
     *
115
     *
111
     * @throws \moodle_exception
116
     * @return array
112
     */
117
     */
-
 
118
    public function get_meta_course_contacts() {
Línea -... Línea 119...
-
 
119
        if ($this->course->has_course_contacts()) {
-
 
120
            $contacts = [];
-
 
121
 
113
    public function get_category(): string {
122
            $instructors = $this->course->get_course_contacts();
-
 
123
        
-
 
124
            // Counter for teachers IDs separator.
-
 
125
            $k = 0;
-
 
126
            $last_key = count($instructors);
-
 
127
 
-
 
128
            foreach ($instructors as $instructor) {
-
 
129
                $k++;
-
 
130
                $user = $instructor['user'];
-
 
131
 
-
 
132
                $contacts = "{$user->firstname} {$user->lastname}";
-
 
133
 
-
 
134
                // Counter for teachers IDs separator.
-
 
135
                if ($k < $last_key) {
-
 
136
                    $contacts =  ', ';
114
        $cat = core_course_category::get($this->course->category, IGNORE_MISSING);
137
                }
115
 
138
            }
-
 
139
        
Línea -... Línea 140...
-
 
140
            return $contacts;
-
 
141
        }
-
 
142
    }
-
 
143
 
-
 
144
    /**
-
 
145
     * Returns HTML to display course language for filter.
-
 
146
     *
116
        if (!$cat) {
147
     * @return array
117
            return '';
148
     */
Línea 118... Línea 149...
118
        }
149
    public function get_meta_course_lang() {
119
 
150
        $lang = strval($this->course->lang);
120
        return $cat->get_formatted_name();
151
        return $lang;
-
 
152
    }
121
    }
153
 
122
 
154
    /**
123
    /**
155
     * Returns HTML to display course custom field for a given filter.
-
 
156
     *
-
 
157
     * @param int $filterNumber The filter number (e.g., 1, 2, 3, etc.).
-
 
158
     * @return string The HTML output for the filter.
-
 
159
     */
-
 
160
    public function get_meta_course_customfilter($filterNumber) {
-
 
161
        global $DB;
-
 
162
        $output = '';
-
 
163
 
124
     * Returns course summary.
164
        $theme = theme_config::load('universe');
-
 
165
 
-
 
166
        $customfilter = $theme->settings->{'customfilter' . $filterNumber};
-
 
167
        $record = $DB->get_record('customfield_field', ['shortname' => $customfilter]);
-
 
168
 
-
 
169
        if ($record != null) {
-
 
170
            $cfid = $record;
125
     *
171
            $record = $DB->get_record('customfield_data', ['fieldid' => $cfid->id, 'instanceid' => $this->course->id]);
-
 
172
 
-
 
173
            if ($record != null) {
126
     * @param coursecat_helper $chelper
174
                if($record->intvalue != null) {
-
 
175
 
-
 
176
                    $fieldid = $DB->get_record('customfield_field', ['id' => $record->fieldid]);
-
 
177
                    $jsonString = $fieldid->configdata;
-
 
178
                            
-
 
179
                    // Decode JSON string into a PHP associative array
-
 
180
                    $array = json_decode($jsonString, true);
-
 
181
                    // Check if decoding was successful
-
 
182
                    if (json_last_error() === JSON_ERROR_NONE) {
-
 
183
                        // Access the 'options' key
-
 
184
                        $options = $array['options'];
-
 
185
                        
-
 
186
                        // // Print the options
-
 
187
                        // echo $options;
-
 
188
                    } else {
-
 
189
                        // Handle JSON decoding error
-
 
190
                        echo "Error decoding JSON: " . json_last_error_msg();
-
 
191
                    }
-
 
192
                    $optionsArray = explode("\r\n", $options);
-
 
193
                    $key = $record->intvalue - 1;
-
 
194
                    if($key >= 0) {
127
     */
195
                        $output .= $optionsArray[$key];
-
 
196
                    }
128
    public function get_summary(coursecat_helper $chelper): string {
197
                } else {
Línea 129... Línea 198...
129
        if ($this->course->has_summary()) {
198
                    $output .= $record->value;
130
            return $chelper->get_course_formatted_summary($this->course,
199
                }
Línea 131... Línea 200...
131
                ['overflowdiv' => true, 'noclean' => true, 'para' => false]
200
            }
132
            );
201
 
133
        }
-
 
134
 
-
 
135
        return false;
202
        }
136
    }
203
 
137
 
204
        return $output;
138
    /**
-
 
-
 
205
    }
Línea -... Línea 206...
-
 
206
 
-
 
207
    /**
-
 
208
     * Returns HTML to display course custom field #1 for filter.
-
 
209
     */
139
     * Returns course custom fields.
210
    public function get_meta_course_customfilter1() {
140
     *
211
        return $this->get_meta_course_customfilter(1);
Línea -... Línea 212...
-
 
212
    }
-
 
213
 
141
     * @return string
214
    /**
-
 
215
     * Returns HTML to display course custom field #2 for filter.
-
 
216
     */
142
     */
217
    public function get_meta_course_customfilter2() {
Línea 143... Línea 218...
143
    public function get_custom_fields(): string {
218
        return $this->get_meta_course_customfilter(2);
-
 
219
    }
-
 
220
 
-
 
221
    /**
-
 
222
     * Returns HTML to display course custom field #3 for filter.
-
 
223
     */
-
 
224
    public function get_meta_course_customfilter3() {
-
 
225
        return $this->get_meta_course_customfilter(3);
-
 
226
    }
-
 
227
 
-
 
228
    /**
-
 
229
     * Returns HTML to display course custom field #4 for filter.
-
 
230
     */
-
 
231
    public function get_meta_course_customfilter4() {
-
 
232
        return $this->get_meta_course_customfilter(4);
-
 
233
    }
-
 
234
 
-
 
235
    /**
-
 
236
     * Returns HTML to display course custom field #5 for filter.
-
 
237
     */
-
 
238
    public function get_meta_course_customfilter5() {
-
 
239
        return $this->get_meta_course_customfilter(5);
-
 
240
    }
144
        if ($this->course->has_custom_fields()) {
241
 
145
            $handler = \core_course\customfield\course_handler::create();
242
    /**
146
 
243
     * Returns HTML to display course custom field #6 for filter.
-
 
244
     */
-
 
245
    public function get_meta_course_customfilter6() {
147
            return $handler->display_custom_fields_data($this->course->get_custom_fields());
246
        return $this->get_meta_course_customfilter(6);
148
        }
247
    }
149
 
248
 
-
 
249
 
-
 
250
    /**
150
        return '';
251
     * Returns HTML to display course category name.
151
    }
252
     *
Línea 152... Línea 253...
152
 
253
     * @return string
153
    /**
254
     *
Línea 154... Línea 255...
154
     * Returns HTML to display course enrolment icons.
255
     * @throws \moodle_exception
155
     *
-
 
156
     * @return array
-
 
157
     */
256
     */
158
    public function get_enrolment_icons(): array {
257
    public function get_category(): string {
159
        if ($icons = enrol_get_course_info_icons($this->course)) {
258
        $cat = core_course_category::get($this->course->category, IGNORE_MISSING);
160
            return $icons;
259
 
161
        }
260
        if (!$cat) {
-
 
261
            return '';
162
 
262
        }
-
 
263
 
-
 
264
        return $cat->get_formatted_name();
-
 
265
    }
-
 
266
 
-
 
267
    /**
-
 
268
     * Returns course summary.
163
        return [];
269
     *
Línea 164... Línea 270...
164
    }
270
     * @param coursecat_helper $chelper
165
 
271
     */
Línea 166... Línea 272...
166
    /**
272
    public function get_summary(coursecat_helper $chelper): string {
167
     * Get the user progress in the course.
-
 
-
 
273
        if ($this->course->has_summary()) {
168
     *
274
            return $chelper->get_course_formatted_summary(
Línea 169... Línea 275...
169
     * @param null $userid
275
                $this->course,
Línea 170... Línea 276...
170
     *
276
                ['overflowdiv' => true, 'noclean' => true, 'para' => false]
171
     * @return mixed
277
            );
Línea 172... Línea 278...
172
     */
278
        }
173
    public function get_progress($userid = null) {
279
 
174
        return \core_completion\progress::get_course_progress_percentage($this->course, $userid);
280
        return false;
175
    }
281
    }
Línea 176... Línea 282...
176
 
282
 
177
    public function course_get_taux() {
283
    public function course_get_taux() {
178
        global $CFG, $COURSE;
-
 
179
 
-
 
Línea 180... Línea 284...
180
        $course = get_course($this->course->id);
284
        global $CFG, $COURSE;
181
 
285
 
182
        $courseelement = new \core_course_list_element($course);
286
        $course = get_course($this->course->id);
Línea 183... Línea -...
183
 
-
 
184
        if ($courseelement->has_custom_fields()) {
-
 
185
 
287
        $customfieldvalue = null;
186
            $fields = $courseelement->get_custom_fields();
288
        $courseelement = new \core_course_list_element($course);
187
            $content = '';
-
 
188
 
289
 
-
 
290
        if ($courseelement->has_custom_fields()) {
-
 
291
 
-
 
292
            $fields = $courseelement->get_custom_fields();
-
 
293
            $content = '';
-
 
294
 
-
 
295
            foreach ($fields as $field) {
-
 
296
                if (empty($field->get_value())) {
-
 
297
                    continue;
-
 
298
                }
-
 
299
 
-
 
300
                // Get field shortname
-
 
301
                $customfieldname = $field->get_field()->get('name');
-
 
302
 
-
 
303
                switch ($field->get_field()->get('type')) {
-
 
304
                    case 'select':
-
 
305
                        $value = $field->get_value();
-
 
306
 
-
 
307
                        if ($value != null) {
-
 
308
                            $customfieldvalue = null;
-
 
309
                        }
-
 
310
 
-
 
311
                        $options = $field->get_field()->get_options();
-
 
312
                        if (array_key_exists($value, $options)) {
-
 
313
                            $customfieldvalue = format_string(
-
 
314
                                $options[$value],
-
 
315
                                true,
-
 
316
                                ['context' => $field->get_field()->get_handler()->get_configuration_context()]
-
 
317
                            );
-
 
318
                        }
-
 
319
                        break;
-
 
320
                    default:
-
 
321
                        $customfieldvalue = $field->get_value();
-
 
322
                        break;
-
 
323
                }
-
 
324
                
-
 
325
                $customfieldshortname =  $field->get_field()->get('shortname');
-
 
326
 
-
 
327
                // Array with custom fields which need to be hidden.
-
 
328
                $hiddencustomfields = array(
-
 
329
                    "enrolldesc",
-
 
330
                    "enrollvideo",
-
 
331
                    "customcoursefavicon",
-
 
332
                    "topbarcolor",
189
            foreach ($fields as $field) { 
333
                    "dmtopbarcolor",
-
 
334
                    "maincolor1",
-
 
335
                    "maincolor2",
-
 
336
                    "customcourselogo",
-
 
337
                    "customcoursedmlogo",
-
 
338
                    "footercolor",
-
 
339
                    "topbartextcolor",
-
 
340
                    "topbarbghovercolor",
-
 
341
                    "topbartexthovercolor",
190
                if (empty($field->get_value())) {
342
                    "dmtopbartextcolor",
-
 
343
                    "dmtopbarbghovercolor",
191
                    continue;
344
                    "dmtopbartexthovercolor",
192
                }
345
                    "topbarcolor2",
193
 
346
                    "dmtopbarcolor2"
194
                // Get field shortname
347
                );
195
                $customfieldname = $field->get_field()->get('name');
348
                $hiddencftitles = ["tool_courserating"];
196
                $customfieldvalue = $field->get_value();
349
 
197
                $customfieldshortname =  $field->get_field()->get('shortname');
350
                if (!in_array($customfieldshortname, $hiddencustomfields)) {
198
 
351
                    $content .= html_writer::start_tag('div', ['class' => 'rui-custom-field-box rui-cf-' . $customfieldshortname]);
-
 
352
                    if (!in_array($customfieldshortname, $hiddencftitles)) {
-
 
353
                        $content .= html_writer::tag(
-
 
354
                            'div',
-
 
355
                            format_string($customfieldname),
-
 
356
                            array('class' => 'rui-custom-field-name rui-custom-field-' . $customfieldshortname)
-
 
357
                        );
-
 
358
                    }
-
 
359
                    $content .= html_writer::tag(
-
 
360
                        'div',
-
 
361
                        format_string($customfieldvalue),
-
 
362
                        ['class' => 'rui-custom-field-value']
-
 
363
                    );
-
 
364
                    $content .= html_writer::end_tag('div');
-
 
365
                }
-
 
366
            }
-
 
367
            return $content;
-
 
368
        } else {
-
 
369
            return false;
-
 
370
        }
-
 
371
    }
-
 
372
 
-
 
373
 
-
 
374
    /**
-
 
375
     * Returns HTML to display course enrolment icons.
-
 
376
     *
199
                // Array with custom fields which need to be hidden.
377
     * @return array