00001 <?php
00002
00015
00016 import('lib.pkp.classes.controllers.grid.CategoryGridHandler');
00017
00018
00019 import('controllers.grid.users.stageParticipant.StageParticipantGridRow');
00020 import('controllers.grid.users.stageParticipant.StageParticipantGridCategoryRow');
00021 import('classes.log.MonographEventLogEntry');
00022
00023 class StageParticipantGridHandler extends CategoryGridHandler {
00027 function StageParticipantGridHandler() {
00028 parent::CategoryGridHandler();
00029
00030 $this->addRoleAssignment(
00031 array(ROLE_ID_PRESS_ASSISTANT),
00032 $peOps = array('fetchGrid', 'fetchCategory', 'fetchRow')
00033 );
00034
00035 $this->addRoleAssignment(
00036 array(ROLE_ID_PRESS_MANAGER, ROLE_ID_SERIES_EDITOR),
00037 array_merge($peOps, array('addParticipant', 'deleteParticipant', 'saveParticipant', 'fetchUserList'))
00038 );
00039 }
00040
00041
00042
00043
00044
00049 function &getMonograph() {
00050 return $this->getAuthorizedContextObject(ASSOC_TYPE_MONOGRAPH);
00051 }
00052
00057 function getStageId() {
00058 return $this->getAuthorizedContextObject(ASSOC_TYPE_WORKFLOW_STAGE);
00059 }
00060
00061
00062
00063
00067 function authorize(&$request, $args, $roleAssignments) {
00068 $stageId = (int) $request->getUserVar('stageId');
00069 import('classes.security.authorization.OmpWorkflowStageAccessPolicy');
00070 $this->addPolicy(new OmpWorkflowStageAccessPolicy($request, $args, $roleAssignments, 'monographId', $stageId));
00071 return parent::authorize($request, $args, $roleAssignments);
00072 }
00073
00079 function _canAdminister() {
00080
00081 return (boolean) array_intersect(
00082 array(ROLE_ID_PRESS_MANAGER, ROLE_ID_SERIES_EDITOR),
00083 $this->getAuthorizedContextObject(ASSOC_TYPE_USER_ROLES)
00084 );
00085 }
00086
00087
00091 function initialize(&$request) {
00092 parent::initialize($request);
00093
00094
00095 AppLocale::requireComponents(
00096 LOCALE_COMPONENT_OMP_EDITOR,
00097 LOCALE_COMPONENT_PKP_USER,
00098 LOCALE_COMPONENT_OMP_DEFAULT_SETTINGS
00099 );
00100
00101
00102 import('controllers.grid.users.stageParticipant.StageParticipantGridCellProvider');
00103 $cellProvider = new StageParticipantGridCellProvider();
00104 $this->addColumn(new GridColumn(
00105 'participants',
00106 null,
00107 null,
00108 'controllers/grid/gridCell.tpl',
00109 $cellProvider
00110 ));
00111
00112
00113
00114 if ($this->_canAdminister()) {
00115 $router =& $request->getRouter();
00116 $this->addAction(
00117 new LinkAction(
00118 'requestAccount',
00119 new AjaxModal(
00120 $router->url($request, null, null, 'addParticipant', null, $this->getRequestArgs()),
00121 __('editor.monograph.addStageParticipant'),
00122 'modal_add_user'
00123 ),
00124 __('common.add'),
00125 'add_user'
00126 )
00127 );
00128 }
00129
00130 $this->setEmptyCategoryRowText('editor.monograph.noneAssigned');
00131 }
00132
00133
00134
00135
00136
00140 function getCategoryData(&$userGroup) {
00141
00142 $monograph =& $this->getMonograph();
00143 $stageId = $this->getStageId();
00144
00145 $stageAssignmentDao =& DAORegistry::getDAO('StageAssignmentDAO');
00146 $stageAssignments =& $stageAssignmentDao->getBySubmissionAndStageId(
00147 $monograph->getId(),
00148 $stageId,
00149 $userGroup->getId()
00150 );
00151
00152 return $stageAssignments->toAssociativeArray();
00153 }
00154
00158 function getIsSubcomponent() {
00159 return true;
00160 }
00161
00165 function &getRowInstance() {
00166 $monograph =& $this->getMonograph();
00167 $row = new StageParticipantGridRow($monograph, $this->getStageId(), $this->_canAdminister());
00168 return $row;
00169 }
00170
00174 function &getCategoryRowInstance() {
00175 $monograph =& $this->getMonograph();
00176 $row = new StageParticipantGridCategoryRow($monograph, $this->getStageId());
00177 return $row;
00178 }
00179
00183 function getCategoryRowIdParameterName() {
00184 return 'userGroupId';
00185 }
00186
00190 function getRequestArgs() {
00191 $monograph =& $this->getMonograph();
00192 return array_merge(
00193 parent::getRequestArgs(),
00194 array('monographId' => $monograph->getId(),
00195 'stageId' => $this->getStageId())
00196 );
00197 }
00198
00202 function loadData($request, $filter) {
00203 $userGroupDao = & DAORegistry::getDAO('UserGroupDAO');
00204 $press =& $request->getPress();
00205 $userGroups =& $userGroupDao->getUserGroupsByStage($press->getId(), $this->getStageId(), false, true);
00206
00207 return $userGroups;
00208 }
00209
00210
00211
00212
00213
00220 function addParticipant($args, &$request) {
00221 $monograph =& $this->getMonograph();
00222 $stageId = $this->getStageId();
00223 $userGroups =& $this->getGridDataElements($request);
00224
00225 import('controllers.grid.users.stageParticipant.form.AddParticipantForm');
00226 $form = new AddParticipantForm($monograph, $stageId, $userGroups);
00227 $form->initData();
00228
00229 $json = new JSONMessage(true, $form->fetch($request));
00230 return $json->getString();
00231 }
00232
00233
00240 function saveParticipant($args, &$request) {
00241 $monograph =& $this->getMonograph();
00242 $stageId = $this->getStageId();
00243 $userGroups =& $this->getGridDataElements($request);
00244
00245 import('controllers.grid.users.stageParticipant.form.AddParticipantForm');
00246 $form = new AddParticipantForm($monograph, $stageId, $userGroups);
00247 $form->readInputData();
00248 if ($form->validate()) {
00249 list($userGroupId, $userId, $stageAssignmentId) = $form->execute();
00250
00251 $notificationMgr = new NotificationManager();
00252
00253
00254 $userGroupDao =& DAORegistry::getDAO('UserGroupDAO');
00255 $stageAssignmentDao =& DAORegistry::getDAO('StageAssignmentDAO');
00256
00257 $userGroup = $userGroupDao->getById($userGroupId);
00258 if ($userGroup->getRoleId() == ROLE_ID_PRESS_MANAGER) {
00259
00260 $stages = $this->_getStages();
00261 foreach ($stages as $workingStageId) {
00262 $notificationMgr->updateEditorAssignmentNotification($monograph, $workingStageId, $request);
00263
00264 if ($stageAssignmentDao->editorAssignedToStage($monograph->getId(), $stageId)) {
00265 $notificationMgr->deleteEditorRequiredTaskNotification($monograph, $request);
00266 }
00267 }
00268 }
00269
00270
00271 $user =& $request->getUser();
00272 $notificationMgr->createTrivialNotification($user->getId(), NOTIFICATION_TYPE_SUCCESS, array('contents' => __('notification.addedStageParticipant')));
00273
00274
00275 $userDao =& DAORegistry::getDAO('UserDAO');
00276 $assignedUser =& $userDao->getById($userId);
00277 import('classes.log.MonographLog');
00278 MonographLog::logEvent($request, $monograph, MONOGRAPH_LOG_ADD_PARTICIPANT, 'submission.event.participantAdded', array('name' => $assignedUser->getFullName(), 'username' => $assignedUser->getUsername(), 'userGroupName' => $userGroup->getLocalizedName()));
00279
00280 return DAO::getDataChangedEvent($userGroupId);
00281 } else {
00282 $json = new JSONMessage(true, $form->fetch($request));
00283 return $json->getString();
00284 }
00285 }
00286
00293 function deleteParticipant($args, &$request) {
00294 $monograph =& $this->getMonograph();
00295 $stageId = $this->getStageId();
00296 $assignmentId = (int) $request->getUserVar('assignmentId');
00297
00298 $stageAssignmentDao =& DAORegistry::getDAO('StageAssignmentDAO');
00299 $stageAssignment =& $stageAssignmentDao->getById($assignmentId);
00300 if (!$stageAssignment || $stageAssignment->getSubmissionId() != $monograph->getId()) {
00301 fatalError('Invalid Assignment');
00302 }
00303
00304
00305 $userId = $stageAssignment->getUserId();
00306 $signoffDao =& DAORegistry::getDAO('SignoffDAO');
00307 $submissionFileDao =& DAORegistry::getDAO('SubmissionFileDAO');
00308
00309 $signoffsFactory =& $signoffDao->getByUserId($userId);
00310 while($signoff =& $signoffsFactory->next()) {
00311 if (($signoff->getSymbolic() != 'SIGNOFF_COPYEDITING' &&
00312 $signoff->getSymbolic() != 'SIGNOFF_PROOFING') ||
00313 $signoff->getAssocType() != ASSOC_TYPE_MONOGRAPH_FILE ||
00314 $signoff->getDateCompleted()) continue;
00315 $monographFileId = $signoff->getAssocId();
00316 $monographFile =& $submissionFileDao->getLatestRevision($monographFileId, null, $stageAssignment->getSubmissionId());
00317 if (is_a($monographFile, 'MonographFile')) {
00318 $signoffDao->deleteObject($signoff);
00319 }
00320 }
00321
00322
00323 $stageAssignmentDao->deleteObject($stageAssignment);
00324
00325
00326
00327 $notificationMgr = new NotificationManager();
00328 $stages = $this->_getStages();
00329 foreach ($stages as $workingStageId) {
00330
00331
00332 $stageAssignmentDao->deleteByAll($monograph->getId(), $workingStageId, $stageAssignment->getUserGroupId(), $stageAssignment->getUserId());
00333
00334
00335 $notificationMgr->updateEditorAssignmentNotification($monograph, $workingStageId, $request);
00336 }
00337
00338
00339 $userDao =& DAORegistry::getDAO('UserDAO');
00340 $assignedUser =& $userDao->getById($userId);
00341 $userGroupDao =& DAORegistry::getDAO('UserGroupDAO');
00342 $userGroup =& $userGroupDao->getById($stageAssignment->getUserGroupId());
00343 import('classes.log.MonographLog');
00344 MonographLog::logEvent($request, $monograph, MONOGRAPH_LOG_REMOVE_PARTICIPANT, 'submission.event.participantRemoved', array('name' => $assignedUser->getFullName(), 'username' => $assignedUser->getUsername(), 'userGroupName' => $userGroup->getLocalizedName()));
00345
00346
00347 return DAO::getDataChangedEvent($stageAssignment->getUserGroupId());
00348 }
00349
00356 function fetchUserList($args, &$request) {
00357 $monograph =& $this->getAuthorizedContextObject(ASSOC_TYPE_MONOGRAPH);
00358 $stageId = $this->getAuthorizedContextObject(ASSOC_TYPE_WORKFLOW_STAGE);
00359
00360 $userGroupId = (int) $request->getUserVar('userGroupId');
00361
00362 $userStageAssignmentDao =& DAORegistry::getDAO('UserStageAssignmentDAO');
00363 $users =& $userStageAssignmentDao->getUsersNotAssignedToStageInUserGroup($monograph->getId(), $stageId, $userGroupId);
00364
00365 $userGroupDao =& DAORegistry::getDAO('UserGroupDAO');
00366 $userGroup =& $userGroupDao->getById($userGroupId);
00367 $roleId = $userGroup->getRoleId();
00368
00369 $seriesId = $monograph->getSeriesId();
00370 $pressId = $monograph->getPressId();
00371
00372 $filterSeriesEditors = false;
00373 if ($roleId == ROLE_ID_SERIES_EDITOR && $seriesId) {
00374 $seriesEditorsDao =& DAORegistry::getDAO('SeriesEditorsDAO');
00375
00376 $filterSeriesEditors = true;
00377 }
00378
00379 $userList = array();
00380 while($user =& $users->next()) {
00381 if ($filterSeriesEditors && !$seriesEditorsDao->editorExists($pressId, $seriesId, $user->getId())) {
00382 unset($user);
00383 continue;
00384 }
00385 $userList[$user->getId()] = $user->getFullName();
00386 unset($user);
00387 }
00388
00389 if (count($userList) == 0) {
00390 $userList[0] = __('common.noMatches');
00391 }
00392
00393 $json = new JSONMessage(true, $userList);
00394 return $json->getString();
00395 }
00396
00397
00398
00399
00400
00405 function _getStages() {
00406 return array(WORKFLOW_STAGE_ID_SUBMISSION,
00407 WORKFLOW_STAGE_ID_INTERNAL_REVIEW,
00408 WORKFLOW_STAGE_ID_EXTERNAL_REVIEW,
00409 WORKFLOW_STAGE_ID_EDITING,
00410 WORKFLOW_STAGE_ID_PRODUCTION);
00411 }
00412 }
00413
00414 ?>