Find the last menu item when calling mod_mainmenu.php, in Joomla?

Hi EE -

In mod_mainmenu.php,
Joomla Info:
PHP built On:          OpenBSD server_name.com 3.7 GENERIC#431 sparc64
Database Version:       4.0.13
PHP Version:       5.1.4
Web Server:       Apache/1.3.34 (Unix) PHP/5.1.4
WebServer to PHP interface:       apache
Joomla! Version:       Joomla! 1.0.13 Stable [ Sunglow ] 21 July 2007 16:00 UTC
User Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.11) Gecko/20071127 Firefox/2.0.0.11

 I have:

default:  
            // open in parent window
            $txt = '<li><a href="'. $mitem->link .'" class="'. $menuclass .'" '. $id .'>'. $mitem->name .'</a></li>';
            break;

I have added the <li>'s, but when the last $mitem comes through I would like to have something like this:

// open in parent window
            if (CONDITON WATCH FOR LAST ITEM )
            {
               $txt = '<li class="last"><a href="'. $mitem->link .'" class="'. $menuclass .'" '. $id .'>'. $mitem->name .'</a></li>';
            } else
            {
               $txt = '<li><a href="'. $mitem->link .'" class="'. $menuclass .'" '. $id .'>'. $mitem->name .'</a></li>';
            }
            break;

Is there a global variable floating around, I can watch for or is there a built in function already available or something else? Any help is greatly appreciated.

Thanks -
Wotan1953
wotan1953Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

modcon_jscottCommented:
A basic example of this type of loop could be like so:

$count = count($my_array);
for($i=0;$i<$count;$i++){
    //check to see if there is an item after this one.
    $class = ( ($i<$cont-1) ) ? ' class="last" ' : '';
    $txt = '<li '.$class.'><a href="'. $mitem->link .'" class="'. $menuclass .'" '. $id .'>'. $mitem->name .'</a></li>
}

Now it seems as though the $mitem is an object, and I dont know exactly how this object is produced. You should check to see if there is an EOF attribute of that method or you might be able to implement a variation of this example in a while loop when this object is constructed.

It might be easier to do this in javascript after the menu is constructed and the DOM has been loaded. You will need to assign a class name to all of the li elements. Then you will be able to find them pretty easy.

window.onload = function(){
  var list = document.getElementsByTagName('li');
  var len = list.length;
  list[ (len-1) ].className += 'last';
}

This will only work if there is only one set of li elements in your document. If there arent then you will need to search within the list array for the clasName you are interested in.

Hope this helps.....
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
wotan1953Author Commented:
Hey Thanks Much modcon_jscott.  I did as you said and went to the function that was packing this object each time. I waited outside the loop and grabbed the value of the last $row->id. Made it a global var $lastmenuitem. And then watched for it up in the main function. If ($menuitem->id == $lastmenuitem) {
do something different}
0
wotan1953Author Commented:
Hi Thanks -

First I went to the function that was calling this object ($mitem)

function mosRecurseVIMenu( $id, $level, &$children, &$open, &$indents, &$params ) {
    global $menulastid ;
            if (@$children[$id]) {
                  $n = min( $level, count( $indents )-1 );
// echo "Test 06022008c ".count($children[$id])." <br>";
      echo "\n".$indents[$n][0];
                  foreach ($children[$id] as $row) {

                        echo "\n".$indents[$n][1];

                        echo mosGetMenuLink( $row, $level, $params, $open );

.

.
.
}
                  echo "\n".$indents[$n][3];
                  // echo "<br>Row ID Last ".$row->id." Stop<br>";
                  $menulastid = $row->id;
                  
            }
      }

Then as soon as I dropped out of this loop, I set this var - $menulastid. Plus I made it global.

Then when I get back here:

function mosGetMenuLink( $mitem, $level=0, &$params, $open=null ) {
            global $Itemid, $mosConfig_live_site, $mainframe, $numlinks, $menulastid;
            
.
.
.
.
if (($mitem->id) != ($menulastid ))
                        {
                         
           $txt = '<li><a href="'. $mitem->link .'" class="'. $menuclass .'" '. $id .'>'.$mitem->name .'</a></li>';
        } else
        {
           $txt = '<li class="last"><a href="'. $mitem->link .'" class="'. $menuclass .'" '. $id .'>'. $mitem->name.'</a></li>';
        }
                        // $txt = '<li><a href="'. $mitem->link .'" class="'. $menuclass .'" '. $id .'>'. $mitem->name .'</a></li>';
                        break;

.
.
.
 }

Works great!

Thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.