2013-11-25 00:02:07 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace FML\Controls;
|
|
|
|
|
2013-11-28 01:12:52 +01:00
|
|
|
use FML\Types\Styleable;
|
|
|
|
|
2013-11-25 00:02:07 +01:00
|
|
|
/**
|
2014-01-12 00:51:46 +01:00
|
|
|
* Gauge Element
|
|
|
|
* (CMlGauge)
|
2013-11-25 00:02:07 +01:00
|
|
|
*
|
|
|
|
* @author steeffeen
|
|
|
|
*/
|
|
|
|
class Gauge extends Control implements Styleable {
|
|
|
|
/**
|
2013-12-31 02:55:19 +01:00
|
|
|
* Protected Properties
|
2013-11-25 00:02:07 +01:00
|
|
|
*/
|
|
|
|
protected $ratio = 1.;
|
2014-01-12 00:51:46 +01:00
|
|
|
// TODO: validate grading
|
2013-11-25 00:02:07 +01:00
|
|
|
protected $grading = 1.;
|
2013-11-28 01:12:52 +01:00
|
|
|
protected $color = '';
|
2013-11-25 00:02:07 +01:00
|
|
|
protected $rotation = 0.;
|
|
|
|
protected $centered = 0;
|
|
|
|
protected $clan = 0;
|
|
|
|
protected $drawBg = 1;
|
|
|
|
protected $drawBlockBg = 1;
|
2013-11-28 01:12:52 +01:00
|
|
|
protected $style = '';
|
2013-11-25 00:02:07 +01:00
|
|
|
|
|
|
|
/**
|
2013-12-31 02:55:19 +01:00
|
|
|
* Construct a new Gauge 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);
|
2013-11-28 01:12:52 +01:00
|
|
|
$this->tagName = 'gauge';
|
2013-11-25 00:02:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-12-31 02:55:19 +01:00
|
|
|
* Set Ratio
|
2013-11-25 00:02:07 +01:00
|
|
|
*
|
2014-01-12 00:51:46 +01:00
|
|
|
* @param float $ratio Ratio Value
|
2013-11-28 01:12:52 +01:00
|
|
|
* @return \FML\Controls\Gauge
|
2013-11-25 00:02:07 +01:00
|
|
|
*/
|
|
|
|
public function setRatio($ratio) {
|
2014-01-12 00:51:46 +01:00
|
|
|
$this->ratio = (float) $ratio;
|
2013-11-28 01:12:52 +01:00
|
|
|
return $this;
|
2013-11-25 00:02:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-12-31 02:55:19 +01:00
|
|
|
* Set Grading
|
2013-11-25 00:02:07 +01:00
|
|
|
*
|
2014-01-12 00:51:46 +01:00
|
|
|
* @param float $grading Grading Value
|
2013-11-28 01:12:52 +01:00
|
|
|
* @return \FML\Controls\Gauge
|
2013-11-25 00:02:07 +01:00
|
|
|
*/
|
|
|
|
public function setGrading($grading) {
|
2014-01-12 00:51:46 +01:00
|
|
|
$this->grading = (float) $grading;
|
2013-11-28 01:12:52 +01:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-12-31 02:55:19 +01:00
|
|
|
* Set Color
|
2013-11-28 01:12:52 +01:00
|
|
|
*
|
2014-01-12 00:51:46 +01:00
|
|
|
* @param string $color Gauge Color
|
2013-11-28 01:12:52 +01:00
|
|
|
* @return \FML\Controls\Gauge
|
|
|
|
*/
|
|
|
|
public function setColor($color) {
|
2014-01-12 00:51:46 +01:00
|
|
|
$this->color = (string) $color;
|
2013-11-28 01:12:52 +01:00
|
|
|
return $this;
|
2013-11-25 00:02:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-12-31 02:55:19 +01:00
|
|
|
* Set Rotation
|
2013-11-25 00:02:07 +01:00
|
|
|
*
|
2014-01-12 00:51:46 +01:00
|
|
|
* @param float $rotation Gauge Rotation
|
2013-11-28 01:12:52 +01:00
|
|
|
* @return \FML\Controls\Gauge
|
2013-11-25 00:02:07 +01:00
|
|
|
*/
|
|
|
|
public function setRotation($rotation) {
|
2014-01-12 00:51:46 +01:00
|
|
|
$this->rotation = (float) $rotation;
|
2013-11-28 01:12:52 +01:00
|
|
|
return $this;
|
2013-11-25 00:02:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-12-31 02:55:19 +01:00
|
|
|
* Set Centered
|
2013-11-25 00:02:07 +01:00
|
|
|
*
|
2014-01-12 00:51:46 +01:00
|
|
|
* @param bool $centered Whether Gauge is centered
|
2013-11-28 01:12:52 +01:00
|
|
|
* @return \FML\Controls\Gauge
|
2013-11-25 00:02:07 +01:00
|
|
|
*/
|
|
|
|
public function setCentered($centered) {
|
|
|
|
$this->centered = ($centered ? 1 : 0);
|
2013-11-28 01:12:52 +01:00
|
|
|
return $this;
|
2013-11-25 00:02:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-12-31 02:55:19 +01:00
|
|
|
* Set Clan
|
2013-11-25 00:02:07 +01:00
|
|
|
*
|
2014-01-12 00:51:46 +01:00
|
|
|
* @param int $clan Clan number
|
2013-11-28 01:12:52 +01:00
|
|
|
* @return \FML\Controls\Gauge
|
2013-11-25 00:02:07 +01:00
|
|
|
*/
|
|
|
|
public function setClan($clan) {
|
2014-01-12 00:51:46 +01:00
|
|
|
$this->clan = (int) $clan;
|
2013-11-28 01:12:52 +01:00
|
|
|
return $this;
|
2013-11-25 00:02:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-12-31 02:55:19 +01:00
|
|
|
* Set Draw Background
|
2013-11-25 00:02:07 +01:00
|
|
|
*
|
2014-01-12 00:51:46 +01:00
|
|
|
* @param bool $drawBg Whether Gauge Background should be drawn
|
2013-11-28 01:12:52 +01:00
|
|
|
* @return \FML\Controls\Gauge
|
2013-11-25 00:02:07 +01:00
|
|
|
*/
|
|
|
|
public function setDrawBg($drawBg) {
|
|
|
|
$this->drawBg = ($drawBg ? 1 : 0);
|
2013-11-28 01:12:52 +01:00
|
|
|
return $this;
|
2013-11-25 00:02:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-12-31 02:55:19 +01:00
|
|
|
* Set Draw Block Background
|
2013-11-25 00:02:07 +01:00
|
|
|
*
|
2014-01-12 00:51:46 +01:00
|
|
|
* @param bool $drawBlockBg Whether Gauge Block Background should be drawn
|
2013-11-28 01:12:52 +01:00
|
|
|
* @return \FML\Controls\Gauge
|
2013-11-25 00:02:07 +01:00
|
|
|
*/
|
|
|
|
public function setDrawBlockBg($drawBlockBg) {
|
|
|
|
$this->drawBlockBg = ($drawBlockBg ? 1 : 0);
|
2013-11-28 01:12:52 +01:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @see \FML\Types\Styleable::setStyle()
|
2013-12-31 02:55:19 +01:00
|
|
|
* @return \FML\Controls\Gauge
|
2013-11-28 01:12:52 +01:00
|
|
|
*/
|
|
|
|
public function setStyle($style) {
|
2014-01-12 00:51:46 +01:00
|
|
|
$this->style = (string) $style;
|
2013-11-28 01:12:52 +01:00
|
|
|
return $this;
|
2013-11-25 00:02:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @see \FML\Control::render()
|
|
|
|
*/
|
|
|
|
public function render(\DOMDocument $domDocument) {
|
2014-01-12 00:51:46 +01:00
|
|
|
$xmlElement = parent::render($domDocument);
|
|
|
|
// TODO: validate default values
|
|
|
|
$xmlElement->setAttribute('ratio', $this->ratio);
|
|
|
|
$xmlElement->setAttribute('grading', $this->grading);
|
2013-11-28 01:12:52 +01:00
|
|
|
if ($this->color) {
|
2014-01-12 00:51:46 +01:00
|
|
|
$xmlElement->setAttribute('color', $this->color);
|
2013-11-28 01:12:52 +01:00
|
|
|
}
|
|
|
|
if ($this->rotation) {
|
2014-01-12 00:51:46 +01:00
|
|
|
$xmlElement->setAttribute('rotation', $this->rotation);
|
2013-11-28 01:12:52 +01:00
|
|
|
}
|
|
|
|
if ($this->centered) {
|
2014-01-12 00:51:46 +01:00
|
|
|
$xmlElement->setAttribute('centered', $this->centered);
|
2013-11-28 01:12:52 +01:00
|
|
|
}
|
|
|
|
if ($this->clan) {
|
2014-01-12 00:51:46 +01:00
|
|
|
$xmlElement->setAttribute('clan', $this->clan);
|
2013-11-28 01:12:52 +01:00
|
|
|
}
|
2014-01-12 00:51:46 +01:00
|
|
|
$xmlElement->setAttribute('drawbg', $this->drawBg);
|
|
|
|
$xmlElement->setAttribute('drawblockbg', $this->drawBlockBg);
|
2013-11-28 01:12:52 +01:00
|
|
|
if ($this->style) {
|
2014-01-12 00:51:46 +01:00
|
|
|
$xmlElement->setAttribute('style', $this->style);
|
2013-11-28 01:12:52 +01:00
|
|
|
}
|
2014-01-12 00:51:46 +01:00
|
|
|
return $xmlElement;
|
2013-11-25 00:02:07 +01:00
|
|
|
}
|
|
|
|
}
|