Relations.php 2.0 KB

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