<?php namespace App\Libs\Composers;

use App\Models\CaseStudyTemplateConfiguration;
use App\Models\Sector;

class CaseStudiesTemplateComposer
{

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

        /* $templateData = HpTemplateConfiguration::with('homepageSlides.testimonial', 'homepageSlides.image')
            ->where('entry_id', $page->id)->first();
        */

        $templateData = CaseStudyTemplateConfiguration::with(array(
            'slides' => function ($q) {
                $q->full()->with('testimonial')->orderBy("website_objects.position", "asc");
            }
        ))->where('entry_id', $page->id)->first();


        /*
        $corporateSectors = Sector::full()
            ->where('sector_type', 'corporate')
            ->orderBy('website_objects.position', 'asc')->get();
        $publicSectors = Sector::full()
            ->where('sector_type', 'public')
            ->orderBy('website_objects.position', 'asc')->get();

        $corporateSectorAll = new Sector;
        $corporateSectorAll->id = "corporate";
        $corporateSectorAll->title = "All corporate";
        $corporateSectorAll->sector_type = "corporate";
        $corporateSectors->prepend($corporateSectorAll);

        $publicSectorAll = new Sector;
        $publicSectorAll->id = "public";
        $publicSectorAll->title = "All public";
        $publicSectorAll->sector_type = "public";
        $publicSectors->prepend($publicSectorAll);
        */

        $sectors = Sector::full()
            ->where('status', 'published')
            ->orderBy('website_objects.position', 'asc')
            ->get();


        $view->with(array(
            'templateData' => $templateData,
            'sectors' => $sectors
            /* 'corporateSectors' => $corporateSectors,
            'publicSectors' => $publicSectors */
        ));
    }
}
