Proyectos de Subversion Moodle

Rev

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

Rev 1 Rev 1441
Línea 55... Línea 55...
55
    /**
55
    /**
56
     * Content type constructor
56
     * Content type constructor
57
     *
57
     *
58
     * @param \context $context Optional context to check (default null)
58
     * @param \context $context Optional context to check (default null)
59
     */
59
     */
60
    public function __construct(\context $context = null) {
60
    public function __construct(?\context $context = null) {
61
        if (empty($context)) {
61
        if (empty($context)) {
62
            $context = \context_system::instance();
62
            $context = \context_system::instance();
63
        }
63
        }
64
        $this->context = $context;
64
        $this->context = $context;
65
    }
65
    }
Línea 69... Línea 69...
69
     *
69
     *
70
     * @throws dml_exception A DML specific exception is thrown for any creation error.
70
     * @throws dml_exception A DML specific exception is thrown for any creation error.
71
     * @param \stdClass $record An optional content record compatible object (default null)
71
     * @param \stdClass $record An optional content record compatible object (default null)
72
     * @return content  Object with content bank information.
72
     * @return content  Object with content bank information.
73
     */
73
     */
74
    public function create_content(\stdClass $record = null): content {
74
    public function create_content(?\stdClass $record = null): content {
75
        global $USER, $DB, $CFG;
75
        global $USER, $DB, $CFG;
Línea 76... Línea 76...
76
 
76
 
77
        $entry = new \stdClass();
77
        $entry = new \stdClass();
78
        if (isset($record->visibility)) {
78
        if (isset($record->visibility)) {
Línea 107... Línea 107...
107
     * @throws dml_exception if the content creation fails
107
     * @throws dml_exception if the content creation fails
108
     * @param stored_file $file the uploaded file
108
     * @param stored_file $file the uploaded file
109
     * @param \stdClass|null $record an optional content record
109
     * @param \stdClass|null $record an optional content record
110
     * @return content  Object with content bank information.
110
     * @return content  Object with content bank information.
111
     */
111
     */
112
    public function upload_content(stored_file $file, \stdClass $record = null): content {
112
    public function upload_content(stored_file $file, ?\stdClass $record = null): content {
113
        if (empty($record)) {
113
        if (empty($record)) {
114
            $record = new \stdClass();
114
            $record = new \stdClass();
115
            $record->name = $file->get_filename();
115
            $record->name = $file->get_filename();
116
        }
116
        }
117
        $content = $this->create_content($record);
117
        $content = $this->create_content($record);
Línea 236... Línea 236...
236
     *
236
     *
237
     * @param  content $content The content to be displayed.
237
     * @param  content $content The content to be displayed.
238
     * @return string           HTML code to include in view.php.
238
     * @return string           HTML code to include in view.php.
239
     */
239
     */
240
    public function get_view_content(content $content): string {
240
    public function get_view_content(content $content): string {
-
 
241
        global $PAGE;
-
 
242
 
241
        // Trigger an event for viewing this content.
243
        // Trigger an event for viewing this content.
242
        $event = contentbank_content_viewed::create_from_record($content->get_content());
244
        $event = contentbank_content_viewed::create_from_record($content->get_content());
243
        $event->trigger();
245
        $event->trigger();
Línea -... Línea 246...
-
 
246
 
-
 
247
        if ($content->has_custom_fields()) {
-
 
248
            $renderer = $PAGE->get_renderer('core');
-
 
249
            $renderable = new \core_contentbank\output\customfields($content);
-
 
250
            return $renderer->render($renderable);
244
 
251
        }
245
        return '';
252
        return '';
Línea 246... Línea 253...
246
    }
253
    }
247
 
254