Passed
Push — dependabot/npm_and_yarn/nanoid... ( aaf2c9...c4aa90 )
by
unknown
14:37 queued 06:22
created

Language::setIsocode()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 5
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\Entity;
8
9
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
10
use ApiPlatform\Doctrine\Orm\Filter\BooleanFilter;
11
use ApiPlatform\Metadata\ApiFilter;
12
use ApiPlatform\Metadata\ApiResource;
13
use Chamilo\CoreBundle\Repository\LanguageRepository;
14
use Doctrine\Common\Collections\ArrayCollection;
15
use Doctrine\Common\Collections\Collection;
16
use Doctrine\ORM\Mapping as ORM;
17
use Symfony\Component\Serializer\Annotation\Groups;
18
use Symfony\Component\Validator\Constraints as Assert;
19
20
/**
21
 * Platform languages.
22
 */
23
#[ApiResource(paginationEnabled: false)]
24
#[ApiFilter(BooleanFilter::class, properties: ['available'])]
25
#[ApiFilter(OrderFilter::class, properties: ['english_name' => 'DESC'])]
26
#[ORM\Table(name: 'language', options: ['row_format' => 'DYNAMIC'])]
27
#[ORM\Entity(repositoryClass: LanguageRepository::class)]
28
class Language
29
{
30
    #[Groups(['language:read'])]
31
    #[ORM\Column(name: 'id', type: 'integer')]
32
    #[ORM\Id]
33
    #[ORM\GeneratedValue]
34
    protected ?int $id = null;
35
36
    #[Groups(['language:read', 'language:write'])]
37
    #[Assert\NotBlank]
38
    #[ORM\Column(name: 'original_name', type: 'string', length: 255, nullable: true)]
39
    protected ?string $originalName = null;
40
41
    #[Groups(['language:read', 'language:write'])]
42
    #[Assert\NotBlank]
43
    #[ORM\Column(name: 'english_name', type: 'string', length: 255)]
44
    protected string $englishName;
45
46
    #[Groups(['language:read', 'language:write'])]
47
    #[Assert\NotBlank]
48
    #[ORM\Column(name: 'isocode', type: 'string', length: 10)]
49
    protected string $isocode;
50
51
    #[Groups(['language:read', 'language:write'])]
52
    #[ORM\Column(name: 'available', type: 'boolean', nullable: false)]
53
    protected bool $available;
54
55
    #[ORM\ManyToOne(targetEntity: self::class, inversedBy: 'subLanguages')]
56
    #[ORM\JoinColumn(name: 'parent_id', referencedColumnName: 'id', nullable: true)]
57
    protected ?Language $parent = null;
58
59
    /**
60
     * @var Collection<int, self>
61
     */
62
    #[Groups(['language:read', 'language:write'])]
63
    #[ORM\OneToMany(mappedBy: 'parent', targetEntity: self::class)]
64
    protected Collection $subLanguages;
65
66
    public function __construct()
67
    {
68
        $this->subLanguages = new ArrayCollection();
69
    }
70
71
    public function setOriginalName(string $originalName): self
72
    {
73
        $this->originalName = $originalName;
74
75
        return $this;
76
    }
77
78
    public function getOriginalName(): string
79
    {
80
        return $this->originalName;
81
    }
82
83
    public function setEnglishName(string $englishName): self
84
    {
85
        $this->englishName = $englishName;
86
87
        return $this;
88
    }
89
90
    public function getEnglishName(): string
91
    {
92
        return $this->englishName;
93
    }
94
95
    public function setIsocode(string $isocode): self
96
    {
97
        $this->isocode = $isocode;
98
99
        return $this;
100
    }
101
102
    public function getIsocode(): string
103
    {
104
        return $this->isocode;
105
    }
106
107
    public function setAvailable(bool $available): self
108
    {
109
        $this->available = $available;
110
111
        return $this;
112
    }
113
114
    public function getAvailable(): bool
115
    {
116
        return $this->available;
117
    }
118
119
    public function setParent(?self $parent): static
120
    {
121
        $this->parent = $parent;
122
123
        return $this;
124
    }
125
126
    public function getParent(): ?static
0 ignored issues
show
Bug introduced by
A parse error occurred: Syntax error, unexpected T_STATIC on line 126 at column 34
Loading history...
127
    {
128
        return $this->parent;
129
    }
130
131
    /**
132
     * @return Collection<int, self>
133
     */
134
    public function getSubLanguages(): Collection
135
    {
136
        return $this->subLanguages;
137
    }
138
139
    /**
140
     * Get id.
141
     *
142
     * @return int
143
     */
144
    public function getId()
145
    {
146
        return $this->id;
147
    }
148
149
    public function addSubLanguage(self $subLanguage): static
150
    {
151
        if (!$this->subLanguages->contains($subLanguage)) {
152
            $this->subLanguages->add($subLanguage);
153
            $subLanguage->setParent($this);
154
        }
155
156
        return $this;
157
    }
158
159
    public function removeSub(self $sub): static
160
    {
161
        if ($this->subLanguages->removeElement($sub)) {
162
            // set the owning side to null (unless already changed)
163
            if ($sub->getParent() === $this) {
164
                $sub->setParent(null);
165
            }
166
        }
167
168
        return $this;
169
    }
170
}
171