2014-01-19 19:30:21 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace FML\Elements;
|
|
|
|
|
2017-04-02 16:32:57 +02:00
|
|
|
use FML\Stylesheet\Style;
|
2014-01-19 19:30:21 +01:00
|
|
|
use FML\Types\Container;
|
2017-03-25 18:40:15 +01:00
|
|
|
use FML\Types\Identifiable;
|
2014-01-19 19:30:21 +01:00
|
|
|
use FML\Types\Renderable;
|
2014-06-21 03:18:21 +02:00
|
|
|
use FML\UniqueID;
|
2014-01-19 19:30:21 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Class representing a Frame Model
|
|
|
|
*
|
2014-05-20 15:44:45 +02:00
|
|
|
* @author steeffeen <mail@steeffeen.com>
|
2017-03-25 18:40:15 +01:00
|
|
|
* @copyright FancyManiaLinks Copyright © 2017 Steffen Schröder
|
2014-05-14 23:24:00 +02:00
|
|
|
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
2014-01-19 19:30:21 +01:00
|
|
|
*/
|
2017-03-25 18:40:15 +01:00
|
|
|
class FrameModel implements Container, Identifiable, Renderable
|
|
|
|
{
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string $modelId Model id
|
|
|
|
*/
|
|
|
|
protected $modelId = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var Renderable[] $children Children
|
|
|
|
*/
|
|
|
|
protected $children = array();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var Format $format Format
|
|
|
|
*/
|
|
|
|
protected $format = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new Frame Model
|
|
|
|
*
|
|
|
|
* @api
|
|
|
|
* @param string $modelId Model id
|
|
|
|
* @param Renderable[] $children Children
|
|
|
|
* @return static
|
|
|
|
*/
|
|
|
|
public static function create($modelId = null, array $children = null)
|
|
|
|
{
|
|
|
|
return new static($modelId, $children);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Construct a new Frame Model
|
|
|
|
*
|
|
|
|
* @api
|
|
|
|
* @param string $modelId Model id
|
|
|
|
* @param Renderable[] $children Children
|
|
|
|
*/
|
|
|
|
public function __construct($modelId = null, array $children = null)
|
|
|
|
{
|
|
|
|
if ($modelId) {
|
|
|
|
$this->setId($modelId);
|
|
|
|
}
|
|
|
|
if ($children) {
|
|
|
|
$this->addChildren($children);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @see Identifiable::getId()
|
|
|
|
*/
|
|
|
|
public function getId()
|
|
|
|
{
|
|
|
|
if (!$this->modelId) {
|
|
|
|
return $this->createId();
|
|
|
|
}
|
|
|
|
return $this->modelId;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @see Identifiable::setId()
|
|
|
|
*/
|
|
|
|
public function setId($modelId)
|
|
|
|
{
|
|
|
|
$this->modelId = (string)$modelId;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @see Identifiable::checkId()
|
|
|
|
*/
|
|
|
|
public function checkId()
|
|
|
|
{
|
|
|
|
return UniqueID::check($this);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new model id
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
protected function createId()
|
|
|
|
{
|
|
|
|
$modelId = UniqueID::create();
|
|
|
|
$this->setId($modelId);
|
|
|
|
return $this->getId();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @see Container::getChildren()
|
|
|
|
*/
|
|
|
|
public function getChildren()
|
|
|
|
{
|
|
|
|
return $this->children;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @see Container::addChild()
|
|
|
|
*/
|
2017-04-02 16:32:57 +02:00
|
|
|
public function addChild(Renderable $child)
|
2017-03-25 18:40:15 +01:00
|
|
|
{
|
2017-04-02 16:32:57 +02:00
|
|
|
if (!in_array($child, $this->children, true)) {
|
|
|
|
array_push($this->children, $child);
|
2017-03-25 18:40:15 +01:00
|
|
|
}
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2017-04-02 16:32:57 +02:00
|
|
|
/**
|
|
|
|
* @deprecated Use addChild()
|
|
|
|
* @see FrameModel::addChild()
|
|
|
|
*/
|
|
|
|
public function add(Renderable $child)
|
|
|
|
{
|
|
|
|
return $this->addChild($child);
|
|
|
|
}
|
|
|
|
|
2017-03-25 18:40:15 +01:00
|
|
|
/**
|
|
|
|
* @see Container::addChildren()
|
|
|
|
*/
|
|
|
|
public function addChildren(array $children)
|
|
|
|
{
|
|
|
|
foreach ($children as $child) {
|
|
|
|
$this->addChild($child);
|
|
|
|
}
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @see Container::removeAllChildren()
|
|
|
|
*/
|
|
|
|
public function removeAllChildren()
|
|
|
|
{
|
|
|
|
$this->children = array();
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-04-02 16:32:57 +02:00
|
|
|
* @deprecated Use removeAllChildren()
|
|
|
|
* @see FrameModel::removeAllChildren()
|
2017-03-25 18:40:15 +01:00
|
|
|
*/
|
2017-04-02 16:32:57 +02:00
|
|
|
public function removeChildren()
|
2017-03-25 18:40:15 +01:00
|
|
|
{
|
2017-04-02 16:32:57 +02:00
|
|
|
return $this->removeAllChildren();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @deprecated Use Style
|
|
|
|
* @see Style
|
|
|
|
*/
|
|
|
|
public function getFormat($createIfEmpty = true)
|
|
|
|
{
|
|
|
|
if (!$this->format && $createIfEmpty) {
|
|
|
|
$this->setFormat(new Format());
|
|
|
|
}
|
2017-03-25 18:40:15 +01:00
|
|
|
return $this->format;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-04-02 16:32:57 +02:00
|
|
|
* @deprecated Use Style
|
|
|
|
* @see Style
|
2017-03-25 18:40:15 +01:00
|
|
|
*/
|
|
|
|
public function setFormat(Format $format = null)
|
|
|
|
{
|
|
|
|
$this->format = $format;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @see Renderable::render()
|
|
|
|
*/
|
|
|
|
public function render(\DOMDocument $domDocument)
|
|
|
|
{
|
|
|
|
$domElement = $domDocument->createElement("framemodel");
|
|
|
|
$domElement->setAttribute("id", $this->getId());
|
|
|
|
|
|
|
|
if ($this->format) {
|
|
|
|
$formatElement = $this->format->render($domDocument);
|
|
|
|
$domElement->appendChild($formatElement);
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($this->children as $child) {
|
|
|
|
$childElement = $child->render($domDocument);
|
|
|
|
$domElement->appendChild($childElement);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $domElement;
|
|
|
|
}
|
|
|
|
|
2014-01-19 19:30:21 +01:00
|
|
|
}
|