From 396a5776cd043e899e4897ec50fc8edc52585512 Mon Sep 17 00:00:00 2001 From: vincent-peugnet Date: Wed, 30 Jan 2019 15:56:04 +0100 Subject: author filter home --- app/class/modelart.php | 23 ++++++++++++++++ app/class/modelhome.php | 4 ++- app/class/opt.php | 61 ++++++++++++++++++++++++++++++++++++++++-- app/view/templates/homeopt.php | 48 ++++++++++++++++++++++++++++++--- 4 files changed, 130 insertions(+), 6 deletions(-) (limited to 'app') diff --git a/app/class/modelart.php b/app/class/modelart.php index 0cb9b1c..45ff3c2 100644 --- a/app/class/modelart.php +++ b/app/class/modelart.php @@ -178,6 +178,29 @@ class Modelart extends Modeldb return $filteredlist; } + public function filterauthorfilter(array $artlist, array $authorchecked, $authorcompare = 'OR') + { + + $filteredlist = []; + foreach ($artlist as $art) { + if (empty($authorchecked)) { + $filteredlist[] = $art->id(); + } else { + $inter = (array_intersect($art->authors('array'), $authorchecked)); + if ($authorcompare == 'OR') { + if (!empty($inter)) { + $filteredlist[] = $art->id(); + } + } elseif ($authorcompare == 'AND') { + if (!array_diff($authorchecked, $art->authors('array'))) { + $filteredlist[] = $art->id(); + } + } + } + } + return $filteredlist; + } + public function filtersecure(array $artlist, $secure) { $filteredlist = []; diff --git a/app/class/modelhome.php b/app/class/modelhome.php index 78e51ba..fb5989c 100644 --- a/app/class/modelhome.php +++ b/app/class/modelhome.php @@ -13,6 +13,7 @@ class Modelhome extends Modelart $opt = new Opt(Art2::classvarlist()); $opt->setcol(['id', 'tag', 'linkfrom', 'linkto', 'description', 'title', 'datemodif', 'datecreation', 'date', 'secure', 'visitcount']); $opt->settaglist($table); + $opt->setauthorlist($table); $opt->submit(); return $opt; @@ -27,9 +28,10 @@ class Modelhome extends Modelart $filtertagfilter = $listmanager->filtertagfilter($table, $opt->tagfilter(), $opt->tagcompare()); + $filterauthorfilter = $listmanager->filterauthorfilter($table, $opt->authorfilter(), $opt->authorcompare()); $filtersecure = $listmanager->filtersecure($table, $opt->secure()); - $filter = array_intersect($filtertagfilter, $filtersecure); + $filter = array_intersect($filtertagfilter, $filtersecure, $filterauthorfilter); $table2 = []; $table2invert = []; foreach ($table as $art) { diff --git a/app/class/opt.php b/app/class/opt.php index 6ea3e7e..9eddf9f 100644 --- a/app/class/opt.php +++ b/app/class/opt.php @@ -5,11 +5,14 @@ class Opt private $order = 1; private $tagfilter = []; private $tagcompare = 'OR'; + private $authorfilter = []; + private $authorcompare = 'OR'; private $secure = 4; private $linkto = ['min' => '0', 'max' => '0']; private $linkfrom = ['min' => '0', 'max' => '0']; private $col = ['id']; private $taglist = []; + private $authorlist = []; private $invert = 0; private $artvarlist; @@ -64,7 +67,7 @@ class Opt public function getall() { - $optlist = ['sortby', 'order', 'secure', 'tagcompare', 'tagfilter', 'invert']; + $optlist = ['sortby', 'order', 'secure', 'tagcompare', 'tagfilter', 'authorcompare', 'authorfilter', 'invert']; foreach ($optlist as $method) { if (method_exists($this, $method)) { @@ -101,6 +104,10 @@ class Opt foreach ($this->tagfilter as $tag) { $adress .= '&tagfilter[]=' . $tag; } + $adress .= '&authorcompare=' . $this->authorcompare; + foreach ($this->authorfilter as $author) { + $adress .= '&authorfilter[]=' . $author; + } if($this->invert == 1) { $adress .= '&invert=1'; } @@ -141,6 +148,16 @@ class Opt return $this->tagcompare; } + public function authorfilter($type = 'array') + { + return $this->authorfilter; + } + + public function authorcompare() + { + return $this->authorcompare; + } + public function linkto($type = 'array') { return $this->linkto; @@ -165,6 +182,11 @@ class Opt return $this->taglist; } + public function authorlist() + { + return $this->authorlist; + } + public function invert() { return $this->invert; @@ -213,6 +235,26 @@ class Opt } } + public function setauthorfilter($authorfilter) + { + if (!empty($authorfilter) && is_array($authorfilter)) { + $authorfilterverif = []; + foreach ($authorfilter as $author) { + if(array_key_exists($author, $this->authorlist)) { + $authorfilterverif[] = $author; + } + } + $this->authorfilter = $authorfilterverif; + } + } + + public function setauthorcompare($authorcompare) + { + if (in_array($authorcompare, ['OR', 'AND'])) { + $this->authorcompare = $authorcompare; + } + } + public function setsecure($secure) { if ($secure >= 0 && $secure <= 5) { @@ -257,7 +299,6 @@ class Opt } } - public function settaglist(array $artlist) { $taglist = []; @@ -274,6 +315,22 @@ class Opt $this->taglist = $taglist; } + public function setauthorlist(array $artlist) + { + $authorlist = []; + foreach ($artlist as $art) { + foreach ($art->authors('array') as $author) { + if (!array_key_exists($author, $authorlist)) { + $authorlist[$author] = 1; + } else { + $authorlist[$author]++; + } + } + } + $authorlistsorted = arsort($authorlist); + $this->authorlist = $authorlist; + } + public function setinvert(int $invert) { if ($invert == 0 || $invert == 1) { diff --git a/app/view/templates/homeopt.php b/app/view/templates/homeopt.php index 4008a71..36b44c5 100644 --- a/app/view/templates/homeopt.php +++ b/app/view/templates/homeopt.php @@ -28,8 +28,9 @@ foreach ($opt->col('array') as $key => $col) {
  • secure() == 0 ? "checked" : "" ?>/>
  • -
    Tag + +
    + +
    + Author(s) + + + +
    invert() == 1) { -- cgit v1.2.3