Recent Topics

1 Jul 14, 2008 08:32    

Is there any way to display paged results, it shows 20 by default.
I put 4 there but it doesn't break results by 4

$FileList = & new DataObjectList2( $FileCache, 4 );

'total_rows' => 0,
'limit' => 4,
'result_num_rows' => 7,
'page' => NULL,
'page_ID_list' => NULL,
'page_ID_array' => NULL,
'current_idx' => 0,
'global_idx' => NULL,
'global_is_first' => NULL,
'global_is_last' => NULL,

Thanks

2 Jul 14, 2008 09:00

Try :

$FileCache = & get_Cache( 'FileCache' );

$FileList = & new DataObjectList2( $FileCache );

// Query list of files:
$SQL = & new SQL();
$SQL->SELECT( 'post_ID, post_datestart, post_datemodified, post_main_cat_ID, post_urltitle, post_ptyp_ID, post_title, post_excerpt, post_url,
							file_ID, file_title, file_root_type, file_root_ID, file_path, file_alt, file_desc' );
$SQL->FROM( 'T_categories INNER JOIN T_postcats ON cat_ID = postcat_cat_ID
							INNER JOIN T_items__item ON postcat_post_ID = post_ID
							INNER JOIN T_links ON post_ID = link_itm_ID
							INNER JOIN T_files ON link_file_ID = file_ID' );
$SQL->WHERE( 'cat_blog_ID = '.$Blog->ID ); // fp> TODO: want to restrict on images :]
$SQL->WHERE_and( 'post_status = "published"' );	// TODO: this is a dirty temporary hack. More should be shown.
$SQL->GROUP_BY( 'link_ID' );
$SQL->ORDER_BY( 'post_'.$Blog->get_setting('orderby').' '.$Blog->get_setting('orderdir')
								.', post_ID '.$Blog->get_setting('orderdir').', link_ID' );

$SQL->LIMIT( 4 );

¥

3 Jul 14, 2008 09:05

I shows 4 items, but how to navigate to the next 4?

'total_rows' => 0,
'limit' => '20',
'result_num_rows' => 4,
'page' => NULL,

4 Jul 14, 2008 09:09

Try :

	<?php
		// -------------------- PREV/NEXT PAGE LINKS (POST LIST MODE) --------------------
		$FileList->page_links( array(
		'block_start'		=>	'<p class="center">',
		'block_end'		=>	'</p>',
   		'prev_text'		=>	'&lt;&lt;',
   		'next_text'		=>	'&gt;&gt;',
		) );
		// ------------------------- END OF PREV/NEXT PAGE LINKS -------------------------
	?>

¥

5 Jul 14, 2008 09:11

Call to undefined method DataObjectList2::page_links()

6 Jul 14, 2008 09:16

:P

You could try replicating the function from inc/items/model/_itemlistlight.class.php ( approx 1460 ), you'd need to change all $this to $FileList

	/**
	 * Template tag
	 */
	function page_links( $params = array() )
	{
		global $generating_static;

		$default_params = array(
				'block_start' => '<p class="center">',
				'block_end' => '</p>',
				'block_single' => '',
				'links_format' => '#',
				'page_url' => '', // All generated links will refer to the current page
				'prev_text' => '&lt;&lt;',
				'next_text' => '&gt;&gt;',
				'no_prev_text' => '',
				'no_next_text' => '',
				'list_prev_text' => '...',
				'list_next_text' => '...',
				'list_span' => 11,
				'scroll_list_range' => 5,
			);
	  if( !empty($generating_static) )
	  {	// When generating a static page, act as if we were currently on the blog main page:
	  	$default_params['page_url'] = $this->Blog->get('url');
		}

		// Use defaults + overrides:
		$params = array_merge( $default_params, $params );

		if( $this->total_pages <= 1 )
		{	// Single page:
			echo $params['block_single'];
			return;
		}

		if( $params['links_format'] == '#' )
		{
			$params['links_format'] = '$prev$ $first$ $list_prev$ $list$ $list_next$ $last$ $next$';
		}

 		if( $this->Blog->get_setting( 'paged_nofollowto' ) )
		{	// We prefer robots not to follow to pages:
			$this-> nofollow_pagenav = true;
		}

		echo $params['block_start'];
		echo $this->replace_vars( $params['links_format'], $params );
		echo $params['block_end'];
	}

¥

7 Jul 14, 2008 09:21

Also worth looking at is inc/_core/ui/_results.class.php ( approx 1320 )

	/**
	 * Display navigation text, based on template.
	 *
	 * @param string template: 'header' or 'footer'
	 * @access protected
	 */
	function display_nav( $template )
	{
		echo $this->params[$template.'_start'];

		if( empty($this->limit) && isset($this->params[$template.'_text_no_limit']) )
		{	// No LIMIT (there's always only one page)
			echo $this->params[$template.'_text_no_limit'];
		}
		elseif( ( $this->total_pages <= 1 ) )
		{	// Single page (we probably don't want to show navigation in this case)
			echo $this->params[$template.'_text_single'];
		}
		else
		{	// Several pages
			echo $this->replace_vars( $this->params[$template.'_text'] );
		}

		echo $this->params[$template.'_end'];
	}

and ( same file ) ( approx 1658 )

	/**
	 * Widget callback for template vars.
	 *
	 * This allows to replace template vars, see {@link Widget::replace_callback()}.
	 *
	 * @return string
	 */
	function replace_callback( $matches )
	{
		// echo '['.$matches[1].']';
		switch( $matches[1] )
		{
			case 'start' :
				return ( ($this->page-1)*$this->limit+1 );

			case 'end' :
				return ( min( $this->total_rows, $this->page*$this->limit ) );

			case 'total_rows' :
				//total number of rows in the sql query
				return ( $this->total_rows );

			case 'page' :
				//current page number
				return ( $this->page );

			case 'total_pages' :
				//total number of pages
				return ( $this->total_pages );

			case 'prev' :
				// inits the link to previous page
				if ( $this->page <= 1 )
				{
					return $this->params['no_prev_text'];
				}
				$r = '<a href="'
						.regenerate_url( $this->page_param, (($this->page > 2) ? $this->page_param.'='.($this->page-1) : ''), $this->params['page_url'] ).'"';
				if( $this->nofollow_pagenav )
				{	// We want to NOFOLLOW page navigation
					$r .= ' rel="nofollow"';
				}
				$r .= '>'.$this->params['prev_text'].'</a>';
				return $r;

			case 'next' :
				// inits the link to next page
				if( $this->page >= $this->total_pages )
				{
					return $this->params['no_next_text'];
				}
				$r = '<a href="'
						.regenerate_url( $this->page_param, $this->page_param.'='.($this->page+1), $this->params['page_url'] ).'"';
				if( $this->nofollow_pagenav )
				{	// We want to NOFOLLOW page navigation
					$r .= ' rel="nofollow"';
				}
				$r .= '>'.$this->params['next_text'].'</a>';
				return $r;

			case 'list' :
				//inits the page list
				return $this->page_list( $this->first(), $this->last(), $this->params['page_url'] );

			case 'scroll_list' :
				//inits the scrolling list of pages
				return $this->page_scroll_list();

			case 'first' :
				//inits the link to first page
				return $this->display_first( $this->params['page_url'] );

			case 'last' :
				//inits the link to last page
				return $this->display_last( $this->params['page_url'] );

			case 'list_prev' :
				//inits the link to previous page range
				return $this->display_prev( $this->params['page_url'] );

			case 'list_next' :
				//inits the link to next page range
				return $this->display_next( $this->params['page_url'] );

			default :
				return parent::replace_callback( $matches );
		}
	}

¥

8 Jul 14, 2008 09:22

Ok thanks, let me try all this :)

9 Jul 14, 2008 15:22

Nothing good...
Let me explain what I need, maybe there is an easier way to do it.
I want to display a thumbnail image linked to the post (b2evo 2.5), it would be only one image in my case. What if we get a $File object by $Item->ID in posts mode?

if( is_object($File) && $File->is_image() )
{
	echo '<a href="'.$Item->get_permanent_url().'">';
	echo '<img src="'.$File->get_thumb_url( 'fit-170x190' ).'" '
				.'alt="'.$Item->title.'" '
				.'title="'.$Item->title.'" />';
	echo '</a>';
}

10 Jul 14, 2008 15:48

I'm a smidge lost as to what you're after doing .... not that it takes much to lose a blonde ;)

Where are you generating $File ( ie/ how are you selecting the image in the first place ) ?

<?php
$ItemCache = get_Cache( 'ItemCache' );
$Item = $ItemCache->get_by_ID( $File->get->( 'itm_ID' ) );
?>

¥

11 Jul 14, 2008 15:59

I moved to $disp=posts , so I already have an Item and want to get a File.
I tried this

$SQL = & new SQL();

$SQL->SELECT( 'link_ID, link_ltype_ID, file_ID, file_title, file_root_type, file_root_ID, file_path, file_alt, file_desc' );
$SQL->FROM( 'T_links LEFT JOIN T_files ON link_file_ID = file_ID' );
$SQL->WHERE( 'link_itm_ID = '.$Item->ID );
$SQL->ORDER_BY( 'link_ID' );

$Results = & new Results( $SQL->get(), 'link_' );
$Results->query( false, false, false );

$File = & $FileCache->get_by_ID( $Results->XXXXXX, false, false );

I think I'm very close :)

But I have no idea what is XXXXX :(

12 Jul 14, 2008 17:00

Ta-da!!! :)
I did it. Here is the code from _posts.disp.php
Thanks ¥åßßå for pointing me in the right direction.

$FileCache = & get_Cache( 'FileCache' );

echo '<table class="image_index" cellpadding="0" cellspacing="0">';

$nb_cols = 4;
$count = 0;
$prev_post_ID = 0;
while( $Item = & mainlist_get_item() )
{
	$SQL = & new SQL();
	
	$SQL->SELECT( 'link_ID, link_ltype_ID, file_ID, file_title, file_root_type, file_root_ID, file_path, file_alt, file_desc' );
	$SQL->FROM( 'T_links LEFT JOIN T_files ON link_file_ID = file_ID' );
	$SQL->WHERE( 'link_itm_ID = '.$Item->ID );
	$SQL->ORDER_BY( 'link_ID' );
	
	$Results = & new Results( $SQL->get(), 'link_' );
	$Results->query( false, false, false );
	
	if( $Results->total_rows != 1 )
		continue;
		
	$File = & $FileCache->get_by_ID( $Results->rows[0]->file_ID, false, false );

	if( !is_object($File) && !$File->is_image() )
		continue;
	
	if( $count % $nb_cols == 0 )
	{
		echo "\n<tr>";
	}
	if( $Item->ID != $prev_post_ID )
	{
		$prev_post_ID = $Item->ID;
		$count++;
	}
	
	echo "\n\t".'<td><div id="item_'.$Item->ID.'" class="PostsCell">';	
	
	// =====================
	
	echo '<a href="'.$Item->get_permanent_url().'">';
	echo '<img src="'.$File->get_thumb_url( 'fit-170x190' ).'" '
				.'alt="'.$Item->title.'" '
				.'title="'.$Item->title.'" />';							// Image
	echo '</a>';
	echo '<div class="PostsTitle">'.$Item->title.'</div>';				// Title
	echo '<div class="PostsPrice">$'.$Item->get('double1').'</div>';	// Price
	
	// =====================	
	
	echo '</div></td>';
	if( $count % $nb_cols == 0 )
	{
		echo '</tr>';
	}

}

if( $count && ( $count % $nb_cols != 0 ) )
{
	echo '</tr>';
}

echo '</table>';

13 Jul 14, 2008 18:02

Ahh, that's pretty much the opposite of what I thought you were trying to do .... I did say put it in blonde terms :p

You might be interested in inc/model/_item.class.php ( approx 1531 )

	/**
	 * Display the images linked to the current Item
	 *
	 * @param array of params
	 * @param string Output format, see {@link format_to_output()}
	 */
	function images( $params = array(), $format = 'htmlbody' )
	{
		echo $this->get_images( $params, $format );
	}


	/**
	 * Get block of images linked to the current Item
	 *
	 * @param array of params
	 * @param string Output format, see {@link format_to_output()}
	 */
	function get_images( $params = array(), $format = 'htmlbody' )
	{
		$params = array_merge( array(
				'before' =>              '<div>',
				'before_image' =>        '<div class="image_block">',
				'before_image_legend' => '<div class="image_legend">',
				'after_image_legend' =>  '</div>',
				'after_image' =>         '</div>',
				'after' =>               '</div>',
				'image_size' =>          'fit-720x500',
				'image_link_to' =>       'original',
				'limit' =>               1000,	// Max # of images displayed
			), $params );

		$FileCache = & get_Cache( 'FileCache' );

		$FileList = & new DataObjectList2( $FileCache );


		$SQL = & new SQL();
		$SQL->SELECT( 'file_ID, file_title, file_root_type, file_root_ID, file_path, file_alt, file_desc' );
		$SQL->FROM( 'T_links INNER JOIN T_files ON link_file_ID = file_ID' );
		$SQL->WHERE( 'link_itm_ID = '.$this->ID );
		$SQL->ORDER_BY( 'link_ID' );
		$SQL->LIMIT( $params['limit'] );

		$FileList->sql = $SQL->get();

		$FileList->query( false, false, false );

		$r = '';
    /**
		 * @var File
		 */
		$File = NULL;
		while( $File = & $FileList->get_next() )
		{
			if( ! $File->is_image() )
			{	// Skip anything that is not an image
				// fp> TODO: maybe this property should be stored in link_ltype_ID
				continue;
			}
			// Generate the IMG tag with all the alt, title and desc if available
			$r .= $File->get_tag( $params['before_image'], $params['before_image_legend'], $params['after_image_legend'], $params['after_image'], $params['image_size'], $params['image_link_to'] );
		}

		if( !empty($r) )
		{
			$r = $params['before'].$r.$params['after'];

			// Character conversions
			$r = format_to_output( $r, $format );
		}

		return $r;
	}

¥

14 Jul 14, 2008 18:08

OMG XX( it works!
I spent 5 hours to copy the existing function...

15 Jul 14, 2008 18:09

At least i learned something :)

16 Jul 14, 2008 19:00

We've all been there ... more than once ;)

¥

17 Aug 21, 2009 18:37

I'm not sure if what's been attempted here is the same as what sam was going after, but I'm trying to paginate the mediaidx here:

http://birthdayshoes.com/photos.php?disp=mediaidx

I see the template at skins/_mediaidx.disp.php here:

<?php
/**
 * This is the template that displays the media index for a blog
 *
 * This file is not meant to be called directly.
 * It is meant to be called by an include in the main.page.php template.
 * To display the archive directory, you should call a stub AND pass the right parameters
 * For example: /blogs/index.php?disp=arcdir
 *
 * b2evolution - {@link http://b2evolution.net/}
 * Released under GNU GPL License - {@link http://b2evolution.net/about/license.html}
 * @copyright (c)2003-2009 by Francois PLANQUE - {@link http://fplanque.net/}
 *
 * @package evoskins
 */
if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );

// --------------------------------- START OF MEDIA INDEX --------------------------------
skin_widget( array(
		// CODE for the widget:
		'widget' => 'coll_media_index',
		// Optional display params
		'block_start' => '',
		'block_end' => '',
		'block_display_title' => false,
		'thumb_size' => 'fit-80x80',
		'thumb_layout' => 'grid',
		'grid_start' => '<table class="image_index" cellspacing="3">',
		'grid_end' => '</table>',
		'grid_nb_cols' => 10,
		'grid_colstart' => '<tr>',
		'grid_colend' => '</tr>',
		'grid_cellstart' => '<td>',
		'grid_cellend' => '</td>',
		'order_by' => $Blog->get_setting('orderby'),
		'order_dir' => $Blog->get_setting('orderdir'),
		'limit' => 1000,
	) );
// ---------------------------------- END OF MEDIA INDEX ---------------------------------



?>

I tried adding:

 <?php 
        // -------------------- PREV/NEXT PAGE LINKS (POST LIST MODE) -------------------- 
        $FileList->page_links( array( 
        'block_start'            '<p class="center">', 
        'block_end'            '</p>', 
           'prev_text'            '&lt;&lt;', 
           'next_text'            '&gt;&gt;', 
        ) ); 
        // ------------------------- END OF PREV/NEXT PAGE LINKS ------------------------- 
    ?> 

I'm confused by the various solutions above but sense the solution isn't too difficult. :roll:


Form is loading...