/** * @param int|null $nodeId * * @return bool */ public function isEditMode($nodeId = null) { $request = $this->requestStack->getMasterRequest(); $hasRequest = !!$request; if ($nodeId) { return $hasRequest && 1 === (int) $request->get('_jarves_editor') && $this->acl->isUpdatable('jarves/node', ['id' => $nodeId]); } return $hasRequest && 1 === (int) $request->get('_jarves_editor') && $this->pageStack->getCurrentPage() && $this->acl->isUpdatable('jarves/node', ['id' => $this->pageStack->getCurrentPage()->getId()]); }
/** * {@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; }
/** * Each item goes through this function in getItems(). Defines whether a item is editable or deleteable. * You can attach here extra action icons, too. * * Result should be: * * $item['_editable'] = true|false * $item['_deleteable'] = true|false * $item['_actions'] = array( * array('/* action * /') //todo * ) * ) * * @param array $item * * @return array */ public function prepareRow(&$item) { $item['_editable'] = $this->acl->isUpdatable($this->getObject(), $item); $item['_deletable'] = $this->acl->isDeletable($this->getObject(), $item); }