API/Lite question

Discussion in 'aMember Pro v.4' started by boernerrha, Dec 23, 2011.

  1. boernerrha

    boernerrha aMember Pro Customer

    Joined:
    Nov 16, 2011
    Messages:
    28
    API Lite is a pretty useful tool. Is there a possibility of adding some aggregate functions? In particular I would like an Am_Lite::COUNT() for each product/subscription and for non-product users category, to give me total number of subscribers in each one.
  2. boernerrha

    boernerrha aMember Pro Customer

    Joined:
    Nov 16, 2011
    Messages:
    28
    Nevermind, it turned out to be pretty easy to add a function in Lite.php to do this.
  3. thehpmc

    thehpmc Member

    Joined:
    Aug 24, 2006
    Messages:
    901
    Might be interesting to others if you included the code you used.
  4. boernerrha

    boernerrha aMember Pro Customer

    Joined:
    Nov 16, 2011
    Messages:
    28
    Add this function to Lite.php, call it from your page with (for example):

    $active = 1;

    print_r(Am_Lite::getInstance()->getActiveMemberCount($active));

    public function getActiveMemberCount($status)
    {

    // $status 0 : pending, 1:active, 2:expired

    $membercount = 0;

    $result = $this->query("SELECT count(*) as membercount FROM ?_user where status = $status");

    $result = $result->fetch();

    $membercount = $result['membercount'];
    // but use a foreach loop if your query returns more than a single value - plenty of examples in the
    Lite.php file.

    return $membercount;
    }

Share This Page