2007-07-19 12:40:28 +02:00
|
|
|
<?php
|
|
|
|
/**
|
2008-01-09 05:18:36 +01:00
|
|
|
* Implements a single tab in a {@link TabSet}.
|
2010-10-15 05:55:22 +02:00
|
|
|
*
|
|
|
|
* Here is a simple implementation of a Tab. Obviously, you can include as much fields
|
|
|
|
* inside as you want. A tab can contain other tabs as well.
|
|
|
|
*
|
|
|
|
* <code>
|
|
|
|
* new Tab(
|
|
|
|
* $title='Tab one',
|
|
|
|
* new HeaderField("A header"),
|
|
|
|
* new LiteralField("Lipsum","Lorem ipsum dolor sit amet enim.")
|
|
|
|
* )
|
|
|
|
* </code>
|
|
|
|
*
|
2008-01-09 05:18:36 +01:00
|
|
|
* @package forms
|
|
|
|
* @subpackage fields-structural
|
2007-07-19 12:40:28 +02:00
|
|
|
*/
|
|
|
|
class Tab extends CompositeField {
|
|
|
|
protected $tabSet;
|
|
|
|
|
2008-10-10 18:00:50 +02:00
|
|
|
/**
|
|
|
|
* @uses FormField::name_to_label()
|
|
|
|
*
|
|
|
|
* @param string $name Identifier of the tab, without characters like dots or spaces
|
|
|
|
* @param string $title Natural language title of the tab. If its left out,
|
|
|
|
* the class uses {@link FormField::name_to_label()} to produce a title from the {@link $name} parameter.
|
|
|
|
* @param FormField All following parameters are inserted as children to this tab
|
|
|
|
*/
|
2008-08-09 07:57:44 +02:00
|
|
|
public function __construct($name) {
|
2007-07-19 12:40:28 +02:00
|
|
|
$args = func_get_args();
|
2008-10-10 18:00:50 +02:00
|
|
|
|
2008-08-09 07:57:44 +02:00
|
|
|
$name = array_shift($args);
|
2008-10-10 18:00:50 +02:00
|
|
|
if(!is_string($name)) user_error('TabSet::__construct(): $name parameter to a valid string', E_USER_ERROR);
|
2008-08-09 07:57:44 +02:00
|
|
|
$this->name = $name;
|
2007-07-19 12:40:28 +02:00
|
|
|
|
2008-10-10 18:00:50 +02:00
|
|
|
$this->id = preg_replace('/[^0-9A-Za-z]+/', '', $name);
|
|
|
|
|
|
|
|
// Legacy handling: only assume second parameter as title if its a string,
|
|
|
|
// otherwise it might be a formfield instance
|
|
|
|
if(isset($args[0]) && is_string($args[0])) {
|
|
|
|
$title = array_shift($args);
|
|
|
|
}
|
|
|
|
$this->title = (isset($title)) ? $title : FormField::name_to_label($name);
|
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
parent::__construct($args);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function id() {
|
2012-02-10 11:50:10 +01:00
|
|
|
return ($this->tabSet) ? $this->tabSet->id() . '_' . $this->id : $this->id;
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function Fields() {
|
|
|
|
return $this->children;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setTabSet($val) {
|
|
|
|
$this->tabSet = $val;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the named field
|
|
|
|
*/
|
|
|
|
public function fieldByName($name) {
|
|
|
|
foreach($this->children as $child) {
|
2011-10-29 06:01:52 +02:00
|
|
|
if($name == $child->getName()) return $child;
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|