tripal_pub.api.inc

  1. 2.x tripal_pub/api/tripal_pub.api.inc
  2. 1.x tripal_pub/api/tripal_pub.api.inc

The Tripal Pub API

tripal_pub_api Publication Module API

File

tripal_pub/api/tripal_pub.api.inc
View source
  1. <?php
  2. /**
  3. * @file
  4. * The Tripal Pub API
  5. *
  6. * @defgroup tripal_pub_api Publication Module API
  7. * @ingroup tripal_api
  8. */
  9. /*
  10. * Retrieves a list of publications as an associated array where
  11. * keys correspond directly with Tripal Pub CV terms.
  12. *
  13. * @param remote_db
  14. * The name of the remote publication database to query. These names should
  15. * match the name of the databases in the Chado 'db' table. Currently
  16. * supported databass include
  17. * 'PMID': PubMed
  18. *
  19. * @param search_array
  20. * An associate array containing the search criteria. The following key
  21. * are expected
  22. * 'remote_db': Specifies the name of the remote publication database
  23. * 'num_criteria': Specifies the number of criteria present in the search array
  24. * 'days': The number of days to include in the search starting from today
  25. * 'criteria': An associate array containing the search critiera. There should
  26. * be no less than 'num_criteria' elements in this array.
  27. *
  28. * The following keys are expected in the 'criteria' array
  29. * 'search_terms': A list of terms to search on, separated by spaces.
  30. * 'scope': The fields to search in the remote database. Valid values
  31. * include: 'title', 'abstract', 'author' and 'any'
  32. * 'operation': The logical operation to use for this criteria. Valid
  33. * values include: 'AND', 'OR' and 'NOT'.
  34. * @param $num_to_retrieve
  35. * The number of records to retrieve. In cases with large numbers of
  36. * records to retrieve, the remote database may limit the size of each
  37. * retrieval.
  38. * @param $pager_id
  39. * Optional. This function uses the 'tripal_pager_callback' function
  40. * to page a set of results. This is helpful when generating results to
  41. * be view online. The pager works identical to the pager_query function
  42. * of drupal. Simply provide a unique integer value for this argument. Each
  43. * form on a single page should have a unique $pager_id.
  44. * @param $page
  45. * Optional. If this function is called where the
  46. * page for the pager cannot be set using the $_GET variable, use this
  47. * argument to specify the page to retrieve.
  48. *
  49. * @return
  50. * Returns an array of pubs where each element is
  51. * an associative array where the keys are Tripal Pub CV terms.
  52. *
  53. * @ingroup tripal_pub_api
  54. */
  55. function tripal_pub_get_remote_search_results($remote_db, $search_array,
  56. $num_to_retrieve, $pager_id = 0, $page = 0) {
  57. // manually set the $_GET['page'] parameter to trick the pager
  58. // into giving us the requested page
  59. if (is_int($page) and $page > 0) {
  60. $_GET['page'] = $page;
  61. }
  62. // now call the callback function to get the results
  63. $callback = "tripal_pub_remote_search_$remote_db";
  64. $pubs = array();
  65. if (function_exists($callback)) {
  66. $pubs = call_user_func($callback, $search_array, $num_to_retrieve, $pager_id);
  67. }
  68. return $pubs;
  69. }
  70. /*
  71. * @ingroup tripal_pub_api
  72. */
  73. function tripal_pub_get_raw_data($dbxref) {
  74. if(preg_match('/^(.*?):(.*?)$/', $dbxref, $matches)) {
  75. $remote_db = $matches[1];
  76. $accession = $matches[2];
  77. // check that the database is supported
  78. $supported_dbs = variable_get('tripal_pub_supported_dbs', array());
  79. if(!in_array($remote_db, $supported_dbs)) {
  80. return "Unsupported database: $dbxref";
  81. }
  82. $search = array(
  83. 'num_criteria' => 1,
  84. 'remote_db' => $remote_db,
  85. 'criteria' => array(
  86. '1' => array(
  87. 'search_terms' => "$remote_db:$accession",
  88. 'scope' => 'id',
  89. 'operation' => '',
  90. 'is_phrase' => 0,
  91. ),
  92. ),
  93. );
  94. $pubs = tripal_pub_get_remote_search_results($remote_db, $search, 1, 0);
  95. return '<textarea cols=80 rows=20>' . $pubs[0]['raw'] . '</textarea>';
  96. }
  97. return 'Invalid DB xref';
  98. }
  99. /**
  100. * @ingroup tripal_pub_api
  101. */
  102. function tripal_pub_update_publications($do_contact = FALSE, $dbxref = NULL, $db = NULL) {
  103. // get a persistent connection
  104. $connection = tripal_db_persistent_chado();
  105. if (!$connection) {
  106. print "A persistant connection was not obtained. Loading will be slow\n";
  107. }
  108. // if we cannot get a connection then let the user know the loading will be slow
  109. tripal_db_start_transaction();
  110. if ($connection) {
  111. print "\nNOTE: Loading of publications is performed using a database transaction. \n" .
  112. "If the load fails or is terminated prematurely then the entire set of \n" .
  113. "insertions/updates is rolled back and will not be found in the database\n\n";
  114. }
  115. // get a list of all publications by their Dbxrefs that have supported databases
  116. $sql = "
  117. SELECT DB.name as db_name, DBX.accession
  118. FROM pub P
  119. INNER JOIN pub_dbxref PDBX ON P.pub_id = PDBX.pub_id
  120. INNER JOIN dbxref DBX ON DBX.dbxref_id = PDBX.dbxref_id
  121. INNER JOIN db DB ON DB.db_id = DBX.db_id
  122. ";
  123. $args = array();
  124. if ($dbxref and preg_match('/^(.*?):(.*?)$/', $dbxref, $matches)) {
  125. $dbname = $matches[1];
  126. $accession = $matches[2];
  127. $sql .= "WHERE DBX.accession = '%s' and DB.name = '%s' ";
  128. $args[] = $accession;
  129. $args[] = $dbname;
  130. }
  131. elseif ($db) {
  132. $sql .= " WHERE DB.name = '%s' ";
  133. $args[] = $db;
  134. }
  135. $sql .= "ORDER BY DB.name, P.pub_id";
  136. $results = chado_query($sql, $args);
  137. $num_to_retrieve = 100;
  138. $i = 0; // count the number of IDs. When we hit $num_to_retrieve we'll do the query
  139. $curr_db = ''; // keeps track of the current current database
  140. $ids = array(); // the list of IDs for the database
  141. $search = array(); // the search array passed to the search function
  142. // iterate through the pub IDs
  143. while ($pub = db_fetch_object($results)) {
  144. $accession = $pub->accession;
  145. $remote_db = $pub->db_name;
  146. // here we need to only update publications for databases we support
  147. $supported_dbs = variable_get('tripal_pub_supported_dbs', array());
  148. if(!in_array($remote_db, $supported_dbs)) {
  149. continue;
  150. }
  151. $search = array(
  152. 'num_criteria' => 1,
  153. 'remote_db' => $remote_db,
  154. 'criteria' => array(
  155. '1' => array(
  156. 'search_terms' => "$remote_db:$accession",
  157. 'scope' => 'id',
  158. 'operation' => '',
  159. 'is_phrase' => 0,
  160. ),
  161. ),
  162. );
  163. $pubs = tripal_pub_get_remote_search_results($remote_db, $search, 1, 0);
  164. tripal_pub_add_publications($pubs, $do_contact, TRUE);
  165. $i++;
  166. }
  167. // transaction is complete
  168. tripal_db_commit_transaction();
  169. print "Transaction Complete\n";
  170. // sync the newly added publications with Drupal
  171. print "Syncing publications with Drupal...\n";
  172. tripal_pub_sync_pubs();
  173. // if the caller wants to create contacts then we should sync them
  174. if ($do_contact) {
  175. print "Syncing contacts with Drupal...\n";
  176. tripal_contact_sync_contacts();
  177. }
  178. print "Done.\n";
  179. }
  180. /*
  181. * @ingroup tripal_pub_api
  182. */
  183. function tripal_pub_import_publications($report_email = FALSE, $do_update = FALSE) {
  184. $num_to_retrieve = 100;
  185. $pager_id = 0;
  186. $page = 0;
  187. $num_pubs = 0;
  188. // get a persistent connection
  189. $connection = tripal_db_persistent_chado();
  190. if (!$connection) {
  191. print "A persistant connection was not obtained. Loading will be slow\n";
  192. }
  193. // if we cannot get a connection then let the user know the loading will be slow
  194. tripal_db_start_transaction();
  195. if ($connection) {
  196. print "\nNOTE: Loading of publications is performed using a database transaction. \n" .
  197. "If the load fails or is terminated prematurely then the entire set of \n" .
  198. "insertions/updates is rolled back and will not be found in the database\n\n";
  199. }
  200. // get all of the loaders
  201. $args = array();
  202. $sql = "SELECT * FROM {tripal_pub_import} WHERE disabled = 0 ";
  203. $results = db_query($sql, $args);
  204. $do_contact = FALSE;
  205. $reports = array();
  206. while ($import = db_fetch_object($results)) {
  207. $page = 0;
  208. print "Importing: " . $import->name . "\n";
  209. // keep track if any of the importers want to create contacts from authors
  210. if ($import->do_contact == 1) {
  211. $do_contact = TRUE;
  212. }
  213. $criteria = unserialize($import->criteria);
  214. $remote_db = $criteria['remote_db'];
  215. do {
  216. // retrieve the pubs for this page. We'll retreive 10 at a time
  217. $pubs = tripal_pub_get_remote_search_results($remote_db, $criteria, $num_to_retrieve, $pager_id, $page);
  218. $reports[$import->name] = tripal_pub_add_publications($pubs, $import->do_contact, $do_update);
  219. $page++;
  220. }
  221. // continue looping until we have a $pubs array that does not have
  222. // our requested numer of records. This means we've hit the end
  223. while (count($pubs) == $num_to_retrieve);
  224. }
  225. // transaction is complete
  226. tripal_db_commit_transaction();
  227. print "Transaction Complete\n";
  228. // sync the newly added publications with Drupal. If the user
  229. // requested a report then we don't want to print any syncing information
  230. // so pass 'FALSE' to the sync call
  231. print "Syncing publications with Drupal...\n";
  232. tripal_pub_sync_pubs();
  233. // iterate through each of the reports and generate a final report with HTML links
  234. $HTML_report = '';
  235. if ($report_email) {
  236. $HTML_report .= "<html>";
  237. global $base_url;
  238. foreach ($reports as $importer => $report) {
  239. $total = count($report['inserted']);
  240. $HTML_report .= "<b>$total new publications from importer: $importer</b><br><ol>\n";
  241. foreach ($report['inserted'] as $pub) {
  242. $item = $pub['Title'];
  243. if ($pub['pub_id']) {
  244. $item = l($pub['Title'], "$base_url/pub/" . $pub['pub_id']);
  245. }
  246. $HTML_report .= "<li>$item</li>\n";
  247. }
  248. $HTML_report .= "</ol>\n";
  249. }
  250. $HTML_report .= "</html>";
  251. $site_email = variable_get('site_mail', '');
  252. $params = array(
  253. 'message' => $HTML_report
  254. );
  255. drupal_mail('tripal_pub', 'import_report', $report_email, language_default(), $params, $site_email, TRUE);
  256. }
  257. // if any of the importers wanted to create contacts from the authors then sync them
  258. if($do_contact) {
  259. print "Syncing contacts with Drupal...\n";
  260. tripal_contact_sync_contacts();
  261. }
  262. print "Done.\n";
  263. }
  264. /*
  265. * @ingroup tripal_pub_api
  266. */
  267. function tripal_pub_import_by_dbxref($pub_dbxref, $do_contact = FALSE, $do_update) {
  268. $num_to_retrieve = 1;
  269. $pager_id = 0;
  270. $page = 0;
  271. $num_pubs = 0;
  272. // get a persistent connection
  273. $connection = tripal_db_persistent_chado();
  274. if (!$connection) {
  275. print "A persistant connection was not obtained. Loading will be slow\n";
  276. }
  277. // if we cannot get a connection then let the user know the loading will be slow
  278. tripal_db_start_transaction();
  279. if ($connection) {
  280. print "\nNOTE: Loading of the publication is performed using a database transaction. \n" .
  281. "If the load fails or is terminated prematurely then the entire set of \n" .
  282. "insertions/updates is rolled back and will not be found in the database\n\n";
  283. }
  284. if(preg_match('/^(.*?):(.*?)$/', $pub_dbxref, $matches)) {
  285. $dbname = $matches[1];
  286. $accession = $matches[2];
  287. $criteria = array(
  288. 'num_criteria' => 1,
  289. 'remote_db' => $dbname,
  290. 'criteria' => array(
  291. '1' => array(
  292. 'search_terms' => "$dbname:$accession",
  293. 'scope' => 'id',
  294. 'operation' => '',
  295. 'is_phrase' => 0,
  296. ),
  297. ),
  298. );
  299. $remote_db = $criteria['remote_db'];
  300. $pubs = tripal_pub_get_remote_search_results($remote_db, $criteria, $num_to_retrieve, $pager_id, $page);
  301. $pub_id = tripal_pub_add_publications($pubs, $do_contact, $do_update);
  302. }
  303. // transaction is complete
  304. tripal_db_commit_transaction();
  305. print "Transaction Complete\n";
  306. // sync the newly added publications with Drupal
  307. print "Syncing publications with Drupal...\n";
  308. tripal_pub_sync_pubs();
  309. // if any of the importers wanted to create contacts from the authors then sync them
  310. if($do_contact) {
  311. print "Syncing contacts with Drupal...\n";
  312. tripal_contact_sync_contacts();
  313. }
  314. print "Done.\n";
  315. }
  316. /*
  317. *
  318. */
  319. function tripal_pub_add_publications($pubs, $do_contact, $update = FALSE) {
  320. $report = array();
  321. $report['error'] = 0;
  322. $report['inserted'] = array();
  323. $report['skipped'] = array();
  324. $total_pubs = count($pubs);
  325. // iterate through the publications and add each one
  326. $i = 1;
  327. foreach ($pubs as $pub) {
  328. $memory = number_format(memory_get_usage()) . " bytes";
  329. print "Processing $i of $total_pubs. Memory usage: $memory.\r";
  330. // add the publication to Chado
  331. $action = '';
  332. // make sure the publication has a citation before trying to add. The citation
  333. // becomes the uniquename for the pub. If it doesn't exist then the importer
  334. // couldn't create one because the pub type is not handled, so skip it
  335. if(!$pub['Citation']) {
  336. $action = 'skipped';
  337. }
  338. else {
  339. $pub_id = tripal_pub_add_publication($pub, $action, $do_contact, $update);
  340. }
  341. if ($pub_id){
  342. // add the publication cross reference (e.g. to PubMed)
  343. if ($pub['Publication Dbxref']) {
  344. $pub_dbxref = tripal_pub_add_pub_dbxref($pub_id, $pub['Publication Dbxref']);
  345. }
  346. $pub['pub_id'] = $pub_id;
  347. }
  348. switch ($action) {
  349. case 'error':
  350. $report['error']++;
  351. break;
  352. case 'inserted':
  353. $report['inserted'][] = $pub;
  354. break;
  355. case 'updated':
  356. $report['updated'][] = $pub;
  357. break;
  358. case 'skipped':
  359. $report['skipped'][] = $pub;
  360. break;
  361. }
  362. $i++;
  363. }
  364. print "\n";
  365. return $report;
  366. }
  367. /*
  368. *
  369. */
  370. function tripal_pub_add_pub_dbxref($pub_id, $pub_dbxref) {
  371. // break apart the dbxref
  372. $dbname = '';
  373. $accession = '';
  374. if(preg_match('/^(.*?):(.*?)$/', $pub_dbxref, $matches)) {
  375. $dbname = $matches[1];
  376. $accession = $matches[2];
  377. }
  378. else {
  379. return FALSE;
  380. }
  381. // check to see if the pub_dbxref record already exist
  382. $values = array(
  383. 'dbxref_id' => array(
  384. 'accession' => $accession,
  385. 'db_id' => array(
  386. 'name' => $dbname,
  387. ),
  388. ),
  389. 'pub_id' => $pub_id,
  390. );
  391. $options = array('statement_name' => 'sel_pubdbxref_dbpu');
  392. $results = tripal_core_chado_select('pub_dbxref', array('*'), $values, $options);
  393. // if the pub_dbxref record exist then we don't need to re-add it.
  394. if(count($results) > 0) {
  395. return $results[0];
  396. }
  397. // make sure our database already exists
  398. $db = tripal_db_add_db($dbname);
  399. // get the database cross-reference
  400. $dbxvalues = array(
  401. 'accession' => $accession,
  402. 'db_id' => $db->db_id,
  403. );
  404. $dbxoptions = array('statement_name' => 'sel_dbxref_acdb');
  405. $results = tripal_core_chado_select('dbxref', array('dbxref_id'), $dbxvalues, $dbxoptions);
  406. // if the accession doesn't exist then add it
  407. if(count($results) == 0){
  408. $dbxref = tripal_db_add_dbxref($db->db_id, $accession);
  409. }
  410. else {
  411. $dbxref = $results[0];
  412. }
  413. // now add the record
  414. $options = array('statement_name' => 'ins_pubdbxref_dbpu');
  415. $results = tripal_core_chado_insert('pub_dbxref', $values, $options);
  416. if (!$results) {
  417. watchdog('tripal_pub', "Cannot add publication dbxref: %db:%accession.",
  418. array('%db' => $dbname, '%accession' => $accession). WATCHDOG_ERROR);
  419. return FALSE;
  420. }
  421. return $results;
  422. }
  423. /**
  424. * Returns the list of publications that are assigned the database
  425. * cross-reference provided
  426. *
  427. * @param $pub_dbxref
  428. * The database cross reference accession. It should be in the form
  429. * DB:ACCESSION, where DB is the database name and ACCESSION is the
  430. * unique publication identifier (e.g. PMID:4382934)
  431. *
  432. * @return
  433. * Returns an array of all the publications that have the provided
  434. * cross reference. If no publications match, then an empty array
  435. * is returned.
  436. *
  437. * @ingroup tripal_pub_api
  438. *
  439. */
  440. function tripal_pub_get_pubs_by_dbxref($pub_dbxref) {
  441. $return = array();
  442. if(preg_match('/^(.*?):(.*?)$/', $pub_dbxref, $matches)) {
  443. $dbname = $matches[1];
  444. $accession = $matches[2];
  445. $values = array(
  446. 'dbxref_id' => array (
  447. 'accession' => $accession,
  448. 'db_id' => array(
  449. 'name' => $dbname
  450. ),
  451. ),
  452. );
  453. $options = array('statement_name' => 'sel_pubdbxref_db');
  454. $results = tripal_core_chado_select('pub_dbxref', array('pub_id'), $values, $options);
  455. foreach ($results as $index => $pub) {
  456. $return[] = $pub->pub_id;
  457. }
  458. }
  459. return $return;
  460. }
  461. /**
  462. * Returns the list of publications that match a given title, type and year
  463. *
  464. * @param title
  465. * The title of the publication to look for
  466. * @param type
  467. * Optional. The publication type. The value of this field should come from
  468. * the Tripal Pub vocabulary. This should be the type name (e.g. cvterm.name)
  469. * @param year
  470. * Optional. The year the publication was published.
  471. * @param series_name
  472. * Optional. The name of the series (e.g. Journal name)
  473. *
  474. * @return
  475. * Returns an array of all the publications that have the provided
  476. * cross reference. If no publications match, then an empty array
  477. * is returned.
  478. *
  479. * @ingroup tripal_pub_api
  480. *
  481. */
  482. function tripal_pub_get_pubs_by_title_type_pyear_series($title, $type = NULL, $pyear = NULL, $series_name = NULL) {
  483. $return = array();
  484. // build the values array for the query.
  485. $values = array(
  486. 'title' => $title,
  487. );
  488. $stmnt_suffix = 'ti';
  489. if ($type) {
  490. $values['type_id'] = array(
  491. 'name' => $type,
  492. 'cv_id' => array(
  493. 'name' => 'tripal_pub'
  494. )
  495. );
  496. $stmnt_suffix .= 'ty';
  497. }
  498. if ($pyear) {
  499. $values['pyear'] = $pyear;
  500. $stmnt_suffix .= 'py';
  501. }
  502. if ($series_name) {
  503. $values['series_name'] = strtolower($series_name);
  504. $stmnt_suffix .= 'se';
  505. }
  506. $options = array(
  507. 'statement_name' => 'sel_pub_' . $stmnt_suffix,
  508. 'case_insensitive_columns' => array('title', 'series_name'),
  509. );
  510. $results = tripal_core_chado_select('pub', array('pub_id'), $values, $options);
  511. // iterate through any matches and pull out the pub_id
  512. foreach ($results as $index => $pub) {
  513. $return[] = $pub->pub_id;
  514. }
  515. return $return;
  516. }
  517. /**
  518. * Returns the list of publications that match a given title, type and year
  519. *
  520. * @param title
  521. * The title of the publication to look for
  522. * @param type
  523. * Optional. The publication type. The value of this field should come from
  524. * the Tripal Pub vocabulary. This should be the type name (e.g. cvterm.name)
  525. * @param year
  526. * Optional. The year the publication was published.
  527. * @param series_name
  528. * Optional. The name of the series (e.g. Journal name)
  529. *
  530. * @return
  531. * Returns an array of all the publications that have the provided
  532. * cross reference. If no publications match, then an empty array
  533. * is returned.
  534. *
  535. * @ingroup tripal_pub_api
  536. *
  537. */
  538. function tripal_pub_get_pub_by_uniquename($name) {
  539. $return = array();
  540. // build the values array for the query.
  541. $values = array(
  542. 'uniquename' => $name,
  543. );
  544. $options = array(
  545. 'statement_name' => 'sel_pub_un',
  546. 'case_insensitive_columns' => array('uniquename'),
  547. );
  548. $results = tripal_core_chado_select('pub', array('pub_id'), $values, $options);
  549. // iterate through any matches and pull out the pub_id
  550. foreach ($results as $index => $pub) {
  551. $return[] = $pub->pub_id;
  552. }
  553. return $return;
  554. }
  555. /**
  556. * Adds a new publication to the Chado, along with all properties and
  557. * database cross-references. If the publication does not already exist
  558. * in Chado then it is added. If it does exist nothing is done. If
  559. * the $update parameter is TRUE then the publication is updated if it exists.
  560. *
  561. * @param $pub_details
  562. * An associative array containing all of the details about the publication.
  563. * @param $action
  564. * This variable will get set to a text value indicating the action that was
  565. * performed. The values include 'skipped', 'inserted', 'updated' or 'error'.
  566. * @param $do_contact
  567. * Optional. Set to TRUE if a contact entry should be added to the Chado contact table
  568. * for authors of the publication.
  569. * @param $update_if_exists
  570. * Optional. If the publication already exists then this function will return
  571. * without adding a new publication. However, set this value to TRUE to force
  572. * the function to pudate the publication using the $pub_details that are provided.
  573. *
  574. * @return
  575. * If the publication already exists, is inserted or updated then the publication
  576. * ID is returned, otherwise FALSE is returned. If the publication already exists
  577. * and $update_if_exists is not TRUE then the $action variable is set to 'skipped'.
  578. * If the publication already exists and $update_if_exists is TRUE and if the update
  579. * was successful then $action is set to 'updated'. Otherwise on successful insert
  580. * the $action variable is set to 'inserted'. If the function failes then the
  581. * $action variable is set to 'error'
  582. *
  583. */
  584. function tripal_pub_add_publication($pub_details, &$action, $do_contact = FALSE, $update_if_exists = FALSE) {
  585. $pub_id = 0;
  586. // first try to find the publication using the accession number. It will have
  587. // one if the pub has already been loaded for the publication database
  588. if ($pub_details['Publication Dbxref']) {
  589. $results = tripal_pub_get_pubs_by_dbxref($pub_details['Publication Dbxref']);
  590. if(count($results) == 1) {
  591. $pub_id = $results[0];
  592. if ($pub_id and !$update_if_exists) {
  593. watchdog('tripal_pub', "A publication with this Dbxref already exists... Skipping: %dbxref",
  594. array('%dbxref' => $pub_details['Publication Dbxref']), WATCHDOG_WARNING);
  595. $action = 'skipped';
  596. return $pub_id;
  597. }
  598. }
  599. elseif (count($results) > 1) {
  600. watchdog('tripal_pub', "There are two publications with this accession: %db:%accession. Cannot determine which to update.",
  601. array('%db' => $dbname, '%accession' => $accession), WATCHDOG_ERROR);
  602. $action = 'error';
  603. return FALSE;
  604. }
  605. }
  606. // if we couldn't find a publication by the accession (which means it doesn't
  607. // yet exist or it has been added using a different publication database) then
  608. // try to find it using the title and publication year.
  609. if (!$pub_id and $pub_details['Title']) {
  610. $results = tripal_pub_get_pubs_by_title_type_pyear_series($pub_details['Title'], NULL, $pub_details['Year']);
  611. if (count($results) == 1) {
  612. $pub_id = $results[0];
  613. if ($pub_id and !$update_if_exists) {
  614. watchdog('tripal_pub', "The publication with the same title, type and year already exists. Skipping. ".
  615. " Title: '%title'. Type: '%type'. Year: '%year'",
  616. array('%title' => $pub_details['Title'], '%type' => $pub_details['Publication Type'], '%year' => $pub_details['Year']), WATCHDOG_WARNING);
  617. $action = 'skipped';
  618. return $pub_id;
  619. }
  620. }
  621. elseif (count($results) > 1) {
  622. watchdog('tripal_pub', "The publication with the same title, type and year is present multiple times. Cannot ".
  623. "determine which to use. Title: '%title'. Type: '%type'. Year: '%year'",
  624. array('%title' => $pub_details['Title'], '%type' => $pub_details['Publication Type'], '%year' => $pub_details['Year']), WATCHDOG_ERROR);
  625. $action = 'error';
  626. return FALSE;
  627. }
  628. }
  629. // get the publication type (use the first publication type, any others will get stored as properties)
  630. if (is_array($pub_details['Publication Type'])) {
  631. $pub_type = tripal_cv_get_cvterm_by_name($pub_details['Publication Type'][0], NULL, 'tripal_pub');
  632. }
  633. elseif ($pub_details['Publication Type']) {
  634. $pub_type = tripal_cv_get_cvterm_by_name($pub_details['Publication Type'], NULL, 'tripal_pub');
  635. }
  636. else {
  637. watchdog('tripal_pub', "The Publication Type is a required property but is missing", array(), WATCHDOG_ERROR);
  638. $action = 'error';
  639. return FALSE;
  640. }
  641. if (!$pub_type) {
  642. watchdog('tripal_pub', "Cannot find publication type: '%type'",
  643. array('%type' => $pub_details['Publication Type'][0]), WATCHDOG_ERROR);
  644. $action = 'error';
  645. return FALSE;
  646. }
  647. // build the values array for inserting or updating
  648. $values = array(
  649. 'title' => $pub_details['Title'],
  650. 'volume' => $pub_details['Volume'],
  651. 'series_name' => substr($pub_details['Journal Name'], 0, 255),
  652. 'issue' => $pub_details['Issue'],
  653. 'pyear' => $pub_details['Year'],
  654. 'pages' => $pub_details['Pages'],
  655. 'uniquename' => $pub_details['Citation'],
  656. 'type_id' => $pub_type->cvterm_id,
  657. );
  658. // if there is no pub_id then we need to do an insert.
  659. if (!$pub_id) {
  660. $options = array('statement_name' => 'ins_pub_tivoseispypaunty');
  661. $pub = tripal_core_chado_insert('pub', $values, $options);
  662. if (!$pub) {
  663. watchdog('tripal_pub', "Cannot insert the publication with title: %title",
  664. array('%title' => $pub_details['Title']), WATCHDOG_ERROR);
  665. $action = 'error';
  666. return FALSE;
  667. }
  668. $pub_id = $pub['pub_id'];
  669. $action = 'inserted';
  670. }
  671. // if there is a pub_id and we've been told to update, then do the update
  672. if ($pub_id and $update_if_exists) {
  673. $match = array('pub_id' => $pub_id);
  674. $options = array('statement_name' => 'up_pub_tivoseispypaunty');
  675. $success = tripal_core_chado_update('pub', $match, $values, $options);
  676. if (!$success) {
  677. watchdog('tripal_pub', "Cannot update the publication with title: %title",
  678. array('%title' => $pub_details['Title']), WATCHDOG_ERROR);
  679. $action = 'error';
  680. return FALSE;
  681. }
  682. $action = 'updated';
  683. }
  684. // before we add any new properties we need to remove those that are there if this
  685. // is an update. The only thing we don't want to remove are the 'Publication Dbxref'
  686. if ($update_if_exists) {
  687. $sql = "
  688. DELETE FROM {pubprop}
  689. WHERE
  690. pub_id = %d AND
  691. NOT type_id in (
  692. SELECT cvterm_id
  693. FROM {cvterm}
  694. WHERE name = 'Publication Dbxref'
  695. )
  696. ";
  697. chado_query($sql, $pub_id);
  698. }
  699. // iterate through the properties and add them
  700. foreach ($pub_details as $key => $value) {
  701. // the pub_details may have the raw search data (e.g. in XML from PubMed. We'll irgnore this for now
  702. if($key == 'raw') {
  703. continue;
  704. }
  705. // get the cvterm by name or synonym
  706. $cvterm = tripal_cv_get_cvterm_by_name($key, NULL, 'tripal_pub');
  707. if (!$cvterm) {
  708. $cvterm = tripal_cv_get_cvterm_by_synonym($key, NULL, 'tripal_pub');
  709. }
  710. if (!$cvterm) {
  711. watchdog('tripal_pub', "Cannot find term: '%prop'. Skipping.", array('%prop' => $key), WATCHDOG_ERROR);
  712. continue;
  713. }
  714. // skip details that won't be stored as properties
  715. if ($key == 'Author List') {
  716. tripal_pub_add_authors($pub_id, $value, $do_contact);
  717. continue;
  718. }
  719. if ($key == 'Title' or $key == 'Volume' or $key == 'Journal Name' or $key == 'Issue' or
  720. $key == 'Year' or $key == 'Pages') {
  721. continue;
  722. }
  723. $success = 0;
  724. if (is_array($value)) {
  725. foreach ($value as $subkey => $subvalue) {
  726. // if the key is an integer then this array is a simple list and
  727. // we will insert using the primary key. Otheriwse, use the new key
  728. if(is_int($subkey)) {
  729. $success = tripal_core_insert_property('pub', $pub_id, $key, 'tripal_pub', $subvalue, FALSE);
  730. }
  731. else {
  732. $success = tripal_core_insert_property('pub', $pub_id, $subkey, 'tripal_pub', $subvalue, FALSE);
  733. }
  734. }
  735. }
  736. else {
  737. $success = tripal_core_insert_property('pub', $pub_id, $key, 'tripal_pub', $value, TRUE);
  738. }
  739. if (!$success) {
  740. watchdog('tripal_pub', "Cannot add property '%prop' to publication. Skipping.",
  741. array('%prop' => $key), WATCHDOG_ERROR);
  742. continue;
  743. }
  744. }
  745. return $pub_id;
  746. }
  747. /*
  748. *
  749. */
  750. function tripal_pub_add_authors($pub_id, $authors, $do_contact) {
  751. $rank = 0;
  752. // first remove any of the existing pubauthor entires
  753. $sql = "DELETE FROM {pubauthor} WHERE pub_id = %d";
  754. chado_query($sql, $pub_id);
  755. // iterate through the authors and add them to the pubauthors and contact
  756. // tables of chado, then link them through the custom pubauthors_contact table
  757. foreach ($authors as $author) {
  758. // skip invalid author entires
  759. if ($author['valid'] == 'N') {
  760. continue;
  761. }
  762. // remove the 'valid' property as we don't have a CV term for it
  763. unset($author['valid']);
  764. // construct the contact.name field using the author information
  765. $name = '';
  766. $type = 'Person';
  767. if ($author['Given Name']) {
  768. $name .= $author['Given Name'];
  769. }
  770. if ($author['Surname']) {
  771. $name .= ' ' . $author['Surname'];
  772. }
  773. if ($author['Suffix']) {
  774. $name .= ' ' . $author['Suffix'];
  775. }
  776. if ($author['Collective']) {
  777. $name = $author['Collective'];
  778. $type = 'Collective';
  779. }
  780. $name = trim($name);
  781. // add an entry to the pubauthors table
  782. $values = array(
  783. 'pub_id' => $pub_id,
  784. 'rank' => $rank,
  785. 'surname' => $author['Surname'] ? substr($author['Surname'], 0, 100) : substr($author['Collective'], 0, 100),
  786. 'givennames' => $author['Given Name'],
  787. 'suffix' => $author['Suffix'],
  788. );
  789. $options = array('statement_name' => 'ins_pubauthor_idrasugisu');
  790. $pubauthor = tripal_core_chado_insert('pubauthor', $values, $options);
  791. // if the user wants us to create a contact for each author then do it.
  792. if ($do_contact) {
  793. // Add the contact
  794. $contact = tripal_contact_add_contact($name, '', $type, $author);
  795. // if we have succesfully added the contact and the pubauthor entries then we want to
  796. // link them together
  797. if ($contact and $pubauthor) {
  798. // link the pubauthor entry to the contact
  799. $values = array(
  800. 'pubauthor_id' => $pubauthor['pubauthor_id'],
  801. 'contact_id' => $contact['contact_id'],
  802. );
  803. $options = array('statement_name' => 'ins_pubauthorcontact_puco');
  804. $pubauthor_contact = tripal_core_chado_insert('pubauthor_contact', $values, $options);
  805. if (!$pubauthor_contact) {
  806. watchdog('tripal_pub', "Cannot link pub authro and contact.", array(), WATCHDOG_ERROR);
  807. }
  808. }
  809. }
  810. $rank++;
  811. }
  812. }
  813. /**
  814. * Retrieve properties of a given type for a given pub
  815. *
  816. * @param $pub_id
  817. * The pub_id of the properties you would like to retrieve
  818. * @param $property
  819. * The cvterm name of the properties to retrieve
  820. *
  821. * @return
  822. * An pub chado variable with the specified properties expanded
  823. *
  824. * @ingroup tripal_pub_api
  825. */
  826. function tripal_pub_get_property($pub_id, $property) {
  827. return tripal_core_get_property('pub', $pub_id, $property, 'tripal_pub');
  828. }
  829. /**
  830. * Insert a given property
  831. *
  832. * @param $pub_id
  833. * The pub_id of the property to insert
  834. * @param $property
  835. * The cvterm name of the property to insert
  836. * @param $value
  837. * The value of the property to insert
  838. * @param $update_if_present
  839. * A boolean indicated whether to update the record if it's already present
  840. *
  841. * @return
  842. * True of success, False otherwise
  843. *
  844. * @ingroup tripal_pub_api
  845. */
  846. function tripal_pub_insert_property($pub_id, $property, $value, $update_if_present = 0) {
  847. return tripal_core_insert_property('pub', $pub_id, $property, 'tripal_pub', $value, $update_if_present);
  848. }
  849. /**
  850. * Update a given property
  851. *
  852. * @param $pub_id
  853. * The pub_id of the property to update
  854. * @param $property
  855. * The cvterm name of the property to update
  856. * @param $value
  857. * The value of the property to update
  858. * @param $insert_if_missing
  859. * A boolean indicated whether to insert the record if it's absent
  860. *
  861. * Note: The property will be identified using the unique combination of the $pub_id and $property
  862. * and then it will be updated with the supplied value
  863. *
  864. * @return
  865. * True of success, False otherwise
  866. *
  867. * @ingroup tripal_pub_api
  868. */
  869. function tripal_pub_update_property($pub_id, $property, $value, $insert_if_missing = 0) {
  870. return tripal_core_update_property('pub', $pub_id, $property, 'tripal_pub', $value, $insert_if_missing);
  871. }
  872. /**
  873. * Delete a given property
  874. *
  875. * @param $pub_id
  876. * The pub_id of the property to delete
  877. * @param $property
  878. * The cvterm name of the property to delete
  879. *
  880. * Note: The property will be identified using the unique combination of the $pub_id and $property
  881. * and then it will be deleted
  882. *
  883. * @return
  884. * True of success, False otherwise
  885. *
  886. * @ingroup tripal_pub_api
  887. */
  888. function tripal_pub_delete_property($pub_id, $property) {
  889. return tripal_core_delete_property('pub', $pub_id, $property, 'tripal_pub');
  890. }
  891. /**
  892. * This function generates an array suitable for use with the
  893. * tripal_pub_create_citation function for any publication
  894. * already stored in the Chado tables.
  895. *
  896. * @param $pub_id
  897. * The publication ID
  898. * @param $skip_existing
  899. * Set to TRUE to skip publications that already have a citation
  900. * in the pubprop table. Set to FALSE to generate a citation
  901. * regardless if the citation already exists.
  902. *
  903. * @return
  904. * An array suitable for the trpial_pub_create_citation function. On
  905. * failure returns FALSE.
  906. */
  907. function tripal_pub_get_publication_array($pub_id, $skip_existing = TRUE) {
  908. $options = array('return_array' => 1);
  909. // ---------------------------------
  910. // get the publication
  911. // ---------------------------------
  912. $values = array('pub_id' => $pub_id);
  913. $pub = tripal_core_generate_chado_var('pub', $values);
  914. // expand the title
  915. $pub = tripal_core_expand_chado_vars($pub, 'field', 'pub.title');
  916. $pub = tripal_core_expand_chado_vars($pub, 'field', 'pub.volumetitle');
  917. $pub = tripal_core_expand_chado_vars($pub, 'field', 'pub.uniquename');
  918. $pub_array = array();
  919. if (trim($pub->title)) {
  920. $pub_array['Title'] = $pub->title;
  921. }
  922. if (trim($pub->volumetitle)) {
  923. $pub_array['Volume Title'] = $pub->volumetitle;
  924. }
  925. if (trim($pub->volume)) {
  926. $pub_array['Volume'] = $pub->volume;
  927. }
  928. if (trim($pub->series_name)) {
  929. $pub_array['Series Name'] = $pub->series_name;
  930. }
  931. if (trim($pub->issue)) {
  932. $pub_array['Issue'] = $pub->issue;
  933. }
  934. if (trim($pub->pyear)) {
  935. $pub_array['Year'] = $pub->pyear;
  936. }
  937. if (trim($pub->pages)) {
  938. $pub_array['Pages'] = $pub->pages;
  939. }
  940. if (trim($pub->miniref)) {
  941. $pub_array['Mini Ref'] = $pub->miniref;
  942. }
  943. if (trim($pub->uniquename)) {
  944. $pub_array['Uniquename'] = $pub->uniquename;
  945. }
  946. $pub_array['Publication Type'][] = $pub->type_id->name;
  947. // ---------------------------------
  948. // get the citation
  949. // ---------------------------------
  950. $values = array(
  951. 'pub_id' => $pub->pub_id,
  952. 'type_id' => array(
  953. 'name' => 'Citation',
  954. ),
  955. );
  956. $citation = tripal_core_generate_chado_var('pubprop', $values);
  957. if ($citation) {
  958. $citation = tripal_core_expand_chado_vars($citation, 'field', 'pubprop.value', $options);
  959. if (count($citation) > 1) {
  960. watchdog('tripal_pub', "Publication has multiple citations already: %pub_id",
  961. array('%pub_id' => $pubid), WATCHDOG_ERROR);
  962. return FALSE;
  963. }
  964. elseif (count($citation) == 1 and $skip_existing == TRUE) {
  965. // skip this publication, it already has a citation
  966. return FALSE;
  967. }
  968. }
  969. // ---------------------------------
  970. // get the publication types
  971. // ---------------------------------
  972. $values = array(
  973. 'pub_id' => $pub->pub_id,
  974. 'type_id' => array(
  975. 'name' => 'Publication Type',
  976. ),
  977. );
  978. $ptypes = tripal_core_generate_chado_var('pubprop', $values, $options);
  979. if ($ptypes) {
  980. $ptypes = tripal_core_expand_chado_vars($ptypes, 'field', 'pubprop.value', $options);
  981. foreach ($ptypes as $ptype) {
  982. $pub_array['Publication Type'][] = $ptype->value;
  983. }
  984. }
  985. // ---------------------------------
  986. // get the authors list
  987. // ---------------------------------
  988. $values = array(
  989. 'pub_id' => $pub->pub_id,
  990. 'type_id' => array(
  991. 'name' => 'Authors',
  992. ),
  993. );
  994. $authors = tripal_core_generate_chado_var('pubprop', $values);
  995. $authors = tripal_core_expand_chado_vars($authors, 'field', 'pubprop.value', $options);
  996. if (count($authors) > 1) {
  997. watchdog('tripal_pub', "Publication has multiple author lists. It should have only one list: %pub_id",
  998. array('%pub_id' => $pubid), WATCHDOG_ERROR);
  999. return FALSE;
  1000. }
  1001. else if (trim($authors->value)) {
  1002. $pub_array['Authors'] = $authors->value;
  1003. }
  1004. // if there is no 'Author's property then try to retreive authors from the pubauthor table
  1005. else {
  1006. $sql = "SELECT string_agg(surname || ' ' || givennames, ', ') FROM {pubauthor} WHERE pub_id = %d GROUP BY pub_id";
  1007. $au = db_result(chado_query($sql));
  1008. if ($au) {
  1009. $pub_array['Authors'] = $au;
  1010. }
  1011. }
  1012. //Get other props
  1013. $props = array(
  1014. 'Journal Abbreviation',
  1015. 'Elocation',
  1016. 'Media Code',
  1017. 'Conference Name',
  1018. 'Keywords',
  1019. 'Series Name',
  1020. 'pISSN',
  1021. 'Publication Date',
  1022. 'Journal Code',
  1023. 'Journal Alias',
  1024. 'Journal Country',
  1025. 'Published Location',
  1026. 'Publication Model',
  1027. 'Language Abbr',
  1028. 'Alias',
  1029. 'Publication Dbxref',
  1030. 'Copyright',
  1031. 'Abstract',
  1032. 'Notes',
  1033. 'Citation',
  1034. 'Language',
  1035. 'URL',
  1036. 'eISSN',
  1037. 'DOI',
  1038. 'ISSN',
  1039. 'Publication Code',
  1040. 'Comments',
  1041. 'Publisher',
  1042. 'Media Alias',
  1043. 'Original Title');
  1044. foreach ($props AS $prop) {
  1045. $sql =
  1046. "SELECT value FROM {pubprop}
  1047. WHERE type_id = (SELECT cvterm_id FROM {cvterm} WHERE name = '%s' AND cv_id = (SELECT cv_id FROM cv WHERE name = 'tripal_pub'))
  1048. AND pub_id = %d";
  1049. $val = trim(db_result(chado_query($sql, $prop, $pub->pub_id)));
  1050. if ($val) {
  1051. $pub_array[$prop] =$val;
  1052. }
  1053. }
  1054. return $pub_array;
  1055. }
  1056. /**
  1057. * This function generates citations for publications. It requires
  1058. * an array structure with keys being the terms in the Tripal
  1059. * publication ontology. This function is intended to be used
  1060. * for any function that needs to generate a citation.
  1061. *
  1062. * @param $pub
  1063. * An array structure containing publication details where the keys
  1064. * are the publication ontology term names and values are the
  1065. * corresponding details. The pub array can contain the following
  1066. * keys with corresponding values:
  1067. * - Publication Type: an array of publication types. a publication can have more than one type
  1068. * - Authors: a string containing all of the authors of a publication
  1069. * - Journal Name: a string containing the journal name
  1070. * - Journal Abbreviation: a string containing the journal name abbreviation
  1071. * - Series Name: a string containing the series (e.g. conference proceedings) name
  1072. * - Series Abbreviation: a string containing the series name abbreviation
  1073. * - Volume: the serives volume number
  1074. * - Issue: the series issue number
  1075. * - Pages: the page numbers for the publication
  1076. * - Publication Date: A date in the format "Year Month Day"
  1077. *
  1078. * @return
  1079. * A text string containing the citation
  1080. */
  1081. function tripal_pub_create_citation($pub) {
  1082. $citation = '';
  1083. $pub_type = '';
  1084. // An article may have more than one publication type. For example,
  1085. // a publication type can be 'Journal Article' but also a 'Clinical Trial'.
  1086. // Therefore, we need to select the type that makes most sense for
  1087. // construction of the citation. Here we'll iterate through them all
  1088. // and select the one that matches best.
  1089. if(is_array($pub['Publication Type'])) {
  1090. foreach ($pub['Publication Type'] as $ptype) {
  1091. if ($ptype == 'Journal Article' ) {
  1092. $pub_type = $ptype;
  1093. break;
  1094. }
  1095. else if ($ptype == 'Conference Proceedings'){
  1096. $pub_type = $ptype;
  1097. break;
  1098. }
  1099. else if ($ptype == 'Book') {
  1100. $pub_type = $ptype;
  1101. break;
  1102. }
  1103. else if ($ptype == 'Letter') {
  1104. $pub_type = $ptype;
  1105. break;
  1106. }
  1107. else if ($ptype == 'Book Chapter') {
  1108. $pub_type = $ptype;
  1109. break;
  1110. }
  1111. else if ($ptype == "Research Support, Non-U.S. Gov't") {
  1112. $pub_type = $ptype;
  1113. // we don't break because if the article is also a Journal Article
  1114. // we prefer that type
  1115. }
  1116. }
  1117. if (!$pub_type) {
  1118. watchdog('tripal_pub', "Cannot generate citation for publication type: %types",
  1119. array('%types' => print_r($pub['Publication Type'], TRUE)), WATCHDOG_WARNING);
  1120. return FALSE;
  1121. }
  1122. }
  1123. else {
  1124. $pub_type = $pub['Publication Type'];
  1125. }
  1126. //----------------------
  1127. // Journal Article
  1128. //----------------------
  1129. if ($pub_type == 'Journal Article') {
  1130. $citation = $pub['Authors'] . '. ' . $pub['Title'] . '. ';
  1131. if ($pub['Journal Name']) {
  1132. $citation .= $pub['Journal Name'] . '. ';
  1133. }
  1134. elseif ($pub['Journal Abbreviation']) {
  1135. $citation .= $pub['Journal Abbreviation'] . '. ';
  1136. }
  1137. elseif ($pub['Series Name']) {
  1138. $citation .= $pub['Series Name'] . '. ';
  1139. }
  1140. elseif ($pub['Series Abbreviation']) {
  1141. $citation .= $pub['Series Abbreviation'] . '. ';
  1142. }
  1143. if ($pub['Publication Date']) {
  1144. $citation .= $pub['Publication Date'];
  1145. }
  1146. elseif ($pub['Year']) {
  1147. $citation .= $pub['Year'];
  1148. }
  1149. if ($pub['Volume'] or $pub['Issue'] or $pub['Pages']) {
  1150. $citation .= '; ';
  1151. }
  1152. if ($pub['Volume']) {
  1153. $citation .= $pub['Volume'];
  1154. }
  1155. if ($pub['Issue']) {
  1156. $citation .= '(' . $pub['Issue'] . ')';
  1157. }
  1158. if ($pub['Pages']) {
  1159. if($pub['Volume']) {
  1160. $citation .= ':';
  1161. }
  1162. $citation .= $pub['Pages'];
  1163. }
  1164. $citation .= '.';
  1165. }
  1166. //----------------------
  1167. // Research Support, Non-U.S. Gov't
  1168. //----------------------
  1169. elseif ($pub_type == "Research Support, Non-U.S. Gov't") {
  1170. $citation = $pub['Authors'] . '. ' . $pub['Title'] . '. ';
  1171. if ($pub['Journal Name']) {
  1172. $citation .= $pub['Journal Name'] . '. ';
  1173. }
  1174. if ($pub['Publication Date']) {
  1175. $citation .= $pub['Publication Date'];
  1176. }
  1177. elseif ($pub['Year']) {
  1178. $citation .= $pub['Year'];
  1179. }
  1180. $citation .= '.';
  1181. }
  1182. //----------------------
  1183. // Letter
  1184. //----------------------
  1185. elseif ($pub_type == 'Letter') {
  1186. $citation = $pub['Authors'] . '. ' . $pub['Title'] . '. ';
  1187. if ($pub['Journal Name']) {
  1188. $citation .= $pub['Journal Name'] . '. ';
  1189. }
  1190. elseif ($pub['Journal Abbreviation']) {
  1191. $citation .= $pub['Journal Abbreviation'] . '. ';
  1192. }
  1193. elseif ($pub['Series Name']) {
  1194. $citation .= $pub['Series Name'] . '. ';
  1195. }
  1196. elseif ($pub['Series Abbreviation']) {
  1197. $citation .= $pub['Series Abbreviation'] . '. ';
  1198. }
  1199. if ($pub['Publication Date']) {
  1200. $citation .= $pub['Publication Date'];
  1201. }
  1202. elseif ($pub['Year']) {
  1203. $citation .= $pub['Year'];
  1204. }
  1205. if ($pub['Volume'] or $pub['Issue'] or $pub['Pages']) {
  1206. $citation .= '; ';
  1207. }
  1208. if ($pub['Volume']) {
  1209. $citation .= $pub['Volume'];
  1210. }
  1211. if ($pub['Issue']) {
  1212. $citation .= '(' . $pub['Issue'] . ')';
  1213. }
  1214. if ($pub['Pages']) {
  1215. if($pub['Volume']) {
  1216. $citation .= ':';
  1217. }
  1218. $citation .= $pub['Pages'];
  1219. }
  1220. $citation .= '.';
  1221. }
  1222. //----------------------
  1223. // Book
  1224. //----------------------
  1225. elseif ($pub_type == 'Book') {
  1226. }
  1227. //----------------------
  1228. // Book Chapter
  1229. //----------------------
  1230. elseif ($pub_type == 'Book Chapter') {
  1231. }
  1232. //----------------------
  1233. // Conference Proceedings
  1234. //----------------------
  1235. elseif ($pub_type == 'Conference Proceedings') {
  1236. $citation = $pub['Authors'] . '. ' . $pub['Title'] . '. ';
  1237. if ($pub['Conference Name']) {
  1238. $citation .= $pub['Conference Name'] . '. ';
  1239. }
  1240. elseif ($pub['Series Name']) {
  1241. $citation .= $pub['Series Name'] . '. ';
  1242. }
  1243. elseif ($pub['Series Abbreviation']) {
  1244. $citation .= $pub['Series Abbreviation'] . '. ';
  1245. }
  1246. if ($pub['Publication Date']) {
  1247. $citation .= $pub['Publication Date'];
  1248. }
  1249. elseif ($pub['Year']) {
  1250. $citation .= $pub['Year'];
  1251. }
  1252. if ($pub['Volume'] or $pub['Issue'] or $pub['Pages']) {
  1253. $citation .= '; ';
  1254. }
  1255. if ($pub['Volume']) {
  1256. $citation .= $pub['Volume'];
  1257. }
  1258. if ($pub['Issue']) {
  1259. $citation .= '(' . $pub['Issue'] . ')';
  1260. }
  1261. if ($pub['Pages']) {
  1262. if($pub['Volume']) {
  1263. $citation .= ':';
  1264. }
  1265. $citation .= $pub['Pages'];
  1266. }
  1267. $citation .= '.';
  1268. }
  1269. return $citation;
  1270. }

Related topics