Passed
Push — master ( 727abb...ceefce )
by Yannick
07:55 queued 14s
created

CTool::getVisibility()   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
/* For licensing terms, see /license.txt */
4
5
declare(strict_types=1);
6
7
namespace Chamilo\CourseBundle\Entity;
8
9
use ApiPlatform\Doctrine\Orm\Filter\OrderFilter;
10
use ApiPlatform\Metadata\ApiFilter;
11
use ApiPlatform\Metadata\ApiResource;
12
use ApiPlatform\Metadata\GetCollection;
13
use Chamilo\CoreBundle\ApiResource\CourseTool;
14
use Chamilo\CoreBundle\Entity\AbstractResource;
15
use Chamilo\CoreBundle\Entity\Course;
16
use Chamilo\CoreBundle\Entity\ResourceInterface;
17
use Chamilo\CoreBundle\Entity\ResourceShowCourseResourcesInSessionInterface;
18
use Chamilo\CoreBundle\Entity\Session;
19
use Chamilo\CoreBundle\Entity\Tool;
20
use Chamilo\CoreBundle\Filter\CidFilter;
21
use Chamilo\CoreBundle\Filter\SidFilter;
22
use Chamilo\CoreBundle\State\CToolProvider;
23
use Chamilo\CourseBundle\Repository\CToolRepository;
24
use Doctrine\ORM\Mapping as ORM;
25
use Gedmo\Mapping\Annotation as Gedmo;
26
use Stringable;
27
use Symfony\Component\Validator\Constraints as Assert;
28
29
#[ApiResource(
30
    operations: [
31
        new GetCollection(),
32
    ],
33
    normalizationContext: ['groups' => ['ctool:read']],
34
    output: CourseTool::class,
35
    provider: CToolProvider::class,
36
)]
37
#[ORM\Table(name: 'c_tool')]
38
#[ORM\Index(columns: ['c_id'], name: 'course')]
39
#[ORM\Index(columns: ['session_id'], name: 'session_id')]
40
#[ORM\HasLifecycleCallbacks]
41
#[ORM\Entity(repositoryClass: CToolRepository::class)]
42
#[ApiFilter(CidFilter::class)]
43
#[ApiFilter(SidFilter::class)]
44
#[ApiFilter(OrderFilter::class, properties: ['position' => 'ASC'])]
45
class CTool extends AbstractResource implements ResourceInterface, ResourceShowCourseResourcesInSessionInterface, Stringable
46
{
47
    #[ORM\Column(name: 'iid', type: 'integer')]
48
    #[ORM\Id]
49
    #[ORM\GeneratedValue]
50
    protected ?int $iid = null;
51
52
    #[Assert\NotBlank]
53
    #[Groups(['ctool:read'])]
54
    #[ORM\Column(name: 'title', type: 'text', nullable: false)]
55
    protected string $title;
56
57
    #[ORM\Column(name: 'visibility', type: 'boolean', nullable: true)]
58
    protected ?bool $visibility = null;
59
60
    #[ORM\ManyToOne(targetEntity: Course::class, inversedBy: 'tools')]
61
    #[ORM\JoinColumn(name: 'c_id', referencedColumnName: 'id', nullable: false, onDelete: 'CASCADE')]
62
    #[Gedmo\SortableGroup]
63
    protected Course $course;
64
65
    #[ORM\ManyToOne(targetEntity: Session::class)]
66
    #[ORM\JoinColumn(name: 'session_id', referencedColumnName: 'id', nullable: true, onDelete: 'CASCADE')]
67
    #[Gedmo\SortableGroup]
68
    protected ?Session $session = null;
69
70
    #[ORM\ManyToOne(targetEntity: Tool::class)]
71
    #[ORM\JoinColumn(name: 'tool_id', referencedColumnName: 'id', nullable: false)]
72
    protected Tool $tool;
73
74
    #[Gedmo\SortablePosition]
75
    #[ORM\Column(name: 'position', type: 'integer')]
76
    protected int $position;
77
78
    public function __construct()
79
    {
80
        $this->visibility = true;
81
        $this->position = 0;
82
    }
83
84
    public function __toString(): string
85
    {
86
        return $this->getTitle();
87
    }
88
89
    public function getNameToTranslate(): string
90
    {
91
        return ucfirst(str_replace('_', ' ', $this->title));
92
    }
93
94
    public function getTitle(): string
95
    {
96
        return $this->title;
97
    }
98
99
    public function setTitle(string $title): self
100
    {
101
        $this->title = $title;
102
103
        return $this;
104
    }
105
106
    public function getIid(): ?int
107
    {
108
        return $this->iid;
109
    }
110
111
    public function getCourse(): Course
112
    {
113
        return $this->course;
114
    }
115
116
    public function setCourse(Course $course): self
117
    {
118
        $this->course = $course;
119
120
        return $this;
121
    }
122
123
    public function getSession(): ?Session
124
    {
125
        return $this->session;
126
    }
127
128
    public function setSession(Session $session = null): self
129
    {
130
        $this->session = $session;
131
132
        return $this;
133
    }
134
135
    public function getVisibility(): ?bool
136
    {
137
        return $this->visibility;
138
    }
139
140
    public function setVisibility(bool $visibility): self
141
    {
142
        $this->visibility = $visibility;
143
144
        return $this;
145
    }
146
147
    public function getTool(): Tool
148
    {
149
        return $this->tool;
150
    }
151
152
    public function setTool(Tool $tool): self
153
    {
154
        $this->tool = $tool;
155
156
        return $this;
157
    }
158
159
    public function getPosition(): int
160
    {
161
        return $this->position;
162
    }
163
164
    public function setPosition(int $position): self
165
    {
166
        $this->position = $position;
167
168
        return $this;
169
    }
170
171
    public function getResourceIdentifier(): int
172
    {
173
        return $this->iid;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->iid could return the type null which is incompatible with the type-hinted return integer. Consider adding an additional type-check to rule them out.
Loading history...
174
    }
175
176
    public function getResourceName(): string
177
    {
178
        return $this->getTitle();
179
    }
180
181
    public function setResourceName(string $name): self
182
    {
183
        return $this->setTitle($name);
184
    }
185
}
186