Open Monograph Press  1.1
 All Classes Namespaces Functions Variables Groups Pages
CatalogEntryFormatMetadataForm.inc.php
1 <?php
2 
16 import('lib.pkp.classes.form.Form');
17 import('classes.plugins.PubIdPluginHelper');
18 
20 
23 
25  var $_stageId;
26 
29 
32 
37 
46  function CatalogEntryFormatMetadataForm($monographId, $publicationFormatId, $isPhysicalFormat = true, $stageId = null, $formParams = null) {
47  parent::Form('controllers/tab/catalogEntry/form/publicationMetadataFormFields.tpl');
48  $monographDao = DAORegistry::getDAO('MonographDAO');
49  $this->_monograph = $monographDao->getById($monographId);
50 
51  $this->_pubIdPluginHelper = new PubIdPluginHelper();
52 
53  $this->_stageId = $stageId;
54  $this->_publicationFormatId = $publicationFormatId;
55  $this->_isPhysicalFormat = $isPhysicalFormat;
56  $this->_formParams = $formParams;
57 
58  $this->addCheck(new FormValidator($this, 'productAvailabilityCode', 'required', 'grid.catalogEntry.productAvailabilityRequired'));
59  $this->addCheck(new FormValidatorRegExp($this, 'directSalesPrice', 'optional', 'grid.catalogEntry.validPriceRequired', '/^[0-9]*(\.[0-9]+)?$/'));
60  $this->addCheck(new FormValidator($this, 'productCompositionCode', 'required', 'grid.catalogEntry.productCompositionRequired'));
61  $this->addCheck(new FormValidatorPost($this));
62  }
63 
69  function fetch($request) {
70  $monograph = $this->getMonograph();
71  $press = $request->getPress();
72 
73  $templateMgr = TemplateManager::getManager($request);
74  $templateMgr->assign('submissionId', $monograph->getId());
75  $templateMgr->assign('publicationFormatId', (int) $this->getPublicationFormatId());
76  $templateMgr->assign('isPhysicalFormat', (bool) $this->getPhysicalFormat()); // included to load format-specific template
77  $templateMgr->assign('stageId', $this->getStageId());
78  $templateMgr->assign('formParams', $this->getFormParams());
79  $templateMgr->assign('submissionApproved', $monograph->getDatePublished());
80 
81  $onixCodelistItemDao = DAORegistry::getDAO('ONIXCodelistItemDAO');
82 
83  // Check if e-commerce is available
84  import('classes.payment.omp.OMPPaymentManager');
85  $ompPaymentManager = new OMPPaymentManager($request);
86  if ($ompPaymentManager->isConfigured()) {
87  $templateMgr->assign('paymentConfigured', true);
88  $templateMgr->assign('currency', $press->getSetting('currency'));
89  }
90 
91  // get the lists associated with the select elements on these publication format forms.
92  $codes = array(
93  'productCompositionCodes' => 'List2', // single item, multiple item, trade-only, etc
94  'measurementUnitCodes' => 'List50', // grams, inches, millimeters
95  'weightUnitCodes' => 'List95', // pounds, grams, ounces
96  'measurementTypeCodes' => 'List48', // height, width, depth
97  'productFormDetailCodes' => 'List175', // refinement of product form (SACD, Mass market (rack) paperback, etc)
98  'productAvailabilityCodes' => 'List65', // Available, In Stock, Print On Demand, Not Yet Available, etc
99  'technicalProtectionCodes' => 'List144', // None, DRM, Apple DRM, etc
100  'returnableIndicatorCodes' => 'List66', // No, not returnable, Yes, full copies only, (required for physical items only)
101  'countriesIncludedCodes' => 'List91', // country region codes
102  );
103 
104  foreach ($codes as $templateVarName => $list) {
105  $templateMgr->assign_by_ref($templateVarName, $onixCodelistItemDao->getCodes($list));
106  }
107 
108  // consider public identifiers
109  $pubIdPlugins = PluginRegistry::loadCategory('pubIds', true);
110  $templateMgr->assign('pubIdPlugins', $pubIdPlugins);
111 
112  // Notification options.
113  $notificationRequestOptions = array(
114  NOTIFICATION_LEVEL_NORMAL => array(
115  NOTIFICATION_TYPE_CONFIGURE_PAYMENT_METHOD => array(ASSOC_TYPE_PRESS, $press->getId()),
116  NOTIFICATION_TYPE_FORMAT_NEEDS_APPROVED_SUBMISSION => array(ASSOC_TYPE_MONOGRAPH, $monograph->getId())),
117  NOTIFICATION_LEVEL_TRIVIAL => array()
118  );
119 
120  $templateMgr->assign('notificationRequestOptions', $notificationRequestOptions);
121 
122  return parent::fetch($request);
123  }
124 
128  function initData() {
130  LOCALE_COMPONENT_APP_COMMON,
131  LOCALE_COMPONENT_PKP_SUBMISSION,
132  LOCALE_COMPONENT_APP_SUBMISSION
133  );
134 
135  $publicationFormatDao = DAORegistry::getDAO('PublicationFormatDAO');
136  $monograph = $this->getMonograph();
137  $publicationFormat = $publicationFormatDao->getById($this->getPublicationFormatId(), $monograph->getId());
138  assert($publicationFormat);
139 
140  $this->_data = array(
141  'fileSize' => (boolean) $publicationFormat->getFileSize() ? $publicationFormat->getFileSize() : $publicationFormat->getCalculatedFileSize(),
142  'override' => (boolean) $publicationFormat->getData('fileSize') ? true : false,
143  'frontMatter' => $publicationFormat->getFrontMatter(),
144  'backMatter' => $publicationFormat->getBackMatter(),
145  'height' => $publicationFormat->getHeight(),
146  'heightUnitCode' => $publicationFormat->getHeightUnitCode() != '' ? $publicationFormat->getHeightUnitCode() : 'mm',
147  'width' => $publicationFormat->getWidth(),
148  'widthUnitCode' => $publicationFormat->getWidthUnitCode() != '' ? $publicationFormat->getWidthUnitCode() : 'mm',
149  'thickness' => $publicationFormat->getThickness(),
150  'thicknessUnitCode' => $publicationFormat->getThicknessUnitCode() != '' ? $publicationFormat->getThicknessUnitCode() : 'mm',
151  'weight' => $publicationFormat->getWeight(),
152  'weightUnitCode' => $publicationFormat->getWeightUnitCode() != '' ? $publicationFormat->getWeightUnitCode() : 'gr',
153  'productCompositionCode' => $publicationFormat->getProductCompositionCode(),
154  'productFormDetailCode' => $publicationFormat->getProductFormDetailCode(),
155  'countryManufactureCode' => $publicationFormat->getCountryManufactureCode() != '' ? $publicationFormat->getCountryManufactureCode() : 'CA',
156  'imprint' => $publicationFormat->getImprint(),
157  'productAvailabilityCode' => $publicationFormat->getProductAvailabilityCode() != '' ? $publicationFormat->getProductAvailabilityCode() : '20',
158  'technicalProtectionCode' => $publicationFormat->getTechnicalProtectionCode() != '' ? $publicationFormat->getTechnicalProtectionCode() : '00',
159  'returnableIndicatorCode' => $publicationFormat->getReturnableIndicatorCode() != '' ? $publicationFormat->getReturnableIndicatorCode() : 'Y',
160  'isApproved' => (bool) $publicationFormat->getIsApproved(),
161  // the pubId plugin needs the format object.
162  'publicationFormat' => $publicationFormat
163  );
164 
165  // initialize the pubId fields.
166  $pubIdPluginHelper = $this->_getPubIdPluginHelper();
167  $pubIdPluginHelper->init($this, $publicationFormat);
168  }
169 
173  function readInputData() {
174  $this->readUserVars(array(
175  'directSalesPrice',
176  'fileSize',
177  'override',
178  'frontMatter',
179  'backMatter',
180  'height',
181  'heightUnitCode',
182  'width',
183  'widthUnitCode',
184  'thickness',
185  'thicknessUnitCode',
186  'weight',
187  'weightUnitCode',
188  'productCompositionCode',
189  'productFormDetailCode',
190  'countryManufactureCode',
191  'imprint',
192  'productAvailabilityCode',
193  'technicalProtectionCode',
194  'returnableIndicatorCode',
195  'isApproved'
196  ));
197 
198  // consider the additional field names from the public identifer plugins
199  $pubIdPluginHelper = $this->_getPubIdPluginHelper();
200  $pubIdPluginHelper->readInputData($this);
201  }
202 
206  function execute($request) {
207  parent::execute();
208 
209  $monograph = $this->getMonograph();
210  $publicationFormatDao = DAORegistry::getDAO('PublicationFormatDAO');
211  $publicationFormat = $publicationFormatDao->getById($this->getPublicationFormatId(), $monograph->getId());
212  assert($publicationFormat);
213 
214  // Manage tombstones for the publication format.
215  if ($publicationFormat->getIsApproved() && !$this->getData('isApproved')) {
216  // Publication format was approved and its being disabled. Create
217  // a tombstone for it.
218  $press = $request->getPress();
219  import('classes.publicationFormat.PublicationFormatTombstoneManager');
220  $publicationFormatTombstoneMgr = new PublicationFormatTombstoneManager();
221  $publicationFormatTombstoneMgr->insertTombstoneByPublicationFormat($publicationFormat, $press);
222 
223  // Log unpublish event.
224  import('lib.pkp.classes.log.SubmissionLog');
225  SubmissionLog::logEvent($request, $monograph, SUBMISSION_LOG_PUBLICATION_FORMAT_UNPUBLISH, 'submission.event.publicationFormatUnpublished', array('publicationFormatName' => $publicationFormat->getLocalizedName()));
226  } elseif (!$publicationFormat->getIsApproved() && $this->getData('isApproved')) {
227  // Wasn't approved and now it is. Delete tombstone.
228  $tombstoneDao = DAORegistry::getDAO('DataObjectTombstoneDAO');
229  $tombstoneDao->deleteByDataObjectId($publicationFormat->getId());
230 
231  // Log publish event.
232  import('lib.pkp.classes.log.SubmissionLog');
233  SubmissionLog::logEvent($request, $monograph, SUBMISSION_LOG_PUBLICATION_FORMAT_PUBLISH, 'submission.event.publicationFormatPublished', array('publicationFormatName' => $publicationFormat->getLocalizedName()));
234  }
235 
236  // populate the published monograph with the cataloging metadata
237  $publicationFormat->setFileSize($this->getData('override') ? $this->getData('fileSize'):null);
238  $publicationFormat->setFrontMatter($this->getData('frontMatter'));
239  $publicationFormat->setBackMatter($this->getData('backMatter'));
240  $publicationFormat->setHeight($this->getData('height'));
241  $publicationFormat->setHeightUnitCode($this->getData('heightUnitCode'));
242  $publicationFormat->setWidth($this->getData('width'));
243  $publicationFormat->setWidthUnitCode($this->getData('widthUnitCode'));
244  $publicationFormat->setThickness($this->getData('thickness'));
245  $publicationFormat->setThicknessUnitCode($this->getData('thicknessUnitCode'));
246  $publicationFormat->setWeight($this->getData('weight'));
247  $publicationFormat->setWeightUnitCode($this->getData('weightUnitCode'));
248  $publicationFormat->setProductCompositionCode($this->getData('productCompositionCode'));
249  $publicationFormat->setProductFormDetailCode($this->getData('productFormDetailCode'));
250  $publicationFormat->setCountryManufactureCode($this->getData('countryManufactureCode'));
251  $publicationFormat->setImprint($this->getData('imprint'));
252  $publicationFormat->setProductAvailabilityCode($this->getData('productAvailabilityCode'));
253  $publicationFormat->setTechnicalProtectionCode($this->getData('technicalProtectionCode'));
254  $publicationFormat->setReturnableIndicatorCode($this->getData('returnableIndicatorCode'));
255  $publicationFormat->setIsApproved($this->getData('isApproved')?true:false);
256 
257  // consider the additional field names from the public identifer plugins
258  $pubIdPluginHelper = $this->_getPubIdPluginHelper();
259  $pubIdPluginHelper->execute($this, $publicationFormat);
260 
261  $publicationFormatDao->updateObject($publicationFormat);
262  }
263 
264  //
265  // Getters and Setters
266  //
271  function &getMonograph() {
272  return $this->_monograph;
273  }
274 
279  function getStageId() {
280  return $this->_stageId;
281  }
282 
287  function getPhysicalFormat() {
289  }
290 
297  }
298 
302  function getFormParams() {
303  return $this->_formParams;
304  }
305 
311  return $this->_pubIdPluginHelper;
312  }
313 }
314 
315 ?>
static & getDAO($name, $dbconn=null)
addCheck($formValidator)
Definition: Form.inc.php:396
Form validation check to make sure the form is POSTed.
static requireComponents()
readUserVars($vars)
Definition: Form.inc.php:364
Class defining basic operations for handling HTML forms.
Definition: Form.inc.php:47
static & loadCategory($category, $enabledOnly=false, $mainContextId=null)
getData($key)
Definition: Form.inc.php:210
Class defining basic operations for publication format tombstones.
CatalogEntryFormatMetadataForm($monographId, $publicationFormatId, $isPhysicalFormat=true, $stageId=null, $formParams=null)
Provides payment management functions.
Helper class for public identifiers plugins.
Parent class for forms used by the various publication formats.
Form validation check using a regular expression.
static logEvent($request, $submission, $eventType, $messageKey, $params=array())
Class to represent a form validation check.