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

use CfHpTemplateConfiguration;

class CfHomeTemplateComposer
{

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

        $templateData = CfHpTemplateConfiguration::with(array(
            'slides' => function ($q) {
                $q->full()
                    ->where('is_active', 1)
                    ->with('image')
                    ->orderBy("website_objects.position", "asc");
            }, 'tiles' => function ($q) {
                $q->full()->with('image', 'sideImage')->orderBy("website_objects.position", "asc");
            }, 'lboxIcons' => function ($q) {
                $q->orderBy("cf_temp_lbox_images.position", "asc");
            }, 'lboxHoverIcons' => function ($q) {
                $q->orderBy("cf_temp_lbox_hover_images.position", "asc");
            },
            'rboxIcons' => function ($q) {
                $q->orderBy("cf_temp_rbox_images.position", "asc");
            }, 'rboxHoverIcons' => function ($q) {
                $q->orderBy("cf_temp_rbox_hover_images.position", "asc");
            }, 'caseStudies' => function ($q) {
                $q->full()->with('clientImage', 'overviewImage')
                    ->where('status', 'published')
                    ->orderBy("cf_home_case_studies.position", "asc");
            }, 'contact' => function ($q) {
                $q->with('image');
            }
        ))->where('entry_id', $page->id)->first();

        $latestNews = \News::full()
            ->where('status', 'published')
            ->where('type', 'news')
            ->orderBy('date', 'desc')
            ->take(3)
            ->get();


        $view->with(array(
            'homeData' => $templateData,
            'latestNews' => $latestNews
        ));
    }
}
