Proyectos de Subversion Moodle

Rev

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

Rev 1 Rev 1093
Línea 19... Línea 19...
19
 *
19
 *
20
 * @package    core_course
20
 * @package    core_course
21
 * @copyright  2015 Damyon Wiese
21
 * @copyright  2015 Damyon Wiese
22
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
22
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 */
23
 */
-
 
24
 
24
namespace core_course\external;
25
namespace core_course\external;
-
 
26
 
25
defined('MOODLE_INTERNAL') || die();
27
defined('MOODLE_INTERNAL') || die();
Línea 26... Línea 28...
26
 
28
 
27
use renderer_base;
29
use renderer_base;
Línea 31... Línea 33...
31
 * Class for exporting a course summary from an stdClass.
33
 * Class for exporting a course summary from an stdClass.
32
 *
34
 *
33
 * @copyright  2015 Damyon Wiese
35
 * @copyright  2015 Damyon Wiese
34
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
36
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
35
 */
37
 */
36
class course_summary_exporter extends \core\external\exporter {
38
class course_summary_exporter extends \core\external\exporter
-
 
39
{
Línea 37... Línea 40...
37
 
40
 
38
    /**
41
    /**
39
     * Constructor - saves the persistent object, and the related objects.
42
     * Constructor - saves the persistent object, and the related objects.
40
     *
43
     *
41
     * @param mixed $data - Either an stdClass or an array of values.
44
     * @param mixed $data - Either an stdClass or an array of values.
42
     * @param array $related - An optional list of pre-loaded objects related to this object.
45
     * @param array $related - An optional list of pre-loaded objects related to this object.
43
     */
46
     */
-
 
47
    public function __construct($data, $related = array())
44
    public function __construct($data, $related = array()) {
48
    {
45
        if (!array_key_exists('isfavourite', $related)) {
49
        if (!array_key_exists('isfavourite', $related)) {
46
            $related['isfavourite'] = false;
50
            $related['isfavourite'] = false;
47
        }
51
        }
48
        parent::__construct($data, $related);
52
        parent::__construct($data, $related);
Línea 49... Línea 53...
49
    }
53
    }
-
 
54
 
50
 
55
    protected static function define_related()
51
    protected static function define_related() {
56
    {
52
        // We cache the context so it does not need to be retrieved from the course.
57
        // We cache the context so it does not need to be retrieved from the course.
Línea 53... Línea 58...
53
        return array('context' => '\\context', 'isfavourite' => 'bool?');
58
        return array('context' => '\\context', 'isfavourite' => 'bool?');
-
 
59
    }
54
    }
60
 
55
 
61
    protected function get_other_values(renderer_base $output)
56
    protected function get_other_values(renderer_base $output) {
62
    {
57
        global $CFG;
63
        global $CFG;
58
        $courseimage = self::get_course_image($this->data);
64
        $courseimage = self::get_course_image($this->data);
Línea 77... Línea 83...
77
            'showshortname' => $CFG->courselistshortnames ? true : false,
83
            'showshortname' => $CFG->courselistshortnames ? true : false,
78
            'coursecategory' => $coursecategory->name
84
            'coursecategory' => $coursecategory->name
79
        );
85
        );
80
    }
86
    }
Línea 81... Línea 87...
81
 
87
 
-
 
88
    public static function define_properties()
82
    public static function define_properties() {
89
    {
83
        return array(
90
        return array(
84
            'id' => array(
91
            'id' => array(
85
                'type' => PARAM_INT,
92
                'type' => PARAM_INT,
86
            ),
93
            ),
Línea 130... Línea 137...
130
    /**
137
    /**
131
     * Get the formatting parameters for the summary.
138
     * Get the formatting parameters for the summary.
132
     *
139
     *
133
     * @return array
140
     * @return array
134
     */
141
     */
135
    protected function get_format_parameters_for_summary() {
142
    protected function get_format_parameters_for_summary()
-
 
143
    {
136
        return [
144
        return [
137
            'component' => 'course',
145
            'component' => 'course',
138
            'filearea' => 'summary',
146
            'filearea' => 'summary',
139
        ];
147
        ];
140
    }
148
    }
Línea 141... Línea 149...
141
 
149
 
-
 
150
    public static function define_other_properties()
142
    public static function define_other_properties() {
151
    {
143
        return array(
152
        return array(
144
            'fullnamedisplay' => array(
153
            'fullnamedisplay' => array(
145
                'type' => PARAM_TEXT,
154
                'type' => PARAM_TEXT,
146
            ),
155
            ),
Línea 180... Línea 189...
180
     * Get the course image if added to course.
189
     * Get the course image if added to course.
181
     *
190
     *
182
     * @param object $course
191
     * @param object $course
183
     * @return string|false url of course image or false if it's not exist.
192
     * @return string|false url of course image or false if it's not exist.
184
     */
193
     */
185
    public static function get_course_image($course) {
194
    public static function get_course_image($course)
-
 
195
    {
186
        $image = \cache::make('core', 'course_image')->get($course->id);
196
        $image = \cache::make('core', 'course_image')->get($course->id);
Línea 187... Línea 197...
187
 
197
 
188
        if (is_null($image)) {
198
        if (is_null($image)) {
189
            $image = false;
199
            $image = false;
Línea 198... Línea 208...
198
     * The datauri is an encoded svg that can be passed as a url.
208
     * The datauri is an encoded svg that can be passed as a url.
199
     * @param object $course
209
     * @param object $course
200
     * @return string datauri
210
     * @return string datauri
201
     * @deprecated 3.7
211
     * @deprecated 3.7
202
     */
212
     */
203
    public static function get_course_pattern($course) {
213
    public static function get_course_pattern($course)
-
 
214
    {
204
        global $OUTPUT;
215
        global $OUTPUT;
205
        debugging('course_summary_exporter::get_course_pattern() is deprecated. ' .
216
        debugging('course_summary_exporter::get_course_pattern() is deprecated. ' .
206
            'Please use $OUTPUT->get_generated_image_for_id() instead.', DEBUG_DEVELOPER);
217
            'Please use $OUTPUT->get_generated_image_for_id() instead.', DEBUG_DEVELOPER);
207
        return $OUTPUT->get_generated_image_for_id($course->id);
218
        return $OUTPUT->get_generated_image_for_id($course->id);
208
    }
219
    }
Línea 211... Línea 222...
211
     * Get the course progress percentage.
222
     * Get the course progress percentage.
212
     *
223
     *
213
     * @param object $course
224
     * @param object $course
214
     * @return int progress
225
     * @return int progress
215
     */
226
     */
216
    public static function get_course_progress($course) {
227
    public static function get_course_progress($course)
-
 
228
    {
217
        return \core_completion\progress::get_course_progress_percentage($course);
229
        return \core_completion\progress::get_course_progress_percentage($course);
218
    }
230
    }
Línea 219... Línea 231...
219
 
231
 
220
    /**
232
    /**
221
     * Get the course color.
233
     * Get the course color.
222
     *
234
     *
223
     * @param int $courseid
235
     * @param int $courseid
224
     * @return string hex color code.
236
     * @return string hex color code.
225
     * @deprecated 3.7
237
     * @deprecated 3.7
226
     */
238
     */
-
 
239
    public static function coursecolor($courseid)
227
    public static function coursecolor($courseid) {
240
    {
228
        global $OUTPUT;
241
        global $OUTPUT;
229
        debugging('course_summary_exporter::coursecolor() is deprecated. ' .
242
        debugging('course_summary_exporter::coursecolor() is deprecated. ' .
230
            'Please use $OUTPUT->get_generated_color_for_id() instead.', DEBUG_DEVELOPER);
243
            'Please use $OUTPUT->get_generated_color_for_id() instead.', DEBUG_DEVELOPER);
231
        return $OUTPUT->get_generated_color_for_id($courseid);
244
        return $OUTPUT->get_generated_color_for_id($courseid);