00001 <?php
00002
00015 import('lib.pkp.classes.form.Form');
00016
00017 class AddParticipantForm extends Form {
00019 var $_monograph;
00020
00022 var $_stageId;
00023
00025 var $_userGroups;
00026
00030 function AddParticipantForm(&$monograph, $stageId, &$userGroups) {
00031 parent::Form('controllers/grid/users/stageParticipant/addParticipantForm.tpl');
00032 $this->_monograph =& $monograph;
00033 $this->_stageId = $stageId;
00034 $this->_userGroups =& $userGroups;
00035
00036 $this->addCheck(new FormValidator($this, 'userGroupId', 'required', 'editor.monograph.addStageParticipant.form.userGroupRequired'));
00037
00038
00039 $this->addCheck(new FormValidator($this, 'userId', 'required', 'editor.monograph.addStageParticipant.form.userRequired'));
00040 $this->addCheck(new FormValidatorPost($this));
00041 }
00042
00043
00044
00045
00050 function &getMonograph() {
00051 return $this->_monograph;
00052 }
00053
00058 function getStageId() {
00059 return $this->_stageId;
00060 }
00061
00065 function &getUserGroups() {
00066 return $this->_userGroups;
00067 }
00068
00073 function fetch(&$request) {
00074 $templateMgr =& TemplateManager::getManager();
00075 $userGroups =& $this->getUserGroups();
00076
00077 $userGroupOptions = array();
00078 foreach ($userGroups as $userGroupId => $userGroup) {
00079 $userGroupOptions[$userGroupId] = $userGroup->getLocalizedName();
00080 }
00081
00082 $templateMgr->assign_by_ref('userGroupOptions', $userGroupOptions);
00083
00084 $templateMgr->assign('selectedUserGroupId', array_shift(array_keys($userGroupOptions)));
00085
00086
00087 $monograph =& $this->getMonograph();
00088 $templateMgr->assign('monographId', $monograph->getId());
00089 $templateMgr->assign('stageId', $this->getStageId());
00090
00091 return parent::fetch($request);
00092 }
00093
00098 function readInputData() {
00099 $this->readUserVars(array(
00100 'userGroupId',
00101 'userId'
00102 ));
00103 }
00104
00109 function validate() {
00110 $userGroupId = (int) $this->getData('userGroupId');
00111 $userId = (int) $this->getData('userId');
00112 $monograph =& $this->getMonograph();
00113
00114 $userGroupDao =& DAORegistry::getDAO('UserGroupDAO');
00115 return parent::validate() && $userGroupDao->userInGroup($userId, $userGroupId) && $userGroupDao->getById($userGroupId, $monograph->getPressId());
00116 }
00117
00123 function execute() {
00124 $stageAssignmentDao =& DAORegistry::getDAO('StageAssignmentDAO');
00125 $userGroupDao =& DAORegistry::getDAO('UserGroupDAO');
00126
00127 $monograph =& $this->getMonograph();
00128 $userGroupId = (int) $this->getData('userGroupId');
00129 $userId = (int) $this->getData('userId');
00130
00131
00132 if ($userGroupDao->userGroupAssignedToStage($userGroupId, $this->getStageId())) {
00133
00134 $stageAssignment = $stageAssignmentDao->build($monograph->getId(), $userGroupId, $userId);
00135 }
00136 return array($userGroupId, $userId, $stageAssignment->getId());
00137 }
00138 }
00139
00140 ?>