public function evaluate(APILimitationValue $value, APIUserReference $currentUser, ValueObject $object, array $targets = null)
{
if (!$value instanceof APIObjectStateLimitation) {
throw new InvalidArgumentException('$value', 'Must be of type: APIObjectStateLimitation');
}
if ($object instanceof Content) {
$object = $object->getVersionInfo()->getContentInfo();
} elseif ($object instanceof VersionInfo) {
$object = $object->getContentInfo();
} elseif (!$object instanceof ContentInfo && !$object instanceof ContentCreateStruct) {
throw new InvalidArgumentException('$object', 'Must be of type: Content, VersionInfo or ContentInfo');
}
if (empty($value->limitationValues)) {
return false;
}
$objectStateIdArray = array();
$objectStateHandler = $this->persistence->objectStateHandler();
$stateGroups = $objectStateHandler->loadAllGroups();
// First deal with unpublished content
if ($object instanceof ContentCreateStruct || !$object->published) {
foreach ($stateGroups as $stateGroup) {
$states = $objectStateHandler->loadObjectStates($stateGroup->id);
if (empty($states)) {
continue;
}
$defaultStateId = null;
$defaultStatePriority = -1;
foreach ($states as $state) {
if ($state->priority > $defaultStatePriority) {
$defaultStateId = $state->id;
$defaultStatePriority = $state->priority;
}
}
if ($defaultStateId === null) {
throw new BadStateException('$defaultStateId', "Could not find a default state for object state group {$stateGroup->id}");
}
$objectStateIdArray[] = $defaultStateId;
}
} else {
/*
* @var $object ContentInfo
*/
foreach ($stateGroups as $stateGroup) {
$objectStateIdArray[] = $objectStateHandler->getContentState($object->id, $stateGroup->id)->id;
}
}
$intersect = array_intersect($value->limitationValues, $objectStateIdArray);
return !empty($intersect);
}