|
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\Doctrine\Orm\Filter\SearchFilter; |
|
10
|
|
|
use ApiPlatform\Metadata\ApiFilter; |
|
11
|
|
|
use ApiPlatform\Metadata\ApiResource; |
|
12
|
|
|
use ApiPlatform\Metadata\Delete; |
|
13
|
|
|
use ApiPlatform\Metadata\Get; |
|
14
|
|
|
use ApiPlatform\Metadata\GetCollection; |
|
15
|
|
|
use ApiPlatform\Metadata\Post; |
|
16
|
|
|
use ApiPlatform\Metadata\Put; |
|
17
|
|
|
use Chamilo\CoreBundle\Entity\AbstractResource; |
|
18
|
|
|
use Chamilo\CoreBundle\Entity\ResourceInterface; |
|
19
|
|
|
use Chamilo\CoreBundle\Entity\ResourceShowCourseResourcesInSessionInterface; |
|
20
|
|
|
use Chamilo\CoreBundle\Filter\CidFilter; |
|
21
|
|
|
use Chamilo\CoreBundle\Filter\SidFilter; |
|
22
|
|
|
use Chamilo\CourseBundle\Repository\CToolIntroRepository; |
|
23
|
|
|
use Doctrine\ORM\Mapping as ORM; |
|
24
|
|
|
use Stringable; |
|
25
|
|
|
use Symfony\Component\Serializer\Annotation\Groups; |
|
26
|
|
|
use Symfony\Component\Uid\Uuid; |
|
27
|
|
|
use Symfony\Component\Validator\Constraints as Assert; |
|
28
|
|
|
|
|
29
|
|
|
#[ApiResource( |
|
30
|
|
|
operations: [ |
|
31
|
|
|
new Get(security: "is_granted('VIEW', object)"), |
|
32
|
|
|
new Put(security: "is_granted('EDIT', object)"), |
|
33
|
|
|
new Delete(security: "is_granted('DELETE', object)"), |
|
34
|
|
|
new GetCollection(security: "is_granted('ROLE_USER')"), |
|
35
|
|
|
new Post(securityPostDenormalize: "is_granted('CREATE', object)"), |
|
36
|
|
|
], |
|
37
|
|
|
normalizationContext: [ |
|
38
|
|
|
'groups' => ['c_tool_intro:read'], |
|
39
|
|
|
], |
|
40
|
|
|
denormalizationContext: [ |
|
41
|
|
|
'groups' => ['c_tool_intro:write'], |
|
42
|
|
|
], |
|
43
|
|
|
security: "is_granted('ROLE_ADMIN') or is_granted('ROLE_CURRENT_COURSE_TEACHER')", |
|
44
|
|
|
)] |
|
45
|
|
|
#[ORM\Table(name: 'c_tool_intro')] |
|
46
|
|
|
#[ORM\Entity(repositoryClass: CToolIntroRepository::class)] |
|
47
|
|
|
#[ApiFilter(filterClass: SearchFilter::class, properties: ['courseTool' => 'exact'])] |
|
48
|
|
|
#[ApiFilter(filterClass: CidFilter::class)] |
|
49
|
|
|
#[ApiFilter(filterClass: SidFilter::class)] |
|
50
|
|
|
class CToolIntro extends AbstractResource implements ResourceInterface, ResourceShowCourseResourcesInSessionInterface, Stringable |
|
51
|
|
|
{ |
|
52
|
|
|
#[Groups(['c_tool_intro:read'])] |
|
53
|
|
|
#[ORM\Column(name: 'iid', type: 'integer')] |
|
54
|
|
|
#[ORM\Id] |
|
55
|
|
|
#[ORM\GeneratedValue] |
|
56
|
|
|
protected ?int $iid = null; |
|
57
|
|
|
|
|
58
|
|
|
#[Assert\NotNull] |
|
59
|
|
|
#[Groups(['c_tool_intro:read', 'c_tool_intro:write'])] |
|
60
|
|
|
#[ORM\Column(name: 'intro_text', type: 'text', nullable: false)] |
|
61
|
|
|
protected string $introText; |
|
62
|
|
|
|
|
63
|
|
|
#[Assert\NotNull] |
|
64
|
|
|
#[Groups(['c_tool_intro:read', 'c_tool_intro:write'])] |
|
65
|
|
|
#[ORM\ManyToOne(targetEntity: CTool::class)] |
|
66
|
|
|
#[ORM\JoinColumn(name: 'c_tool_id', referencedColumnName: 'iid', nullable: false, onDelete: 'CASCADE')] |
|
67
|
|
|
protected CTool $courseTool; |
|
68
|
|
|
|
|
69
|
|
|
public function __toString(): string |
|
70
|
|
|
{ |
|
71
|
|
|
return $this->getIntroText(); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
public function getIid(): ?int |
|
75
|
|
|
{ |
|
76
|
|
|
return $this->iid; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
public function getCourseTool(): CTool |
|
80
|
|
|
{ |
|
81
|
|
|
return $this->courseTool; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
public function setCourseTool(CTool $courseTool): self |
|
85
|
|
|
{ |
|
86
|
|
|
$this->courseTool = $courseTool; |
|
87
|
|
|
|
|
88
|
|
|
return $this; |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
public function setIntroText(string $introText): self |
|
92
|
|
|
{ |
|
93
|
|
|
$this->introText = $introText; |
|
94
|
|
|
|
|
95
|
|
|
return $this; |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
public function getIntroText(): string |
|
99
|
|
|
{ |
|
100
|
|
|
return $this->introText; |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
public function getResourceIdentifier(): int|Uuid |
|
104
|
|
|
{ |
|
105
|
|
|
return $this->getIid(); |
|
|
|
|
|
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
public function getResourceName(): string |
|
109
|
|
|
{ |
|
110
|
|
|
return $this->getCourseTool()->getTitle(); |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
public function setResourceName(string $name): self |
|
114
|
|
|
{ |
|
115
|
|
|
return $this; |
|
116
|
|
|
} |
|
117
|
|
|
} |
|
118
|
|
|
|