Open Journal Systems  3.3.0
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 __construct($genreId = null) {
43  $this->setGenreId($genreId);
44  parent::__construct('controllers/grid/settings/genre/form/genreForm.tpl');
45 
46  $request = Application::get()->getRequest();
47  $context = $request->getContext();
48 
49  // Validation checks for this form
50  $form = $this;
51  $this->addCheck(new FormValidatorLocale($this, 'name', 'required', 'manager.setup.form.genre.nameRequired'));
52  $this->addCheck(new FormValidatorCustom($this, 'key', 'optional', 'manager.setup.genres.key.exists', function($key) use ($context, $form) {
53  $genreDao = DAORegistry::getDAO('GenreDAO'); /* @var $genreDao GenreDAO */
54  return $key == '' || !$genreDao->keyExists($key, $context->getId(), $form->getGenreId());
55  }));
56  $this->addCheck(new FormValidatorRegExp($this, 'key', 'optional', 'manager.setup.genres.key.alphaNumeric', '/^[a-z0-9]+([\-_][a-z0-9]+)*$/i'));
57  $this->addCheck(new FormValidatorPost($this));
58  $this->addCheck(new FormValidatorCSRF($this));
59  }
60 
65  function initData($args) {
66  $request = Application::get()->getRequest();
67  $context = $request->getContext();
68 
69  $genreDao = DAORegistry::getDAO('GenreDAO'); /* @var $genreDao GenreDAO */
70 
71  if($this->getGenreId()) {
72  $genre = $genreDao->getById($this->getGenreId(), $context->getId());
73  }
74 
75  if (isset($genre) ) {
76  $this->_data = array(
77  'genreId' => $this->getGenreId(),
78  'name' => $genre->getName(null),
79  'category' => $genre->getCategory(),
80  'dependent' => $genre->getDependent(),
81  'supplementary' => $genre->getSupplementary(),
82  'key' => $genre->getKey(),
83  'keyReadOnly' => $genre->isDefault(),
84  );
85  } else {
86  $this->_data = array(
87  'name' => array(),
88  );
89  }
90 
91  // grid related data
92  $this->_data['gridId'] = $args['gridId'];
93  $this->_data['rowId'] = isset($args['rowId']) ? $args['rowId'] : null;
94  }
95 
99  function fetch($request, $template = null, $display = false) {
100  $templateMgr = TemplateManager::getManager($request);
101  $templateMgr->assign('submissionFileCategories', array(
102  GENRE_CATEGORY_DOCUMENT => __('submission.document'),
103  GENRE_CATEGORY_ARTWORK => __('submission.art'),
104  GENRE_CATEGORY_SUPPLEMENTARY => __('submission.supplementary'),
105  ));
106 
107  AppLocale::requireComponents(LOCALE_COMPONENT_APP_MANAGER);
108  return parent::fetch($request, $template, $display);
109  }
110 
115  function readInputData() {
116  $this->readUserVars(array('genreId', 'name', 'category', 'dependent', 'supplementary', 'gridId', 'rowId', 'key'));
117  }
118 
123  function execute(...$functionArgs) {
124  $genreDao = DAORegistry::getDAO('GenreDAO'); /* @var $genreDao GenreDAO */
125  $request = Application::get()->getRequest();
126  $context = $request->getContext();
127 
128  // Update or insert genre
129  if (!$this->getGenreId()) {
130  $genre = $genreDao->newDataObject();
131  $genre->setContextId($context->getId());
132  } else {
133  $genre = $genreDao->getById($this->getGenreId(), $context->getId());
134  }
135 
136  $genre->setData('name', $this->getData('name'), null); // Localized
137  $genre->setCategory($this->getData('category'));
138  $genre->setDependent($this->getData('dependent'));
139  $genre->setSupplementary($this->getData('supplementary'));
140 
141  if (!$genre->isDefault()) {
142  $genre->setKey($this->getData('key'));
143  }
144 
145  if (!$this->getGenreId()) {
146  $this->setGenreId($genreDao->insertObject($genre));
147  } else {
148  $genreDao->updateObject($genre);
149  }
150  parent::execute(...$functionArgs);
151  return true;
152  }
153 }
154 
155 
GenreForm\__construct
__construct($genreId=null)
Definition: GenreForm.inc.php:42
AppLocale\requireComponents
static requireComponents()
Definition: env1/MockAppLocale.inc.php:56
GenreForm\getGenreId
getGenreId()
Definition: GenreForm.inc.php:34
DAORegistry\getDAO
static & getDAO($name, $dbconn=null)
Definition: DAORegistry.inc.php:57
FormValidatorLocale
Class to represent a form validation check for localized fields.
Definition: FormValidatorLocale.inc.php:16
Form\readUserVars
readUserVars($vars)
Definition: Form.inc.php:378
Form\getData
getData($key)
Definition: Form.inc.php:220
GenreForm\$_genreId
$_genreId
Definition: GenreForm.inc.php:20
FormValidatorPost
Form validation check to make sure the form is POSTed.
Definition: FormValidatorPost.inc.php:18
GenreForm\setGenreId
setGenreId($genreId)
Definition: GenreForm.inc.php:26
GenreForm
Form for adding/editing a Submission File Genre.
Definition: GenreForm.inc.php:18
GenreForm\fetch
fetch($request, $template=null, $display=false)
Definition: GenreForm.inc.php:99
PKPTemplateManager\getManager
static & getManager($request=null)
Definition: PKPTemplateManager.inc.php:1239
GenreForm\execute
execute(... $functionArgs)
Definition: GenreForm.inc.php:123
FormValidatorRegExp
Form validation check using a regular expression.
Definition: FormValidatorRegExp.inc.php:18
GenreForm\readInputData
readInputData()
Definition: GenreForm.inc.php:115
Form\addCheck
addCheck($formValidator)
Definition: Form.inc.php:395
FormValidatorCSRF
Form validation check to make sure the CSRF token is correct.
Definition: FormValidatorCSRF.inc.php:18
Form
Class defining basic operations for handling HTML forms.
Definition: Form.inc.php:47
PKPApplication\get
static get()
Definition: PKPApplication.inc.php:235
FormValidatorCustom
Form validation check with a custom user function performing the validation check.
Definition: FormValidatorCustom.inc.php:18
GenreForm\initData
initData($args)
Definition: GenreForm.inc.php:65