<?php
namespace VisualMedia\ComponentBundle\Element\widgets;
use VisualMedia\BartBundle\Element\Component;
use VisualMedia\PageBundle\Entity\BasePage;
use VisualMedia\BartBundle\Element\backend\layout\ButtonElement;
use VisualMedia\ComponentBundle\Element\widgets\page\RowComponent;
use VisualMedia\ComponentBundle\Element\widgets\page\ColumnComponent;
use VisualMedia\BartBundle\Entity\RootEntity;
use VisualMedia\ComponentBundle\Element\Element;
use VisualMedia\ComponentBundle\Model\ComponentEntityModel;
use VisualMedia\ComponentBundle\Element\widgets\page\HeaderComponent;
use VisualMedia\ComponentBundle\Element\widgets\page\GlobalComponent;
use VisualMedia\ComponentBundle\Element\widgets\page\FooterComponent;
use VisualMedia\BartBundle\Controller\RootController;
class PageComponent extends ComponentsComponent{
public static function createComponents($entity, $componentField = false){
$component = new PageComponent();
$component->setPage($entity);
if($componentField) $component->componentField = $componentField;
$component->id = "components_".$entity->id;
$component->object = $entity;
$component->entity = $entity;
$components = [];
if($entity->{$component->componentField}){
$components = json_decode($entity->{$component->componentField},true);
$components = Element::fromArray($components);
if(!is_array($components)) $components = [$components];
$component->elements = $components;
}
else{
$component->elements = [];
$entity->{$component->componentField} = json_encode($component->elements);
}
if(RootController::getSetting("componenten_use_header"))$component->getHeader();
if(RootController::getSetting("componenten_use_footer"))$component->getFooter();
return $component;
}
public function getHeader(){
$header = $this->findBy("type","HeaderComponent");
if(!$header){
$header = GlobalComponent::findGlobalComponentBy("name", "header-default");
if($header){
$addHeader = new HeaderComponent();
$addHeader->loadData($header->getData());
array_unshift($this->elements,$addHeader);
}
}
else if (isset($header->header)){
$oldId = $header->id;
$header = GlobalComponent::findGlobalComponentBy("name", $header->header);
$this->replaceElement($header,$oldId);
//dd($this->elements);
}
}
public function getFooter(){
$footer = $this->findBy("type","FooterComponent");
if(!$footer){
$footer = GlobalComponent::findGlobalComponentBy("name", "footer-default");
if($footer){
$addFooter = new FooterComponent();
$addFooter->loadData($footer->getData());
$this->elements[] = $addFooter;
}
}
}
}
?>