You are here

function _biblio_get_authors in Bibliography Module 7

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

File

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

Code

function _biblio_get_authors($filter = NULL) {
  global $user;
  $where = array();
  $authors = array();
  $where_clause = '';
  $output = '';
  if ($filter) {
    $filter = strtoupper($filter);
    $where['filter'] = "UPPER(SUBSTRING(lastname,1,1)) = :filter ";
    $header_ext = t(' (whose last name starts with the letter "@letter") ', array(
      '@letter' => $filter,
    ));
  }
  else {
    $query_ext = NULL;
    $header_ext = NULL;
  }
  if (!biblio_access('edit_author')) {
    $where['access'] = 'n.status = 1 ';
  }

  //show only published entries to everyone except admin
  if (count($where)) {
    $where_clause = 'WHERE (' . implode(') AND (', $where) . ')';
  }
  $query = db_select('biblio_contributor_data', 'bcd')
    ->fields('bcd', array(
    'lastname',
    'firstname',
    'alt_form',
  ))
    ->groupBy('lastname')
    ->groupBy('firstname')
    ->groupBy('alt_form')
    ->having('COUNT(*) > 1');
  if ($filter) {
    $filter = strtoupper($filter);
    $query
      ->where("UPPER(SUBSTRING(lastname,1,1)) = :filter ", array(
      ':filter' => $filter,
    ));
  }
  $result = $query
    ->execute();
  $suspects = array();
  foreach ($result as $author) {
    $suspects[] = $author->lastname;
  }
  $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, bd.literal,
                                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, bd.literal
                            ORDER BY  lastname ASC, SUBSTRING(firstname,1,1) ASC,
                            initials ASC', array(
    ':filter' => $filter,
  ));
  foreach ($db_result as $author) {
    if (array_search($author->lastname, $suspects) !== FALSE) {
      $author->suspect = TRUE;
    }
    $authors[] = $author;
  }
  return $authors;
}