Phosphorum\Controllers\DiscussionsController::showRelatedAction PHP Method

showRelatedAction() public method

Finds related posts
public showRelatedAction ( )
    public function showRelatedAction()
    {
        $this->view->setRenderLevel(View::LEVEL_ACTION_VIEW);
        $post = Posts::findFirstById($this->request->getPost('id'));
        if ($post) {
            $indexer = new Indexer();
            $posts = $indexer->search(['title' => $post->title, 'category' => $post->categories_id], 5, true);
            if (count($posts) == 0) {
                $posts = $indexer->search(['title' => $post->title], 5, true);
            }
            $this->view->setVar('posts', $posts);
        } else {
            $this->view->setVar('posts', []);
        }
    }