/** * Performs a query for a single content object * * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException if the object was not found by the query or due to permissions * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if criterion is not valid * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if there is more than one result matching the criterions * * @todo define structs for the field filters * @param \eZ\Publish\API\Repository\Values\Content\Query\Criterion $filter * @param array $fieldFilters - a map of filters for the returned fields. * Currently supported: <code>array("languages" => array(<language1>,..))</code>. * @param boolean $filterOnUserPermissions if true only the objects which is the user allowed to read are returned. * * @return \eZ\Publish\API\Repository\Values\Content\Content */ public function findSingle(Criterion $filter, array $fieldFilters = array(), $filterOnUserPermissions = true) { $this->validateContentCriteria(array($filter), "\$filter"); if ($filterOnUserPermissions && !$this->permissionsCriterionHandler->addPermissionsCriterion($filter)) { throw new NotFoundException('Content', '*'); } return $this->domainMapper->buildContentDomainObject($this->searchHandler->findSingle($filter, $fieldFilters)); }
/** * Performs a query for a single content object * * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException if the object was not found by the query or due to permissions * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if criterion is not valid * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if there is more than one result matching the criterions * * @todo define structs for the field filters * @param \eZ\Publish\API\Repository\Values\Content\Query\Criterion $filter * @param array $fieldFilters - a map of filters for the returned fields. * Currently supports: <code>array("languages" => array(<language1>,..), "useAlwaysAvailable" => bool)</code> * useAlwaysAvailable defaults to true to avoid exceptions on missing translations. * @param boolean $filterOnUserPermissions if true only the objects which is the user allowed to read are returned. * * @return \eZ\Publish\API\Repository\Values\Content\Content */ public function findSingle(Criterion $filter, array $fieldFilters = array(), $filterOnUserPermissions = true) { $this->validateContentCriteria(array($filter), "\$filter"); if ($filterOnUserPermissions && !$this->permissionsCriterionHandler->addPermissionsCriterion($filter)) { throw new NotFoundException('Content', '*'); } $contentInfo = $this->searchHandler->findSingle($filter, $fieldFilters); return $this->repository->getContentService()->loadContent($contentInfo->id, !empty($fieldFilters['languages']) ? $fieldFilters['languages'] : null, null, isset($fieldFilters['useAlwaysAvailable']) ? $fieldFilters['useAlwaysAvailable'] : true); }