Open Journal Systems  3.0.0
 All Classes Namespaces Functions Variables Groups Pages
MetadataDescriptionDAO.inc.php
1 <?php
2 
17 import('lib.pkp.classes.metadata.MetadataDescription');
18 
19 
20 class MetadataDescriptionDAO extends DAO {
25  parent::DAO();
26  }
27 
34  function insertObject(&$metadataDescription) {
35  $metadataSchema =& $metadataDescription->getMetadataSchema();
36  $this->update(
37  sprintf('INSERT INTO metadata_descriptions
38  (assoc_type, assoc_id, schema_namespace, schema_name, display_name, seq)
39  VALUES (?, ?, ?, ?, ?, ?)'),
40  array(
41  (integer)$metadataDescription->getAssocType(),
42  (integer)$metadataDescription->getAssocId(),
43  $metadataSchema->getNamespace(),
44  $metadataSchema->getName(),
45  $metadataDescription->getDisplayName(),
46  (integer)$metadataDescription->getSeq()
47  )
48  );
49  $metadataDescription->setId($this->getInsertId());
50  $this->_updateObjectMetadata($metadataDescription);
51  return $metadataDescription->getId();
52  }
53 
59  function &getObjectById($metadataDescriptionId) {
60  $result = $this->retrieve(
61  'SELECT * FROM metadata_descriptions WHERE metadata_description_id = ?', $metadataDescriptionId
62  );
63 
64  $metadataDescription = null;
65  if ($result->RecordCount() != 0) {
66  $metadataDescription = $this->_fromRow($result->GetRowAssoc(false));
67  }
68 
69  $result->Close();
70  return $metadataDescription;
71  }
72 
80  function getObjectsByAssocId($assocType, $assocId, $rangeInfo = null) {
81  $result = $this->retrieveRange(
82  'SELECT *
83  FROM metadata_descriptions
84  WHERE assoc_type = ? AND assoc_id = ?
85  ORDER BY metadata_description_id DESC',
86  array((int)$assocType, (int)$assocId),
87  $rangeInfo
88  );
89 
90  return new DAOResultFactory($result, $this, '_fromRow', array('id'));
91  }
92 
97  function updateObject(&$metadataDescription) {
98  $metadataSchema =& $metadataDescription->getMetadataSchema();
99  $this->update(
100  'UPDATE metadata_descriptions
101  SET assoc_type = ?,
102  assoc_id = ?,
103  schema_name = ?,
104  schema_namespace = ?,
105  display_name = ?,
106  seq = ?
107  WHERE metadata_description_id = ?',
108  array(
109  (integer)$metadataDescription->getAssocType(),
110  (integer)$metadataDescription->getAssocId(),
111  $metadataSchema->getName(),
112  $metadataSchema->getNamespace(),
113  $metadataDescription->getDisplayName(),
114  $metadataDescription->getSeq(),
115  $metadataDescription->getId()
116  )
117  );
118  $this->_updateObjectMetadata($metadataDescription);
119  }
120 
126  function deleteObject(&$metadataDescription) {
127  return $this->deleteObjectById($metadataDescription->getId());
128  }
129 
135  function deleteObjectById($metadataDescriptionId) {
136  $params = array((int)$metadataDescriptionId);
137  $this->update('DELETE FROM metadata_descriptions WHERE metadata_description_id = ?', $params);
138  return $this->update('DELETE FROM metadata_description_settings WHERE metadata_description_id = ?', $params);
139  }
140 
147  function deleteObjectsByAssocId($assocType, $assocId) {
148  $metadataDescriptions = $this->getObjectsByAssocId($assocType, $assocId);
149  while ($metadataDescription = $metadataDescriptions->next()) {
150  $this->deleteObjectById($metadataDescription->getId());
151  }
152  return true;
153  }
154 
155  //
156  // Protected helper methods
157  //
162  function getInsertId() {
163  return parent::_getInsertId('metadata_descriptions', 'metadata_description_id');
164  }
165 
166 
167  //
168  // Private helper methods
169  //
180  function &_resolveSchemaIdentifierToMetadataSchemaName($metadataSchemaId) {
181  static $metadataSchemaMapping = array(
182  'nlm30:nlm-3.0-element-citation' => 'lib.pkp.plugins.metadata.nlm30.schema.Nlm30CitationSchema',
183  'nlm30:nlm-3.0-name' => 'lib.pkp.plugins.metadata.nlm30.schema.Nlm30NameSchema',
184  'openurl10:openurl-1.0-journal' => 'lib.pkp.plugins.metadata.nlm30.schema.Openurl10JournalSchema',
185  'openurl10:openurl-1.0-book' => 'lib.pkp.plugins.metadata.nlm30.schema.Openurl10BookSchema',
186  'openurl10:openurl-1.0-dissertation' => 'lib.pkp.plugins.metadata.nlm30.schema.Openurl10DissertationSchema'
187  );
188 
189  // Map the metadata schema identifier to a metadata schema class name.
190  assert(isset($metadataSchemaMapping[$metadataSchemaId]));
191  $metadataSchemaName = $metadataSchemaMapping[$metadataSchemaId];
192  return $metadataSchemaName;
193  }
194 
203  function &_newDataObject($metadataSchemaNamespace, $metadataSchemaName, $assocType) {
204  $metadataSchemaName =& $this->_resolveSchemaIdentifierToMetadataSchemaName($metadataSchemaNamespace.':'.$metadataSchemaName);
205  $metadataDescription = new MetadataDescription($metadataSchemaName, $assocType);
206  return $metadataDescription;
207  }
208 
215  function _fromRow($row) {
216  $metadataDescription = $this->_newDataObject($row['schema_namespace'], $row['schema_name'], (int)$row['assoc_type']);
217  $metadataDescription->setId((int)$row['metadata_description_id']);
218  $metadataDescription->setAssocId((int)$row['assoc_id']);
219  $metadataDescription->setDisplayName($row['display_name']);
220  $metadataDescription->setSeq((int)$row['seq']);
221 
222  $this->getDataObjectSettings('metadata_description_settings', 'metadata_description_id', $row['metadata_description_id'], $metadataDescription);
223 
224  return $metadataDescription;
225  }
226 
231  function _updateObjectMetadata(&$metadataDescription) {
232  // Inject a dummy meta-data adapter so that we can
233  // use the meta-data persistence infrastructure of the
234  // DAO and DataObject classes to persist our meta-data
235  // description.
236  import('lib.pkp.classes.metadata.MetadataDescriptionDummyAdapter');
237  $metadataAdapter = new MetadataDescriptionDummyAdapter($metadataDescription);
238  $metadataDescription->addSupportedMetadataAdapter($metadataAdapter);
239 
240  $this->updateDataObjectSettings('metadata_description_settings', $metadataDescription,
241  array('metadata_description_id' => $metadataDescription->getId()));
242  }
243 }
244 
245 ?>
Operations for retrieving and modifying objects from a database.
Definition: DAO.inc.php:30
updateObject(&$metadataDescription)
& retrieve($sql, $params=false, $callHooks=true)
Definition: DAO.inc.php:84
& getObjectById($metadataDescriptionId)
deleteObjectById($metadataDescriptionId)
insertObject(&$metadataDescription)
updateDataObjectSettings($tableName, &$dataObject, $idArray)
Definition: DAO.inc.php:474
& _newDataObject($metadataSchemaNamespace, $metadataSchemaName, $assocType)
& retrieveRange($sql, $params=false, $dbResultRange=null, $callHooks=true)
Definition: DAO.inc.php:174
Class that simulates a metadata adapter for metadata description object for direct metadata descripti...
deleteObject(&$metadataDescription)
Wrapper around ADORecordSet providing &quot;factory&quot; features for generating objects from DAOs...
& _resolveSchemaIdentifierToMetadataSchemaName($metadataSchemaId)
getDataObjectSettings($tableName, $idFieldName, $idFieldValue, &$dataObject)
Definition: DAO.inc.php:567
update($sql, $params=false, $callHooks=true, $dieOnError=true)
Definition: DAO.inc.php:208
Operations for retrieving and modifying MetadataDescription objects.
deleteObjectsByAssocId($assocType, $assocId)
_updateObjectMetadata(&$metadataDescription)
Class modeling a description (DCMI abstract model) or subject- predicate-object graph (RDF)...
getObjectsByAssocId($assocType, $assocId, $rangeInfo=null)