aboutsummaryrefslogtreecommitdiff
path: root/lib/models/Courseware/BlockTypes/Download.php
blob: 00f424c485ba9b4ef73d4ace48a59e1dac8708f5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<?php

namespace Courseware\BlockTypes;

/**
 * This class represents the content of a Courseware download block.
 *
 * @author  Ron Lucke <lucke@elan-ev.de>
 * @license GPL2 or any later version
 *
 * @since   Stud.IP 5.0
 */
class Download extends BlockType
{
    public static function getType(): string
    {
        return 'download';
    }

    public static function getTitle(): string
    {
        return _('Download');
    }

    public static function getDescription(): string
    {
        return _('Stellt eine Datei aus dem Dateibereich zum Download bereit.');
    }

    public function initialPayload(): array
    {
        return [
            'title' => '',
            'info' => '',
            'success' => '',
            'grade' => false,
            'file_id' => '',
        ];
    }

    /**
     * get all files related to this bloc.
     *
     * @return \FileRef[] list of file references realted to this block
     */
    public function getFiles(): array
    {
        $payload = $this->getPayload();
        if (!$payload['file_id']) {
            return [];
        }

        $files = [];

        if ($fileRef = \FileRef::find($payload['file_id'])) {
            $files[] = $fileRef;
        }

        return $files;
    }

    public function copyPayload(string $rangeId = ''): array
    {
        $payload = $this->getPayload();

        if ('' != $payload['file_id']) {
            $payload['file_id'] = $this->copyFileById($payload['file_id'], $rangeId);
        }

        return $payload;
    }

    public static function getJsonSchema(): string
    {
        $schemaFile = __DIR__.'/Download.json';

        return file_get_contents($schemaFile);
    }

    public static function getCategories(): array
    {
        return ['files'];
    }

    public static function getContentTypes(): array
    {
        return ['files'];
    }

    public static function getFileTypes(): array
    {
        return ['all'];
    }

    public static function getTags(): array
    {
        return [
            _('Dateiliste'), _('Dateiablage'), _('Datei'), _('Teilen'), _('Ablegen'),
            _('Upload'), _('Skript'), ('Herunterladen'), _('Medien'), _('Material'),
            _('Filesharing'), _('Hochladen'), _('Dokument'), _('Dateibereich'), 'pdf',
            'ppt', 'doc', 'xls', 'odt', 'ods', 'odp', 'PowerPoint',
            'Word', 'Excel', 'LibreOffice', 'OpenOffice', _('Präsentation'),
            _('Sicherung'), _('Literatur'), _('Zusatzmaterial'), _('Semesterapparat'),
            _('Infomaterial')
        ];
    }
}