Agaric Design Collective

Lighter weight biblio_load_contributors

By Benjamin Melançon
on 05 Apr
0 comments

Description

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;
}
?>

 

Post new comment
The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <blockquote> <h1> <h2> <h3> <h4> <h5> <h6> <small> <pre> <strike> <sub> <sup> <kbd> <s>
  • Lines and paragraphs break automatically.
  • Web page addresses and e-mail addresses turn into links automatically.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Copy the characters (respecting upper/lower case) from the image.