|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* For licensing terms, see /license.txt */ |
|
6
|
|
|
|
|
7
|
|
|
namespace Chamilo\CoreBundle\Entity; |
|
8
|
|
|
|
|
9
|
|
|
use ApiPlatform\Metadata\ApiResource; |
|
10
|
|
|
use ApiPlatform\Metadata\Delete; |
|
11
|
|
|
use ApiPlatform\Metadata\Get; |
|
12
|
|
|
use ApiPlatform\Metadata\GetCollection; |
|
13
|
|
|
use ApiPlatform\Metadata\Patch; |
|
14
|
|
|
use ApiPlatform\Metadata\Post; |
|
15
|
|
|
use ApiPlatform\Metadata\Put; |
|
16
|
|
|
use DateTime; |
|
17
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
|
18
|
|
|
use Doctrine\Common\Collections\Collection; |
|
19
|
|
|
use Doctrine\ORM\Mapping as ORM; |
|
20
|
|
|
use Stringable; |
|
21
|
|
|
use Symfony\Component\Serializer\Annotation\Groups; |
|
22
|
|
|
use Symfony\Component\Validator\Constraints as Assert; |
|
23
|
|
|
|
|
24
|
|
|
#[ApiResource(operations: [new Get(), new Put(), new Patch(), new Delete(), new GetCollection(security: 'is_granted(\'ROLE_USER\')'), new Post(security: 'is_granted(\'ROLE_ADMIN\')')], security: 'is_granted(\'ROLE_USER\')', denormalizationContext: ['groups' => ['session_category:write']], normalizationContext: ['groups' => ['session_category:read']])] |
|
25
|
|
|
#[ORM\Table(name: 'session_category')] |
|
26
|
|
|
#[ORM\Entity] |
|
27
|
|
|
class SessionCategory implements Stringable |
|
28
|
|
|
{ |
|
29
|
|
|
#[Groups(['session_category:read', 'session_rel_user:read'])] |
|
30
|
|
|
#[ORM\Column(name: 'id', type: 'integer', nullable: false)] |
|
31
|
|
|
#[ORM\Id] |
|
32
|
|
|
#[ORM\GeneratedValue] |
|
33
|
|
|
protected ?int $id = null; |
|
34
|
|
|
#[ORM\ManyToOne(targetEntity: AccessUrl::class, inversedBy: 'sessionCategories', cascade: ['persist'])] |
|
35
|
|
|
#[ORM\JoinColumn(name: 'access_url_id', referencedColumnName: 'id')] |
|
36
|
|
|
protected AccessUrl $url; |
|
37
|
|
|
#[ORM\OneToMany(targetEntity: Session::class, mappedBy: 'category')] |
|
38
|
|
|
protected Collection $sessions; |
|
39
|
|
|
#[Groups(['session_category:read', 'session_category:write', 'session:read', 'session_rel_user:read'])] |
|
40
|
|
|
#[Assert\NotBlank] |
|
41
|
|
|
#[ORM\Column(name: 'title', type: 'string', length: 100, nullable: false, unique: false)] |
|
42
|
|
|
protected string $title; |
|
43
|
|
|
#[ORM\Column(name: 'date_start', type: 'date', nullable: true, unique: false)] |
|
44
|
|
|
protected ?DateTime $dateStart = null; |
|
45
|
|
|
#[ORM\Column(name: 'date_end', type: 'date', nullable: true, unique: false)] |
|
46
|
|
|
protected ?DateTime $dateEnd = null; |
|
47
|
|
|
public function __construct() |
|
48
|
|
|
{ |
|
49
|
|
|
$this->sessions = new ArrayCollection(); |
|
50
|
|
|
} |
|
51
|
|
|
public function __toString(): string |
|
52
|
|
|
{ |
|
53
|
|
|
return $this->title; |
|
54
|
|
|
} |
|
55
|
|
|
public function setUrl(AccessUrl $url): self |
|
56
|
|
|
{ |
|
57
|
|
|
$this->url = $url; |
|
58
|
|
|
|
|
59
|
|
|
return $this; |
|
60
|
|
|
} |
|
61
|
|
|
public function getUrl(): AccessUrl |
|
62
|
|
|
{ |
|
63
|
|
|
return $this->url; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* Get id. |
|
68
|
|
|
* |
|
69
|
|
|
* @return int |
|
70
|
|
|
*/ |
|
71
|
|
|
public function getId() |
|
72
|
|
|
{ |
|
73
|
|
|
return $this->id; |
|
74
|
|
|
} |
|
75
|
|
|
public function setTitle(string $title): self |
|
76
|
|
|
{ |
|
77
|
|
|
$this->title = $title; |
|
78
|
|
|
|
|
79
|
|
|
return $this; |
|
80
|
|
|
} |
|
81
|
|
|
public function getTitle(): string |
|
82
|
|
|
{ |
|
83
|
|
|
return $this->title; |
|
84
|
|
|
} |
|
85
|
|
|
public function setDateStart(DateTime $dateStart): self |
|
86
|
|
|
{ |
|
87
|
|
|
$this->dateStart = $dateStart; |
|
88
|
|
|
|
|
89
|
|
|
return $this; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* Get dateStart. |
|
94
|
|
|
* |
|
95
|
|
|
* @return DateTime |
|
96
|
|
|
*/ |
|
97
|
|
|
public function getDateStart() |
|
98
|
|
|
{ |
|
99
|
|
|
return $this->dateStart; |
|
100
|
|
|
} |
|
101
|
|
|
public function setDateEnd(DateTime $dateEnd): self |
|
102
|
|
|
{ |
|
103
|
|
|
$this->dateEnd = $dateEnd; |
|
104
|
|
|
|
|
105
|
|
|
return $this; |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
/** |
|
109
|
|
|
* Get dateEnd. |
|
110
|
|
|
* |
|
111
|
|
|
* @return DateTime |
|
112
|
|
|
*/ |
|
113
|
|
|
public function getDateEnd() |
|
114
|
|
|
{ |
|
115
|
|
|
return $this->dateEnd; |
|
116
|
|
|
} |
|
117
|
|
|
} |
|
118
|
|
|
|