2013-11-25 00:02:07 +01:00
|
|
|
<?php
|
2014-05-14 23:24:00 +02:00
|
|
|
// TODO: add entry styles
|
2013-11-25 00:02:07 +01:00
|
|
|
|
|
|
|
namespace FML\Controls;
|
|
|
|
|
2014-05-14 23:24:00 +02:00
|
|
|
use FML\Script\Features\EntrySubmit;
|
2013-11-28 17:36:39 +01:00
|
|
|
use FML\Types\NewLineable;
|
|
|
|
use FML\Types\Scriptable;
|
|
|
|
use FML\Types\Styleable;
|
|
|
|
use FML\Types\TextFormatable;
|
|
|
|
|
2013-11-25 00:02:07 +01:00
|
|
|
/**
|
2014-01-19 19:30:21 +01:00
|
|
|
* Entry Control
|
2014-01-12 00:51:46 +01:00
|
|
|
* (CMlEntry)
|
2013-11-25 00:02:07 +01:00
|
|
|
*
|
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
|
2013-11-25 00:02:07 +01:00
|
|
|
*/
|
|
|
|
class Entry extends Control implements NewLineable, Scriptable, Styleable, TextFormatable {
|
2014-01-21 20:30:40 +01:00
|
|
|
/*
|
2013-12-31 02:55:19 +01:00
|
|
|
* Protected Properties
|
2013-11-25 00:02:07 +01:00
|
|
|
*/
|
|
|
|
protected $name = '';
|
|
|
|
protected $default = null;
|
2013-11-28 17:36:39 +01:00
|
|
|
protected $autoNewLine = 0;
|
|
|
|
protected $scriptEvents = 0;
|
|
|
|
protected $style = '';
|
|
|
|
protected $textColor = '';
|
|
|
|
protected $textSize = -1;
|
2014-01-19 19:30:21 +01:00
|
|
|
protected $focusAreaColor1 = '';
|
|
|
|
protected $focusAreaColor2 = '';
|
2014-04-27 14:44:40 +02:00
|
|
|
protected $autoComplete = null;
|
2014-01-19 19:30:21 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new Entry Control
|
|
|
|
*
|
|
|
|
* @param string $id (optional) Control Id
|
|
|
|
* @return \FML\Controls\Entry
|
|
|
|
*/
|
|
|
|
public static function create($id = null) {
|
|
|
|
$entry = new Entry($id);
|
|
|
|
return $entry;
|
|
|
|
}
|
2013-11-25 00:02:07 +01:00
|
|
|
|
|
|
|
/**
|
2013-12-31 02:55:19 +01:00
|
|
|
* Construct a new Entry 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);
|
|
|
|
$this->tagName = 'entry';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-12-31 02:55:19 +01:00
|
|
|
* Set Entry Name
|
2013-11-25 00:02:07 +01:00
|
|
|
*
|
2014-01-12 00:51:46 +01:00
|
|
|
* @param string $name Entry Name
|
2013-11-25 00:02:07 +01:00
|
|
|
* @return \FML\Controls\Entry
|
|
|
|
*/
|
|
|
|
public function setName($name) {
|
2014-05-14 23:24:00 +02:00
|
|
|
$this->name = (string)$name;
|
2013-11-25 00:02:07 +01:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2014-04-27 14:44:40 +02:00
|
|
|
/**
|
|
|
|
* Get the Entry Name
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getName() {
|
|
|
|
return $this->name;
|
|
|
|
}
|
|
|
|
|
2013-11-25 00:02:07 +01:00
|
|
|
/**
|
2013-12-31 02:55:19 +01:00
|
|
|
* Set Default Value
|
2013-11-25 00:02:07 +01:00
|
|
|
*
|
2014-01-12 00:51:46 +01:00
|
|
|
* @param string $default Default Value
|
2013-11-25 00:02:07 +01:00
|
|
|
* @return \FML\Controls\Entry
|
|
|
|
*/
|
|
|
|
public function setDefault($default) {
|
|
|
|
$this->default = $default;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2013-11-28 17:36:39 +01:00
|
|
|
/**
|
2014-05-14 23:24:00 +02:00
|
|
|
* Get the Default Value
|
2013-11-28 17:36:39 +01:00
|
|
|
*
|
2014-05-14 23:24:00 +02:00
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function getDefault() {
|
|
|
|
return $this->default;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-11-28 17:36:39 +01:00
|
|
|
* @see \FML\Types\NewLineable::setAutoNewLine()
|
|
|
|
*/
|
|
|
|
public function setAutoNewLine($autoNewLine) {
|
|
|
|
$this->autoNewLine = ($autoNewLine ? 1 : 0);
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @see \FML\Types\Scriptable::setScriptEvents()
|
|
|
|
*/
|
|
|
|
public function setScriptEvents($scriptEvents) {
|
|
|
|
$this->scriptEvents = ($scriptEvents ? 1 : 0);
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @see \FML\Types\Styleable::setStyle()
|
|
|
|
*/
|
|
|
|
public function setStyle($style) {
|
2014-05-14 23:24:00 +02:00
|
|
|
$this->style = (string)$style;
|
2013-11-28 17:36:39 +01:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @see \FML\Types\TextFormatable::setTextColor()
|
|
|
|
*/
|
|
|
|
public function setTextColor($textColor) {
|
2014-05-14 23:24:00 +02:00
|
|
|
$this->textColor = (string)$textColor;
|
2013-11-28 17:36:39 +01:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @see \FML\Types\TextFormatable::setTextSize()
|
|
|
|
*/
|
|
|
|
public function setTextSize($textSize) {
|
2014-05-14 23:24:00 +02:00
|
|
|
$this->textSize = (int)$textSize;
|
2013-11-28 17:36:39 +01:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @see \FML\Types\TextFormatable::setAreaColor()
|
|
|
|
*/
|
|
|
|
public function setAreaColor($areaColor) {
|
2014-05-14 23:24:00 +02:00
|
|
|
$this->focusAreaColor1 = (string)$areaColor;
|
2013-11-28 17:36:39 +01:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @see \FML\Types\TextFormatable::setAreaFocusColor()
|
|
|
|
*/
|
|
|
|
public function setAreaFocusColor($areaFocusColor) {
|
2014-05-14 23:24:00 +02:00
|
|
|
$this->focusAreaColor2 = (string)$areaFocusColor;
|
2013-11-28 17:36:39 +01:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2014-04-27 14:44:40 +02:00
|
|
|
/**
|
|
|
|
* Set Auto Completion
|
|
|
|
*
|
|
|
|
* @param bool $autoComplete Whether the Default Value should be automatically completed based on the current Request Parameters
|
|
|
|
* @return \FML\Controls\Entry
|
|
|
|
*/
|
|
|
|
public function setAutoComplete($autoComplete) {
|
2014-05-14 23:24:00 +02:00
|
|
|
$this->autoComplete = (bool)$autoComplete;
|
2014-04-27 14:44:40 +02:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a dynamic Feature submitting the Entry
|
|
|
|
*
|
|
|
|
* @param string $url Submit Url
|
|
|
|
* @return \FML\Controls\Entry
|
|
|
|
*/
|
|
|
|
public function addSubmitFeature($url) {
|
|
|
|
$entrySubmit = new EntrySubmit($this, $url);
|
2014-05-14 23:24:00 +02:00
|
|
|
$this->addScriptFeature($entrySubmit);
|
2014-04-27 14:44:40 +02: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);
|
2013-11-25 00:02:07 +01:00
|
|
|
if ($this->name) {
|
2014-01-12 00:51:46 +01:00
|
|
|
$xmlElement->setAttribute('name', $this->name);
|
2013-11-25 00:02:07 +01:00
|
|
|
}
|
|
|
|
if ($this->default !== null) {
|
2014-01-12 00:51:46 +01:00
|
|
|
$xmlElement->setAttribute('default', $this->default);
|
2014-05-14 23:24:00 +02:00
|
|
|
} else if ($this->autoComplete) {
|
2014-04-27 14:44:40 +02:00
|
|
|
$value = null;
|
|
|
|
if (array_key_exists($this->name, $_GET)) {
|
|
|
|
$value = $_GET[$this->name];
|
2014-05-14 23:24:00 +02:00
|
|
|
} else if (array_key_exists($this->name, $_POST)) {
|
2014-04-27 14:44:40 +02:00
|
|
|
$value = $_POST[$this->name];
|
|
|
|
}
|
|
|
|
if ($value) {
|
|
|
|
$xmlElement->setAttribute('default', $value);
|
|
|
|
}
|
|
|
|
}
|
2013-11-28 17:36:39 +01:00
|
|
|
if ($this->autoNewLine) {
|
2014-01-12 00:51:46 +01:00
|
|
|
$xmlElement->setAttribute('autonewline', $this->autoNewLine);
|
2013-11-28 17:36:39 +01:00
|
|
|
}
|
|
|
|
if ($this->scriptEvents) {
|
2014-01-12 00:51:46 +01:00
|
|
|
$xmlElement->setAttribute('scriptevents', $this->scriptEvents);
|
2013-11-28 17:36:39 +01:00
|
|
|
}
|
|
|
|
if ($this->style) {
|
2014-01-12 00:51:46 +01:00
|
|
|
$xmlElement->setAttribute('style', $this->style);
|
2013-11-28 17:36:39 +01:00
|
|
|
}
|
|
|
|
if ($this->textColor) {
|
2014-01-12 00:51:46 +01:00
|
|
|
$xmlElement->setAttribute('textcolor', $this->textColor);
|
2013-11-28 17:36:39 +01:00
|
|
|
}
|
|
|
|
if ($this->textSize >= 0.) {
|
2014-01-12 00:51:46 +01:00
|
|
|
$xmlElement->setAttribute('textsize', $this->textSize);
|
2013-11-28 17:36:39 +01:00
|
|
|
}
|
2014-01-19 19:30:21 +01:00
|
|
|
if ($this->focusAreaColor1) {
|
|
|
|
$xmlElement->setAttribute('focusareacolor1', $this->focusAreaColor1);
|
2013-11-28 17:36:39 +01:00
|
|
|
}
|
2014-01-19 19:30:21 +01:00
|
|
|
if ($this->focusAreaColor2) {
|
|
|
|
$xmlElement->setAttribute('focusareacolor2', $this->focusAreaColor2);
|
2013-11-28 17:36:39 +01:00
|
|
|
}
|
2014-01-12 00:51:46 +01:00
|
|
|
return $xmlElement;
|
2013-11-25 00:02:07 +01:00
|
|
|
}
|
|
|
|
}
|