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/Menu.php | 53 ++++++++++++ src/model/Path.php | 84 ++++++++++++++++++++ src/model/doctrine-bootstrap.php | 31 ++++++++ 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 +++++++++++ 9 files changed, 710 insertions(+) create mode 100644 src/model/Menu.php create mode 100644 src/model/Path.php create mode 100644 src/model/doctrine-bootstrap.php 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') diff --git a/src/model/Menu.php b/src/model/Menu.php new file mode 100644 index 0000000..624a0fc --- /dev/null +++ b/src/model/Menu.php @@ -0,0 +1,53 @@ +children = new ArrayCollection(); + + $bulk_data = $entityManager + ->createQuery('SELECT n FROM App\Entity\Page n WHERE n.parent IS null') // :Doctrine\ORM\Query + ->getResult(); // :array de Page + + if(count($bulk_data) === 0){ + makeStartPage($entityManager); + } + + foreach($bulk_data as $first_level_entries){ + // génération du menu + if($first_level_entries->getInMenu()){ + $this->addChild($first_level_entries); + } + // autres pages + else{ + // attention, seul le premier élément du chemin est pris en compte + $this->other_pages[] = $first_level_entries; + } + } + + foreach($this->getChildren() as $page){ + $page->fillChildrenPagePath(); + } + + /*for($i = 0; $i < count($this->getChildren()[1]->getChildren()); $i++){ + echo $this->getChildren()[1]->getChildren()[$i]->getEndOfPath() . ' - '; + echo $this->getChildren()[1]->getChildren()[$i]->getPageName() . '
'; + }*/ + //die; + } + + public function getOtherPages(): array + { + return $this->other_pages; + } +} \ No newline at end of file diff --git a/src/model/Path.php b/src/model/Path.php new file mode 100644 index 0000000..6faadfd --- /dev/null +++ b/src/model/Path.php @@ -0,0 +1,84 @@ +findPage(Director::$menu_data, $path_array); // remplit $this->current_page + } + catch(Exception $e){} + /*echo "nb d'autres pages: " . count(Director::$menu_data->getOtherPages()) . '
'; + echo 'longueur du chemin: ' . count($this->current_page) . '
'; + foreach($this->current_page as $current){ + echo $current->getEndOfPath() . ' '; + } + die;*/ + } + + // produit un tableau de Page en comparant le chemin demandé avec les données dans Menu + // succès => une exception est lancée pour sortir des fonctions imbriquées + // echec => redirection vers la page erreur 404 + private function findPage(Page|Menu $menu, array $path_array) + { + // recherche dans les autres pages + if($menu instanceof Menu){ + foreach($menu->getOtherPages() as $page) + { + if($path_array[0] === $page->getEndOfPath()) + { + $this->current_page[] = $page; + throw new Exception(); + } + } + } + // recherche dans le menu + foreach($menu->getChildren() as $page) + { + if($path_array[0] === $page->getEndOfPath()) + { + $this->current_page[] = $page; + if(count($path_array) > 1) + { + array_shift($path_array); // $this->path_array n'est pas modifié, un tableau PHP est passé à une fonction par copie + $this->findPage($page, $path_array); + } + else{ + throw new Exception(); // sortir de tous les findPage() en même temps + } + } + } + // rien trouvé + URL::setPath('erreur404.html'); + header('Location: '. new URL); + die; + } + + public function getString(): string + { + $path_string = ""; + foreach($this->current_page as $one_page){ + $path_string .= $one_page->getEndOfPath() . '/'; + } + return rtrim($path_string, '/'); + } + public function getArray(): array + { + return $this->current_page; + } + + // c'est là qu'on est quoi + public function getLast(): Page + { + return $this->current_page[count($this->current_page) - 1]; + } +} \ No newline at end of file diff --git a/src/model/doctrine-bootstrap.php b/src/model/doctrine-bootstrap.php new file mode 100644 index 0000000..139f410 --- /dev/null +++ b/src/model/doctrine-bootstrap.php @@ -0,0 +1,31 @@ + Config::$db_driver, + 'user' => Config::$user, + 'password' => Config::$password, + 'host' => Config::$db_host, + 'dbname' => Config::$database, +], $config); + +// obtaining the entity manager +$entityManager = new EntityManager($connection, $config); + +foreach($entityManager->getMetadataFactory()->getAllMetadata() as $class){} \ No newline at end of file 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