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

use ContactsTemplateConf;
use DB;
use Localization;

class CfContactsTemplateComposer
{
    use \App\Libs\Composers\CF\CfRelatedComposerTrait;

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

        $continents = DB::table('countries')
            ->select(DB::raw('DISTINCT continent'))
            ->join('offices', 'countries.id', '=', 'offices.country_id')
            ->join('website_objects', 'website_objects.object_id', '=', 'offices.id')
            ->where('website_objects.object_type', 'Office')
            ->where('website_objects.status', 'published')
            ->where('website_objects.website_id', $website->id)
            ->get();

        $templateData = ContactsTemplateConf::where('entry_id', $page->id)
            ->first();

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

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