Latest forum activity - how to fetch

Author Message

Radek Kuchta

Wednesday 03 October 2007 9:03:31 am

Hi,

How to use fetch function to get latest forum activity? - the same as here: http://ez.no/developer (with a number of reply).

http://ez.no/certification/verify/272582

Mads Ovesen

Saturday 06 October 2007 12:54:31 pm

Asuming each forum activity is a node in the content tree:

{$array = fetch( 'content', 'list', hash( 'parent_node_id', <parent_node_id>,
                                                     'class_filter_type', 'include',
                                                     'class_filter_array', array( 'forum_activity' ),
                                                     'limit',10,
                                                     'sort_by', array( 'published', false() ) ) ) }

/m

Radek Kuchta

Tuesday 09 October 2007 11:11:19 am

Hi Mads,

I know that each forum activity is a node (the same is a forum topic and a forum reply).
But what I need, is a fetch that bring me a last forum reply (as a <b>unique</b> link to that reply - the last reply to the topic, like in the right column here http://ez.no/developer). I think taht regular content tree function is not enough.

http://ez.no/certification/verify/272582

André R.

Tuesday 09 October 2007 1:13:18 pm

Well you need to sort by modified_subnode, add a loop to loop over the array and count its children(the replys).

something like this:

{def $topics = fetch( 'content', 'tree', hash( 
                            'parent_node_id', <parent_node_id>, 
                            'class_filter_type', 'include', 
                            'class_filter_array', array( 'forum_topic' ), 
                            'limit', 10,
                            'depth', 4,
                            'depth_operator', 'lt',
                            'load_data_map', false(),
                            'sort_by', array( 'modified_subnode', false() ) ) ) }
{if $topics}
  {foreach $topics as $topic}
    <a href={$topic.url_alias|ezurl}>{$topic.name|wash}</a> ({$topic.children_count})<br />
  {/foreach}
{/if}

eZ Online Editor 5: http://projects.ez.no/ezoe || eZJSCore (Ajax): http://projects.ez.no/ezjscore || eZ Publish EE http://ez.no/eZPublish/eZ-Publish-Enterprise-Subscription
@: http://twitter.com/andrerom

Ole Morten Halvorsen

Wednesday 10 October 2007 2:18:23 am

Hi,

As André mentioned, you need to fetch forum messages sorted on modified_subnode.

Here's the code we use to generate the Latest forum activity on ez.no/developer.

{let forum_list=fetch_alias( lastest_forum_replies, hash( parent_node_id, 308 ) )}
{section show=$forum_list}
    <ul class="linklist">
        {section loop=$forum_list}
            {let last_reply_array=fetch_alias( last_forum_reply, hash( parent_node_id, $:item.node_id ))
                 last_reply=$last_reply_array.0}
            <li>
                {section show=$:last_reply}
                    {node_view_gui view=listitem content_node=$:last_reply show_extra_info=true()}
                {section-else}
                    {node_view_gui view=listitem content_node=$:item show_extra_info=true()}
                {/section}
            </li>
            {/let}
        {/section}
        </ul>
{/section}
{/let}

- lastest_forum_replies is defined as following:

[lastest_forum_replies]
Module=content
FunctionName=tree
Parameter[parent_node_id]=parent_node_id
Constant[sort_by]=modified_subnode;0
Constant[depth]=2
Constant[limit]=10
Constant[class_filter_type]=include
Constant[class_filter_array]=forum_message

- last_forum_reply is defined like this:

[last_forum_reply]
Module=content
FunctionName=list
Parameter[parent_node_id]=parent_node_id
Constant[sort_by]=published;0
Constant[limit]=1
Constant[class_filter_type]=include
Constant[class_filter_array]=forum_message

Here's the listitem view for the forum message:

{* List item for form message *}

{* Parameters:
   - show_extra_info = Boolean true(), false()
     Shows extra info such as date, author and number of replies.
     Typicaly used by the community frontpage.
     Default is false()
*}

<div class="content-view-list">
<div class="class-forummessage">

{def $post_count_html=""}

{if $node.parent.object.contentclass_id|eq( 14 )}
    {def $offset=0
         $post_count=$node.parent.children_count}
    
    {if $show_extra_info}
        {set $post_count_html=concat('&nbsp;<span class="forum-replies">(', $post_count, ')</span>' )}
    {/if}
    {include uri="design:parts/forum/calc_offset.tpl" count=$post_count}

    {if $offset|le( 0 )}
        <h3><a title="Posted by: {$node.object.owner.name}: {$node.data_map.message.content|wash|shorten( 400 )}" href={concat( $node.parent.url_alias, '#msg', $node.node_id )|ezurl}>{$node.parent.name|wash}</a>{$post_count_html}</h3>
    {else}
        <h3><a title="Posted by: {$node.object.owner.name}: {$node.data_map.message.content|wash|shorten( 400 )}" href={concat( $node.parent.url_alias, '/(offset)/', $offset, '/#msg', $node.node_id )|ezurl}>{$node.parent.name|wash}</a>{$post_count_html}</h3>
    {/if}
{else}
    {if $show_extra_info}
        {set $post_count_html='&nbsp;<span class="forum-replies">(0)</span>'}
    {/if}
    
    <h3><a title="Posted by: {$node.object.owner.name}: {$node.data_map.message.content|wash|shorten( 400 )}" href={concat( $node.url_alias, '#msg', $node.node_id )|ezurl}>{$node.name|wash}</a>{$post_count_html}</h3>
{/if}

{if $show_extra_info}
    <div class="attribute-byline float-break">
        <p class="date">{$node.object.published|l10n( 'shortdatetime' )}</p>
        <p class="author">{$node.object.owner.name}</p>
    </div>
{/if}

</div>
</div>

and finally the "calc_offset.tpl" template which does just that, calculate the offset.

{set offset=$count|div( 20 )|ceil()|sub( 1 )|mul( 20 )}

Make sure you add an unique anchor each of your forum messages when viewing a thread. The {$node.node_id} is perfect for that.
I hope this helps :)

Senior Software Engineer - Vision with Technology

http://www.visionwt.com
http://www.omh.cc
http://www.twitter.com/omh

eZ Certified Developer
http://ez.no/certification/verify/358441
http://ez.no/certification/verify/272578

Radek Kuchta

Sunday 14 October 2007 8:32:52 am

Ole, It is exactly what I need. It works correctly of course. Thanks a lot.

http://ez.no/certification/verify/272582

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