Open Journal Systems  3.3.0
AddParticipantForm.inc.php
1 <?php
2 
16 import('controllers.grid.users.stageParticipant.form.StageParticipantNotifyForm');
17 
20  var $_submission;
21 
24 
27 
30 
32  var $_contextId;
33 
40  function __construct($submission, $stageId, $assignmentId = null) {
41  parent::__construct($submission->getId(), ASSOC_TYPE_SUBMISSION, $stageId, 'controllers/grid/users/stageParticipant/addParticipantForm.tpl');
42  $this->_submission = $submission;
43  $this->_stageId = $stageId;
44  $this->_assignmentId = $assignmentId;
45  $this->_contextId = $submission->getContextId();
46 
47  // add checks in addition to anything that the Notification form may apply.
48  // FIXME: should use a custom validator to check that the userId belongs to this group.
49  $this->addCheck(new FormValidator($this, 'userGroupId', 'required', 'editor.submission.addStageParticipant.form.userGroupRequired'));
50  $this->addCheck(new FormValidatorPost($this));
51  $this->addCheck(new FormValidatorCSRF($this));
52 
53  $this->initialize();
54  }
55 
56  //
57  // Getters and Setters
58  //
63  function getSubmission() {
64  return $this->_submission;
65  }
66 
70  function initialize() {
71  $userGroupDao = DAORegistry::getDAO('UserGroupDAO'); /* @var $userGroupDao UserGroupDAO */
72 
73  // assign all user group IDs with ROLE_ID_MANAGER or ROLE_ID_SUB_EDITOR
74  $this->_managerGroupIds = $userGroupDao->getUserGroupIdsByRoleId(ROLE_ID_MANAGER, $this->_contextId);
75  $subEditorGroupIds = $userGroupDao->getUserGroupIdsByRoleId(ROLE_ID_SUB_EDITOR, $this->_contextId);
76  $this->_possibleRecommendOnlyUserGroupIds = array_merge($this->_managerGroupIds, $subEditorGroupIds);
77  }
78 
84  protected function _isChangePermitMetadataAllowed($userGroupId) {
85  return !in_array($userGroupId, $this->_managerGroupIds);
86  }
87 
93  protected function _isChangeRecommendOnlyAllowed($userGroupId) {
94  return in_array($userGroupId, $this->_possibleRecommendOnlyUserGroupIds);
95  }
96 
100  function fetch($request, $template = null, $display = false) {
101  $userGroupDao = DAORegistry::getDAO('UserGroupDAO'); /* @var $userGroupDao UserGroupDAO */
102  $userGroups = $userGroupDao->getUserGroupsByStage(
103  $request->getContext()->getId(),
104  $this->getStageId()
105  );
106 
107  $userGroupOptions = array();
108  while ($userGroup = $userGroups->next()) {
109  // Exclude reviewers.
110  if ($userGroup->getRoleId() == ROLE_ID_REVIEWER) continue;
111  $userGroupOptions[$userGroup->getId()] = $userGroup->getLocalizedName();
112  }
113 
114  $templateMgr = TemplateManager::getManager($request);
115  $keys = array_keys($userGroupOptions);
116  $templateMgr->assign(array(
117  'userGroupOptions' => $userGroupOptions,
118  'selectedUserGroupId' => array_shift($keys), // assign the first element as selected
119  'possibleRecommendOnlyUserGroupIds' => $this->_possibleRecommendOnlyUserGroupIds,
120  'recommendOnlyUserGroupIds' => $userGroupDao->getRecommendOnlyGroupIds($request->getContext()->getId()),
121  'notPossibleEditSubmissionMetadataPermissionChange' => $this->_managerGroupIds,
122  'permitMetadataEditUserGroupIds' => $userGroupDao->getPermitMetadataEditGroupIds($request->getContext()->getId()),
123  'submissionId' => $this->getSubmission()->getId(),
124  'userGroupId' => '',
125  'userIdSelected' => '',
126  ));
127 
128  if ($this->_assignmentId) {
130  $stageAssignmentDao = DAORegistry::getDAO('StageAssignmentDAO'); /* @var $stageAssignmentDao StageAssignmentDAO */
131 
133  $stageAssignment = $stageAssignmentDao->getById($this->_assignmentId);
134 
135  $userDao = DAORegistry::getDAO('UserDAO'); /* @var $userDao UserDAO */
137  $currentUser = $userDao->getById($stageAssignment->getUserId());
138 
139  $userGroupDao = DAORegistry::getDAO('UserGroupDAO'); /* @var $userGroupDao UserGroupDAO */
141  $userGroup = $userGroupDao->getById($stageAssignment->getUserGroupId());
142 
143  $templateMgr->assign(array(
144  'assignmentId' => $this->_assignmentId,
145  'currentUserName' => $currentUser->getFullName(),
146  'currentUserGroup' => $userGroup->getLocalizedName(),
147  'userGroupId' => $stageAssignment->getUserGroupId(),
148  'userIdSelected' => $stageAssignment->getUserId(),
149  'currentAssignmentRecommendOnly' => $stageAssignment->getRecommendOnly(),
150  'currentAssignmentPermitMetadataEdit' => $stageAssignment->getCanChangeMetadata(),
151  'isChangePermitMetadataAllowed' => $this->_isChangePermitMetadataAllowed($userGroup->getId()),
152  'isChangeRecommendOnlyAllowed' => $this->_isChangeRecommendOnlyAllowed($userGroup->getId()),
153  ));
154  }
155 
156 
157  // If submission is in review, add a list of reviewer Ids that should not be
158  // assigned as participants because they have blind peer reviews in progress
159  import('lib.pkp.classes.submission.reviewAssignment.ReviewAssignment');
160  $blindReviewerIds = array();
161  if (in_array($this->getSubmission()->getStageId(), array(WORKFLOW_STAGE_ID_INTERNAL_REVIEW, WORKFLOW_STAGE_ID_EXTERNAL_REVIEW))) {
162  $blindReviewMethods = array(SUBMISSION_REVIEW_METHOD_BLIND, SUBMISSION_REVIEW_METHOD_DOUBLEBLIND);
163  $reviewAssignmentDao = DAORegistry::getDAO('ReviewAssignmentDAO'); /* @var $reviewAssignmentDao ReviewAssignmentDAO */
164  $reviewAssignments = $reviewAssignmentDao->getBySubmissionId($this->getSubmission()->getId());
165  $blindReviews = array_filter($reviewAssignments, function($reviewAssignment) use ($blindReviewMethods) {
166  return in_array($reviewAssignment->getReviewMethod(), $blindReviewMethods) && !$reviewAssignment->getDeclined();
167  });
168  $blindReviewerIds = array_map(function($reviewAssignment) {
169  return $reviewAssignment->getReviewerId();
170  }, $blindReviews);
171 
172  }
173  $templateMgr->assign(array(
174  'blindReviewerIds' => array_values(array_unique($blindReviewerIds)),
175  'blindReviewerWarning' => __('editor.submission.addStageParticipant.form.reviewerWarning'),
176  'blindReviewerWarningOk' => __('common.ok'),
177  ));
178 
179  return parent::fetch($request, $template, $display);
180  }
181 
185  function readInputData() {
186  $this->readUserVars(array(
187  'userGroupId',
188  'userId',
189  'message',
190  'template',
191  'recommendOnly',
192  'canChangeMetadata',
193  ));
194  }
195 
199  function validate($callHooks = true) {
200  $userGroupId = (int) $this->getData('userGroupId');
201  $userId = (int) $this->getData('userId');
202  $submission = $this->getSubmission();
203 
204  $userGroupDao = DAORegistry::getDAO('UserGroupDAO'); /* @var $userGroupDao UserGroupDAO */
205  return $userGroupDao->userInGroup($userId, $userGroupId) && $userGroupDao->getById($userGroupId, $submission->getContextId());
206  }
207 
212  function execute(...$functionParams) {
213  $stageAssignmentDao = DAORegistry::getDAO('StageAssignmentDAO');
214  $userGroupDao = DAORegistry::getDAO('UserGroupDAO');
216  $submission = $this->getSubmission();
217  $userGroupId = (int) $this->getData('userGroupId');
218  $userId = (int) $this->getData('userId');
219  $recommendOnly = $this->_isChangeRecommendOnlyAllowed($userGroupId) ? (boolean) $this->getData('recommendOnly') : false;
220  $canChangeMetadata = $this->_isChangePermitMetadataAllowed($userGroupId) ? (boolean) $this->getData('canChangeMetadata') : true;
221 
222  // sanity check
223  if ($userGroupDao->userGroupAssignedToStage($userGroupId, $this->getStageId())) {
224  $updated = false;
225 
226  if ($this->_assignmentId) {
228  $stageAssignment = $stageAssignmentDao->getById($this->_assignmentId);
229 
230  if ($stageAssignment) {
231  $stageAssignment->setRecommendOnly($recommendOnly);
232  $stageAssignment->setCanChangeMetadata($canChangeMetadata);
233  $stageAssignmentDao->updateObject($stageAssignment);
234  $updated = true;
235  }
236  }
237 
238  if (!$updated) {
239  // insert the assignment
240  $stageAssignment = $stageAssignmentDao->build($submission->getId(), $userGroupId, $userId, $recommendOnly, $canChangeMetadata);
241  }
242  }
243 
244  parent::execute(...$functionParams);
245  return array($userGroupId, $userId, $stageAssignment->getId());
246  }
247 
252  function isMessageRequired() {
253  return false;
254  }
255 }
256 
257 
PKPStageParticipantNotifyForm\getStageId
getStageId()
Definition: PKPStageParticipantNotifyForm.inc.php:295
DAORegistry\getDAO
static & getDAO($name, $dbconn=null)
Definition: DAORegistry.inc.php:57
AddParticipantForm\fetch
fetch($request, $template=null, $display=false)
Definition: AddParticipantForm.inc.php:115
Form\readUserVars
readUserVars($vars)
Definition: Form.inc.php:378
Form\getData
getData($key)
Definition: Form.inc.php:220
FormValidatorPost
Form validation check to make sure the form is POSTed.
Definition: FormValidatorPost.inc.php:18
StageParticipantNotifyForm
Form to notify a user regarding a file.
Definition: StageParticipantNotifyForm.inc.php:19
AddParticipantForm\$_managerGroupIds
$_managerGroupIds
Definition: AddParticipantForm.inc.php:35
AddParticipantForm\_isChangePermitMetadataAllowed
_isChangePermitMetadataAllowed($userGroupId)
Definition: AddParticipantForm.inc.php:99
AddParticipantForm\isMessageRequired
isMessageRequired()
Definition: AddParticipantForm.inc.php:267
AddParticipantForm\_isChangeRecommendOnlyAllowed
_isChangeRecommendOnlyAllowed($userGroupId)
Definition: AddParticipantForm.inc.php:108
AddParticipantForm\getSubmission
getSubmission()
Definition: AddParticipantForm.inc.php:78
AddParticipantForm\validate
validate($callHooks=true)
Definition: AddParticipantForm.inc.php:214
AddParticipantForm\$_submission
$_submission
Definition: AddParticipantForm.inc.php:23
PKPTemplateManager\getManager
static & getManager($request=null)
Definition: PKPTemplateManager.inc.php:1239
FormValidator
Class to represent a form validation check.
Definition: FormValidator.inc.php:23
AddParticipantForm
Form for adding a stage participant.
Definition: AddParticipantForm.inc.php:18
AddParticipantForm\__construct
__construct($submission, $stageId, $assignmentId=null)
Definition: AddParticipantForm.inc.php:55
AddParticipantForm\readInputData
readInputData()
Definition: AddParticipantForm.inc.php:200
AddParticipantForm\execute
execute(... $functionParams)
Definition: AddParticipantForm.inc.php:227
AddParticipantForm\initialize
initialize()
Definition: AddParticipantForm.inc.php:85
AddParticipantForm\$_assignmentId
$_assignmentId
Definition: AddParticipantForm.inc.php:29
Form\addCheck
addCheck($formValidator)
Definition: Form.inc.php:395
FormValidatorCSRF
Form validation check to make sure the CSRF token is correct.
Definition: FormValidatorCSRF.inc.php:18
AddParticipantForm\$_possibleRecommendOnlyUserGroupIds
$_possibleRecommendOnlyUserGroupIds
Definition: AddParticipantForm.inc.php:41
AddParticipantForm\$_contextId
$_contextId
Definition: AddParticipantForm.inc.php:47