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)  

SuppFileDAO.inc.php
Go to the documentation of this file.
1 <?php
2 
16 //$Id$
17 
18 import('paper.SuppFile');
19 
20 class SuppFileDAO extends DAO {
27  function &getSuppFile($suppFileId, $paperId = null) {
28  $params = array($suppFileId);
29  if ($paperId) $params[] = $paperId;
30 
31  $result =& $this->retrieve(
32  'SELECT s.*, a.file_name, a.original_file_name, a.file_type, a.file_size, a.date_uploaded, a.date_modified FROM paper_supplementary_files s LEFT JOIN paper_files a ON (s.file_id = a.file_id) WHERE s.supp_id = ?' . ($paperId?' AND s.paper_id = ?':''),
33  $params
34  );
35 
36  $returner = null;
37  if ($result->RecordCount() != 0) {
38  $returner =& $this->_returnSuppFileFromRow($result->GetRowAssoc(false));
39  }
40 
41  $result->Close();
42  unset($result);
43 
44  return $returner;
45  }
46 
53  function &getSuppFileByPublicSuppFileId($publicSuppId, $paperId) {
54  $result =& $this->retrieve(
55  'SELECT s.*, a.file_name, a.original_file_name, a.file_type, a.file_size, a.date_uploaded, a.date_modified FROM paper_supplementary_files s LEFT JOIN paper_files a ON (s.file_id = a.file_id) WHERE s.public_supp_file_id = ? AND s.paper_id = ?',
56  array($publicSuppId, $paperId)
57  );
58 
59  $returner = null;
60  if ($result->RecordCount() != 0) {
61  $returner =& $this->_returnSuppFileFromRow($result->GetRowAssoc(false));
62  }
63 
64  $result->Close();
65  unset($result);
66 
67  return $returner;
68  }
69 
75  function &getSuppFilesByPaper($paperId) {
76  $suppFiles = array();
77 
78  $result =& $this->retrieve(
79  'SELECT s.*, a.file_name, a.original_file_name, a.file_type, a.file_size, a.date_uploaded, a.date_modified FROM paper_supplementary_files s LEFT JOIN paper_files a ON (s.file_id = a.file_id) WHERE s.paper_id = ? ORDER BY s.seq',
80  $paperId
81  );
82 
83  while (!$result->EOF) {
84  $suppFiles[] =& $this->_returnSuppFileFromRow($result->GetRowAssoc(false));
85  $result->moveNext();
86  }
87 
88  $result->Close();
89  unset($result);
90 
91  return $suppFiles;
92  }
93 
98  function getLocaleFieldNames() {
99  return array('title', 'creator', 'subject', 'typeOther', 'description', 'publisher', 'sponsor', 'source');
100  }
101 
106  function updateLocaleFields(&$suppFile) {
107  $this->updateDataObjectSettings('paper_supp_file_settings', $suppFile, array(
108  'supp_id' => $suppFile->getId()
109  ));
110  }
111 
117  function &_returnSuppFileFromRow(&$row) {
118  $suppFile = new SuppFile();
119  $suppFile->setSuppFileID($row['supp_id']);
120  $suppFile->setPublicSuppFileID($row['public_supp_file_id']);
121  $suppFile->setFileId($row['file_id']);
122  $suppFile->setPaperId($row['paper_id']);
123  $suppFile->setType($row['type']);
124  $suppFile->setDateCreated($this->dateFromDB($row['date_created']));
125  $suppFile->setLanguage($row['language']);
126  $suppFile->setShowReviewers($row['show_reviewers']);
127  $suppFile->setDateSubmitted($this->datetimeFromDB($row['date_submitted']));
128  $suppFile->setSequence($row['seq']);
129 
130  //PaperFile set methods
131  $suppFile->setFileName($row['file_name']);
132  $suppFile->setOriginalFileName($row['original_file_name']);
133  $suppFile->setFileType($row['file_type']);
134  $suppFile->setFileSize($row['file_size']);
135  $suppFile->setDateModified($this->datetimeFromDB($row['date_modified']));
136  $suppFile->setDateUploaded($this->datetimeFromDB($row['date_uploaded']));
137 
138  $this->getDataObjectSettings('paper_supp_file_settings', 'supp_id', $row['supp_id'], $suppFile);
139 
140  HookRegistry::call('SuppFileDAO::_returnSuppFileFromRow', array(&$suppFile, &$row));
141 
142  return $suppFile;
143  }
144 
149  function insertSuppFile(&$suppFile) {
150  if ($suppFile->getDateSubmitted() == null) {
151  $suppFile->setDateSubmitted(Core::getCurrentDate());
152  }
153  if ($suppFile->getSequence() == null) {
154  $suppFile->setSequence($this->getNextSuppFileSequence($suppFile->getPaperId()));
155  }
156  $this->update(
157  sprintf('INSERT INTO paper_supplementary_files
158  (public_supp_file_id, file_id, paper_id, type, date_created, language, show_reviewers, date_submitted, seq)
159  VALUES
160  (?, ?, ?, ?, %s, ?, ?, %s, ?)',
161  $this->dateToDB($suppFile->getDateCreated()), $this->datetimeToDB($suppFile->getDateSubmitted())),
162  array(
163  $suppFile->getPublicSuppFileId(),
164  $suppFile->getFileId(),
165  $suppFile->getPaperId(),
166  $suppFile->getType(),
167  $suppFile->getLanguage(),
168  $suppFile->getShowReviewers(),
169  $suppFile->getSequence()
170  )
171  );
172  $suppFile->setId($this->getInsertSuppFileId());
173  $this->updateLocaleFields($suppFile);
174  return $suppFile->getId();
175  }
176 
181  function updateSuppFile(&$suppFile) {
182  $returner = $this->update(
183  sprintf('UPDATE paper_supplementary_files
184  SET
185  public_supp_file_id = ?,
186  file_id = ?,
187  type = ?,
188  date_created = %s,
189  language = ?,
190  show_reviewers = ?,
191  seq = ?
192  WHERE supp_id = ?',
193  $this->dateToDB($suppFile->getDateCreated())),
194  array(
195  $suppFile->getPublicSuppFileId(),
196  $suppFile->getFileId(),
197  $suppFile->getType(),
198  $suppFile->getLanguage(),
199  $suppFile->getShowReviewers(),
200  $suppFile->getSequence(),
201  $suppFile->getId()
202  )
203  );
204  $this->updateLocaleFields($suppFile);
205  return $returner;
206  }
207 
212  function deleteSuppFile(&$suppFile) {
213  return $this->deleteSuppFileById($suppFile->getId());
214  }
215 
221  function deleteSuppFileById($suppFileId, $paperId = null) {
222  if (isset($paperId)) {
223  $returner = $this->update('DELETE FROM paper_supplementary_files WHERE supp_id = ? AND paper_id = ?', array($suppFileId, $paperId));
224  if ($returner) $this->update('DELETE FROM paper_supp_file_settings WHERE supp_id = ?', $suppFileId);
225  return $returner;
226 
227  } else {
228  $this->update('DELETE FROM paper_supp_file_settings WHERE supp_id = ?', $suppFileId);
229  return $this->update(
230  'DELETE FROM paper_supplementary_files WHERE supp_id = ?', $suppFileId
231  );
232  }
233  }
234 
239  function deleteSuppFilesByPaper($paperId) {
240  $suppFiles =& $this->getSuppFilesByPaper($paperId);
241  foreach ($suppFiles as $suppFile) {
242  $this->deleteSuppFile($suppFile);
243  }
244  }
245 
252  function suppFileExistsByFileId($paperId, $fileId) {
253  $result =& $this->retrieve(
254  'SELECT COUNT(*) FROM paper_supplementary_files
255  WHERE paper_id = ? AND file_id = ?',
256  array($paperId, $fileId)
257  );
258 
259  $returner = isset($result->fields[0]) && $result->fields[0] == 1 ? true : false;
260 
261  $result->Close();
262  unset($result);
263 
264  return $returner;
265  }
266 
271  function resequenceSuppFiles($paperId) {
272  $result =& $this->retrieve(
273  'SELECT supp_id FROM paper_supplementary_files WHERE paper_id = ? ORDER BY seq',
274  $paperId
275  );
276 
277  for ($i=1; !$result->EOF; $i++) {
278  list($suppId) = $result->fields;
279  $this->update(
280  'UPDATE paper_supplementary_files SET seq = ? WHERE supp_id = ?',
281  array($i, $suppId)
282  );
283  $result->moveNext();
284  }
285 
286  $result->close();
287  unset($result);
288  }
289 
295  function getNextSuppFileSequence($paperId) {
296  $result =& $this->retrieve(
297  'SELECT MAX(seq) + 1 FROM paper_supplementary_files WHERE paper_id = ?',
298  $paperId
299  );
300  $returner = floor($result->fields[0]);
301 
302  $result->Close();
303  unset($result);
304 
305  return $returner;
306  }
307 
312  function getInsertSuppFileId() {
313  return $this->getInsertId('paper_supplementary_files', 'supp_id');
314  }
315 
323  function &getSuppFileByBestSuppFileId($paperId, $suppId) {
324  $suppFile =& $this->getSuppFileByPublicSuppFileId($suppId, $paperId);
325  if (!isset($suppFile) && ctype_digit("$suppId")) $suppFile =& $this->getSuppFile((int) $suppId, $paperId);
326  return $suppFile;
327  }
328 
336  function suppFileExistsByPublicId($publicSuppFileId, $suppId, $schedConfId) {
337  $result =& $this->retrieve(
338  'SELECT COUNT(*) FROM paper_supplementary_files f, papers a WHERE f.paper_id = a.paper_id AND f.public_supp_file_id = ? AND f.supp_id <> ? AND a.sched_conf_id = ?', array($publicSuppFileId, $suppId, $schedConfId)
339  );
340  $returner = $result->fields[0] ? true : false;
341 
342  $result->Close();
343  unset($result);
344 
345  return $returner;
346  }
347 }
348 
349 ?>
config TEMPLATE inc php
Definition: config.inc.php:4
updateSuppFile(&$suppFile)
Operations for retrieving and modifying objects from a database.
Definition: DAO.inc.php:30
suppFileExistsByFileId($paperId, $fileId)
& getSuppFilesByPaper($paperId)
& retrieve($sql, $params=false, $callHooks=true)
Definition: DAO.inc.php:62
suppFileExistsByPublicId($publicSuppFileId, $suppId, $schedConfId)
getInsertId($table='', $id='', $callHooks=true)
Definition: DAO.inc.php:225
updateDataObjectSettings($tableName, &$dataObject, $idArray)
Definition: DAO.inc.php:412
getCurrentDate($ts=null)
Definition: Core.inc.php:90
resequenceSuppFiles($paperId)
dateToDB($d)
Definition: DAO.inc.php:267
deleteSuppFileById($suppFileId, $paperId=null)
Supplementary file class.
datetimeFromDB($dt)
Definition: DAO.inc.php:276
& getSuppFileByPublicSuppFileId($publicSuppId, $paperId)
deleteSuppFilesByPaper($paperId)
Operations for retrieving and modifying SuppFile objects.
& _returnSuppFileFromRow(&$row)
& getSuppFileByBestSuppFileId($paperId, $suppId)
call($hookName, $args=null)
insertSuppFile(&$suppFile)
getDataObjectSettings($tableName, $idFieldName, $idFieldValue, &$dataObject)
Definition: DAO.inc.php:498
deleteSuppFile(&$suppFile)
datetimeToDB($dt)
Definition: DAO.inc.php:258
updateLocaleFields(&$suppFile)
update($sql, $params=false, $callHooks=true, $dieOnError=true)
Definition: DAO.inc.php:186
getNextSuppFileSequence($paperId)
dateFromDB($d)
Definition: DAO.inc.php:285
& getSuppFile($suppFileId, $paperId=null)