×

Notice

The forum is in read only mode.
Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1

TOPIC: ItemID?

ItemID? 15 years 11 months ago #2220

  • Chris
  • Chris's Avatar Topic Author
  • Offline
  • Fresh Boarder
  • Fresh Boarder
  • Posts: 5
  • Thank you received: 0
Have u ever thought of adding an ItemID to the commenter link??

Because right now, the modules I have published in my users' profiles don't show when I go to their profiles using the joomlacomment link.

The ItemID is missing!

This is how I do it in my CB SuperActivity Plugin:

// ************************
// FETCH ITEMID
// this function will fetch ANY ItemID
// of ANY of your pages
// and ANY of your components
// ************************
function newItemID($link, $id, $notlike) {
  $db =& JFactory::getDBO();
  $sql = "SELECT id FROM jos_menu WHERE link = '$link$id' AND published=1";
  $db->setQuery($sql);
  $data = $db->loadObjectList();
  if (count($data)==0) {
    if ($notlike) $notlike = "AND link NOT LIKE '$notlike'";
    $sql = "SELECT id FROM jos_menu WHERE link LIKE '$link%' AND published=1 $notlike";
    $db->setQuery($sql);
    $data = $db->loadObjectList();
  }
  $itemid = $data[0]->id;
  if ($itemid) {
    $itemid="&Itemid=".$itemid;
  }
  return $itemid;
}

where for:
$link you give a general link, something like "index.php?option=com_content" or "index.php?option=com_comprofiler", etc.
$id you give a better identification to your link, something like "&view=article&ID=155", or "&task=userprofile&user=70"
$notlike you give what you don't want to be found, for example for eventlist events, you want to find the ItemID of event pages and not venue pages, so you give: $link="option=com_eventlist"; $id="&view=event&id=xx"; $notlike="venue";

This little function will do the BEST guess of ItemIDs, if you use it correctly, because it will search for the exact ItemID of the item, if it doesn't find it, it will search for a more general ItemID that is correct, and you have the option to define what should be excluded from the search! ;)

PLEASE add ItemID to your links, because modules now don't get displayed in UserProfile Pages!!

ItemID? 15 years 11 months ago #2223

  • Daniel Dimitrov
  • Daniel Dimitrov's Avatar
  • Offline
  • Administrator
  • Administrator
  • Posts: 9618
  • Karma: 155
  • Thank you received: 1081
Hey there! Thank you for your proposition.

Can you explain me that in more details.

with
 
$sql = "SELECT id FROM jos_menu WHERE link = '$link$id' AND published=1"; 

you try to find an article that is linked to a menu? If the query returns 0 entries, then you look only for the option and not for an id?

how you generate the $notlike variable.

if you use only LIKE '$link' then you risk to get 20 entries from the sort index.php?option=com_content, ....option=com_content&view=..., option...

Can you explain me this?

ItemID? 15 years 11 months ago #2224

  • Chris
  • Chris's Avatar Topic Author
  • Offline
  • Fresh Boarder
  • Fresh Boarder
  • Posts: 5
  • Thank you received: 0
yes, look:
in table menu, all menu-items store their link, something like "index.php?option=com_content&view=article&id=58".
With articles, it doesn't work that good if the admin didn't make a menu-item for the article you want to get correct ItemID, because there might be items pointing to a lot of sections categories, or other articles. But with some changes you can make it be more precise...

Anyway, I made the function to work best with components, so I will give you an example for the eventlist component.
Let's say the admin has made menu-items for his eventlist component. The basic things of the eventlist are two: events, and venues.
Let's say you want to link to some event.
in this case you could call the function like this:
$eventid = 15; // or any other number
          $link = "index.php?option=com_eventlist";
          $exactlink = "&view=details&id=".$eventid;
          $notlike = "%venue%";
          $itemid = newItemID($link,$exactlink,$notlike);
          $link_jc = JRoute::_($link."&view=details&id=".$eventid.$itemid);
It searches for the link "index.php?option=com_eventlist&view=details&id=15"
If the user has made a menu item that points to this event, it will find it and return the ID from the row it found it in the table jos_menu.
This is the ItemID. Let's say it is 28, so your $link_jc will be now "index.php?option=com_eventlist&view=details&id=15&Itemid=28". Cool, we found it!

If the user didn't make a menu-item for this event, the function will enter the (count($data)==0) condition, and it will search for a more generic eventlist menu-item. But we want to link to an event, so we must exclude venues, that's why $notlike="%venue%";
Since $notlike has a value now, this is true: if ($notlike) $notlike = "AND link NOT LIKE '$notlike'";
So $notlike is now "AND link NOT LIKE '%venue%'
So the query now will bring all eventlist menu-items which are good for events and will not bring any that are for venues.
You take the first one ($itemid = $data[0]->id) and you use it as ItemID.

I SAID this is the best GUESS, it's not always correct, but what can you do? We all know the problem with Joomla's stupid ItemIDs... :)

But I think this is too much. What joomlacomment needs is just a link to CB profiles. The MAIN menu-item of CB is this "index.php?option=com_comprofiler"
CB component tells you to make ONLY one main menu-item!
So, all you need to do is call the function like this:
$userid = 62; // or any other number
          $link = "index.php?option=com_comprofiler";
          $itemid = newItemID($link,'','');
          $link_jc = JRoute::_($link."&task=userProfile&user=".$userid.$itemid);
This way, it will search for the main CB menu-item, and will return the exact ItemID!
If the admin didn't make the mandatory CB menu-item (highly unlikely), it will bring you the first one that is -at least- CB menu-item.
e.g. admin didn't make CB main menu-item, but made "edit profile" CB menu-item (index.php?option=com_comprofiler&task=userProfile&task=userDetails). It will bring the ItemID of this menu-item, at least! ;)

Anyway, I had many complaints about ItemIDs in CB Super Activity, since my module lists more than 20 activities, it would be crazy to make 20 special functions for every different component. I made this, I didn't have ONE complaint since then!! :)
  • Page:
  • 1
Time to create page: 0.135 seconds