Jump to content

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.

 

 

Link to comment
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>";
			}
        }
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