Updated to ManiaLink v3
This commit is contained in:
@ -5,7 +5,6 @@ namespace FML\Components;
|
||||
use FML\Controls\Entry;
|
||||
use FML\Controls\Frame;
|
||||
use FML\Controls\Quad;
|
||||
use FML\Models\CheckBoxDesign;
|
||||
use FML\Script\Features\CheckBoxFeature;
|
||||
use FML\Script\Features\ScriptFeature;
|
||||
use FML\Types\Renderable;
|
||||
@ -14,144 +13,257 @@ use FML\Types\ScriptFeatureable;
|
||||
/**
|
||||
* CheckBox Component
|
||||
*
|
||||
* @uses Quad
|
||||
* @author steeffeen <mail@steeffeen.com>
|
||||
* @copyright FancyManiaLinks Copyright © 2014 Steffen Schröder
|
||||
* @copyright FancyManiaLinks Copyright © 2017 Steffen Schröder
|
||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||
*/
|
||||
class CheckBox implements Renderable, ScriptFeatureable {
|
||||
/*
|
||||
* Protected properties
|
||||
*/
|
||||
protected $name = null;
|
||||
protected $feature = null;
|
||||
class CheckBox implements Renderable, ScriptFeatureable
|
||||
{
|
||||
|
||||
/**
|
||||
* Create a new CheckBox Component
|
||||
*
|
||||
* @param string $name (optional) CheckBox name
|
||||
* @param bool $default (optional) Default value
|
||||
* @param Quad $quad (optional) CheckBox quad
|
||||
*/
|
||||
public function __construct($name = null, $default = null, Quad $quad = null) {
|
||||
$this->feature = new CheckBoxFeature();
|
||||
$this->setName($name);
|
||||
$this->setDefault($default);
|
||||
$this->setQuad($quad);
|
||||
}
|
||||
/**
|
||||
* @var string $name CheckBox name
|
||||
*/
|
||||
protected $name = null;
|
||||
|
||||
/**
|
||||
* Set the name
|
||||
*
|
||||
* @param string $name CheckBox name
|
||||
* @return static
|
||||
*/
|
||||
public function setName($name) {
|
||||
$this->name = (string)$name;
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* @var CheckBoxFeature $feature CheckBox Feature
|
||||
*/
|
||||
protected $feature = null;
|
||||
|
||||
/**
|
||||
* Set the default value
|
||||
*
|
||||
* @param bool $default Default value
|
||||
* @return static
|
||||
*/
|
||||
public function setDefault($default) {
|
||||
$this->feature->setDefault($default);
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* Construct a new CheckBox
|
||||
*
|
||||
* @api
|
||||
* @param string $name (optional) CheckBox name
|
||||
* @param bool $default (optional) Default value
|
||||
* @param Quad $quad (optional) CheckBox quad
|
||||
*/
|
||||
public function __construct($name = null, $default = null, Quad $quad = null)
|
||||
{
|
||||
$this->feature = new CheckBoxFeature();
|
||||
if ($name) {
|
||||
$this->setName($name);
|
||||
}
|
||||
if ($default !== null) {
|
||||
$this->setDefault($default);
|
||||
}
|
||||
if ($quad) {
|
||||
$this->setQuad($quad);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the enabled Design
|
||||
*
|
||||
* @param string $style Style name or image url
|
||||
* @param string $subStyle SubStyle name
|
||||
* @return static
|
||||
*/
|
||||
public function setEnabledDesign($style, $subStyle = null) {
|
||||
if ($style instanceof CheckBoxDesign) {
|
||||
$this->feature->setEnabledDesign($style);
|
||||
} else {
|
||||
$checkBoxDesign = new CheckBoxDesign($style, $subStyle);
|
||||
$this->feature->setEnabledDesign($checkBoxDesign);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* Get the name
|
||||
*
|
||||
* @api
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the disabled Design
|
||||
*
|
||||
* @param string $style Style name or image url
|
||||
* @param string $subStyle SubStyle name
|
||||
* @return static
|
||||
*/
|
||||
public function setDisabledDesign($style, $subStyle = null) {
|
||||
if ($style instanceof CheckBoxDesign) {
|
||||
$this->feature->setDisabledDesign($style);
|
||||
} else {
|
||||
$checkBoxDesign = new CheckBoxDesign($style, $subStyle);
|
||||
$this->feature->setDisabledDesign($checkBoxDesign);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* Set the name
|
||||
*
|
||||
* @api
|
||||
* @param string $name CheckBox name
|
||||
* @return static
|
||||
*/
|
||||
public function setName($name)
|
||||
{
|
||||
$this->name = (string)$name;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the CheckBox Quad
|
||||
*
|
||||
* @param Quad $quad CheckBox Quad
|
||||
* @return static
|
||||
*/
|
||||
public function setQuad(Quad $quad = null) {
|
||||
$this->feature->setQuad($quad);
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* Get the default value
|
||||
*
|
||||
* @api
|
||||
* @return bool
|
||||
*/
|
||||
public function getDefault()
|
||||
{
|
||||
return $this->feature->getDefault();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see \FML\Types\ScriptFeatureable::getScriptFeatures()
|
||||
*/
|
||||
public function getScriptFeatures() {
|
||||
return ScriptFeature::collect($this->feature, $this->getQuad(), $this->feature->getEntry());
|
||||
}
|
||||
/**
|
||||
* Set the default value
|
||||
*
|
||||
* @api
|
||||
* @param bool $default Default value
|
||||
* @return static
|
||||
*/
|
||||
public function setDefault($default)
|
||||
{
|
||||
$this->feature->setDefault($default);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the CheckBox Quad
|
||||
*
|
||||
* @param bool $createIfEmpty (optional) Create the Quad if it's not set
|
||||
* @return \FML\Controls\Quad
|
||||
*/
|
||||
public function getQuad($createIfEmpty = true) {
|
||||
if (!$this->feature->getQuad() && $createIfEmpty) {
|
||||
$quad = new Quad();
|
||||
$quad->setSize(10, 10);
|
||||
$this->setQuad($quad);
|
||||
}
|
||||
return $this->feature->getQuad();
|
||||
}
|
||||
/**
|
||||
* Get the enabled design
|
||||
*
|
||||
* @api
|
||||
* @return CheckBoxDesign
|
||||
*/
|
||||
public function getEnabledDesign()
|
||||
{
|
||||
return $this->feature->getEnabledDesign();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see \FML\Types\Renderable::render()
|
||||
*/
|
||||
public function render(\DOMDocument $domDocument) {
|
||||
$frame = new Frame();
|
||||
/**
|
||||
* Set the enabled design
|
||||
*
|
||||
* @api
|
||||
* @param string|CheckBoxDesign $style Style name, image url or checkbox design
|
||||
* @param string $subStyle SubStyle name
|
||||
* @return static
|
||||
*/
|
||||
public function setEnabledDesign($style, $subStyle = null)
|
||||
{
|
||||
if ($style instanceof CheckBoxDesign) {
|
||||
$this->feature->setEnabledDesign($style);
|
||||
} else {
|
||||
$checkBoxDesign = new CheckBoxDesign($style, $subStyle);
|
||||
$this->feature->setEnabledDesign($checkBoxDesign);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
$quad = $this->getQuad();
|
||||
$frame->add($quad);
|
||||
/**
|
||||
* Get the disabled design
|
||||
*
|
||||
* @api
|
||||
* @return CheckBoxDesign
|
||||
*/
|
||||
public function getDisabledDesign()
|
||||
{
|
||||
return $this->feature->getDisabledDesign();
|
||||
}
|
||||
|
||||
$entry = $this->buildEntry();
|
||||
$frame->add($entry);
|
||||
$this->feature->setEntry($entry);
|
||||
/**
|
||||
* Set the disabled design
|
||||
*
|
||||
* @api
|
||||
* @param string|CheckBoxDesign $style Style name, image url or checkbox design
|
||||
* @param string $subStyle SubStyle name
|
||||
* @return static
|
||||
*/
|
||||
public function setDisabledDesign($style, $subStyle = null)
|
||||
{
|
||||
if ($style instanceof CheckBoxDesign) {
|
||||
$this->feature->setDisabledDesign($style);
|
||||
} else {
|
||||
$checkBoxDesign = new CheckBoxDesign($style, $subStyle);
|
||||
$this->feature->setDisabledDesign($checkBoxDesign);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
return $frame->render($domDocument);
|
||||
}
|
||||
/**
|
||||
* Get the CheckBox Quad
|
||||
*
|
||||
* @api
|
||||
* @return Quad
|
||||
*/
|
||||
public function getQuad()
|
||||
{
|
||||
$quad = $this->feature->getQuad();
|
||||
if ($quad) {
|
||||
return $quad;
|
||||
}
|
||||
return $this->createQuad();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the CheckBox Quad
|
||||
*
|
||||
* @api
|
||||
* @param Quad $quad CheckBox Quad
|
||||
* @return static
|
||||
*/
|
||||
public function setQuad(Quad $quad)
|
||||
{
|
||||
$this->feature->setQuad($quad);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the CheckBox Quad
|
||||
*
|
||||
* @return Quad
|
||||
*/
|
||||
protected function createQuad()
|
||||
{
|
||||
$quad = new Quad();
|
||||
$quad->setSize(10, 10);
|
||||
$this->setQuad($quad);
|
||||
return $quad;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the hidden Entry
|
||||
*
|
||||
* @return Entry
|
||||
*/
|
||||
public function getEntry()
|
||||
{
|
||||
$entry = $this->feature->getEntry();
|
||||
if ($entry) {
|
||||
return $entry;
|
||||
}
|
||||
return $this->createEntry();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the hidden Entry
|
||||
*
|
||||
* @param Entry $entry Hidden Entry
|
||||
* @return static
|
||||
*/
|
||||
public function setEntry(Entry $entry)
|
||||
{
|
||||
$this->feature->setEntry($entry);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the hidden Entry
|
||||
*
|
||||
* @return Entry
|
||||
*/
|
||||
protected function createEntry()
|
||||
{
|
||||
$entry = new Entry();
|
||||
$entry->setVisible(false)
|
||||
->setName($this->name);
|
||||
$this->setEntry($entry);
|
||||
return $entry;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ScriptFeatureable::getScriptFeatures()
|
||||
*/
|
||||
public function getScriptFeatures()
|
||||
{
|
||||
return ScriptFeature::collect($this->feature, $this->getQuad(), $this->feature->getEntry());
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Renderable::render()
|
||||
*/
|
||||
public function render(\DOMDocument $domDocument)
|
||||
{
|
||||
$frame = new Frame();
|
||||
|
||||
$quad = $this->getQuad();
|
||||
$frame->addChild($quad);
|
||||
|
||||
$entry = $this->getEntry();
|
||||
$frame->addChild($entry);
|
||||
|
||||
return $frame->render($domDocument);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the hidden Entry
|
||||
*
|
||||
* @return \FML\Controls\Entry
|
||||
*/
|
||||
protected function buildEntry() {
|
||||
$entry = new Entry();
|
||||
$entry->setVisible(false)->setName($this->name);
|
||||
return $entry;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user