TrackManiaControl/libs/FML/Controls/Entry.php

218 lines
4.8 KiB
PHP
Raw Normal View History

<?php
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-20 15:44:45 +02:00
* @author steeffeen <mail@steeffeen.com>
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
/*
2014-06-21 03:18:21 +02:00
* Protected properties
*/
2014-06-21 03:18:21 +02:00
protected $tagName = 'entry';
protected $name = null;
protected $default = null;
2014-06-21 03:18:21 +02:00
protected $autoNewLine = null;
protected $scriptEvents = null;
protected $style = null;
protected $textColor = null;
protected $textSize = -1;
2014-07-04 23:50:43 +02:00
protected $textFont = null;
2014-06-21 03:18:21 +02:00
protected $focusAreaColor1 = null;
protected $focusAreaColor2 = null;
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
* @see \FML\Controls\Control::getManiaScriptClass()
*/
public function getManiaScriptClass() {
return 'CMlEntry';
}
/**
2014-06-21 03:18:21 +02:00
* 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;
}
/**
2014-06-21 03:18:21 +02:00
* Set Entry name
*
2014-06-21 03:18:21 +02:00
* @param string $name Entry name
2014-07-03 22:34:47 +02:00
* @return static
*/
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-06-21 03:18:21 +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
}
/**
2014-06-21 03:18:21 +02:00
* Set default value
*
2014-06-21 03:18:21 +02:00
* @param string $default Default value
2014-07-03 22:34:47 +02:00
* @return static
*/
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;
}
2014-07-04 23:50:43 +02:00
/**
* @see \FML\Types\TextFormatable::setTextFont()
*/
public function setTextFont($textFont) {
$this->textFont = (string)$textFont;
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
/**
2014-06-21 03:18:21 +02:00
* Set auto completion
2014-04-27 14:44:40 +02:00
*
2014-06-21 03:18:21 +02:00
* @param bool $autoComplete Whether the default value should be automatically completed based on the current request parameters
2014-07-03 22:34:47 +02:00
* @return static
2014-04-27 14:44:40 +02:00
*/
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
*
2014-06-21 03:18:21 +02:00
* @param string $url Submit url
2014-07-03 22:34:47 +02:00
* @return static
2014-04-27 14:44:40 +02:00
*/
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;
}
/**
2014-07-03 22:34:47 +02:00
* @see \FML\Types\Renderable::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);
}
2014-08-11 23:15:53 +02: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);
}
}
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-07-04 23:50:43 +02:00
if ($this->textFont) {
$xmlElement->setAttribute('textfont', $this->textFont);
}
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;
}
}