Jump to content

Adding badge


projectmyst

Recommended Posts

Hi Everyone

I'm trying to add active domains badge via hooks, but I'm not having much luck. Does anyone how I can achieve this? This is my current code:

 

	// Domains
	if ($primaryNavbar) {
        $primaryNavbar->addChild('Domains')
        ->setLabel('Domains')
        ->setOrder(97);
    	if ($primaryNavbar && !is_null($primaryNavbar->getChild('Domains'))) {
	    	if (!is_null($client)) {
			    $primaryNavbar->getChild('Domains')->addChild('My Domains')
		        ->setUri('clientarea.php?action=domains')
		        ->setLabel('My Domains')
		        ->setBadge(($badges['activedomains']))
		        ->setOrder(1);
		        $primaryNavbar->getChild('Domains')->addChild('Divider-My Domains')
		        ->setUri('#')
		        ->setLabel('-----')
		        ->setClass('nav-divider')
		        ->setOrder(2);
			}
		    $primaryNavbar->getChild('Domains')->addChild('Register a New Domain')
	        ->setUri('cart.php?a=add&domain=register')
	        ->setLabel('Register a New Domain')
	        ->setIcon('fas fa-envelope-open')
	        ->setOrder(3);
		    $primaryNavbar->getChild('Domains')->addChild('Transfer a Domain to Us')
	        ->setUri('cart.php?a=add&domain=transfer')
	        ->setLabel('Transfer Domains to Us')
	        ->setIcon('fas fa-envelope-open')
	        ->setOrder(4);
	        if (!is_null($client)) {
		        $primaryNavbar->getChild('Domains')->addChild('Divider-Renew Domains')
		        ->setUri('#')
		        ->setLabel('-----')
		        ->setClass('nav-divider')
		        ->setOrder(5);
			    $primaryNavbar->getChild('Domains')->addChild('Renew Domains')
		        ->setUri('cart.php?gid=renewals')
		        ->setLabel('Renew Domains')
		        ->setOrder(6);
			}
	    }
	}

 

Link to comment
Share on other sites

2 hours ago, projectmyst said:

I'm trying to add active domains badge via hooks, but I'm not having much luck. Does anyone how I can achieve this?

in your code, how were you defining $badges ? I think that will have been your issue...

try the following hook, it should work...

<?php

use WHMCS\View\Menu\Item as MenuItem;

add_hook('ClientAreaPrimaryNavbar', 1, function (MenuItem $primaryNavbar) {
	
	$client = Menu::context('client');
	$primaryNavbar->addChild('Domains')->setLabel(Lang::trans('navdomains'))->setOrder(97);
	if (!is_null($client)) {
		$domaincount = $client->domains->count();
		$primaryNavbar->getChild('Domains')->addChild('My Domains')->setUri('clientarea.php?action=domains')->setLabel(Lang::trans('clientareanavdomains'))->setBadge($domaincount)->setOrder(1);
		$primaryNavbar->getChild('Domains')->addChild('Divider-My Domains')->setUri('#')->setLabel('-----')->setClass('nav-divider')->setOrder(2);
		$primaryNavbar->getChild('Domains')->addChild('Divider-Renew Domains')->setUri('#')->setLabel('-----')->setClass('nav-divider')->setOrder(5);
		$primaryNavbar->getChild('Domains')->addChild('Renew Domains')->setUri('cart.php?gid=renewals')->setLabel(Lang::trans('navrenewdomains'))->setOrder(6);
	}
	$primaryNavbar->getChild('Domains')->addChild('Register a New Domain')->setUri('cart.php?a=add&domain=register')->setLabel(Lang::trans('navregisterdomain'))->setIcon('fas fa-envelope-open')->setOrder(3);
	$primaryNavbar->getChild('Domains')->addChild('Transfer a Domain to Us')->setUri('cart.php?a=add&domain=transfer')->setLabel(Lang::trans('navtransferdomain'))->setIcon('fas fa-envelope-open')->setOrder(4);
});

even the above code could be trimmed further, but it should be enough to get you on your way... 🙂

Link to comment
Share on other sites

Hi brian

 

How can I make it to just show the actives ones and not the totals. For example, only active domains and not total, active services and not total, due invoices and not total and so on. This is the code that I have so far.

// Badge Count
if (!is_null($client)) {
    $domainscount = $client->domains->count();
    $servicescount = $client->services->count();
    $invoicescount = $client->invoices->count();
    $ticketscount = $client->tickets->count();
    $quotescount = $client->quotes->count();
    // Funds
    $currencydata = getCurrency($client->id);
    $creditcount = formatCurrency($client->credit, $currencydata);
}

// Cart Count Badge
$itemsincart = (count($_SESSION['cart']['products']) + count($_SESSION['cart']['domains']));

 

Edited by projectmyst
Link to comment
Share on other sites

3 hours ago, projectmyst said:

How can I make it to just show the actives ones and not the totals. For example, only active domains and not total, active services and not total, due invoices and not total and so on. This is the code that I have so far.

for domains...

$domainscount = $client->domains()->where('status','Active')->count();

for services...

$servicescount = $client->services()->where('domainstatus','Active')->count();

note that 'due' is a little more awkward because there isn't a "due" status, so they're effectively unpaid invoices where today is before/equal the due date... if today is after the due date, then they're overdue...

if you just wanted an unpaid invoices count...

$invoicescount = $client->invoices()->unpaid()->count();

or overdue invoices...

$invoicescount = $client->invoices()->overdue()->count();

so to get a due value, you would either use the due date in the query and compare it to today... or you could take the overdue count value from the unpaid count value and that should give you a due count value.

Edited by brian!
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated