Forums / Extensions / eZ Flow / [Example] How to do a dynamic block.useful for you!

[Example] How to do a dynamic block.useful for you!

Author Message

Bin LIU

Wednesday 09 July 2008 2:24:51 am

here, an example to explicate how to do a dynamic block.

We will make a block 8 random Recipes of the parent folder recipes node 999.

firstly, in the block.ini

#section_name + 'Layout_zone' + zone_number
#Solution for avoid all block in adding list of zone layout
#see http://ez.no/developer/forum/extensions/ez_flow/solution_for_avoid_all_block_in_adding_list_of_zone_layout
[CookingLayout_zone2]
AllowedTypes[]
AllowedTypes[]=RecipesRandom

[RecipesRandom]
Name=RecipesRandom
NumberOfValidItems=8
NumberOfArchivedItems=0
ManualAddingOfItems=disabled
FetchClass=LARandomObjects
FetchFixedParameters[]
FetchFixedParameters[Class]=recipe
FetchParameters[]
FetchParameters[Source]=nodeID
FetchParameters[Depth]=2
FetchParameters[Limit]=8
FetchParametersSelectionType[Source]=single
FetchParametersIsRequired[]
FetchParametersIsRequired[Source]=true
FetchParametersIsRequired[Depth]=true
FetchParametersIsRequired[Limit]=true
ViewList[]=8_recipes_random
ViewName[8_recipes_random]=8 Recipes Random
#Time for change the block after the crontab ezflow passed.
TTL=1800

and then, we should create the class FetchClass. so create larandomobjects.php in ezflow/classes/fetches

<?php
/**
 * LARandomObjects
 * @author LIU Bin <bin.liu@lagardere-active.com>
 */

include_once( 'extension/ezflow/classes/ezflowfetchinterface.php' );

class LARandomObjects extends eZFlowFetchInterface
{
    function fetch( $parameters, $publishedAfter, $publishedBeforeOrAt )
    {
        if ( isset( $parameters['Source'] ) )
        {
            $nodeID = $parameters['Source'];
            $node = eZContentObjectTreeNode::fetch( $nodeID, false, false ); // not as an object
        }
        else
        {
            $nodeID = 0;
        }

        $subTreeParameters = array();
        $subTreeParameters['AsObject'] = false;
        $subTreeParameters['Limit'] = isset( $parameters['Limit'] ) ? $parameters['Limit']:false;
        $subTreeParameters['Depth'] = isset( $parameters['Depth'] ) ? $parameters['Depth']:false;

        if ( isset( $parameters['Class'] ) )
        {
            $subTreeParameters['ClassFilterType'] = 'include';
            $subTreeParameters['ClassFilterArray'] = explode( ';', $parameters['Class'] );
        }

        $result = hfpFetchRandom::subTreeRandomByNodeID( $subTreeParameters, $nodeID );
        $fetchResult = array();
        foreach( $result as $item )
        {
            $fetchResult[] = array( 'object_id' => $item['contentobject_id'],
                                    'node_id' => $item['node_id'],
                                    'ts_publication' => $item['published'] );
        }

        return $fetchResult;
    }
}

?>

the class Fetch random see http://projects.ez.no/la_fetch_random

And in the ezflow bo, add source folder 999, config depth 2 and limit 8, and validate.

it works.

=== Lagardère Active ===

Fetch random
http://projects.ez.no/la_fetch_random
LA Static Cache
http://projects.ez.no/lastaticcache
LA Bookmarks (jquery)
http://projects.ez.no/labookmark
LA Calendar (jquery)
http://projects.ez.no/lacalendar

My site ez
http://lingping.info

Bin LIU

Tuesday 22 July 2008 2:33:19 am

I forgot the override.ini


[8_recipes_random]
Source=block/view/view.tpl
MatchFile=block/cooking/8_recipes_random.tpl
Subdir=templates
Match[type]=RecipesRandom
Match[view]=8_recipes_random

and my block/cooking/8_recipes_random.tpl


{def $valid_nodes = $block.valid_nodes}

<div class="contentLargeCol">
	<h3>{"Our favorites recipes :"|texttoimage('cooking_home')}</h3>
		{foreach $valid_nodes as $key => $recipe}
			<dl class="">
				<dt>{attribute_view_gui attribute=$recipe.data_map.image image_class='small_recipe' href=$recipe.url_alias|ezurl()}</dt>
				<dd><a href={$recipe.url_alias|ezurl()}>{$recipe.name}</a></dd>
			</dl>
		{/foreach}		
</div>

=== Lagardère Active ===

Fetch random
http://projects.ez.no/la_fetch_random
LA Static Cache
http://projects.ez.no/lastaticcache
LA Bookmarks (jquery)
http://projects.ez.no/labookmark
LA Calendar (jquery)
http://projects.ez.no/lacalendar

My site ez
http://lingping.info

Mircea Sabau

Thursday 24 July 2008 1:14:35 am

Another problem...

I followed your examples and seems to work ..
But when I publish a new article in source folder, the article in not diplayed... Only the initial articles are diplayed ...

I fetches articles with parameter

$subTreeParameters['SortBy'] = array( 'published', false ); // I need first the newest

Is correct?

Can you help me?

Bin LIU

Thursday 24 July 2008 5:10:13 am

it's normal

you must wait the cron pass, and the cron refresh the cache content paglayout. The new article will be show

active your cron ezflow

=== Lagardère Active ===

Fetch random
http://projects.ez.no/la_fetch_random
LA Static Cache
http://projects.ez.no/lastaticcache
LA Bookmarks (jquery)
http://projects.ez.no/labookmark
LA Calendar (jquery)
http://projects.ez.no/lacalendar

My site ez
http://lingping.info

Quynh Nguyen

Wednesday 18 February 2009 1:20:22 am

I followed your example:

- active extension: http://projects.ez.no/la_fetch_random

- I insert information in block.ini to ezflow/settings/block.ini.append.php

- create larandomobject2s.php in folder: ezflow/classes/fetches

- create file override.ini.append.php in ezflow/settings folder

- create file 8_recipes_random.tpl in ezflow/design/ezflow/override/templates/block/cooking

- clear cache and then add one more this block, and I got error:

Fatal error: eZ Publish did not finish its request

The execution of eZ Publish was abruptly ended, the debug output is present below.

JF Ozange

Thursday 19 February 2009 1:30:51 am

Hello Quynh Nguyen
I had the same error when i tried the dynamic blocs example from the EZ Flow setup docs.
I just changed the FetchClass=ezmLatestObjects by FetchClass=eZFlowLatestObjects to make it work.
Maybe your class is the problem ?

Bin LIU

Monday 18 May 2009 8:37:13 am

it is used in project elle international, and no error

in ezflow1 and ez4.0

perhaps it need some modif in the last version

=== Lagardère Active ===

Fetch random
http://projects.ez.no/la_fetch_random
LA Static Cache
http://projects.ez.no/lastaticcache
LA Bookmarks (jquery)
http://projects.ez.no/labookmark
LA Calendar (jquery)
http://projects.ez.no/lacalendar

My site ez
http://lingping.info

A Fowler

Thursday 09 July 2009 1:19:02 pm

Is there a way to specify multiple classes to show, via the FetchFixedParameters[Class] parameter? For example (this is just a guess, and an attempt to show what I mean, though I have tested it and it doesn't work):

[DynamicMainBlock]
...
FetchFixedParameters[Class]=recipe
FetchFixedParameters[Class]=special_tip
...

Is this possible? Is there a different syntax for it?

Thank you!

A Fowler

Thursday 09 July 2009 1:42:37 pm

Never mind, I see the syntax in the Example text in the block.ini.append.php that I have. It shows this syntax:

# FetchFixedParameters[Class]=article;folder

I only got it to work, however, after both clearing the cache and removing and re-adding the dynamic block to the main layout on the front page.

eZ debug

Timing: Jan 18 2025 03:06:31
Script start
Timing: Jan 18 2025 03:06:31
Module start 'content'
Timing: Jan 18 2025 03:06:31
Module end 'content'
Timing: Jan 18 2025 03:06:32
Script end

Main resources:

Total runtime0.2746 sec
Peak memory usage4,096.0000 KB
Database Queries220

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0092 587.9844180.7578
Module start 'content' 0.00920.1430 768.7422728.6328
Module end 'content' 0.15220.1223 1,497.3750348.4063
Script end 0.2745  1,845.7813 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00381.3727210.0002
Check MTime0.00150.5314210.0001
Mysql Total
Database connection0.00060.228710.0006
Mysqli_queries0.186467.87702200.0008
Looping result0.00220.80342180.0000
Template Total0.241187.820.1205
Template load0.00210.768120.0011
Template processing0.239087.028220.1195
Template load and register function0.00010.037210.0001
states
state_id_array0.00070.244710.0007
state_identifier_array0.00090.331420.0005
Override
Cache load0.00190.7013600.0000
Sytem overhead
Fetch class attribute can translate value0.00120.448460.0002
Fetch class attribute name0.00130.4739100.0001
XML
Image XML parsing0.00100.369560.0002
class_abstraction
Instantiating content class attribute0.00000.0093130.0000
General
dbfile0.00321.1740260.0001
String conversion0.00000.003030.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
9content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
15content/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: 39
 Number of unique templates used: 7

Time used to render debug report: 0.0002 secs