diff options
Diffstat (limited to 'src/model/entities/Image.php')
| -rw-r--r-- | src/model/entities/Image.php | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/src/model/entities/Image.php b/src/model/entities/Image.php new file mode 100644 index 0000000..181c137 --- /dev/null +++ b/src/model/entities/Image.php | |||
| @@ -0,0 +1,91 @@ | |||
| 1 | <?php | ||
| 2 | // src/model/entities/Image.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 . "image")] | ||
| 12 | class Image | ||
| 13 | { | ||
| 14 | #[ORM\Id] | ||
| 15 | #[ORM\GeneratedValue] | ||
| 16 | #[ORM\Column(type: "integer")] | ||
| 17 | private int $id_image; | ||
| 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: "images")] | ||
| 45 | private $node_data; | ||
| 46 | |||
| 47 | #[ORM\ManyToMany(targetEntity: Article::class, mappedBy: "images")] | ||
| 48 | private $article; | ||
| 49 | |||
| 50 | public function __construct(string $name, ?string $path, ?string $path_mini, string $mime_type, string $alt) | ||
| 51 | { | ||
| 52 | $this->file_name = $name; | ||
| 53 | $this->file_path = $path; | ||
| 54 | $this->file_path_mini = $path_mini; | ||
| 55 | $this->mime_type = $mime_type; | ||
| 56 | $this->alt = $alt; | ||
| 57 | } | ||
| 58 | |||
| 59 | public function getFileName(): string | ||
| 60 | { | ||
| 61 | return $this->file_name; | ||
| 62 | } | ||
| 63 | public function getFilePath(): string | ||
| 64 | { | ||
| 65 | return $this->file_path; | ||
| 66 | } | ||
| 67 | public function getFilePathMini(): string | ||
| 68 | { | ||
| 69 | return $this->file_path_mini; | ||
| 70 | } | ||
| 71 | public function getAlt(): string | ||
| 72 | { | ||
| 73 | return $this->alt; | ||
| 74 | } | ||
| 75 | |||
| 76 | |||
| 77 | // pour ViewBuilder? | ||
| 78 | /*public function displayImage($imageId): void | ||
| 79 | { | ||
| 80 | //$imageId = 1; // Exemple d'ID d'image | ||
| 81 | $stmt = $pdo->prepare("SELECT file_path FROM images WHERE id = ?"); | ||
| 82 | $stmt->execute([$imageId]); | ||
| 83 | $image = $stmt->fetch(); | ||
| 84 | |||
| 85 | if ($image) { | ||
| 86 | echo "<img src='" . $image['file_path'] . "' alt='Image'>"; | ||
| 87 | } else { | ||
| 88 | echo "Image non trouvée."; | ||
| 89 | } | ||
| 90 | }*/ | ||
| 91 | } | ||
