Open Monograph Press  1.1
 All Classes Namespaces Functions Variables Groups Pages
SponsorForm.inc.php
1 <?php
2 
17 import('lib.pkp.classes.form.Form');
18 
19 class SponsorForm extends Form {
22 
26  function SponsorForm($sponsorId = null) {
27  $this->sponsorId = $sponsorId;
28  parent::Form('controllers/grid/settings/sponsor/form/sponsorForm.tpl');
29 
30  // Validation checks for this form
31  $this->addCheck(new FormValidator($this, 'institution', 'required', 'manager.setup.form.sponsors.institutionRequired'));
32  $this->addCheck(new FormValidatorUrl($this, 'url', 'required', 'manager.emails.form.sponsors.urlRequired'));
33  $this->addCheck(new FormValidatorPost($this));
34  }
35 
41  function initData($args, $request) {
42  $context = $request->getContext();
43 
44  $sponsors = $context->getSetting('sponsors');
45  if ( $this->sponsorId && isset($sponsors[$this->sponsorId]) ) {
46  $this->_data = array(
47  'sponsorId' => $this->sponsorId,
48  'institution' => $sponsors[$this->sponsorId]['institution'],
49  'url' => $sponsors[$this->sponsorId]['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  $templateMgr = TemplateManager::getManager($request);
71  $templateMgr->assign('institution', $this->_data['institution']);
72  $templateMgr->assign('url', $this->_data['url']);
73  return parent::fetch($request);
74  }
75 
80  function readInputData() {
81  $this->readUserVars(array('sponsorId', 'institution', 'url'));
82  $this->readUserVars(array('gridId', 'rowId'));
83  }
84 
89  function execute($request) {
90  $context = $request->getContext();
91  $sponsors = $context->getSetting('sponsors');
92  if (empty($sponsors)) {
93  $sponsors = array();
94  $this->sponsorId = 1;
95  } else {
96  //FIXME: a bit of kludge to get unique sponsor id's
97  $this->sponsorId = ($this->sponsorId?$this->sponsorId:(max(array_keys($sponsors)) + 1));
98  }
99  $sponsors[$this->sponsorId] = array(
100  'institution' => $this->getData('institution'),
101  'url' => $this->getData('url')
102  );
103 
104  $context->updateSetting('sponsors', $sponsors, 'object', false);
105  return true;
106  }
107 }
108 
109 ?>
addCheck($formValidator)
Definition: Form.inc.php:396
initData($args, $request)
Form for adding/edditing a sponsor stores/retrieves from an associative array.
execute($request)
fetch($request)
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
getData($key)
Definition: Form.inc.php:210
Form validation check for URLs.
SponsorForm($sponsorId=null)
Class to represent a form validation check.