public function getAllSubResources(ResourceInterface $project) { if (!$project instanceof Project) { throw new \RuntimeException(); } return $project->getItems(); }
/** * {@inheritdoc} */ public function getAllSubResources(ResourceInterface $resource) { if (!$resource instanceof CascadingResource) { return []; } $subResources = []; foreach ($resource->getSubResources($this->entityManager) as $subResource) { $subResources[] = $subResource; // Recursively get its sub-resources $subResources = array_merge($subResources, $this->parentTraverser->getAllSubResources($subResource)); } return $this->unique($subResources); }
/** * Remove all the authorizations that apply to the given resource. * * @param ResourceInterface $resource * @throws \RuntimeException If the resource is an entity, it must be persisted. */ public function removeAuthorizationsForResource(ResourceInterface $resource) { $qb = $this->_em->createQueryBuilder(); $qb->delete($this->getEntityName(), 'a'); if ($resource instanceof EntityResource) { if ($resource->getId() === null) { throw new \RuntimeException(sprintf('The entity resource %s must be persisted (id not null) to be able to remove the authorizations', ClassUtils::getClass($resource))); } $qb->andWhere('a.entityClass = :entityClass'); $qb->andWhere('a.entityId = :entityId'); $qb->setParameter('entityClass', ClassUtils::getClass($resource)); $qb->setParameter('entityId', $resource->getId()); } if ($resource instanceof ClassResource) { $qb->andWhere('a.entityClass = :entityClass'); $qb->andWhere('a.entityId IS NULL'); $qb->setParameter('entityClass', $resource->getClass()); } $qb->getQuery()->execute(); }