From d9816ef4affa3d7096a2189e9b171d9d130a727e Mon Sep 17 00:00:00 2001 From: vincent-peugnet Date: Fri, 10 Jan 2020 15:28:56 +0100 Subject: new feature : multi edit base working --- app/class/Controllerhome.php | 14 +++++++++++ app/class/Metaedit.php | 44 +++++++++++++++++++++++++++++++++++ app/class/Modelpage.php | 36 ++++++++++++++++++++++++++++- app/class/Routes.php | 1 + app/view/templates/home.php | 4 ++-- app/view/templates/homemenu.php | 51 ++++++++++++++++++++++++++++------------- 6 files changed, 131 insertions(+), 19 deletions(-) create mode 100644 app/class/Metaedit.php (limited to 'app') diff --git a/app/class/Controllerhome.php b/app/class/Controllerhome.php index 003a325..bb22e57 100644 --- a/app/class/Controllerhome.php +++ b/app/class/Controllerhome.php @@ -6,6 +6,7 @@ class Controllerhome extends Controllerpage { /** @var Modelhome */ protected $modelhome; + /** @var Opt */ protected $opt; /** @var Optlist */ protected $optlist; @@ -125,6 +126,19 @@ class Controllerhome extends Controllerpage } $this->routedirect('home'); } + + public function multiedit() + { + if ($this->user->issupereditor() && isset($_POST['pagesid'])) { + $datas = $_POST['datas'] ?? []; + $reset = $_POST['reset'] ?? []; + $addtag = $_POST['addtag'] ?? []; + foreach ($_POST['pagesid'] as $id) { + $this->pagemanager->pageedit($id, $datas, $reset, $addtag); + } + } + $this->routedirect('home'); + } } ?> diff --git a/app/class/Metaedit.php b/app/class/Metaedit.php new file mode 100644 index 0000000..e21a0c2 --- /dev/null +++ b/app/class/Metaedit.php @@ -0,0 +1,44 @@ +resettag) { + $page->tag([]); + } + $page->addtag($this->tag); + if($this->resetdate) { + $page->date() + } + $page->secure($this->secure); + $page->templatebody($this->templatebody); + $page->templatecss($this->templatecss); + $page->templatejavascript($this->templatejavascript); + + return $page; + } + +} + + + + + +?> \ No newline at end of file diff --git a/app/class/Modelpage.php b/app/class/Modelpage.php index 9438c96..3f4dcf4 100644 --- a/app/class/Modelpage.php +++ b/app/class/Modelpage.php @@ -152,11 +152,21 @@ class Modelpage extends Modeldb } } + /** + * Update a page in the database + * + * @todo Check if page already exist before updating ? + * + * @param Page $page The page that is going to be updated + * + * @return bool True if success otherwise, false + * + */ public function update(Page $page) { $pagedata = new Document($page->dry()); $pagedata->setId($page->id()); - $this->repo->store($pagedata); + return $this->repo->store($pagedata); } public function combine(Page $pagea, Page $pageb) @@ -323,4 +333,28 @@ class Modelpage extends Modeldb return $idlist; } + public function pageedit($pageid, $datas, $reset, $addtag) + { + $page = $this->get($pageid); + $page = $this->reset($page, $reset); + $page->hydrate($datas); + $page->addtag($addtag); + $this->update($page); + } + + + public function reset(Page $page, $reset) + { + if($reset['tag']) { + $page->settag([]); + } + if($reset['date']) { + // reset date as now + } + if($reset['datemodif']) { + // reset datemodif as now + } + return $page; + } + } diff --git a/app/class/Routes.php b/app/class/Routes.php index a803bd6..7bd373a 100644 --- a/app/class/Routes.php +++ b/app/class/Routes.php @@ -22,6 +22,7 @@ class Routes ['POST', '/columns', 'Controllerhome#columns', 'homecolumns'], ['GET', '//renderall', 'Controllerhome#renderall', 'homerenderall'], ['POST', '/bookmark', 'Controllerhome#bookmark', 'homebookmark'], + ['POST', '/multiedit', 'Controllerhome#multiedit', 'multiedit'], ['POST', '/upload', 'Controllerpage#upload', 'pageupload'], ['POST', '/!co', 'Controllerconnect#log', 'log'], ['GET', '/!co', 'Controllerconnect#connect', 'connect'], diff --git a/app/view/templates/home.php b/app/view/templates/home.php index 01bc0e4..63706d0 100644 --- a/app/view/templates/home.php +++ b/app/view/templates/home.php @@ -16,7 +16,7 @@ insert('homemenu', ['user' => $user, 'opt' => $opt, 'optlist' => $optlist]); + $this->insert('homemenu', ['user' => $user, 'opt' => $opt, 'optlist' => $optlist, 'pagelist' => $pagelist]); ?> @@ -85,7 +85,7 @@ - + diff --git a/app/view/templates/homemenu.php b/app/view/templates/homemenu.php index 838ca81..fc16340 100644 --- a/app/view/templates/homemenu.php +++ b/app/view/templates/homemenu.php @@ -44,30 +44,32 @@

Edit Meta infos

-
+ Tag
- + +
- +
Date
- + +
- +
- +
Privacy
- + @@ -76,21 +78,38 @@
Templates
- + + ' . $page . ''; + } + ?>
- +
- +
+ + + +
-- cgit v1.2.3