Open Journal Systems  3.0.0
 All Classes Namespaces Functions Variables Groups Pages
IssueGalleyDAO.inc.php
1 <?php
2 
17 import('classes.issue.IssueGalley');
18 
19 class IssueGalleyDAO extends DAO {
20 
24  function IssueGalleyDAO() {
25  parent::DAO();
26  }
27 
34  function getById($galleyId, $issueId = null) {
35  $params = array((int) $galleyId);
36  if ($issueId !== null) $params[] = (int) $issueId;
37  $result = $this->retrieve(
38  'SELECT
39  g.*,
40  f.file_name,
41  f.original_file_name,
42  f.file_type,
43  f.file_size,
44  f.content_type,
45  f.date_uploaded,
46  f.date_modified
47  FROM issue_galleys g
48  LEFT JOIN issue_files f ON (g.file_id = f.file_id)
49  WHERE g.galley_id = ?' .
50  ($issueId !== null?' AND g.issue_id = ?':''),
51  $params
52  );
53 
54  $returner = null;
55  if ($result->RecordCount() != 0) {
56  $returner = $this->_fromRow($result->GetRowAssoc(false));
57  } else {
58  HookRegistry::call('IssueGalleyDAO::getById', array(&$galleyId, &$issueId, &$returner));
59  }
60  $result->Close();
61  return $returner;
62  }
63 
75  function pubIdExists($pubIdType, $pubId, $galleyId, $journalId) {
76  $result = $this->retrieve(
77  'SELECT COUNT(*)
78  FROM issue_galley_settings igs
79  INNER JOIN issue_galleys ig ON igs.galley_id = ig.galley_id
80  INNER JOIN issues i ON ig.issue_id = i.issue_id
81  WHERE igs.setting_name = ? AND igs.setting_value = ? AND igs.galley_id <> ? AND i.journal_id = ?',
82  array(
83  'pub-id::'.$pubIdType,
84  $pubId,
85  (int) $galleyId,
86  (int) $journalId
87  )
88  );
89  $returner = $result->fields[0] ? true : false;
90  $result->Close();
91  return $returner;
92  }
93 
103  function getByPubId($pubIdType, $pubId, $issueId) {
104  $result = $this->retrieve(
105  'SELECT
106  g.*,
107  f.file_name,
108  f.original_file_name,
109  f.file_type,
110  f.file_size,
111  f.content_type,
112  f.date_uploaded,
113  f.date_modified
114  FROM issue_galleys g
115  INNER JOIN issue_galley_settings gs ON g.galley_id = gs.galley_id
116  LEFT JOIN issue_files f ON (g.file_id = f.file_id)
117  WHERE gs.setting_name = ? AND
118  gs.setting_value = ? AND
119  g.issue_id = ?',
120  array('pub-id::'.$pubIdType, $pubId, (int) $issueId)
121  );
122 
123  $returner = null;
124  if ($result->RecordCount() != 0) {
125  $returner = $this->_fromRow($result->GetRowAssoc(false));
126  } else {
127  HookRegistry::call('IssueGalleyDAO::getByPubId', array(&$pubIdType, &$pubId, &$issueId, &$returner));
128  }
129  $result->Close();
130  return $returner;
131  }
132 
138  function getByIssueId($issueId) {
139  $galleys = array();
140 
141  $result = $this->retrieve(
142  'SELECT
143  g.*,
144  f.file_name,
145  f.original_file_name,
146  f.file_type,
147  f.file_size,
148  f.content_type,
149  f.date_uploaded,
150  f.date_modified
151  FROM issue_galleys g
152  LEFT JOIN issue_files f ON (g.file_id = f.file_id)
153  WHERE g.issue_id = ? ORDER BY g.seq',
154  (int) $issueId
155  );
156 
157  while (!$result->EOF) {
158  $issueGalley = $this->_fromRow($result->GetRowAssoc(false));
159  $galleys[$issueGalley->getId()] = $issueGalley;
160  $result->MoveNext();
161  }
162 
163  $result->Close();
164  HookRegistry::call('IssueGalleyDAO::getGalleysByIssue', array(&$galleys, &$issueId));
165  return $galleys;
166  }
167 
175  function getByBestId($galleyId, $issueId) {
176  if ($galleyId != '') $galley =& $this->getByPubId('publisher-id', $galleyId, $issueId);
177  if (!isset($galley) && ctype_digit("$galleyId")) $galley = $this->getById((int) $galleyId, $issueId);
178  return $galley;
179  }
180 
185  function getLocaleFieldNames() {
186  return array();
187  }
188 
195  $additionalFields = parent::getAdditionalFieldNames();
196  // FIXME: Move this to a PID plug-in.
197  $additionalFields[] = 'pub-id::publisher-id';
198  return $additionalFields;
199  }
200 
205  function updateLocaleFields($galley) {
206  $this->updateDataObjectSettings('issue_galley_settings', $galley, array(
207  'galley_id' => $galley->getId()
208  ));
209  }
210 
215  function newDataObject() {
216  return new IssueGalley();
217  }
218 
224  function _fromRow($row) {
225  $galley = $this->newDataObject();
226 
227  $galley->setId($row['galley_id']);
228  $galley->setIssueId($row['issue_id']);
229  $galley->setLocale($row['locale']);
230  $galley->setFileId($row['file_id']);
231  $galley->setLabel($row['label']);
232  $galley->setSequence($row['seq']);
233 
234  // IssueFile set methods
235  $galley->setServerFileName($row['file_name']);
236  $galley->setOriginalFileName($row['original_file_name']);
237  $galley->setFileType($row['file_type']);
238  $galley->setFileSize($row['file_size']);
239  $galley->setContentType($row['content_type']);
240  $galley->setDateModified($this->datetimeFromDB($row['date_modified']));
241  $galley->setDateUploaded($this->datetimeFromDB($row['date_uploaded']));
242 
243  $this->getDataObjectSettings('issue_galley_settings', 'galley_id', $row['galley_id'], $galley);
244 
245  HookRegistry::call('IssueGalleyDAO::_fromRow', array(&$galley, &$row));
246 
247  return $galley;
248  }
249 
254  function insertObject($galley) {
255  $this->update(
256  'INSERT INTO issue_galleys
257  (issue_id,
258  file_id,
259  label,
260  locale,
261  seq)
262  VALUES
263  (?, ?, ?, ?, ?)',
264  array(
265  (int) $galley->getIssueId(),
266  (int) $galley->getFileId(),
267  $galley->getLabel(),
268  $galley->getLocale(),
269  $galley->getSequence() == null ? $this->getNextGalleySequence($galley->getIssueId()) : $galley->getSequence()
270  )
271  );
272  $galley->setId($this->getInsertId());
273  $this->updateLocaleFields($galley);
274 
275  HookRegistry::call('IssueGalleyDAO::insertObject', array(&$galley, $galley->getId()));
276 
277  return $galley->getId();
278  }
279 
284  function updateObject($galley) {
285  $this->update(
286  'UPDATE issue_galleys
287  SET
288  file_id = ?,
289  label = ?,
290  locale = ?,
291  seq = ?
292  WHERE galley_id = ?',
293  array(
294  (int) $galley->getFileId(),
295  $galley->getLabel(),
296  $galley->getLocale(),
297  $galley->getSequence(),
298  (int) $galley->getId()
299  )
300  );
301  $this->updateLocaleFields($galley);
302  }
303 
308  function deleteObject($galley) {
309  return $this->deleteById($galley->getId(), $galley->getIssueId());
310  }
311 
317  function deleteById($galleyId, $issueId = null) {
318  HookRegistry::call('IssueGalleyDAO::deleteGalleyById', array(&$galleyId, &$issueId));
319 
320  if (isset($issueId)) {
321  $this->update(
322  'DELETE FROM issue_galleys WHERE galley_id = ? AND issue_id = ?',
323  array((int) $galleyId, (int) $issueId)
324  );
325  } else {
326  $this->update(
327  'DELETE FROM issue_galleys WHERE galley_id = ?', (int) $galleyId
328  );
329  }
330  if ($this->getAffectedRows()) {
331  $this->update('DELETE FROM issue_galley_settings WHERE galley_id = ?', array((int) $galleyId));
332  }
333  }
334 
340  function deleteByIssueId($issueId) {
341  $galleys = $this->getByIssueId($issueId);
342  foreach ($galleys as $galley) {
343  $this->deleteById($galley->getId(), $issueId);
344  }
345  }
346 
353  function galleyExistsByFileId($issueId, $fileId) {
354  $result = $this->retrieve(
355  'SELECT COUNT(*) FROM issue_galleys
356  WHERE issue_id = ? AND file_id = ?',
357  array((int) $issueId, (int) $fileId)
358  );
359 
360  $returner = isset($result->fields[0]) && $result->fields[0] == 1 ? true : false;
361  $result->Close();
362  return $returner;
363  }
364 
369  function incrementViews($galleyId) {
370  if ( !HookRegistry::call('IssueGalleyDAO::incrementViews', array(&$galleyId)) ) {
371  return $this->update(
372  'UPDATE issue_galleys SET views = views + 1 WHERE galley_id = ?',
373  (int) $galleyId
374  );
375  } else return false;
376  }
377 
382  function resequence($issueId) {
383  $result = $this->retrieve(
384  'SELECT galley_id FROM issue_galleys WHERE issue_id = ? ORDER BY seq',
385  (int) $issueId
386  );
387 
388  for ($i=1; !$result->EOF; $i++) {
389  list($galleyId) = $result->fields;
390  $this->update(
391  'UPDATE issue_galleys SET seq = ? WHERE galley_id = ?',
392  array($i, $galleyId)
393  );
394  $result->MoveNext();
395  }
396 
397  $result->Close();
398  }
399 
405  function getNextGalleySequence($issueId) {
406  $result = $this->retrieve(
407  'SELECT MAX(seq) + 1 FROM issue_galleys WHERE issue_id = ?',
408  (int) $issueId
409  );
410  $returner = floor($result->fields[0]);
411  $result->Close();
412  return $returner;
413  }
414 
419  function getInsertId() {
420  return $this->_getInsertId('issue_galleys', 'galley_id');
421  }
422 }
423 
424 ?>
galleyExistsByFileId($issueId, $fileId)
Operations for retrieving and modifying IssueGalley objects.
getByBestId($galleyId, $issueId)
Operations for retrieving and modifying objects from a database.
Definition: DAO.inc.php:30
& retrieve($sql, $params=false, $callHooks=true)
Definition: DAO.inc.php:84
getNextGalleySequence($issueId)
deleteById($galleyId, $issueId=null)
updateDataObjectSettings($tableName, &$dataObject, $idArray)
Definition: DAO.inc.php:457
_getInsertId($table= '', $id= '')
Definition: DAO.inc.php:249
pubIdExists($pubIdType, $pubId, $galleyId, $journalId)
datetimeFromDB($dt)
Definition: DAO.inc.php:313
getAffectedRows()
Definition: DAO.inc.php:258
static call($hookName, $args=null)
getByPubId($pubIdType, $pubId, $issueId)
getById($galleyId, $issueId=null)
incrementViews($galleyId)
A galley is a final presentation version of the full-text of an issue.
update($sql, $params=false, $callHooks=true, $dieOnError=true)
Definition: DAO.inc.php:208