AccessGroupStorageAcl.php 4.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. Lib::loadClass('Core_AclBase');
  3. Lib::loadClass('User');
  4. Lib::loadClass('UsersHelper');
  5. Lib::loadClass('ParseOgcFilter');
  6. class Schema_AccessGroupStorageAcl extends Core_AclBase {// Read only class
  7. public function getNamespace() { return 'default_objects/' . $this->getName(); }
  8. public function getSourceName() { return 'objects'; }
  9. public function init($force = false) {}
  10. public function isInitialized() { return true; }
  11. public function getName() { return 'AccessGroup'; }
  12. public function getRootTableName() { return 'CRM_LISTA_ZASOBOW'; }
  13. public function getFieldListByIdZasob() { return $this->getRealFieldListByIdZasob(); }
  14. public function getVisibleFieldListByIdZasob() { return $this->getRealFieldListByIdZasob(); }
  15. public function getVirtualFieldListByIdZasob() { return array(); }
  16. public function getRealFieldListByIdZasob($force = false) {
  17. $cols[100000] = 'id';// CRM_LISTA_ZASOBOW.ID
  18. $cols[100001] = 'name';// CRM_LISTA_ZASOBOW.DESC
  19. $cols[100002] = 'uid';// Ldap.uid -> value stored in fields: A_ADM_COMPANY, A_CLASSIFIED
  20. return $cols;
  21. }
  22. public function getFields() { return array_values($this->getRealFieldListByIdZasob()); }
  23. public function getFieldType($fieldName) { return null; }
  24. // TODO: replace legacy functions: isAllowed, hasFieldPerm, getFieldIdByName
  25. public function canCreateField($fieldName) { return false; }
  26. public function canReadField($fieldName) { return true; }
  27. public function canReadObjectField($fieldName, $record) {return true; }
  28. public function canWriteField($fieldName) { return false; }
  29. public function canWriteObjectField($fieldName, $record) { return false; }
  30. public function getItems($params = array()) {
  31. $DBG = V::get('DBG_DS', 0, $_GET, 'int');
  32. if($DBG>2){echo 'C.'.get_class($this).' L.' . __LINE__ . " getItems \$params:";print_r($params);echo "\n";}
  33. $items = array();
  34. // TODO: fetch groups connectes with current user
  35. {
  36. $userLdapGroups = UsersHelper::getLDAPGroupByUserName(User::getLogin());
  37. if($DBG>4){echo 'C.'.get_class($this).' L.' . __LINE__ . " getItems \$userLdapGroups:";print_r($userLdapGroups);echo "\n";}
  38. if (empty($userLdapGroups)) throw new Exception("User groups not found", 404);
  39. foreach ($userLdapGroups as $vLdapGroup) {
  40. $allowGroup = false;
  41. if ('workgroup' == $vLdapGroup->cn) {
  42. $items[1] = ['id'=>0, 'name'=>$vLdapGroup->name, 'uid'=>$vLdapGroup->cn];
  43. } else {
  44. $cnTest = str_replace('-', '_', $vLdapGroup->cn);
  45. $cnTest = explode('_', $cnTest);
  46. $idZasob = $cnTest[0];
  47. if (!is_numeric($idZasob)) {
  48. if($DBG>2){echo 'C.'.get_class($this).' L.' . __LINE__ . " getItems - skip cn - missing id zasob \$vLdapGroup->cn:";print_r($vLdapGroup->cn);echo "\n";}
  49. continue;
  50. }
  51. $items[$idZasob] = ['id'=>$idZasob, 'name'=>$vLdapGroup->name, 'uid'=>$vLdapGroup->cn];
  52. }
  53. }
  54. }
  55. if ($pk = V::get('primaryKey', '', $params, 'int')) {// [primaryKey] => 2948
  56. if (!array_key_exists($pk, $items)) return array();
  57. $items = array($pk => $items[$pk]);
  58. }
  59. if (!empty($params['ogc:Filter'])) {
  60. $parser = new ParseOgcFilter();
  61. $parser->loadOgcFilter($params['ogc:Filter']);
  62. $queryWhereBuilder = $parser->convertToSqlQueryWhereBuilder();
  63. DBG::_('DBG_DS', '>2', "ogc:Filter \$queryWhereBuilder", $queryWhereBuilder, __CLASS__, __FUNCTION__, __LINE__);
  64. if($DBG>2){echo 'C.'.get_class($this).' L.' . __LINE__ . " getItems \$items:";print_r($items);echo "\n";}
  65. $items = array_filter($items, array($queryWhereBuilder, 'filterRawArray'));
  66. }
  67. if($DBG>2){echo 'C.'.get_class($this).' L.' . __LINE__ . " getItems \$items:";print_r($items);echo "\n";}
  68. return $items;
  69. }
  70. public function addItem($itemTodo) { throw new Exception("Insert not allowed"); }
  71. public function updateItem($itemPatch) { throw new Exception("Update not allowed"); }
  72. public function getGeomFieldType($fieldName) { return null; }
  73. public function getPrimaryKeyField() { return 'id'; }
  74. public function getID() { return 0; }
  75. public function getAttributesFromZasoby() { return array(); }
  76. public function isEnumerationField($fieldName) { return false; }
  77. public function getEnumerations($fieldName) { return null; }
  78. public function getXsdFieldType($fieldName) {
  79. if ('id' == $fieldName) return 'xsd:string';
  80. if ('name' == $fieldName) return 'xsd:string';
  81. if ('uid' == $fieldName) return 'xsd:string';
  82. }
  83. public function isGeomField($fldName) { return false; }
  84. }