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

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.

eZ debug

Timing: Jan 19 2025 03:32:52
Script start
Timing: Jan 19 2025 03:32:52
Module start 'layout'
Timing: Jan 19 2025 03:32:52
Module start 'content'
Timing: Jan 19 2025 03:32:53
Module end 'content'
Timing: Jan 19 2025 03:32:53
Script end

Main resources:

Total runtime0.9871 sec
Peak memory usage4,096.0000 KB
Database Queries46

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0059 589.2891152.6406
Module start 'layout' 0.00600.0039 741.929739.4766
Module start 'content' 0.00990.9755 781.4063433.0313
Module end 'content' 0.98540.0016 1,214.437512.1250
Script end 0.9870  1,226.5625 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00340.3429160.0002
Check MTime0.00140.1428160.0001
Mysql Total
Database connection0.00080.085210.0008
Mysqli_queries0.932694.4838460.0203
Looping result0.00050.0464440.0000
Template Total0.951096.320.4755
Template load0.00230.228920.0011
Template processing0.948796.110920.4743
Template load and register function0.00020.019410.0002
states
state_id_array0.00180.179610.0018
state_identifier_array0.00150.152420.0008
Override
Cache load0.00180.1862250.0001
Sytem overhead
Fetch class attribute can translate value0.00070.069910.0007
Fetch class attribute name0.00080.078110.0008
XML
Image XML parsing0.00010.013410.0001
class_abstraction
Instantiating content class attribute0.00000.000510.0000
General
dbfile0.00080.0785100.0001
String conversion0.00000.000940.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
1content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
5content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
5content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
2content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 15
 Number of unique templates used: 6

Time used to render debug report: 0.0002 secs