Open Journal Systems  2.4.3
 All Classes Namespaces Functions Variables Groups Pages
TemporaryFileDAO.inc.php
1 <?php
2 
18 import('lib.pkp.classes.file.TemporaryFile');
19 
20 class TemporaryFileDAO extends DAO {
24  function TemporaryFileDAO() {
25  parent::DAO();
26  }
27 
34  function &getTemporaryFile($fileId, $userId) {
35  $result =& $this->retrieveLimit(
36  'SELECT t.* FROM temporary_files t WHERE t.file_id = ? and t.user_id = ?',
37  array((int) $fileId, (int) $userId),
38  1
39  );
40 
41  $returner = null;
42  if (isset($result) && $result->RecordCount() != 0) {
43  $returner =& $this->_returnTemporaryFileFromRow($result->GetRowAssoc(false));
44  }
45 
46  $result->Close();
47  unset($result);
48 
49  return $returner;
50  }
51 
56  function newDataObject() {
57  return new TemporaryFile();
58  }
59 
65  function &_returnTemporaryFileFromRow(&$row) {
66  $temporaryFile = $this->newDataObject();
67  $temporaryFile->setId($row['file_id']);
68  $temporaryFile->setFileName($row['file_name']);
69  $temporaryFile->setFileType($row['file_type']);
70  $temporaryFile->setFileSize($row['file_size']);
71  $temporaryFile->setUserId($row['user_id']);
72  $temporaryFile->setOriginalFileName($row['original_file_name']);
73  $temporaryFile->setDateUploaded($this->datetimeFromDB($row['date_uploaded']));
74 
75  HookRegistry::call('TemporaryFileDAO::_returnTemporaryFileFromRow', array(&$temporaryFile, &$row));
76 
77  return $temporaryFile;
78  }
79 
85  function insertTemporaryFile(&$temporaryFile) {
86  $this->update(
87  sprintf('INSERT INTO temporary_files
88  (user_id, file_name, file_type, file_size, original_file_name, date_uploaded)
89  VALUES
90  (?, ?, ?, ?, ?, %s)',
91  $this->datetimeToDB($temporaryFile->getDateUploaded())),
92  array(
93  (int) $temporaryFile->getUserId(),
94  $temporaryFile->getFileName(),
95  $temporaryFile->getFileType(),
96  (int) $temporaryFile->getFileSize(),
97  $temporaryFile->getOriginalFileName()
98  )
99  );
100 
101  $temporaryFile->setId($this->getInsertTemporaryFileId());
102  return $temporaryFile->getId();
103  }
104 
109  function updateObject(&$temporaryFile) {
110  $this->update(
111  sprintf('UPDATE temporary_files
112  SET
113  file_name = ?,
114  file_type = ?,
115  file_size = ?,
116  user_id = ?,
117  original_file_name = ?,
118  date_uploaded = %s
119  WHERE file_id = ?',
120  $this->datetimeToDB($temporaryFile->getDateUploaded())),
121  array(
122  $temporaryFile->getFileName(),
123  $temporaryFile->getFileType(),
124  (int) $temporaryFile->getFileSize(),
125  (int) $temporaryFile->getUserId(),
126  $temporaryFile->getOriginalFileName(),
127  (int) $temporaryFile->getId()
128  )
129  );
130 
131  return $temporaryFile->getId();
132  }
133 
134  function updateTemporaryFile(&$temporaryFile) {
135  if (Config::getVar('debug', 'deprecation_warnings')) trigger_error('Deprecated function.');
136  return $this->updateObject($temporaryFile);
137  }
138 
144  function deleteTemporaryFileById($fileId, $userId) {
145  return $this->update(
146  'DELETE FROM temporary_files WHERE file_id = ? AND user_id = ?',
147  array((int) $fileId, (int) $userId)
148  );
149  }
150 
155  function deleteTemporaryFilesByUserId($userId) {
156  return $this->update(
157  'DELETE FROM temporary_files WHERE user_id = ?',
158  array((int) $userId)
159  );
160  }
161 
162  function &getExpiredFiles() {
163  // Files older than one day can be cleaned up.
164  $expiryThresholdTimestamp = time() - (60 * 60 * 24);
165 
166  $temporaryFiles = array();
167 
168  $result =& $this->retrieve(
169  'SELECT * FROM temporary_files WHERE date_uploaded < ' . $this->datetimeToDB($expiryThresholdTimestamp)
170  );
171 
172  while (!$result->EOF) {
173  $temporaryFiles[] =& $this->_returnTemporaryFileFromRow($result->GetRowAssoc(false));
174  $result->MoveNext();
175  }
176 
177  $result->Close();
178  unset($result);
179 
180  return $temporaryFiles;
181  }
182 
188  return $this->getInsertId('temporary_files', 'file_id');
189  }
190 }
191 
192 ?>
deleteTemporaryFileById($fileId, $userId)
Operations for retrieving and modifying objects from a database.
Definition: DAO.inc.php:29
& retrieveLimit($sql, $params=false, $numRows=false, $offset=false, $callHooks=true)
Definition: DAO.inc.php:147
& retrieve($sql, $params=false, $callHooks=true)
Definition: DAO.inc.php:83
getInsertId($table= '', $id= '', $callHooks=true)
Definition: DAO.inc.php:252
& getTemporaryFile($fileId, $userId)
Temporary file class.
datetimeFromDB($dt)
Definition: DAO.inc.php:316
getVar($section, $key, $default=null)
Definition: Config.inc.php:34
Operations for retrieving and modifying TemporaryFile objects.
call($hookName, $args=null)
insertTemporaryFile(&$temporaryFile)
& _returnTemporaryFileFromRow(&$row)
updateObject(&$temporaryFile)
datetimeToDB($dt)
Definition: DAO.inc.php:296
update($sql, $params=false, $callHooks=true, $dieOnError=true)
Definition: DAO.inc.php:211
deleteTemporaryFilesByUserId($userId)