diff options
author | n-peugnet <n.peugnet@free.fr> | 2019-01-30 21:15:17 +0100 |
---|---|---|
committer | vincent-peugnet <v.peugnet@free.fr> | 2019-01-30 23:16:26 +0100 |
commit | 8ac5a09605992f1e434cb793ceca7497c6f46d23 (patch) | |
tree | 091f9879f8f94b849300fef2d1a1238f3881f78e /app/class | |
parent | 396a5776cd043e899e4897ec50fc8edc52585512 (diff) | |
download | wcms-8ac5a09605992f1e434cb793ceca7497c6f46d23.tar.gz wcms-8ac5a09605992f1e434cb793ceca7497c6f46d23.zip |
feat: editBy to store the current editor of an art
Diffstat (limited to 'app/class')
-rw-r--r-- | app/class/art2.php | 28 | ||||
-rw-r--r-- | app/class/controller.php | 6 | ||||
-rw-r--r-- | app/class/controllerart.php | 36 | ||||
-rw-r--r-- | app/class/routes.php | 2 |
4 files changed, 72 insertions, 0 deletions
diff --git a/app/class/art2.php b/app/class/art2.php index 7354e8c..4f04858 100644 --- a/app/class/art2.php +++ b/app/class/art2.php @@ -39,6 +39,7 @@ class Art2 protected $affcount; protected $visitcount; protected $editcount; + protected $editby; const LEN = 255; @@ -110,6 +111,7 @@ class Art2 $this->setaffcount(0); $this->setvisitcount(0); $this->seteditcount(0); + $this->seteditby([]); } @@ -441,6 +443,10 @@ class Art2 return $this->editcount; } + public function editby($type = 'array') + { + return $this->editby; + } @@ -761,6 +767,13 @@ class Art2 } } + public function seteditby($editby) + { + if(is_array($editby)) { + $this->editby = $editby; + } + } + // __________________________________ C O U N T E R S ______________________________ @@ -794,6 +807,21 @@ class Art2 } } + public function addeditby(string $id) + { + $this->editby[$id] = true; + } + + public function removeeditby(string $id) + { + unset($this->editby[$id]); + } + + public function iseditedby() + { + return count($this->editby) > 0; + } + } diff --git a/app/class/controller.php b/app/class/controller.php index 65d61c3..ce1507a 100644 --- a/app/class/controller.php +++ b/app/class/controller.php @@ -79,6 +79,12 @@ class Controller $this->redirect($this->router->generate($route, []) . $get); } + public function error(int $code) + { + http_response_code($code); + exit; + } + } diff --git a/app/class/controllerart.php b/app/class/controllerart.php index ef720a1..dfdde7f 100644 --- a/app/class/controllerart.php +++ b/app/class/controllerart.php @@ -275,6 +275,7 @@ class Controllerart extends Controller $this->art->hydrate($date); $this->art->updateedited(); $this->art->addauthor($this->user->id()); + $this->art->removeeditby($this->user->id()); $this->artmanager->update($this->art); @@ -293,6 +294,41 @@ class Controllerart extends Controller $this->routedirect('art'); } + /** + * This function set the actual editor of the page + * + * @param string $artid as the page id + */ + public function editby(string $artid) + { + $this->art = new Art2(['id' => $artid]); + if($this->importart($artid)) { + $this->art->addeditby($this->user->id()); + $this->artmanager->update($this->art); + echo json_encode(['success' => true]); + } else { + $this->error(400); + } + } + + /** + * This function remove the actual editor of the page + * + * @param string $artid as the page id + */ + public function removeeditby(string $artid) + { + $this->art = new Art2(['id' => $artid]); + if($this->importart($artid)) { + $this->art->removeeditby($this->user->id()); + $this->artmanager->update($this->art); + echo json_encode(['success' => true]); + } else { + $this->error(400); + } + } + + public function movepanels() { $_SESSION['workspace']['showrightpanel'] = isset($_POST['workspace']['showrightpanel']); diff --git a/app/class/routes.php b/app/class/routes.php index 9f3ce37..f3b9adf 100644 --- a/app/class/routes.php +++ b/app/class/routes.php @@ -43,6 +43,8 @@ class Routes ['GET', '/[cid:art]/log', 'Controllerart#log', 'artlog'], ['GET', '/[cid:art]/download', 'Controllerart#download', 'artdownload'], ['POST', '/[cid:art]/edit', 'Controllerart#update', 'artupdate'], + ['POST', '/[cid:art]/editby', 'Controllerart#editby', 'arteditby'], + ['POST', '/[cid:art]/removeeditby', 'Controllerart#removeeditby', 'artremoveeditby'], ['GET', '/[cid:art]/delete', 'Controllerart#confirmdelete', 'artconfirmdelete'], ['POST', '/[cid:art]/delete', 'Controllerart#delete', 'artdelete'], ['GET', '/[cid:art]/[*]', 'Controllerart#artdirect', 'artread/etoile'], |