eZ Community » Forums » Developer » assignToUser in content edit handler...
expandshrink

assignToUser in content edit handler not working

assignToUser in content edit handler not working

Thursday 05 July 2012 5:16:31 pm

hi all,

I have started a custom edit handler in order to set up groups as seen in ezteamroom, thus creating 2 objects user_group beneath the contentobject and assigning roles to it. I have been folllowing the references of 

http://serwatka.net/en/blog/ez_publish_3_8_new_custom_edit_handler

http://share.ez.no/forums/developer/roles-user-sections-urgent#comment43114

and contentobject creation is working fine for the first user_group. Assigning roles though does not work at all and I have not clue why exactly. I have attached the code snippet below in the hope that somebody can give me hint on this issue. For information the roleID below is 3 thus I expect it to pointing to Editor role in ezdemo standard installation.

 <?php
 
class eziogHandler extends eZContentObjectEditHandler
{
 
    function __construct()
    {
    }
 
 
    function fetchInput( $http, &$module, &$class, $object, &$version, $contentObjectAttributes, $editVersion, $editLanguage, $fromLanguage )
    {
    }
 
    static function storeActionList()
    {
    }
 
    function publish( $contentObjectID, $contentObjectVersion )
    {
        // fetch object
        $object =& eZContentObject::fetch( $contentObjectID );
        // get content class object
        $contentClass =& $object->attribute('content_class');
 
        // check if currently object is regional_group
    $classIdentifierMap = eZTeamroom::getClassIdentifierList();
        $roleLeaderIdentifierMap = eZIog::getLeaderRoleIdentifierList();
    $user = eZUser::currentUser();
        if ( $contentClass->attribute( 'identifier' ) == $classIdentifierMap['regional_group'] )
        {
            include_once( 'lib/ezutils/classes/ezoperationhandler.php' );
 
    // checking for existing user_group
        $parentNodeID = $object->mainNodeID();
            $parentObjectID = $object->attribute( 'id' );
 
 
        $params= array( 'Depth'=> 1);
            $childs = eZContentObjectTreeNode::subTreeByNodeID( $params ,$object->mainNodeID() );
            $already_has_user_group=false;
            foreach ($childs as $childObject)
            {
            if ($childObject->classIdentifier()=='user_group')
            $already_has_user_group=true;
                break; 
            }
 
    // create new user_group in case there's none
        if ($already_has_user_group==false)
            {
    // fetching parent objects based on initial object
        $parentNodeID = $object->mainNodeID();
        $parentObjectID = $object->attribute( 'id' );
 
    // fetching section + creating new user_group object
            $class = eZContentClass::fetchByIdentifier( 'user_group' );
                $parentContentObjectTreeNode = eZContentObjectTreeNode::fetch( $parentNodeID );
                $parentContentObject = $parentContentObjectTreeNode->attribute( 'object' );
                $sectionID = $parentContentObject->attribute( 'section_id' );
                $userGroupContentObject = $class->instantiate( $parentObjectID, $sectionID );
                $userGroupContentObjectID = $userGroupContentObject->attribute( 'id' );
     
                $nodeAssignment = eZNodeAssignment::create( array( 'contentobject_id' => $userGroupContentObject->attribute( 'id' ),
                'contentobject_version' => $userGroupContentObject->attribute( 'current_version' ),
                'parent_node' => $parentContentObjectTreeNode->attribute( 'node_id' ),
                'is_main' => 1 ) );
                $nodeAssignment->store();
 
                $userGroupContentObjectAttributes =& $userGroupContentObject->contentObjectAttributes();
 
                $loopLenght = count( $userGroupContentObjectAttributes );
 
                // Fill up content object name attribute with user object name
                for( $i = 0; $i < $loopLenght; $i++ )
                {
                    switch( $userGroupContentObjectAttributes[$i]->attribute( 'contentclass_attribute_identifier' ) )
                    {
                        case 'name':
                            $userGroupContentObjectAttributes[$i]->setAttribute( 'data_text', 'Gruppenmitglieder' );
                            $userGroupContentObjectAttributes[$i]->store();
                            break;
                    }
                }
 
                $userGroupContentObject->setAttribute( 'status', EZ_VERSION_STATUS_DRAFT );
                $userGroupContentObject->store();
 
                // publish new object
                $operationResult = eZOperationHandler::execute( 'content', 'publish', array( 'object_id' => $userGroupContentObjectID, 'version' => 1 ) );
 
        // add member roles to user_group
        $roleMemberIdentifierMap = eZIog::getMemberRoleIdentifierList();
                foreach ($roleMemberIdentifierMap as $roleID)
                {
            $role = eZRole::fetch( $roleID );
            $role->assignToUser( $userGroupContentObjectID, 'subtree', $object->attribute('main_node_id') );
            eZRole::expireCache();
            eZContentCacheManager::clearAllContentCache();
            eZUser::cleanupCache();
                }
 
        }
 
        }
 
    }
 
    function validateInput( $http, &$module, &$class, $object, &$version, $contentObjectAttributes, $editVersion, $editLanguage, $fromLanguage, $validationParameters )
    {
        $result = array( 'is_valid' => true, 'warnings' => array() );
        return $result;
    }
}
 
?>

Modified on Thursday 05 July 2012 7:39:15 pm by Sebastian Schoeller

No reply yet!

expandshrink

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu