示例#1
0
    /**
     * @param integer $id
     * @return bool
     * @throws ModelNotFoundException
     * @throws UnauthorizedException
     * @throws ServiceException
     */
    public function delete($id)
    {
        $facility = $this->find($id);

        if (!$this->resourcePermissionService->isAllowedToFacility($facility, 'delete')) {
            throw new UnauthorizedException(
                sprintf('Not authorized to delete facility with identifier %d', $facility->getId())
            );
        }

        try {
            $this->facilityRepository->remove($facility);
            return true;
        } catch (RepositoryException $e) {
            throw new ServiceException(
                sprintf('Failed to delete facility with identifier %d', $facility->getId()),
                0,
                $e
            );
        }
    }
示例#2
0
    /**
     * @param array|Traversable|stdClass $data
     * @return Court
     * @throws ModelNotFoundException
     * @throws UnauthorizedException
     * @throws ServiceException
     */
    public function populate($data)
    {
        /** @var  $inputFilter */
        $inputFilter = $this->getPopulateInputFilter($data);
        if (!$inputFilter->isValid()) {
            throw new InvalidInputException(
                'Unable to update court because of invalid input',
                0,
                null,
                $inputFilter->getMessages()
            );
        }

        /** @var Court $court */
        $court = $this->baseHydrator->hydrate($inputFilter->getValues(), $this->courtRepository->find($inputFilter->getValue('id')));

        if (!$this->resourcePermissionService->isAllowedToCourt($court, 'update')) {
            throw new UnauthorizedException(
                sprintf('Not authorized to update court with identifier %d', $court->getId())
            );
        }

        return $court;
    }