/**
     * @param bool $allRelations
     * @return int
     */
    static function relationTypeMask( $allRelations = false )
    {
        $relationTypeMask = eZContentObject::RELATION_COMMON |
                            eZContentObject::RELATION_EMBED;

        if ( eZContentObject::isObjectRelationTyped() )
        {
            $relationTypeMask |= eZContentObject::RELATION_LINK;
        }

        if ( $allRelations )
        {
            $relationTypeMask |= eZContentObject::RELATION_ATTRIBUTE;
        }

        return $relationTypeMask;
    }
 public static function fetchReverseRelatedObjectsID($objectID, $attributeID, $allRelations)
 {
     if (!is_array($allRelations) || $allRelations === array()) {
         $allRelations = array('common', 'xml_embed', 'attribute');
         if (eZContentObject::isObjectRelationTyped()) {
             $allRelations[] = 'xml_link';
         }
     }
     $relatedObjectsTyped = array();
     foreach ($allRelations as $relationType) {
         $relatedObjectsTyped[$relationType] = eZContentFunctionCollection::fetchReverseRelatedObjects($objectID, $attributeID, array($relationType), false, array(), null);
     }
     $relatedObjectsTypedIDArray = array();
     foreach ($relatedObjectsTyped as $relationTypeName => $relatedObjectsByType) {
         $relatedObjectsTypedIDArray[$relationTypeName] = array();
         foreach ($relatedObjectsByType['result'] as $relatedObjectByType) {
             $relatedObjectsTypedIDArray[$relationTypeName][] = $relatedObjectByType->ID;
         }
     }
     return array('result' => $relatedObjectsTypedIDArray);
 }
function handleRelationTemplate($module, $class, $object, $version, $contentObjectAttributes, $editVersion, $editLanguage, $tpl)
{
    $relatedObjects = $object->relatedContentObjectArray($editVersion);
    $tpl->setVariable('related_contentobjects', $relatedObjects);
    $relatedObjectsTyped = array();
    $relatedObjectsTyped['common'] = $object->relatedContentObjectArray($editVersion, false, 0, array('AllRelations' => eZContentObject::RELATION_COMMON));
    $relatedObjectsTyped['xml_embed'] = $object->relatedContentObjectArray($editVersion, false, 0, array('AllRelations' => eZContentObject::RELATION_EMBED));
    if (eZContentObject::isObjectRelationTyped()) {
        $relatedObjectsTyped['xml_link'] = $object->relatedContentObjectArray($editVersion, false, 0, array('AllRelations' => eZContentObject::RELATION_LINK));
    }
    $relatedObjectsTypedIDArray = array();
    foreach ($relatedObjectsTyped as $relationTypeName => $relatedObjectsByType) {
        $relatedObjectsTypedIDArray[$relationTypeName] = array();
        foreach ($relatedObjectsByType as $relatedObjectByType) {
            $relatedObjectsTypedIDArray[$relationTypeName][] = $relatedObjectByType->ID;
        }
    }
    unset($relatedObjectsTyped);
    $ini = eZINI::instance('content.ini');
    $groups = $ini->variable('RelationGroupSettings', 'Groups');
    $defaultGroup = $ini->variable('RelationGroupSettings', 'DefaultGroup');
    $groupedRelatedObjects = array();
    $groupClassLists = array();
    $classGroupMap = array();
    foreach ($groups as $groupName) {
        $groupedRelatedObjects[$groupName] = array();
        $setting = strtoupper($groupName[0]) . substr($groupName, 1) . 'ClassList';
        $groupClassLists[$groupName] = $ini->variable('RelationGroupSettings', $setting);
        foreach ($groupClassLists[$groupName] as $classIdentifier) {
            $classGroupMap[$classIdentifier] = $groupName;
        }
    }
    $groupedRelatedObjects[$defaultGroup] = array();
    foreach ($relatedObjects as $relatedObjectKey => $relatedObject) {
        $classIdentifier = $relatedObject->attribute('class_identifier');
        if (isset($classGroupMap[$classIdentifier])) {
            $groupName = $classGroupMap[$classIdentifier];
            $groupedRelatedObjects[$groupName][] = $relatedObjects[$relatedObjectKey];
        } else {
            $groupedRelatedObjects[$defaultGroup][] = $relatedObjects[$relatedObjectKey];
        }
    }
    $tpl->setVariable('related_contentobjects', $relatedObjects);
    $tpl->setVariable('related_contentobjects_id', $relatedObjectsTypedIDArray);
    $tpl->setVariable('grouped_related_contentobjects', $groupedRelatedObjects);
}