class Creators in Bibliography Module 6
Same name and namespace in other branches
Hierarchy
- class \PARSECREATORS
- class \Creators
Expanded class hierarchy of Creators
File
- bibtexParse/
PARSECREATORS.php, line 2
View source
class Creators extends PARSECREATORS {
protected $authors = array();
private $existing_authors = array();
protected $typeMap = array();
private $md5 = array();
function Creators($init = null) {
$this
->buildTypeMap();
if (is_array($init)) {
$this
->setCreators($init);
}
elseif (is_numeric($init)) {
$this
->loadCreators($init);
}
}
function buildTypeMap() {
$result = db_query("SELECT * FROM {biblio_contributor_type} ;");
while ($type = db_fetch_object($result)) {
$this->typeMap[$type->type] = $type->ctid;
}
}
function getCreatorByName($name) {
$result = db_query('SELECT *
FROM {biblio_contributor_data}
WHERE lastname RLIKE "[[:<:]]%s[[:>:]]" ', $name);
}
function getCreatorCount() {
return count($this->authors);
}
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);
}
}
}
function getAuthorArray() {
return $this->authors;
}
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
*/
function setCreators($authors) {
foreach ($authors as $author) {
if (strlen(trim($author['name']))) {
$this->authors[] = $this
->parseAuthor($author['name'], $author['type']);
}
}
}
function setCreator($author, $type = 'author') {
$this->authors[] = $this
->parseAuthor($author, $type);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
Creators:: |
protected | property | ||
Creators:: |
private | property | ||
Creators:: |
private | property | ||
Creators:: |
protected | property | ||
Creators:: |
function | |||
Creators:: |
function | |||
Creators:: |
function | |||
Creators:: |
function | |||
Creators:: |
function | |||
Creators:: |
function | |||
Creators:: |
function | |||
Creators:: |
public | function | ||
Creators:: |
private | function | ||
Creators:: |
public | function | ||
Creators:: |
function | |||
Creators:: |
function | update object with an array of authors | ||
PARSECREATORS:: |
function | |||
PARSECREATORS:: |
function | |||
PARSECREATORS:: |
function | |||
PARSECREATORS:: |
function | |||
PARSECREATORS:: |
function | |||
PARSECREATORS:: |
function | |||
PARSECREATORS:: |
function |