Author Topic

Roy Bøhmer

Wednesday 05 April 2006 2:16:17 pm

Comment44723

Hi!
This is some highly un-testet template code (with typos for free), that is supposed to loop through two arrays and sort them into a third array. As I said: I'm far from have tested it, but to make it work should require less time than making a custom fetch.



{let fetch1Array=fetch( 'content', 'list', hash(
       'parent_node_id', array(79,80,81,82,83,84,85,115), 
       'limit', 5, 
       'class_filter_type', 'include',
       'class_filter_array', array( 'class1' ),
       'sort_by', array( 'attribute', false(), 'class1/date_released' ) 
      ) ) 

   fetch2Array=fetch( 'content', 'list', hash(
      'parent_node_id', array(79,80,81,82,83,84,85,115), 
      'limit', 5, 
      'class_filter_type', 'include',
      'class_filter_array', array( 'class2' ),
      'sort_by', array( 'attribute', false(), 'class2/date_released' ) 
    ) ) 

   fetch1Count=sub( $fecth1Array|count, 1)
   fetch2Count=sub( $fecth2Array|count, 1)
   fetch1Iterator=0
   fetch2Iterator=0
   loop=true()
}

{let resultArray=array()}


{while $loop=true()}

   {if $fetch1Count|ge( $fetch1Iterator )}
      {if $fetch2Count|ge( $fetch2Iterator )}
          {if ge( $fetch1Array[$fetch1Iterator].data_map.date_released.content, $fetch2Array[$fetch2Iterator].data_map.date_released.content )}
             {set resultArray = $resultArray|append( $fetch1Array[$fetch1Iterator] ) }
             {set fetch1Iterator = sum( $fetch1Iterator, 1)}
          {else}
             {set resultArray = $resultArray|append( $fetch2Array[$fetch2Iterator] ) }
             {set fetch2Iterator = sum( $fetch2Iterator, 1)}
          {/if}

      {else}
          {set resultArray = $resultArray|merge( $fetch1Array|extract( sum( $fetch1Iterator, 1) ) )}
          {break}
      {/if}
           
   {else}
       {set resultArray = $resultArray|merge( $fetch2Array|extract( sum( $fetch2Iterator, 1) ) )}
       {break}
   {/if}


{/section}


{/let}

{* here you can use $resultArray *}

{/let}