From 0937c851313b5098dc15e5d411b6c3638cbd5116 Mon Sep 17 00:00:00 2001 From: vincent-peugnet Date: Wed, 12 Feb 2020 15:31:08 +0100 Subject: new feature : filter by link to --- app/class/Opt.php | 70 ++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 54 insertions(+), 16 deletions(-) (limited to 'app/class/Opt.php') diff --git a/app/class/Opt.php b/app/class/Opt.php index e920cb7..e0a8492 100644 --- a/app/class/Opt.php +++ b/app/class/Opt.php @@ -11,14 +11,15 @@ class Opt extends Item protected $authorfilter = []; protected $authorcompare = 'AND'; protected $secure = 4; - protected $linkto = ['min' => '0', 'max' => '0']; - protected $linkfrom = ['min' => '0', 'max' => '0']; + protected $linkto = ''; protected $col = ['id']; protected $taglist = []; protected $authorlist = []; protected $invert = 0; protected $limit = 0; + protected $pageidlist = []; + protected $pagevarlist; public function __construct(array $donnees = []) @@ -63,7 +64,7 @@ class Opt extends Item public function getall() { - $optlist = ['sortby', 'order', 'secure', 'tagcompare', 'tagfilter', 'authorcompare', 'authorfilter', 'limit', 'invert']; + $optlist = ['sortby', 'order', 'secure', 'tagcompare', 'tagfilter', 'authorcompare', 'authorfilter', 'limit', 'invert', 'linkto']; foreach ($optlist as $method) { if (method_exists($this, $method)) { @@ -140,6 +141,15 @@ class Opt extends Item return '' . $secure . '' . PHP_EOL; } + public function linktolink(array $linkfromlist) + { + $linkfromstring = ""; + foreach ($linkfromlist as $linkfrom ) { + $linkfromstring .= '' . $linkfrom . '' . PHP_EOL; + } + return $linkfromstring; + } + public function getfilteradress(array $vars = []) { @@ -230,16 +240,11 @@ class Opt extends Item return $this->authorcompare; } - public function linkto($type = 'array') + public function linkto($type = 'string') { return $this->linkto; } - public function linkfrom($type = 'array') - { - return $this->linkfrom; - } - public function col($type = 'array') { if ($type == 'string') { @@ -274,6 +279,11 @@ class Opt extends Item return $this->limit; } + public function pageidlist() + { + return $this->pageidlist; + } + // __________________________________________________ S E T _____________________________________________ @@ -339,14 +349,19 @@ class Opt extends Item } } - public function setlinkto($range) + public function setlinkto($linkto) : bool { - $this->linkto = $range; - } - - public function setlinkfrom($range) - { - $this->linkfrom = $range; + if (is_string($linkto)) { + if (in_array($linkto, $this->pageidlist)) { + + $this->linkto = idclean($linkto); + return true; + } else { + return false; + } + } else { + return false; + } } public function setlinktomin($min) @@ -428,6 +443,29 @@ class Opt extends Item $this->limit = $limit; } + /** + * Import list of pages IDs + * + * @param array $pageidlist could be array of IDs or array of Page Object + * + * @return bool false if array content isn't string or Pages, otherwise : true + */ + public function setpageidlist(array $pageidlist) : bool + { + $idlist = []; + foreach ($pageidlist as $item) { + if (is_string($item)) { + $idlist[] = $item; + } elseif ($item instanceof Page) { + $idlist[] = $item->id(); + } else { + return false; + } + } + $this->pageidlist = $idlist; + return true; + } + public function setpagevarlist(array $pagevarlist) { -- cgit v1.2.3