diff options
author | vincent-peugnet <v.peugnet@free.fr> | 2020-02-08 15:18:54 +0100 |
---|---|---|
committer | vincent-peugnet <v.peugnet@free.fr> | 2020-02-08 15:18:54 +0100 |
commit | c0a2817accea23837ab85b8ba31aabc7fbb20fc3 (patch) | |
tree | 7ccfc4ffd83c9ab21538706b969d444019701981 /app/class/Controllerpage.php | |
parent | 36f5229b006668c989399d91a0ff849f82b9b8cf (diff) | |
download | wcms-c0a2817accea23837ab85b8ba31aabc7fbb20fc3.tar.gz wcms-c0a2817accea23837ab85b8ba31aabc7fbb20fc3.zip |
new feature : duplicate close #14
Diffstat (limited to 'app/class/Controllerpage.php')
-rw-r--r-- | app/class/Controllerpage.php | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/app/class/Controllerpage.php b/app/class/Controllerpage.php index 585db0a..92632fc 100644 --- a/app/class/Controllerpage.php +++ b/app/class/Controllerpage.php @@ -230,6 +230,16 @@ class Controllerpage extends Controller } } + public function addascopy(string $id, string $copy) + { + $id = idclean($id); + if($this->copy($copy, $id)) { + $this->routedirect('pageedit', ['page' => $this->page->id()]); + } else { + $this->routedirect('pageread/', ['page' => $id]); + } + } + public function confirmdelete($id) { $this->setpage($id, 'pageconfirmdelete'); @@ -304,6 +314,38 @@ class Controllerpage extends Controller $this->routedirect('home'); } + public function duplicate(string $srcid, string $targetid) + { + $targetid = idclean($targetid); + if ($this->copy($srcid, $targetid)) { + $this->routedirect('pageread/', ['page' => $targetid]); + } else { + $this->routedirect('pageread/', ['page' => idclean($srcid)]); + + } + } + + /** + * Copy a page to a new ID + * + * @param string $srcid Source page ID + * @param string $targetid Target page ID + */ + public function copy(string $srcid, string $targetid) + { + if ($this->user->iseditor()) { + $this->page = $this->pagemanager->get($srcid); + if($this->page !== false && $this->canedit() && $this->pagemanager->get($targetid) === false) { + $this->page->setid($targetid); + $this->page->setdatecreation(true); // Reset date of creation + $this->page->addauthor($this->user->id()); + $this->pagemanager->add($this->page); + return true; + } + } + return false; + } + public function update($id) { $this->setpage($id, 'pageupdate'); |