Passed
Push — master ( f19b34...1fcb39 )
by Yannick
07:53 queued 01:16
created

AbstractTool::getTitle()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
/* For licensing terms, see /license.txt */
6
7
namespace Chamilo\CoreBundle\Tool;
8
9
use Sylius\Bundle\SettingsBundle\Schema\SchemaInterface;
10
use Symfony\Component\Serializer\Annotation\Groups;
11
12
abstract class AbstractTool
13
{
14
    #[Groups(['ctool:read'])]
15
    protected string $title;
16
17
    #[Groups(['ctool:read'])]
18
    protected string $titleToShow = '';
19
20
    #[Groups(['ctool:read'])]
21
    protected string $icon = '';
22
23
    #[Groups(['ctool:read'])]
24
    protected string $category = '';
25
    protected string $link;
26
    protected string $image;
27
    protected string $admin;
28
    protected ?SchemaInterface $settings = null;
29
    protected array $resourceTypes = [];
30
31
    /**
32
     * Tool scope.
33
     *
34
     * Values can be the following.
35
     *
36
     * - 00 disabled tool
37
     * - 01 course tool
38
     * - 10 global tool
39
     * - 11 global or course or both
40
     */
41
    protected string $scope;
42
43
    abstract public function getCategory(): string;
44
    abstract public function getLink(): string;
45
46
    /*public function __construct(
47
        string $title,
48
        string $category,
49
        string $link,
50
        ?SchemaInterface $settings = null,
51
        ?array $resourceTypes = []
52
    ) {
53
        $this->title = $title;
54
        $this->titleToShow = $title;
55
        $this->category = $category;
56
        $this->link = $link;
57
        $this->image = $title.'.png';
58
        $this->settings = $settings;
59
        $this->resourceTypes = $resourceTypes;
60
        $this->icon = 'mdi-crop-square';
61
    }*/
62
63
    public function isCourseTool(): bool
64
    {
65
        return false;
66
    }
67
68
    public function isGlobal(): bool
69
    {
70
        return true;
71
    }
72
73
    public function getTitle(): string
74
    {
75
        return $this->title;
76
    }
77
78
    public function getTarget(): string
79
    {
80
        return '_self';
81
    }
82
83
    public function getImage(): string
84
    {
85
        return $this->image;
86
    }
87
88
    public function getEntityByResourceType(string $type): ?string
89
    {
90
        return $this->getResourceTypes()[$type] ?? null;
91
    }
92
93
    public function getTypeNameByEntity(string $entityClass): ?string
94
    {
95
        if (empty($this->getResourceTypes())) {
96
            return null;
97
        }
98
99
        $list = array_flip($this->getResourceTypes());
100
101
        if (isset($list[$entityClass])) {
102
            return $list[$entityClass];
103
        }
104
105
        return null;
106
    }
107
108
    public function getResourceTypes(): ?array
109
    {
110
        return $this->resourceTypes;
111
    }
112
113
    public function setResourceTypes(?array $resourceTypes): self
114
    {
115
        $this->resourceTypes = $resourceTypes;
116
117
        return $this;
118
    }
119
120
    public function getTitleToShow(): string
121
    {
122
        // return $this->getTitle();
123
        return ucfirst(str_replace('_', ' ', $this->getTitle()));
124
    }
125
126
    public function setTitleToShow(string $titleToShow): self
127
    {
128
        $this->titleToShow = $titleToShow;
129
130
        return $this;
131
    }
132
}
133