Forums / Setup & design / Latest forum activity - how to fetch

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

eZ debug

Timing: Jan 20 2025 01:11:12
Script start
Timing: Jan 20 2025 01:11:12
Module start 'content'
Timing: Jan 20 2025 01:11:13
Module end 'content'
Timing: Jan 20 2025 01:11:13
Script end

Main resources:

Total runtime0.8175 sec
Peak memory usage4,096.0000 KB
Database Queries207

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0053 590.0938180.8281
Module start 'content' 0.00530.6960 770.9219679.9844
Module end 'content' 0.70130.1161 1,450.9063345.7109
Script end 0.8174  1,796.6172 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00390.4817210.0002
Check MTime0.00140.1740210.0001
Mysql Total
Database connection0.00060.074410.0006
Mysqli_queries0.729389.21622070.0035
Looping result0.00200.25062050.0000
Template Total0.794297.220.3971
Template load0.00160.200020.0008
Template processing0.792696.958420.3963
Template load and register function0.00020.027810.0002
states
state_id_array0.00060.073110.0006
state_identifier_array0.00060.069120.0003
Override
Cache load0.00150.1776370.0000
Sytem overhead
Fetch class attribute can translate value0.00130.161250.0003
Fetch class attribute name0.00130.156980.0002
XML
Image XML parsing0.00540.655850.0011
class_abstraction
Instantiating content class attribute0.00000.0029100.0000
General
dbfile0.01121.3720340.0003
String conversion0.00000.000830.0000
Note: percentages do not add up to 100% because some accumulators overlap

CSS/JS files loaded with "ezjscPacker" during request:

CacheTypePacklevelSourceFiles
CSS0extension/community/design/community/stylesheets/ext/jquery.autocomplete.css
extension/community_design/design/suncana/stylesheets/scrollbars.css
extension/community_design/design/suncana/stylesheets/tabs.css
extension/community_design/design/suncana/stylesheets/roadmap.css
extension/community_design/design/suncana/stylesheets/content.css
extension/community_design/design/suncana/stylesheets/star-rating.css
extension/community_design/design/suncana/stylesheets/syntax_and_custom_tags.css
extension/community_design/design/suncana/stylesheets/buttons.css
extension/community_design/design/suncana/stylesheets/tweetbox.css
extension/community_design/design/suncana/stylesheets/jquery.fancybox-1.3.4.css
extension/bcsmoothgallery/design/standard/stylesheets/magnific-popup.css
extension/sevenx/design/simple/stylesheets/star_rating.css
extension/sevenx/design/simple/stylesheets/libs/fontawesome/css/all.min.css
extension/sevenx/design/simple/stylesheets/main.v02.css
extension/sevenx/design/simple/stylesheets/main.v02.res.css
JS0extension/ezjscore/design/standard/lib/yui/3.17.2/build/yui/yui-min.js
extension/ezjscore/design/standard/javascript/jquery-3.7.0.min.js
extension/community_design/design/suncana/javascript/jquery.ui.core.min.js
extension/community_design/design/suncana/javascript/jquery.ui.widget.min.js
extension/community_design/design/suncana/javascript/jquery.easing.1.3.js
extension/community_design/design/suncana/javascript/jquery.ui.tabs.js
extension/community_design/design/suncana/javascript/jquery.hoverIntent.min.js
extension/community_design/design/suncana/javascript/jquery.popmenu.js
extension/community_design/design/suncana/javascript/jScrollPane.js
extension/community_design/design/suncana/javascript/jquery.mousewheel.js
extension/community_design/design/suncana/javascript/jquery.cycle.all.js
extension/sevenx/design/simple/javascript/jquery.scrollTo.js
extension/community_design/design/suncana/javascript/jquery.cookie.js
extension/community_design/design/suncana/javascript/ezstarrating_jquery.js
extension/community_design/design/suncana/javascript/jquery.initboxes.js
extension/community_design/design/suncana/javascript/app.js
extension/community_design/design/suncana/javascript/twitterwidget.js
extension/community_design/design/suncana/javascript/community.js
extension/community_design/design/suncana/javascript/roadmap.js
extension/community_design/design/suncana/javascript/ez.js
extension/community_design/design/suncana/javascript/ezshareevents.js
extension/sevenx/design/simple/javascript/main.js

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
4content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
6content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
12content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
7content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
2content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 33
 Number of unique templates used: 7

Time used to render debug report: 0.0002 secs