• Main Page
  • Modules
  • Classes
  • Files
  • File List

controllers/grid/settings/genre/form/GenreForm.inc.php

00001 <?php
00002 
00015 import('lib.pkp.classes.form.Form');
00016 
00017 class GenreForm extends Form {
00019    var $_genreId;
00020 
00025    function setGenreId($genreId) {
00026       $this->_genreId = $genreId;
00027    }
00028 
00033    function getGenreId() {
00034       return $this->_genreId;
00035    }
00036 
00037 
00041    function GenreForm($genreId = null) {
00042       $this->setGenreId($genreId);
00043       parent::Form('controllers/grid/settings/genre/form/genreForm.tpl');
00044 
00045       // Validation checks for this form
00046       $this->addCheck(new FormValidatorLocale($this, 'name', 'required', 'manager.setup.form.genre.nameRequired'));
00047       $this->addCheck(new FormValidatorPost($this));
00048    }
00049 
00055    function initData($args, &$request) {
00056       $press =& $request->getPress();
00057 
00058       $genreDao =& DAORegistry::getDAO('GenreDAO');
00059 
00060       if($this->getGenreId()) {
00061          $genre =& $genreDao->getById($this->getGenreId(), $press->getId());
00062       }
00063 
00064       if (isset($genre) ) {
00065          $this->_data = array(
00066             'genreId' => $this->getGenreId(),
00067             'name' => $genre->getName(null),
00068             'designation' => $genre->getDesignation(null),
00069             'sortable' => $genre->getSortable(),
00070             'category' => $genre->getCategory()
00071          );
00072       } else {
00073          $this->_data = array(
00074             'name' => '',
00075             'designation' => ''
00076          );
00077       }
00078 
00079       // grid related data
00080       $this->_data['gridId'] = $args['gridId'];
00081       $this->_data['rowId'] = isset($args['rowId']) ? $args['rowId'] : null;
00082    }
00083 
00089    function fetch(&$request) {
00090       $templateMgr =& TemplateManager::getManager();
00091       $templateMgr->assign('monographFileCategories', array(GENRE_CATEGORY_DOCUMENT => __('submission.document'),
00092                GENRE_CATEGORY_ARTWORK => __('submission.art')));
00093 
00094       AppLocale::requireComponents(LOCALE_COMPONENT_OMP_MANAGER);
00095       return parent::fetch($request);
00096    }
00097 
00102    function readInputData() {
00103       $this->readUserVars(array('genreId', 'name', 'designation', 'sortable', 'category'));
00104       $this->readUserVars(array('gridId', 'rowId'));
00105    }
00106 
00112    function execute($args, &$request) {
00113       $genreDao =& DAORegistry::getDAO('GenreDAO');
00114       $press =& $request->getPress();
00115 
00116       // Update or insert genre
00117       if (!$this->getGenreId()) {
00118          $genre = $genreDao->newDataObject();
00119          $genre->setPressId($press->getId());
00120       } else {
00121          $genre =& $genreDao->getById($this->getGenreId(), $press->getId());
00122       }
00123 
00124       $genre->setData('name', $this->getData('name'), null); // Localized
00125       $genre->setData('designation', $this->getData('designation'), null); // Localized
00126       $genre->setSortable($this->getData('sortable'));
00127       $genre->setCategory($this->getData('category'));
00128 
00129       if (!$this->getGenreId()) {
00130          $this->setGenreId($genreDao->insertObject($genre));
00131       } else {
00132          $genreDao->updateObject($genre);
00133       }
00134 
00135       return true;
00136    }
00137 }
00138 
00139 ?>

Generated on Mon Sep 17 2012 13:58:56 for Open Monograph Press by  doxygen 1.7.1