/**
  * Set a format's "available" state
  * @param $args array
  * @param $request PKPRequest
  * @return JSONMessage JSON object
  */
 function setAvailable($args, $request)
 {
     $context = $request->getContext();
     $publicationFormatDao = DAORegistry::getDAO('PublicationFormatDAO');
     $publicationFormat = $publicationFormatDao->getById($request->getUserVar('representationId'), null, $context->getId());
     if (!$publicationFormat) {
         return new JSONMessage(false, __('manager.setup.errorDeletingItem'));
     }
     $newAvailableState = (int) $request->getUserVar('newAvailableState');
     $publicationFormat->setIsAvailable($newAvailableState);
     $publicationFormatDao->updateObject($publicationFormat);
     // log the state changing of the format.
     import('lib.pkp.classes.log.SubmissionLog');
     import('classes.log.SubmissionEventLogEntry');
     SubmissionLog::logEvent($request, $this->getSubmission(), $newAvailableState ? SUBMISSION_LOG_PUBLICATION_FORMAT_AVAILABLE : SUBMISSION_LOG_PUBLICATION_FORMAT_UNAVAILABLE, $newAvailableState ? 'submission.event.publicationFormatMadeAvailable' : 'submission.event.publicationFormatMadeUnavailable', array('publicationFormatName' => $publicationFormat->getLocalizedName()));
     // Update the formats tombstones.
     import('classes.publicationFormat.PublicationFormatTombstoneManager');
     $publicationFormatTombstoneMgr = new PublicationFormatTombstoneManager();
     if ($publicationFormat->getIsAvailable() && $publicationFormat->getIsApproved()) {
         // Delete any existing tombstone.
         $publicationFormatTombstoneMgr->deleteTombstonesByPublicationFormats(array($publicationFormat));
     } else {
         // (Re)create a tombstone for this publication format.
         $publicationFormatTombstoneMgr->deleteTombstonesByPublicationFormats(array($publicationFormat));
         $publicationFormatTombstoneMgr->insertTombstoneByPublicationFormat($publicationFormat, $context);
     }
     return DAO::getDataChangedEvent($publicationFormat->getId());
 }
 /**
  * Save the metadata and store the catalog data for this specific publication format.
  */
 function execute($request)
 {
     parent::execute();
     $monograph = $this->getMonograph();
     $publicationFormatDao = DAORegistry::getDAO('PublicationFormatDAO');
     $publicationFormat = $publicationFormatDao->getById($this->getPublicationFormatId(), $monograph->getId());
     assert($publicationFormat);
     // Manage tombstones for the publication format.
     if ($publicationFormat->getIsApproved() && !$this->getData('isApproved')) {
         // Publication format was approved and its being disabled. Create
         // a tombstone for it.
         $press = $request->getPress();
         import('classes.publicationFormat.PublicationFormatTombstoneManager');
         $publicationFormatTombstoneMgr = new PublicationFormatTombstoneManager();
         $publicationFormatTombstoneMgr->insertTombstoneByPublicationFormat($publicationFormat, $press);
         // Log unpublish event.
         import('lib.pkp.classes.log.SubmissionLog');
         SubmissionLog::logEvent($request, $monograph, SUBMISSION_LOG_PUBLICATION_FORMAT_UNPUBLISH, 'submission.event.publicationFormatUnpublished', array('publicationFormatName' => $publicationFormat->getLocalizedName()));
     } elseif (!$publicationFormat->getIsApproved() && $this->getData('isApproved')) {
         // Wasn't approved and now it is. Delete tombstone.
         $tombstoneDao = DAORegistry::getDAO('DataObjectTombstoneDAO');
         $tombstoneDao->deleteByDataObjectId($publicationFormat->getId());
         // Log publish event.
         import('lib.pkp.classes.log.SubmissionLog');
         SubmissionLog::logEvent($request, $monograph, SUBMISSION_LOG_PUBLICATION_FORMAT_PUBLISH, 'submission.event.publicationFormatPublished', array('publicationFormatName' => $publicationFormat->getLocalizedName()));
     }
     // populate the published monograph with the cataloging metadata
     $publicationFormat->setFileSize($this->getData('override') ? $this->getData('fileSize') : null);
     $publicationFormat->setFrontMatter($this->getData('frontMatter'));
     $publicationFormat->setBackMatter($this->getData('backMatter'));
     $publicationFormat->setHeight($this->getData('height'));
     $publicationFormat->setHeightUnitCode($this->getData('heightUnitCode'));
     $publicationFormat->setWidth($this->getData('width'));
     $publicationFormat->setWidthUnitCode($this->getData('widthUnitCode'));
     $publicationFormat->setThickness($this->getData('thickness'));
     $publicationFormat->setThicknessUnitCode($this->getData('thicknessUnitCode'));
     $publicationFormat->setWeight($this->getData('weight'));
     $publicationFormat->setWeightUnitCode($this->getData('weightUnitCode'));
     $publicationFormat->setProductCompositionCode($this->getData('productCompositionCode'));
     $publicationFormat->setProductFormDetailCode($this->getData('productFormDetailCode'));
     $publicationFormat->setCountryManufactureCode($this->getData('countryManufactureCode'));
     $publicationFormat->setImprint($this->getData('imprint'));
     $publicationFormat->setProductAvailabilityCode($this->getData('productAvailabilityCode'));
     $publicationFormat->setTechnicalProtectionCode($this->getData('technicalProtectionCode'));
     $publicationFormat->setReturnableIndicatorCode($this->getData('returnableIndicatorCode'));
     $publicationFormat->setIsApproved($this->getData('isApproved') ? true : false);
     // consider the additional field names from the public identifer plugins
     $pubIdPluginHelper = $this->_getPubIdPluginHelper();
     $pubIdPluginHelper->execute($this, $publicationFormat);
     $publicationFormatDao->updateObject($publicationFormat);
 }