You are here

function _biblio_get_keywords in Bibliography Module 6

Same name and namespace in other branches
  1. 6.2 includes/biblio.pages.inc \_biblio_get_keywords()
  2. 7 includes/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 ./biblio.pages.inc

File

./biblio.pages.inc, line 1221

Code

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

    //show only published entries to everyone except admin
    $where[] = 'n.status = 1 ';
  }
  if (variable_get('biblio_view_only_own', 0)) {

    //show only authors that belong to nodes that the user has access to
    $where[] = "n.uid = {$user->uid}";
  }
  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 HAVING COUNT(*) > 0
                         ORDER BY  word ASC', $filter);
  while ($keyword = db_fetch_object($db_result)) {
    $keywords[] = $keyword;
  }
  return $keywords;
}