<?PHP
class MainView extends View
{
    function fetch()
    {
        $limits = array(
            "news"     => 3,
            "blog"     => 4,
            "workers"  => 4,
            "services" => 100,
            "sales"    => 2,
            "reviews"  => 10
        );

        $page = $this->pages->get_page('');
        if(!$page || !$page->visible)
            return false;

        $page->related_banners = $this->banners->get_banners(array('page_id' => $page->id));

        $schema = array();
        $schema[] = $this->schema->create_breadcrumbs($page);
        $schema[] = $this->schema->create_local_business($page);
        $this->design->assign('schema', $schema);

        //формируем данные для главной страницы
        foreach(array("services", "sales", "news", "workers", "reviews") AS $url)
        {
            $tmp = $this->pages->get_page($url);
            $content = $this->pages->get_pages(array('parent_id' => $tmp->id, 'limit' => $limits[$url]));
            $this->design->assign($url, $content);
        }

        $blog = $this->blog->get_posts(array('limit' => $limits["blog"]));
        $this->design->assign('blog', $blog);

        $portfolio = $this->pages->get_page('portfolio');
        $this->design->assign('portfolio', $portfolio);

        $this->design->assign('page', $page);
        $this->design->assign('meta_title', $page->meta_title);
        $this->design->assign('meta_description', $page->meta_description);

        return $this->design->fetch($page->template);
    }
}
