private function getCells($list, $tag = 'td') { $nodes = ar_html::nodes(); foreach ($list as $key => $content) { $nodes[] = ar_html::el($tag, $content); } return $nodes; }
public function getField($content = null) { $fieldset = parent::getField($content); $count = 0; foreach ($fieldset->div as $field) { $field->appendChild(ar_html::el('button', array('class' => 'formFieldListDelete', 'type' => 'submit', 'name' => $this->name . '[Delete]', 'value' => $count), '-')); $count++; } if ($this->newField) { $newField = $this->newField->getField(); $newField->appendChild(ar_html::el('button', array('class' => 'formFieldListAdd', 'type' => 'submit', 'name' => $this->name . '[Add]', 'value' => $this->name . 'NewField'), '+')); $fieldset->appendChild(ar_html::el('div', array('class' => 'formFieldListAdd'), $newField)); } return $fieldset; }
private function _fillFromArray($list, $current, $parent = '[root]') { // first enter all nodes into the items list // then rearrange them into parent/child relations // otherwise you must always have the parent in the list before any child foreach ($list as $key => $item) { if (!$item) { continue; } $itemInfo = $this->_getItemInfo($item, $key, $parent, $current); $itemNode = $itemInfo['node']; $this->items[$itemInfo['url']] = $itemNode; if ($parent != '[root]') { $parentNode = $this->items[$parent]; if ($parentNode) { $uls = $parentNode->getElementsByTagName($this->options['listTag'], true); if (!$uls || !$uls[0]) { $ul = $parentNode->appendChild(ar_html::el($this->options['listTag'])); } else { $ul = $uls[0]; } $ul->appendChild($itemNode); } } if ($itemInfo['children']) { $this->_fillFromArray($itemInfo['children'], $current, $itemInfo['url']); } } foreach ($this->items as $url => $itemNode) { if ($url != '[root]') { // do not remove, prevents infinite loop if ($parent == '[root]') { if ($url == $this->rooturl) { $parentNode = $this; } else { $oldparent = ''; $newparent = dirname($url) . '/'; if (!$this->options['skipOrphans']) { while ($newparent != $oldparent && !isset($this->items[$newparent]) && $newparent != $this->rooturl) { $oldparent = $newparent; $newparent = dirname($newparent) . '/'; } } if (isset($this->items[$newparent])) { $parentNode = current($this->items[$newparent]->getElementsByTagName($this->options['listTag'])); if (!$parentNode || !isset($parentNode)) { $parentNode = $this->items[$newparent]->appendChild(ar_html::el($this->options['listTag'])); } } else { if ($newparent == $this->rooturl) { $parentNode = $this; } else { if (!$this->options['skipOrphans']) { $parentNode = $this; } else { $parentNode = null; } } } } } else { if (isset($this->items[$parent])) { $parentNode = $this->items[$parent]; } else { if (!$this->options['skipOrphans']) { $parentNode = $this; } else { $parentNode = null; } } } if ($parentNode && $parentNode !== $itemNode) { // itemNode should not be parentNode to prevent loops $temp = $parentNode; $ok = true; while ($temp) { if ($temp === $itemNode) { $ok = false; break; } $temp = $temp->parentNode; } if ($ok) { $parentNode->appendChild($itemNode); } } } } }