This topic is locked

advice needed badges menu items event

1/17/2019 6:06:43 AM
PHPRunner General questions
R
roeland author

Good morning everyone!
I am a happy user of PHPrunner. it makes my life easier :-) But of course I have a question:
I am using the badges on my application menu as described here:

https://xlinesoft.com/blog/2016/01/06/adding-badges-to-application-menu/
When I do exactly what is written it works very well. But with 1 disadvantage, and that is that I also see the badge when the countvalue is "0 " and that makes no sense. So I rewrote the script in Menu item: Modify so it will show only the badge when the value is 0 like this:
$title = $menuItem->getTitle();

$countinvoices = DBLookup("SELECT count() FROM ebinvoicecustomersgrouped");

$countorders = DBLookup("SELECT count(
) FROM order WHERE order.orderbesteld = False");
// IF THEN invoices

if ($title=="Invoicesmain" AND $countinvoices>0) {

$title.="<span class='badge badge-blue'>".$countinvoices."</span>";

$menuItem->setTitle($title); }
// IF THEN orders

if ($title=="Ordersmain" AND $countorders>0) {

$title.="<span class='badge badge-blue'>".$countorders."</span>";

$menuItem->setTitle($title); }
Also this script works very well, but unforuntely, due to the fact that I run the query every time that the menu loads now, it makes the menu and thus the complete application very slow.
I hope someone has a solution for this?
Thanks already!!

admin 1/18/2019

Move the code that runs the count to event like AfterAppLicationInitialized. Save results in session variables and use those variables in in MenuItemModify event.
In this case calculation will be only performed once per page.