From df3612ed7e6691530503f79483d2fdbc032d01b8 Mon Sep 17 00:00:00 2001 From: polo-pc-greta Date: Thu, 27 Mar 2025 10:13:03 +0100 Subject: mise en ligne github --- src/model/entities/Article.php | 77 ++++++++++++++++++ src/model/entities/Image.php | 91 ++++++++++++++++++++++ src/model/entities/Node.php | 168 ++++++++++++++++++++++++++++++++++++++++ src/model/entities/NodeData.php | 62 +++++++++++++++ src/model/entities/Page.php | 97 +++++++++++++++++++++++ src/model/entities/User.php | 47 +++++++++++ 6 files changed, 542 insertions(+) create mode 100644 src/model/entities/Article.php create mode 100644 src/model/entities/Image.php create mode 100644 src/model/entities/Node.php create mode 100644 src/model/entities/NodeData.php create mode 100644 src/model/entities/Page.php create mode 100644 src/model/entities/User.php (limited to 'src/model/entities') 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 @@ + 'CURRENT_TIMESTAMP'], unique: true)] + private \DateTime $date_time; // le type datetime de doctrine convertit en type \DateTime de PHP + + #[ORM\Column(type: "string")] + private string $title; + + #[ORM\Column(type: "text")] + private string $preview; // une simple textarea + + #[ORM\Column(type: "text")] + private string $content; // de l'éditeur html + + // liaison avec table intermédiaire + #[ORM\ManyToMany(targetEntity: Image::class, inversedBy: "article")] + #[ORM\JoinTable( + name: "nb_article_image", + joinColumns: [new ORM\JoinColumn(name: "article_id", referencedColumnName: "id_article", onDelete: "CASCADE")], + inverseJoinColumns: [new ORM\JoinColumn(name: "image_id", referencedColumnName: "id_image", onDelete: "CASCADE")] + )] + private Collection $images; + + public function __construct() + { + $this->images = new ArrayCollection(); // initialisation nécessaire + } + + public function getDateTime(): \DateTime + { + return $this->date_time; + } + public function getTimestamp(): int + { + return $this->date_time->getTimestamp(); + } + public function getTitle(): string + { + return $this->title; + } + public function getPreview(): string + { + return $this->preview; + } + public function getContent(): string + { + return $this->content; + } + public function setContent(string $data): void + { + $this->content = $data; + } + + public function getImages(): Collection + { + return $this->images; + } +} 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 @@ + 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. + => 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. + => 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. + => Déplacement du fichier sur le serveur : Le fichier est déplacé depuis son emplacement temporaire vers le répertoire uploads/. + => Enregistrement dans la base de données : On enregistre les informations de l'image dans la base de données. */ + + #[ORM\ManyToMany(targetEntity: NodeData::class, mappedBy: "images")] + private $node_data; + + #[ORM\ManyToMany(targetEntity: Article::class, mappedBy: "images")] + private $article; + + public function __construct(string $name, ?string $path, ?string $path_mini, string $mime_type, string $alt) + { + $this->file_name = $name; + $this->file_path = $path; + $this->file_path_mini = $path_mini; + $this->mime_type = $mime_type; + $this->alt = $alt; + } + + public function getFileName(): string + { + return $this->file_name; + } + public function getFilePath(): string + { + return $this->file_path; + } + public function getFilePathMini(): string + { + return $this->file_path_mini; + } + public function getAlt(): string + { + return $this->alt; + } + + + // pour ViewBuilder? + /*public function displayImage($imageId): void + { + //$imageId = 1; // Exemple d'ID d'image + $stmt = $pdo->prepare("SELECT file_path FROM images WHERE id = ?"); + $stmt->execute([$imageId]); + $image = $stmt->fetch(); + + if ($image) { + echo "Image"; + } else { + echo "Image non trouvée."; + } + }*/ +} diff --git a/src/model/entities/Node.php b/src/model/entities/Node.php new file mode 100644 index 0000000..49e16ba --- /dev/null +++ b/src/model/entities/Node.php @@ -0,0 +1,168 @@ +name_node = $name; + $this->article_timestamp = $article_timestamp; + $this->attributes = $attributes; + $this->position = $position; + $this->parent = $parent; + $this->page = $page; + $this->article = $article; + } + + public function addChild(self $child): void + { + $this->children[] = $child; + $this->sortChildren(); + } + + // utiliser $position pour afficher les éléments dans l'ordre + private function sortChildren(): void + { + $iteration = count($this->children); + while($iteration > 1) + { + for($i = 0; $i < $iteration - 1; $i++) + { + //echo '
' . $this->children[$i]->getPosition() . ' - ' . $this->children[$i + 1]->getPosition(); + if($this->children[$i]->getPosition() > $this->children[$i + 1]->getPosition()) + { + $tmp = $this->children[$i]; + $this->children[$i] = $this->children[$i + 1]; + $this->children[$i + 1] = $tmp; + } + } + $iteration--; + } + } + + // pfff... + public function getId(): int + { + return $this->id_node; + } + public function getName(): string + { + return $this->name_node; + } + /*public function setName(string $name): void + { + $this->name_node = $name; + }*/ + public function getArticleTimestamp(): string + { + return $this->article_timestamp; + } + public function getAttributes(): array + { + return $this->attributes; + } + /*public function setAttributes(array $attributes): void + { + $this->attributes = $attributes; + }*/ + public function getParent(): ?self + { + return $this->parent; + } + /*public function setParent(?self $parent): void + { + $this->parent = $parent; + }*/ + public function getPosition(): int + { + return $this->position; + } + /*public function setPosition(int $position): void + { + $this->position = $position; + }*/ + public function getPage(): Page + { + return $this->page; + } + /*public function setPage(Page $page): void + { + $this->page = $page; + }*/ + public function getArticle(): Article + { + return $this->article; + } + /*public function setArticle(Article $article): void + { + $this->article = $article; + }*/ + public function getNodeData(): ?NodeData + { + return $this->node_data; + } + public function getChildren(): array + { + return $this->children; + } + + public function getTempChild(): ?self // peut renvoyer null + { + return $this->temp_child; + } + public function setTempChild(self $child): void + { + $this->temp_child = $child; + } +} diff --git a/src/model/entities/NodeData.php b/src/model/entities/NodeData.php new file mode 100644 index 0000000..ddf6083 --- /dev/null +++ b/src/model/entities/NodeData.php @@ -0,0 +1,62 @@ +data = $data; + $this->node = $node; + $this->images = $images; + } + + public function getData(): array + { + return $this->data; + } + /*public function setData(array $data): void + { + $this->data = $data; + } + public function setNode(Node $node): void + { + $this->node = $node; + }*/ + public function getImages(): Collection + { + return $this->images; + } +} diff --git a/src/model/entities/Page.php b/src/model/entities/Page.php new file mode 100644 index 0000000..d7d8098 --- /dev/null +++ b/src/model/entities/Page.php @@ -0,0 +1,97 @@ +name_page = $name; + $this->end_of_path = $eop; + $this->reachable = $reachable; + $this->in_menu = $in_menu; + $this->parent = $parent; + $this->children = new ArrayCollection(); + } + + // getters + /*public function getId(): int + { + return $this->id_page; + }*/ + public function getPageName(): string + { + return $this->name_page; + } + public function getPagePath(): string + { + return $this->page_path; + } + public function getEndOfPath(): string + { + return $this->end_of_path; + } + public function getInMenu(): bool + { + return $this->in_menu; + } + public function getParent(): ?Page + { + return $this->parent; + } + public function getChildren(): Collection + { + return $this->children; + } + + public function fillChildrenPagePath(string $parent_path = ''): void + { + $this->page_path = $parent_path != '' ? $parent_path . '/' . $this->end_of_path : $this->end_of_path; + foreach($this->getChildren() as $page){ + $page->fillChildrenPagePath($this->page_path); + } + } + + public function addChild(self $child): void + { + $this->children[] = $child; + } +} diff --git a/src/model/entities/User.php b/src/model/entities/User.php new file mode 100644 index 0000000..4b1dcb8 --- /dev/null +++ b/src/model/entities/User.php @@ -0,0 +1,47 @@ +login = $login; + $this->password = $password; + } + + public function getLogin(): string + { + return $this->login; + } + public function getPassword(): string + { + return $this->password; + } + + public function setPassword(string $password): void + { + $this->password = $password; + } +} \ No newline at end of file -- cgit v1.2.3