PageRenderTime 42ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/pkp/classes/citation/lookup/isbndb/IsbndbNlmCitationSchemaIsbnFilter.inc.php

https://github.com/lib-uoguelph-ca/ocs
PHP | 108 lines | 49 code | 15 blank | 44 comment | 6 complexity | a70e05a6c8cb4289a6f779f3e9b75a3b MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. /**
  3. * @file classes/citation/lookup/isbndb/IsbndbNlmCitationSchemaIsbnFilter.inc.php
  4. *
  5. * Copyright (c) 2000-2012 John Willinsky
  6. * Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
  7. *
  8. * @class IsbndbNlmCitationSchemaIsbnFilter
  9. * @ingroup citation_lookup_isbndb
  10. *
  11. * @brief Filter that uses the ISBNdb web
  12. * service to identify an ISBN for a given citation.
  13. */
  14. // $Id$
  15. import('citation.lookup.isbndb.IsbndbNlmCitationSchemaFilter');
  16. class IsbndbNlmCitationSchemaIsbnFilter extends IsbndbNlmCitationSchemaFilter {
  17. /*
  18. * Constructor
  19. * @param $apiKey string
  20. */
  21. function IsbndbNlmCitationSchemaIsbnFilter($apiKey) {
  22. parent::IsbndbNlmCitationSchemaFilter($apiKey);
  23. }
  24. //
  25. // Implement template methods from Filter
  26. //
  27. /**
  28. * @see Filter::supports()
  29. * @param $input mixed
  30. * @param $output mixed
  31. * @return boolean
  32. */
  33. function supports(&$input, &$output) {
  34. if (!(is_null($output) || $this->isValidIsbn($output))) return false;
  35. return parent::supports($input, $output, false, true);
  36. }
  37. /**
  38. * @see Filter::process()
  39. * @param $citationDescription MetadataDescription
  40. * @return string an ISBN or null
  41. */
  42. function &process(&$citationDescription) {
  43. $nullVar = null;
  44. // Get the search strings
  45. $searchTemplates =& $this->_getSearchTemplates();
  46. $searchStrings = $this->constructSearchStrings($searchTemplates, $citationDescription);
  47. // Run the searches, in order, until we have a result
  48. $searchParams = array(
  49. 'access_key' => $this->getApiKey(),
  50. 'index1' => 'combined'
  51. );
  52. foreach ($searchStrings as $searchString) {
  53. $searchParams['value1'] = $searchString;
  54. if (is_null($resultDOM =& $this->callWebService(ISBNDB_WEBSERVICE_URL, $searchParams))) return $nullVar;
  55. // Did we get a search hit?
  56. $numResults = $resultDOM->getElementsByTagName('BookList')->item(0)->getAttribute('total_results');
  57. if (!empty($numResults)) break;
  58. }
  59. // Retrieve the first search hit
  60. $bookData =& $resultDOM->getElementsByTagName('BookData')->item(0);
  61. // If no book data present, then abort (this includes no search result at all)
  62. if (empty($bookData)) return $nullVar;
  63. $isbn = $bookData->getAttribute('isbn13');
  64. // If we have no ISBN then abort
  65. if (empty($isbn)) return $nullVar;
  66. return $isbn;
  67. }
  68. //
  69. // Private methods
  70. //
  71. /**
  72. * Return an array of search templates.
  73. * @return array
  74. */
  75. function &_getSearchTemplates() {
  76. $searchTemplates = array(
  77. '%au% %title% %date%',
  78. '%aulast% %title% %date%',
  79. '%au% %title% c%date%',
  80. '%aulast% %title% c%date%',
  81. '%au% %title%',
  82. '%aulast% %title%',
  83. '%title% %date%',
  84. '%title% c%date%',
  85. '%au% %date%',
  86. '%aulast% %date%',
  87. '%au% c%date%',
  88. '%aulast% c%date%'
  89. );
  90. return $searchTemplates;
  91. }
  92. }
  93. ?>