Open Journal Systems  2.4.4
 All Classes Namespaces Functions Variables Groups Pages
IssueFileDAO.inc.php
1 <?php
2 
17 import('lib.pkp.classes.file.PKPFileDAO');
18 import('classes.issue.IssueFile');
19 
20 
21 class IssueFileDAO extends PKPFileDAO {
22 
23  /* @var array MIME types that can be displayed inline in a browser */
24  var $_inlineableTypes = null;
25 
29  function IssueFileDao () {
30  parent::DAO();
31  }
32 
37  function getInlineableTypes() {
38  return $this->_inlineableTypes;
39  }
40 
45  function setInlineableTypes($inlineableTypes) {
46  $this->_inlineableTypes = $inlineableTypes;
47  }
48 
55  function &getIssueFile($fileId, $issueId = null) {
56  if ($fileId === null) {
57  $returner = null;
58  return $returner;
59  }
60 
61  if ($issueId != null) {
62  $result =& $this->retrieve(
63  'SELECT f.*
64  FROM issue_files f
65  WHERE f.file_id = ?
66  AND f.issue_id = ?',
67  array((int) $fileId, (int) $issueId)
68  );
69  } else {
70  $result =& $this->retrieve(
71  'SELECT f.*
72  FROM issue_files f
73  WHERE f.file_id = ?',
74  (int) $fileId
75  );
76  }
77 
78  $returner = null;
79  if (isset($result) && $result->RecordCount() != 0) {
80  $returner =& $this->_returnIssueFileFromRow($result->GetRowAssoc(false));
81  }
82 
83  $result->Close();
84  unset($result);
85 
86  return $returner;
87  }
88 
94  function &getIssueFilesByIssue($issueId) {
95  $issueFiles = array();
96 
97  $result =& $this->retrieve(
98  'SELECT * FROM issue_files WHERE issue_id = ?',
99  (int) $issueId
100  );
101 
102  while (!$result->EOF) {
103  $issueFiles[] =& $this->_returnIssueFileFromRow($result->GetRowAssoc(false));
104  $result->moveNext();
105  }
106 
107  $result->Close();
108  unset($result);
109 
110  return $issueFiles;
111  }
112 
118  function &_returnIssueFileFromRow(&$row) {
119  $issueFile = new IssueFile();
120  $issueFile->setId($row['file_id']);
121  $issueFile->setIssueId($row['issue_id']);
122  $issueFile->setFileName($row['file_name']);
123  $issueFile->setFileType($row['file_type']);
124  $issueFile->setFileSize($row['file_size']);
125  $issueFile->setContentType($row['content_type']);
126  $issueFile->setOriginalFileName($row['original_file_name']);
127  $issueFile->setDateUploaded($this->datetimeFromDB($row['date_uploaded']));
128  $issueFile->setDateModified($this->datetimeFromDB($row['date_modified']));
129  HookRegistry::call('IssueFileDAO::_returnIssueFileFromRow', array(&$issueFile, &$row));
130  return $issueFile;
131  }
132 
138  function insertIssueFile(&$issueFile) {
139  $params = array(
140  (int) $issueFile->getIssueId(),
141  $issueFile->getFileName(),
142  $issueFile->getFileType(),
143  $issueFile->getFileSize(),
144  $issueFile->getContentType(),
145  $issueFile->getOriginalFileName()
146  );
147 
148  $this->update(
149  sprintf(
150  'INSERT INTO issue_files
151  (issue_id,
152  file_name,
153  file_type,
154  file_size,
155  content_type,
156  original_file_name,
157  date_uploaded,
158  date_modified)
159  VALUES
160  (?, ?, ?, ?, ?, ?, %s, %s)',
161  $this->datetimeToDB($issueFile->getDateUploaded()),
162  $this->datetimeToDB($issueFile->getDateModified())
163  ),
164  $params
165  );
166 
167  $issueFile->setId($this->getInsertIssueFileId());
168  return $issueFile->getId();
169  }
170 
175  function updateIssueFile(&$issueFile) {
176  $this->update(
177  sprintf('UPDATE issue_files
178  SET
179  issue_id = ?,
180  file_name = ?,
181  file_type = ?,
182  file_size = ?,
183  content_type = ?,
184  original_file_name = ?,
185  date_uploaded = %s,
186  date_modified = %s
187  WHERE file_id = ?',
188  $this->datetimeToDB($issueFile->getDateUploaded()),
189  $this->datetimeToDB($issueFile->getDateModified())
190  ),
191  array(
192  (int) $issueFile->getIssueId(),
193  $issueFile->getFileName(),
194  $issueFile->getFileType(),
195  $issueFile->getFileSize(),
196  $issueFile->getContentType(),
197  $issueFile->getOriginalFileName(),
198  $issueFile->getId()
199  )
200  );
201 
202  return $issueFile->getId();
203 
204  }
205 
210  function deleteIssueFile(&$issueFile) {
211  return $this->deleteIssueFileById($issueFile->getId());
212  }
213 
219  function deleteIssueFileById($fileId) {
220  return $this->update(
221  'DELETE FROM issue_files WHERE file_id = ?', (int) $fileId
222  );
223  }
224 
229  function deleteIssueFiles($issueId) {
230  return $this->update(
231  'DELETE FROM issue_files WHERE issue_id = ?', (int) $issueId
232  );
233  }
234 
239  function getInsertIssueFileId() {
240  return $this->getInsertId('issue_files', 'file_id');
241  }
242 }
243 
244 ?>
deleteIssueFileById($fileId)
& getIssueFilesByIssue($issueId)
deleteIssueFile(&$issueFile)
Issue file class.
& retrieve($sql, $params=false, $callHooks=true)
Definition: DAO.inc.php:83
getInsertId($table= '', $id= '', $callHooks=true)
Definition: DAO.inc.php:252
updateIssueFile(&$issueFile)
insertIssueFile(&$issueFile)
datetimeFromDB($dt)
Definition: DAO.inc.php:316
Operations for retrieving and modifying IssueFile objects.
& _returnIssueFileFromRow(&$row)
deleteIssueFiles($issueId)
Abstract base class for retrieving and modifying PKPFile objects and their decendents.
call($hookName, $args=null)
& getIssueFile($fileId, $issueId=null)
datetimeToDB($dt)
Definition: DAO.inc.php:296
update($sql, $params=false, $callHooks=true, $dieOnError=true)
Definition: DAO.inc.php:211
setInlineableTypes($inlineableTypes)