aboutsummaryrefslogtreecommitdiff
path: root/app/class
diff options
context:
space:
mode:
authorvincent-peugnet <v.peugnet@free.fr>2019-01-30 15:56:04 +0100
committervincent-peugnet <v.peugnet@free.fr>2019-01-30 15:56:04 +0100
commit396a5776cd043e899e4897ec50fc8edc52585512 (patch)
tree51714a3aa981e698f4573f0ce54e22e1dc8338a8 /app/class
parent3309bd722454fa8696ce2415075f401e444c9910 (diff)
downloadwcms-396a5776cd043e899e4897ec50fc8edc52585512.tar.gz
wcms-396a5776cd043e899e4897ec50fc8edc52585512.zip
author filter home
Diffstat (limited to 'app/class')
-rw-r--r--app/class/modelart.php23
-rw-r--r--app/class/modelhome.php4
-rw-r--r--app/class/opt.php61
3 files changed, 85 insertions, 3 deletions
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) {