Issues (2113)

src/CourseBundle/Entity/CTool.php (1 issue)

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\CToolStateProvider;
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
            output: CourseTool::class,
33
            provider: CToolStateProvider::class,
34
        ),
35
    ],
36
    normalizationContext: ['groups' => ['ctool:read']],
37
)]
38
#[ORM\Table(name: 'c_tool')]
39
#[ORM\Index(columns: ['c_id'], name: 'course')]
40
#[ORM\Index(columns: ['session_id'], name: 'session_id')]
41
#[ORM\HasLifecycleCallbacks]
42
#[ORM\Entity(repositoryClass: CToolRepository::class)]
43
#[ApiFilter(CidFilter::class)]
44
#[ApiFilter(SidFilter::class)]
45
#[ApiFilter(OrderFilter::class, properties: ['position' => 'ASC'])]
46
class CTool extends AbstractResource implements ResourceInterface, ResourceShowCourseResourcesInSessionInterface, Stringable
47
{
48
    #[ORM\Column(name: 'iid', type: 'integer')]
49
    #[ORM\Id]
50
    #[ORM\GeneratedValue]
51
    protected ?int $iid = null;
52
53
    #[Assert\NotBlank]
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
    }
82
83
    public function __toString(): string
84
    {
85
        return $this->getTitle();
86
    }
87
88
    public function getNameToTranslate(): string
89
    {
90
        return ucfirst(str_replace('_', ' ', $this->title));
91
    }
92
93
    public function getTitle(): string
94
    {
95
        return $this->title;
96
    }
97
98
    public function setTitle(string $title): self
99
    {
100
        $this->title = $title;
101
102
        return $this;
103
    }
104
105
    public function getIid(): ?int
106
    {
107
        return $this->iid;
108
    }
109
110
    public function getCourse(): Course
111
    {
112
        return $this->course;
113
    }
114
115
    public function setCourse(Course $course): self
116
    {
117
        $this->course = $course;
118
119
        return $this;
120
    }
121
122
    public function getSession(): ?Session
123
    {
124
        return $this->session;
125
    }
126
127
    public function setSession(?Session $session = null): self
128
    {
129
        $this->session = $session;
130
131
        return $this;
132
    }
133
134
    public function getVisibility(): ?bool
135
    {
136
        return $this->visibility;
137
    }
138
139
    public function setVisibility(bool $visibility): self
140
    {
141
        $this->visibility = $visibility;
142
143
        return $this;
144
    }
145
146
    public function getTool(): Tool
147
    {
148
        return $this->tool;
149
    }
150
151
    public function setTool(Tool $tool): self
152
    {
153
        $this->tool = $tool;
154
155
        return $this;
156
    }
157
158
    public function getPosition(): int
159
    {
160
        return $this->position;
161
    }
162
163
    public function setPosition(int $position): self
164
    {
165
        $this->position = $position;
166
167
        return $this;
168
    }
169
170
    public function getResourceIdentifier(): int
171
    {
172
        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...
173
    }
174
175
    public function getResourceName(): string
176
    {
177
        return $this->getTitle();
178
    }
179
180
    public function setResourceName(string $name): self
181
    {
182
        return $this->setTitle($name);
183
    }
184
}
185