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

controllers/grid/users/author/form/AuthorForm.inc.php

00001 <?php
00002 
00015 import('lib.pkp.classes.form.Form');
00016 
00017 class AuthorForm extends Form {
00019    var $_monograph;
00020 
00022    var $_author;
00023 
00027    function AuthorForm($monograph, $author) {
00028       parent::Form('controllers/grid/users/author/form/authorForm.tpl');
00029       $this->setMonograph($monograph);
00030       $this->setAuthor($author);
00031 
00032       // Validation checks for this form
00033       $this->addCheck(new FormValidator($this, 'firstName', 'required', 'submission.submit.form.authorRequiredFields'));
00034       $this->addCheck(new FormValidator($this, 'lastName', 'required', 'submission.submit.form.authorRequiredFields'));
00035       $this->addCheck(new FormValidatorEmail($this, 'email', 'required', 'form.emailRequired'));
00036       $this->addCheck(new FormValidatorUrl($this, 'url', 'optional', 'user.profile.form.urlInvalid'));
00037       $this->addCheck(new FormValidator($this, 'userGroupId', 'required', 'submission.submit.form.contributorRoleRequired'));
00038       $this->addCheck(new FormValidatorPost($this));
00039    }
00040 
00041    //
00042    // Getters and Setters
00043    //
00048    function getAuthor() {
00049       return $this->_author;
00050    }
00051 
00056    function setAuthor($author) {
00057       $this->_author =& $author;
00058    }
00059 
00064    function getMonograph() {
00065       return $this->_monograph;
00066    }
00067 
00072    function setMonograph($monograph) {
00073       $this->_monograph =& $monograph;
00074    }
00075 
00076 
00077    //
00078    // Overridden template methods
00079    //
00084    function initData() {
00085       $author =& $this->getAuthor();
00086 
00087       if ( $author ) {
00088          $this->_data = array(
00089             'authorId' => $author->getId(),
00090             'firstName' => $author->getFirstName(),
00091             'middleName' => $author->getMiddleName(),
00092             'lastName' => $author->getLastName(),
00093             'suffix' => $author->getSuffix(),
00094             'affiliation' => $author->getAffiliation(AppLocale::getLocale()),
00095             'country' => $author->getCountry(),
00096             'email' => $author->getEmail(),
00097             'url' => $author->getUrl(),
00098             'userGroupId' => $author->getUserGroupId(),
00099             'biography' => $author->getBiography(AppLocale::getLocale()),
00100             'primaryContact' => $author->getPrimaryContact()
00101          );
00102       }
00103    }
00104 
00109    function fetch(&$request) {
00110       $author =& $this->getAuthor();
00111 
00112       $templateMgr =& TemplateManager::getManager();
00113       $countryDao =& DAORegistry::getDAO('CountryDAO');
00114       $countries =& $countryDao->getCountries();
00115       $templateMgr->assign_by_ref('countries', $countries);
00116 
00117       $router =& $request->getRouter();
00118       $context =& $router->getContext($request);
00119 
00120       $userGroupDao =& DAORegistry::getDAO('UserGroupDAO');
00121       $authorUserGroups =& $userGroupDao->getByRoleId($context->getId(), ROLE_ID_AUTHOR);
00122       $templateMgr->assign_by_ref('authorUserGroups', $authorUserGroups);
00123 
00124       $monograph =& $this->getMonograph();
00125       $templateMgr->assign('monographId', $monograph->getId());
00126 
00127       return parent::fetch($request);
00128    }
00129 
00134    function readInputData() {
00135       $this->readUserVars(array(
00136          'authorId',
00137          'firstName',
00138          'middleName',
00139          'lastName',
00140          'suffix',
00141          'affiliation',
00142          'country',
00143          'email',
00144          'url',
00145          'userGroupId',
00146          'biography',
00147          'primaryContact'
00148       ));
00149    }
00150 
00156    function execute() {
00157       $authorDao =& DAORegistry::getDAO('AuthorDAO');
00158       $monograph = $this->getMonograph();
00159 
00160       $author =& $this->getAuthor();
00161       if (!$author) {
00162          // this is a new submission contributor
00163          $author = new Author();
00164          $author->setSubmissionId($monograph->getId());
00165          $existingAuthor = false;
00166       } else {
00167          $existingAuthor = true;
00168          if ($monograph->getId() !== $author->getSubmissionId()) fatalError('Invalid author!');
00169       }
00170 
00171       $author->setFirstName($this->getData('firstName'));
00172       $author->setMiddleName($this->getData('middleName'));
00173       $author->setLastName($this->getData('lastName'));
00174       $author->setSuffix($this->getData('suffix'));
00175       $author->setAffiliation($this->getData('affiliation'), AppLocale::getLocale()); // localized
00176       $author->setCountry($this->getData('country'));
00177       $author->setEmail($this->getData('email'));
00178       $author->setUrl($this->getData('url'));
00179       $author->setUserGroupId($this->getData('userGroupId'));
00180       $author->setBiography($this->getData('biography'), AppLocale::getLocale()); // localized
00181       $author->setPrimaryContact(($this->getData('primaryContact') ? true : false));
00182 
00183       if ($existingAuthor) {
00184          $authorDao->updateAuthor($author);
00185          $authorId = $author->getId();
00186       } else {
00187          $authorId = $authorDao->insertAuthor($author);
00188       }
00189 
00190       return $authorId;
00191    }
00192 }
00193 
00194 ?>

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