Open Monograph Press  1.1
 All Classes Namespaces Functions Variables Groups Pages
Citation.inc.php
1 <?php
2 
24 define('CITATION_RAW', 0x01);
25 define('CITATION_CHECKED', 0x02);
26 define('CITATION_PARSED', 0x03);
27 define('CITATION_LOOKED_UP', 0x04);
28 define('CITATION_APPROVED', 0x05);
29 
30 import('lib.pkp.classes.core.DataObject');
31 import('lib.pkp.plugins.metadata.nlm30.schema.Nlm30CitationSchema');
32 import('lib.pkp.plugins.metadata.nlm30.filter.Nlm30CitationSchemaCitationAdapter');
33 
34 class Citation extends DataObject {
36  var $_citationState = CITATION_RAW;
37 
39  var $_sourceDescriptions = array();
40 
43 
48  var $_errors = array();
49 
50 
55  function Citation($rawCitation = null) {
56  // Switch on meta-data adapter support.
57  $this->setHasLoadableAdapters(true);
58 
59  parent::DataObject();
60 
61  $this->setRawCitation($rawCitation); // this will set state to CITATION_RAW
62  }
63 
64  //
65  // Getters and Setters
66  //
73  function setSourceDescriptions(&$sourceDescriptions) {
74  $this->_sourceDescriptions =& $sourceDescriptions;
75  }
76 
85  function addSourceDescription($sourceDescription) {
86  assert(is_a($sourceDescription, 'MetadataDescription'));
87 
88  // Identify an appropriate sequence number.
89  $seq = $sourceDescription->getSeq();
90  if (is_numeric($seq) && $seq > 0) {
91  // This description has a pre-set sequence number
92  if ($seq > $this->_maxSourceDescriptionSeq) $this->_maxSourceDescriptionSeq = $seq;
93  } else {
94  // We'll create a sequence number for the description
95  $this->_maxSourceDescriptionSeq++;
97  $sourceDescription->setSeq($seq);
98  }
99 
100  // We add descriptions by display name as they are
101  // purely informational. This avoids getting duplicates
102  // when we update a description.
103  $this->_sourceDescriptions[$sourceDescription->getDisplayName()] = $sourceDescription;
104  return $seq;
105  }
106 
113  function &getSourceDescriptions() {
115  }
116 
121  function getCitationState() {
122  return $this->_citationState;
123  }
124 
129  function setCitationState($citationState) {
130  assert(in_array($citationState, Citation::_getSupportedCitationStates()));
131  $this->_citationState = $citationState;
132  }
138  function getAssocType() {
139  return $this->getData('assocType');
140  }
146  function setAssocType($assocType) {
147  $this->setData('assocType', $assocType);
148  }
149 
154  function getAssocId() {
155  return $this->getData('assocId');
156  }
157 
162  function setAssocId($assocId) {
163  $this->setData('assocId', $assocId);
164  }
165 
170  function addError($errorMessage) {
171  $this->_errors[] = $errorMessage;
172  }
173 
178  function getErrors() {
179  return $this->_errors;
180  }
181 
187  function getRawCitation() {
188  return $this->getData('rawCitation');
189  }
195  function setRawCitation($rawCitation) {
196  $rawCitation = $this->_cleanCitationString($rawCitation);
197 
198  $this->setData('rawCitation', $rawCitation);
199  }
200 
205  function getSeq() {
206  return $this->getData('seq');
207  }
208 
213  function setSeq($seq) {
214  $this->setData('seq', $seq);
215  }
216 
223  function &getNamespacedMetadataProperties() {
224  $metadataSchemas =& $this->getSupportedMetadataSchemas();
225  $metadataProperties = array();
226  foreach($metadataSchemas as $metadataSchema) {
227  $metadataProperties[$metadataSchema->getNamespace()] = $metadataSchema->getProperties();
228  }
229  return $metadataProperties;
230  }
231 
232 
233  //
234  // Private methods
235  //
240  static function _getSupportedCitationStates() {
241  static $_supportedCitationStates = array(
242  CITATION_RAW,
243  CITATION_CHECKED,
244  CITATION_PARSED,
245  CITATION_LOOKED_UP,
246  CITATION_APPROVED
247  );
248  return $_supportedCitationStates;
249  }
250 
256  function _cleanCitationString($citationString) {
257  // 1) If the string contains non-UTF8 characters, convert it to UTF-8
258  if (Config::getVar('i18n', 'charset_normalization') && !String::utf8_compliant($citationString)) {
259  $citationString = String::utf8_normalize($citationString);
260  }
261  // 2) Strip slashes and whitespace
262  $citationString = trim(stripslashes($citationString));
263 
264  // 3) Normalize whitespace
265  $citationString = String::regexp_replace('/[\s]+/', ' ', $citationString);
266 
267  return $citationString;
268  }
269 }
270 ?>
setRawCitation($rawCitation)
setAssocId($assocId)
static regexp_replace($pattern, $replacement, $subject, $limit=-1)
Definition: String.inc.php:377
getCitationState()
$_sourceDescriptions
static utf8_normalize($str)
Definition: String.inc.php:541
_cleanCitationString($citationString)
setSourceDescriptions(&$sourceDescriptions)
& getData($key, $locale=null)
addSourceDescription($sourceDescription)
static getVar($section, $key, $default=null)
Definition: Config.inc.php:35
setSeq($seq)
static _getSupportedCitationStates()
addError($errorMessage)
$_maxSourceDescriptionSeq
getSupportedMetadataSchemas()
setAssocType($assocType)
Citation($rawCitation=null)
setHasLoadableAdapters($hasLoadableAdapters)
& getNamespacedMetadataProperties()
Any class with an associated DAO should extend this class.
& getSourceDescriptions()
Class representing a citation (bibliographic reference)
setData($key, $value, $locale=null)
setCitationState($citationState)
static utf8_compliant($str)
Definition: String.inc.php:490