TrackManiaControl/application/core/Libs/FML/Controls/Entry.php

227 lines
5.0 KiB
PHP
Raw Normal View History

<?php
2014-05-14 23:24:00 +02:00
// TODO: add entry styles
namespace FML\Controls;
2014-05-14 23:24:00 +02:00
use FML\Script\Features\EntrySubmit;
use FML\Types\NewLineable;
use FML\Types\Scriptable;
use FML\Types\Styleable;
use FML\Types\TextFormatable;
/**
2014-01-19 19:30:21 +01:00
* Entry Control
2014-01-12 00:51:46 +01:00
* (CMlEntry)
*
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
*/
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
*/
protected $name = '';
protected $default = null;
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
2014-05-16 22:44:22 +02:00
/**
* Construct a new Entry Control
*
* @param string $id (optional) Control Id
*/
public function __construct($id = null) {
parent::__construct($id);
$this->tagName = 'entry';
}
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;
}
/**
2014-05-16 22:44:22 +02:00
* @see \FML\Controls\Control::getManiaScriptClass()
*/
public function getManiaScriptClass() {
return 'CMlEntry';
}
/**
* Get the Entry Name
*
2014-05-16 22:44:22 +02:00
* @return string
*/
2014-05-16 22:44:22 +02:00
public function getName() {
return $this->name;
}
/**
2013-12-31 02:55:19 +01:00
* Set Entry Name
*
2014-01-12 00:51:46 +01:00
* @param string $name Entry Name
* @return \FML\Controls\Entry
*/
public function setName($name) {
2014-05-14 23:24:00 +02:00
$this->name = (string)$name;
return $this;
}
2014-04-27 14:44:40 +02:00
/**
2014-05-16 22:44:22 +02:00
* Get the Default Value
2014-04-27 14:44:40 +02:00
*
2014-05-16 22:44:22 +02:00
* @return mixed
2014-04-27 14:44:40 +02:00
*/
2014-05-16 22:44:22 +02:00
public function getDefault() {
return $this->default;
2014-04-27 14:44:40 +02:00
}
/**
2013-12-31 02:55:19 +01:00
* Set Default Value
*
2014-01-12 00:51:46 +01:00
* @param string $default Default Value
* @return \FML\Controls\Entry
*/
public function setDefault($default) {
$this->default = $default;
return $this;
}
2014-05-14 23:24:00 +02: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;
return $this;
}
/**
* @see \FML\Types\TextFormatable::setTextColor()
*/
public function setTextColor($textColor) {
2014-05-14 23:24:00 +02:00
$this->textColor = (string)$textColor;
return $this;
}
/**
* @see \FML\Types\TextFormatable::setTextSize()
*/
public function setTextSize($textSize) {
2014-05-14 23:24:00 +02:00
$this->textSize = (int)$textSize;
return $this;
}
/**
* @see \FML\Types\TextFormatable::setAreaColor()
*/
public function setAreaColor($areaColor) {
2014-05-14 23:24:00 +02:00
$this->focusAreaColor1 = (string)$areaColor;
return $this;
}
/**
* @see \FML\Types\TextFormatable::setAreaFocusColor()
*/
public function setAreaFocusColor($areaFocusColor) {
2014-05-14 23:24:00 +02:00
$this->focusAreaColor2 = (string)$areaFocusColor;
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;
}
/**
* @see \FML\Control::render()
*/
public function render(\DOMDocument $domDocument) {
2014-01-12 00:51:46 +01:00
$xmlElement = parent::render($domDocument);
if ($this->name) {
2014-01-12 00:51:46 +01:00
$xmlElement->setAttribute('name', $this->name);
}
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);
}
}
if ($this->autoNewLine) {
2014-01-12 00:51:46 +01:00
$xmlElement->setAttribute('autonewline', $this->autoNewLine);
}
if ($this->scriptEvents) {
2014-01-12 00:51:46 +01:00
$xmlElement->setAttribute('scriptevents', $this->scriptEvents);
}
if ($this->style) {
2014-01-12 00:51:46 +01:00
$xmlElement->setAttribute('style', $this->style);
}
if ($this->textColor) {
2014-01-12 00:51:46 +01:00
$xmlElement->setAttribute('textcolor', $this->textColor);
}
if ($this->textSize >= 0.) {
2014-01-12 00:51:46 +01:00
$xmlElement->setAttribute('textsize', $this->textSize);
}
2014-01-19 19:30:21 +01:00
if ($this->focusAreaColor1) {
$xmlElement->setAttribute('focusareacolor1', $this->focusAreaColor1);
}
2014-01-19 19:30:21 +01:00
if ($this->focusAreaColor2) {
$xmlElement->setAttribute('focusareacolor2', $this->focusAreaColor2);
}
2014-01-12 00:51:46 +01:00
return $xmlElement;
}
}