AccessGroupStorageAcl.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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 getTotal($params = array()) {
  31. return count($this->getItems($params));
  32. }
  33. public function getItem($primaryKey) {
  34. $items = $this->getItems(['primaryKey'=>$primaryKey]);
  35. return (!empty($items[$primaryKey])) ? $items[$primaryKey] : null;
  36. }
  37. public function getItems($params = array()) {
  38. $DBG = V::get('DBG_DS', 0, $_GET, 'int');
  39. if($DBG>2){echo 'C.'.get_class($this).' L.' . __LINE__ . " getItems \$params:";print_r($params);echo "\n";}
  40. $items = array();
  41. // TODO: fetch groups connectes with current user
  42. {
  43. $userLdapGroups = UsersHelper::getLDAPGroupByUserName(User::getLogin());
  44. if($DBG>4){echo 'C.'.get_class($this).' L.' . __LINE__ . " getItems \$userLdapGroups:";print_r($userLdapGroups);echo "\n";}
  45. if (empty($userLdapGroups)) throw new Exception("User groups not found", 404);
  46. foreach ($userLdapGroups as $vLdapGroup) {
  47. $allowGroup = false;
  48. if ('workgroup' == $vLdapGroup->cn) {
  49. $items[1] = ['id'=>'0', 'name'=>$vLdapGroup->name, 'uid'=>$vLdapGroup->cn];
  50. } else {
  51. $cnTest = str_replace('-', '_', $vLdapGroup->cn);
  52. $cnTest = explode('_', $cnTest);
  53. $idZasob = $cnTest[0];
  54. if (!is_numeric($idZasob)) {
  55. if($DBG>2){echo 'C.'.get_class($this).' L.' . __LINE__ . " getItems - skip cn - missing id zasob \$vLdapGroup->cn:";print_r($vLdapGroup->cn);echo "\n";}
  56. continue;
  57. }
  58. $items[$idZasob] = ['id'=>$idZasob, 'name'=>$vLdapGroup->name, 'uid'=>$vLdapGroup->cn];
  59. }
  60. }
  61. }
  62. if ($pk = V::get('primaryKey', '', $params, 'int')) {// [primaryKey] => 2948
  63. if (!array_key_exists($pk, $items)) return array();
  64. $items = array($pk => $items[$pk]);
  65. }
  66. if (!empty($params['ogc:Filter'])) {
  67. $parser = new ParseOgcFilter();
  68. $parser->loadOgcFilter($params['ogc:Filter']);
  69. $queryWhereBuilder = $parser->convertToSqlQueryWhereBuilder();
  70. DBG::_('DBG_DS', '>2', "ogc:Filter \$queryWhereBuilder", $queryWhereBuilder, __CLASS__, __FUNCTION__, __LINE__);
  71. if($DBG>2){echo 'C.'.get_class($this).' L.' . __LINE__ . " getItems \$items:";print_r($items);echo "\n";}
  72. $items = array_filter($items, array($queryWhereBuilder, 'filterRawArray'));
  73. }
  74. if($DBG>2){echo 'C.'.get_class($this).' L.' . __LINE__ . " getItems \$items:";print_r($items);echo "\n";}
  75. return $items;
  76. }
  77. public function addItem($itemTodo) { throw new Exception("Insert not allowed"); }
  78. public function updateItem($itemPatch) { throw new Exception("Update not allowed"); }
  79. public function getGeomFieldType($fieldName) { return null; }
  80. public function getPrimaryKeyField() { return 'id'; }
  81. public function getID() { return 0; }
  82. public function getAttributesFromZasoby() { return array(); }
  83. public function isEnumerationField($fieldName) { return false; }
  84. public function getEnumerations($fieldName) { return null; }
  85. public function getXsdFieldType($fieldName) {
  86. if ('id' == $fieldName) return 'xsd:string';
  87. if ('name' == $fieldName) return 'xsd:string';
  88. if ('uid' == $fieldName) return 'xsd:string';
  89. }
  90. public function isGeomField($fldName) { return false; }
  91. }