diff options
author | polo <ordipolo@gmx.fr> | 2025-10-14 17:24:28 +0200 |
---|---|---|
committer | polo <ordipolo@gmx.fr> | 2025-10-14 17:24:28 +0200 |
commit | 50a54e1a9682652d3dcea4fae117d7f456f77e19 (patch) | |
tree | af72b44f8e833bb47f563f6e6806deb8c9c2364a /src/model/entities/Asset.php | |
parent | 596ce6f78e37c901d9b4ed464918b0294ba8dd2a (diff) | |
download | cms-50a54e1a9682652d3dcea4fae117d7f456f77e19.zip |
nouvelle entité Asset, assets séparés de Image
Diffstat (limited to 'src/model/entities/Asset.php')
-rw-r--r-- | src/model/entities/Asset.php | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/src/model/entities/Asset.php b/src/model/entities/Asset.php new file mode 100644 index 0000000..df8c98b --- /dev/null +++ b/src/model/entities/Asset.php | |||
@@ -0,0 +1,88 @@ | |||
1 | <?php | ||
2 | // src/model/entities/Asset.php | ||
3 | |||
4 | declare(strict_types=1); | ||
5 | |||
6 | namespace App\Entity; | ||
7 | |||
8 | use Doctrine\ORM\Mapping as ORM; | ||
9 | |||
10 | #[ORM\Entity] | ||
11 | #[ORM\Table(name: TABLE_PREFIX . "asset")] | ||
12 | class Asset | ||
13 | { | ||
14 | #[ORM\Id] | ||
15 | #[ORM\GeneratedValue] | ||
16 | #[ORM\Column(type: "integer")] | ||
17 | private int $id_asset; | ||
18 | |||
19 | #[ORM\Column(type: "string", length: 255, unique: true)] // nom d'image UNIQUE | ||
20 | private string $file_name; | ||
21 | |||
22 | // choisir un répertoire du genre /var/www/html/uploads/ de préférence hors de /src | ||
23 | #[ORM\Column(type: "string", length: 255, unique: true, nullable: true)] | ||
24 | private ?string $file_path; | ||
25 | |||
26 | #[ORM\Column(type: "string", length: 255, unique: true, nullable: true)] | ||
27 | private ?string $file_path_mini; | ||
28 | |||
29 | #[ORM\Column(type: "string", length: 255, nullable: true)] | ||
30 | private string $mime_type; // image/jpeg, image/png, etc | ||
31 | |||
32 | #[ORM\Column(type: "string", length: 255, nullable: true)] | ||
33 | private string $alt; // texte alternatif | ||
34 | |||
35 | // autre champs optionnels: file_size, date (default current timestamp) | ||
36 | |||
37 | /* étapes au téléchargement: | ||
38 | => Validation du type de fichier : On vérifie que le fichier est bien une image en utilisant le type MIME. On peut aussi vérifier la taille du fichier. | ||
39 | => Création d'un répertoire structuré : On génère un chemin dynamique basé sur la date (uploads/2024/12/24/) pour organiser les images. | ||
40 | => Génération d'un nom de fichier unique : On utilise uniqid() pour générer un nom unique et éviter les conflits de nom. | ||
41 | => Déplacement du fichier sur le serveur : Le fichier est déplacé depuis son emplacement temporaire vers le répertoire uploads/. | ||
42 | => Enregistrement dans la base de données : On enregistre les informations de l'image dans la base de données. */ | ||
43 | |||
44 | #[ORM\ManyToMany(targetEntity: NodeData::class, mappedBy: "assets")] | ||
45 | private $node_data; | ||
46 | |||
47 | public function __construct(string $name, ?string $path, ?string $path_mini, string $mime_type, string $alt) | ||
48 | { | ||
49 | $this->file_name = $name; | ||
50 | $this->file_path = $path; | ||
51 | $this->file_path_mini = $path_mini; | ||
52 | $this->mime_type = $mime_type; | ||
53 | $this->alt = $alt; | ||
54 | } | ||
55 | |||
56 | public function getFileName(): string | ||
57 | { | ||
58 | return $this->file_name; | ||
59 | } | ||
60 | public function getFilePath(): string | ||
61 | { | ||
62 | return $this->file_path; | ||
63 | } | ||
64 | public function getFilePathMini(): string | ||
65 | { | ||
66 | return $this->file_path_mini; | ||
67 | } | ||
68 | public function getAlt(): string | ||
69 | { | ||
70 | return $this->alt; | ||
71 | } | ||
72 | |||
73 | |||
74 | // pour ViewBuilderController? | ||
75 | /*public function displayImage($imageId): void | ||
76 | { | ||
77 | //$imageId = 1; // Exemple d'ID d'image | ||
78 | $stmt = $pdo->prepare("SELECT file_path FROM images WHERE id = ?"); | ||
79 | $stmt->execute([$imageId]); | ||
80 | $image = $stmt->fetch(); | ||
81 | |||
82 | if ($image) { | ||
83 | echo "<img src='" . $image['file_path'] . "' alt='Image'>"; | ||
84 | } else { | ||
85 | echo "Image non trouvée."; | ||
86 | } | ||
87 | }*/ | ||
88 | } | ||