|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* For licensing terms, see /license.txt */ |
|
6
|
|
|
|
|
7
|
|
|
namespace Chamilo\CourseBundle\Entity; |
|
8
|
|
|
|
|
9
|
|
|
use ApiPlatform\Core\Annotation\ApiResource; |
|
10
|
|
|
use Chamilo\CoreBundle\Entity\AbstractResource; |
|
11
|
|
|
use Chamilo\CoreBundle\Entity\Course; |
|
12
|
|
|
use Chamilo\CoreBundle\Entity\ResourceInterface; |
|
13
|
|
|
use Chamilo\CoreBundle\Entity\ResourceShowCourseResourcesInSessionInterface; |
|
14
|
|
|
use Chamilo\CoreBundle\Entity\Session; |
|
15
|
|
|
use Chamilo\CoreBundle\Entity\Tool; |
|
16
|
|
|
use Doctrine\ORM\Mapping as ORM; |
|
17
|
|
|
use Gedmo\Mapping\Annotation as Gedmo; |
|
18
|
|
|
use Symfony\Component\Serializer\Annotation\Groups; |
|
19
|
|
|
use Symfony\Component\Validator\Constraints as Assert; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @ORM\HasLifecycleCallbacks |
|
23
|
|
|
* @ORM\Table( |
|
24
|
|
|
* name="c_tool", |
|
25
|
|
|
* indexes={ |
|
26
|
|
|
* @ORM\Index(name="course", columns={"c_id"}), |
|
27
|
|
|
* @ORM\Index(name="session_id", columns={"session_id"}) |
|
28
|
|
|
* } |
|
29
|
|
|
* ) |
|
30
|
|
|
* @ORM\Entity(repositoryClass="Chamilo\CourseBundle\Repository\CToolRepository") |
|
31
|
|
|
*/ |
|
32
|
|
|
#[ApiResource( |
|
33
|
|
|
attributes: [ |
|
34
|
|
|
'security' => "is_granted('ROLE_ADMIN') or is_granted('ROLE_CURRENT_COURSE_TEACHER')", |
|
35
|
|
|
], |
|
36
|
|
|
denormalizationContext: [ |
|
37
|
|
|
'groups' => ['ctool:write'], |
|
38
|
|
|
], |
|
39
|
|
|
normalizationContext: [ |
|
40
|
|
|
'groups' => ['ctool:read'], |
|
41
|
|
|
], |
|
42
|
|
|
)] |
|
43
|
|
|
class CTool extends AbstractResource implements ResourceInterface, ResourceShowCourseResourcesInSessionInterface |
|
44
|
|
|
{ |
|
45
|
|
|
/** |
|
46
|
|
|
* @ORM\Column(name="iid", type="integer") |
|
47
|
|
|
* @ORM\Id |
|
48
|
|
|
* @ORM\GeneratedValue |
|
49
|
|
|
*/ |
|
50
|
|
|
#[Groups(['ctool:read'])] |
|
51
|
|
|
protected int $iid; |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @ORM\Column(name="name", type="text", nullable=false) |
|
55
|
|
|
*/ |
|
56
|
|
|
#[Assert\NotBlank] |
|
57
|
|
|
#[Groups(['ctool:read'])] |
|
58
|
|
|
protected string $name; |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @ORM\Column(name="visibility", type="boolean", nullable=true) |
|
62
|
|
|
*/ |
|
63
|
|
|
#[Groups(['ctool:read'])] |
|
64
|
|
|
protected ?bool $visibility = null; |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\Course", inversedBy="tools") |
|
68
|
|
|
* @ORM\JoinColumn(name="c_id", referencedColumnName="id", nullable=false) |
|
69
|
|
|
*/ |
|
70
|
|
|
protected Course $course; |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\Session") |
|
74
|
|
|
* @ORM\JoinColumn(name="session_id", referencedColumnName="id", nullable=true) |
|
75
|
|
|
*/ |
|
76
|
|
|
protected ?Session $session = null; |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\Tool") |
|
80
|
|
|
* @ORM\JoinColumn(name="tool_id", referencedColumnName="id", nullable=false) |
|
81
|
|
|
*/ |
|
82
|
|
|
protected Tool $tool; |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* @Gedmo\SortablePosition |
|
86
|
|
|
* @ORM\Column(name="position", type="integer") |
|
87
|
|
|
*/ |
|
88
|
|
|
protected int $position; |
|
89
|
|
|
|
|
90
|
|
|
#[Groups(['ctool:read'])] |
|
91
|
|
|
protected string $nameToTranslate; |
|
92
|
|
|
|
|
93
|
|
|
public function __construct() |
|
94
|
|
|
{ |
|
95
|
|
|
$this->position = 0; |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
public function __toString(): string |
|
99
|
|
|
{ |
|
100
|
|
|
return $this->getName(); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
public function getNameToTranslate(): string |
|
104
|
|
|
{ |
|
105
|
|
|
return ucfirst(str_replace('_', ' ', $this->name)); |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
public function getName(): string |
|
109
|
|
|
{ |
|
110
|
|
|
return $this->name; |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
public function setName(string $name): self |
|
114
|
|
|
{ |
|
115
|
|
|
$this->name = $name; |
|
116
|
|
|
|
|
117
|
|
|
return $this; |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
/** |
|
121
|
|
|
* @return int |
|
122
|
|
|
*/ |
|
123
|
|
|
public function getIid() |
|
124
|
|
|
{ |
|
125
|
|
|
return $this->iid; |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
public function setCourse(Course $course): self |
|
129
|
|
|
{ |
|
130
|
|
|
$this->course = $course; |
|
131
|
|
|
|
|
132
|
|
|
return $this; |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
public function getCourse(): Course |
|
136
|
|
|
{ |
|
137
|
|
|
return $this->course; |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
public function getSession(): ?Session |
|
141
|
|
|
{ |
|
142
|
|
|
return $this->session; |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
public function setSession(Session $session = null): self |
|
146
|
|
|
{ |
|
147
|
|
|
$this->session = $session; |
|
148
|
|
|
|
|
149
|
|
|
return $this; |
|
150
|
|
|
} |
|
151
|
|
|
|
|
152
|
|
|
public function setVisibility(bool $visibility): self |
|
153
|
|
|
{ |
|
154
|
|
|
$this->visibility = $visibility; |
|
155
|
|
|
|
|
156
|
|
|
return $this; |
|
157
|
|
|
} |
|
158
|
|
|
|
|
159
|
|
|
public function getVisibility(): bool |
|
160
|
|
|
{ |
|
161
|
|
|
return $this->visibility; |
|
|
|
|
|
|
162
|
|
|
} |
|
163
|
|
|
|
|
164
|
|
|
public function getTool(): Tool |
|
165
|
|
|
{ |
|
166
|
|
|
return $this->tool; |
|
167
|
|
|
} |
|
168
|
|
|
|
|
169
|
|
|
public function setTool(Tool $tool): self |
|
170
|
|
|
{ |
|
171
|
|
|
$this->tool = $tool; |
|
172
|
|
|
|
|
173
|
|
|
return $this; |
|
174
|
|
|
} |
|
175
|
|
|
|
|
176
|
|
|
public function getPosition(): int |
|
177
|
|
|
{ |
|
178
|
|
|
return $this->position; |
|
179
|
|
|
} |
|
180
|
|
|
|
|
181
|
|
|
public function setPosition(int $position): self |
|
182
|
|
|
{ |
|
183
|
|
|
$this->position = $position; |
|
184
|
|
|
|
|
185
|
|
|
return $this; |
|
186
|
|
|
} |
|
187
|
|
|
|
|
188
|
|
|
public function getResourceIdentifier(): int |
|
189
|
|
|
{ |
|
190
|
|
|
return $this->iid; |
|
191
|
|
|
} |
|
192
|
|
|
|
|
193
|
|
|
public function getResourceName(): string |
|
194
|
|
|
{ |
|
195
|
|
|
return $this->getName(); |
|
196
|
|
|
} |
|
197
|
|
|
|
|
198
|
|
|
public function setResourceName(string $name): self |
|
199
|
|
|
{ |
|
200
|
|
|
return $this->setName($name); |
|
201
|
|
|
} |
|
202
|
|
|
} |
|
203
|
|
|
|