aboutsummaryrefslogtreecommitdiff
path: root/app/class
diff options
context:
space:
mode:
Diffstat (limited to 'app/class')
-rw-r--r--app/class/Modelhome.php4
-rw-r--r--app/class/Modelpage.php19
-rw-r--r--app/class/Opt.php70
3 files changed, 75 insertions, 18 deletions
diff --git a/app/class/Modelhome.php b/app/class/Modelhome.php
index 943f4bd..9d9703d 100644
--- a/app/class/Modelhome.php
+++ b/app/class/Modelhome.php
@@ -16,6 +16,7 @@ class Modelhome extends Modelpage
$opt->setcol(['id', 'tag', 'linkfrom', 'linkto', 'description', 'title', 'datemodif', 'datecreation', 'date', 'secure', 'authors', 'visitcount', 'editcount', 'affcount']);
$opt->settaglist($table);
$opt->setauthorlist($table);
+ $opt->setpageidlist($table);
$opt->submit();
return $opt;
@@ -52,8 +53,9 @@ class Modelhome extends Modelpage
$filtertagfilter = $this->filtertagfilter($table, $opt->tagfilter(), $opt->tagcompare());
$filterauthorfilter = $this->filterauthorfilter($table, $opt->authorfilter(), $opt->authorcompare());
$filtersecure = $this->filtersecure($table, $opt->secure());
+ $filterlinkto = $this->filterlinkto($table, $opt->linkto());
- $filter = array_intersect($filtertagfilter, $filtersecure, $filterauthorfilter);
+ $filter = array_intersect($filtertagfilter, $filtersecure, $filterauthorfilter, $filterlinkto);
$table2 = [];
$table2invert = [];
foreach ($table as $page) {
diff --git a/app/class/Modelpage.php b/app/class/Modelpage.php
index e40ac04..b39b5db 100644
--- a/app/class/Modelpage.php
+++ b/app/class/Modelpage.php
@@ -290,7 +290,7 @@ class Modelpage extends Modeldb
return $filteredlist;
}
- public function filtersecure(array $pagelist, $secure)
+ public function filtersecure(array $pagelist, $secure) : array
{
$filteredlist = [];
foreach ($pagelist as $page) {
@@ -303,6 +303,23 @@ class Modelpage extends Modeldb
return $filteredlist;
}
+ /**
+ * @param array $pagelist Array of Page object
+ * @param string $linkto
+ */
+ public function filterlinkto(array $pagelist, string $linkto) : array
+ {
+ $filteredlist = [];
+ foreach ($pagelist as $page) {
+ if (in_array( $linkto, $page->linkfrom('array'))) {
+ $filteredlist[] = $page->id();
+ } elseif (empty($linkto)) {
+ $filteredlist[] = $page->id();
+ }
+ }
+ return $filteredlist;
+ }
+
public function tag(array $pagelist, $tagchecked)
{
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 '<a class="secure ' . $secure . '" href="?' . $this->getfilteradress(['secure' => $level]) . '">' . $secure . '</a>' . PHP_EOL;
}
+ public function linktolink(array $linkfromlist)
+ {
+ $linkfromstring = "";
+ foreach ($linkfromlist as $linkfrom ) {
+ $linkfromstring .= '<a class="linkfrom" href="?' . $this->getfilteradress(['linkto' => $linkfrom]) . '" >' . $linkfrom . '</a>' . 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)
{