AccessGroupStorageAcl.php 4.3 KB

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