diff options
author | polo-pc-greta <ordipolo@gmx.fr> | 2025-03-27 10:13:03 +0100 |
---|---|---|
committer | polo-pc-greta <ordipolo@gmx.fr> | 2025-03-27 10:13:03 +0100 |
commit | df3612ed7e6691530503f79483d2fdbc032d01b8 (patch) | |
tree | 56d1c68fdc8625f5dad1937a654299d45142c79a /src/model/entities/Article.php | |
download | cms-df3612ed7e6691530503f79483d2fdbc032d01b8.zip |
mise en ligne github
Diffstat (limited to 'src/model/entities/Article.php')
-rw-r--r-- | src/model/entities/Article.php | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/src/model/entities/Article.php b/src/model/entities/Article.php new file mode 100644 index 0000000..3b846da --- /dev/null +++ b/src/model/entities/Article.php | |||
@@ -0,0 +1,77 @@ | |||
1 | <?php | ||
2 | // src/model/entities/Article.php | ||
3 | |||
4 | declare(strict_types=1); | ||
5 | |||
6 | namespace App\Entity; | ||
7 | |||
8 | use Doctrine\ORM\Mapping as ORM; | ||
9 | use Doctrine\Common\Collections\ArrayCollection; | ||
10 | use Doctrine\Common\Collections\Collection; | ||
11 | |||
12 | #[ORM\Entity] | ||
13 | #[ORM\Table(name: TABLE_PREFIX . "article")] | ||
14 | class Article | ||
15 | { | ||
16 | #[ORM\Id] | ||
17 | #[ORM\GeneratedValue] | ||
18 | #[ORM\Column(type: "integer")] | ||
19 | private int $id_article; | ||
20 | |||
21 | // datetime_immutable permet à la base de toujours gérer cette clé primaire correctement | ||
22 | #[ORM\Column(type: 'datetime', options: ['default' => 'CURRENT_TIMESTAMP'], unique: true)] | ||
23 | private \DateTime $date_time; // le type datetime de doctrine convertit en type \DateTime de PHP | ||
24 | |||
25 | #[ORM\Column(type: "string")] | ||
26 | private string $title; | ||
27 | |||
28 | #[ORM\Column(type: "text")] | ||
29 | private string $preview; // une simple textarea | ||
30 | |||
31 | #[ORM\Column(type: "text")] | ||
32 | private string $content; // de l'éditeur html | ||
33 | |||
34 | // liaison avec table intermédiaire | ||
35 | #[ORM\ManyToMany(targetEntity: Image::class, inversedBy: "article")] | ||
36 | #[ORM\JoinTable( | ||
37 | name: "nb_article_image", | ||
38 | joinColumns: [new ORM\JoinColumn(name: "article_id", referencedColumnName: "id_article", onDelete: "CASCADE")], | ||
39 | inverseJoinColumns: [new ORM\JoinColumn(name: "image_id", referencedColumnName: "id_image", onDelete: "CASCADE")] | ||
40 | )] | ||
41 | private Collection $images; | ||
42 | |||
43 | public function __construct() | ||
44 | { | ||
45 | $this->images = new ArrayCollection(); // initialisation nécessaire | ||
46 | } | ||
47 | |||
48 | public function getDateTime(): \DateTime | ||
49 | { | ||
50 | return $this->date_time; | ||
51 | } | ||
52 | public function getTimestamp(): int | ||
53 | { | ||
54 | return $this->date_time->getTimestamp(); | ||
55 | } | ||
56 | public function getTitle(): string | ||
57 | { | ||
58 | return $this->title; | ||
59 | } | ||
60 | public function getPreview(): string | ||
61 | { | ||
62 | return $this->preview; | ||
63 | } | ||
64 | public function getContent(): string | ||
65 | { | ||
66 | return $this->content; | ||
67 | } | ||
68 | public function setContent(string $data): void | ||
69 | { | ||
70 | $this->content = $data; | ||
71 | } | ||
72 | |||
73 | public function getImages(): Collection | ||
74 | { | ||
75 | return $this->images; | ||
76 | } | ||
77 | } | ||