TrackManiaControl/application/core/FML/Controls/Frame.php

104 lines
2.0 KiB
PHP
Raw Normal View History

<?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;
/**
2014-01-19 19:30:21 +01:00
* Frame Control
2014-01-12 00:51:46 +01:00
* (CMlFrame)
*
* @author steeffeen
*/
class Frame extends Control implements Container {
2014-01-21 20:30:40 +01:00
/*
2013-12-31 02:55:19 +01:00
* Protected Properties
*/
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-12-31 02:55:19 +01:00
* Construct a new Frame Control
*
2014-01-12 00:51:46 +01:00
* @param string $id (optional) Control Id
*/
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);
}
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) {
$this->format = new Format();
}
return $this->format;
}
/**
*
* @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);
}
foreach ($this->children as $child) {
2014-01-12 00:51:46 +01:00
$childXmlElement = $child->render($domDocument);
$xmlElement->appendChild($childXmlElement);
}
2014-01-12 00:51:46 +01:00
return $xmlElement;
}
}