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)  

PaperFileDAO.inc.php
Go to the documentation of this file.
1 <?php
2 
16 //$Id$
17 
18 import('paper.PaperFile');
19 
20 class PaperFileDAO extends DAO {
25 
33  function &getPaperFile($fileId, $revision = null, $paperId = null) {
34  if ($fileId === null) {
35  $returner = null;
36  return $returner;
37  }
38  if ($revision == null) {
39  if ($paperId != null) {
40  $result =& $this->retrieveLimit(
41  'SELECT a.* FROM paper_files a WHERE file_id = ? AND paper_id = ? ORDER BY revision DESC',
42  array($fileId, $paperId),
43  1
44  );
45  } else {
46  $result =& $this->retrieveLimit(
47  'SELECT a.* FROM paper_files a WHERE file_id = ? ORDER BY revision DESC',
48  $fileId,
49  1
50  );
51  }
52 
53  } else {
54  if ($paperId != null) {
55  $result =& $this->retrieve(
56  'SELECT a.* FROM paper_files a WHERE file_id = ? AND revision = ? AND paper_id = ?',
57  array($fileId, $revision, $paperId)
58  );
59  } else {
60  $result =& $this->retrieve(
61  'SELECT a.* FROM paper_files a WHERE file_id = ? AND revision = ?',
62  array($fileId, $revision)
63  );
64  }
65  }
66 
67  $returner = null;
68  if (isset($result) && $result->RecordCount() != 0) {
69  $returner =& $this->_returnPaperFileFromRow($result->GetRowAssoc(false));
70  }
71 
72  $result->Close();
73  unset($result);
74 
75  return $returner;
76  }
77 
83  function &getPaperFileRevisions($fileId, $stage = null) {
84  if ($fileId === null) {
85  $returner = null;
86  return $returner;
87  }
88  $paperFiles = array();
89 
90  $params = array($fileId);
91  if ($stage !== null) $params[] = $stage;
92 
93  $result =& $this->retrieve(
94  'SELECT a.* FROM paper_files a WHERE file_id = ? ' .
95  ($stage!==null?'AND a.stage = ? ':'') .
96  'ORDER BY revision',
97  array($params)
98  );
99 
100  while (!$result->EOF) {
101  $paperFiles[] =& $this->_returnPaperFileFromRow($result->GetRowAssoc(false));
102  $result->moveNext();
103  }
104 
105  $result->Close();
106  unset($result);
107 
108  return $paperFiles;
109  }
110 
116  function &getPaperFileRevisionsInRange($fileId, $start = 1, $end = null) {
117  if ($fileId === null) {
118  $returner = null;
119  return $returner;
120  }
121  $paperFiles = array();
122 
123  if ($end == null) {
124  $result =& $this->retrieve(
125  'SELECT a.* FROM paper_files a WHERE file_id = ? AND revision >= ?',
126  array($fileId, $start)
127  );
128  } else {
129  $result =& $this->retrieve(
130  'SELECT a.* FROM paper_files a WHERE file_id = ? AND revision >= ? AND revision <= ?',
131  array($fileId, $start, $end)
132  );
133  }
134 
135  while (!$result->EOF) {
136  $paperFiles[] =& $this->_returnPaperFileFromRow($result->GetRowAssoc(false));
137  $result->moveNext();
138  }
139 
140  $result->Close();
141  unset($result);
142 
143  return $paperFiles;
144  }
145 
151  function &getRevisionNumber($fileId) {
152  if ($fileId === null) {
153  $returner = null;
154  return $returner;
155  }
156  $result =& $this->retrieve(
157  'SELECT MAX(revision) AS max_revision FROM paper_files a WHERE file_id = ?',
158  $fileId
159  );
160 
161  if ($result->RecordCount() == 0) {
162  $returner = null;
163  } else {
164  $row = $result->FetchRow();
165  $returner = $row['max_revision'];
166  }
167 
168  $result->Close();
169  unset($result);
170 
171  return $returner;
172  }
173 
179  function &getPaperFilesByPaper($paperId) {
180  $paperFiles = array();
181 
182  $result =& $this->retrieve(
183  'SELECT * FROM paper_files WHERE paper_id = ?',
184  $paperId
185  );
186 
187  while (!$result->EOF) {
188  $paperFiles[] =& $this->_returnPaperFileFromRow($result->GetRowAssoc(false));
189  $result->moveNext();
190  }
191 
192  $result->Close();
193  unset($result);
194 
195  return $paperFiles;
196  }
197 
203  function &_returnPaperFileFromRow(&$row) {
204  $paperFile = new PaperFile();
205  $paperFile->setFileId($row['file_id']);
206  $paperFile->setRevision($row['revision']);
207  $paperFile->setPaperId($row['paper_id']);
208  $paperFile->setFileName($row['file_name']);
209  $paperFile->setFileType($row['file_type']);
210  $paperFile->setFileSize($row['file_size']);
211  $paperFile->setOriginalFileName($row['original_file_name']);
212  $paperFile->setType($row['type']);
213  $paperFile->setStage($row['stage']);
214  $paperFile->setDateUploaded($this->datetimeFromDB($row['date_uploaded']));
215  $paperFile->setDateModified($this->datetimeFromDB($row['date_modified']));
216  $paperFile->setViewable($row['viewable']);
217  HookRegistry::call('PaperFileDAO::_returnPaperFileFromRow', array(&$paperFile, &$row));
218  return $paperFile;
219  }
220 
226  function insertPaperFile(&$paperFile) {
227  $fileId = $paperFile->getFileId();
228  $params = array(
229  $paperFile->getRevision() === null ? 1 : $paperFile->getRevision(),
230  (int) $paperFile->getPaperId(),
231  $paperFile->getFileName(),
232  $paperFile->getFileType(),
233  $paperFile->getFileSize(),
234  $paperFile->getOriginalFileName(),
235  $paperFile->getType(),
236  (int) $paperFile->getStage(),
237  $paperFile->getViewable()
238  );
239 
240  if ($fileId) {
241  array_unshift($params, $fileId);
242  }
243 
244  $this->update(
245  sprintf('INSERT INTO paper_files
246  (' . ($fileId ? 'file_id, ' : '') . 'revision, paper_id, file_name, file_type, file_size, original_file_name, type, stage, date_uploaded, date_modified, viewable)
247  VALUES
248  (' . ($fileId ? '?, ' : '') . '?, ?, ?, ?, ?, ?, ?, ?, %s, %s, ?)',
249  $this->datetimeToDB($paperFile->getDateUploaded()), $this->datetimeToDB($paperFile->getDateModified())),
250  $params
251  );
252 
253  if (!$fileId) {
254  $paperFile->setFileId($this->getInsertPaperFileId());
255  }
256 
257  return $paperFile->getFileId();
258  }
259 
264  function updatePaperFile(&$paperFile) {
265  $this->update(
266  sprintf('UPDATE paper_files
267  SET
268  paper_id = ?,
269  file_name = ?,
270  file_type = ?,
271  file_size = ?,
272  original_file_name = ?,
273  type = ?,
274  stage = ?,
275  date_uploaded = %s,
276  date_modified = %s,
277  viewable = ?
278  WHERE file_id = ? AND revision = ?',
279  $this->datetimeToDB($paperFile->getDateUploaded()), $this->datetimeToDB($paperFile->getDateModified())),
280  array(
281  (int) $paperFile->getPaperId(),
282  $paperFile->getFileName(),
283  $paperFile->getFileType(),
284  $paperFile->getFileSize(),
285  $paperFile->getOriginalFileName(),
286  $paperFile->getType(),
287  (int) $paperFile->getStage(),
288  $paperFile->getViewable(),
289  $paperFile->getFileId(),
290  $paperFile->getRevision()
291  )
292  );
293 
294  return $paperFile->getFileId();
295 
296  }
297 
302  function deletePaperFile(&$paperFile) {
303  return $this->deletePaperFileById($paperFile->getFileId(), $paperFile->getRevision());
304  }
305 
311  function deletePaperFileById($fileId, $revision = null) {
312  if ($revision == null) {
313  return $this->update(
314  'DELETE FROM paper_files WHERE file_id = ?', $fileId
315  );
316  } else {
317  return $this->update(
318  'DELETE FROM paper_files WHERE file_id = ? AND revision = ?', array($fileId, $revision)
319  );
320  }
321  }
322 
327  function deletePaperFiles($paperId) {
328  return $this->update(
329  'DELETE FROM paper_files WHERE paper_id = ?', $paperId
330  );
331  }
332 
337  function getInsertPaperFileId() {
338  return $this->getInsertId('paper_files', 'file_id');
339  }
340 
346  function isInlineable(&$paperFile) {
347  if (!isset($this->inlineableTypes)) {
348  $this->inlineableTypes = array_filter(file(Config::getVar('general', 'registry_dir') . '/inlineTypes.txt'), create_function('&$a', 'return ($a = trim($a)) && !empty($a) && $a[0] != \'#\';'));
349  }
350  return in_array($paperFile->getFileType(), $this->inlineableTypes);
351  }
352 }
353 
354 ?>
config TEMPLATE inc php
Definition: config.inc.php:4
& getPaperFile($fileId, $revision=null, $paperId=null)
Operations for retrieving and modifying objects from a database.
Definition: DAO.inc.php:30
deletePaperFiles($paperId)
& retrieveLimit($sql, $params=false, $numRows=false, $offset=false, $callHooks=true)
Definition: DAO.inc.php:124
& _returnPaperFileFromRow(&$row)
& retrieve($sql, $params=false, $callHooks=true)
Definition: DAO.inc.php:62
deletePaperFileById($fileId, $revision=null)
Operations for retrieving and modifying PaperFile objects.
getInsertId($table='', $id='', $callHooks=true)
Definition: DAO.inc.php:225
isInlineable(&$paperFile)
updatePaperFile(&$paperFile)
datetimeFromDB($dt)
Definition: DAO.inc.php:276
getVar($section, $key, $default=null)
Definition: Config.inc.php:35
deletePaperFile(&$paperFile)
call($hookName, $args=null)
& getPaperFilesByPaper($paperId)
& getPaperFileRevisionsInRange($fileId, $start=1, $end=null)
& getRevisionNumber($fileId)
datetimeToDB($dt)
Definition: DAO.inc.php:258
update($sql, $params=false, $callHooks=true, $dieOnError=true)
Definition: DAO.inc.php:186
& getPaperFileRevisions($fileId, $stage=null)
insertPaperFile(&$paperFile)
Paper file class.