Open Monograph Press  1.1
 All Classes Namespaces Functions Variables Groups Pages
PublicationFormatDAO.inc.php
1 <?php
16 import('classes.publicationFormat.PublicationFormat');
17 import('lib.pkp.classes.submission.RepresentationDAO');
18 
23  function PublicationFormatDAO() {
24  parent::RepresentationDAO();
25  }
26 
34  function getById($publicationFormatId, $monographId = null, $pressId = null) {
35  $params = array((int) $publicationFormatId);
36  if ($monographId) $params[] = (int) $monographId;
37  if ($pressId) $params[] = (int) $pressId;
38 
39  $result = $this->retrieve(
40  'SELECT pf.*
41  FROM publication_formats pf
42  ' . ($pressId?' JOIN submissions s ON (s.submission_id = pf.submission_id)':'') . '
43  WHERE pf.publication_format_id = ?' .
44  ($monographId?' AND pf.submission_id = ?':'') .
45  ($pressId?' AND s.context_id = ?':''),
46  $params
47  );
48 
49  $returner = null;
50  if ($result->RecordCount() != 0) {
51  $returner = $this->_fromRow($result->GetRowAssoc(false));
52  }
53 
54  $result->Close();
55  return $returner;
56  }
57 
63  function getBySubmissionId($submissionId) {
64  $result = $this->retrieve(
65  'SELECT *
66  FROM publication_formats
67  WHERE submission_id = ?',
68  (int) $submissionId
69  );
70 
71  return new DAOResultFactory($result, $this, '_fromRow');
72  }
73 
79  function getByPressId($pressId) {
80  $params = array((int) $pressId);
81  $result = $this->retrieve(
82  'SELECT pf.*
83  FROM publication_formats pf
84  JOIN submissions s ON (s.submission_id = pf.submission_id)
85  WHERE s.context_id = ?',
86  $params
87  );
88 
89  return new DAOResultFactory($result, $this, '_fromRow');
90  }
91 
97  function getApprovedBySubmissionId($submissionId) {
98  $result = $this->retrieve(
99  'SELECT *
100  FROM publication_formats
101  WHERE submission_id = ? AND is_approved = 1',
102  (int) $submissionId
103  );
104 
105  return new DAOResultFactory($result, $this, '_fromRow');
106  }
107 
112  function deleteById($publicationFormatId) {
113  // remove settings, then the association itself.
114  $this->update('DELETE FROM publication_format_settings WHERE publication_format_id = ?', (int) $publicationFormatId);
115  return $this->update('DELETE FROM publication_formats WHERE publication_format_id = ?', (int) $publicationFormatId);
116  }
117 
122  function updateLocaleFields(&$publicationFormat) {
124  'publication_format_settings',
125  $publicationFormat,
126  array('publication_format_id' => $publicationFormat->getId())
127  );
128  }
129 
134  function newDataObject() {
135  return new PublicationFormat();
136  }
137 
144  function _fromRow($row, $callHooks = true) {
145  $publicationFormat = $this->newDataObject();
146 
147  // Add the additional Publication Format data
148  $publicationFormat->setIsApproved($row['is_approved']);
149  $publicationFormat->setEntryKey($row['entry_key']);
150  $publicationFormat->setPhysicalFormat($row['physical_format']);
151  $publicationFormat->setSeq($row['seq']);
152  $publicationFormat->setId($row['publication_format_id']);
153  $publicationFormat->setSubmissionId($row['submission_id']);
154  $publicationFormat->setFileSize($row['file_size']);
155  $publicationFormat->setFrontMatter($row['front_matter']);
156  $publicationFormat->setBackMatter($row['back_matter']);
157  $publicationFormat->setHeight($row['height']);
158  $publicationFormat->setHeightUnitCode($row['height_unit_code']);
159  $publicationFormat->setWidth($row['width']);
160  $publicationFormat->setWidthUnitCode($row['width_unit_code']);
161  $publicationFormat->setThickness($row['thickness']);
162  $publicationFormat->setThicknessUnitCode($row['thickness_unit_code']);
163  $publicationFormat->setWeight($row['weight']);
164  $publicationFormat->setWeightUnitCode($row['weight_unit_code']);
165  $publicationFormat->setProductCompositionCode($row['product_composition_code']);
166  $publicationFormat->setProductFormDetailCode($row['product_form_detail_code']);
167  $publicationFormat->setCountryManufactureCode($row['country_manufacture_code']);
168  $publicationFormat->setImprint($row['imprint']);
169  $publicationFormat->setProductAvailabilityCode($row['product_availability_code']);
170  $publicationFormat->setTechnicalProtectionCode($row['technical_protection_code']);
171  $publicationFormat->setReturnableIndicatorCode($row['returnable_indicator_code']);
172  $publicationFormat->setIsAvailable($row['is_available']);
173 
174  $this->getDataObjectSettings('publication_format_settings', 'publication_format_id', $row['publication_format_id'], $publicationFormat);
175 
176  if ($callHooks) HookRegistry::call('PublicationFormatDAO::_fromRow', array(&$publicationFormat, &$row));
177  return $publicationFormat;
178  }
179 
185  function insertObject(&$publicationFormat) {
186  $this->update(
187  'INSERT INTO publication_formats
188  (is_approved, entry_key, physical_format, submission_id, seq, file_size, front_matter, back_matter, height, height_unit_code, width, width_unit_code, thickness, thickness_unit_code, weight, weight_unit_code, product_composition_code, product_form_detail_code, country_manufacture_code, imprint, product_availability_code, technical_protection_code, returnable_indicator_code, is_available)
189  VALUES
190  (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)',
191  array(
192  (int) $publicationFormat->getIsApproved(),
193  $publicationFormat->getEntryKey(),
194  (int) $publicationFormat->getPhysicalFormat(),
195  (int) $publicationFormat->getMonographId(),
196  (int) $publicationFormat->getSeq(),
197  $publicationFormat->getFileSize(),
198  $publicationFormat->getFrontMatter(),
199  $publicationFormat->getBackMatter(),
200  $publicationFormat->getHeight(),
201  $publicationFormat->getHeightUnitCode(),
202  $publicationFormat->getWidth(),
203  $publicationFormat->getWidthUnitCode(),
204  $publicationFormat->getThickness(),
205  $publicationFormat->getThicknessUnitCode(),
206  $publicationFormat->getWeight(),
207  $publicationFormat->getWeightUnitCode(),
208  $publicationFormat->getProductCompositionCode(),
209  $publicationFormat->getProductFormDetailCode(),
210  $publicationFormat->getCountryManufactureCode(),
211  $publicationFormat->getImprint(),
212  $publicationFormat->getProductAvailabilityCode(),
213  $publicationFormat->getTechnicalProtectionCode(),
214  $publicationFormat->getReturnableIndicatorCode(),
215  (int) $publicationFormat->getIsAvailable(),
216  )
217  );
218 
219  $publicationFormat->setId($this->_getInsertId('publication_formats', 'publication_format_id'));
220  $this->updateLocaleFields($publicationFormat);
221 
222  return $publicationFormat->getId();
223  }
224 
229  function updateObject(&$publicationFormat) {
230  $this->update(
231  'UPDATE publication_formats
232  SET is_approved = ?,
233  entry_key = ?,
234  physical_format = ?,
235  seq = ?,
236  file_size = ?,
237  front_matter = ?,
238  back_matter = ?,
239  height = ?,
240  height_unit_code = ?,
241  width = ?,
242  width_unit_code = ?,
243  thickness = ?,
244  thickness_unit_code = ?,
245  weight = ?,
246  weight_unit_code = ?,
247  product_composition_code = ?,
248  product_form_detail_code = ?,
249  country_manufacture_code = ?,
250  imprint = ?,
251  product_availability_code = ?,
252  technical_protection_code = ?,
253  returnable_indicator_code = ?,
254  is_available = ?
255  WHERE publication_format_id = ?',
256  array(
257  (int) $publicationFormat->getIsApproved(),
258  $publicationFormat->getEntryKey(),
259  (int) $publicationFormat->getPhysicalFormat(),
260  (int) $publicationFormat->getSeq(),
261  $publicationFormat->getFileSize(),
262  $publicationFormat->getFrontMatter(),
263  $publicationFormat->getBackMatter(),
264  $publicationFormat->getHeight(),
265  $publicationFormat->getHeightUnitCode(),
266  $publicationFormat->getWidth(),
267  $publicationFormat->getWidthUnitCode(),
268  $publicationFormat->getThickness(),
269  $publicationFormat->getThicknessUnitCode(),
270  $publicationFormat->getWeight(),
271  $publicationFormat->getWeightUnitCode(),
272  $publicationFormat->getProductCompositionCode(),
273  $publicationFormat->getProductFormDetailCode(),
274  $publicationFormat->getCountryManufactureCode(),
275  $publicationFormat->getImprint(),
276  $publicationFormat->getProductAvailabilityCode(),
277  $publicationFormat->getTechnicalProtectionCode(),
278  $publicationFormat->getReturnableIndicatorCode(),
279  (int) $publicationFormat->getIsAvailable(),
280  (int) $publicationFormat->getId()
281  )
282  );
283 
284  $this->updateLocaleFields($publicationFormat);
285  }
286 
291  function getLocaleFieldNames() {
292  return array('name');
293  }
294 
299  $additionalFields = parent::getAdditionalFieldNames();
300  $additionalFields[] = 'pub-id::doi';
301  $additionalFields[] = 'doiSuffix';
302  return $additionalFields;
303  }
304 
312  function deleteAllPubIds($pressId, $pubIdType) {
313  $pressId = (int) $pressId;
314  $settingName = 'pub-id::'.$pubIdType;
315 
316  $formats = $this->getByPressId($pressId);
317  while ($format = $formats->next()) {
318  $this->update(
319  'DELETE FROM publication_format_settings WHERE setting_name = ? AND publication_format_id = ?',
320  array(
321  $settingName,
322  (int)$format->getId()
323  )
324  );
325  }
326  $this->flushCache();
327  }
328 
337  function changePubId($formatId, $pubIdType, $pubId) {
338  $publicationFormat = $this->getById($formatId);
339  $publicationFormat->setData('pub-id::'.$pubIdType, $pubId);
340  $this->updateObject($publicationFormat);
341  }
342 
354  function pubIdExists($pubIdType, $pubId, $formatId, $pressId) {
355  $result = $this->retrieve(
356  'SELECT COUNT(*)
357  FROM publication_format_settings pft
358  INNER JOIN publication_formats p ON pft.publication_format_id = p.publication_format_id
359  INNER JOIN submissions s ON p.submission_id = s.submission_id
360  WHERE pft.setting_name = ? and pft.setting_value = ? and p.submission_id <> ? AND s.context_id = ?',
361  array(
362  'pub-id::'.$pubIdType,
363  $pubId,
364  (int) $formatId,
365  (int) $pressId
366  )
367  );
368  $returner = $result->fields[0] ? true : false;
369  $result->Close();
370  return $returner;
371  }
372 }
373 
374 ?>
Abstract DAO for fetching/working with DB storage of Representation objects.
getById($publicationFormatId, $monographId=null, $pressId=null)
& retrieve($sql, $params=false, $callHooks=true)
Definition: DAO.inc.php:84
getApprovedBySubmissionId($submissionId)
updateObject(&$publicationFormat)
updateDataObjectSettings($tableName, &$dataObject, $idArray)
Definition: DAO.inc.php:457
_getInsertId($table= '', $id= '')
Definition: DAO.inc.php:249
static call($hookName, $args=null)
Wrapper around ADORecordSet providing &quot;factory&quot; features for generating objects from DAOs...
A publication format for a monograph.
updateLocaleFields(&$publicationFormat)
_fromRow($row, $callHooks=true)
flushCache()
Definition: DAO.inc.php:282
Operations for retrieving and modifying PublicationFormat objects.
update($sql, $params=false, $callHooks=true, $dieOnError=true)
Definition: DAO.inc.php:208
insertObject(&$publicationFormat)
deleteById($publicationFormatId)
pubIdExists($pubIdType, $pubId, $formatId, $pressId)
deleteAllPubIds($pressId, $pubIdType)
changePubId($formatId, $pubIdType, $pubId)