Open Journal Systems  3.0.0
 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  return $returner;
48  }
49 
54  function newDataObject() {
55  return new TemporaryFile();
56  }
57 
63  function _returnTemporaryFileFromRow($row) {
64  $temporaryFile = $this->newDataObject();
65  $temporaryFile->setId($row['file_id']);
66  $temporaryFile->setServerFileName($row['file_name']);
67  $temporaryFile->setFileType($row['file_type']);
68  $temporaryFile->setFileSize($row['file_size']);
69  $temporaryFile->setUserId($row['user_id']);
70  $temporaryFile->setOriginalFileName($row['original_file_name']);
71  $temporaryFile->setDateUploaded($this->datetimeFromDB($row['date_uploaded']));
72 
73  HookRegistry::call('TemporaryFileDAO::_returnTemporaryFileFromRow', array(&$temporaryFile, &$row));
74 
75  return $temporaryFile;
76  }
77 
83  function insertObject($temporaryFile) {
84  $this->update(
85  sprintf('INSERT INTO temporary_files
86  (user_id, file_name, file_type, file_size, original_file_name, date_uploaded)
87  VALUES
88  (?, ?, ?, ?, ?, %s)',
89  $this->datetimeToDB($temporaryFile->getDateUploaded())),
90  array(
91  (int) $temporaryFile->getUserId(),
92  $temporaryFile->getServerFileName(),
93  $temporaryFile->getFileType(),
94  (int) $temporaryFile->getFileSize(),
95  $temporaryFile->getOriginalFileName()
96  )
97  );
98 
99  $temporaryFile->setId($this->getInsertId());
100  return $temporaryFile->getId();
101  }
102 
107  function updateObject($temporaryFile) {
108  $this->update(
109  sprintf('UPDATE temporary_files
110  SET
111  file_name = ?,
112  file_type = ?,
113  file_size = ?,
114  user_id = ?,
115  original_file_name = ?,
116  date_uploaded = %s
117  WHERE file_id = ?',
118  $this->datetimeToDB($temporaryFile->getDateUploaded())),
119  array(
120  $temporaryFile->getServerFileName(),
121  $temporaryFile->getFileType(),
122  (int) $temporaryFile->getFileSize(),
123  (int) $temporaryFile->getUserId(),
124  $temporaryFile->getOriginalFileName(),
125  (int) $temporaryFile->getId()
126  )
127  );
128 
129  return $temporaryFile->getId();
130  }
131 
137  function deleteTemporaryFileById($fileId, $userId) {
138  return $this->update(
139  'DELETE FROM temporary_files WHERE file_id = ? AND user_id = ?',
140  array((int) $fileId, (int) $userId)
141  );
142  }
143 
148  function deleteByUserId($userId) {
149  return $this->update(
150  'DELETE FROM temporary_files WHERE user_id = ?',
151  (int) $userId
152  );
153  }
154 
155  function &getExpiredFiles() {
156  // Files older than one day can be cleaned up.
157  $expiryThresholdTimestamp = time() - (60 * 60 * 24);
158 
159  $temporaryFiles = array();
160 
161  $result = $this->retrieve(
162  'SELECT * FROM temporary_files WHERE date_uploaded < ' . $this->datetimeToDB($expiryThresholdTimestamp)
163  );
164 
165  while (!$result->EOF) {
166  $temporaryFiles[] =& $this->_returnTemporaryFileFromRow($result->GetRowAssoc(false));
167  $result->MoveNext();
168  }
169 
170  $result->Close();
171  return $temporaryFiles;
172  }
173 
178  function getInsertId() {
179  return $this->_getInsertId('temporary_files', 'file_id');
180  }
181 }
182 
183 ?>
deleteTemporaryFileById($fileId, $userId)
Operations for retrieving and modifying objects from a database.
Definition: DAO.inc.php:30
& retrieveLimit($sql, $params=false, $numRows=false, $offset=false, $callHooks=true)
Definition: DAO.inc.php:146
& retrieve($sql, $params=false, $callHooks=true)
Definition: DAO.inc.php:84
& getTemporaryFile($fileId, $userId)
_getInsertId($table= '', $id= '')
Definition: DAO.inc.php:249
Temporary file class.
datetimeFromDB($dt)
Definition: DAO.inc.php:313
static call($hookName, $args=null)
Operations for retrieving and modifying TemporaryFile objects.
datetimeToDB($dt)
Definition: DAO.inc.php:293
update($sql, $params=false, $callHooks=true, $dieOnError=true)
Definition: DAO.inc.php:208
insertObject($temporaryFile)
updateObject($temporaryFile)