Open Monograph Press  1.1
 All Classes Namespaces Functions Variables Groups Pages
ApprovedProofForm.inc.php
1 <?php
16 import('lib.pkp.classes.form.Form');
17 
18 class ApprovedProofForm extends Form {
20  var $approvedProof;
21 
24 
27 
34  function ApprovedProofForm($monograph, $publicationFormat, $fileIdAndRevision) {
35  parent::Form('controllers/grid/files/proof/form/approvedProofForm.tpl');
36 
37  $this->monograph =& $monograph;
38  $this->publicationFormat =& $publicationFormat;
39 
40  $submissionFileDao = DAORegistry::getDAO('SubmissionFileDAO');
41  list($fileId, $revision) = explode('-', $fileIdAndRevision);
42  $this->approvedProof =& $submissionFileDao->getRevision($fileId, $revision, SUBMISSION_FILE_PROOF, $this->monograph->getId());
43  if (!$this->approvedProof->getViewable()) fatalError('Proof not approved!');
44 
45  // matches currencies like: 1,500.50 1500.50 1,112.15 5,99 .99
46  $this->addCheck(new FormValidatorRegExp($this, 'price', 'optional', 'grid.catalogEntry.validPriceRequired', '/^(([1-9]\d{0,2}(,\d{3})*|[1-9]\d*|0|)(.\d{2})?|([1-9]\d{0,2}(,\d{3})*|[1-9]\d*|0|)(.\d{2})?)$/'));
47  $this->addCheck(new FormValidatorPost($this));
48  }
49 
50 
51  //
52  // Extended methods from Form
53  //
54  function fetch($request) {
55  $templateMgr = TemplateManager::getManager($request);
56  $templateMgr->assign('fileId', $this->approvedProof->getFileIdAndRevision());
57  $templateMgr->assign('submissionId', $this->monograph->getId());
58  $templateMgr->assign('publicationFormatId', $this->publicationFormat->getId());
59 
60  $salesTypes = array(
61  'openAccess' => 'payment.directSales.openAccess',
62  'directSales' => 'payment.directSales.directSales',
63  'notAvailable' => 'payment.directSales.notAvailable',
64  );
65 
66  $templateMgr->assign('salesTypes', $salesTypes);
67  $templateMgr->assign('salesType', $this->approvedProof->getSalesType());
68  return parent::fetch($request);
69  }
70 
74  function readInputData() {
75  $this->readUserVars(array('price', 'salesType'));
76  }
77 
81  function initData() {
82  $this->_data = array(
83  'price' => $this->approvedProof->getDirectSalesPrice(),
84  'salesType' => $this->approvedProof->getSalesType(),
85  );
86  }
87 
91  function execute($request) {
92  $submissionFileDao = DAORegistry::getDAO('SubmissionFileDAO');
93  $salesType = $this->getData('salesType');
94  if ($salesType === 'notAvailable') {
95  // Not available
96  $this->approvedProof->setDirectSalesPrice(null);
97  } elseif ($salesType === 'openAccess') {
98  // Open access
99  $this->approvedProof->setDirectSalesPrice(0);
100  } else { /* $salesType === 'directSales' */
101  // Direct sale
102  $this->approvedProof->setDirectSalesPrice($this->getData('price'));
103  }
104  $this->approvedProof->setSalesType($salesType);
105  $submissionFileDao->updateObject($this->approvedProof);
106 
107  return $this->approvedProof->getFileIdAndRevision();
108  }
109 }
110 
111 ?>
static & getDAO($name, $dbconn=null)
addCheck($formValidator)
Definition: Form.inc.php:396
Form validation check to make sure the form is POSTed.
readUserVars($vars)
Definition: Form.inc.php:364
Class defining basic operations for handling HTML forms.
Definition: Form.inc.php:47
getData($key)
Definition: Form.inc.php:210
Form validation check using a regular expression.
ApprovedProofForm($monograph, $publicationFormat, $fileIdAndRevision)
Form for editing approved proofs (available for direct sales).