Updated to ManiaLink v3
This commit is contained in:
@ -13,122 +13,224 @@ use FML\Types\ScriptFeatureable;
|
||||
/**
|
||||
* ValuePicker Component
|
||||
*
|
||||
* @uses Entry
|
||||
* @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 ValuePicker implements Renderable, ScriptFeatureable {
|
||||
/*
|
||||
* Protected properties
|
||||
*/
|
||||
protected $name = null;
|
||||
protected $feature = null;
|
||||
class ValuePicker implements Renderable, ScriptFeatureable
|
||||
{
|
||||
|
||||
/**
|
||||
* Create a new ValuePicker Component
|
||||
*
|
||||
* @param string $name (optional) CheckBox name
|
||||
* @param array $values (optional) Possible values
|
||||
* @param bool $default (optional) Default value
|
||||
* @param Label $label (optional) ValuePicker label
|
||||
*/
|
||||
public function __construct($name = null, array $values = array(), $default = null, Label $label = null) {
|
||||
$this->feature = new ValuePickerFeature();
|
||||
$this->setName($name);
|
||||
$this->setValues($values);
|
||||
$this->setDefault($default);
|
||||
$this->setLabel($label);
|
||||
}
|
||||
/**
|
||||
* @var string $name ValuePicker name
|
||||
*/
|
||||
protected $name = null;
|
||||
|
||||
/**
|
||||
* Set Name
|
||||
*
|
||||
* @param string $name ValuePicker name
|
||||
* @return static
|
||||
*/
|
||||
public function setName($name) {
|
||||
$this->name = (string)$name;
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* @var ValuePickerFeature $feature ValuePicker Feature
|
||||
*/
|
||||
protected $feature = null;
|
||||
|
||||
/**
|
||||
* Set the possible values
|
||||
*
|
||||
* @param array $values Possible values
|
||||
* @return static
|
||||
*/
|
||||
public function setValues(array $values) {
|
||||
$this->feature->setValues($values);
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* Create a new ValuePicker
|
||||
*
|
||||
* @api
|
||||
* @param string $name (optional) ValuePicker name
|
||||
* @param string[] $values (optional) Possible values
|
||||
* @param string $default (optional) Default value
|
||||
* @param Label $label (optional) ValuePicker label
|
||||
*/
|
||||
public function __construct($name = null, array $values = null, $default = null, Label $label = null)
|
||||
{
|
||||
$this->feature = new ValuePickerFeature();
|
||||
if ($name) {
|
||||
$this->setName($name);
|
||||
}
|
||||
if ($values) {
|
||||
$this->setValues($values);
|
||||
}
|
||||
if ($default !== null) {
|
||||
$this->setDefault($default);
|
||||
}
|
||||
if ($label) {
|
||||
$this->setLabel($label);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the default value
|
||||
*
|
||||
* @param bool $default Default value
|
||||
* @return static
|
||||
*/
|
||||
public function setDefault($default) {
|
||||
$this->feature->setDefault($default);
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* Get the name
|
||||
*
|
||||
* @api
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the ValuePicker Label
|
||||
*
|
||||
* @param Label $label ValuePicker Label
|
||||
* @return static
|
||||
*/
|
||||
public function setLabel(Label $label = null) {
|
||||
$this->feature->setLabel($label);
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* Set the name
|
||||
*
|
||||
* @api
|
||||
* @param string $name ValuePicker name
|
||||
* @return static
|
||||
*/
|
||||
public function setName($name)
|
||||
{
|
||||
$this->name = (string)$name;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the ValuePicker Label
|
||||
*
|
||||
* @param bool $createIfEmpty (optional) Create the Label if it's not set
|
||||
* @return \FML\Controls\Label
|
||||
*/
|
||||
public function getLabel($createIfEmpty = true) {
|
||||
if (!$this->feature->getLabel() && $createIfEmpty) {
|
||||
$label = new Label();
|
||||
$this->setLabel($label);
|
||||
}
|
||||
return $this->feature->getLabel();
|
||||
}
|
||||
/**
|
||||
* Get the possible values
|
||||
*
|
||||
* @api
|
||||
* @return string[]
|
||||
*/
|
||||
public function getValues()
|
||||
{
|
||||
return $this->feature->getValues();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see \FML\Types\ScriptFeatureable::getScriptFeatures()
|
||||
*/
|
||||
public function getScriptFeatures() {
|
||||
return ScriptFeature::collect($this->feature, $this->getLabel(), $this->feature->getEntry());
|
||||
}
|
||||
/**
|
||||
* Set the possible values
|
||||
*
|
||||
* @api
|
||||
* @param array $values Possible values
|
||||
* @return static
|
||||
*/
|
||||
public function setValues(array $values)
|
||||
{
|
||||
$this->feature->setValues($values);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see \FML\Types\Renderable::render()
|
||||
*/
|
||||
public function render(\DOMDocument $domDocument) {
|
||||
$frame = new Frame();
|
||||
/**
|
||||
* Get the default value
|
||||
*
|
||||
* @api
|
||||
* @return string
|
||||
*/
|
||||
public function getDefault()
|
||||
{
|
||||
return $this->feature->getDefault();
|
||||
}
|
||||
|
||||
$label = $this->getLabel();
|
||||
$frame->add($label);
|
||||
/**
|
||||
* Set the default value
|
||||
*
|
||||
* @api
|
||||
* @param bool $default Default value
|
||||
* @return static
|
||||
*/
|
||||
public function setDefault($default)
|
||||
{
|
||||
$this->feature->setDefault($default);
|
||||
return $this;
|
||||
}
|
||||
|
||||
$entry = $this->buildEntry();
|
||||
$frame->add($entry);
|
||||
$this->feature->setEntry($entry);
|
||||
/**
|
||||
* Get the Label
|
||||
*
|
||||
* @api
|
||||
* @return Label
|
||||
*/
|
||||
public function getLabel()
|
||||
{
|
||||
$label = $this->feature->getLabel();
|
||||
if ($label) {
|
||||
return $label;
|
||||
}
|
||||
return $this->createLabel();
|
||||
}
|
||||
|
||||
return $frame->render($domDocument);
|
||||
}
|
||||
/**
|
||||
* Set the Label
|
||||
*
|
||||
* @api
|
||||
* @param Label $label ValuePicker Label
|
||||
* @return static
|
||||
*/
|
||||
public function setLabel(Label $label)
|
||||
{
|
||||
$this->feature->setLabel($label);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the Label
|
||||
*
|
||||
* @return Label
|
||||
*/
|
||||
protected function createLabel()
|
||||
{
|
||||
$label = new Label();
|
||||
$this->setLabel($label);
|
||||
return $label;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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->getLabel(), $this->feature->getEntry());
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Renderable::render()
|
||||
*/
|
||||
public function render(\DOMDocument $domDocument)
|
||||
{
|
||||
$frame = new Frame();
|
||||
|
||||
$label = $this->getLabel();
|
||||
$frame->addChild($label);
|
||||
|
||||
$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