From: Niklas Laxström Date: Sat, 10 May 2008 13:44:25 +0000 (+0000) Subject: * Added code two commonly needed use cases: separate label and input, and select X-Git-Tag: 1.31.0-rc.0~47736 X-Git-Url: https://git.cyclocoop.org/%7B%24admin_url%7Dmembres/modifier.php?a=commitdiff_plain;h=6934849a0a8d5a0862ef7ff0e26c4f4b83ead794;p=lhc%2Fweb%2Fwiklou.git * Added code two commonly needed use cases: separate label and input, and select --- diff --git a/includes/Xml.php b/includes/Xml.php index 84b5210c38..7dad20f875 100644 --- a/includes/Xml.php +++ b/includes/Xml.php @@ -264,9 +264,15 @@ class Xml { * @return string HTML */ public static function inputLabel( $label, $name, $id, $size=false, $value=false, $attribs=array() ) { - return Xml::label( $label, $id ) . - ' ' . - self::input( $name, $size, $value, array( 'id' => $id ) + $attribs ); + list( $label, $input ) = self::inputLabelSep( $label, $name, $id, $size, $value, $attribs ); + return $label . ' ' . $input; + } + + public static function inputLabelSep( $label, $name, $id, $size=false, $value=false, $attribs=array() ) { + return array( + Xml::label( $label, $id ), + self::input( $name, $size, $value, array( 'id' => $id ) + $attribs ) + ); } /** @@ -550,3 +556,33 @@ class Xml { return $form; } } + +class XMLSelect { + protected $options = array(); + protected $default = false; + protected $attributes = array(); + + public function __construct( $name = false, $id = false, $default = false ) { + if ( $name ) $this->setAttribute( 'name', $name ); + if ( $id ) $this->setAttribute( 'id', $id ); + if ( $default ) $this->default = $default; + } + + public function setDefault( $default ) { + $this->default = $default; + } + + public function setAttribute( $name, $value ) { + $this->attributes[$name] = $value; + } + + public function addOption( $name, $value = false ) { + $value = $value ? $value : $name; + $this->options[] = Xml::option( $name, $value, $value === $this->default ); + } + + public function getHTML() { + return Xml::tags( 'select', $this->attributes, implode( "\n", $this->options ) ); + } + +} \ No newline at end of file