Open Monograph Press  1.1
 All Classes Namespaces Functions Variables Groups Pages
GenreForm.inc.php
1 <?php
2 
16 import('lib.pkp.classes.form.Form');
17 
18 class GenreForm extends Form {
20  var $_genreId;
21 
26  function setGenreId($genreId) {
27  $this->_genreId = $genreId;
28  }
29 
34  function getGenreId() {
35  return $this->_genreId;
36  }
37 
38 
42  function GenreForm($genreId = null) {
43  $this->setGenreId($genreId);
44  parent::Form('controllers/grid/settings/genre/form/genreForm.tpl');
45 
46  // Validation checks for this form
47  $this->addCheck(new FormValidatorLocale($this, 'name', 'required', 'manager.setup.form.genre.nameRequired'));
48  $this->addCheck(new FormValidatorPost($this));
49  }
50 
56  function initData($args, $request) {
57  $context = $request->getContext();
58 
59  $genreDao = DAORegistry::getDAO('GenreDAO');
60 
61  if($this->getGenreId()) {
62  $genre = $genreDao->getById($this->getGenreId(), $context->getId());
63  }
64 
65  if (isset($genre) ) {
66  $this->_data = array(
67  'genreId' => $this->getGenreId(),
68  'name' => $genre->getName(null),
69  'designation' => $genre->getDesignation(),
70  'sortable' => $genre->getSortable(),
71  'category' => $genre->getCategory(),
72  'dependent' => $genre->getDependent(),
73  );
74  } else {
75  $this->_data = array(
76  'name' => '',
77  'designation' => ''
78  );
79  }
80 
81  // grid related data
82  $this->_data['gridId'] = $args['gridId'];
83  $this->_data['rowId'] = isset($args['rowId']) ? $args['rowId'] : null;
84  }
85 
91  function fetch($request) {
92  $templateMgr = TemplateManager::getManager($request);
93  $templateMgr->assign('submissionFileCategories', array(GENRE_CATEGORY_DOCUMENT => __('submission.document'),
94  GENRE_CATEGORY_ARTWORK => __('submission.art')));
95 
96  AppLocale::requireComponents(LOCALE_COMPONENT_APP_MANAGER);
97  return parent::fetch($request);
98  }
99 
104  function readInputData() {
105  $this->readUserVars(array('genreId', 'name', 'designation', 'sortable', 'category', 'dependent'));
106  $this->readUserVars(array('gridId', 'rowId'));
107  }
108 
114  function execute($args, $request) {
115  $genreDao = DAORegistry::getDAO('GenreDAO');
116  $context = $request->getContext();
117 
118  // Update or insert genre
119  if (!$this->getGenreId()) {
120  $genre = $genreDao->newDataObject();
121  $genre->setContextId($context->getId());
122  } else {
123  $genre = $genreDao->getById($this->getGenreId(), $context->getId());
124  }
125 
126  $genre->setData('name', $this->getData('name'), null); // Localized
127  $genre->setData('designation', $this->getData('designation'), null); // Localized
128  $genre->setSortable($this->getData('sortable'));
129  $genre->setCategory($this->getData('category'));
130  $genre->setDependent($this->getData('dependent'));
131 
132  if (!$this->getGenreId()) {
133  $this->setGenreId($genreDao->insertObject($genre));
134  } else {
135  $genreDao->updateObject($genre);
136  }
137 
138  return true;
139  }
140 }
141 
142 ?>
static & getDAO($name, $dbconn=null)
addCheck($formValidator)
Definition: Form.inc.php:396
initData($args, $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
GenreForm($genreId=null)
Class to represent a form validation check for localized fields.
Form for adding/editing a Submission File Genre.
setGenreId($genreId)
execute($args, $request)