classes/submission/form/PaperGalleyForm.inc.php

Go to the documentation of this file.
00001 <?php
00002 
00015 //$Id$
00016 
00017 import('form.Form');
00018 
00019 class PaperGalleyForm extends Form {
00021    var $paperId;
00022 
00024    var $galleyId;
00025 
00027    var $galley;
00028 
00030    var $stage;
00031 
00038    function PaperGalleyForm($paperId, $galleyId = null, $stage = null) {
00039       parent::Form('submission/layout/galleyForm.tpl');
00040       $conference =& Request::getConference();
00041       $this->paperId = $paperId;
00042       $this->stage = $stage;
00043 
00044       if (isset($galleyId) && !empty($galleyId)) {
00045          $galleyDao =& DAORegistry::getDAO('PaperGalleyDAO');
00046          $this->galley =& $galleyDao->getGalley($galleyId, $paperId);
00047          if (isset($this->galley)) {
00048             $this->galleyId = $galleyId;
00049          }
00050       }
00051 
00052       // Validation checks for this form
00053       $this->addCheck(new FormValidator($this, 'label', 'required', 'submission.layout.galleyLabelRequired'));
00054       $this->addCheck(new FormValidator($this, 'label', 'required', 'submission.layout.galleyLabelRequired'));
00055       $this->addCheck(new FormValidator($this, 'galleyLocale', 'required', 'submission.layout.galleyLocaleRequired'), create_function('$galleyLocale,$availableLocales', 'return in_array($galleyLocale,$availableLocales);'), array_keys($conference->getSupportedLocaleNames()));
00056       $this->addCheck(new FormValidatorPost($this));
00057    }
00058 
00062    function display() {
00063       $conference =& Request::getConference();
00064       $templateMgr =& TemplateManager::getManager();
00065 
00066       $templateMgr->assign('paperId', $this->paperId);
00067       $templateMgr->assign('galleyId', $this->galleyId);
00068       $templateMgr->assign('stage', $this->stage);
00069       $templateMgr->assign('supportedLocales', $conference->getSupportedLocaleNames());
00070 
00071       if (isset($this->galley)) {
00072          $templateMgr->assign_by_ref('galley', $this->galley);
00073       }
00074       $templateMgr->assign('helpTopicId', 'editorial.layoutEditorsRole.layout');
00075       parent::display();
00076    }
00077 
00081    function initData() {
00082       if (isset($this->galley)) {
00083          $galley =& $this->galley;
00084          $this->_data = array(
00085             'label' => $galley->getLabel(),
00086             'galleyLocale' => $galley->getLocale()
00087          );
00088 
00089       } else {
00090          $this->_data = array();
00091       }
00092 
00093    }
00094 
00098    function readInputData() {
00099       $this->readUserVars(
00100          array(
00101             'label',
00102             'deleteStyleFile',
00103             'galleyLocale'
00104          )
00105       );
00106    }
00107 
00112    function execute($fileName = null) {
00113       import('file.PaperFileManager');
00114       $paperFileManager = new PaperFileManager($this->paperId);
00115       $galleyDao =& DAORegistry::getDAO('PaperGalleyDAO');
00116 
00117       $fileName = isset($fileName) ? $fileName : 'galleyFile';
00118 
00119       if (isset($this->galley)) {
00120          $galley =& $this->galley;
00121 
00122          // Upload galley file
00123          if ($paperFileManager->uploadedFileExists($fileName)) {
00124             if($galley->getFileId()) {
00125                $paperFileManager->uploadPublicFile($fileName, $galley->getFileId());
00126             } else {
00127                $fileId = $paperFileManager->uploadPublicFile($fileName);
00128                $galley->setFileId($fileId);
00129             }
00130 
00131             // Update file search index
00132             import('search.PaperSearchIndex');
00133             PaperSearchIndex::updateFileIndex($this->paperId, PAPER_SEARCH_GALLEY_FILE, $galley->getFileId());
00134          }
00135 
00136          if ($paperFileManager->uploadedFileExists('styleFile')) {
00137             // Upload stylesheet file
00138             $styleFileId = $paperFileManager->uploadPublicFile('styleFile', $galley->getStyleFileId());
00139             $galley->setStyleFileId($styleFileId);
00140 
00141          } else if($this->getData('deleteStyleFile')) {
00142             // Delete stylesheet file
00143             $styleFile =& $galley->getStyleFile();
00144             if (isset($styleFile)) {
00145                $paperFileManager->deleteFile($styleFile->getFileId());
00146             }
00147          }
00148 
00149          // Update existing galley
00150          $galley->setLabel($this->getData('label'));
00151          $galley->setLocale($this->getData('galleyLocale'));
00152          $galleyDao->updateGalley($galley);
00153 
00154       } else {
00155          // Upload galley file
00156          if ($paperFileManager->uploadedFileExists($fileName)) {
00157             $fileType = $paperFileManager->getUploadedFileType($fileName);
00158             $fileId = $paperFileManager->uploadPublicFile($fileName);
00159 
00160             // Update file search index
00161             import('search.PaperSearchIndex');
00162             PaperSearchIndex::updateFileIndex($this->paperId, PAPER_SEARCH_GALLEY_FILE, $fileId);
00163          } else {
00164             $fileId = 0;
00165          }
00166 
00167          if (isset($fileType) && strstr($fileType, 'html')) {
00168             // Assume HTML galley
00169             $galley = new PaperHTMLGalley();
00170          } else {
00171             $galley = new PaperGalley();
00172          }
00173 
00174          $galley->setPaperId($this->paperId);
00175          $galley->setFileId($fileId);
00176 
00177          if ($this->getData('label') == null) {
00178             // Generate initial label based on file type
00179             if ($galley->isHTMLGalley()) {
00180                $galley->setLabel('HTML');
00181 
00182             } else if (isset($fileType)) {
00183                if(strstr($fileType, 'pdf')) {
00184                   $galley->setLabel('PDF');
00185 
00186                } else if (strstr($fileType, 'postscript')) {
00187                   $galley->setLabel('PostScript');
00188                } else if (strstr($fileType, 'xml')) {
00189                   $galley->setLabel('XML');
00190                } else if (strstr($fileType, 'audio')) {
00191                   $galley->setLabel('Audio');
00192                } else if (strstr($fileType, 'powerpoint')) {
00193                   $galley->setLabel('Slideshow');
00194                }
00195             }
00196 
00197             if ($galley->getLabel() == null) {
00198                $galley->setLabel(__('common.untitled'));
00199             }
00200 
00201          } else {
00202             $galley->setLabel($this->getData('label'));
00203          }
00204          $galley->setLocale($this->getData('galleyLocale'));
00205 
00206          // Insert new galley
00207          $galleyDao->insertGalley($galley);
00208          $this->galleyId = $galley->getId();
00209       }
00210 
00211       return $this->galleyId;
00212    }
00213 
00218    function uploadImage() {
00219       import('file.PaperFileManager');
00220       $fileManager = new PaperFileManager($this->paperId);
00221       $galleyDao =& DAORegistry::getDAO('PaperGalleyDAO');
00222 
00223       $fileName = 'imageFile';
00224 
00225       if (isset($this->galley) && $fileManager->uploadedFileExists($fileName)) {
00226          $type = $fileManager->getUploadedFileType($fileName);
00227          $extension = $fileManager->getImageExtension($type);
00228          if (!$extension) {
00229             $this->addError('imageFile', __('submission.layout.imageInvalid'));
00230             return false;
00231          }
00232 
00233          if ($fileId = $fileManager->uploadPublicFile($fileName)) {
00234             $galleyDao->insertGalleyImage($this->galleyId, $fileId);
00235 
00236             // Update galley image files
00237             $this->galley->setImageFiles($galleyDao->getGalleyImages($this->galleyId));
00238          }
00239 
00240       }
00241    }
00242 
00247    function deleteImage($imageId) {
00248       import('file.PaperFileManager');
00249       $fileManager = new PaperFileManager($this->paperId);
00250       $galleyDao =& DAORegistry::getDAO('PaperGalleyDAO');
00251 
00252       if (isset($this->galley)) {
00253          $images =& $this->galley->getImageFiles();
00254          if (isset($images)) {
00255             for ($i=0, $count=count($images); $i < $count; $i++) {
00256                if ($images[$i]->getFileId() == $imageId) {
00257                   $fileManager->deleteFile($images[$i]->getFileId());
00258                   $galleyDao->deleteGalleyImage($this->galleyId, $imageId);
00259                   unset($images[$i]);
00260                   break;
00261                }
00262             }
00263          }
00264       }
00265    }
00266 }
00267 
00268 ?>

Generated on 25 Jul 2013 for Open Conference Systems by  doxygen 1.4.7