Open Monograph Press  1.1
 All Classes Namespaces Functions Variables Groups Pages
SubmissionFile.inc.php
1 <?php
2 
16 import('lib.pkp.classes.file.PKPFile');
17 
18 // Define the file stage identifiers.
19 define('SUBMISSION_FILE_PUBLIC', 1);
20 define('SUBMISSION_FILE_SUBMISSION', 2);
21 define('SUBMISSION_FILE_NOTE', 3);
22 define('SUBMISSION_FILE_REVIEW_FILE', 4);
23 define('SUBMISSION_FILE_REVIEW_ATTACHMENT', 5);
24 // SUBMISSION_FILE_REVIEW_REVISION defined below (FIXME: re-order before release)
25 define('SUBMISSION_FILE_FINAL', 6);
26 define('SUBMISSION_FILE_FAIR_COPY', 7);
27 define('SUBMISSION_FILE_EDITOR', 8);
28 define('SUBMISSION_FILE_COPYEDIT', 9);
29 define('SUBMISSION_FILE_PROOF', 10);
30 define('SUBMISSION_FILE_PRODUCTION_READY', 11);
31 define('SUBMISSION_FILE_ATTACHMENT', 13);
32 define('SUBMISSION_FILE_SIGNOFF', 14);
33 define('SUBMISSION_FILE_REVIEW_REVISION', 15);
34 define('SUBMISSION_FILE_DEPENDENT', 17);
35 
36 class SubmissionFile extends PKPFile {
40  function SubmissionFile() {
41  parent::PKPFile();
42  }
43 
44 
45  //
46  // Getters and Setters
47  //
52  function getFileId() {
53  // WARNING: Do not modernize getter/setters without considering
54  // ID clash with subclasses ArticleGalley and ArticleNote!
55  return $this->getData('fileId');
56  }
57 
62  function setFileId($fileId) {
63  // WARNING: Do not modernize getter/setters without considering
64  // ID clash with subclasses ArticleGalley and ArticleNote!
65  return $this->setData('fileId', $fileId);
66  }
67 
72  function getSourceFileId() {
73  return $this->getData('sourceFileId');
74  }
75 
80  function setSourceFileId($sourceFileId) {
81  return $this->setData('sourceFileId', $sourceFileId);
82  }
83 
88  function getSourceRevision() {
89  return $this->getData('sourceRevision');
90  }
91 
96  function setSourceRevision($sourceRevision) {
97  return $this->setData('sourceRevision', $sourceRevision);
98  }
99 
104  function getAssocId() {
105  return $this->getData('assocId');
106  }
107 
112  function setAssocId($assocId) {
113  return $this->setData('assocId', $assocId);
114  }
115 
120  function getDirectSalesPrice() {
121  return $this->getData('directSalesPrice');
122  }
123 
128  function setDirectSalesPrice($directSalesPrice) {
129  return $this->setData('directSalesPrice', $directSalesPrice);
130  }
131 
136  function getSalesType() {
137  return $this->getData('salesType');
138  }
139 
144  function setSalesType($salesType) {
145  return $this->setData('salesType', $salesType);
146  }
147 
153  function setName($name, $locale) {
154  $this->setData('name', $name, $locale);
155  }
156 
162  function getName($locale) {
163  return $this->getData('name', $locale);
164  }
165 
170  function getLocalizedName() {
171  return $this->getLocalizedData('name');
172  }
173 
178  function getExtension() {
179  import('lib.pkp.classes.file.FileManager');
180  $fileManager = new FileManager();
181  return strtoupper($fileManager->parseFileExtension($this->getOriginalFileName()));
182  }
183 
188  function getDocumentType() {
189  import('lib.pkp.classes.file.FileManager');
190  $fileManager = new FileManager();
191  return $fileManager->getDocumentType($this->getFileType());
192  }
193 
199  function setGenreId($genreId) {
200  $this->setData('genreId', $genreId);
201  }
202 
208  function getGenreId() {
209  return $this->getData('genreId');
210  }
211 
216  function getRevision() {
217  return $this->getData('revision');
218  }
219 
225  function getFileIdAndRevision() {
226  $id = $this->getFileId();
227  $revision = $this->getRevision();
228  $idAndRevision = $id;
229  if ($revision) {
230  $idAndRevision .= '-'.$revision;
231  }
232  return $idAndRevision;
233  }
234 
239  function setRevision($revision) {
240  return $this->setData('revision', $revision);
241  }
242 
247  function getSubmissionId() {
248  return $this->getData('submissionId');
249  }
250 
255  function setSubmissionId($submissionId) {
256  return $this->setData('submissionId', $submissionId);
257  }
258 
263  function getType() {
264  if (Config::getVar('debug', 'deprecation_warnings')) trigger_error('Deprecated function.');
265  return $this->getFileStage();
266  }
267 
272  function setType($type) {
273  if (Config::getVar('debug', 'deprecation_warnings')) trigger_error('Deprecated function.');
274  return $this->setFileStage($type);
275  }
276 
281  function getFileStage() {
282  return $this->getData('fileStage');
283  }
284 
289  function setFileStage($fileStage) {
290  return $this->setData('fileStage', $fileStage);
291  }
292 
298  function getDateModified() {
299  return $this->getData('dateModified');
300  }
301 
307  function setDateModified($dateModified) {
308  return $this->SetData('dateModified', $dateModified);
309  }
310 
316  function getRound() {
317  return $this->getData('round');
318  }
319 
324  function setRound($round) {
325  return $this->SetData('round', $round);
326  }
327 
332  function getViewable() {
333  return $this->getData('viewable');
334  }
335 
336 
341  function setViewable($viewable) {
342  return $this->SetData('viewable', $viewable);
343  }
344 
349  function setUploaderUserId($uploaderUserId) {
350  $this->setData('uploaderUserId', $uploaderUserId);
351  }
352 
357  function getUploaderUserId() {
358  return $this->getData('uploaderUserId');
359  }
360 
365  function setUserGroupId($userGroupId) {
366  $this->setData('userGroupId', $userGroupId);
367  }
368 
373  function getUserGroupId() {
374  return $this->getData('userGroupId');
375  }
376 
381  function getAssocType() {
382  return $this->getData('assocType');
383  }
384 
389  function setAssocType($assocType) {
390  return $this->setData('assocType', $assocType);
391  }
392 
396  function getFilePath() {
397  // Get the context ID
398  $submissionDao = Application::getSubmissionDAO();
399  $submission = $submissionDao->getById($this->getSubmissionId());
400  if (!$submission) return null;
401  $contextId = $submission->getContextId();
402  unset($submission);
403 
404  // Construct the file path
405  import('lib.pkp.classes.file.SubmissionFileManager');
406  $submissionFileManager = new SubmissionFileManager($contextId, $this->getSubmissionId());
407  return $submissionFileManager->getBasePath() . $this->_fileStageToPath($this->getFileStage()) . '/' . $this->getServerFileName();
408  }
409 
414  function getFileLabel($locale = null) {
415  // Retrieve the localized file name as basis for the label.
416  if ($locale) {
417  $fileLabel = $this->getName($locale);
418  } else {
419  $fileLabel = $this->getLocalizedName();
420  }
421 
422  // If we have no file name then use a default name.
423  if (empty($fileLabel)) $fileLabel = $this->getOriginalFileName();
424 
425  // Add the revision number to the label if we have more than one revision.
426  if ($this->getRevision() > 1) $fileLabel .= ' (' . $this->getRevision() . ')';
427 
428  return $fileLabel;
429  }
430 
431 
437  function copyEditableMetadataFrom($submissionFile) {
438  assert(is_a($submissionFile, 'SubmissionFile'));
439  $this->setName($submissionFile->getName(null), null);
440  }
441 
446  function getClientFileName() {
447  // Generate a human readable time stamp.
448  $timestamp = date('Ymd', strtotime($this->getDateUploaded()));
449 
450  $genreDao = DAORegistry::getDAO('GenreDAO');
451  $genre = $genreDao->getById($this->getGenreId());
452 
453  // Make the file name unique across all files and file revisions.
454  // Also make sure that files can be ordered sensibly by file name.
455  return $this->getSubmissionId() . '-'.
456  ($genre? ($genre->getDesignation() . '_' . $genre->getLocalizedName() . '-'):'') .
457  $this->getFileId() . '-' .
458  $this->getRevision() . '-' .
459  $this->getFileStage() . '-' .
460  $timestamp .
461  '.' .
462  strtolower_codesafe($this->getExtension());
463  }
464 
465  //
466  // Overridden public methods from PKPFile
467  //
473  function getServerFileName() {
474  return $this->_generateFileName();
475  }
476 
482  function setServerFileName($fileName) {
483  assert(false);
484  }
485 
490  function getViews() {
491  $application = Application::getApplication();
492  return $application->getPrimaryMetricByAssoc(ASSOC_TYPE_SUBMISSION_FILE, $this->getFileId());
493  }
494 
495  //
496  // Private helper methods
497  //
498 
503  function _generateFileName() {
504  // Generate a human readable time stamp.
505  $timestamp = date('Ymd', strtotime($this->getDateUploaded()));
506 
507  // Make the file name unique across all files and file revisions.
508  // Also make sure that files can be ordered sensibly by file name.
509  return $this->getSubmissionId() . '-'.
510  $this->getGenreId() . '-' .
511  $this->getFileId() . '-' .
512  $this->getRevision() . '-' .
513  $this->getFileStage() . '-' .
514  $timestamp .
515  '.' .
516  strtolower_codesafe($this->getExtension());
517  }
518 
524  function _fileStageToPath($fileStage) {
525  static $fileStageToPath = array(
526  0 => '', // Temporary files do not use stages
527  SUBMISSION_FILE_PUBLIC => 'public',
528  SUBMISSION_FILE_SUBMISSION => 'submission',
529  SUBMISSION_FILE_NOTE => 'note',
530  SUBMISSION_FILE_REVIEW_FILE => 'submission/review',
531  SUBMISSION_FILE_REVIEW_ATTACHMENT => 'submission/review/attachment',
532  SUBMISSION_FILE_REVIEW_REVISION => 'submission/review/revision',
533  SUBMISSION_FILE_FINAL => 'submission/final',
534  SUBMISSION_FILE_FAIR_COPY => 'submission/fairCopy',
535  SUBMISSION_FILE_EDITOR => 'submission/editor',
536  SUBMISSION_FILE_COPYEDIT => 'submission/copyedit',
537  SUBMISSION_FILE_DEPENDENT => 'submission/proof',
538  SUBMISSION_FILE_PROOF => 'submission/proof',
539  SUBMISSION_FILE_PRODUCTION_READY => 'submission/productionReady',
540  SUBMISSION_FILE_ATTACHMENT => 'attachment',
541  SUBMISSION_FILE_SIGNOFF => 'submission/signoff',
542  );
543 
544  assert(isset($fileStageToPath[$fileStage]));
545  return $fileStageToPath[$fileStage];
546  }
547 
548  //
549  // Public methods
550  //
557  function isInlineable() {
558  $submissionFileDao = DAORegistry::getDAO('SubmissionFileDAO'); /* @var $submissionFileDao SubmissionFileDAO */
559  return $submissionFileDao->isInlineable($this);
560  }
561 }
562 
563 ?>
static & getDAO($name, $dbconn=null)
setSourceFileId($sourceFileId)
setUserGroupId($userGroupId)
getFileType()
Definition: PKPFile.inc.php:82
setServerFileName($fileName)
getDateUploaded()
Definition: PKPFile.inc.php:98
setFileStage($fileStage)
setAssocType($assocType)
& getLocalizedData($key)
setDirectSalesPrice($directSalesPrice)
Class defining basic operations for file management.
getFileLabel($locale=null)
& getData($key, $locale=null)
static getVar($section, $key, $default=null)
Definition: Config.inc.php:35
setSubmissionId($submissionId)
static getSubmissionDAO()
setSourceRevision($sourceRevision)
copyEditableMetadataFrom($submissionFile)
setName($name, $locale)
setSalesType($salesType)
Base PKP file class.
Definition: PKPFile.inc.php:16
getOriginalFileName()
Definition: PKPFile.inc.php:66
setUploaderUserId($uploaderUserId)
setDateModified($dateModified)
setData($key, $value, $locale=null)
Submission file class.
_fileStageToPath($fileStage)