Open Journal Systems  2.4.3
 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 &getGalley($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->_returnGalleyFromRow($result->GetRowAssoc(false));
57  } else {
58  HookRegistry::call('IssueGalleyDAO::getGalley', array(&$galleyId, &$issueId, &$returner));
59  }
60 
61  $result->Close();
62  unset($result);
63 
64  return $returner;
65  }
66 
78  function pubIdExists($pubIdType, $pubId, $galleyId, $journalId) {
79  $result =& $this->retrieve(
80  'SELECT COUNT(*)
81  FROM issue_galley_settings igs
82  INNER JOIN issue_galleys ig ON igs.galley_id = ig.galley_id
83  INNER JOIN issues i ON ig.issue_id = i.issue_id
84  WHERE igs.setting_name = ? AND igs.setting_value = ? AND igs.galley_id <> ? AND i.journal_id = ?',
85  array(
86  'pub-id::'.$pubIdType,
87  $pubId,
88  (int) $galleyId,
89  (int) $journalId
90  )
91  );
92  $returner = $result->fields[0] ? true : false;
93 
94  $result->Close();
95  unset($result);
96 
97  return $returner;
98  }
99 
109  function &getGalleyByPubId($pubIdType, $pubId, $issueId) {
110  $result =& $this->retrieve(
111  'SELECT
112  g.*,
113  f.file_name,
114  f.original_file_name,
115  f.file_type,
116  f.file_size,
117  f.content_type,
118  f.date_uploaded,
119  f.date_modified
120  FROM issue_galleys g
121  INNER JOIN issue_galley_settings gs ON g.galley_id = gs.galley_id
122  LEFT JOIN issue_files f ON (g.file_id = f.file_id)
123  WHERE gs.setting_name = ? AND
124  gs.setting_value = ? AND
125  g.issue_id = ?',
126  array('pub-id::'.$pubIdType, $pubId, (int) $issueId)
127  );
128 
129  $returner = null;
130  if ($result->RecordCount() != 0) {
131  $returner =& $this->_returnGalleyFromRow($result->GetRowAssoc(false));
132  } else {
133  HookRegistry::call('IssueGalleyDAO::getGalleyByPubId', array(&$galleyId, &$issueId, &$returner));
134  }
135 
136  $result->Close();
137  unset($result);
138 
139  return $returner;
140  }
141 
147  function &getGalleysByIssue($issueId) {
148  $galleys = array();
149 
150  $result =& $this->retrieve(
151  'SELECT
152  g.*,
153  f.file_name,
154  f.original_file_name,
155  f.file_type,
156  f.file_size,
157  f.content_type,
158  f.date_uploaded,
159  f.date_modified
160  FROM issue_galleys g
161  LEFT JOIN issue_files f ON (g.file_id = f.file_id)
162  WHERE g.issue_id = ? ORDER BY g.seq',
163  (int) $issueId
164  );
165 
166  while (!$result->EOF) {
167  $galleys[] =& $this->_returnGalleyFromRow($result->GetRowAssoc(false));
168  $result->moveNext();
169  }
170 
171  $result->Close();
172  unset($result);
173 
174  HookRegistry::call('IssueGalleyDAO::getGalleysByIssue', array(&$galleys, &$issueId));
175 
176  return $galleys;
177  }
178 
186  function &getGalleyByBestGalleyId($galleyId, $issueId) {
187  if ($galleyId != '') $galley =& $this->getGalleyByPubId('publisher-id', $galleyId, $issueId);
188  if (!isset($galley) && ctype_digit("$galleyId")) $galley =& $this->getGalley((int) $galleyId, $issueId);
189  return $galley;
190  }
191 
196  function getLocaleFieldNames() {
197  return array();
198  }
199 
206  $additionalFields = parent::getAdditionalFieldNames();
207  // FIXME: Move this to a PID plug-in.
208  $additionalFields[] = 'pub-id::publisher-id';
209  return $additionalFields;
210  }
211 
216  function updateLocaleFields(&$galley) {
217  $this->updateDataObjectSettings('issue_galley_settings', $galley, array(
218  'galley_id' => $galley->getId()
219  ));
220  }
221 
227  function &_returnGalleyFromRow(&$row) {
228  $galley = new IssueGalley();
229 
230  $galley->setId($row['galley_id']);
231  $galley->setIssueId($row['issue_id']);
232  $galley->setLocale($row['locale']);
233  $galley->setFileId($row['file_id']);
234  $galley->setLabel($row['label']);
235  $galley->setSequence($row['seq']);
236 
237  // IssueFile set methods
238  $galley->setFileName($row['file_name']);
239  $galley->setOriginalFileName($row['original_file_name']);
240  $galley->setFileType($row['file_type']);
241  $galley->setFileSize($row['file_size']);
242  $galley->setContentType($row['content_type']);
243  $galley->setDateModified($this->datetimeFromDB($row['date_modified']));
244  $galley->setDateUploaded($this->datetimeFromDB($row['date_uploaded']));
245 
246  $this->getDataObjectSettings('issue_galley_settings', 'galley_id', $row['galley_id'], $galley);
247 
248  HookRegistry::call('IssueGalleyDAO::_returnGalleyFromRow', array(&$galley, &$row));
249 
250  return $galley;
251  }
252 
257  function insertGalley(&$galley) {
258  $this->update(
259  'INSERT INTO issue_galleys
260  (issue_id,
261  file_id,
262  label,
263  locale,
264  seq)
265  VALUES
266  (?, ?, ?, ?, ?)',
267  array(
268  (int) $galley->getIssueId(),
269  (int) $galley->getFileId(),
270  $galley->getLabel(),
271  $galley->getLocale(),
272  $galley->getSequence() == null ? $this->getNextGalleySequence($galley->getIssueId()) : $galley->getSequence()
273  )
274  );
275  $galley->setId($this->getInsertGalleyId());
276  $this->updateLocaleFields($galley);
277 
278  HookRegistry::call('IssueGalleyDAO::insertGalley', array(&$galley, $galley->getId()));
279 
280  return $galley->getId();
281  }
282 
287  function updateGalley(&$galley) {
288  $this->update(
289  'UPDATE issue_galleys
290  SET
291  file_id = ?,
292  label = ?,
293  locale = ?,
294  seq = ?
295  WHERE galley_id = ?',
296  array(
297  (int) $galley->getFileId(),
298  $galley->getLabel(),
299  $galley->getLocale(),
300  $galley->getSequence(),
301  (int) $galley->getId()
302  )
303  );
304  $this->updateLocaleFields($galley);
305  }
306 
311  function deleteGalley(&$galley) {
312  return $this->deleteGalleyById($galley->getId(), $galley->getIssueId());
313  }
314 
320  function deleteGalleyById($galleyId, $issueId = null) {
321  HookRegistry::call('IssueGalleyDAO::deleteGalleyById', array(&$galleyId, &$issueId));
322 
323  if (isset($issueId)) {
324  $this->update(
325  'DELETE FROM issue_galleys WHERE galley_id = ? AND issue_id = ?',
326  array((int) $galleyId, (int) $issueId)
327  );
328  } else {
329  $this->update(
330  'DELETE FROM issue_galleys WHERE galley_id = ?', (int) $galleyId
331  );
332  }
333  if ($this->getAffectedRows()) {
334  $this->update('DELETE FROM issue_galley_settings WHERE galley_id = ?', array((int) $galleyId));
335  }
336  }
337 
343  function deleteGalleysByIssue($issueId) {
344  $galleys =& $this->getGalleysByIssue($issueId);
345  foreach ($galleys as $galley) {
346  $this->deleteGalleyById($galley->getId(), $issueId);
347  }
348  }
349 
356  function galleyExistsByFileId($issueId, $fileId) {
357  $result =& $this->retrieve(
358  'SELECT COUNT(*) FROM issue_galleys
359  WHERE issue_id = ? AND file_id = ?',
360  array((int) $issueId, (int) $fileId)
361  );
362 
363  $returner = isset($result->fields[0]) && $result->fields[0] == 1 ? true : false;
364 
365  $result->Close();
366  unset($result);
367 
368  return $returner;
369  }
370 
375  function incrementViews($galleyId) {
376  if ( !HookRegistry::call('IssueGalleyDAO::incrementViews', array(&$galleyId)) ) {
377  return $this->update(
378  'UPDATE issue_galleys SET views = views + 1 WHERE galley_id = ?',
379  (int) $galleyId
380  );
381  } else return false;
382  }
383 
388  function resequenceGalleys($issueId) {
389  $result =& $this->retrieve(
390  'SELECT galley_id FROM issue_galleys WHERE issue_id = ? ORDER BY seq',
391  (int) $issueId
392  );
393 
394  for ($i=1; !$result->EOF; $i++) {
395  list($galleyId) = $result->fields;
396  $this->update(
397  'UPDATE issue_galleys SET seq = ? WHERE galley_id = ?',
398  array($i, $galleyId)
399  );
400  $result->moveNext();
401  }
402 
403  $result->close();
404  unset($result);
405  }
406 
412  function getNextGalleySequence($issueId) {
413  $result =& $this->retrieve(
414  'SELECT MAX(seq) + 1 FROM issue_galleys WHERE issue_id = ?',
415  (int) $issueId
416  );
417  $returner = floor($result->fields[0]);
418 
419  $result->Close();
420  unset($result);
421 
422  return $returner;
423  }
424 
429  function getInsertGalleyId() {
430  return $this->getInsertId('issue_galleys', 'galley_id');
431  }
432 }
433 
434 ?>
galleyExistsByFileId($issueId, $fileId)
deleteGalleyById($galleyId, $issueId=null)
Operations for retrieving and modifying IssueGalley objects.
Operations for retrieving and modifying objects from a database.
Definition: DAO.inc.php:29
& getGalleysByIssue($issueId)
& retrieve($sql, $params=false, $callHooks=true)
Definition: DAO.inc.php:83
getInsertId($table= '', $id= '', $callHooks=true)
Definition: DAO.inc.php:252
getNextGalleySequence($issueId)
updateDataObjectSettings($tableName, &$dataObject, $idArray)
Definition: DAO.inc.php:460
pubIdExists($pubIdType, $pubId, $galleyId, $journalId)
datetimeFromDB($dt)
Definition: DAO.inc.php:316
& getGalleyByBestGalleyId($galleyId, $issueId)
getAffectedRows()
Definition: DAO.inc.php:261
updateLocaleFields(&$galley)
incrementViews($galleyId)
& getGalleyByPubId($pubIdType, $pubId, $issueId)
call($hookName, $args=null)
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:211
& getGalley($galleyId, $issueId=null)
deleteGalleysByIssue($issueId)
resequenceGalleys($issueId)
& _returnGalleyFromRow(&$row)