You are here

function _biblio_get_authors in Bibliography Module 6

Same name and namespace in other branches
  1. 6.2 includes/biblio.pages.inc \_biblio_get_authors()
  2. 7 includes/biblio.pages.inc \_biblio_get_authors()
  3. 7.2 includes/biblio.pages.inc \_biblio_get_authors()
1 call to _biblio_get_authors()
biblio_author_page in ./biblio.pages.inc

File

./biblio.pages.inc, line 1123

Code

function _biblio_get_authors($filter = NULL) {
  global $user;
  $where = array();
  $where_clause = '';
  $base = variable_get('biblio_base', 'biblio');
  $menu = menu_get_active_title();
  if ($menu == 'Authors') {
    $path = $base . '/authors/';
  }
  if ($menu == 'Biblio settings') {
    $path = 'admin/settings/biblio/author/list/';
  }
  if ($filter) {
    $filter = strtoupper($filter);
    $where[] = "UPPER(SUBSTRING(lastname,1,1)) = '%s' ";
    $header_ext = t(' (whose last name starts 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 bd.cid, bd.drupal_uid, bd.name, bd.lastname,
                              bd.firstname, bd.prefix, bd.suffix, bd.initials,
                              bd.affiliation, bd.md5, COUNT(*) AS cnt
                            FROM {biblio_contributor} b
                                 LEFT JOIN {biblio_contributor_data} bd ON b.cid = bd.cid
                                 INNER JOIN {node} n on n.vid = b.vid
                            ' . $where_clause . '
                            GROUP BY bd.cid, bd.drupal_uid, bd.name, bd.lastname,
                                     bd.firstname, bd.prefix, bd.suffix,
                                     bd.initials, bd.affiliation, bd.md5
                            HAVING COUNT(*) > 0
                            ORDER BY  lastname ASC, SUBSTRING(firstname,1,1) ASC,
                            initials ASC', $filter);
  while ($author = db_fetch_array($db_result)) {
    $authors[] = $author;
  }
  return $authors;
}