You are here

function drupagram_drupagram_accounts in Drupagram 7

Same name and namespace in other branches
  1. 6 drupagram.module \drupagram_drupagram_accounts()

Implements hook_drupagram_accounts(). We want to move this into a separate module eventually, but sticking the code here and using a hook lets other modules solve the 'what accounts can a user post with' problem in cleaner ways.

Return value

array with Instagram accounts

File

./drupagram.module, line 287
Provides API integration with the Instagram microblogging service.

Code

function drupagram_drupagram_accounts($account) {
  module_load_include('inc', 'drupagram');
  $query = db_select('drupagram_account', 'da')
    ->fields('da', array(
    'drupagram_id',
  ));
  if (user_access('use global drupagram account', $account)) {
    $or = db_or();
    $or
      ->condition('da.uid', $account->uid);
    $or
      ->condition('da.is_global', 1);
    $query
      ->condition($or);
  }
  else {
    $query
      ->condition('da.uid', $account->uid);
  }
  $drupagram_accounts = array();
  foreach ($query
    ->execute()
    ->fetchCol() as $drupagram_id) {
    $drupagram_accounts[] = drupagram_account_load($drupagram_id);
  }
  return $drupagram_accounts;
}