1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72:
<?php
defined('ICMS_ROOT_PATH') or die("ImpressCMS root path not defined");
class icms_ipf_form_elements_Parentcategory extends icms_form_elements_Select {
public function __construct($object, $key) {
$category_title_field = $object->handler->identifierName;
$addNoParent = isset($object->controls[$key]['addNoParent']) ? $object->controls[$key]['addNoParent'] : true;
$criteria = new icms_db_criteria_Compo();
$criteria->setSort("weight, " . $category_title_field);
$category_handler = icms_getModuleHandler('category', $object->handler->_moduleName);
$categories = $category_handler->getObjects($criteria);
$mytree = new icms_ipf_Tree($categories, "category_id", "category_pid");
parent::__construct($object->vars[$key]['form_caption'], $key, $object->getVar($key, 'e'));
$ret = array();
$options = $this->getOptionArray($mytree, $category_title_field, 0, $ret, "");
if ($addNoParent) {
$newOptions = array('0' => '----');
foreach ($options as $k => $v) {
$newOptions[$k] = $v;
}
$options = $newOptions;
}
$this->addOptionArray($options);
}
private function getOptionArray($tree, $fieldName, $key, &$ret, $prefix_curr = "") {
if ($key > 0) {
$value = $tree->_tree[$key]['obj']->getVar($tree->_myId);
$ret[$key] = $prefix_curr . $tree->_tree[$key]['obj']->getVar($fieldName);
$prefix_curr .= "-";
}
if (isset($tree->_tree[$key]['child']) && !empty($tree->_tree[$key]['child'])) {
foreach ($tree->_tree[$key]['child'] as $childkey) {
$this->getOptionArray($tree, $fieldName, $childkey, $ret, $prefix_curr);
}
}
return $ret;
}
}