diff options
author | vincent-peugnet <v.peugnet@free.fr> | 2020-01-10 15:28:56 +0100 |
---|---|---|
committer | vincent-peugnet <v.peugnet@free.fr> | 2020-01-10 15:28:56 +0100 |
commit | d9816ef4affa3d7096a2189e9b171d9d130a727e (patch) | |
tree | 346e26956d0a7521a3736bc85beea397a24d1c46 | |
parent | 7001272f4e8b683cbc64564c5798d85a34ab9026 (diff) | |
download | wcms-d9816ef4affa3d7096a2189e9b171d9d130a727e.tar.gz wcms-d9816ef4affa3d7096a2189e9b171d9d130a727e.zip |
new feature : multi edit base working
-rw-r--r-- | app/class/Controllerhome.php | 14 | ||||
-rw-r--r-- | app/class/Metaedit.php | 44 | ||||
-rw-r--r-- | app/class/Modelpage.php | 36 | ||||
-rw-r--r-- | app/class/Routes.php | 1 | ||||
-rw-r--r-- | app/view/templates/home.php | 4 | ||||
-rw-r--r-- | app/view/templates/homemenu.php | 51 | ||||
-rw-r--r-- | src/home.js | 2 |
7 files changed, 132 insertions, 20 deletions
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 @@ +<?php + +namespace Wcms; + +class Pageedit extends Page +{ + protected $resettag; + protected $resetdate; + protected $emptycontent; + + + + + /** + * Edit a page based on object seting + * + * @param Page $page Page to be metaedited + * + * @return Page Edited page object + */ + public function editpage(Page $page) + { + if($this->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 @@ <?php $optlist = $optlist ?? null; - $this->insert('homemenu', ['user' => $user, 'opt' => $opt, 'optlist' => $optlist]); + $this->insert('homemenu', ['user' => $user, 'opt' => $opt, 'optlist' => $optlist, 'pagelist' => $pagelist]); ?> @@ -85,7 +85,7 @@ <tbody> <?php foreach ($table2 as $item) { ?> <tr> - <td class="hidephone"><input type="checkbox" name="id[]" value="<?= $item->id() ?>" id="id_<?= $item->id() ?>"></td> + <td class="hidephone"><input type="checkbox" name="pagesid[]" value="<?= $item->id() ?>" id="id_<?= $item->id() ?>" form="multiedit"></td> <td><label title="<?= $item->title() ?>" for="id_<?= $item->id() ?>"><?= $item->id() ?></label></td> <td><a href="<?= $this->upage('pageedit', $item->id()) ?>"><img src="<?= Wcms\Model::iconpath() ?>edit.png" class="icon"></a></td> <td><a href="<?= $this->upage('pageread/', $item->id()) ?>" target="_blank"><img src="<?= Wcms\Model::iconpath() ?>read.png" class="icon"></a></td> 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 @@ <input type="submit" value="delete"> </form> <h2>Edit Meta infos</h2> - <form action="" method="post"> + <form action="<?= $this->url('multiedit') ?>" method="post" id="multiedit"> <strong>Tag</strong> </br> - <input type="checkbox" name="resettag" id="resettag"> + <input type="hidden" name="reset[tag]" value="0"> + <input type="checkbox" name="reset[tag]" id="resettag" value="1"> <label for="resettag">reset tag(s)</label> </br> - <input type="text" name="tag" id="addtag"> + <input type="text" name="addtag" id="addtag"> <label for="addtag">add tag(s)</label> </br> <strong>Date</strong> </br> - <input type="checkbox" name="resetdate" id="resetdate"> + <input type="hidden" name="reset[date]" value="0"> + <input type="checkbox" name="reset[date]" id="resetdate" value="1"> <label for="resetdate">reset date as now</label> </br> - <input type="date" name="date" id="date"> + <input type="date" name="datas[pdate]" id="date"> <label for="date">Date</label> </br> - <input type="time" name="time" id="time"> + <input type="time" name="datas[ptime]" id="time"> <label for="time">Time</label> </br> <strong>Privacy</strong> </br> - <select name="level" id="setlevel"> - <option >--change privacy--</option> + <select name="datas[secure]" id="setlevel"> + <option value="" disabled selected>--change privacy--</option> <option value="0">public</option> <option value="1">private</option> <option value="2">not_published</option> @@ -76,21 +78,38 @@ </br> <strong>Templates</strong> </br> - <select name="templatebody" id="templatebody"> - <option>--set template body--</option> + <select name="datas[templatebody]" id="templatebody"> + <option value="" disabled selected>--set template body--</option> + <?php + foreach ($pagelist as $page) { + echo '<option value ="' . $page . '">' . $page . '</option>'; + } + ?> </select> <label for="templatebody">Body</label> </br> - <select name="templatecss" id="templatecss"> - <option>--set template css--</option> - </select> + <select name="datas[templatecss]" id="templatecss"> + <option value="" disabled selected>--set css template--</option> + <?php + foreach ($pagelist as $page) { + echo '<option value ="' . $page . '">' . $page . '</option>'; + } + ?> </select> <label for="templatecss">CSS</label> </br> - <select name="templatejavascript" id="templatejavascript"> - <option>--set template javascript--</option> - </select> + <select name="datas[templatejavascript]" id="templatejavascript"> + <option value="" disabled selected>--set javascript template--</option> + <?php + foreach ($pagelist as $page) { + echo '<option value ="' . $page . '">' . $page . '</option>'; + } + ?> </select> <label for="templatejavascript">Javascript</label> </br> + <input type="hidden" name="reset[datemodif]" value="0"> + <input type="checkbox" name="reset[datemodif]" id="resetdatemodif" value="1"> + <label for="resetdatemodif">update modification date</label> + </br> <input type="submit" value="edit"> </form> </div> diff --git a/src/home.js b/src/home.js index b10e7c3..670ae3e 100644 --- a/src/home.js +++ b/src/home.js @@ -2,7 +2,7 @@ let checkboxes = []; window.addEventListener('load', () => { - checkboxes = document.getElementsByName('id[]'); + checkboxes = document.getElementsByName('pagesid[]'); let checkall = document.getElementById('checkall'); let checkbox = document.createElement('input'); checkbox.type = 'checkbox'; |