* @package tao */ use oat\tao\helpers\form\elements\xhtml\XhtmlRenderingTrait; /** * Treebox widget */ class tao_helpers_form_elements_xhtml_Treebox extends tao_helpers_form_elements_Treebox { use XhtmlRenderingTrait; /** * * @var core_kernel_classes_Class */ protected $range; /** * * @return void */ public function feed() { $expression = "/^" . preg_quote($this->name, "/") . "(.)*[0-9]+$/"; $this->setValues([]); foreach ($_POST as $key => $value) { if (preg_match($expression, $key)) { $this->addValue(tao_helpers_Uri::decode($value)); } } } /** * * @param string $format * * @return array */ public function getOptions($format = 'flat') { switch ($format) { case 'structured': $returnValue = parent::getOptions(); break; case 'flat': default: $returnValue = tao_helpers_form_GenerisFormFactory::extractTreeData(parent::getOptions()); break; } return $returnValue; } /** * * @param string $value * * @return void */ public function setValue($value) { $this->addValue($value); } /** * * @return string */ public function render() { $widgetTreeName = $this->name . '-TreeBox'; $widgetValueName = $this->name . '-TreeValues'; $returnValue = $this->renderLabel(); $returnValue .= "
"; $returnValue .= "
"; $i = 0; foreach ($this->values as $value) { $returnValue .= 'name . '_' . $i++ . '\' value=\'' . $value . '\' />'; } $returnValue .= "
"; $returnValue .= "
"; $returnValue .= "'; $returnValue .= "

"; return (string) $returnValue; return $returnValue; } /** * * @access public * @return mixed */ public function getEvaluatedValue() { $values = array_map("tao_helpers_Uri::decode", $this->getValues()); if (count($values) === 1) { return $values[0]; } else { return $values; } } }