From 0893f20446a6645c5f928f2cb41f688a9fc5fcf1 Mon Sep 17 00:00:00 2001 From: vincent-peugnet Date: Wed, 12 Feb 2020 20:20:06 +0100 Subject: refactoring home>desktop, fix #47 --- app/class/Controllerhome.php | 67 +++++++++++++++++++++++++++++--------------- 1 file changed, 45 insertions(+), 22 deletions(-) (limited to 'app/class/Controllerhome.php') diff --git a/app/class/Controllerhome.php b/app/class/Controllerhome.php index 5a9110a..42ace87 100644 --- a/app/class/Controllerhome.php +++ b/app/class/Controllerhome.php @@ -27,23 +27,14 @@ class Controllerhome extends Controllerpage } else { - $table = $this->modelhome->getlister(); - $this->opt = $this->modelhome->optinit($table); + $pagelist = $this->modelhome->getlister(); + $this->opt = $this->modelhome->optinit($pagelist); $vars['colors'] = new Colors($this->opt->taglist()); - if (!isset($_GET['search'])) { - $searchopt = ['title' => 1, 'description' => 1, 'content' => 1, 'other' => 0, 'casesensitive' => 0]; - } else { - $searchopt['title'] = $_GET['title'] ?? 0; - $searchopt['description'] = $_GET['description'] ?? 0; - $searchopt['content'] = $_GET['content'] ?? 0; - $searchopt['other'] = $_GET['other'] ?? 0; - $searchopt['casesensitive'] = $_GET['case'] ?? 0; - } - $regex = $_GET['search'] ?? ''; + $deepsearch = $this->deepsearch(); - $vars['table2'] = $this->modelhome->table2($table, $this->opt, $regex , $searchopt); + $vars['table2'] = $this->modelhome->table2($pagelist, $this->opt, $deepsearch['regex'] , $deepsearch['searchopt']); $vars['columns'] = $this->modelhome->setcolumns($this->user->columns()); @@ -52,22 +43,49 @@ class Controllerhome extends Controllerpage $vars['editorlist'] = $this->usermanager->getlisterbylevel(2, '>='); $vars['user'] = $this->user; $vars['opt'] = $this->opt; - $vars['deepsearch'] = $regex; - $vars['searchopt'] = $searchopt; + $vars['deepsearch'] = $deepsearch['regex']; + $vars['searchopt'] = $deepsearch['searchopt']; - $vars['footer'] = ['version' => getversion(), 'total' => count($table), 'database' => Config::pagetable()]; + $vars['footer'] = ['version' => getversion(), 'total' => count($pagelist), 'database' => Config::pagetable()]; - if (isset($_POST['query']) && $this->user->iseditor()) { - $datas = array_merge($_POST, $_SESSION['opt']); - $this->optlist = $this->modelhome->Optlistinit($table); - $this->optlist->hydrate($datas); - $vars['optlist'] = $this->optlist; - } + $this->listquery($pagelist); + + $vars['optlist'] = $this->optlist ?? null; $this->showtemplate('home', $vars); } } + /** + * Look for GET deepsearch datas and transform it an array + * + * @return array containing `string $regex` and `array $searchopt` + */ + public function deepsearch() : array + { + if (!isset($_GET['search'])) { + $searchopt = ['title' => 1, 'description' => 1, 'content' => 1, 'other' => 0, 'casesensitive' => 0]; + } else { + $searchopt['title'] = $_GET['title'] ?? 0; + $searchopt['description'] = $_GET['description'] ?? 0; + $searchopt['content'] = $_GET['content'] ?? 0; + $searchopt['other'] = $_GET['other'] ?? 0; + $searchopt['casesensitive'] = $_GET['case'] ?? 0; + } + $regex = $_GET['search'] ?? ''; + return ['regex' => $regex, 'searchopt' => $searchopt]; + } + + public function listquery(array $pagelist) + { + if (isset($_POST['query']) && $this->user->iseditor()) { + $datas = array_merge($_POST, $_SESSION['opt']); + $this->optlist = $this->modelhome->Optlistinit($pagelist); + $this->optlist->hydrate($datas); + $vars['optlist'] = $this->optlist; + } + } + public function columns() { if (isset($_POST['columns']) && $this->user->iseditor()) { @@ -110,6 +128,11 @@ class Controllerhome extends Controllerpage } } + public function map() + { + + } + /** * Render every pages in the database */ -- cgit v1.2.3