eZ\Publish\Core\Limitation\SectionLimitationType::evaluate PHP Method

evaluate() public method

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
return boolean
    public function evaluate(APILimitationValue $value, APIUserReference $currentUser, ValueObject $object, array $targets = null)
    {
        if (!$value instanceof APISectionLimitation) {
            throw new InvalidArgumentException('$value', 'Must be of type: APISectionLimitation');
        }
        if (empty($value->limitationValues)) {
            return false;
        }
        /**
         * Two cases supported:
         * 1. $object is Section, for possible future support on Section limitations, i.e. be able to limit section/edit
         * 2. $object is Content[Info]/VersionInfo, for all existing content policies, to limit by Section.
         */
        if ($object instanceof Section) {
            return in_array($object->id, $value->limitationValues);
        } elseif ($object instanceof Content) {
            $object = $object->getVersionInfo()->getContentInfo();
        } elseif ($object instanceof VersionInfo) {
            $object = $object->getContentInfo();
        } elseif (!$object instanceof ContentInfo && !$object instanceof ContentCreateStruct) {
            // As this is Role limitation we need to signal abstain on unsupported $object
            return self::ACCESS_ABSTAIN;
        }
        /*
         * We ignore Targets here, they are only interesting in NewState limitation as we on this one is more interested
         * the section already assigned to object.
         *
         * @var $object ContentInfo|ContentCreateStruct
         */
        return in_array($object->sectionId, $value->limitationValues);
    }