You are here

function activity_buddy_activity in Activity 5

Same name and namespace in other branches
  1. 5.2 activity.module \activity_buddy_activity()

function to get all buddy activity @returns array of activity

3 calls to activity_buddy_activity()
activity_block in ./activity.module
create a block for display
activity_feed in ./activity.module
menu callback to return a feed of a signed in user's activity page
activity_page in ./activity.module
Menu callback to display the records in a page

File

./activity.module, line 174
Activity module: Allow users to see their friends' activity on the site.

Code

function activity_buddy_activity($account_id) {
  $buddies = array();
  $buddy_activity = array();

  // took activity_account from here
  $account = activity_account($account_id);

  #dsm($account, 'account returned after activity_account()');
  switch ($_GET['who']) {
    case 'me':

      // show what current user has done
      global $user;
      $me['uid'] = $user->uid;
      $me['name'] = $user->name;
      $me['mail'] = $user->mail;
      $me['online'] = 1;
      array_push($buddies, $me);
      break;
    case 'friends':

      // find who current user's buddies are = obj
      // $account must be int
      $buddies = buddylist_get_buddies($account);
      break;
    default:

      // find who current user's buddies are = obj
      $accounts = buddylist_get_buddies($account_id);

      // add current user to list of buddies
      foreach ($accounts as $account) {
        $account['online'] = 1;

        #dsm($account, 'account default');
        array_push($buddies, $account);

        #dsm($buddies, 'array push');
      }
      break;
  }

  #dsm($buddies, 'emty?');

  // see what activity each buddy has done
  if (!empty($buddies)) {
    foreach ($buddies as $buddy) {

      #dsm($buddy, 'buddy in loop');
      $query = db_query("SELECT * FROM {activity} WHERE uid = %d ORDER BY timestamp DESC", $buddy['uid']);
      while ($row = db_fetch_object($query)) {

        #dsm($row, 'row');

        // appending count to make the time stamp unique for sorting purposes
        $buddy_activity[$row->timestamp . $count] = $row;
        $count++;
      }
    }
  }

  // TODO: get this message from a setting
  $msg = 'buddy emtpy string';
  $buddy_activity = empty($buddy_activity) ? $msg : $buddy_activity;
  if (is_array($buddy_activity)) {
    return $buddy_activity;
  }
  else {
    return array(
      $msg,
    );
  }
}