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

classes/submission/form/SubmissionSubmitStep1Form.inc.php

00001 <?php
00002 
00016 import('classes.submission.form.SubmissionSubmitForm');
00017 
00018 class SubmissionSubmitStep1Form extends SubmissionSubmitForm {
00022    function SubmissionSubmitStep1Form($press, $monograph = null) {
00023       parent::SubmissionSubmitForm($press, $monograph, 1);
00024 
00025       // Validation checks for this form
00026       $supportedSubmissionLocales = $press->getSetting('supportedSubmissionLocales');
00027       if (!is_array($supportedSubmissionLocales) || count($supportedSubmissionLocales) < 1) $supportedSubmissionLocales = array($press->getPrimaryLocale());
00028       $this->addCheck(new FormValidatorInSet($this, 'locale', 'required', 'submission.submit.form.localeRequired', $supportedSubmissionLocales));
00029       if ((boolean) $press->getSetting('copyrightNoticeAgree')) {
00030          $this->addCheck(new FormValidator($this, 'copyrightNoticeAgree', 'required', 'submission.submit.copyrightNoticeAgreeRequired'));
00031       }
00032       $this->addCheck(new FormValidator($this, 'authorUserGroupId', 'required', 'user.authorization.userGroupRequired'));
00033 
00034 
00035       foreach ($press->getLocalizedSetting('submissionChecklist') as $key => $checklistItem) {
00036          $this->addCheck(new FormValidator($this, "checklist-$key", 'required', 'submission.submit.checklistErrors'));
00037       }
00038    }
00039 
00043    function display($request) {
00044       $user =& $request->getUser();
00045 
00046       $templateMgr =& TemplateManager::getManager();
00047 
00048       // FIXME: If this user is a series editor, they are allowed
00049       // to submit to series flagged as "editor-only" for
00050       // submissions. Otherwise, display only series they are allowed
00051       // to submit to.
00052       $roleDao =& DAORegistry::getDAO('RoleDAO');
00053       $isEditor = $roleDao->userHasRole($this->press->getId(), $user->getId(), ROLE_ID_SERIES_EDITOR);
00054 
00055       // Get series for this press
00056       $seriesDao =& DAORegistry::getDAO('SeriesDAO');
00057       $seriesOptions = array('0' => __('submission.submit.selectSeries')) + $seriesDao->getTitlesByPressId($this->press->getId());
00058       $templateMgr->assign('seriesOptions', $seriesOptions);
00059 
00060       // Provide available submission languages. (Convert the array
00061       // of locale symbolic names xx_XX into an associative array
00062       // of symbolic names => readable names.)
00063       $supportedSubmissionLocales = $this->press->getSetting('supportedSubmissionLocales');
00064       if (empty($supportedSubmissionLocales)) $supportedSubmissionLocales = array($this->press->getPrimaryLocale());
00065       $templateMgr->assign(
00066          'supportedSubmissionLocaleNames',
00067          array_flip(array_intersect(
00068             array_flip(AppLocale::getAllLocales()),
00069             $supportedSubmissionLocales
00070          ))
00071       );
00072 
00073       // if this press has a copyright notice that the author must agree to, present the form items.
00074       $press =& $request->getPress();
00075       if ((boolean) $press->getSetting('copyrightNoticeAgree')) {
00076          $templateMgr->assign('copyrightNotice', $press->getLocalizedSetting('copyrightNotice'));
00077          $templateMgr->assign('copyrightNoticeAgree', true);
00078       }
00079 
00080       // Get list of user's author user groups.  If its more than one, we'll need to display an author user group selector
00081       $userGroupAssignmentDao =& DAORegistry::getDAO('UserGroupAssignmentDAO');
00082       $userGroupDao =& DAORegistry::getDAO('UserGroupDAO');
00083       $authorUserGroupAssignments =& $userGroupAssignmentDao->getByUserId($user->getId(), $this->press->getId(), ROLE_ID_AUTHOR);
00084       if(!$authorUserGroupAssignments->wasEmpty()) {
00085          $authorUserGroupNames = array();
00086          while($authorUserGroupAssignment =& $authorUserGroupAssignments->next()) {
00087             $authorUserGroup =& $userGroupDao->getById($authorUserGroupAssignment->getUserGroupId());
00088             if ($userGroupDao->userGroupAssignedToStage($authorUserGroup->getId(), WORKFLOW_STAGE_ID_SUBMISSION)) {
00089                $authorUserGroupNames[$authorUserGroup->getId()] = $authorUserGroup->getLocalizedName();
00090             }
00091             unset($authorUserGroupAssignment);
00092          }
00093          $templateMgr->assign('authorUserGroupOptions', $authorUserGroupNames);
00094       } else {
00095          // The user doesn't have any author user group assignments.  They should be either a manager.
00096          $userGroupNames = array();
00097 
00098          // Add all manager user groups
00099          $managerUserGroupAssignments =& $userGroupAssignmentDao->getByUserId($user->getId(), $this->press->getId(), ROLE_ID_PRESS_MANAGER);
00100          if($managerUserGroupAssignments) while($managerUserGroupAssignment =& $managerUserGroupAssignments->next()) {
00101             $managerUserGroup =& $userGroupDao->getById($managerUserGroupAssignment->getUserGroupId());
00102             $userGroupNames[$managerUserGroup->getId()] = $managerUserGroup->getLocalizedName();
00103             unset($managerUserGroupAssignment);
00104          }
00105 
00106          $templateMgr->assign('authorUserGroupOptions', $userGroupNames);
00107       }
00108 
00109       parent::display($request);
00110    }
00111 
00115    function initData() {
00116       if (isset($this->monograph)) {
00117          $this->_data = array(
00118             'seriesId' => $this->monograph->getSeriesId(),
00119             'seriesPosition' => $this->monograph->getSeriesPosition(),
00120             'locale' => $this->monograph->getLocale(),
00121             'workType' => $this->monograph->getWorkType(),
00122             'commentsToEditor' => $this->monograph->getCommentsToEditor()
00123          );
00124       } else {
00125          $supportedSubmissionLocales = $this->press->getSetting('supportedSubmissionLocales');
00126          // Try these locales in order until we find one that's
00127          // supported to use as a default.
00128          $tryLocales = array(
00129             $this->getFormLocale(), // Current form locale
00130             AppLocale::getLocale(), // Current UI locale
00131             $this->press->getPrimaryLocale(), // Press locale
00132             $supportedSubmissionLocales[array_shift(array_keys($supportedSubmissionLocales))] // Fallback: first one on the list
00133          );
00134          $this->_data = array();
00135          foreach ($tryLocales as $locale) {
00136             if (in_array($locale, $supportedSubmissionLocales)) {
00137                // Found a default to use
00138                $this->_data['locale'] = $locale;
00139                break;
00140             }
00141          }
00142       }
00143    }
00144 
00148    function readInputData() {
00149       $vars = array(
00150          'authorUserGroupId', 'locale', 'workType', 'copyrightNoticeAgree', 'seriesId', 'seriesPosition', 'commentsToEditor', 'copyrightNoticeAgree'
00151       );
00152       foreach ($this->press->getLocalizedSetting('submissionChecklist') as $key => $checklistItem) {
00153          $vars[] = "checklist-$key";
00154       }
00155 
00156       $this->readUserVars($vars);
00157    }
00158 
00165    function execute($args, &$request) {
00166       $monographDao =& DAORegistry::getDAO('MonographDAO');
00167 
00168       if (isset($this->monograph)) {
00169          // Update existing monograph
00170          $this->monograph->setSeriesId($this->getData('seriesId'));
00171          $this->monograph->setSeriesPosition($this->getData('seriesPosition'));
00172          $this->monograph->setLocale($this->getData('locale'));
00173          $this->monograph->setCommentsToEditor($this->getData('commentsToEditor'));
00174             $this->monograph->setWorkType($this->getData('workType'));
00175          if ($this->monograph->getSubmissionProgress() <= $this->step) {
00176             $this->monograph->stampStatusModified();
00177             $this->monograph->setSubmissionProgress($this->step + 1);
00178          }
00179          $monographDao->updateMonograph($this->monograph);
00180       } else {
00181          $user =& $request->getUser();
00182          $press =& $request->getPress();
00183 
00184          // Create new monograph
00185          $this->monograph = new Monograph();
00186          $this->monograph->setLocale($this->getData('locale'));
00187          $this->monograph->setUserId($user->getId());
00188          $this->monograph->setPressId($this->press->getId());
00189          $this->monograph->setSeriesId($this->getData('seriesId'));
00190          $this->monograph->setSeriesPosition($this->getData('seriesPosition'));
00191          $this->monograph->stampStatusModified();
00192          $this->monograph->setSubmissionProgress($this->step + 1);
00193          $this->monograph->setLanguage(String::substr($this->monograph->getLocale(), 0, 2));
00194          $this->monograph->setCommentsToEditor($this->getData('commentsToEditor'));
00195          $this->monograph->setWorkType($this->getData('workType'));
00196          $this->monograph->setStageId(WORKFLOW_STAGE_ID_SUBMISSION);
00197          $this->monograph->setCopyrightNotice($press->getLocalizedSetting('copyrightNotice'), $this->getData('locale'));
00198          // Insert the monograph
00199          $this->monographId = $monographDao->insertMonograph($this->monograph);
00200 
00201          // Set user to initial author
00202          $authorDao =& DAORegistry::getDAO('AuthorDAO');
00203          $author = new Author();
00204          $author->setFirstName($user->getFirstName());
00205          $author->setMiddleName($user->getMiddleName());
00206          $author->setLastName($user->getLastName());
00207          $author->setAffiliation($user->getAffiliation(null), null);
00208          $author->setCountry($user->getCountry());
00209          $author->setEmail($user->getEmail());
00210          $author->setUrl($user->getUrl());
00211          $author->setBiography($user->getBiography(null), null);
00212          $author->setPrimaryContact(1);
00213 
00214          // Get the user group to display the submitter as
00215          $authorUserGroupId = (int) $this->getData('authorUserGroupId');
00216          $author->setUserGroupId($authorUserGroupId);
00217 
00218          $author->setSubmissionId($this->monographId);
00219          $authorDao->insertAuthor($author);
00220 
00221          // Assign the user author to the stage
00222          $stageAssignmentDao =& DAORegistry::getDAO('StageAssignmentDAO');
00223          $stageAssignmentDao->build($this->monographId, $authorUserGroupId, $user->getId());
00224       }
00225 
00226       return $this->monographId;
00227    }
00228 }
00229 
00230 ?>

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