Snippets for eZ publish 3: Adding collaboration notification rules

The following code sample shows you how to create a new collaboration notification rule for a specific user. The known variables are:

  • $collaborationIdentifier: identifier of the collaboration type, for example ezapprove
  • $userID: the content object id of the user we want to create the rule for
include_once('kernel/classes/notification/handler/ezcollaborationnotification/ezcollaborationnotificationrule.php');
$existing = &eZCollaborationNotificationRule::fetchItemTypeList( $collaborationIdentifier, array( $userID ) );

if ( count( $existing ) == 0 )
{
    $rule = &eZCollaborationNotificationRule::create( $collaborationIdentifier, $userID );
    $rule->store( );
}