| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- <?php
- Lib::loadClass('FileStorage');
- class FileStorageAcl {
- public function __construct() {
- }
- public function init($force = false) {}
- public function isInitialized() { return true; }
- public function getRealFieldListByIdZasob($force = false) {
- $cols = array();// FileStorage::getFileById()
- $cols[1] = 'id';
- $cols[2] = 'name';
- $cols[3] = 'size';
- $cols[4] = 'mimeType';
- $cols[5] = 'version';
- $cols[6] = 'content';
- // $cols[] = 'relativePath';
- // $cols[] = 'absolutePath';
- // $cols[] = 'exists';
- return $cols;
- }
- public function isIntegerField($fieldName) {
- if ('id' == $fieldName) return true;
- if ('size' == $fieldName) return true;
- if ('version' == $fieldName) return true;
- return false;
- }
- public function isDecimalField($fieldName) { return false; }
- public function isGeomField($fldName) { return false; }
- public function isDateField($fldName) { return false; }
- public function isDateTimeField($fldName) { return false; }
- public function isStringField($fieldName) {
- if ('name' == $fieldName) return true;
- if ('mimeType' == $fieldName) return true;
- return false;
- }
- public function isTextField($fldName) { return false; }
- public function isBinaryField($fieldName) {
- if ('content' == $fieldName) return true;
- return false;
- }
- public function isEnumerationField($fldName) { return false; }
- public function getFieldType($colName) {
- switch ($colName) {
- case 'id': return array(); break;
- }
- return null;
- }
- public function isAllowed($idZasob, $taskPerm, $record = null) {
- if ('C' == $taskPerm && $idZasob > 1 && $idZasob < 7) return true;
- if ('R' == $taskPerm && $idZasob > 0 && $idZasob < 7) return true;
- return false;
- }
- public function hasFieldPerm($idZasob, $taskPerm) {
- if ('C' == $taskPerm && $idZasob > 1 && $idZasob < 7) return true;
- if ('R' == $taskPerm && $idZasob > 0 && $idZasob < 7) return true;
- return false;
- }
- public function getItems($params = array()) {
- $sqlLimit = V::get('limit', 10000, $params);
- $sqlOffset = V::get('limitstart', 0, $params);
- // TODO: parse params:
- // [sortBy] => ID D,test_date A
- // [cols] => Array( [0] => ID
- // [1] => test_date
- // [2] => A_STATUS )
- $sqlTblName = FileStorage::getTableName();
- $sqlUserLogin = User::getLogin();
- $rows = array_map(function($row) {
- $wfsItem = array();
- $wfsItem['id'] = $row['ID'];
- $wfsItem['name'] = V::get('FILE_LABEL', $row['ID'], $row);
- $wfsItem['size'] = $row['FILE_SIZE'];
- $wfsItem['mimeType'] = $row['FILE_MIME_TYPE'];
- $wfsItem['version'] = $row['FILE_VERSION'];
- {// fetch file content
- $objectFile = FileStorage::getFileById($row['ID']);// TODO: avoid sql in FileStorage::convertFromDBRow($row)
- $wfsItem['content'] = ($objectFile['exists']) ? base64_encode(file_get_contents($objectFile['absolutePath'])) : null;
- }
- return $wfsItem;
- }, DB::getPDO()->fetchAll("
- select t.ID
- , t.FILE_HASH
- , t.FILE_LABEL
- , t.FILE_TYPE
- , t.FILE_MIME_TYPE
- , t.FILE_MTIME
- , t.FILE_SIZE
- , t.FILE_VERSION
- , t.A_STATUS
- , t.A_RECORD_CREATE_DATE
- , t.A_RECORD_CREATE_AUTHOR
- , t.A_RECORD_UPDATE_DATE
- , t.A_RECORD_UPDATE_AUTHOR
- , t.A_ADM_COMPANY
- , t.A_CLASSIFIED
- , INET_NTOA(t.A_USER_IP) as IP
- from `{$sqlTblName}` t
- where t.`A_RECORD_CREATE_AUTHOR` = '{$sqlUserLogin}'
- order by ID DESC
- limit {$sqlLimit} offset {$sqlOffset}
- "));
- $items = array();
- foreach ($rows as $row) {
- $items[$row['id']] = (object)$row;
- }
- return $items;
- }
- public function getPrimaryKeyField() { return 'id'; }
- public function getID() { return 0; }
- public function getAttributesFromZasoby() {
- $attributes = array();// fldName => [ 'id_zasob' => int, 'label' => str, 'description' => str ]
- // if ($acl->hasFieldPerm($idZasob, 'W')) $elNode->setAttributeNS($rootWfsNsUri, "{$rootWfsNs}:allow_write", "true");
- // if ($acl->hasFieldPerm($idZasob, 'C')) $elNode->setAttributeNS($rootWfsNsUri, "{$rootWfsNs}:allow_create", "true");
- // if (!$acl->hasFieldPerm($idZasob, 'R')) $elNode->setAttributeNS($rootWfsNsUri, "{$rootWfsNs}:allow_read", "false");
- return $attributes;
- }
- }
|