Open Journal Systems  2.4.3
 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  unset($result);
71 
72  return $metadataDescription;
73  }
74 
82  function &getObjectsByAssocId($assocType, $assocId, $rangeInfo = null) {
83  $result =& $this->retrieveRange(
84  'SELECT *
85  FROM metadata_descriptions
86  WHERE assoc_type = ? AND assoc_id = ?
87  ORDER BY metadata_description_id DESC',
88  array((int)$assocType, (int)$assocId),
89  $rangeInfo
90  );
91 
92  $returner = new DAOResultFactory($result, $this, '_fromRow', array('id'));
93  return $returner;
94  }
95 
100  function updateObject(&$metadataDescription) {
101  $metadataSchema =& $metadataDescription->getMetadataSchema();
102  $returner = $this->update(
103  'UPDATE metadata_descriptions
104  SET assoc_type = ?,
105  assoc_id = ?,
106  schema_name = ?,
107  schema_namespace = ?,
108  display_name = ?,
109  seq = ?
110  WHERE metadata_description_id = ?',
111  array(
112  (integer)$metadataDescription->getAssocType(),
113  (integer)$metadataDescription->getAssocId(),
114  $metadataSchema->getName(),
115  $metadataSchema->getNamespace(),
116  $metadataDescription->getDisplayName(),
117  $metadataDescription->getSeq(),
118  $metadataDescription->getId()
119  )
120  );
121  $this->_updateObjectMetadata($metadataDescription);
122  }
123 
129  function deleteObject(&$metadataDescription) {
130  return $this->deleteObjectById($metadataDescription->getId());
131  }
132 
138  function deleteObjectById($metadataDescriptionId) {
139  $params = array((int)$metadataDescriptionId);
140  $this->update('DELETE FROM metadata_descriptions WHERE metadata_description_id = ?', $params);
141  return $this->update('DELETE FROM metadata_description_settings WHERE metadata_description_id = ?', $params);
142  }
143 
150  function deleteObjectsByAssocId($assocType, $assocId) {
151  $metadataDescriptions =& $this->getObjectsByAssocId($assocType, $assocId);
152  while ($metadataDescription =& $metadataDescriptions->next()) {
153  $this->deleteObjectById($metadataDescription->getId());
154  unset($metadataDescription);
155  }
156  return true;
157  }
158 
159  //
160  // Protected helper methods
161  //
166  function getInsertId() {
167  return parent::getInsertId('metadata_descriptions', 'metadata_description_id');
168  }
169 
170 
171  //
172  // Private helper methods
173  //
184  function &_resolveSchemaIdentifierToMetadataSchemaName($metadataSchemaId) {
185  static $metadataSchemaMapping = array(
186  'nlm30:nlm-3.0-element-citation' => 'lib.pkp.plugins.metadata.nlm30.schema.Nlm30CitationSchema',
187  'nlm30:nlm-3.0-name' => 'lib.pkp.plugins.metadata.nlm30.schema.Nlm30NameSchema',
188  'openurl10:openurl-1.0-journal' => 'lib.pkp.plugins.metadata.nlm30.schema.Openurl10JournalSchema',
189  'openurl10:openurl-1.0-book' => 'lib.pkp.plugins.metadata.nlm30.schema.Openurl10BookSchema',
190  'openurl10:openurl-1.0-dissertation' => 'lib.pkp.plugins.metadata.nlm30.schema.Openurl10DissertationSchema'
191  );
192 
193  // Map the metadata schema identifier to a metadata schema class name.
194  assert(isset($metadataSchemaMapping[$metadataSchemaId]));
195  $metadataSchemaName = $metadataSchemaMapping[$metadataSchemaId];
196  return $metadataSchemaName;
197  }
198 
207  function &_newDataObject($metadataSchemaNamespace, $metadataSchemaName, $assocType) {
208  $metadataSchemaName =& $this->_resolveSchemaIdentifierToMetadataSchemaName($metadataSchemaNamespace.':'.$metadataSchemaName);
209  $metadataDescription = new MetadataDescription($metadataSchemaName, $assocType);
210  return $metadataDescription;
211  }
212 
219  function &_fromRow(&$row) {
220  $metadataDescription =& $this->_newDataObject($row['schema_namespace'], $row['schema_name'], (int)$row['assoc_type']);
221  $metadataDescription->setId((int)$row['metadata_description_id']);
222  $metadataDescription->setAssocId((int)$row['assoc_id']);
223  $metadataDescription->setDisplayName($row['display_name']);
224  $metadataDescription->setSeq((int)$row['seq']);
225 
226  $this->getDataObjectSettings('metadata_description_settings', 'metadata_description_id', $row['metadata_description_id'], $metadataDescription);
227 
228  return $metadataDescription;
229  }
230 
235  function _updateObjectMetadata(&$metadataDescription) {
236  // Inject a dummy meta-data adapter so that we can
237  // use the meta-data persistence infrastructure of the
238  // DAO and DataObject classes to persist our meta-data
239  // description.
240  import('lib.pkp.classes.metadata.MetadataDescriptionDummyAdapter');
241  $metadataAdapter = new MetadataDescriptionDummyAdapter($metadataDescription);
242  $metadataDescription->addSupportedMetadataAdapter($metadataAdapter);
243 
244  $this->updateDataObjectSettings('metadata_description_settings', $metadataDescription,
245  array('metadata_description_id' => $metadataDescription->getId()));
246  }
247 }
248 
249 ?>
Operations for retrieving and modifying objects from a database.
Definition: DAO.inc.php:29
updateObject(&$metadataDescription)
& retrieve($sql, $params=false, $callHooks=true)
Definition: DAO.inc.php:83
& getObjectById($metadataDescriptionId)
deleteObjectById($metadataDescriptionId)
insertObject(&$metadataDescription)
updateDataObjectSettings($tableName, &$dataObject, $idArray)
Definition: DAO.inc.php:460
& _newDataObject($metadataSchemaNamespace, $metadataSchemaName, $assocType)
& retrieveRange($sql, $params=false, $dbResultRange=null, $callHooks=true)
Definition: DAO.inc.php:176
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)
update($sql, $params=false, $callHooks=true, $dieOnError=true)
Definition: DAO.inc.php:211
Operations for retrieving and modifying MetadataDescription objects.
deleteObjectsByAssocId($assocType, $assocId)
_updateObjectMetadata(&$metadataDescription)
& getObjectsByAssocId($assocType, $assocId, $rangeInfo=null)
Class modeling a description (DCMI abstract model) or subject- predicate-object graph (RDF)...