/**
  * 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);
             }
         }
     }
 }
Esempio n. 2
0
 /**
  * Gets the permission on the module
  *
  * @param CStoredObject $object        Object to load the permissions of
  * @param int           $permType      Permission level
  * @param CStoredObject $defaultObject Default object to load the permissions from
  * @param int           $user_id       User ID
  *
  * @return bool
  */
 static function getPermObject(CStoredObject $object, $permType, $defaultObject = null, $user_id = null)
 {
     $user = CUser::get($user_id);
     // Shorteners
     $class = $object->_class;
     $id = $object->_id;
     // Use permission query cache when available
     if (isset(self::$users_cache[$user->_id][$class][$id])) {
         return self::$users_cache[$user->_id][$class][$id] >= $permType;
     }
     // New cached permissions system : DO NOT REMOVE
     if (is_array(self::$users_perms)) {
         self::buildUser($user->_id);
         $perms = self::$users_perms[$user->_id];
         // Object specific, or Class specific, or Module generic
         $perm = isset($perms[$class][$id]) ? $perms[$class][$id] : (isset($perms[$class]["all"]) ? $perms[$class]["all"] : "module");
         // In case of module check, first build module cache, then get value from cache
         if ($perm == "module") {
             $mod_id = $object->_ref_module->_id;
             CPermModule::getPermModule($mod_id, $permType, $user->_id);
             $perm = CPermModule::$users_cache[$user->_id][$mod_id]["permission"];
         }
         self::$users_cache[$user->_id][$class][$id] = $perm;
         return $perm >= $permType;
     }
     global $userPermsObjects;
     $object_class = $object->_class;
     $object_id = $object->_id;
     if (isset($userPermsObjects[$object_class][$object_id])) {
         return $userPermsObjects[$object_class][$object_id]->permission >= $permType;
     }
     if (isset($userPermsObjects[$object_class][0])) {
         return $userPermsObjects[$object_class][0]->permission >= $permType;
     }
     return $defaultObject != null ? $defaultObject->getPerm($permType) : $object->_ref_module->getPerm($permType);
 }