diff options
Diffstat (limited to 'src/controller/post.php')
-rw-r--r-- | src/controller/post.php | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/src/controller/post.php b/src/controller/post.php index 6fac796..2aa7780 100644 --- a/src/controller/post.php +++ b/src/controller/post.php | |||
@@ -6,6 +6,8 @@ declare(strict_types=1); | |||
6 | use App\Entity\Node; | 6 | use App\Entity\Node; |
7 | use App\Entity\NodeData; | 7 | use App\Entity\NodeData; |
8 | use App\Entity\Page; | 8 | use App\Entity\Page; |
9 | use App\Entity\Image; | ||
10 | use Doctrine\Common\Collections\ArrayCollection; | ||
9 | 11 | ||
10 | if($_SERVER['REQUEST_METHOD'] === 'POST' && $_SESSION['admin'] === true) | 12 | if($_SERVER['REQUEST_METHOD'] === 'POST' && $_SESSION['admin'] === true) |
11 | { | 13 | { |
@@ -29,7 +31,7 @@ if($_SERVER['REQUEST_METHOD'] === 'POST' && $_SESSION['admin'] === true) | |||
29 | trim(htmlspecialchars($_POST["page_name"])), | 31 | trim(htmlspecialchars($_POST["page_name"])), |
30 | trim(htmlspecialchars($_POST["page_name_path"])), | 32 | trim(htmlspecialchars($_POST["page_name_path"])), |
31 | true, true, false, | 33 | true, true, false, |
32 | $previous_page->getPosition(), | 34 | $previous_page->getPosition(), |
33 | $parent); // peut et DOIT être null si on est au 1er niveau | 35 | $parent); // peut et DOIT être null si on est au 1er niveau |
34 | 36 | ||
35 | // on a donné à la nouvelle entrée la même position qu'à la précédente, | 37 | // on a donné à la nouvelle entrée la même position qu'à la précédente, |
@@ -56,6 +58,12 @@ if($_SERVER['REQUEST_METHOD'] === 'POST' && $_SESSION['admin'] === true) | |||
56 | 'title' => trim(htmlspecialchars($_POST["page_name"])), | 58 | 'title' => trim(htmlspecialchars($_POST["page_name"])), |
57 | 'description' => trim(htmlspecialchars($_POST["page_description"]))], | 59 | 'description' => trim(htmlspecialchars($_POST["page_description"]))], |
58 | $node); | 60 | $node); |
61 | |||
62 | $bulk_data = $entityManager | ||
63 | ->createQuery('SELECT n FROM App\Entity\Image n WHERE n.file_name LIKE :name') | ||
64 | ->setParameter('name', '%favicon%') | ||
65 | ->getResult(); | ||
66 | $data->setImages(new ArrayCollection($bulk_data)); | ||
59 | 67 | ||
60 | $entityManager->persist($page); | 68 | $entityManager->persist($page); |
61 | $entityManager->persist($node); | 69 | $entityManager->persist($node); |
@@ -66,6 +74,28 @@ if($_SERVER['REQUEST_METHOD'] === 'POST' && $_SESSION['admin'] === true) | |||
66 | header("Location: " . new URL(['page' => $page->getPagePath(), 'action' => 'modif_page'])); | 74 | header("Location: " . new URL(['page' => $page->getPagePath(), 'action' => 'modif_page'])); |
67 | die; | 75 | die; |
68 | } | 76 | } |
77 | |||
78 | /* -- suppression d'une page -- */ | ||
79 | elseif(isset($_POST['page_id']) && $_POST['page_id'] !== null | ||
80 | && isset($_POST['submit_hidden']) && $_POST['submit_hidden'] === '') | ||
81 | { | ||
82 | $page = $entityManager->find('App\Entity\Page', (int)$_POST['page_id']); | ||
83 | $nodes = $entityManager->getRepository('App\Entity\Node')->findBy(['page' => $page]); | ||
84 | $data = []; | ||
85 | foreach($nodes as $node){ | ||
86 | $data[] = $entityManager->getRepository('App\Entity\NodeData')->findOneBy(['node' => $node]); | ||
87 | $entityManager->remove($node); | ||
88 | } | ||
89 | foreach($data as $one_data){ | ||
90 | $entityManager->remove($one_data); | ||
91 | } | ||
92 | $entityManager->remove($page); // suppression en BDD | ||
93 | |||
94 | $entityManager->flush(); | ||
95 | header("Location: " . new URL); | ||
96 | die; | ||
97 | } | ||
98 | |||
69 | 99 | ||
70 | /* -- mode Modification d'une page -- */ | 100 | /* -- mode Modification d'une page -- */ |
71 | 101 | ||