• Main Page
  • Modules
  • Classes
  • Files
  • File List

classes/monograph/MonographFile.inc.php

00001 <?php
00002 
00018 import('lib.pkp.classes.submission.SubmissionFile');
00019 
00020 // Define the file stage identifiers.
00021 define('MONOGRAPH_FILE_PUBLIC', 1);
00022 define('MONOGRAPH_FILE_SUBMISSION', 2);
00023 define('MONOGRAPH_FILE_NOTE', 3);
00024 define('MONOGRAPH_FILE_REVIEW_FILE', 4);
00025 define('MONOGRAPH_FILE_REVIEW_ATTACHMENT', 5);
00026 // MONOGRAPH_FILE_REVIEW_REVISION defined below (FIXME: re-order before release)
00027 define('MONOGRAPH_FILE_FINAL', 6);
00028 define('MONOGRAPH_FILE_FAIR_COPY', 7);
00029 define('MONOGRAPH_FILE_EDITOR', 8);
00030 define('MONOGRAPH_FILE_COPYEDIT', 9);
00031 define('MONOGRAPH_FILE_PROOF', 10);
00032 define('MONOGRAPH_FILE_PRODUCTION_READY', 11);
00033 define('MONOGRAPH_FILE_LAYOUT', 12);
00034 define('MONOGRAPH_FILE_ATTACHMENT', 13);
00035 define('MONOGRAPH_FILE_SIGNOFF', 14);
00036 define('MONOGRAPH_FILE_REVIEW_REVISION', 15);
00037 
00038 class MonographFile extends SubmissionFile {
00039 
00043    function MonographFile() {
00044       parent::SubmissionFile();
00045    }
00046 
00047 
00048    //
00049    // Get/set methods
00050    //
00055    function setUploaderUserId($uploaderUserId) {
00056       $this->setData('uploaderUserId', $uploaderUserId);
00057    }
00058 
00063    function getUploaderUserId() {
00064       return $this->getData('uploaderUserId');
00065    }
00066 
00071    function setUserGroupId($userGroupId) {
00072       $this->setData('userGroupId', $userGroupId);
00073    }
00074 
00079    function getUserGroupId() {
00080       return $this->getData('userGroupId');
00081    }
00082 
00087    function getAssocType() {
00088       return $this->getData('assocType');
00089    }
00090 
00095    function setAssocType($assocType) {
00096       return $this->setData('assocType', $assocType);
00097    }
00098 
00103    function getAssocId() {
00104       return $this->getData('assocId');
00105    }
00106 
00111    function setAssocId($assocId) {
00112       return $this->setData('assocId', $assocId);
00113    }
00114 
00119    function getMonographId() {
00120       return $this->getSubmissionId();
00121    }
00122 
00127    function setMonographId($monographId) {
00128       return $this->setSubmissionId($monographId);
00129    }
00130 
00135    function getDirectSalesPrice() {
00136       return $this->getData('directSalesPrice');
00137    }
00138 
00143    function setDirectSalesPrice($directSalesPrice) {
00144       return $this->setData('directSalesPrice', $directSalesPrice);
00145    }
00146 
00152    function setName($name, $locale) {
00153       $this->setData('name', $name, $locale);
00154    }
00155 
00161    function getName($locale) {
00162       return $this->getData('name', $locale);
00163    }
00164 
00169    function getLocalizedName() {
00170       return $this->getLocalizedData('name');
00171    }
00172 
00177    function getExtension() {
00178       import('lib.pkp.classes.file.FileManager');
00179       $fileManager = new FileManager();
00180       return strtoupper($fileManager->parseFileExtension($this->getOriginalFileName()));
00181    }
00182 
00187    function getDocumentType() {
00188       import('lib.pkp.classes.file.FileManager');
00189       $fileManager = new FileManager();
00190       return $fileManager->getDocumentType($this->getFileType());
00191    }
00192 
00198    function setGenreId($genreId) {
00199       $this->setData('genreId', $genreId);
00200    }
00201 
00207    function getGenreId() {
00208       return $this->getData('genreId');
00209    }
00210 
00215    function getFileLabel($locale = null) {
00216       // Retrieve the localized file name as basis for the label.
00217       if ($locale) {
00218          $fileLabel = $this->getName($locale);
00219       } else {
00220          $fileLabel = $this->getLocalizedName();
00221       }
00222 
00223       // If we have no file name then use a default name.
00224       if (empty($fileLabel)) $fileLabel = $this->getOriginalFileName();
00225 
00226       // Add the revision number to the label if we have more than one revision.
00227       if ($this->getRevision() > 1) $fileLabel .= ' (' . $this->getRevision() . ')';
00228 
00229       return $fileLabel;
00230    }
00231 
00237    function copyEditableMetadataFrom($monographFile) {
00238       assert(is_a($monographFile, 'MonographFile'));
00239       $this->setName($monographFile->getName(null), null);
00240    }
00241 
00242    //
00243    // Overridden public methods from PKPFile
00244    //
00250    function getFileName() {
00251       // FIXME: Need to move this to PKPFile or remove PKPFile's getFileName()
00252       // implementation and place it into app-specific classes, see #6446.
00253       return $this->_generateFileName();
00254    }
00255 
00261    function setFileName($fileName) {
00262       // FIXME: Remove this setter from PKPFile, too? See #6446.
00263       assert(false);
00264    }
00265 
00266 
00267    //
00268    // Implementation of template methods from SubmissionFile
00269    //
00273    function getFilePath() {
00274       // Get the press ID
00275       $monographDao =& DAORegistry::getDAO('MonographDAO');
00276       $monograph =& $monographDao->getById($this->getMonographId());
00277       if (!$monograph) return null;
00278       $pressId = $monograph->getPressId();
00279       unset($monograph);
00280 
00281       // Construct the file path
00282       import('classes.file.MonographFileManager');
00283       $monographFileManager = new MonographFileManager($pressId, $this->getMonographId());
00284       return $monographFileManager->getBasePath() . $this->_fileStageToPath($this->getFileStage()) . '/' . $this->getFileName();
00285    }
00286 
00287 
00288    //
00289    // Private helper methods
00290    //
00296    function _fileStageToPath($fileStage) {
00297       static $fileStageToPath = array(
00298             MONOGRAPH_FILE_PUBLIC => 'public',
00299             MONOGRAPH_FILE_SUBMISSION => 'submission',
00300             MONOGRAPH_FILE_NOTE => 'note',
00301             MONOGRAPH_FILE_REVIEW_FILE => 'submission/review',
00302             MONOGRAPH_FILE_REVIEW_ATTACHMENT => 'submission/review/attachment',
00303             MONOGRAPH_FILE_REVIEW_REVISION => 'submission/review/revision',
00304             MONOGRAPH_FILE_FINAL => 'submission/final',
00305             MONOGRAPH_FILE_FAIR_COPY => 'submission/fairCopy',
00306             MONOGRAPH_FILE_EDITOR => 'submission/editor',
00307             MONOGRAPH_FILE_COPYEDIT => 'submission/copyedit',
00308             MONOGRAPH_FILE_PROOF => 'submission/proof',
00309             MONOGRAPH_FILE_PRODUCTION_READY => 'submission/productionReady',
00310             MONOGRAPH_FILE_LAYOUT => 'submission/layout',
00311             MONOGRAPH_FILE_ATTACHMENT => 'attachment',
00312             MONOGRAPH_FILE_SIGNOFF => 'submission/signoff',
00313       );
00314 
00315       assert(isset($fileStageToPath[$fileStage]));
00316       return $fileStageToPath[$fileStage];
00317    }
00318 
00323    function _generateFileName() {
00324       // Remember the ID information we generated the file name
00325       // on so that we only have to re-generate the name if the
00326       // relevant information changed.
00327       static $lastIds = array();
00328       static $fileName = null;
00329 
00330       // Retrieve the current id information.
00331       $currentIds = array(
00332          'genreId' => $this->getGenreId(),
00333          'dateUploaded' => $this->getDateUploaded(),
00334          'monographId' => $this->getMonographId(),
00335          'fileId' => $this->getFileId(),
00336          'revision' => $this->getRevision(),
00337          'fileStage' => $this->getFileStage(),
00338          'extension' => strtolower_codesafe($this->getExtension())
00339       );
00340 
00341       // Check whether we need a refresh.
00342       $refreshRequired = false;
00343       foreach($currentIds as $key => $currentId) {
00344          if (!isset($lastIds[$key]) || $lastIds[$key] !== $currentId) {
00345             $refreshRequired = true;
00346             $lastIds = $currentIds;
00347             break;
00348          }
00349       }
00350 
00351       // Refresh the file name if required.
00352       if ($refreshRequired) {
00353          // If the file has a file genre set then include
00354          // human readable genre information.
00355          $genreName = '';
00356          if ($currentIds['genreId']) {
00357             $primaryLocale = AppLocale::getPrimaryLocale();
00358             $genreDao =& DAORegistry::getDAO('GenreDAO'); /* @var $genreDao GenreDAO */
00359             $genre =& $genreDao->getById($currentIds['genreId']);
00360             assert(is_a($genre, 'Genre'));
00361             $genreName = $genre->getDesignation($primaryLocale).'_'.$genre->getName($primaryLocale).'-';
00362          }
00363 
00364          // Generate a human readable time stamp.
00365          $timestamp = date('Ymd', strtotime($currentIds['dateUploaded']));
00366 
00367          // Make the file name unique across all files and file revisions.
00368          // Also make sure that files can be ordered sensibly by file name.
00369          $fileName = $currentIds['monographId'].'-'.$genreName.$currentIds['fileId'].'-'.$currentIds['revision'].'-'.$currentIds['fileStage'].'-'.$timestamp.'.'.$currentIds['extension'];
00370       }
00371 
00372       return $fileName;
00373    }
00374 }
00375 
00376 ?>

Generated on Mon Sep 17 2012 13:58:55 for Open Monograph Press by  doxygen 1.7.1