TrackManiaControl/application/libs/FML/Controls/FrameInstance.php

93 lines
2.1 KiB
PHP
Raw Normal View History

2014-01-19 19:30:21 +01:00
<?php
namespace FML\Controls;
use FML\Elements\FrameModel;
2014-04-27 14:44:40 +02:00
2014-01-19 19:30:21 +01:00
/**
2014-06-21 03:18:21 +02:00
* Class representing an instance of a Frame Model
2014-01-19 19:30:21 +01:00
* (CMlFrame)
*
2014-05-20 15:44:45 +02:00
* @author steeffeen <mail@steeffeen.com>
2014-04-13 18:21:40 +02:00
* @copyright FancyManiaLinks Copyright © 2014 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
*/
class FrameInstance extends Control {
2014-01-21 20:30:40 +01:00
/*
2014-06-21 03:18:21 +02:00
* Protected properties
2014-01-19 19:30:21 +01:00
*/
2014-06-21 03:18:21 +02:00
protected $tagName = 'frameinstance';
protected $modelId = null;
2014-05-14 23:24:00 +02:00
/** @var FrameModel $model */
2014-01-19 19:30:21 +01:00
protected $model = null;
/**
2014-06-21 03:18:21 +02:00
* Create a new Frame Instance object
2014-01-19 19:30:21 +01:00
*
2014-06-21 03:18:21 +02:00
* @param string $modelId (optional) Frame Model id
* @param string $controlId (optional) Frame id
2014-07-03 22:34:47 +02:00
* @return static
2014-06-21 03:18:21 +02:00
*/
public static function create($modelId = null, $controlId = null) {
return new static($modelId, $controlId);
}
/**
* Construct a new Frame Instance object
*
* @param string $modelId (optional) Frame Model id
* @param string $controlId (optional) Frame id
2014-01-19 19:30:21 +01:00
*/
public function __construct($modelId = null, $controlId = null) {
parent::__construct($controlId);
2014-06-21 03:18:21 +02:00
if (!is_null($modelId)) {
2014-01-19 19:30:21 +01:00
$this->setModelId($modelId);
}
}
/**
2014-06-21 03:18:21 +02:00
* Set Frame Model id
2014-01-19 19:30:21 +01:00
*
2014-06-21 03:18:21 +02:00
* @param string $modelId Frame Model id
2014-07-03 22:34:47 +02:00
* @return static
2014-01-19 19:30:21 +01:00
*/
public function setModelId($modelId) {
2014-05-14 23:24:00 +02:00
$this->modelId = (string)$modelId;
$this->model = null;
2014-01-19 19:30:21 +01:00
return $this;
}
2014-05-16 22:44:22 +02:00
/**
2014-06-21 03:18:21 +02:00
* Set Frame Model
2014-05-16 22:44:22 +02:00
*
2014-06-21 03:18:21 +02:00
* @param FrameModel $frameModel Frame Model
2014-07-03 22:34:47 +02:00
* @return static
2014-05-16 22:44:22 +02:00
*/
2014-06-21 03:18:21 +02:00
public function setModel(FrameModel $frameModel) {
$this->model = $frameModel;
$this->modelId = null;
return $this;
2014-05-16 22:44:22 +02:00
}
/**
* @see \FML\Controls\Control::getManiaScriptClass()
*/
public function getManiaScriptClass() {
return 'CMlFrame';
}
2014-01-19 19:30:21 +01:00
/**
* @see \FML\Renderable::render()
*/
public function render(\DOMDocument $domDocument) {
$xmlElement = parent::render($domDocument);
if ($this->model) {
$this->model->checkId();
$xmlElement->setAttribute('modelid', $this->model->getId());
2014-05-14 23:24:00 +02:00
} else if ($this->modelId) {
2014-01-19 19:30:21 +01:00
$xmlElement->setAttribute('modelid', $this->modelId);
}
return $xmlElement;
}
}