<?php

namespace Startup\Forum\Http\Controllers;

use App\Http\Controllers\PublicWebController as PublicController;
use Startup\Forum\Interfaces\ForumRepositoryInterface;

class ForumPublicWebController extends PublicController
{
    /**
     * Constructor.
     *
     * @param type \Startup\Forum\Interfaces\ForumRepositoryInterface $forum
     *
     * @return type
     */
    public function __construct(ForumRepositoryInterface $forum)
    {
        $this->repository = $forum;
        parent::__construct();
    }

    /**
     * Show forum's list.
     *
     * @param string $slug
     *
     * @return response
     */
    protected function index()
    {
        $forums = $this->repository->scopeQuery(function($query){
            return $query->orderBy('id','DESC');
        })->paginate();

        return $this->theme->of('forum::public.forum.index', compact('forums'))->render();
    }

    /**
     * Show forum.
     *
     * @param string $slug
     *
     * @return response
     */
    protected function show($slug)
    {
        $forum = $this->repository->scopeQuery(function($query) use ($slug) {
            return $query->orderBy('id','DESC')
                         ->where('slug', $slug);
        })->first(['*']);

        return $this->theme->of('forum::public.forum.show', compact('forum'))->render();
    }
}