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
|
|
|
#[ORM\Column(name: 'name', type: 'text', nullable: false)] |
54
|
|
|
protected string $name; |
55
|
|
|
|
56
|
|
|
#[ORM\Column(name: 'visibility', type: 'boolean', nullable: true)] |
57
|
|
|
protected ?bool $visibility = null; |
58
|
|
|
|
59
|
|
|
#[ORM\ManyToOne(targetEntity: Course::class, inversedBy: 'tools')] |
60
|
|
|
#[ORM\JoinColumn(name: 'c_id', referencedColumnName: 'id', nullable: false, onDelete: 'CASCADE')] |
61
|
|
|
#[Gedmo\SortableGroup] |
62
|
|
|
protected Course $course; |
63
|
|
|
|
64
|
|
|
#[ORM\ManyToOne(targetEntity: Session::class)] |
65
|
|
|
#[ORM\JoinColumn(name: 'session_id', referencedColumnName: 'id', nullable: true, onDelete: 'CASCADE')] |
66
|
|
|
#[Gedmo\SortableGroup] |
67
|
|
|
protected ?Session $session = null; |
68
|
|
|
|
69
|
|
|
#[ORM\ManyToOne(targetEntity: Tool::class)] |
70
|
|
|
#[ORM\JoinColumn(name: 'tool_id', referencedColumnName: 'id', nullable: false)] |
71
|
|
|
protected Tool $tool; |
72
|
|
|
|
73
|
|
|
#[Gedmo\SortablePosition] |
74
|
|
|
#[ORM\Column(name: 'position', type: 'integer')] |
75
|
|
|
protected int $position; |
76
|
|
|
|
77
|
|
|
public function __construct() |
78
|
|
|
{ |
79
|
|
|
$this->visibility = true; |
80
|
|
|
$this->position = 0; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
public function __toString(): string |
84
|
|
|
{ |
85
|
|
|
return $this->getName(); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
public function getName(): string |
89
|
|
|
{ |
90
|
|
|
return $this->name; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
public function setName(string $name): self |
94
|
|
|
{ |
95
|
|
|
$this->name = $name; |
96
|
|
|
|
97
|
|
|
return $this; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
public function getIid(): ?int |
101
|
|
|
{ |
102
|
|
|
return $this->iid; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
public function getCourse(): Course |
106
|
|
|
{ |
107
|
|
|
return $this->course; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
public function setCourse(Course $course): self |
111
|
|
|
{ |
112
|
|
|
$this->course = $course; |
113
|
|
|
|
114
|
|
|
return $this; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
public function getSession(): ?Session |
118
|
|
|
{ |
119
|
|
|
return $this->session; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
public function setSession(Session $session = null): self |
123
|
|
|
{ |
124
|
|
|
$this->session = $session; |
125
|
|
|
|
126
|
|
|
return $this; |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
public function getVisibility(): ?bool |
130
|
|
|
{ |
131
|
|
|
return $this->visibility; |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
public function setVisibility(bool $visibility): self |
135
|
|
|
{ |
136
|
|
|
$this->visibility = $visibility; |
137
|
|
|
|
138
|
|
|
return $this; |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
public function getTool(): Tool |
142
|
|
|
{ |
143
|
|
|
return $this->tool; |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
public function setTool(Tool $tool): self |
147
|
|
|
{ |
148
|
|
|
$this->tool = $tool; |
149
|
|
|
|
150
|
|
|
return $this; |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
public function getPosition(): int |
154
|
|
|
{ |
155
|
|
|
return $this->position; |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
public function setPosition(int $position): self |
159
|
|
|
{ |
160
|
|
|
$this->position = $position; |
161
|
|
|
|
162
|
|
|
return $this; |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
public function getResourceIdentifier(): int |
166
|
|
|
{ |
167
|
|
|
return $this->iid; |
|
|
|
|
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
public function getResourceName(): string |
171
|
|
|
{ |
172
|
|
|
return $this->getName(); |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
public function setResourceName(string $name): self |
176
|
|
|
{ |
177
|
|
|
return $this->setName($name); |
178
|
|
|
} |
179
|
|
|
} |
180
|
|
|
|