Open Monograph Press  1.1
 All Classes Namespaces Functions Variables Groups Pages
AddParticipantForm.inc.php
1 <?php
2 
16 import('controllers.grid.users.stageParticipant.form.StageParticipantNotifyForm');
17 
20  var $_submission;
21 
23  var $_stageId;
24 
27 
34  function AddParticipantForm($submission, $stageId, &$userGroups) {
35  parent::StageParticipantNotifyForm($submission->getId(), ASSOC_TYPE_SUBMISSION, 'controllers/grid/users/stageParticipant/addParticipantForm.tpl');
36  $this->_submission = $submission;
37  $this->_stageId = $stageId;
38  $this->_userGroups = $userGroups;
39 
40  // add checks in addition to anything that the Notification form may apply.
41  $this->addCheck(new FormValidator($this, 'userGroupId', 'required', 'editor.submission.addStageParticipant.form.userGroupRequired'));
42  // FIXME: should use a custom validator to check that the user belongs to this group.
43  // validating in validate method for now.
44  $this->addCheck(new FormValidator($this, 'userId', 'required', 'editor.submission.addStageParticipant.form.userRequired'));
45  $this->addCheck(new FormValidatorPost($this));
46  }
47 
48  //
49  // Getters and Setters
50  //
55  function &getSubmission() {
56  return $this->_submission;
57  }
58 
63  function getStageId() {
64  return $this->_stageId;
65  }
66 
70  function getUserGroups() {
71  return $this->_userGroups;
72  }
73 
78  function fetch($request) {
79  $templateMgr = TemplateManager::getManager($request);
80  $userGroups = $this->getUserGroups();
81 
82  $userGroupOptions = array();
83  foreach ($userGroups as $userGroupId => $userGroup) {
84  $userGroupOptions[$userGroupId] = $userGroup->getLocalizedName();
85  }
86  // assign the user groups options
87  $templateMgr->assign('userGroupOptions', $userGroupOptions);
88  // assigned the first element as selected
89  $templateMgr->assign('selectedUserGroupId', array_shift(array_keys($userGroupOptions)));
90 
91  // assign the vars required for the request
92  $submission = $this->getSubmission();
93  $templateMgr->assign('submissionId', $submission->getId());
94  $templateMgr->assign('stageId', $this->getStageId());
95 
96  return parent::fetch($request);
97  }
98 
102  function readInputData() {
103  $this->readUserVars(array(
104  'userGroupId',
105  'userId',
106  'message',
107  'template'
108  ));
109  }
110 
114  function validate() {
115  $userGroupId = (int) $this->getData('userGroupId');
116  $userId = (int) $this->getData('userId');
117  $submission = $this->getSubmission();
118 
119  $userGroupDao = DAORegistry::getDAO('UserGroupDAO'); /* @var $userGroupDao UserGroupDAO */
120  return $userGroupDao->userInGroup($userId, $userGroupId) && $userGroupDao->getById($userGroupId, $submission->getContextId());
121  }
122 
128  function execute($request) {
129  $stageAssignmentDao = DAORegistry::getDAO('StageAssignmentDAO'); /* @var $stageAssignmentDao StageAssignmentDAO */
130  $userGroupDao = DAORegistry::getDAO('UserGroupDAO'); /* @var $userGroupDao UserGroupDAO */
131 
132  $submission = $this->getSubmission();
133  $userGroupId = (int) $this->getData('userGroupId');
134  $userId = (int) $this->getData('userId');
135 
136  // sanity check
137  if ($userGroupDao->userGroupAssignedToStage($userGroupId, $this->getStageId())) {
138  // insert the assignment
139  $stageAssignment = $stageAssignmentDao->build($submission->getId(), $userGroupId, $userId);
140  }
141 
142  parent::execute($request);
143  return array($userGroupId, $userId, $stageAssignment->getId());
144  }
145 
150  function includeNotifyUsersListbuilder() {
151  return false; // use whoever is assigned to the stage when the form is submitted instead.
152  }
153 }
154 
155 ?>
static & getDAO($name, $dbconn=null)
Form validation check to make sure the form is POSTed.
Form for adding a stage participant.
Form to notify a user regarding a file.
AddParticipantForm($submission, $stageId, &$userGroups)
Class to represent a form validation check.