Skip to content

Commit

Permalink
change random page behavior
Browse files Browse the repository at this point in the history
limit the page selection to intersection with linkto of origin.
Instead of showing an error if random page is out of list.
  • Loading branch information
vincent-peugnet committed Jan 19, 2024
1 parent b7722d4 commit 0d66967
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
12 changes: 4 additions & 8 deletions app/class/Controllerrandom.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,10 @@ public function direct()
$pages = $this->pagemanager->pagelist();
$pages = $this->pagemanager->pagetable($pages, $this->optrandom);
unset($pages[$origin->id()]);
if (!empty($pages)) {
$page = $pages[array_rand($pages)];

if (in_array($page->id(), $origin->linkto())) {
$this->routedirect('pageread', ['page' => $page->id()]);
} else {
$message = 'Wrong filters';
}
$keys = array_intersect_key($pages, array_flip($origin->linkto()));
if (!empty($keys)) {
$page = $pages[array_rand($keys)];
$this->routedirect('pageread', ['page' => $page->id()]);
} else {
$message = 'Empty set of page';
}
Expand Down
2 changes: 1 addition & 1 deletion app/class/Modelpage.php
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ public function renderpage(Page $page, AltoRouter $router): Page
* @param string $regex Regex to match.
* @param array $searchopt Option search, could be `content` `title` `description`.
*
* @return Page[] associative array of `Page` objects *
* @return Page[] associative array of `Page` objects
*/
public function pagetable(array $pagelist, Opt $opt, $regex = '', $searchopt = []): array
{
Expand Down

0 comments on commit 0d66967

Please sign in to comment.