AclHelper.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. class Core_AclHelper {// Helper class for Acl
  3. public static function hasCreatePerms($acl) {
  4. foreach ($acl->getFieldListByIdZasob() as $fieldName) {// TODO: use getFieldList
  5. // echo"<p>\$acl->canCreateField({$fieldName}): (".$acl->canCreateField($fieldName).")</p>";
  6. if ($acl->canCreateField($fieldName)) return true;
  7. }
  8. return false;
  9. }
  10. public static function hasGeomFields($acl) {
  11. foreach ($acl->getFieldListByIdZasob() as $fieldName) {
  12. // echo"<p>\$acl->isGeomField({$fieldName}): (".$acl->isGeomField($fieldName).") \$acl->canReadField({$fieldName}): (".$acl->canReadField($fieldName).")</p>";
  13. if ($acl->isGeomField($fieldName) && $acl->canReadField($fieldName)) return true;
  14. }
  15. return false;
  16. }
  17. public static function getAclByNamespace($namespace, $forceTblAclInit) {
  18. if ('http' != substr($namespace, 0, 4)) $namespace = Api_WfsNs::getBaseWfsUri() . '/' . $namespace;//Request::getHostUri() . '/' . $namespace;
  19. $baseNsUri = Api_WfsNs::getBaseWfsUri();
  20. if ("{$baseNsUri}/" == substr($namespace, 0, strlen($baseNsUri) + 1)) {
  21. $schemaNs = substr($namespace, strlen($baseNsUri) + 1);
  22. $ns = explode('/', $schemaNs);// "http://biuro.biall-net.pl/wfs/ default_db/{$nazwa_tabeli}/{$nazwa_obj}
  23. $sourceName = array_shift($ns);// remove first element - source name
  24. if ('default_db' == $sourceName || 'p5_default_db' == $sourceName) {
  25. $sourceName = 'default_db';
  26. $objName = $ns[0];
  27. if (1 == count($ns)) {
  28. $acl = User::getAcl()->getObjectAcl($sourceName, $objName);
  29. if (!$acl) throw new Exception("Could not get acl for '{$schemaNs}'");
  30. $acl->init($forceTblAclInit);
  31. return $acl;
  32. }
  33. else throw new Exception("Nieznany namespace default_db: '{$schemaNs}'", 501);
  34. }
  35. else if ('default_objects' == $sourceName || 'SystemObjects' == $sourceName || 'p5_objects' == $sourceName) {
  36. $sourceName = 'objects';
  37. $objName = $ns[0];
  38. if (1 == count($ns)) {
  39. $acl = User::getAcl()->getObjectAcl($sourceName, $objName);
  40. if (!$acl) throw new Exception("Could not get acl for '{$schemaNs}'");
  41. $acl->init($forceTblAclInit);
  42. return $acl;
  43. }
  44. else throw new Exception("Nieznany namespace SystemObjects: '{$schemaNs}'", 501);
  45. }
  46. else if ('zasob_' == substr($sourceName, 0, 6)) {
  47. $dbName = substr($sourceName, 6);
  48. throw new Exception("TODO db[{$dbName}] namespace '{$schemaNs}'", 501);
  49. }
  50. else throw new Exception("Nieznany namespace '{$schemaNs}'", 501);
  51. }
  52. else throw new HttpException("Zasoby zewnętrzenj systemu nie są jeszcze zaimplementowane", 501);
  53. throw new HttpException("TODO L.".__LINE__." ns({$namespace})", 501);
  54. }
  55. }