2014-01-19 19:30:21 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace FML\Stylesheet;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class representing the ManiaLinks Stylesheet
|
|
|
|
*
|
2014-05-14 23:24:00 +02:00
|
|
|
* @author steeffeen
|
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 Stylesheet {
|
2014-01-21 20:30:40 +01:00
|
|
|
/*
|
2014-01-19 19:30:21 +01:00
|
|
|
* Protected Properties
|
|
|
|
*/
|
|
|
|
protected $tagName = 'stylesheet';
|
|
|
|
protected $styles3d = array();
|
2014-05-14 23:24:00 +02:00
|
|
|
/** @var Mood $mood */
|
2014-01-19 19:30:21 +01:00
|
|
|
protected $mood = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new Stylesheet Object
|
|
|
|
*
|
2014-04-27 14:44:40 +02:00
|
|
|
* @return \FML\Stylesheet\Stylesheet
|
2014-01-19 19:30:21 +01:00
|
|
|
*/
|
|
|
|
public static function create() {
|
|
|
|
$stylesheet = new Stylesheet();
|
|
|
|
return $stylesheet;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Construct a new Stylesheet Object
|
|
|
|
*/
|
|
|
|
public function __construct() {
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a new Style3d
|
|
|
|
*
|
|
|
|
* @param Style3d $style3d The Style3d to add
|
2014-04-27 14:44:40 +02:00
|
|
|
* @return \FML\Stylesheet\Stylesheet
|
2014-01-19 19:30:21 +01:00
|
|
|
*/
|
|
|
|
public function addStyle3d(Style3d $style3d) {
|
|
|
|
if (!in_array($style3d, $this->styles3d, true)) {
|
|
|
|
array_push($this->styles3d, $style3d);
|
|
|
|
}
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove all Styles
|
|
|
|
*
|
2014-04-27 14:44:40 +02:00
|
|
|
* @return \FML\Stylesheet\Stylesheet
|
2014-01-19 19:30:21 +01:00
|
|
|
*/
|
|
|
|
public function removeStyles() {
|
|
|
|
$this->styles3d = array();
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the Mood Object of the Stylesheet
|
|
|
|
*
|
|
|
|
* @param Mood $mood Mood Object
|
|
|
|
* @return \FML\Stylesheet\Stylesheet
|
|
|
|
*/
|
|
|
|
public function setMood(Mood $mood) {
|
|
|
|
$this->mood = $mood;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the Mood Object
|
|
|
|
*
|
|
|
|
* @param bool $createIfEmpty (optional) Whether the Mood Object should be created if it's not set yet
|
|
|
|
* @return \FML\Stylesheet\Mood
|
|
|
|
*/
|
|
|
|
public function getMood($createIfEmpty = true) {
|
|
|
|
if (!$this->mood && $createIfEmpty) {
|
2014-04-13 18:21:40 +02:00
|
|
|
$this->setMood(new Mood());
|
2014-01-19 19:30:21 +01:00
|
|
|
}
|
|
|
|
return $this->mood;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Render the Stylesheet XML Element
|
|
|
|
*
|
|
|
|
* @param \DOMDocument $domDocument DomDocument for which the Stylesheet XML Element should be rendered
|
|
|
|
* @return \DOMElement
|
|
|
|
*/
|
|
|
|
public function render(\DOMDocument $domDocument) {
|
|
|
|
$stylesheetXml = $domDocument->createElement($this->tagName);
|
|
|
|
if ($this->styles3d) {
|
|
|
|
$stylesXml = $domDocument->createElement('frame3dstyles');
|
|
|
|
$stylesheetXml->appendChild($stylesXml);
|
|
|
|
foreach ($this->styles3d as $style3d) {
|
2014-05-14 23:24:00 +02:00
|
|
|
/** @var Style3d $style3d */
|
2014-01-19 19:30:21 +01:00
|
|
|
$style3dXml = $style3d->render($domDocument);
|
|
|
|
$stylesXml->appendChild($style3dXml);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($this->mood) {
|
|
|
|
$moodXml = $this->mood->render($domDocument);
|
|
|
|
$stylesheetXml->appendChild($moodXml);
|
|
|
|
}
|
|
|
|
return $stylesheetXml;
|
|
|
|
}
|
|
|
|
}
|