/**
  * Fetch the form.
  * @see Form::fetch()
  */
 function fetch(&$request)
 {
     $templateMgr =& TemplateManager::getManager();
     $templateMgr->assign('fileId', $this->_fileId);
     $templateMgr->assign('signoffId', $this->_signoffId);
     //$templateMgr->assign('monographId', $this->_monographId);
     $artworkFileDao =& DAORegistry::getDAO('ArtworkFileDAO');
     $artworkFile =& $artworkFileDao->getByFileId($this->_fileId);
     $templateMgr->assign_by_ref('artworkFile', $artworkFile);
     $submissionFileDao =& DAORegistry::getDAO('SubmissionFileDAO');
     /* @var $submissionFileDao SubmissionFileDAO */
     $monographFile =& $submissionFileDao->getLatestRevision($this->_fileId);
     $templateMgr->assign_by_ref('monographFile', $monographFile);
     $templateMgr->assign_by_ref('monographId', $monographFile->getMonographId());
     // artwork can be grouped by monograph chapter
     if ($artworkFile) {
         $chapterDao =& DAORegistry::getDAO('ChapterDAO');
         $chapters =& $chapterDao->getChapters($artworkFile->getMonographId());
         $chapterOptions = array();
         if ($chapters) {
             while ($chapter =& $chapters->next()) {
                 $chapterId = $chapter->getId();
                 $chapterOptions[$chapterId] = $chapter->getLocalizedTitle();
                 unset($chapter);
             }
         }
         $templateMgr->assign_by_ref('selectedChapter', $artworkFile->getChapterId());
     } else {
         $chapters = null;
     }
     $noteDao =& DAORegistry::getDAO('NoteDAO');
     $notes =& $noteDao->getByAssoc(ASSOC_TYPE_MONOGRAPH_FILE, $this->_fileId);
     $templateMgr->assign('note', $notes->next());
     $templateMgr->assign_by_ref('chapterOptions', $chapterOptions);
     return parent::fetch($request);
 }
 /**
  * Edit the metadata of a submission file
  * @param $args array
  * @param $request PKPRequest
  * @return string Serialized JSON object
  */
 function editMetadata($args, &$request)
 {
     $fileId = $request->getUserVar('fileId');
     $signoffId = $request->getUserVar('signoffId');
     $submissionFileDao =& DAORegistry::getDAO('SubmissionFileDAO');
     /* @var $submissionFileDao SubmissionFileDAO */
     $monographFile =& $submissionFileDao->getLatestRevision($fileId);
     $genreDao =& DAORegistry::getDAO('GenreDAO');
     $genre = $genreDao->getById($monographFile->getGenreId());
     $monographId = $monographFile->getMonographId();
     switch ($genre->getCategory()) {
         // FIXME: Need a way to determine artwork file type from user-specified artwork file types
         case GENRE_CATEGORY_ARTWORK:
             import('controllers.grid.files.form.SubmissionFilesArtworkMetadataForm');
             $metadataForm = new SubmissionFilesArtworkMetadataForm($monographFile, WORKFLOW_STAGE_ID_EDITING);
             break;
         default:
             import('controllers.grid.files.form.SubmissionFilesMetadataForm');
             $metadataForm = new SubmissionFilesMetadataForm($monographFile, WORKFLOW_STAGE_ID_EDITING);
             break;
     }
     $templateMgr =& TemplateManager::getManager();
     $templateMgr->assign('gridId', $this->getId());
     $templateMgr->assign('monographId', $monographId);
     if ($metadataForm->isLocaleResubmit()) {
         $metadataForm->readInputData();
     } else {
         $metadataForm->initData($args, $request);
     }
     $json = new JSON(true, $metadataForm->fetch($request));
     return $json->getString();
 }