eZ Community » Forums » Setup & design » One click to add and remove notification
expandshrink

One click to add and remove notification

One click to add and remove notification

Monday 29 November 2004 1:06:55 pm - 1 reply

Now if you want to remove a node form the notification you have to:
1) go to the /notification/setting page
2) select the node you want to remove
3) click delete
4) click store to be sure...
5) click a link to return to the site

Replace the template
design/standard/templates/toolbar/full/notification.tpl
with the following and for each node you get the button "Keep me updated" or "Remove"

Please note that a there is bug related to this code:
http://ez.no/community/bug_reports/node_not_set_and_fatal_error

Now it works once every time you clear the cache.

Let me know it was usefull.

Tested only with 3.5.0rc1, may works with 3.4.4, earlyer needs
at least a workarond for {set scope=root subscribed=true()}.

{*?template charset=iso-8859-15?*}
<div class="toolbar-item {$placement}">
    <div class="toolbox">
        <div class="toolbox-design">
            <h2>{'Notification'|i18n( 'design/standard/toolbar' )}</h2>
            <div class="toolbox-content">
            {section show=not(is_set($node))}
              {* Expect to be here when you aren't in a node: e.g /notification/settings *}
              {* Or if there are problem: http://ez.no/community/bug_reports/node_not_set_and_fatal_error *}
              $node.node_id not set:
              {* FIXME: requires i18n *}
              Notification not avaliable for this page.
            {section-else}
              {let subscribed=false()}
                {section show=eq($current_user.contentobject_id,$anonymous_user_id)}
                  <a class="menuitem" href={"/user/login/"|ezurl}>{"Login"|i18n("design/standard/layout")}</a>
                {section-else}
                  {let subscribed_nodes=fetch( 'notification', 'subscribed_nodes')}
                    {* FIXME is possible to use one function instead of looping? E.g.: $subscribed_nodes_array|contains($node.node_id) *}
                    {section name=Rules loop=$subscribed_nodes}
                      {section show=eq($Rules:item.node.node_id,$node.node_id)}
                        {* FIXME is possible to stop the loop if we found one occurrence *}
                        {set scope=root subscribed=true()}
                        <form method="post" action={"/content/action/"|ezurl}>
                          <input type="hidden" name="ContentNodeID" value="{$node.node_id}" />
                          <input type="hidden" name="ContentObjectID" value="{$node.contentobject_id.}" />
                          <input type="hidden" name="NodeID" value="{$node.node_id}" />
                          {* NOTE this action require a patch to kernel/content/action.php*}
                          <input class="button" type="submit" name="ActionRemoveFromNotification" value="{'Remove'|i18n('design/standard/notification')}" />
                          {* FIXME css design class *}
                          <input type="hidden" name="ClassIdentifier" value="forum_topic" />
                        </form>
                      {/section}
                    {/section}
                  {/let}
                  {section show=not($subscribed)}
                    <form method="post" action={"content/action/"|ezurl}>
                      <input type="hidden" name="ContentNodeID" value="{$node.node_id}" />
                      <input type="hidden" name="ContentObjectID" value="{$node.contentobject_id.}" />
                      <input type="hidden" name="NodeID" value="{$node.node_id}" />
                      <input class="button forum-keep-me-updated" type="submit" name="ActionAddToNotification" value="{'Keep me updated'|i18n( 'design/base' )}" />
                      {* FIXME css design class *}
                      <input type="hidden" name="ClassIdentifier" value="forum_topic" />
                    </form>
                  {/section}
                {/section}
              {/let}  
            {/section}
            </div>
        </div>
    </div>
</div>

# Also add in kernel/content/action.php after
else if ( $http->hasPostVariable( "ActionAddToNotification" ) )
{
....
}

else if ( $http->hasPostVariable( "ActionRemoveFromNotification" ) )
{
    include_once( 'kernel/classes/notification/handler/ezsubtree/ezsubtreenotificationrule.php' );
    $user =& eZUser::currentUser();

    $nodeID = $http->postVariable( 'ContentNodeID' );

    if ( $http->hasPostVariable( 'ViewMode' ) )
        $viewMode = $http->postVariable( 'ViewMode' );
    else
        $viewMode = 'full';

    if ( !$user->isLoggedIn() )
    {
        eZDebug::writeError( 'User not logged in trying to unsubscribe for notification, node ID: ' . $nodeID,
                             'kernel/content/action.php' );
        $module->redirectTo( $module->functionURI( 'view' ) . '/' . $viewMode . '/' . $nodeID . '/' );
        return;
    }
    $contentNode = eZContentObjectTreeNode::fetch( $nodeID );
    if ( !$contentNode->attribute( 'can_read' ) )
    {
        eZDebug::writeError( 'User does not have access to unsubscribe for notification, node ID: ' . $nodeID . ', user ID: ' . $user->attribute( 'contentobject_id' ),
                             'kernel/content/action.php' );
        $module->redirectTo( $module->functionURI( 'view' ) . '/' . $viewMode . '/' . $nodeID . '/' );
        return;
    }

    $nodeIDList =& eZSubtreeNotificationRule::fetchNodesForUserID( $user->attribute( 'contentobject_id' ), false );
    if ( in_array( $nodeID, $nodeIDList ) )
    {
        eZSubtreeNotificationRule::removeByNodeAndUserID( $user->attribute( 'contentobject_id' ), $nodeID );
    }
    $module->redirectTo( $module->functionURI( 'view' ) . '/' . $viewMode . '/' . $nodeID . '/' );
    return;
}

Modified on Monday 29 November 2004 1:17:16 pm by Daniele P.

Tuesday 26 February 2013 4:54:43 pm

This is an old post but I couldn't find a more updated solution to this problem so I found it very useful.  So, thanks Daniel!  I've updated the code a bit to take out ez sections and make it a bit more concise.  In case anyone has the same need, here it is: 

In your template:

<form method="post" action={"content/action"|ezurl}>                        {if $node.can_create}                        <input type="hidden" name="ClassIdentifier" value="comment" />                        <input type="hidden" name="NodeID" value="{$node.node_id}" />                        <input type="hidden" name="ContentLanguageCode" value="{ezini( 'RegionalSettings', 'ContentObjectLocale', 'site.ini')}" />                        <input class="button" type="submit" name="NewButton" value="{'Add a Comment'|i18n( 'design/ezwebin/full/article' )}" />                        <input type="hidden" name="RedirectURIAfterPublish" value="{$node.url_alias|ezurl('no', 'full')}" />                        <input type="hidden" name="RedirectIfDiscarded" value="{$node.url_alias|ezurl('no', 'full')}" />                        <input type="hidden" name="RedirectIfCancel" value="{$node.url_alias|ezurl('no', 'full')}" />                        {/if}                        {def $notification_access=fetch( 'user', 'has_access_to', hash( 'module', 'notification', 'function', 'use' ) )}                        {if $notification_access}                        <input type="hidden" name="ContentNodeID" value="{$node.node_id}" />                            {def $subscriptions=fetch( 'notification', 'subscribed_nodes' )}                            {def $subscriptionItem = ''}                            {foreach $subscriptions as $subscription}                                {if eq( $node.node_id, $subscription.node_id )}                                    {set $subscriptionItem = $subscription}                                    {break}                                {/if}                            {/foreach}                            {if $subscriptionItem}                            {* NOTE this action requires a patch to kernel/content/action.php *}                        <input class="button" type="submit" name="ActionRemoveFromNotification" value="{'Unsubscribe'|i18n('design/standard/notification')}" />                            {else}                        <input class="button" type="submit" name="ActionAddToNotification" value="{'Subscribe'|i18n( 'design/standard/notification' )}" />                            {/if}                        {/if}                    </form>

 

In kernel/content/action.php

// THIS IS A PATCH TO ALLOW ONE CLICK REMOVAL OF A NODE FROM NOTIFICATION SUBSCRIPTIONS
else if ( $http->hasPostVariable( "ActionRemoveFromNotification" ) ){    include_once( 'kernel/classes/notification/handler/ezsubtree/ezsubtreenotificationrule.php' );    $user = eZUser::currentUser();    $redirectURI = $http->postVariable( 'RedirectURI', $http->sessionVariable( 'LastAccessesURI', '/' ) );    $nodeID = $http->postVariable( 'ContentNodeID' );    $viewMode = $http->hasPostVariable( 'ViewMode' ) ? $http->postVariable( 'ViewMode' ) : 'full';    if ( !$user->isLoggedIn() )    {        eZDebug::writeError( 'User not logged in trying to unsubscribe for notification, node ID: ' . $nodeID,                             'kernel/content/action.php' );        $module->redirectTo( $redirectURI );        return;    }    $nodeIDList =& eZSubtreeNotificationRule::fetchNodesForUserID( $user->attribute( 'contentobject_id' ), false );    if ( in_array( $nodeID, $nodeIDList ) )    {        eZSubtreeNotificationRule::removeByNodeAndUserID( $user->attribute( 'contentobject_id' ), $nodeID );    }    $module->redirectTo( $redirectURI );    return;}// END OF PATCH

Modified on Tuesday 26 February 2013 4:55:45 pm by Fraser Hore

expandshrink

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

36 542 Users on board!

Forums menu

Proudly Developed with from