folderstructure change
This commit is contained in:
committed by
Steffen Schröder
parent
043c85fa97
commit
570b32fff8
116
application/core/Libs/FML/Elements/FrameModel.php
Normal file
116
application/core/Libs/FML/Elements/FrameModel.php
Normal file
@ -0,0 +1,116 @@
|
||||
<?php
|
||||
|
||||
namespace FML\Elements;
|
||||
|
||||
use FML\Controls\Control;
|
||||
use FML\Types\Container;
|
||||
use FML\Types\Renderable;
|
||||
|
||||
/**
|
||||
* Class representing a Frame Model
|
||||
*
|
||||
* @author steeffeen
|
||||
*/
|
||||
class FrameModel implements Container, Renderable {
|
||||
/*
|
||||
* Protected Properties
|
||||
*/
|
||||
protected $tagName = 'framemodel';
|
||||
protected $id = '';
|
||||
protected $children = array();
|
||||
protected $format = null;
|
||||
|
||||
/**
|
||||
* Set Model Id
|
||||
*
|
||||
* @param string $id Model Id
|
||||
* @return \FML\Elements\FrameModel
|
||||
*/
|
||||
public function setId($id) {
|
||||
$this->id = (string) $id;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Model Id
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getId() {
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assign an Id if necessary
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function checkId() {
|
||||
if (!$this->id) {
|
||||
$this->id = uniqid();
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @see \FML\Types\Container::add()
|
||||
* @return \FML\Elements\FrameModel
|
||||
*/
|
||||
public function add(Control $childControl) {
|
||||
if (!in_array($childControl, $this->children, true)) {
|
||||
array_push($this->children, $childControl);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @see \FML\Types\Container::removeChildren()
|
||||
* @return \FML\Elements\FrameModel
|
||||
*/
|
||||
public function removeChildren() {
|
||||
$this->children = array();
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @see \FML\Types\Container::setFormat()
|
||||
* @return \FML\Elements\FrameModel
|
||||
*/
|
||||
public function setFormat(Format $format) {
|
||||
$this->format = $format;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @see \FML\Types\Container::getFormat()
|
||||
*/
|
||||
public function getFormat($createIfEmpty = true) {
|
||||
if (!$this->format && $createIfEmpty) {
|
||||
$this->format = new Format();
|
||||
}
|
||||
return $this->format;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @see \FML\Types\Renderable::render()
|
||||
*/
|
||||
public function render(\DOMDocument $domDocument) {
|
||||
$xmlElement = $domDocument->createElement($this->tagName);
|
||||
$this->checkId();
|
||||
$xmlElement->setAttribute('id', $this->getId());
|
||||
if ($this->format) {
|
||||
$formatXml = $this->format->render($domDocument);
|
||||
$xmlElement->appendChild($formatXml);
|
||||
}
|
||||
foreach ($this->children as $child) {
|
||||
$childElement = $child->render($domDocument);
|
||||
$xmlElement->appendChild($childElement);
|
||||
}
|
||||
return $xmlElement;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user