You are here

class Creators in Bibliography Module 7

Same name and namespace in other branches
  1. 6.2 modules/bibtexParse/PARSECREATORS.php \Creators
  2. 6 bibtexParse/PARSECREATORS.php \Creators
  3. 7.3 plugins/biblio_style/bibtex/PARSECREATORS.php \Creators
  4. 7.2 modules/bibtexParse/PARSECREATORS.php \Creators

Hierarchy

Expanded class hierarchy of Creators

File

modules/bibtexParse/PARSECREATORS.php, line 11
Classes Creators and PARSECREATORS.

View source
class Creators extends PARSECREATORS {
  protected $authors = array();
  private $existing_authors = array();
  protected $typeMap = array();
  private $md5 = array();

  /**
   *
   */
  public function __construct($init = NULL) {
    $this
      ->buildTypeMap();
    if (is_array($init)) {
      $this
        ->setCreators($init);
    }
    elseif (is_numeric($init)) {
      $this
        ->loadCreators($init);
    }
  }

  /**
   *
   */
  public function buildTypeMap() {
    $result = db_query("SELECT * FROM {biblio_contributor_type} ;");
    while ($type = db_fetch_object($result)) {
      $this->typeMap[$type->type] = $type->ctid;
    }
  }

  /**
   *
   */
  public function getCreatorByName($name) {

    // [[:<:]], [[:>:]] These stand for word boundaries; see biblio.pages.inc.
    $result = db_query('SELECT *
                    FROM {biblio_contributor_data}
                    WHERE lastname RLIKE :lastname', array(
      'lastname' => '[[:<:]]' . preg_quote($name) . '[[:>:]]',
    ));
  }

  /**
   *
   */
  public function getCreatorCount() {
    return count($this->authors);
  }

  /**
   *
   */
  public function getCreatorString() {
    foreach ($this->authors as $key => $author) {
      $author_array[$author['rank']] = $author['firstname'] . ' ' . $author['initials'] . ' ' . $author['lastname'];
    }
    ksort($author_array);
    return implode(',  ', $author_array);
  }

  /**
   *
   */
  private function loadMD5() {
    $result = db_query('SELECT md5,cid  FROM {biblio_contributor_data} ');
    while ($row = db_fetch_array($result)) {
      $this->md5[$row['cid']] = $row['md5'];
    }
  }

  /**
   *
   */
  public function loadCreators($vid) {
    $query = 'SELECT bcd.lastname, bcd.firstname, bcd.initials,
             bcd.affiliation, bct.type, bc.rank
          FROM    {biblio_contributor} bc,
           {biblio_contributor_data} bcd,
           {biblio_contributor_type} bct
          WHERE bc.vid = %d
             AND bc.cid = bcd.cid
             AND  bc.ctid = bct.ctid
          ORDER BY bc.ctid ASC, bc.rank ASC;';
    $result = db_query($query, array(
      $vid,
    ));
    while ($creator = db_fetch_array($result)) {
      $this->authors[] = $creator;
    }
  }

  /**
   *
   */
  public function saveCreators($nid, $vid) {
    if (!empty($this->authors)) {
      $this
        ->loadMD5();
      db_query('DELETE FROM {biblio_contributor} WHERE nid = %d AND vid = %d', $nid, $vid);
      foreach ($this->authors as $rank => $author) {
        if (empty($author['cid']) && !empty($this->md5)) {
          $author['cid'] = array_search($author['md5'], $this->md5);
        }
        if (empty($author['cid'])) {
          drupal_write_record('biblio_contributor_data', $author);
          $cid = db_last_insert_id('biblio_contributor_data', 'cid');
        }
        else {
          $cid = $author['cid'];
        }
        $link_array = array(
          'nid' => $nid,
          'vid' => $vid,
          'cid' => $cid,
          'rank' => $rank,
          'ctid' => $author['type'],
        );
        drupal_write_record('biblio_contributor', $link_array);
      }
    }
  }

  /**
   *
   */
  public function getAuthorArray() {
    return $this->authors;
  }

  /**
   *
   */
  public function getAuthor($rank) {
    return $this->authors[$rank];
  }

  /**
   * Update object with an array of authors.
   *
   * @param $authors
   *   an array containing two keys "name" and "type"
   *   the name is the full name of the contributor which will be parsed into
   *   component pieces, and type contains a string indicating the author type
   */
  public function setCreators($authors) {
    foreach ($authors as $author) {
      if (strlen(trim($author['name']))) {
        $this->authors[] = $this
          ->parseAuthor($author['name'], $author['type']);
      }
    }
  }

  /**
   *
   */
  public function setCreator($author, $type = 'author') {
    $this->authors[] = $this
      ->parseAuthor($author, $type);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Creators::$authors protected property
Creators::$existing_authors private property
Creators::$md5 private property
Creators::$typeMap protected property
Creators::buildTypeMap public function
Creators::getAuthor public function
Creators::getAuthorArray public function
Creators::getCreatorByName public function
Creators::getCreatorCount public function
Creators::getCreatorString public function
Creators::loadCreators public function
Creators::loadMD5 private function
Creators::saveCreators public function
Creators::setCreator public function
Creators::setCreators public function Update object with an array of authors.
Creators::__construct public function
PARSECREATORS::grabFirstnameInitials public function Grab firstname and initials which may be of form "A.B.C." or "A. B. C. " or " A B C " etc.
PARSECREATORS::grabSurname public function Surname may have title such as 'den', 'von', 'de la' etc. - characterised by first character lowercased. Any uppercased part means lowercased parts following are part of the surname (e.g. Van den Bussche)
PARSECREATORS::md5sum public function
PARSECREATORS::parse public function
PARSECREATORS::parseArray public function
PARSECREATORS::parseAuthor public function Create writer arrays from bibtex input.