<?php namespace App\Libs\Composers\CF;

use CfSolution;

class CfSolutionsTemplateComposer
{
    use \App\Libs\Composers\BarComposerTrait,
        \App\Libs\Composers\CF\CfRelatedComposerTrait,
        \App\Libs\Composers\SidebarComposerTrait;

    public function compose($view)
    {
        $data = $view->getData();
        $page = $data['object'];

        $templateData = \CfSolutionsTemplateCfg::with(array(
            'headerImage', 'tiles' => function ($q) {
                $q->full()->with('image', 'sideImage')->orderBy("website_objects.position", "asc");
            }
        ))->where('entry_id', $page->id)->first();

        $this->composeBars($view, $templateData);
        $this->composeRelated($view, $templateData);

        $solutions = CfSolution::full()
            ->with('solutionIcon')
            ->where('is_highlight', 1)
            ->where('status', 'published')
            ->where('type', $templateData->type)
            ->orderBy('website_objects.position', 'asc')->get();

        $this->composeSidebar($view, \CfSolutionsTemplateCfg::query());

        $view->with(array(
            'solutions' => $solutions,
            'templateData' => $templateData,
            'tiles' => $templateData->tiles
        ));
    }
}
