using administrator's pagenav on frontend

Discussion and education for beginner / novice programmers interested in embarking on the development process to take advantage of the extensible nature of the Joomla! CMS.

Moderators: tjay, seadap, Rogue4ngel, matthewhayashida

Forum rules
Post Reply
khaotik
Joomla! Fledgling
Joomla! Fledgling
Posts: 2
Joined: Sun Jul 30, 2006 1:43 am

using administrator's pagenav on frontend

Post by khaotik » Wed Nov 14, 2007 1:10 pm

i'm making a component that manages a database on frontend, but it must have a reordering feature (those blue up and down arrows). since frontend version of the pagenav include dont offer that possibility, i am trying to use the backend version of this include, but it's not working. when i click any of the buttons, it does a "random" ordering, far from the desired result. this is what i'm trying to do:

This goes on the beginning of the main php file. it defines the navigation object:

Code: Select all

$limit = $mainframe->getUserStateFromRequest( "viewlistlimit", 'limit', 10 );
$limitstart = $mainframe->getUserStateFromRequest( "view{$option}limitstart", 'limitstart', 0 );
$rows = array();
$dbdest->setQuery( "SELECT COUNT(*) FROM #__destaques" );
$total = $dbdest->loadResult();
$pageNav = new mosPageNav( $total, $limitstart, $limit );


and this is the function that loads the item listing:

Code: Select all

function listDestaques( $option )
{
   global $mainframe, $my;
   global $mosConfig_live_site;
   global $Itemid;
   global $dbdest, $pageNav;
   global $mosConfig_list_limit;
   
   $query = "SELECT id, url, title, description, date, hits, params, ordering, published, checked_out"
   . "\n FROM #__destaques"
   . "\n ORDER BY ordering"
   . "\n LIMIT $pageNav->limitstart,$pageNav->limit"
   ;
   $dbdest->setQuery( $query );
   $rows = $dbdest->loadObjectList();
   $menu = new mosMenu( $dbdest );
   $menu->load( $Itemid );
   $params = new mosParameters( $menu->params );
   $params->def( 'page_title', 1 );
   $params->def( 'header', $menu->name );
   $params->def( 'pageclass_sfx', '' );
   $params->def( 'headings', 1 );
   $params->def( 'hits', $mainframe->getCfg( 'hits' ) );
   $params->def( 'item_description', 1 );
   $params->def( 'other_cat_section', 1 );
   $params->def( 'other_cat', 1 );
   $params->def( 'description', 1 );
   $params->def( 'description_text', _WEBLINKS_DESC );
   $params->def( 'image', '-1' );
   $params->def( 'destaque_icons', '' );
   $params->def( 'image_align', 'right' );
   $params->def( 'back_button', $mainframe->getCfg( 'back_button' ) );
   $tabclass = array( 'sectiontableentry1', 'sectiontableentry2' );
   HTML_destaques::displaylist( $rows, $params, $tabclass, $option, $pageNav );
}


Now, for the html part:

Some of the parameters necessary to use the methods that build the arrows and allow the reordering are defined here:

Code: Select all

      for ($i=0, $n=count( $rows ); $i < $n; $i++)
      {
         $row = $rows[$i];
         $iparams = new mosParameters( $row->params );
         $link = sefRelToAbs( 'index.php?option=com_destaques&task=view&id='. $row->id );


I will not put the entire code of the displaylist method, because the pageNav isn't used in it, but passed as parameter to another method of the HTML class, called showTable, that build the rows with data, as follows:

Code: Select all

<td>
    <?php echo $pageNav->orderUpIcon( $i, TRUE); ?>
</td>
<td colspan="2" align="center" class="<?php echo "row$k"; ?>">
      
</td>
<td>
    <?php echo $pageNav->orderDownIcon( $i, $n, TRUE); ?>
</td>


As you could see, that was the code that built the arrow buttons, using as parameter those variables declared in the beginning of the loop.

The last instance of the pagenav object is here:

Code: Select all

$pageNav->getListFooter();


That one goes after the table of the displaylist form. And thats it...

I have compared it to the com_content code (backend), and (to me) the codes are all in the right places, but the resulting pagination is a mess. Only 1 item is listed at a time, the reordering is not working, it is a complete chaos. if someone who have experienced this or something close to it, or have a better knowing of the pageNav class and want to help, i will be very thankful!
Last edited by khaotik on Wed Nov 14, 2007 2:33 pm, edited 1 time in total.

khaotik
Joomla! Fledgling
Joomla! Fledgling
Posts: 2
Joined: Sun Jul 30, 2006 1:43 am

Re: using administrator's pagenav on frontend

Post by khaotik » Mon Nov 19, 2007 8:17 pm

alright people, i solved most of the problems with simple things, like putting mosGetParam's to get limit and limitstart, instead of using those wretched getUserStatementWhatever... And instead of using getListFooter at the end of the list, i've put three echo's:

Code: Select all

echo $pageNav->writePagesLinks("index.php?option=$option&Itemid=$Itemid");
echo $pageNav->writePagesCounter();
$pageNav->writeLimitBox("index.php?option=$option&Itemid=$Itemid");


now it's almost everything cool, but the ordering thing still not working. Wandering through the database I've discovered that every item have the ordering value set to 0 on the database, what wasn't supposed to happen. Then i manually set some ordering values to some itens, and when operating the ordering buttons again, some of them were set to 0 again!!! I think that the problem is in the javascript operating the loading... i don't know...
anyone willing to share some wisdom? thankyou!


Post Reply