You are here

function _biblio_get_keywords in Bibliography Module 7

Same name and namespace in other branches
  1. 6.2 includes/biblio.pages.inc \_biblio_get_keywords()
  2. 6 biblio.pages.inc \_biblio_get_keywords()
  3. 7.2 includes/biblio.pages.inc \_biblio_get_keywords()
1 call to _biblio_get_keywords()
biblio_keyword_page in includes/biblio.pages.inc

File

includes/biblio.pages.inc, line 1433
Copyright (C) 2006-2011 Ron Jerome.

Code

function _biblio_get_keywords($filter = NULL) {
  global $user;
  $keywords = array();
  $where = array();
  $where_clause = '';
  if ($filter) {
    $filter = strtoupper($filter);
    $where[] = "UPPER(SUBSTRING(word,1,1)) = :filter ";
    $header_ext = t(' (which start with the letter "@letter") ', array(
      '@letter' => $filter,
    ));
  }
  else {
    $query_ext = NULL;
    $header_ext = NULL;
  }
  if ($user->uid != 1) {
    $where[] = 'n.status = 1 ';
  }

  //show only published entries to everyone except admin
  if (count($where)) {
    $where_clause = count($where) > 1 ? 'WHERE (' . implode(') AND (', $where) . ')' : 'WHERE ' . $where[0];
  }
  $db_result = db_query('SELECT bkd.kid, bkd.word, COUNT(*) AS cnt
                         FROM {biblio_keyword} bk
                         LEFT JOIN {biblio_keyword_data} bkd ON bkd.kid = bk.kid
                         INNER JOIN {node} n ON n.vid = bk.vid
                         ' . $where_clause . '
                         GROUP BY bkd.kid, bkd.word
                         ORDER BY  word ASC', array(
    ':filter' => $filter,
  ));
  foreach ($db_result as $keyword) {
    $keywords[] = $keyword;
  }
  return $keywords;
}