How to display/use a subscriber's starting subscription date

Discussion in 'aMember Pro v.4' started by crogue, Dec 18, 2011.

  1. crogue

    crogue New Member

    Joined:
    Dec 17, 2011
    Messages:
    13
    I have a membership site that drip-feeds content by week. I needed a way for users to see a list of what stuff they had access to and what they didn't (yet).

    in Amember v3 a subscriber could see incremental links based off of their subscriber date while looking at their user panel. in v4 that functionality isn't handled the same way.

    So I submitted a feature request, and wished that there was a function for little old me.

    then I looked at http://www.amember.com/docs/API/Lite, and thought "Holy f***balls, that is SO much better than the session() way that it was handled in v3."

    Then I looked at Lite.php, noticed that it already had a getExpire() function, and thought "wait, I might be able to write this myself, since I am handsome and awesome." (I can't remember my exact thoughts, but it was probably something along those lines)

    Anyway, if you want to display a subscriber's starting date (2011-10-12 for instance) or use that date to create a customized display, here's how you do it:

    Just add the following code to amember/library/Am/Lite.php:
    PHP:
        /** @@@ by crogue **
        * Retrieve earliest subscription date for selected products
        * for logged-in user
        *
        * @param <type> $search
        * @return string|null date in SQL format YY-mm-dd
        */
        
    public function getBegin($search self::ANY)
        {
            
    $begin '2037-12-31';
            if (
    $this->hasIdentity())
            {
                
    $accessRecors $this->_getAccessRecords($search);
                
    print_r ($accessRecors);
                foreach (
    $accessRecors as $access)
                {
                    if (
    $access['begin_date'] < $begin)
                    {
                        
    $begin $access['begin_date'];
                    }
                }
            }
            if (
    $begin == '2037-12-31')
                
    $begin null;
            return 
    $begin;
        }
    and call it on your page with something like
    PHP:
    require_once '/home/user/public_html/amember/library/Am/Lite.php';
    echo 
    Am_Lite::getInstance()->getBegin($search)  ; //$search info at http://www.amember.com/docs/API/Lite
    Hope this helps someone!

Share This Page