eZ\Publish\Core\Limitation\ParentOwnerLimitationType::evaluate PHP Метод

evaluate() публичный Метод

Evaluate permission against content & target(placement/parent/assignment).
public evaluate ( eZ\Publish\API\Repository\Values\User\Limitation $value, eZ\Publish\API\Repository\Values\User\UserReference $currentUser, eZ\Publish\API\Repository\Values\ValueObject $object, array $targets = null ) : boolean
$value eZ\Publish\API\Repository\Values\User\Limitation
$currentUser eZ\Publish\API\Repository\Values\User\UserReference
$object eZ\Publish\API\Repository\Values\ValueObject
$targets array The context of the $object, like Location of Content, if null none where provided by caller
Результат boolean
    public function evaluate(APILimitationValue $value, APIUserReference $currentUser, ValueObject $object, array $targets = null)
    {
        if (!$value instanceof APIParentOwnerLimitation) {
            throw new InvalidArgumentException('$value', 'Must be of type: APIParentOwnerLimitation');
        }
        if ($value->limitationValues[0] != 1 && $value->limitationValues[0] != 2) {
            throw new BadStateException('Parent Owner limitation', 'expected limitation value to be 1 or 2 but got:' . $value->limitationValues[0]);
        }
        // Parent Limitations are usually used by content/create where target is specified, so we return false if not provided.
        if (empty($targets)) {
            return false;
        }
        foreach ($targets as $target) {
            if ($target instanceof LocationCreateStruct) {
                $target = $this->persistence->locationHandler()->load($target->parentLocationId);
            }
            if ($target instanceof Location) {
                $targetContentInfo = $target->getContentInfo();
            } elseif ($target instanceof SPILocation) {
                $targetContentInfo = $this->persistence->contentHandler()->loadContentInfo($target->contentId);
            } else {
                throw new InvalidArgumentException('$targets', 'Must contain objects of type: Location or LocationCreateStruct');
            }
            $userId = $currentUser->getUserId();
            $isOwner = $targetContentInfo->ownerId === $userId;
            $isSelf = $targetContentInfo->id === $userId;
            if (!($isOwner || $isSelf)) {
                return false;
            }
        }
        return true;
    }