Welcome to the MetaMod and Chameleon Support Forums.

Before posting, please check out the FAQs.

helpme

 

Need extra help with your Joomla site? Consider paid Joomla support by the developer of Chameleon and MetaMod.

 

[solved] Configuring menu so that it shows number of new messages

[solved] Configuring menu so that it shows number of new messages

Hi,

I am using the latest version Chameleon on a Joomla 3.2 website, which also has Community Builder and uddeIM installed.

I configured Chameleon so that a different menu is presented to logged in users. One of the items in this menu is "Messages".

Whenever there is a new, unread message waiting for the user, I would like to display to the right of the menu item the number of unread messages waiting, in parenthesis, like this...  Messages (3)

I found an earlier forum post where you explained how to do this:
http://www.metamodpro.com/forums/topic?id=876

However, when I tried it, I got an system error message on a white screen and nothing else would display. Perhaps the error came because the post was for a J1.5 website, where I am running J3.2

Can you please explain what I need to do to achieve this?

Many thanks!
Hector

Edited By: metamodguy
17-Dec-13 23:30:20

hectoritobh
Beginner Modder
ranks
useravatar
Offline
7 Posts
Administrator has disabled public posting

Re: [solved] Configuring menu so that it shows number of new messages

Hi Hector,

you are right, the original post was for a Joomla 1.5 install. I've done some updating so it can work on J2.5, though I have not been able to test the part of it that detects the uddeIM database. Try this however: (this requires the full version of Chameleon for Joomla 2.5)


Code:

$menuid = XXX; // replace XXX with the id of the menu item to change 


$udduserid = $user->id;
$uddsql="SEL" . "ECT count(a.id) FROM #_" . "_uddeim AS a WHERE `a`.`delayed`=0 AND a.totrash=0 AND a.toread=0 AND a.toid=".(int)$udduserid;

$db->setQuery($uddsql);
$uddresult=(int)$db->loadResult();
$message = "Private Messages";
if ($uddresult > 0) $message .= " ($uddresult new)";

$allmenus = JFactory::getApplication()->getMenu();           
$rProperty = new ReflectionProperty($allmenus, '_items');
$rProperty->setAccessible(true);
$items = $rProperty->getValue($allmenus);
$items[$menuid]->title = $message;

Stephen Brandon
MetaMod / Chameleon developer
If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

metamodguy
useravatar
Offline
3313 Posts
User info in posts
Administrator has disabled public posting

Re: [solved] Configuring menu so that it shows number of new messages

Hi Stephen,

Many thanks.

That worked beautifully! smile (On a Joomla 3.2 website, by the way ;-)

Cheers,
Hector

hectoritobh
Beginner Modder
ranks
useravatar
Offline
7 Posts
Administrator has disabled public posting

Re: [solved] Configuring menu so that it shows number of new messages

Excellent - glad that worked for you. This is quite a powerful technique. [wondering out loud if this would be a candidate for a Chameleon "action": to change a particular menu item name. But exactly what kind of options to provide, I don't know]

Thanks for reporting back,
Stephen

Stephen Brandon
MetaMod / Chameleon developer
If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

metamodguy
useravatar
Offline
3313 Posts
User info in posts
Administrator has disabled public posting

Re: [solved] Configuring menu so that it shows number of new messages

Hi Stephen,

Having the option to change a menu item name sounds like a great idea. So many possibilities! The challenge may be how to handle so many different options! smile

Kind regards,
Hector

hectoritobh
Beginner Modder
ranks
useravatar
Offline
7 Posts
Administrator has disabled public posting

Re: [solved] Configuring menu so that it shows number of new messages

Yes, as always that's the predicament. A simple text rename would be one thing, but it would not have helped in your case as you needed a very specific value from the database to populate it with, and then only if it was >0. So PHP is really the easiest way to implement it, but it's not very user friendly.

Oh well. At least we made it do exactly what you wanted.

Stephen Brandon
MetaMod / Chameleon developer
If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

metamodguy
useravatar
Offline
3313 Posts
User info in posts
Administrator has disabled public posting

Re: [solved] Configuring menu so that it shows number of new messages

This is not working for me yet? What type of menu do I create to get this to work? I am expecting to see an unread messages count somewhere?

Maranatha
Beginner Modder
ranks
useravatar
Offline
5 Posts
Administrator has disabled public posting

Re: [solved] Configuring menu so that it shows number of new messages

Pardon me it's working.

Can I display a red dot as well to indicate new/unread mesages?

Maranatha
Beginner Modder
ranks
useravatar
Offline
5 Posts
Administrator has disabled public posting

Re: [solved] Configuring menu so that it shows number of new messages

Or better still change the background color of the menu tab.

Maranatha
Beginner Modder
ranks
useravatar
Offline
5 Posts
Administrator has disabled public posting

Re: [solved] Configuring menu so that it shows number of new messages

Hi Maranatha,

In general, to achieve the type of results you are looking for, you will be looking for ways to affect the HTML and CSS of the page. One approach would be to identify from the HTML output of the page, the exact HTML that your menu item contains. e.g. it may look like:

<li class="item-444"><a href="/sample-sites" >Sample Sites</a></li>

So, you could use the find-and-replace action in Chameleon to search for:

<li class="item-444">

and replace it with:

<li class="item-444"><span style="color:red">&bull;</span>&nbsp;

(obviously, you only want to do that on the pages where you are doing the original action of changing the menu item text, so do that in your existing rule)

If you want to change the background colour of the menu tab you'll need to investigate what CSS is currently applied to that menu tab (will be different for every template). Then in the succeed action you could output some CSS code to target that tab. For the example above it may be as simple as the following:

li.item-444 {background-color:red;}

Hope that helps,
Stephen

Stephen Brandon
MetaMod / Chameleon developer
If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

metamodguy
useravatar
Offline
3313 Posts
User info in posts
Administrator has disabled public posting

Board Info

Board Stats:
 
Total Topics:
1679
Total Polls:
6
Total Posts:
5913
Dormant:
User Info:
 
Total Users:
10783
Newest User:
weatti4qx
Members Online:
0
Guests Online:
234

Online: 
There are no members online

Forum Legend:

 Topic
 New
 Locked
 Sticky
 Active
 New/Active
 New/Locked
 New Sticky
 Locked/Active
 Active/Sticky
 Sticky/Locked
 Sticky/Active/Locked