You are here

function flag_lists_get_user_flags in Flag Lists 7

Same name and namespace in other branches
  1. 6 flag_lists.module \flag_lists_get_user_flags()
  2. 7.3 flag_lists.module \flag_lists_get_user_flags()

Get a single user's lists, and merge in flag module flags

4 calls to flag_lists_get_user_flags()
flag_lists_generate_lists_form_submit in ./flag_lists.admin.inc
Submit handler for flag_lists_generate_lists_form.
flag_lists_ops_form in ./flag_lists.module
Add the Flag list select menu widget.
theme_flag_lists_list in ./flag_lists.module
theme_flag_lists_user_page in ./flag_lists.module
Theme the output for a user flag administration page.

File

./flag_lists.module, line 929
The Flag Lists module.

Code

function flag_lists_get_user_flags($content_type = NULL, $account = NULL, $use_flags = FALSE) {
  $flags = array();
  $lists = array();
  if (!isset($account)) {
    $account = $GLOBALS['user'];
  }

  // Get flag lists flags
  $query = db_select('flag_lists_flags', 'fl')
    ->fields('fl')
    ->condition('fl.uid', $account->uid);
  $query
    ->leftJoin('flags', 'f', 'fl.pfid = f.fid');
  $query
    ->leftJoin('flag_lists_types', 'ft', 'ft.name = f.name');
  $query
    ->addField('ft', 'type');
  if ($content_type) {
    $query
      ->condition('ft.type', $content_type);
  }
  $result = $query
    ->execute();
  foreach ($result as $row) {
    if (!isset($lists[$row->name])) {
      $lists[$row->name] = flag_flag::factory_by_row($row);
      $lists[$row->name]->module = 'flag_lists';
    }
    else {
      $lists[$row->name]->types[] = $row->type;
    }
  }

  // Get regular flags.
  if ($use_flags) {
    $flags = flag_get_flags('node', $content_type, $account);

    // Strip out any list templates
    foreach ($flags as $key => $flag) {
      if (stristr($flag->name, 'fl_template') !== FALSE) {
        unset($flags[$key]);
      }
    }
  }
  $flags = array_merge($lists, $flags);
  return $flags;
}