AclSimpleSchemaBase.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. <?php
  2. Lib::loadClass('Api_WfsNs');
  3. Lib::loadClass('Api_WfsException');
  4. Lib::loadClass('User');
  5. Lib::loadClass('Core_AclHelper');
  6. Lib::loadClass('Core_AclBase');
  7. class Core_AclSimpleSchemaBase extends Core_AclBase {
  8. /** simpleSchema - php structure:
  9. $simpleSchema = [
  10. 'root' => [
  11. '@namespace' => 'default_db/ZALICZKA/Zaliczka',
  12. 'ID' => 'xsd:integer', // short syntax - define only simpleType
  13. 'KWOTA' => [ // long syntax - define type with another params like restrictions
  14. '@type' => 'xsd:decimal'
  15. ],
  16. 'worker' => 'ref:Worker' // short syntax - define only type = ref
  17. 'pozycja' => [ // long syntax - define ref with maxOccurs, TODO: use more xsd attributes
  18. '@ref' => 'ZaliczkaPozycja',
  19. '@maxOccurs' => 'unbounded'
  20. ]
  21. ],
  22. 'Worker' => [
  23. '@namespace' => 'default_objects/AccessOwner',
  24. ...
  25. ],
  26. 'ZaliczkaPozycja' => [
  27. '@namespace' => 'default_db/ZALICZKA_POZYCJA/ZaliczkaPozycja',
  28. ...
  29. ]
  30. ]
  31. */
  32. public $_simpleSchema = array();
  33. public $_xsdTypes = null;// set by parseXsdTypes()
  34. public $_name = '';
  35. public $_rootTableName = '';
  36. public $_xmlnsMap = [];
  37. public function __construct($simpleSchema = null) {
  38. if ($simpleSchema) $this->_simpleSchema = $simpleSchema;
  39. if (!$this->_simpleSchema) throw new Exception("Missing simpleSchema");
  40. if (empty($this->_simpleSchema['root'])) throw new Exception("Wrong simpleSchema syntax");
  41. if (empty($this->_simpleSchema['root']['@namespace'])) throw new Exception("Missing @namespace in simpleSchema");
  42. $ns = explode('/', $this->_simpleSchema['root']['@namespace']);
  43. $this->_name = end($ns);
  44. if (count($ns) < 2) throw new Exception("Wrong @namespace syntax in simpleSchema");
  45. $this->_rootTableName = $ns[1];
  46. // $this->parseXsdTypes();// parse xsdTypes
  47. $this->_xsdTypes = array();
  48. {
  49. $generatedIdZasob = 10000;// fake zasob id
  50. foreach ($this->_simpleSchema['root'] as $key => $value) {
  51. if ('@' == substr($key, 0, 1)) continue;// skip attributes
  52. if (is_array($value)) {
  53. $fieldName = $key;
  54. $field = [ 'name' => $fieldName, 'perms' => '', 'idZasob' => $generatedIdZasob ];
  55. if (!empty($value['@type'])) $field['xsdType'] = "{$value['@type']}";
  56. else if (!empty($value['@ref'])) $field['xsdType'] = "ref:{$value['@ref']}";
  57. else throw new Exception("StorageAcl - field type not defined '{$key}'");
  58. if (!empty($value['@maxOccurs'])) $field['maxOccurs'] = $value['@maxOccurs'];
  59. $this->_xsdTypes[$fieldName] = $field;
  60. } else if (is_scalar($value)) {// short syntax: $fieldName => $xsdType
  61. $fieldName = $key;
  62. $field = [ 'name' => $fieldName, 'perms' => '', 'idZasob' => $generatedIdZasob ];
  63. $field['xsdType'] = $value;
  64. $this->_xsdTypes[$fieldName] = $field;
  65. } else {
  66. throw new Exception("StorageAcl - TODO: Unimplemented value type in simpleSchema: " . json_encode($value));
  67. }
  68. $generatedIdZasob++;
  69. }
  70. }
  71. // TODO: fix 'ref:*' types - use Core_AclHelper::parseNamespaceUrl($namespace)
  72. }
  73. public function getSimpleSchema() { return $this->_simpleSchema; }
  74. public function getName() { return $this->_name; }
  75. public function getRootTableName() { $this->_rootTableName; }
  76. public function getXsdTypes() { return $this->_xsdTypes; }
  77. public function getNamespace() { return 'default_db/' . $this->_rootTableName . '/' . $this->_name; }
  78. public function getSourceName() { return 'default_db__x3A__' . $this->_rootTableName; }
  79. public function init($force = false) {}
  80. public function isInitialized() { return true; }
  81. public function getFieldListByIdZasob() { return $this->getRealFieldListByIdZasob(); }
  82. public function getVisibleFieldListByIdZasob() { return $this->getRealFieldListByIdZasob(); }
  83. public function getVirtualFieldListByIdZasob() { return array(); }
  84. public function getRealFieldListByIdZasob($force = false) {
  85. $cols = array();
  86. foreach ($this->getFields() as $idField => $field) {
  87. $cols[$idField] = $field['name'];
  88. }
  89. return $cols;
  90. }
  91. public function getFields() {// @returns array - $this->_fields
  92. $fieldsById = array();
  93. foreach ($this->getXsdTypes() as $fieldName => $field) {
  94. $field['name'] = $fieldName;
  95. $fieldsById[ $field['idZasob'] ] = $field;
  96. }
  97. return $fieldsById;
  98. }
  99. public function getFieldType($fieldName) {
  100. foreach ($this->getFields() as $field) {
  101. if ($fieldName == $field['name']) return $field;
  102. }
  103. return null;
  104. }
  105. // TODO: replace legacy functions: isAllowed, hasFieldPerm, getFieldIdByName
  106. public function canCreateField($fieldName) {
  107. return false;// TODO: perms from Procesy
  108. }
  109. public function canReadField($fieldName) {
  110. return true;// TODO: perms from Procesy
  111. }
  112. public function canReadObjectField($fieldName, $record) {
  113. return true;// TODO: perms from Procesy
  114. }
  115. public function canWriteField($fieldName) {
  116. return false;// TODO: perms from Procesy
  117. }
  118. public function canWriteObjectField($fieldName, $record) {
  119. return false;// TODO: perms from Procesy
  120. }
  121. public function getTotal($params = array()) {// TODO: use ParseOgcQuery
  122. throw new Exception("Unimplemented - TODO: F." . __FUNCTION__);
  123. }
  124. public function getItem($primaryKey) {
  125. throw new Exception("Unimplemented - TODO: F." . __FUNCTION__);
  126. }
  127. public function getItems($params = array()) {// TODO: use ParseOgcQuery
  128. throw new Exception("Unimplemented - TODO: F." . __FUNCTION__);
  129. }
  130. public function fetchItemRef(&$items) {
  131. throw new Exception("Unimplemented - TODO: F." . __FUNCTION__);
  132. }
  133. public function addItem($itemTodo) {
  134. throw new Exception("Unimplemented - TODO: F." . __FUNCTION__);
  135. // return $this->parentAcl->addItem($itemTodo);
  136. }
  137. public function updateItem($itemPatch) {
  138. throw new Exception("Unimplemented - TODO: F." . __FUNCTION__);
  139. // return $this->parentAcl->updateItem($itemPatch);
  140. }
  141. public function getGeomFieldType($fieldName) { return null; }
  142. public function getPrimaryKeyField() { return 'ID'; }
  143. public function getID() { return 0; }
  144. public function getAttributesFromZasoby() { return array(); }
  145. public function isEnumerationField($fieldName) { return false; }
  146. public function getEnumerations($fieldName) { return null; }
  147. public function getXsdFieldType($fieldName) {
  148. $xsdTypes = $this->getXsdTypes();
  149. if (empty($xsdTypes[$fieldName])) throw new Exception("Field '{$fieldName}' not exists");
  150. return $xsdTypes[$fieldName]['xsdType'];
  151. }
  152. public function isGeomField($fldName) {
  153. if ('File' == $fieldName) return false;
  154. if ('AccessGroupRead' == $fieldName) return false;
  155. if ('AccessGroupWrite' == $fieldName) return false;
  156. if ('AccessOwner' == $fieldName) return false;
  157. // if ('NestedObjectTest' == $fieldName) return false;
  158. // return $this->parentAcl->isGeomField($fldName);
  159. }
  160. }