/** * Internal DOM export method * * @param CStoredObject $object Object to export * @param int $depth Export depth * * @return void */ private function _toDOM(CStoredObject $object, $depth) { if ($depth == 0 || !$object->_id || !$object->getPerm(PERM_READ)) { return; } $doc = $this->doc; $object_node = $doc->getElementById($object->_guid); // Objet deja exporté if ($object_node) { return; } $object_node = $doc->createElement("object"); $object_node->setAttribute('class', $object->_class); $object_node->setAttribute('id', $object->_guid); $object_node->setIdAttribute('id', true); $doc->documentElement->appendChild($object_node); $db_fields = $object->getPlainFields(); foreach ($db_fields as $key => $value) { // Forward Refs Fields $_fwd_spec = $object->_specs[$key]; if ($_fwd_spec instanceof CRefSpec) { if ($key === $object->_spec->key && $object->_specs[$key]->className !== $object->_class) { continue; } if (!isset($this->fwdrefs_tree[$object->_class]) || !in_array($key, $this->fwdrefs_tree[$object->_class])) { continue; } $object->loadFwdRef($key); $guid = ""; $_object = $object->_fwd[$key]; if ($_object && $_object->_id) { $this->_toDOM($_object, $depth - 1); $guid = $_object->_guid; } if ($this->empty_values || $guid) { $object_node->setAttribute($key, $guid); //$doc->insertTextElement($object_node, "field", $id, array("name" => $key)); } } else { $value = self::trimString($value); if ($this->empty_values || $value !== "") { $doc->insertTextElement($object_node, "field", $value, array("name" => $key)); } } } if ($this->object_callback && is_callable($this->object_callback)) { call_user_func($this->object_callback, $object, $object_node, $depth); } // Collections if (!isset($this->backrefs_tree[$object->_class])) { return; } foreach ($object->_backProps as $backName => $backProp) { if (!in_array($backName, $this->backrefs_tree[$object->_class])) { continue; } $_backspec = $object->makeBackSpec($backName); // Add fwd ref field value for each object in the collection if ($_backspec) { $_class = $_backspec->class; if (!isset($this->fwdrefs_tree[$_class])) { $this->fwdrefs_tree[$_class] = array(); } if (!array_key_exists($_backspec->field, $this->fwdrefs_tree[$_class])) { $this->fwdrefs_tree[$_class][] = $_backspec->field; } } $objects = $object->loadBackRefs($backName); if ($objects) { foreach ($objects as $_object) { $this->_toDOM($_object, $depth - 1); } } } }