AclSimpleSchemaBase.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <?php
  2. Lib::loadClass('Api_WfsNs');
  3. Lib::loadClass('Api_WfsException');
  4. Lib::loadClass('User');
  5. Lib::loadClass('Core_AclHelper');
  6. class Core_AclSimpleSchemaBase extends Core_AclBase {
  7. public $_simpleSchema = array();
  8. public $_xsdTypes = null;
  9. public function getSimpleSchema() { return $this->_simpleSchema; }
  10. public function getNamespace() { return 'default_objects/' . $this->getName(); }
  11. public function getSourceName() { return 'default_objects'; }
  12. public function init($force = false) {}
  13. public function isInitialized() { return true; }
  14. public function getFieldListByIdZasob() { return $this->getRealFieldListByIdZasob(); }
  15. public function getVisibleFieldListByIdZasob() { return $this->getRealFieldListByIdZasob(); }
  16. public function getVirtualFieldListByIdZasob() { return array(); }
  17. public function getRealFieldListByIdZasob($force = false) {
  18. $cols = array();
  19. foreach ($this->getFields() as $idField => $field) {
  20. $cols[$idField] = $field['name'];
  21. }
  22. return $cols;
  23. }
  24. public function getXsdTypes() {
  25. if (null !== $this->_xsdTypes) return $this->_xsdTypes;
  26. $this->_xsdTypes = array();
  27. $generatedIdZasob = 10000;
  28. foreach ($this->_simpleSchema as $key => $value) {
  29. if ('@' == substr($key, 0, 1)) continue;// skip attributes
  30. if (is_array($value)) {
  31. $fieldName = $key;
  32. $field = [ 'name' => $fieldName, 'perms' => 'R', 'idZasob' => $generatedIdZasob ];
  33. if (!empty($value['@baseTypeName'])) $field['xsdType'] = "alias_ref:{$value['@baseTypeName']}";
  34. else if (!empty($value['@ref'])) $field['xsdType'] = "alias_ref:{$value['@ref']}";
  35. else throw new Exception("StorageAcl - field type not defined '{$key}'");
  36. if (!empty($value['@maxOccurs'])) $field['maxOccurs'] = $value['@maxOccurs'];
  37. $this->_xsdTypes[$fieldName] = $field;
  38. } else if (is_scalar($value)) {
  39. $fieldName = $key;
  40. $field = [ 'name' => $fieldName, 'perms' => 'R', 'idZasob' => $generatedIdZasob ];
  41. $field['xsdType'] = $value;
  42. $this->_xsdTypes[$fieldName] = $field;
  43. } else {
  44. throw new Exception("StorageAcl - TODO: Unimplemented value type in simpleSchema: " . json_encode($value));
  45. }
  46. $generatedIdZasob++;
  47. }
  48. return $this->_xsdTypes;
  49. }
  50. public function getFields() {// @returns array - $this->_fields
  51. $fieldsById = array();
  52. foreach ($this->getXsdTypes() as $fieldName => $field) {
  53. $field['name'] = $fieldName;
  54. $fieldsById[ $field['idZasob'] ] = $field;
  55. }
  56. return $fieldsById;
  57. }
  58. public function getFieldType($fieldName) {
  59. foreach ($this->getFields() as $field) {
  60. if ($fieldName == $field['name']) return $field;
  61. }
  62. return null;
  63. }
  64. // TODO: replace legacy functions: isAllowed, hasFieldPerm, getFieldIdByName
  65. public function canCreateField($fieldName) {
  66. return false;// TODO: perms from Procesy
  67. }
  68. public function canReadField($fieldName) {
  69. return true;// TODO: perms from Procesy
  70. }
  71. public function canReadObjectField($fieldName, $record) {
  72. return true;// TODO: perms from Procesy
  73. }
  74. public function canWriteField($fieldName) {
  75. return false;// TODO: perms from Procesy
  76. }
  77. public function canWriteObjectField($fieldName, $record) {
  78. return false;// TODO: perms from Procesy
  79. }
  80. public function getTotal($params = array()) {// TODO: use ParseOgcQuery
  81. throw new Exception("Unimplemented - TODO: F." . __FUNCTION__);
  82. }
  83. public function getItem($primaryKey) {
  84. throw new Exception("Unimplemented - TODO: F." . __FUNCTION__);
  85. }
  86. public function getItems($params = array()) {// TODO: use ParseOgcQuery
  87. throw new Exception("Unimplemented - TODO: F." . __FUNCTION__);
  88. }
  89. public function fetchItemRef(&$items) {
  90. throw new Exception("Unimplemented - TODO: F." . __FUNCTION__);
  91. }
  92. public function addItem($itemTodo) {
  93. throw new Exception("Unimplemented - TODO: F." . __FUNCTION__);
  94. // return $this->parentAcl->addItem($itemTodo);
  95. }
  96. public function updateItem($itemPatch) {
  97. throw new Exception("Unimplemented - TODO: F." . __FUNCTION__);
  98. // return $this->parentAcl->updateItem($itemPatch);
  99. }
  100. public function getGeomFieldType($fieldName) { return null; }
  101. public function getPrimaryKeyField() { return 'ID'; }
  102. public function getID() { return 0; }
  103. public function getAttributesFromZasoby() { return array(); }
  104. public function isEnumerationField($fieldName) { return false; }
  105. public function getEnumerations($fieldName) { return null; }
  106. public function getXsdFieldType($fieldName) {
  107. $xsdTypes = $this->getXsdTypes();
  108. if (empty($xsdTypes[$fieldName])) throw new Exception("Field '{$fieldName}' not exists");
  109. return $xsdTypes[$fieldName]['xsdType'];
  110. }
  111. public function isGeomField($fldName) {
  112. if ('File' == $fieldName) return false;
  113. if ('AccessGroupRead' == $fieldName) return false;
  114. if ('AccessGroupWrite' == $fieldName) return false;
  115. if ('AccessOwner' == $fieldName) return false;
  116. // if ('NestedObjectTest' == $fieldName) return false;
  117. // return $this->parentAcl->isGeomField($fldName);
  118. }
  119. }