File: D:/HostingSpaces/SBogers10/finsteps.komma.pro/app/Components/ComponentService.php
<?php
/**
* Created by PhpStorm.
* User: mike
* Date: 27/07/2018
* Time: 15:22
*/
namespace App\Components;
use App\Components\Component\Component;
use App\Components\Component\ComponentSaveState;
use App\Components\Component\ViewComponent;
use App\Components\ComponentArea\ComponentAreaService;
use Komma\KMS\Core\AbstractTranslationModel;
use Illuminate\Support\Collection;
class ComponentService
{
/**
* @var ComponentAreaService
*/
private $componentAreaService;
/**
* ComponentService constructor.
* @param ComponentAreaService $componentAreaService
*/
public function __construct(ComponentAreaService $componentAreaService)
{
$this->componentAreaService = $componentAreaService;
}
/**
* For a View we want a simplified class which includes flat values instead of models
*
* @param AbstractTranslationModel $modelTranslation
* @return Collection
* @throws \ReflectionException
*/
public function getViewComponents(AbstractTranslationModel $modelTranslation)
{
$viewComponents = collect();
// Fetch components
$components = $modelTranslation->components();
/** @var Component $component */
foreach($components as $component)
{
// Create our ViewComponent
/** @var ViewComponent $viewComponent */
$viewComponent = new ViewComponent($component);
// Push prepared ViewComponent in collection
$viewComponents->push($viewComponent);
}
return $viewComponents;
}
}