- Leaderboard
  thoughts:
    - Can be tied to a location
      (checkin N different times at one location)
    - Can be tied to activities
      (hike 5 different trails)
    - Can be tied to number of checkins
      (N checkins gets badge A)
      (N*2 checkins get badge B)
    - Can be tied to number of friends
      N Friends gets a badge
    - Can be tied to number of reviews
    : use an abstract base class
      - new class for each leaderboard type
      - get leaderboards
      
     
  properties:
    - name,
    - type
    - create date
    - userlist
      - uid
      - score
    - data (store the criteria)

  class leaderboard_operations
    : get_leaderboards()

  api:
    edit_member($uid,$score);
    remove_member($uid);
    get_member_rank($uid);
    get_member_score($uid);
    get_member_stats($uid);

    get_user_rankings($uid_list);

    count_members();
    count_members_in_range($min,$max)
    
    remove_members_in_range($min,$max);
    get_leaders();
    
- LeaderboardOperations 
  api:
     static create ($name);
     static delete ($name);
     static get_info ($name);

- Leaderboard Processing
  : When a checkin is saved, and is approved
    - send OnCheckin event

  : OnCheckin event handler
    if checkin is approved
    1. find matching leaderboards
    * Process leaderboards
      
      - for each leaderboard
        if( leaderboard matches ) (see A: below)
          increase score
          check badges (see B: below)
    
    ** A: test if leaderboard matches
      switch leaderboard type:
       location
         if checkin location matches the board location
         if checkin location is in board category id(s)
         if checkin location is in board category hierarchy, or children?
       activity
         if a checkin activity matches board activity(s), or children       
       checkins
         count gross checkins
       friends
         count gross friends
         

    ** B: check badges
      : need user score
      for each badge attached to location
        if user score > min score
          Store badge in database
          Send NewBadgeAwarded Event (user,leaderboard,badge)

 : NewBadgeAwarded Event
   send our messages out to social networks
      
================================================================

- Badges
  properties:
    - id
    - leaderboard id
    - name
    - create date
    - image
    - notes
    - min score
    - max score?
    - unique (only one person can have this badge).

  badge owners
    - badge id
    - owner id
    - created

  api:
     static create_basge()
     static delete_badge()
     static list_badges()
     static get_badge()
     
     get_user_badges($uid);
     get_badge_owner($badge_id);
     
     process_badges($uid);
     remove_badge_from_user($uid,$badge_id);


$leaderboard->get_badges();
$leaderboard->add_badge();


$badge->save();
$badge->delete();
$badge->get_owners();

$user->get_badges();

// more api functions
$location->get_leaderboards();
$user->get_badges();
