FileStorageAcl.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <?php
  2. Lib::loadClass('FileStorage');
  3. class FileStorageAcl {
  4. public function __construct() {
  5. }
  6. public function init($force = false) {}
  7. public function isInitialized() { return true; }
  8. public function getRealFieldListByIdZasob($force = false) {
  9. $cols = array();// FileStorage::getFileById()
  10. $cols[1] = 'id';
  11. $cols[2] = 'name';
  12. $cols[3] = 'size';
  13. $cols[4] = 'mimeType';
  14. $cols[5] = 'version';
  15. $cols[6] = 'content';
  16. // $cols[] = 'relativePath';
  17. // $cols[] = 'absolutePath';
  18. // $cols[] = 'exists';
  19. return $cols;
  20. }
  21. public function isIntegerField($fieldName) {
  22. if ('id' == $fieldName) return true;
  23. if ('size' == $fieldName) return true;
  24. if ('version' == $fieldName) return true;
  25. return false;
  26. }
  27. public function isDecimalField($fieldName) { return false; }
  28. public function isGeomField($fldName) { return false; }
  29. public function isDateField($fldName) { return false; }
  30. public function isDateTimeField($fldName) { return false; }
  31. public function isStringField($fieldName) {
  32. if ('name' == $fieldName) return true;
  33. if ('mimeType' == $fieldName) return true;
  34. return false;
  35. }
  36. public function isTextField($fldName) { return false; }
  37. public function isBinaryField($fieldName) {
  38. if ('content' == $fieldName) return true;
  39. return false;
  40. }
  41. public function isEnumerationField($fldName) { return false; }
  42. public function getFieldType($colName) {
  43. switch ($colName) {
  44. case 'id': return array(); break;
  45. }
  46. return null;
  47. }
  48. public function isAllowed($idZasob, $taskPerm, $record = null) {
  49. if ('C' == $taskPerm && $idZasob > 1 && $idZasob < 7) return true;
  50. if ('R' == $taskPerm && $idZasob > 0 && $idZasob < 7) return true;
  51. return false;
  52. }
  53. public function hasFieldPerm($idZasob, $taskPerm) {
  54. if ('C' == $taskPerm && $idZasob > 1 && $idZasob < 7) return true;
  55. if ('R' == $taskPerm && $idZasob > 0 && $idZasob < 7) return true;
  56. return false;
  57. }
  58. public function getItems($params = array()) {
  59. $sqlLimit = V::get('limit', 10000, $params);
  60. $sqlOffset = V::get('limitstart', 0, $params);
  61. // TODO: parse params:
  62. // [sortBy] => ID D,test_date A
  63. // [cols] => Array( [0] => ID
  64. // [1] => test_date
  65. // [2] => A_STATUS )
  66. $sqlTblName = FileStorage::getTableName();
  67. $sqlUserLogin = User::getLogin();
  68. $rows = array_map(function($row) {
  69. $wfsItem = array();
  70. $wfsItem['id'] = $row['ID'];
  71. $wfsItem['name'] = V::get('FILE_LABEL', $row['ID'], $row);
  72. $wfsItem['size'] = $row['FILE_SIZE'];
  73. $wfsItem['mimeType'] = $row['FILE_MIME_TYPE'];
  74. $wfsItem['version'] = $row['FILE_VERSION'];
  75. {// fetch file content
  76. $objectFile = FileStorage::getFileById($row['ID']);// TODO: avoid sql in FileStorage::convertFromDBRow($row)
  77. $wfsItem['content'] = ($objectFile['exists']) ? base64_encode(file_get_contents($objectFile['absolutePath'])) : null;
  78. }
  79. return $wfsItem;
  80. }, DB::getPDO()->fetchAll("
  81. select t.ID
  82. , t.FILE_HASH
  83. , t.FILE_LABEL
  84. , t.FILE_TYPE
  85. , t.FILE_MIME_TYPE
  86. , t.FILE_MTIME
  87. , t.FILE_SIZE
  88. , t.FILE_VERSION
  89. , t.A_STATUS
  90. , t.A_RECORD_CREATE_DATE
  91. , t.A_RECORD_CREATE_AUTHOR
  92. , t.A_RECORD_UPDATE_DATE
  93. , t.A_RECORD_UPDATE_AUTHOR
  94. , t.A_ADM_COMPANY
  95. , t.A_CLASSIFIED
  96. , INET_NTOA(t.A_USER_IP) as IP
  97. from `{$sqlTblName}` t
  98. where t.`A_RECORD_CREATE_AUTHOR` = '{$sqlUserLogin}'
  99. order by ID DESC
  100. limit {$sqlLimit} offset {$sqlOffset}
  101. "));
  102. $items = array();
  103. foreach ($rows as $row) {
  104. $items[$row['id']] = (object)$row;
  105. }
  106. return $items;
  107. }
  108. public function getPrimaryKeyField() { return 'id'; }
  109. public function getID() { return 0; }
  110. public function getAttributesFromZasoby() {
  111. $attributes = array();// fldName => [ 'id_zasob' => int, 'label' => str, 'description' => str ]
  112. // if ($acl->hasFieldPerm($idZasob, 'W')) $elNode->setAttributeNS($rootWfsNsUri, "{$rootWfsNs}:allow_write", "true");
  113. // if ($acl->hasFieldPerm($idZasob, 'C')) $elNode->setAttributeNS($rootWfsNsUri, "{$rootWfsNs}:allow_create", "true");
  114. // if (!$acl->hasFieldPerm($idZasob, 'R')) $elNode->setAttributeNS($rootWfsNsUri, "{$rootWfsNs}:allow_read", "false");
  115. return $attributes;
  116. }
  117. }