17 import(
'lib.pkp.classes.context.LibraryFile');
27 function getById($fileId, $contextId =
null) {
29 $params = array((
int) $fileId);
30 if ($contextId) $params[] = (int) $contextId;
33 'SELECT file_id, context_id, file_name, original_file_name, file_type, file_size, type, date_uploaded, submission_id, public_access FROM library_files WHERE file_id = ?'
34 . ($contextId ?
' AND context_id = ?' :
''),
39 if (isset($result) && $result->RecordCount() != 0) {
40 $returner = $this->
_fromRow($result->GetRowAssoc(
false));
54 $params = array((
int) $contextId);
55 if (isset($type)) $params[] = (int) $type;
60 WHERE context_id = ? AND submission_id = 0 ' . (isset($type)?
' AND type = ?' :
''),
74 $params = array((
int) $submissionId);
75 if (isset($type)) $params[] = (int) $type;
76 if (isset($contextId)) $params[] = (
int) $contextId;
81 WHERE submission_id = ? ' . (isset($contextId)?
' AND context_id = ?' :
'') . (isset($type)?
' AND type = ?' :
''),
101 return array(
'name');
110 'library_file_settings',
112 array(
'file_id' => $libraryFile->getId())
124 $libraryFile->setId($row[
'file_id']);
125 $libraryFile->setContextId($row[
'context_id']);
126 $libraryFile->setServerFileName($row[
'file_name']);
127 $libraryFile->setOriginalFileName($row[
'original_file_name']);
128 $libraryFile->setFileType($row[
'file_type']);
129 $libraryFile->setFileSize($row[
'file_size']);
130 $libraryFile->setType($row[
'type']);
131 $libraryFile->setDateUploaded($this->
datetimeFromDB($row[
'date_uploaded']));
132 $libraryFile->setSubmissionId($row[
'submission_id']);
133 $libraryFile->setPublicAccess($row[
'public_access']);
149 (
int) $libraryFile->getContextId(),
150 $libraryFile->getServerFileName(),
151 $libraryFile->getOriginalFileName(),
152 $libraryFile->getFileType(),
153 (
int) $libraryFile->getFileSize(),
154 (
int) $libraryFile->getType(),
155 (
int) $libraryFile->getSubmissionId(),
156 (
int) $libraryFile->getPublicAccess()
159 if ($libraryFile->getId()) $params[] = (int) $libraryFile->getId();
162 sprintf(
'INSERT INTO library_files
163 (context_id, file_name, original_file_name, file_type, file_size, type, submission_id, public_access, date_uploaded, date_modified' . ($libraryFile->getId()?
', file_id':
'') .
')
165 (?, ?, ?, ?, ?, ?, ?, ?, %s, %s' . ($libraryFile->getId()?
', ?':
'') .
')',
166 $this->datetimeToDB($libraryFile->getDateUploaded()),
167 $this->datetimeToDB($libraryFile->getDateModified())
172 if (!$libraryFile->getId()) $libraryFile->setId($this->
getInsertId());
175 return $libraryFile->getId();
185 sprintf(
'UPDATE library_files
188 original_file_name = ?,
198 (
int) $libraryFile->getContextId(),
199 $libraryFile->getServerFileName(),
200 $libraryFile->getOriginalFileName(),
201 $libraryFile->getFileType(),
202 (
int) $libraryFile->getFileSize(),
203 (
int) $libraryFile->getType(),
204 (
int) $libraryFile->getSubmissionId(),
205 (
int) $libraryFile->getPublicAccess(),
206 (
int) $libraryFile->getId()
211 return $libraryFile->getId();
221 'DELETE FROM library_files WHERE file_id = ?',
225 'DELETE FROM library_file_settings WHERE file_id = ?',
238 'SELECT COUNT(*) FROM library_files WHERE context_id = ? AND file_name = ?',
239 array((
int) $contextId, $fileName)
242 $returner = (isset($result->fields[0]) && $result->fields[0] > 0) ?
true :
false;