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/opt.php | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 59 insertions(+), 2 deletions(-) (limited to 'app/class/opt.php') 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) { -- cgit v1.2.3