| 1 |
<?php |
<?php |
| 2 |
//$Id: biblio.contributors.inc,v 1.18 2009/10/23 20:19:37 rjerome Exp $ |
//$Id: biblio.contributors.inc,v 1.18.2.1 2009/10/26 13:04:29 rjerome Exp $ |
| 3 |
/** |
/** |
| 4 |
* @param $aid |
* @param $aid |
| 5 |
* @return unknown_type |
* @return unknown_type |
| 97 |
*/ |
*/ |
| 98 |
function _save_contributors($contributors, $nid, $vid, $update = FALSE) { |
function _save_contributors($contributors, $nid, $vid, $update = FALSE) { |
| 99 |
$md5 = _loadMD5(); |
$md5 = _loadMD5(); |
| 100 |
db_query('DELETE FROM {biblio_contributor} WHERE nid = %d AND vid = %d', array($nid, $vid)); |
db_query('DELETE FROM {biblio_contributor} WHERE nid = :nid AND vid = :vid', array(':nid' => $nid, ':vid' => $vid)); |
| 101 |
foreach ($contributors as $cat => $authors) { |
foreach ($contributors as $cat => $authors) { |
| 102 |
foreach ($authors as $key => $author) { |
foreach ($authors as $key => $author) { |
| 103 |
|
$auth_type = $author['auth_type']; |
| 104 |
|
unset ($author['auth_type']); |
| 105 |
if ($update && !empty($author['cid'])) $author['cid'] = null; // null out the cid so we don't do a global change |
if ($update && !empty($author['cid'])) $author['cid'] = null; // null out the cid so we don't do a global change |
| 106 |
if (empty ($author['cid']) && !empty ($md5)) |
if (empty ($author['cid']) && !empty ($md5)) |
| 107 |
$author['cid'] = array_search($author['md5'], $md5); |
$author['cid'] = array_search($author['md5'], $md5); |
| 108 |
if (empty ($author['cid'])) { |
if (empty ($author['cid'])) { |
| 109 |
if (!drupal_write_record('biblio_contributor_data', $author)) return false; |
unset ($author['cid']); |
| 110 |
$cid = db_last_insert_id('biblio_contributor_data', 'cid'); |
$cid = db_insert('biblio_contributor_data')->fields($author)->execute(); |
| 111 |
|
if (!$cid) return false; |
| 112 |
} else { |
} else { |
| 113 |
$cid = $author['cid']; |
$cid = $author['cid']; |
| 114 |
} |
} |
| 117 |
'vid' => $vid, |
'vid' => $vid, |
| 118 |
'cid' => $cid, |
'cid' => $cid, |
| 119 |
'rank' => (isset($author['rank']) && is_numeric($author['rank'])) ? $author['rank'] : $key, |
'rank' => (isset($author['rank']) && is_numeric($author['rank'])) ? $author['rank'] : $key, |
| 120 |
'auth_type' => $author['auth_type'], |
'auth_type' => $auth_type, |
| 121 |
'auth_category' => $cat, |
'auth_category' => $cat, |
| 122 |
); |
); |
| 123 |
|
|
| 297 |
function _loadMD5() { |
function _loadMD5() { |
| 298 |
static $md5 = array(); |
static $md5 = array(); |
| 299 |
static $count =0; |
static $count =0; |
| 300 |
$db_count = db_result(db_query("SELECT COUNT(*) FROM {biblio_contributor_data}")); |
$db_count = db_query("SELECT COUNT(*) FROM {biblio_contributor_data}")->fetchCol();; |
| 301 |
if ($db_count > $count){ |
if ($db_count > $count){ |
| 302 |
$count = $db_count; |
$count = $db_count; |
| 303 |
$result = db_query('SELECT md5,cid FROM {biblio_contributor_data} '); |
$result = db_query('SELECT md5,cid FROM {biblio_contributor_data} '); |
| 304 |
while ($row = db_fetch_array($result)) { |
foreach ($result as $row ) { |
| 305 |
$md5[$row['cid']] = $row['md5']; |
$md5[$row->cid] = $row->md5; |
| 306 |
} |
} |
| 307 |
} |
} |
| 308 |
return (count($md5)) ? $md5 : NULL; |
return (count($md5)) ? $md5 : NULL; |