* @package tao */ class tao_helpers_form_elements_xhtml_Treeview extends tao_helpers_form_elements_Treeview { use XhtmlRenderingTrait; const NO_TREEVIEW_INTERACTION_IDENTIFIER = 'x-tao-no-treeview-interaction'; /** * Short description of method feed * * @access public * @author Joel Bout, * @return mixed */ public function feed() { $expression = "/^" . preg_quote($this->name, "/") . "(.)*[0-9]+$/"; $foundIndexes = []; foreach ($_POST as $key => $value) { if (preg_match($expression, $key)) { $foundIndexes[] = $key; } } if ((count($foundIndexes) > 0 && $_POST[$foundIndexes[0]] !== self::NO_TREEVIEW_INTERACTION_IDENTIFIER) || count($foundIndexes) === 0) { $this->setValues([]); } elseif ((count($foundIndexes) > 0 && $_POST[$foundIndexes[0]] === self::NO_TREEVIEW_INTERACTION_IDENTIFIER)) { array_shift($foundIndexes); } foreach ($foundIndexes as $index) { $this->addValue(tao_helpers_Uri::decode($_POST[$index])); } } /** * Short description of method getOptions * * @access public * @author Joel Bout, * @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 (array) $returnValue; } /** * Short description of method setValue * * @access public * @author Joel Bout, * @param string value * @return mixed */ public function setValue($value) { $this->addValue($value); } /** * Short description of method render * * @access public * @author Joel Bout, * @return string */ public function render() { $widgetTreeName = $this->name . '-TreeBox'; $widgetValueName = $this->name . '-TreeValues'; $returnValue = $this->renderLabel(); $returnValue .= "
"; $returnValue .= "
"; $returnValue .= ''; $returnValue .= "
"; $returnValue .= "
"; // initialize the AsyncFileUpload Js component $returnValue .= ' '; $returnValue .= "

"; return (string) $returnValue; } /** * Short description of method getEvaluatedValue * * @access public * @author Joel Bout, * @return mixed */ public function getEvaluatedValue() { $values = array_map("tao_helpers_Uri::decode", $this->getValues()); if (count($values) == 1) { return $values[0]; } else { return $values; } } public function rangeToTree(core_kernel_classes_Class $range, $recursive = true) { $openNodes = array_reduce($range->getSubClasses(true), function ($carry, $item) { if (! $carry) { $carry = []; } $carry[] = $item->getUri(); return $carry; }); $openNodes[] = $range->getUri(); $factory = new GenerisTreeFactory(true, $openNodes, 10, 0); $array = $factory->buildTree($range); return $array; } }