Open Journal Systems  3.3.0
MetadataSchema.inc.php
1 <?php
2 
66 import('lib.pkp.classes.metadata.MetadataProperty');
67 
70  var $_assocTypes;
71 
73  var $_name;
74 
76  var $_namespace;
77 
80 
85  var $_properties = array();
86 
100  function __construct($name, $namespace, $classname, $assocTypes) {
101  assert(is_string($name) && is_string($namespace) && is_string($classname));
102  assert(is_array($assocTypes) || is_integer($assocTypes));
103 
104  // Set name and namespace.
105  $this->_name = $name;
106  $this->_namespace = $namespace;
107  $this->_classname = $classname;
108 
109  // Normalize and set the association types.
110  if (!is_array($assocTypes)) {
111  $assocTypes = array($assocTypes);
112  }
113  $this->_assocTypes = $assocTypes;
114  }
115 
116 
117  //
118  // Getters and Setters
119  //
124  function getName() {
125  return $this->_name;
126  }
127 
132  function getNamespace() {
133  return $this->_namespace;
134  }
135 
140  function getClassName() {
141  return $this->_classname;
142  }
143 
149  function getAssocTypes() {
150  return $this->_assocTypes;
151  }
152 
157  function &getProperties() {
158  return $this->_properties;
159  }
160 
166  function &getProperty($propertyName) {
167  assert(is_string($propertyName));
168  if ($this->hasProperty($propertyName)) {
169  $property =& $this->_properties[$propertyName];
170  } else {
171  $property = null;
172  }
173  return $property;
174  }
175 
182  function getNamespacedPropertyId($propertyName) {
183  $property =& $this->getProperty($propertyName);
184  assert(is_a($property, 'MetadataProperty'));
185  return $this->getNamespace().ucfirst($property->getId());
186  }
187 
192  function setProperties(&$properties) {
193  // Remove the existing properties
194  $this->_properties = array();
195 
196  // Insert the new properties
197  foreach($properties as $property) {
198  $this->addProperty($property);
199  }
200  }
201 
212  function addProperty($name, $allowedTypes = METADATA_PROPERTY_TYPE_STRING,
213  $translated = false, $cardinality = METADATA_PROPERTY_CARDINALITY_ONE, $displayName = null, $validationMessage = null, $mandatory = false) {
214  // Make sure that this property has not been added before
215  assert(!is_null($name) && !isset($this->_properties[$name]));
216 
217  // Instantiate the property.
218  $property = new MetadataProperty($name, $this->_assocTypes, $allowedTypes, $translated, $cardinality, $displayName, $validationMessage, $mandatory);
219 
220  // Add the property
221  $this->_properties[$name] =& $property;
222  }
223 
228  function getPropertyNames() {
229  return array_keys($this->_properties);
230  }
231 
237  function getPropertyNamesByType($propertyType) {
238  assert(in_array($propertyType, MetadataProperty::getSupportedTypes()));
239 
240  $propertyNames = array();
241  foreach($this->_properties as $property) {
242  $allowedPropertyTypes = $property->getAllowedTypes();
243  if (isset($allowedPropertyTypes[$propertyType])) {
244  $propertyNames[] = $property->getName();
245  }
246  }
247 
248  return $propertyNames;
249  }
250 
256  function hasProperty($propertyName) {
257  return isset($this->_properties[$propertyName]);
258  }
259 }
260 
MetadataSchema\setProperties
setProperties(&$properties)
Definition: MetadataSchema.inc.php:207
MetadataSchema\getProperty
& getProperty($propertyName)
Definition: MetadataSchema.inc.php:181
MetadataSchema\hasProperty
hasProperty($propertyName)
Definition: MetadataSchema.inc.php:271
MetadataSchema\$_name
$_name
Definition: MetadataSchema.inc.php:79
MetadataSchema\getNamespacedPropertyId
getNamespacedPropertyId($propertyName)
Definition: MetadataSchema.inc.php:197
MetadataSchema\$_namespace
$_namespace
Definition: MetadataSchema.inc.php:85
MetadataSchema\$_classname
$_classname
Definition: MetadataSchema.inc.php:91
MetadataSchema\getAssocTypes
getAssocTypes()
Definition: MetadataSchema.inc.php:164
MetadataSchema\getName
getName()
Definition: MetadataSchema.inc.php:139
MetadataSchema\$_properties
$_properties
Definition: MetadataSchema.inc.php:100
MetadataSchema\getPropertyNames
getPropertyNames()
Definition: MetadataSchema.inc.php:243
MetadataSchema
Class that represents a meta-data schema (e.g. NLM element-citation, OpenURL, dc(terms),...
Definition: MetadataSchema.inc.php:68
MetadataSchema\getProperties
& getProperties()
Definition: MetadataSchema.inc.php:172
MetadataSchema\getPropertyNamesByType
getPropertyNamesByType($propertyType)
Definition: MetadataSchema.inc.php:252
MetadataSchema\$_assocTypes
$_assocTypes
Definition: MetadataSchema.inc.php:73
MetadataProperty
Class representing metadata properties. It specifies type and cardinality of a meta-data property (=t...
Definition: MetadataProperty.inc.php:53
MetadataProperty\getSupportedTypes
static getSupportedTypes()
Definition: MetadataProperty.inc.php:458
MetadataSchema\getNamespace
getNamespace()
Definition: MetadataSchema.inc.php:147
MetadataSchema\addProperty
addProperty($name, $allowedTypes=METADATA_PROPERTY_TYPE_STRING, $translated=false, $cardinality=METADATA_PROPERTY_CARDINALITY_ONE, $displayName=null, $validationMessage=null, $mandatory=false)
Definition: MetadataSchema.inc.php:227
MetadataSchema\getClassName
getClassName()
Definition: MetadataSchema.inc.php:155
MetadataSchema\__construct
__construct($name, $namespace, $classname, $assocTypes)
Definition: MetadataSchema.inc.php:115