Esempio n. 1
0
 /**
  * Save series.
  * @param $args array
  * @param $request PKPRequest
  */
 function execute($args, $request)
 {
     $seriesDao = DAORegistry::getDAO('SeriesDAO');
     $press = $request->getPress();
     // Get or create the series object
     if ($this->getSeriesId()) {
         $series = $seriesDao->getById($this->getSeriesId(), $press->getId());
     } else {
         $series = $seriesDao->newDataObject();
         $series->setPressId($press->getId());
     }
     // Populate/update the series object from the form
     $series->setPath($this->getData('path'));
     $series->setFeatured($this->getData('featured'));
     $series->setTitle($this->getData('title'), null);
     // Localized
     $series->setDescription($this->getData('description'), null);
     // Localized
     $series->setPrefix($this->getData('prefix'), null);
     // Localized
     $series->setSubtitle($this->getData('subtitle'), null);
     // Localized
     $series->setEditorRestricted($this->getData('restricted'));
     $series->setOnlineISSN($this->getData('onlineIssn'));
     $series->setPrintISSN($this->getData('printIssn'));
     $series->setSortOption($this->getData('sortOption'));
     // Insert or update the series in the DB
     if ($this->getSeriesId()) {
         $seriesDao->updateObject($series);
     } else {
         $this->setSeriesId($seriesDao->insertObject($series));
     }
     // Handle the image upload if there was one.
     if ($temporaryFileId = $this->getData('temporaryFileId')) {
         // Fetch the temporary file storing the uploaded library file
         $temporaryFileDao = DAORegistry::getDAO('TemporaryFileDAO');
         $temporaryFile = $temporaryFileDao->getTemporaryFile($temporaryFileId, $this->_userId);
         $temporaryFilePath = $temporaryFile->getFilePath();
         import('lib.pkp.classes.file.ContextFileManager');
         $pressFileManager = new ContextFileManager($press->getId());
         $basePath = $pressFileManager->getBasePath() . '/series/';
         // Delete the old file if it exists
         $oldSetting = $series->getImage();
         if ($oldSetting) {
             $pressFileManager->deleteFile($basePath . $oldSetting['thumbnailName']);
             $pressFileManager->deleteFile($basePath . $oldSetting['name']);
         }
         // The following variables were fetched in validation
         assert($this->_sizeArray && $this->_imageExtension);
         // Generate the surrogate image.
         switch ($this->_imageExtension) {
             case '.jpg':
                 $image = imagecreatefromjpeg($temporaryFilePath);
                 break;
             case '.png':
                 $image = imagecreatefrompng($temporaryFilePath);
                 break;
             case '.gif':
                 $image = imagecreatefromgif($temporaryFilePath);
                 break;
             default:
                 $image = null;
                 // Suppress warn
         }
         assert($image);
         $coverThumbnailsMaxWidth = $press->getSetting('coverThumbnailsMaxWidth');
         $coverThumbnailsMaxHeight = $press->getSetting('coverThumbnailsMaxHeight');
         $thumbnailFilename = $series->getId() . '-series-thumbnail' . $this->_imageExtension;
         $xRatio = min(1, $coverThumbnailsMaxWidth / $this->_sizeArray[0]);
         $yRatio = min(1, $coverThumbnailsMaxHeight / $this->_sizeArray[1]);
         $ratio = min($xRatio, $yRatio);
         $thumbnailWidth = round($ratio * $this->_sizeArray[0]);
         $thumbnailHeight = round($ratio * $this->_sizeArray[1]);
         $thumbnail = imagecreatetruecolor($thumbnailWidth, $thumbnailHeight);
         imagecopyresampled($thumbnail, $image, 0, 0, 0, 0, $thumbnailWidth, $thumbnailHeight, $this->_sizeArray[0], $this->_sizeArray[1]);
         // Copy the new file over
         $filename = $series->getId() . '-series' . $this->_imageExtension;
         $pressFileManager->copyFile($temporaryFile->getFilePath(), $basePath . $filename);
         switch ($this->_imageExtension) {
             case '.jpg':
                 imagejpeg($thumbnail, $basePath . $thumbnailFilename);
                 break;
             case '.png':
                 imagepng($thumbnail, $basePath . $thumbnailFilename);
                 break;
             case '.gif':
                 imagegif($thumbnail, $basePath . $thumbnailFilename);
                 break;
         }
         imagedestroy($thumbnail);
         imagedestroy($image);
         $series->setImage(array('name' => $filename, 'width' => $this->_sizeArray[0], 'height' => $this->_sizeArray[1], 'thumbnailName' => $thumbnailFilename, 'thumbnailWidth' => $thumbnailWidth, 'thumbnailHeight' => $thumbnailHeight, 'uploadName' => $temporaryFile->getOriginalFileName(), 'dateUploaded' => Core::getCurrentDate()));
         // Clean up the temporary file
         import('lib.pkp.classes.file.TemporaryFileManager');
         $temporaryFileManager = new TemporaryFileManager();
         $temporaryFileManager->deleteFile($temporaryFileId, $this->_userId);
     }
     // Update series object to store image information.
     $seriesDao->updateObject($series);
     import('lib.pkp.classes.controllers.listbuilder.ListbuilderHandler');
     // Save the series editor associations.
     ListbuilderHandler::unpack($request, $this->getData('subEditors'), array(&$this, 'deleteSubEditorEntry'), array(&$this, 'insertSubEditorEntry'), array(&$this, 'updateSubEditorEntry'));
     // Save the category associations.
     ListbuilderHandler::unpack($request, $this->getData('categories'), array(&$this, 'deleteCategoryEntry'), array(&$this, 'insertCategoryEntry'), array(&$this, 'updateCategoryEntry'));
     return true;
 }
Esempio n. 2
0
 /**
  * @see Form::execute()
  */
 function execute($request)
 {
     $categoryId = $this->getCategoryId();
     $categoryDao = DAORegistry::getDAO('CategoryDAO');
     // Get a category object to edit or create
     if ($categoryId == null) {
         $category = $categoryDao->newDataObject();
         $category->setPressId($this->getPressId());
     } else {
         $category = $categoryDao->getById($categoryId, $this->getPressId());
     }
     // Set the editable properties of the category object
     $category->setTitle($this->getData('name'), null);
     // Localized
     $category->setDescription($this->getData('description'), null);
     // Localized
     $category->setParentId($this->getData('parentId'));
     $category->setPath($this->getData('path'));
     $category->setSortOption($this->getData('sortOption'));
     // Update or insert the category object
     if ($categoryId == null) {
         $category->setId($categoryDao->insertObject($category));
     } else {
         $category->setSequence(REALLY_BIG_NUMBER);
         $categoryDao->updateObject($category);
         $categoryDao->resequenceCategories($this->getPressId());
     }
     // Handle the image upload if there was one.
     if ($temporaryFileId = $this->getData('temporaryFileId')) {
         // Fetch the temporary file storing the uploaded library file
         $temporaryFileDao = DAORegistry::getDAO('TemporaryFileDAO');
         $temporaryFile = $temporaryFileDao->getTemporaryFile($temporaryFileId, $this->_userId);
         $temporaryFilePath = $temporaryFile->getFilePath();
         import('lib.pkp.classes.file.ContextFileManager');
         $pressFileManager = new ContextFileManager($this->getPressId());
         $basePath = $pressFileManager->getBasePath() . '/categories/';
         // Delete the old file if it exists
         $oldSetting = $category->getImage();
         if ($oldSetting) {
             $pressFileManager->deleteFile($basePath . $oldSetting['thumbnailName']);
             $pressFileManager->deleteFile($basePath . $oldSetting['name']);
         }
         // The following variables were fetched in validation
         assert($this->_sizeArray && $this->_imageExtension);
         // Generate the surrogate images.
         switch ($this->_imageExtension) {
             case '.jpg':
                 $image = imagecreatefromjpeg($temporaryFilePath);
                 break;
             case '.png':
                 $image = imagecreatefrompng($temporaryFilePath);
                 break;
             case '.gif':
                 $image = imagecreatefromgif($temporaryFilePath);
                 break;
             default:
                 $image = null;
                 // Suppress warn
         }
         assert($image);
         $press = $request->getPress();
         $coverThumbnailsMaxWidth = $press->getSetting('coverThumbnailsMaxWidth');
         $coverThumbnailsMaxHeight = $press->getSetting('coverThumbnailsMaxHeight');
         $thumbnailFilename = $category->getId() . '-category-thumbnail' . $this->_imageExtension;
         $xRatio = min(1, $coverThumbnailsMaxWidth / $this->_sizeArray[0]);
         $yRatio = min(1, $coverThumbnailsMaxHeight / $this->_sizeArray[1]);
         $ratio = min($xRatio, $yRatio);
         $thumbnailWidth = round($ratio * $this->_sizeArray[0]);
         $thumbnailHeight = round($ratio * $this->_sizeArray[1]);
         $thumbnail = imagecreatetruecolor($thumbnailWidth, $thumbnailHeight);
         imagecopyresampled($thumbnail, $image, 0, 0, 0, 0, $thumbnailWidth, $thumbnailHeight, $this->_sizeArray[0], $this->_sizeArray[1]);
         // Copy the new file over
         $filename = $category->getId() . '-category' . $this->_imageExtension;
         $pressFileManager->copyFile($temporaryFile->getFilePath(), $basePath . $filename);
         switch ($this->_imageExtension) {
             case '.jpg':
                 imagejpeg($thumbnail, $basePath . $thumbnailFilename);
                 break;
             case '.png':
                 imagepng($thumbnail, $basePath . $thumbnailFilename);
                 break;
             case '.gif':
                 imagegif($thumbnail, $basePath . $thumbnailFilename);
                 break;
         }
         imagedestroy($thumbnail);
         imagedestroy($image);
         $category->setImage(array('name' => $filename, 'width' => $this->_sizeArray[0], 'height' => $this->_sizeArray[1], 'thumbnailName' => $thumbnailFilename, 'thumbnailWidth' => $thumbnailWidth, 'thumbnailHeight' => $thumbnailHeight, 'uploadName' => $temporaryFile->getOriginalFileName(), 'dateUploaded' => Core::getCurrentDate()));
         // Clean up the temporary file
         import('lib.pkp.classes.file.TemporaryFileManager');
         $temporaryFileManager = new TemporaryFileManager();
         $temporaryFileManager->deleteFile($temporaryFileId, $this->_userId);
     }
     // Update category object to store image information.
     $categoryDao->updateObject($category);
     return $category;
 }