/** * Routine to instantiate and pre-populate a new monograph file. * @param $monographId integer * @param $fileStage integer * @param $revisedFileId integer * @param $genreId integer * @param $assocId integer * @param $assocType integer * @return MonographFile returns the instantiated monograph file or null if an error occurs. */ function &_instantiateMonographFile($monographId, $fileStage, $revisedFileId, $genreId, $assocId, $assocType) { // Instantiate a new monograph file. $monographFile = new MonographFile(); $monographFile->setMonographId($monographId); // Do we create a new file or a new revision of an existing file? if ($revisedFileId) { // Retrieve the revised file. $submissionFileDao =& DAORegistry::getDAO('SubmissionFileDAO'); /* @var $submissionFileDao SubmissionFileDAO */ $revisedFile =& $submissionFileDao->getLatestRevision($revisedFileId, $fileStage, $monographId); if (!is_a($revisedFile, 'MonographFile')) { return false; } // Create a new revision of the file with the existing file id. $monographFile->setFileId($revisedFileId); $monographFile->setRevision($revisedFile->getRevision() + 1); // Make sure that the monograph of the revised file is // the same as that of the uploaded file. assert($revisedFile->getMonographId() == $monographId); $nullVar = null; if ($revisedFile->getMonographId() != $monographId) { return $nullVar; } // Copy the file workflow stage. assert(is_null($fileStage) || $fileStage == $revisedFile->getFileStage()); $fileStage = (int) $revisedFile->getFileStage(); // Copy the file genre. assert(is_null($genreId) || $genreId == $revisedFile->getGenreId()); $genreId = (int) $revisedFile->getGenreId(); // Copy the assoc type. assert(is_null($assocType) || $assocType == $revisedFile->getAssocType()); $assocType = (int) $revisedFile->getAssocType(); // Copy the assoc id. assert(is_null($assocId) || $assocId == $revisedFile->getAssocId()); $assocId = (int) $revisedFile->getAssocId(); } else { // Create the first revision of a new file. $monographFile->setRevision(1); } // Set a preliminary file name and file size. $monographFile->setFileName('unknown'); $monographFile->setFileSize(0); // Set the file file stage. $monographFile->setFileStage($fileStage); // Set the file genre (if given). if (isset($genreId)) { $monographFile->setGenreId($genreId); } // Set modification dates to the current system date. $monographFile->setDateUploaded(Core::getCurrentDate()); $monographFile->setDateModified(Core::getCurrentDate()); // Is the monograph file associated to another entity? if (isset($assocId)) { assert(isset($assocType)); $monographFile->setAssocType($assocType); $monographFile->setAssocId($assocId); } // Return the pre-populated monograph file. return $monographFile; }