aboutsummaryrefslogtreecommitdiff
path: root/lib/models/Courseware/ContainerTypes/TabsContainer.php
blob: 66a56b8f8846322b8626a65798ddec1f100362ec (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
<?php

namespace Courseware\ContainerTypes;

/**
 * This class represents the content of a Courseware tabs container stored in payload.
 *
 * @author  Marcus Eibrink-Lunzenauer <lunzenauer@elan-ev.de>
 * @license GPL2 or any later version
 *
 * @since   Stud.IP 5.0
 */
class TabsContainer extends ContainerType
{
    public static function getType(): string
    {
        return 'tabs';
    }

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

    public static function getDescription(): string
    {
        return _('Dieser Abschnitt verfügt über eine horizontale Navigation, '
                . 'über die sich Gruppen von Blöcken erreichen lassen.');
    }

    public function initialPayload(): array
    {
        return [
            'colspan' => 'full',
            'sections' => [
                'name' => _('neuer Tab'),
                'icon' => '',
                'blocks' => [],
            ],
        ];
    }

    public function addBlock($block, $sectionIndex = null): void
    {
        $payload = $this->getPayload();
        if ($sectionIndex !== null) {
            array_push($payload['sections'][$sectionIndex]['blocks'], $block->id);
        } else {
            array_push($payload['sections'][count($payload['sections']) - 1]['blocks'], $block->id);
        }

        $this->setPayload($payload);
    }

    public static function getJsonSchema(): string
    {
        $schemaFile = __DIR__.'/TabsContainer.json';
        return file_get_contents($schemaFile);
    }
}