Proyectos de Subversion Moodle

Rev

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

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