Open Monograph Press  1.1
 All Classes Namespaces Functions Variables Groups Pages
ContributorForm.inc.php
1 <?php
2 
17 import('lib.pkp.classes.form.Form');
18 
19 class ContributorForm extends Form {
22 
26  function ContributorForm($contributorId = null) {
27  $this->contributorId = $contributorId;
28  parent::Form('controllers/grid/settings/contributor/form/contributorForm.tpl');
29 
30  // Validation checks for this form
31  $this->addCheck(new FormValidator($this, 'institution', 'required', 'manager.setup.form.contributors.institutionRequired'));
32  $this->addCheck(new FormValidatorUrl($this, 'url', 'required', 'manager.emails.form.contributors.urlRequired'));
33  $this->addCheck(new FormValidatorPost($this));
34  }
35 
41  function initData($args, $request) {
42  $context = $request->getContext();
43 
44  $contributors = $context->getSetting('contributors');
45  if ( $this->contributorId && isset($contributors[$this->contributorId]) ) {
46  $this->_data = array(
47  'contributorId' => $this->contributorId,
48  'institution' => $contributors[$this->contributorId]['institution'],
49  'url' => $contributors[$this->contributorId]['url']
50  );
51  } else {
52  $this->_data = array(
53  'institution' => '',
54  'url' => ''
55  );
56  }
57 
58  // grid related data
59  $this->_data['gridId'] = $args['gridId'];
60  $this->_data['rowId'] = isset($args['rowId']) ? $args['rowId'] : null;
61  }
62 
68  function fetch($request) {
69  AppLocale::requireComponents(LOCALE_COMPONENT_APP_MANAGER);
70  return parent::fetch($request);
71  }
72 
77  function readInputData() {
78  $this->readUserVars(array('contributorId', 'institution', 'url'));
79  $this->readUserVars(array('gridId', 'rowId'));
80  }
81 
86  function execute($request) {
87  $context = $request->getContext();
88  $contributors = $context->getSetting('contributors');
89  if (empty($contributors)) {
90  $contributors = array();
91  $this->contributorId = 1;
92  } else {
93  //FIXME: a bit of kludge to get unique contributor id's
94  $this->contributorId = ($this->contributorId?$this->contributorId:(max(array_keys($contributors)) + 1));
95  }
96 
97  $contributors[$this->contributorId] = array('institution' => $this->getData('institution'),
98  'url' => $this->getData('url'));
99  $context->updateSetting('contributors', $contributors, 'object', false);
100  return true;
101  }
102 }
103 
104 ?>
addCheck($formValidator)
Definition: Form.inc.php:396
ContributorForm($contributorId=null)
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
initData($args, $request)
getData($key)
Definition: Form.inc.php:210
Form validation check for URLs.
Form for adding/edditing a contributor stores/retrieves from an associative array.
Class to represent a form validation check.