Add related pages function

This commit is contained in:
Diego Najar 2020-07-23 12:14:43 +02:00
parent 2517f0d181
commit 1e778b3b54
3 changed files with 27 additions and 1 deletions

View file

@ -34,6 +34,7 @@ class dbList extends dbJSON
}
// Returns the list of keys filter by pageNumber
// $pageNumber start in 1
public function getList($key, $pageNumber, $numberOfItems)
{
if (!isset($this->db[$key])) {

@ -1 +1 @@
Subproject commit 372403e6a9e33f57ccd4f57ad35007248440220e
Subproject commit 09138280134ec8014982f260c1ebb6a5b0091fdc

View file

@ -265,6 +265,8 @@ class Page {
return implode(',', $tags);
}
public function json($returnsArray=false)
{
$tmp['key'] = $this->key();
@ -582,4 +584,27 @@ class Page {
}
return false;
}
// Returns an array with all pages key related to the page
// The relation is based on the tags
public function related() {
global $tags;
$pageTags = $this->tags(true);
$list = array();
// For each tag get the list of related pages
foreach ($pageTags as $tagKey=>$tagName) {
$pagesRelated = $tags->getList($tagKey, 1, -1);
$list = array_merge($list, $pagesRelated);
}
// Remove duplicates
$list = array_unique($list);
// Remove himself from the list
if (($key = array_search($this->key(), $list)) !== false) {
unset($list[$key]);
}
return $list;
}
}