Relations.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. Lib::loadClass('ACL');
  3. Lib::loadClass('Api_WfsNs');
  4. class Relations {
  5. static function isAllowedToCreateRelation($userLogin, $typeName, $primaryKey, $remoteTypeName) {
  6. if ($userLogin !== User::getLogin()) throw new Exception("Not Implemented - isAllowedToCreateRelation for another user");
  7. $acl = ACL::getAclByNamespace( Api_WfsNs::toNamespace($typeName) );
  8. if (!$acl->hasField($remoteTypeName)) throw new Exception("Missing field in given object. Field '{$remoteTypeName}' not exists in '{$typeName}'");
  9. if (!$acl->canCreateField($remoteTypeName)) throw new HttpException("Forbidden create relations from {$typeName} to {$remoteTypeName} ", 403);
  10. $item = $acl->getItem($primaryKey);
  11. if (!$item) throw new HttpException("Object not found {$typeName}.{$primaryKey}", 404);
  12. if (!$acl->canWriteObjectField($remoteTypeName, $item)) throw new HttpException("Forbidden create relations from {$typeName}.{$primaryKey} to {$remoteTypeName} ", 403);
  13. return true;
  14. }
  15. static function isAllowedToGetRelation($userLogin, $typeName, $primaryKey, $remoteTypeName) {
  16. if ($userLogin !== User::getLogin()) throw new Exception("Not Implemented - isAllowedToGetRelation for another user");
  17. $acl = ACL::getAclByNamespace( Api_WfsNs::toNamespace($typeName) );
  18. if (!$acl->hasField($remoteTypeName)) throw new Exception("Missing field in given object. Field '{$remoteTypeName}' not exists in '{$typeName}'");
  19. if (!$acl->canReadField($remoteTypeName)) throw new HttpException("Forbidden reading relations from {$typeName} to {$remoteTypeName} ", 403);
  20. $item = $acl->getItem($primaryKey);
  21. if (!$item) throw new HttpException("Object not found {$typeName}.{$primaryKey}", 404);
  22. if (!$acl->canReadObjectField($remoteTypeName, $item)) throw new HttpException("Forbidden reading relations from {$typeName}.{$primaryKey} to {$remoteTypeName} ", 403);
  23. return true;
  24. }
  25. static function isAllowedToDeleteRelation($userLogin, $typeName, $primaryKey, $remoteTypeName) {
  26. DBG::log("TODO: Relations::isAllowedToDeleteRelation()...");
  27. return false;
  28. }
  29. static function getRelations($typeName, $primaryKey, $remoteTypeName) {
  30. $namespace = Api_WfsNs::toNamespace($typeName);
  31. return ACL::fetchRefs($namespace, $primaryKey, $remoteTypeName);
  32. }
  33. static function createRelations($typeName, $primaryKey, $remoteTypeName, $listRemotePrimaryKeys) {
  34. $namespace = Api_WfsNs::toNamespace($typeName);
  35. $acl = ACL::getAclByNamespace($namespace);
  36. ACL::addListRef($namespace, $remoteTypeName, $primaryKey, $listRemotePrimaryKeys);
  37. }
  38. static function deleteRelations($typeName, $primaryKey, $remoteTypeName, $listRemotePrimaryKeys) {
  39. $namespace = Api_WfsNs::toNamespace($typeName);
  40. $acl = ACL::getAclByNamespace($namespace);
  41. ACL::removeListRef($namespace, $remoteTypeName, $primaryKey, $listRemotePrimaryKeys);
  42. }
  43. }