2013-11-25 00:02:07 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace FML\Controls;
|
|
|
|
|
|
|
|
use FML\Types\Container;
|
|
|
|
use FML\Types\Renderable;
|
2014-01-19 19:30:21 +01:00
|
|
|
use FML\Elements\Format;
|
|
|
|
use FML\Elements\FrameModel;
|
2013-11-25 00:02:07 +01:00
|
|
|
|
|
|
|
/**
|
2014-01-19 19:30:21 +01:00
|
|
|
* Frame Control
|
2014-01-12 00:51:46 +01:00
|
|
|
* (CMlFrame)
|
2013-11-25 00:02:07 +01:00
|
|
|
*
|
|
|
|
* @author steeffeen
|
2014-04-13 18:21:40 +02:00
|
|
|
* @copyright FancyManiaLinks Copyright © 2014 Steffen Schröder
|
|
|
|
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
2013-11-25 00:02:07 +01:00
|
|
|
*/
|
|
|
|
class Frame extends Control implements Container {
|
2014-01-21 20:30:40 +01:00
|
|
|
/*
|
2013-12-31 02:55:19 +01:00
|
|
|
* Protected Properties
|
2013-11-25 00:02:07 +01:00
|
|
|
*/
|
|
|
|
protected $children = array();
|
2014-01-19 19:30:21 +01:00
|
|
|
protected $format = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new Frame Control
|
|
|
|
*
|
|
|
|
* @param string $id (optional) Control Id
|
|
|
|
* @return \FML\Controls\Frame
|
|
|
|
*/
|
|
|
|
public static function create($id = null) {
|
|
|
|
$frame = new Frame($id);
|
|
|
|
return $frame;
|
|
|
|
}
|
2013-11-25 00:02:07 +01:00
|
|
|
|
|
|
|
/**
|
2013-12-31 02:55:19 +01:00
|
|
|
* Construct a new Frame Control
|
2013-11-25 00:02:07 +01:00
|
|
|
*
|
2014-01-12 00:51:46 +01:00
|
|
|
* @param string $id (optional) Control Id
|
2013-11-25 00:02:07 +01:00
|
|
|
*/
|
|
|
|
public function __construct($id = null) {
|
|
|
|
parent::__construct($id);
|
|
|
|
$this->tagName = 'frame';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @see \FML\Types\Container::add()
|
|
|
|
* @return \FML\Controls\Frame
|
|
|
|
*/
|
2014-01-19 19:30:21 +01:00
|
|
|
public function add(Control $child) {
|
2014-01-12 14:47:17 +01:00
|
|
|
if (!in_array($child, $this->children, true)) {
|
2014-01-12 00:51:46 +01:00
|
|
|
array_push($this->children, $child);
|
|
|
|
}
|
2013-11-25 00:02:07 +01:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @see \FML\Types\Container::removeChildren()
|
|
|
|
* @return \FML\Controls\Frame
|
|
|
|
*/
|
|
|
|
public function removeChildren() {
|
|
|
|
$this->children = array();
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2014-01-19 19:30:21 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @see \FML\Types\Container::setFormat()
|
|
|
|
* @return \FML\Controls\Frame
|
|
|
|
*/
|
|
|
|
public function setFormat(Format $format) {
|
|
|
|
$this->format = $format;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @see \FML\Types\Container::getFormat()
|
|
|
|
*/
|
|
|
|
public function getFormat($createIfEmpty = true) {
|
|
|
|
if (!$this->format && $createIfEmpty) {
|
2014-04-13 18:21:40 +02:00
|
|
|
$this->setFormat(new Format());
|
2014-01-19 19:30:21 +01:00
|
|
|
}
|
|
|
|
return $this->format;
|
|
|
|
}
|
|
|
|
|
2013-11-25 00:02:07 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @see \FML\Renderable::render()
|
|
|
|
*/
|
|
|
|
public function render(\DOMDocument $domDocument) {
|
2014-01-12 00:51:46 +01:00
|
|
|
$xmlElement = parent::render($domDocument);
|
2014-01-19 19:30:21 +01:00
|
|
|
if ($this->format) {
|
|
|
|
$formatXml = $this->format->render($domDocument);
|
|
|
|
$xmlElement->appendChild($formatXml);
|
|
|
|
}
|
2013-11-25 00:02:07 +01:00
|
|
|
foreach ($this->children as $child) {
|
2014-01-12 00:51:46 +01:00
|
|
|
$childXmlElement = $child->render($domDocument);
|
|
|
|
$xmlElement->appendChild($childXmlElement);
|
2013-11-25 00:02:07 +01:00
|
|
|
}
|
2014-01-12 00:51:46 +01:00
|
|
|
return $xmlElement;
|
2013-11-25 00:02:07 +01:00
|
|
|
}
|
|
|
|
}
|