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

classes/submission/SubmissionMetadataFormImplementation.inc.php

00001 <?php
00002 
00016 class SubmissionMetadataFormImplementation {
00017 
00019    var $_parentForm;
00020 
00026    function SubmissionMetadataFormImplementation($parentForm = null) {
00027 
00028       if (is_a($parentForm, 'Form')) {
00029          $this->_parentForm = $parentForm;
00030       } else {
00031          assert(false);
00032       }
00033    }
00034 
00039    function addChecks(&$monograph) {
00040 
00041       import('lib.pkp.classes.form.validation.FormValidatorLocale');
00042       import('lib.pkp.classes.form.validation.FormValidatorCustom');
00043 
00044       // Validation checks.
00045       $this->_parentForm->addCheck(new FormValidatorLocale($this->_parentForm, 'title', 'required', 'submission.submit.form.titleRequired'));
00046       $this->_parentForm->addCheck(new FormValidatorLocale($this->_parentForm, 'abstract', 'required', 'submission.submit.form.abstractRequired'));
00047       // Validates that at least one author has been added (note that authors are in grid, so Form does not
00048       // directly see the authors value (there is no "authors" input. Hence the $ignore parameter.
00049       $this->_parentForm->addCheck(new FormValidatorCustom(
00050          $this->_parentForm, 'authors', 'required', 'submission.submit.form.authorRequired',
00051          // The first parameter is ignored. This
00052          create_function('$ignore, $monograph', 'return count($monograph->getAuthors()) > 0;'),
00053          array($monograph)
00054       ));
00055    }
00056 
00061    function initData(&$monograph) {
00062       $seriesDao =& DAORegistry::getDAO('SeriesDAO');
00063 
00064       if (isset($monograph)) {
00065          $formData = array(
00066             'title' => $monograph->getTitle(null), // Localized
00067             'prefix' => $monograph->getPrefix(null), // Localized
00068             'subtitle' => $monograph->getSubtitle(null), // Localized
00069             'abstract' => $monograph->getAbstract(null), // Localized
00070             'subjectClass' => $monograph->getSubjectClass(null), // Localized
00071             'coverageGeo' => $monograph->getCoverageGeo(null), // Localized
00072             'coverageChron' => $monograph->getCoverageChron(null), // Localized
00073             'coverageSample' => $monograph->getCoverageSample(null), // Localized
00074             'type' => $monograph->getType(null), // Localized
00075             'source' =>$monograph->getSource(null), // Localized
00076             'rights' => $monograph->getRights(null), // Localized
00077             'series' => $seriesDao->getById($monograph->getSeriesId()),
00078             'citations' => $monograph->getCitations()
00079          );
00080 
00081          foreach ($formData as $key => $data) {
00082             $this->_parentForm->setData($key, $data);
00083          }
00084 
00085          // get the supported locale keys
00086          $locales = array_keys($this->_parentForm->supportedLocales);
00087 
00088          // load the persisted metadata controlled vocabularies
00089          $monographKeywordDao =& DAORegistry::getDAO('MonographKeywordDAO');
00090          $monographSubjectDao =& DAORegistry::getDAO('MonographSubjectDAO');
00091          $monographDisciplineDao =& DAORegistry::getDAO('MonographDisciplineDAO');
00092          $monographAgencyDao =& DAORegistry::getDAO('MonographAgencyDAO');
00093          $monographLanguageDao =& DAORegistry::getDAO('MonographLanguageDAO');
00094 
00095          $this->_parentForm->setData('subjects', $monographSubjectDao->getSubjects($monograph->getId(), $locales));
00096          $this->_parentForm->setData('keywords', $monographKeywordDao->getKeywords($monograph->getId(), $locales));
00097          $this->_parentForm->setData('disciplines', $monographDisciplineDao->getDisciplines($monograph->getId(), $locales));
00098          $this->_parentForm->setData('agencies', $monographAgencyDao->getAgencies($monograph->getId(), $locales));
00099          $this->_parentForm->setData('languages', $monographLanguageDao->getLanguages($monograph->getId(), $locales));
00100       }
00101    }
00102 
00106    function readInputData() {
00107 
00108       // 'keywords' is a tagit catchall that contains an array of values for each keyword/locale combination on the form.
00109       $userVars = array('title', 'prefix', 'subtitle', 'abstract', 'coverageGeo', 'coverageChron', 'coverageSample', 'type', 'subjectClass', 'source', 'rights', 'keywords');
00110       $this->_parentForm->readUserVars($userVars);
00111    }
00112 
00117    function getLocaleFieldNames() {
00118       return array('title', 'prefix', 'subtitle', 'abstract', 'coverageGeo', 'coverageChron', 'coverageSample', 'type', 'subjectClass', 'source', 'rights');
00119    }
00120 
00127    function execute(&$monograph, &$request) {
00128       $monographDao =& DAORegistry::getDAO('MonographDAO');
00129 
00130       // Update monograph
00131       $monograph->setTitle($this->_parentForm->getData('title'), null); // Localized
00132       $monograph->setPrefix($this->_parentForm->getData('prefix'), null); // Localized
00133       $monograph->setSubtitle($this->_parentForm->getData('subtitle'), null); // Localized
00134       $monograph->setAbstract($this->_parentForm->getData('abstract'), null); // Localized
00135       $monograph->setCoverageGeo($this->_parentForm->getData('coverageGeo'), null); // Localized
00136       $monograph->setCoverageChron($this->_parentForm->getData('coverageChron'), null); // Localized
00137       $monograph->setCoverageSample($this->_parentForm->getData('coverageSample'), null); // Localized
00138       $monograph->setType($this->_parentForm->getData('type'), null); // Localized
00139       $monograph->setSubjectClass($this->_parentForm->getData('subjectClass'), null); // Localized
00140       $monograph->setRights($this->_parentForm->getData('rights'), null); // Localized
00141       $monograph->setSource($this->_parentForm->getData('source'), null); // Localized
00142 
00143       // Save the monograph
00144       $monographDao->updateMonograph($monograph);
00145 
00146       // get the supported locale keys
00147       $locales = array_keys($this->_parentForm->supportedLocales);
00148 
00149       // persist the metadata/keyword fields.
00150       $monographKeywordDao =& DAORegistry::getDAO('MonographKeywordDAO');
00151       $monographDisciplineDao =& DAORegistry::getDAO('MonographDisciplineDAO');
00152       $monographAgencyDao =& DAORegistry::getDAO('MonographAgencyDAO');
00153       $monographSubjectDao =& DAORegistry::getDAO('MonographSubjectDAO');
00154       $monographLanguageDao =& DAORegistry::getDAO('MonographLanguageDAO');
00155 
00156       $keywords = array();
00157       $agencies = array();
00158       $disciplines = array();
00159       $languages = array();
00160       $subjects = array();
00161 
00162       $tagitKeywords = $this->_parentForm->getData('keywords');
00163 
00164       if (is_array($tagitKeywords)) {
00165          foreach ($locales as $locale) {
00166             $keywords[$locale] = array_key_exists($locale . '-keyword', $tagitKeywords) ? $tagitKeywords[$locale . '-keyword'] : array();
00167             $agencies[$locale] = array_key_exists($locale . '-agencies', $tagitKeywords) ? $tagitKeywords[$locale . '-agencies'] : array();
00168             $disciplines[$locale] = array_key_exists($locale . '-disciplines', $tagitKeywords) ? $tagitKeywords[$locale . '-disciplines'] : array();
00169             $languages[$locale] = array_key_exists($locale . '-languages', $tagitKeywords) ? $tagitKeywords[$locale . '-languages'] : array();
00170             $subjects[$locale] = array_key_exists($locale . '-subjects', $tagitKeywords) ?$tagitKeywords[$locale . '-subjects'] : array();
00171          }
00172       }
00173 
00174       // persist the controlled vocabs
00175       $monographKeywordDao->insertKeywords($keywords, $monograph->getId());
00176       $monographAgencyDao->insertAgencies($agencies, $monograph->getId());
00177       $monographDisciplineDao->insertDisciplines($disciplines, $monograph->getId());
00178       $monographLanguageDao->insertLanguages($languages, $monograph->getId());
00179       $monographSubjectDao->insertSubjects($subjects, $monograph->getId());
00180 
00181       // Resequence the authors (this ensures a primary contact).
00182       $authorDao =& DAORegistry::getDAO('AuthorDAO');
00183       $authorDao->resequenceAuthors($monograph->getId());
00184 
00185       // Log the modification event.
00186       import('classes.log.MonographLog');
00187       import('classes.log.MonographEventLogEntry');
00188       MonographLog::logEvent($request, $monograph, MONOGRAPH_LOG_METADATA_UPDATE, 'submission.event.general.metadataUpdated');
00189    }
00190 }
00191 
00192 ?>

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