Open Monograph Press  1.1
 All Classes Namespaces Functions Variables Groups Pages
PublicationFormatForm.inc.php
1 <?php
2 
16 import('lib.pkp.classes.form.Form');
17 
18 class PublicationFormatForm extends Form {
21 
24 
28  function PublicationFormatForm($monograph, $publicationFormat) {
29  parent::Form('controllers/grid/catalogEntry/form/formatForm.tpl');
30  $this->setMonograph($monograph);
31  $this->setPublicationFormat($publicationFormat);
32 
33  // Validation checks for this form
34  $this->addCheck(new FormValidator($this, 'name', 'required', 'grid.catalogEntry.nameRequired'));
35  $this->addCheck(new FormValidator($this, 'entryKey', 'required', 'grid.catalogEntry.publicationFormatRequired'));
36  $this->addCheck(new FormValidatorPost($this));
37  }
38 
39  //
40  // Getters and Setters
41  //
46  function getPublicationFormat() {
48  }
49 
54  function setPublicationFormat($publicationFormat) {
55  $this->_publicationFormat = $publicationFormat;
56  }
57 
62  function getMonograph() {
63  return $this->_monograph;
64  }
65 
70  function setMonograph($monograph) {
71  $this->_monograph = $monograph;
72  }
73 
74 
75  //
76  // Overridden template methods
77  //
81  function initData() {
82  $format = $this->getPublicationFormat();
83 
84  if ($format) {
85  $this->_data = array(
86  'entryKey' => $format->getEntryKey(),
87  'name' => $format->getName(),
88  'isPhysicalFormat' => $format->getPhysicalFormat()?true:false,
89  );
90  } else {
91  $this->setData('entryKey', 'DA');
92  }
93  }
94 
99  function fetch($request) {
100  $format = $this->getPublicationFormat();
101  $press = $request->getPress();
102 
103 
104  $templateMgr = TemplateManager::getManager($request);
105  $onixCodelistItemDao = DAORegistry::getDAO('ONIXCodelistItemDAO');
106  $templateMgr->assign('entryKeys', $onixCodelistItemDao->getCodes('List7')); // List7 is for object formats
107 
108  $monograph = $this->getMonograph();
109  $templateMgr->assign('submissionId', $monograph->getId());
110  $publicationFormat = $this->getPublicationFormat();
111  if ($publicationFormat != null) {
112  $templateMgr->assign('publicationFormatId', $publicationFormat->getId());
113  }
114  return parent::fetch($request);
115  }
116 
121  function readInputData() {
122  $this->readUserVars(array(
123  'name',
124  'entryKey',
125  'isPhysicalFormat',
126  ));
127  }
128 
134  function execute($request) {
135  $publicationFormatDao = DAORegistry::getDAO('PublicationFormatDAO');
136  $monograph = $this->getMonograph();
137  $publicationFormat = $this->getPublicationFormat();
138  if (!$publicationFormat) {
139  // this is a new format to this published monograph
140  $publicationFormat = $publicationFormatDao->newDataObject();
141  $publicationFormat->setMonographId($monograph->getId());
142  $existingFormat = false;
143  } else {
144  $existingFormat = true;
145  if ($monograph->getId() !== $publicationFormat->getMonographId()) fatalError('Invalid format!');
146  }
147 
148  $publicationFormat->setName($this->getData('name'));
149  $publicationFormat->setEntryKey($this->getData('entryKey'));
150  $publicationFormat->setPhysicalFormat($this->getData('isPhysicalFormat')?true:false);
151 
152  if ($existingFormat) {
153  $publicationFormatDao->updateObject($publicationFormat);
154  $publicationFormatId = $publicationFormat->getId();
155  } else {
156  $publicationFormatId = $publicationFormatDao->insertObject($publicationFormat);
157  // log the creation of the format.
158  import('lib.pkp.classes.log.SubmissionLog');
159  import('classes.log.SubmissionEventLogEntry');
160  SubmissionLog::logEvent($request, $monograph, SUBMISSION_LOG_PUBLICATION_FORMAT_CREATE, 'submission.event.publicationFormatCreated', array('formatName' => $publicationFormat->getLocalizedName()));
161  }
162 
163  return $publicationFormatId;
164  }
165 }
166 
167 ?>
static & getDAO($name, $dbconn=null)
addCheck($formValidator)
Definition: Form.inc.php:396
setData($key, $value)
Definition: Form.inc.php:219
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
PublicationFormatForm($monograph, $publicationFormat)
getData($key)
Definition: Form.inc.php:210
setPublicationFormat($publicationFormat)
static logEvent($request, $submission, $eventType, $messageKey, $params=array())
Form for adding/editing a format.
Class to represent a form validation check.