Forums / Setup & design / One click to add and remove notification

One click to add and remove notification

Author Message

Daniele P.

Monday 29 November 2004 4:06:55 am

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;
}