From 8e2abd192527a308d08920c69ab4a551b6f1e994 Mon Sep 17 00:00:00 2001 From: vincent-peugnet Date: Wed, 22 Jan 2020 01:21:39 +0100 Subject: new feature : multidelete --- app/class/Controllerhome.php | 18 ++++++++++++++++-- app/class/Modelpage.php | 24 ++++++++++++++++++++---- app/view/templates/homemenu.php | 10 ++++++---- 3 files changed, 42 insertions(+), 10 deletions(-) diff --git a/app/class/Controllerhome.php b/app/class/Controllerhome.php index 80644d1..1603511 100644 --- a/app/class/Controllerhome.php +++ b/app/class/Controllerhome.php @@ -129,7 +129,7 @@ class Controllerhome extends Controllerpage public function multi() { - if(isset($_POST['action'])) { + if(isset($_POST['action']) && $this->user->issupereditor() && !empty($_POST['pagesid'])) { switch ($_POST['action']) { case 'edit': $this->multiedit(); @@ -138,6 +138,10 @@ class Controllerhome extends Controllerpage case 'render': $this->multirender(); break; + + case 'delete': + $this->multidelete(); + break; } } $this->routedirect('home'); @@ -145,7 +149,7 @@ class Controllerhome extends Controllerpage public function multiedit() { - if ($this->user->issupereditor() && isset($_POST['pagesid'])) { + if (isset($_POST['pagesid'])) { $datas = $_POST['datas']?? []; $datas = array_filter($datas, function ($var) { return $var !== ""; @@ -169,6 +173,16 @@ class Controllerhome extends Controllerpage } } + + public function multidelete() + { + if(isset($_POST['confirmdelete']) && $_POST['confirmdelete']) { + $pagelist = $_POST['pagesid'] ?? []; + foreach ($pagelist as $id) { + $this->pagemanager->delete($id); + } + } + } } ?> diff --git a/app/class/Modelpage.php b/app/class/Modelpage.php index 21cdf8a..1cc6b27 100644 --- a/app/class/Modelpage.php +++ b/app/class/Modelpage.php @@ -134,13 +134,29 @@ class Modelpage extends Modeldb } } - public function delete(Page $page) + /** + * Delete a page and it's linked rendered html and css files + * + * @param Page|string $id could be an Page object or a id string + * + * @return bool true if success otherwise false + */ + public function delete($page) : bool { - $this->repo->delete($page->id()); - $this->unlink($page->id()); + if ($page instanceof Page) { + $page = $page->id(); + } + if (is_string($page)) { + $this->unlink($page); + return $this->repo->delete($page); + } else { + return false; + } } - + /** + * Delete rendered CSS and HTML files + */ public function unlink(string $pageid) { $files = ['.css', '.quick.css', '.js']; diff --git a/app/view/templates/homemenu.php b/app/view/templates/homemenu.php index 25ce60c..2ee1381 100644 --- a/app/view/templates/homemenu.php +++ b/app/view/templates/homemenu.php @@ -37,11 +37,7 @@ Edit -- cgit v1.2.3