public function evaluate(APILimitationValue $value, APIUserReference $currentUser, ValueObject $object, array $targets = null)
{
if (!$value instanceof APIParentContentTypeLimitation) {
throw new InvalidArgumentException('$value', 'Must be of type: APIParentContentTypeLimitation');
}
if ($object instanceof ContentCreateStruct) {
return $this->evaluateForContentCreateStruct($value, $targets);
} elseif ($object instanceof Content) {
$object = $object->getVersionInfo()->getContentInfo();
} elseif ($object instanceof VersionInfo) {
$object = $object->getContentInfo();
} elseif (!$object instanceof ContentInfo) {
throw new InvalidArgumentException('$object', 'Must be of type: ContentCreateStruct, Content, VersionInfo or ContentInfo');
}
// Try to load locations if no targets were provided
if (empty($targets)) {
if ($object->published) {
$targets = $this->persistence->locationHandler()->loadLocationsByContent($object->id);
} else {
// @todo Need support for draft locations to to work correctly
$targets = $this->persistence->locationHandler()->loadParentLocationsForDraftContent($object->id);
}
}
// If targets is empty/null return false as user does not have access
// to content w/o location with this limitation
if (empty($targets)) {
return false;
}
foreach ($targets as $target) {
if ($target instanceof LocationCreateStruct) {
$target = $this->persistence->locationHandler()->load($target->parentLocationId);
}
if ($target instanceof Location) {
$contentTypeId = $target->getContentInfo()->contentTypeId;
} elseif ($target instanceof SPILocation) {
$spiContentInfo = $this->persistence->contentHandler()->loadContentInfo($target->contentId);
$contentTypeId = $spiContentInfo->contentTypeId;
} else {
throw new InvalidArgumentException('$targets', 'Must contain objects of type: Location or LocationCreateStruct');
}
if (!in_array($contentTypeId, $value->limitationValues)) {
return false;
}
}
return true;
}