Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 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
 * Course class utility class
19
 *
20
 * @package   theme_monocolor
21
 * @copyright 2022 - 2023 Marcin Czaja (https://rosea.io)
22
 * @license   Commercial https://themeforest.net/licenses
23
 */
24
 
25
namespace theme_monocolor\util;
26
 
27
use moodle_url;
28
use core_course_list_element;
29
use coursecat_helper;
30
use core_course_category;
31
use html_writer;
32
use context_course;
33
 
34
/**
35
 * Course class utility class
36
 *
37
 * @package   theme_monocolor
38
 * @copyright 2022 - 2023 Marcin Czaja (https://rosea.io)
39
 * @license   Commercial https://themeforest.net/licenses
40
 */
41
class course {
42
    /**
43
     * @var \stdClass $course The course object.
44
     */
45
    protected $course;
46
 
47
    /**
48
     * Class constructor
49
     *
50
     * @param core_course_list_element $course
51
     *
52
     */
53
    public function __construct($course) {
54
        $this->course = $course;
55
    }
56
 
57
    /**
58
     * Returns the first course's summary image url
59
     *
60
     * @return string
61
     */
62
    public function get_summary_image() {
63
        global $CFG, $OUTPUT;
64
 
65
        foreach ($this->course->get_course_overviewfiles() as $file) {
66
            if ($file->is_valid_image()) {
67
                $url = moodle_url::make_file_url("$CFG->wwwroot/pluginfile.php",
68
                    '/' . $file->get_contextid() . '/' . $file->get_component() . '/' .
69
                    $file->get_filearea() . $file->get_filepath() . $file->get_filename(), !$file->is_valid_image());
70
 
71
                return $url->out();
72
            }
73
        }
74
 
75
        return $OUTPUT->get_generated_image_for_id($this->course->id);
76
    }
77
 
78
    /**
79
     * Returns HTML to display course contacts.
80
     *
81
     * @return array
82
     */
83
    public function get_course_contacts() {
84
        $theme = \theme_config::load('monocolor');
85
 
86
        $contacts = [];
87
        if ($this->course->has_course_contacts() && $theme->settings->cccteachers == 1) {
88
            $instructors = $this->course->get_course_contacts();
89
 
90
            foreach ($instructors as $instructor) {
91
                $user = $instructor['user'];
92
                $userutil = new user($user->id);
93
 
94
                $contacts[] = [
95
                    'id' => $user->id,
96
                    'fullname' => fullname($user),
97
                    'userpicture' => $userutil->get_user_picture(),
98
                    'role' => $instructor['role']->displayname
99
                ];
100
            }
101
        }
102
 
103
        return $contacts;
104
    }
105
 
106
    /**
107
     * Returns HTML to display course category name.
108
     *
109
     * @return string
110
     *
111
     * @throws \moodle_exception
112
     */
113
    public function get_category(): string {
114
        $cat = core_course_category::get($this->course->category, IGNORE_MISSING);
115
 
116
        if (!$cat) {
117
            return '';
118
        }
119
 
120
        return $cat->get_formatted_name();
121
    }
122
 
123
    /**
124
     * Returns course summary.
125
     *
126
     * @param coursecat_helper $chelper
127
     */
128
    public function get_summary(coursecat_helper $chelper): string {
129
        if ($this->course->has_summary()) {
130
            return $chelper->get_course_formatted_summary($this->course,
131
                ['overflowdiv' => true, 'noclean' => true, 'para' => false]
132
            );
133
        }
134
 
135
        return false;
136
    }
137
 
138
    /**
139
     * Returns course custom fields.
140
     *
141
     * @return string
142
     */
143
    public function get_custom_fields(): string {
144
        if ($this->course->has_custom_fields()) {
145
            $handler = \core_course\customfield\course_handler::create();
146
 
147
            return $handler->display_custom_fields_data($this->course->get_custom_fields());
148
        }
149
 
150
        return '';
151
    }
152
 
153
    /**
154
     * Returns HTML to display course enrolment icons.
155
     *
156
     * @return array
157
     */
158
    public function get_enrolment_icons(): array {
159
        if ($icons = enrol_get_course_info_icons($this->course)) {
160
            return $icons;
161
        }
162
 
163
        return [];
164
    }
165
 
166
    /**
167
     * Get the user progress in the course.
168
     *
169
     * @param null $userid
170
     *
171
     * @return mixed
172
     */
173
    public function get_progress($userid = null) {
174
        return \core_completion\progress::get_course_progress_percentage($this->course, $userid);
175
    }
176
 
177
    public function course_get_taux() {
178
        global $CFG, $COURSE;
179
 
180
        $course = get_course($this->course->id);
181
 
182
        $courseelement = new \core_course_list_element($course);
183
 
184
        if ($courseelement->has_custom_fields()) {
185
 
186
            $fields = $courseelement->get_custom_fields();
187
            $content = '';
188
 
189
            foreach ($fields as $field) {
190
                if (empty($field->get_value())) {
191
                    continue;
192
                }
193
 
194
                // Get field shortname
195
                $customfieldname = $field->get_field()->get('name');
196
                $customfieldvalue = $field->get_value();
197
                $customfieldshortname =  $field->get_field()->get('shortname');
198
 
199
                // Array with custom fields which need to be hidden.
200
                $hiddencustomfields = array("enrolldesc", "enrollvideo");
201
                $hiddencftitles = array("tool_courserating");
202
 
203
                if(!in_array($customfieldshortname, $hiddencustomfields)) {
204
                    $content .= html_writer::start_tag('div', array('class' => 'rui-custom-field-box rui-cf-' . $customfieldshortname));
205
                        if (!in_array($customfieldshortname, $hiddencftitles)) {
206
                            $content .= html_writer::tag('div', $customfieldname,
207
                                array('class' => 'rui-custom-field-name rui-custom-field-' . $customfieldshortname));
208
                        }
209
                        $content .= html_writer::tag('div', $customfieldvalue,
210
                            array('class' => 'rui-custom-field-value'));
211
                    $content .= html_writer::end_tag('div');
212
                }
213
            }
214
            return $content;
215
        } else {
216
            return false;
217
        }
218
    }
219
}