/** * Get a condition object for item listings. * * @param string $objectKey * * @return Condition */ public function getListingCondition($objectKey) { $objectKey = Objects::normalizeObjectKey($objectKey); $obj = $this->objects->getStorageController($objectKey); $rules = self::getRules($objectKey, static::MODE_LISTING); if (count($rules) === 0) { return null; } if ($this->getCaching()) { $cacheKey = md5($objectKey); $cached = $this->cacher->getDistributedCache('core/acl/listing/' . $cacheKey); if (null !== $cached) { return $cached; } } $condition = ''; $primaryList = $this->objects->getPrimaryList($objectKey); $primaryKey = current($primaryList); $denyList = array(); $conditionObject = new Condition(null, $this->jarves); foreach ($rules as $rule) { if ($rule['constraint_type'] === ACL::CONSTRAINT_EXACT) { //todo $rule['constraint_code'] can be a (urlencoded) composite pk //todo constraint_code is always urlencoded; $condition = Condition::create(array($primaryKey, '=', Tools::urlDecode($rule['constraint_code'])), $this->jarves); } if ($rule['constraint_type'] === ACL::CONSTRAINT_CONDITION) { $condition = Condition::create($rule['constraint_code'], $this->jarves); } if ($rule['constraint_type'] === ACL::CONSTRAINT_ALL) { $condition = array('1', '=', '1'); } elseif ($rule['sub']) { $subCondition = $obj->getNestedSubCondition($condition); if ($subCondition) { $condition = array($condition, 'OR', $subCondition); } } if ($rule['access'] === 1) { if ($denyList) { $condition = array($condition, 'AND NOT', $denyList); $conditionObject->addOr($condition); // $conditionObject->add('AND NOT', $denyList); } else { $conditionObject->addOr($condition); } } if ($rule['access'] !== 1) { if ($denyList) { $denyList[] = 'AND NOT'; } $denyList[] = $condition; } } if (!$conditionObject->hasRules()) { $conditionObject->addAnd(array('1', '!=', '1')); } if ($this->getCaching()) { $cacheKey = md5($objectKey); $this->cacher->setDistributedCache('core/acl/listing/' . $cacheKey, $conditionObject); } return $conditionObject; }
/** * {@inheritDoc} */ public function getBranch($pk = null, Condition $condition = null, $depth = 1, $scope = null, $options = null) { if ($pk) { $path = $this->getPathFromPK($pk); } else { $path = '/'; } if ($depth === null) { $depth = 1; } try { $files = $this->webFilesystem->getFiles($path); } catch (NotADirectoryException $e) { return null; } $c = 0; // $offset = $options['offset']; // $limit = $options['limit']; $result = array(); $blacklistedFiles = array(); $showHiddenFiles = false; //todo foreach ($files as $file) { $file = $file->toArray(); if (isset($blacklistedFiles[$file['path']]) | (!$showHiddenFiles && substr($file['name'], 0, 1) == '.')) { continue; } if ($condition && $condition->hasRules() && !$condition->satisfy($file, 'jarves/file')) { continue; } $file['writeAccess'] = $this->acl->isUpdatable('jarves/file', array('path' => $file['path'])); $c++; // if ($offset && $offset >= $c) { // continue; // } // if ($limit && $limit < $c) { // break; // } if ($depth > 0) { $children = array(); if ($file['type'] == 'dir') { try { $children = self::getBranch(array('path' => $file['path']), $condition, $depth - 1); } catch (FileNotFoundException $e) { $children = null; } } $file['_childrenCount'] = count($children); if ($depth > 1 && $file['type'] == 'dir') { $file['_children'] = $children; } } $result[] = $file; } return $result; }
/** * @param string $join * @param array|Condition $condition */ public function merge($join, $condition) { if (!$condition || $condition instanceof Condition && !$condition->hasRules()) { return; } if (0 < count($this->rules)) { $this->rules = array($this->rules, $join, $this->normalizeToArray($condition)); } else { $this->rules = $this->normalizeToArray($condition); } }
/** * {@inheritDoc} */ public function getBranch($pk = null, Condition $condition = null, $depth = 1, $scope = null, $options = null) { $result = null; $path = $pk['path']; if ($depth === null) { $depth = 1; } if ($path) { $path = '@' . trim($path, '/@'); $path = str_replace(':', '/', $path); } $c = 0; $offset = $options['offset']; $limit = $options['limit']; $result = array(); if (!$path) { $result = array(); $bundles = array_keys($this->jarves->getBundles()); foreach ($bundles as $bundleName) { $directory = $this->jarves->resolvePath('@' . $bundleName, 'Resources/views', true); if (!$this->localFilesystem->has($directory)) { continue; } $file = $this->localFilesystem->getFile($directory); if (!$file) { $result[] = $directory; continue; } $file = $file->toArray(); $file['name'] = $bundleName; $file['path'] = $bundleName; if ($offset && $offset > $c) { continue; } if ($limit && $limit < $c) { continue; } if ($condition && $condition->hasRules() && !$this->conditionOperator->satisfy($condition, $file)) { $result[] = $directory; continue; } $c++; if ($depth > 0) { $children = self::getBranch(array('path' => $bundleName), $condition, $depth - 1); $file['_childrenCount'] = count($children); if ($depth > 1 && $file['type'] == 'dir') { $file['_children'] = $children; } } } } else { if (!($bundleName = $this->jarves->getBundleFromPath($path))) { return []; } $directory = $this->jarves->resolvePath($path, 'Resources/views', true) . '/'; if (!$this->localFilesystem->has($directory)) { return []; } $files = $this->localFilesystem->getFiles($directory); foreach ($files as $file) { $item = $file->toArray(); if ($condition && $condition->hasRules() && !$this->conditionOperator->satisfy($condition, $item, 'jarves/file')) { continue; } $c++; if ($offset && $offset >= $c) { continue; } if ($limit && $limit < $c) { continue; } $item = array('name' => $this->buildPath($path . '/' . Tools::getRelativePath($item['path'], $directory)), 'path' => $this->buildPath($path . '/' . Tools::getRelativePath($item['path'], $directory))); if ($file->isDir()) { $children = self::getBranch(array('path' => $item['path']), $condition, $depth - 1); foreach ($children as $child) { // $child['name'] = $item['name'] . '/' . $child['name']; $result[] = $child; } } if ($file->isFile()) { $result[] = $item; } } } return $result; }