<?php
namespace App\Libs\Backoffice\Generic\ContentInfo;

use App\Libs\Facades\ContentTypes;

class Block implements BaseContentInfo
{
    const RELATED_CONTENT_TYPES = [
        'Entry', 'Project', 'BlogPost', 'CaseStudy', 'EventItem', 'News', 'Publication', 'Sector', 'Solution'
    ];

    public function getInfoView($contentType, $model)
    {
        $wols = $model->websites->first()->languages;

        $referringModels = [];
        foreach (self::RELATED_CONTENT_TYPES as $relatedContentClass) {
            $relatedContentClass = 'App\\Models\\' . $relatedContentClass;
            $contentType = ContentTypes::findByModel($relatedContentClass);
            $referringModels[$contentType->getType()] = $relatedContentClass::withTrashed()->full()->whereHas('blocks', function ($query) use ($model) {
                $query->where('blocks.id', $model->id);
            })->get();
        }

        return view('admin/generic/pages/content_info/block', array(
            "contentType" => $contentType,
            "model" => $model,
            "wols" => $wols,
            "referringModels" => $referringModels
        ));
    }
}
