Пример #1
0
 /**
  * Converts an XML string into an object struct.
  *
  * @param string $data The XML string
  *
  * @return esXml The parsed XML
  */
 private function xmlToObject($data)
 {
     $root = new Node();
     $root->setName('root');
     $actualLevel = 1;
     $actualNode = $root;
     $stack = array();
     $stack[1] = $root;
     foreach ($this->parseIntoStruct($data) as $element) {
         if ($element['type'] === 'close') {
             continue;
         }
         $node = new Node();
         $node->setName($element['tag']);
         if (isset($element['attributes'])) {
             $node->setAttributes($element['attributes']);
         }
         if (isset($element['value'])) {
             $node->setValue($element['value']);
         }
         $level = $element['level'];
         if ($level > $actualLevel) {
             $stack[$level] = $actualNode;
         }
         $stack[$level]->addChild($node);
         $actualNode = $node;
         $actualLevel = $element['level'];
     }
     $children = $root->getChildren();
     unset($root);
     return $children[0]->setParent(null);
 }
Пример #2
0
 private function createNodeFromElement($elem, $parent)
 {
     $node = new Node();
     $node->setParent($parent);
     $node->setType($elem->nodeName);
     $node->setText($elem->nodeValue);
     $node->setDepth($parent->getDepth() + 1);
     $node->setAttributes($this->getElementAttributes($elem));
     return $node;
 }
 /**
  * Adds an error. The XML representation will look like this:
  * <xmp>
  *   <error
  *    checker="foo.bar.wrapper.MyLoginDataChecker"
  *    type="user_nonexistant"
  *    field="username"                    
  *   />                                                 
  * </xmp>
  *
  * @param   string checker The class checking the input
  * @param   string type The error type
  * @param   string field default '*' The form field corresponding
  * @param   var info default NULL 
  * @return  bool FALSE
  */
 public function addFormError($checker, $type, $field = '*', $info = NULL)
 {
     if (is_array($info)) {
         $c = Node::fromArray($info, 'error');
     } else {
         if (is_object($info)) {
             $c = Node::fromObject($info, 'error');
         } else {
             $c = new Node('error', $info);
         }
     }
     $c->setAttributes(array('type' => $type, 'field' => $field, 'checker' => $checker));
     $this->document->formerrors->addChild($c);
     return FALSE;
 }
Пример #4
0
 public function insertDefaultNodes($mindmapId)
 {
     $parent = false;
     foreach ($this->_defaultNodes as $dnode) {
         $node = new Node();
         $node->setAttributes($dnode);
         $node->mindmap_id = $mindmapId;
         if ($parent) {
             $node->parent_id = $parent;
         }
         if (!$node->save()) {
             return false;
         }
         if ($dnode['type'] == 1) {
             $parent = $node->id;
         }
     }
     return true;
 }