ocs  2.3.6
About: OCS (Open Conference System) is a Web publishing tool that will create a complete Web presence for your scholarly conference.
  Fossies Dox: ocs-2.3.6.tar.gz  ("inofficial" and yet experimental doxygen-generated source code documentation)  

PaperGalleyDAO.inc.php
Go to the documentation of this file.
1 <?php
2 
16 //$Id$
17 
18 import('paper.PaperGalley');
19 import('paper.PaperHTMLGalley');
20 
21 class PaperGalleyDAO extends DAO {
24 
28  function PaperGalleyDAO() {
29  parent::DAO();
30  $this->paperFileDao =& DAORegistry::getDAO('PaperFileDAO');
31  }
32 
39  function &getGalley($galleyId, $paperId = null) {
40  if (isset($paperId)) {
41  $result =& $this->retrieve(
42  'SELECT g.*,
43  a.file_name, a.original_file_name, a.file_type, a.file_size, a.date_uploaded, a.date_modified
44  FROM paper_galleys g
45  LEFT JOIN paper_files a ON (g.file_id = a.file_id)
46  WHERE g.galley_id = ? AND g.paper_id = ?',
47  array($galleyId, $paperId)
48  );
49 
50  } else {
51  $result =& $this->retrieve(
52  'SELECT g.*,
53  a.file_name, a.original_file_name, a.file_type, a.file_size, a.date_uploaded, a.date_modified
54  FROM paper_galleys g
55  LEFT JOIN paper_files a ON (g.file_id = a.file_id)
56  WHERE g.galley_id = ?',
57  $galleyId
58  );
59  }
60 
61  $returner = null;
62  if ($result->RecordCount() != 0) {
63  $returner =& $this->_returnGalleyFromRow($result->GetRowAssoc(false));
64  }
65 
66  $result->Close();
67  unset($result);
68 
69  return $returner;
70  }
71 
77  function &getGalleysByPaper($paperId) {
78  $galleys = array();
79 
80  $result =& $this->retrieve(
81  'SELECT g.*,
82  a.file_name, a.original_file_name, a.file_type, a.file_size, a.date_uploaded, a.date_modified
83  FROM paper_galleys g
84  LEFT JOIN paper_files a ON (g.file_id = a.file_id)
85  WHERE g.paper_id = ? ORDER BY g.seq',
86  $paperId
87  );
88 
89  while (!$result->EOF) {
90  $galleys[] =& $this->_returnGalleyFromRow($result->GetRowAssoc(false));
91  $result->moveNext();
92  }
93 
94  $result->Close();
95  unset($result);
96 
97  HookRegistry::call('PaperGalleyDAO::getGalleysByPaper', array(&$galleys, &$paperId));
98 
99  return $galleys;
100  }
101 
107  function &_returnGalleyFromRow(&$row) {
108  if ($row['html_galley']) {
109  $galley = new PaperHTMLGalley();
110 
111  // HTML-specific settings
112  $galley->setStyleFileId($row['style_file_id']);
113  if ($row['style_file_id']) {
114  $galley->setStyleFile($this->paperFileDao->getPaperFile($row['style_file_id']));
115  }
116 
117  // Retrieve images
118  $images =& $this->getGalleyImages($row['galley_id']);
119  $galley->setImageFiles($images);
120 
121  } else {
122  $galley = new PaperGalley();
123  }
124  $galley->setId($row['galley_id']);
125  $galley->setPaperId($row['paper_id']);
126  $galley->setLocale($row['locale']);
127  $galley->setFileId($row['file_id']);
128  $galley->setLabel($row['label']);
129  $galley->setSequence($row['seq']);
130  $galley->setViews($row['views']);
131 
132  // PaperFile set methods
133  $galley->setFileName($row['file_name']);
134  $galley->setOriginalFileName($row['original_file_name']);
135  $galley->setFileType($row['file_type']);
136  $galley->setFileSize($row['file_size']);
137  $galley->setDateModified($this->datetimeFromDB($row['date_modified']));
138  $galley->setDateUploaded($this->datetimeFromDB($row['date_uploaded']));
139 
140  HookRegistry::call('PaperGalleyDAO::_returnGalleyFromRow', array(&$galley, &$row));
141 
142  return $galley;
143  }
144 
149  function insertGalley(&$galley) {
150  $this->update(
151  'INSERT INTO paper_galleys
152  (paper_id, file_id, label, locale, html_galley, style_file_id, seq)
153  VALUES
154  (?, ?, ?, ?, ?, ?, ?)',
155  array(
156  $galley->getPaperId(),
157  $galley->getFileId(),
158  $galley->getLabel(),
159  $galley->getLocale(),
160  (int)$galley->isHTMLGalley(),
161  $galley->isHTMLGalley() ? $galley->getStyleFileId() : null,
162  $galley->getSequence() == null ? $this->getNextGalleySequence($galley->getPaperId()) : $galley->getSequence()
163  )
164  );
165  $galley->setId($this->getInsertGalleyId());
166  return $galley->getId();
167  }
168 
173  function updateGalley(&$galley) {
174  return $this->update(
175  'UPDATE paper_galleys
176  SET
177  file_id = ?,
178  label = ?,
179  locale = ?,
180  html_galley = ?,
181  style_file_id = ?,
182  seq = ?
183  WHERE galley_id = ?',
184  array(
185  $galley->getFileId(),
186  $galley->getLabel(),
187  $galley->getLocale(),
188  (int)$galley->isHTMLGalley(),
189  $galley->isHTMLGalley() ? $galley->getStyleFileId() : null,
190  $galley->getSequence(),
191  $galley->getId()
192  )
193  );
194  }
195 
200  function deleteGalley(&$galley) {
201  return $this->deleteGalleyById($galley->getId());
202  }
203 
209  function deleteGalleyById($galleyId, $paperId = null) {
210  $this->deleteImagesByGalley($galleyId);
211  if (isset($paperId)) {
212  return $this->update(
213  'DELETE FROM paper_galleys WHERE galley_id = ? AND paper_id = ?',
214  array($galleyId, $paperId)
215  );
216 
217  } else {
218  return $this->update(
219  'DELETE FROM paper_galleys WHERE galley_id = ?', $galleyId
220  );
221  }
222  }
223 
229  function deleteGalleysByPaper($paperId) {
230  $galleys =& $this->getGalleysByPaper($paperId);
231  foreach ($galleys as $galley) {
232  $this->deleteGalleyById($galley->getId(), $paperId);
233  }
234  }
235 
242  function galleyExistsByFileId($paperId, $fileId) {
243  $result =& $this->retrieve(
244  'SELECT COUNT(*) FROM paper_galleys
245  WHERE paper_id = ? AND file_id = ?',
246  array($paperId, $fileId)
247  );
248 
249  $returner = isset($result->fields[0]) && $result->fields[0] == 1 ? true : false;
250 
251  $result->Close();
252  unset($result);
253 
254  return $returner;
255  }
256 
261  function incrementViews($galleyId) {
262  return $this->update(
263  'UPDATE paper_galleys SET views = views + 1 WHERE galley_id = ?',
264  $galleyId
265  );
266  }
267 
272  function resequenceGalleys($paperId) {
273  $result =& $this->retrieve(
274  'SELECT galley_id FROM paper_galleys WHERE paper_id = ? ORDER BY seq',
275  $paperId
276  );
277 
278  for ($i=1; !$result->EOF; $i++) {
279  list($galleyId) = $result->fields;
280  $this->update(
281  'UPDATE paper_galleys SET seq = ? WHERE galley_id = ?',
282  array($i, $galleyId)
283  );
284  $result->moveNext();
285  }
286 
287  $result->close();
288  unset($result);
289  }
290 
296  function getNextGalleySequence($paperId) {
297  $result =& $this->retrieve(
298  'SELECT MAX(seq) + 1 FROM paper_galleys WHERE paper_id = ?',
299  $paperId
300  );
301  $returner = floor($result->fields[0]);
302 
303  $result->Close();
304  unset($result);
305 
306  return $returner;
307  }
308 
313  function getInsertGalleyId() {
314  return $this->getInsertId('paper_galleys', 'galley_id');
315  }
316 
317 
318  //
319  // Extra routines specific to HTML galleys.
320  //
321 
327  function &getGalleyImages($galleyId) {
328  $images = array();
329 
330  $result =& $this->retrieve(
331  'SELECT a.* FROM paper_html_galley_images i, paper_files a
332  WHERE i.file_id = a.file_id AND i.galley_id = ?',
333  $galleyId
334  );
335 
336  while (!$result->EOF) {
337  $images[] =& $this->paperFileDao->_returnPaperFileFromRow($result->GetRowAssoc(false));
338  $result->MoveNext();
339  }
340 
341  $result->Close();
342  unset($result);
343 
344  return $images;
345  }
346 
352  function insertGalleyImage($galleyId, $fileId) {
353  return $this->update(
354  'INSERT INTO paper_html_galley_images
355  (galley_id, file_id)
356  VALUES
357  (?, ?)',
358  array($galleyId, $fileId)
359  );
360  }
361 
367  function deleteGalleyImage($galleyId, $fileId) {
368  return $this->update(
369  'DELETE FROM paper_html_galley_images
370  WHERE galley_id = ? AND file_id = ?',
371  array($galleyId, $fileId)
372  );
373  }
374 
379  function deleteImagesByGalley($galleyId) {
380  return $this->update(
381  'DELETE FROM paper_html_galley_images WHERE galley_id = ?',
382  $galleyId
383  );
384  }
385 }
386 
387 ?>
config TEMPLATE inc php
Definition: config.inc.php:4
& _returnGalleyFromRow(&$row)
Operations for retrieving and modifying objects from a database.
Definition: DAO.inc.php:30
deleteGalleyById($galleyId, $paperId=null)
& retrieve($sql, $params=false, $callHooks=true)
Definition: DAO.inc.php:62
resequenceGalleys($paperId)
getInsertId($table='', $id='', $callHooks=true)
Definition: DAO.inc.php:225
Operations for retrieving and modifying PaperGalley/PaperHTMLGalley objects.
& getGalley($galleyId, $paperId=null)
deleteGalleyImage($galleyId, $fileId)
getNextGalleySequence($paperId)
deleteImagesByGalley($galleyId)
datetimeFromDB($dt)
Definition: DAO.inc.php:276
& getGalleysByPaper($paperId)
deleteGalleysByPaper($paperId)
galleyExistsByFileId($paperId, $fileId)
incrementViews($galleyId)
& getDAO($name, $dbconn=null)
& getGalleyImages($galleyId)
call($hookName, $args=null)
insertGalleyImage($galleyId, $fileId)
update($sql, $params=false, $callHooks=true, $dieOnError=true)
Definition: DAO.inc.php:186
An HTML galley may include an optional stylesheet and set of images.
A galley is a final presentation version of the full-text of a paper.