User login

Lighter weight biblio_load_contributors

Somehow I wrote the explanatory text for the function twice. It seems far too much for a small function so we're pulling out the philosophy and putting it here, for now.

<?php
/**
 * Return array of single words from the contributor fields of biblio content.
 *
 * This is just a stripped down version of biblio_load_contributors, used as a
 * helper module for our implementation of hook_cron which creates an index of
 * keywords from the titles and authors of biblio nodes.
 *
  // we could get d.lastname, d.firstname in the query above, but if we
  // are going to split on spaces just in case there are multiple firstnames
  // or lastnames, we can just grab and split the single combined name field.
 * This could probably be done more efficiently as part of the main query,
 * using concat or something to make the authors one big field, but this is
 * cleaner.  @REVIEW
 *
 * @param vid
 *   The revision ID of a biblio node.
 * @return
 *   An array of keywords from the contributors (authors) to a biblio node.
 */
//  $query = 'SELECT bcd.name FROM {biblio_contributor} bc, {biblio_contributor_data} bcd WHERE bc.vid = %d AND bc.cid = bcd.cid;';

/**
 * Load contributors (authors) for a given biblio node version id.
 *
 * This will be faster than biblio_load_contributors() not because it selects
 * fewer fields but because it defines the fields and doesn't use an asterisk.
 */
function biblioreference_load_contributors($vid) {
  $contributors = array();
  $query = "SELECT lastname, firstname, initials, prefix
      FROM {biblio_contributor} bc
            INNER JOIN {biblio_contributor_data} bcd ON bc.cid=bcd.cid
            WHERE bc.vid=%d
            ORDER BY bc.rank ASC"; // do not change order of presentation
  $result = db_query($query, $vid);
  while ($creator = db_fetch_array($result)) {
    $contributors[] = $creator;
  }
  return $contributors;
}
?>

Resolution

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • You can use Markdown syntax to format and style the text. Also see Markdown Extra for tables, footnotes, and more.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img> <blockquote> <small> <h2> <h3> <h4> <h5> <h6> <sub> <sup> <p> <br> <strike> <table> <tr> <td> <thead> <th> <tbody> <tt> <output>
  • Lines and paragraphs break automatically.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.