Jump to content
zarvis

Passing parameter to internal API

Recommended Posts

Hello,

 

I am trying to make a widget and in that  I am using Internal API to fetch the product wth status suspended and due date greater than today.

<?php

use WHMCS\Database\Capsule;

add_hook('AdminHomeWidgets', 1, function() {
    return new HelloWorldWidget();
});

/**
 * Hello World Widget.
 */
class HelloWorldWidget extends \WHMCS\Module\AbstractWidget
{
    protected $title = 'Hello World';
    protected $description = '';
    protected $weight = 150;
    protected $columns = 1;
    protected $cache = false;
    protected $cacheExpiry = 120;
    protected $requiredPermission = '';

    public function getData()
    {
        $command = 'GetClientsProducts';
		$postData = array(
			'status' => 'Suspended',
			//nextsuedate should be greater than today
		);
		
		$products = localAPI($command, $postData);
		//$products = localAPI('GetClientsProducts', []);

        return array(
            'welcome' => 'Hello World!',
            'products' => $products['products'],
        );
    }
	
	
    public function generateOutput($data)
    {
        $clientOutput = [];
        foreach ($data['products']['product'] as $product) {
            $clientOutput[] = "<a href=\"clientsservices.php?id={$product['id']}\">{$product['id']}</a>";
        }

        if (count($clientOutput) == 0) {
            $clientOutput[] = 'No Clients Found';
        }

        $clientOutput = implode('<br>', $clientOutput);

        return <<<EOF
<div class="widget-content-padded">
    <div>{$data['welcome']}</div>
    <div id="sampleWidgetClientOutput">{$clientOutput}</div>
</div>
EOF;
    }
}

I tried with just status as suspended but it is returning all the orders.

 

 

Share this post


Link to post
Share on other sites

Hello, 

Please contact us for any WHMCS development here

Hope to hear from your

Share this post


Link to post
Share on other sites
On 19/07/2019 at 09:05, zarvis said:

I tried with just status as suspended but it is returning all the orders.

as I think it's supposed to.

just add an if statement to the $clientoutput loop and your array should only contain suspended services....

        $clientOutput = [];
        foreach ($data['products']['product'] as $product) {
			if ($product['status'] == 'Suspended') {
				$clientOutput[] = "<a href=\"clientsservices.php?id={$product['id']}\">{$product['id']}</a>";
			}
        }

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×

Important Information

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