00001 <?php
00002
00015
00016 import('lib.pkp.classes.controllers.grid.CategoryGridHandler');
00017
00018
00019 import('controllers.grid.files.signoff.SignoffFilesGridCategoryRow');
00020 import('controllers.grid.files.signoff.SignoffGridRow');
00021 import('controllers.grid.files.signoff.SignoffGridCellProvider');
00022 import('controllers.grid.files.signoff.SignoffFilesGridCellProvider');
00023
00024
00025 import('lib.pkp.classes.linkAction.request.AjaxModal');
00026
00027 class SignoffFilesGridHandler extends CategoryGridHandler {
00028
00029 var $_stageId;
00030
00031
00032 var $_symbolic;
00033
00034
00035 var $_fileStage;
00036
00037
00038 var $_eventType;
00039
00040
00041 var $_assocType;
00042
00043
00044 var $_assocId;
00045
00046
00050 function SignoffFilesGridHandler($stageId, $fileStage, $symbolic, $eventType, $assocType = null, $assocId = null) {
00051 $this->_stageId = $stageId;
00052 $this->_fileStage = $fileStage;
00053 $this->_symbolic = $symbolic;
00054 $this->_eventType = $eventType;
00055 $this->_assocType = $assocType;
00056 $this->_assocId = $assocId;
00057
00058 $this->addRoleAssignment(
00059 array(ROLE_ID_PRESS_MANAGER, ROLE_ID_SERIES_EDITOR, ROLE_ID_PRESS_ASSISTANT),
00060 array(
00061 'fetchGrid', 'fetchCategory', 'fetchRow', 'returnFileRow', 'returnSignoffRow',
00062 'addAuditor', 'saveAddAuditor', 'getAuditorAutocomplete',
00063 'signOffsignOff', 'deleteSignOffSignOff', 'deleteSignoff', 'viewLibrary',
00064 'editReminder', 'sendReminder'
00065 )
00066 );
00067 parent::CategoryGridHandler();
00068 }
00069
00070
00071
00072
00073
00080 function authorize(&$request, $args, $roleAssignments) {
00081 import('classes.security.authorization.OmpWorkflowStageAccessPolicy');
00082 $this->addPolicy(new OmpWorkflowStageAccessPolicy($request, $args, $roleAssignments, 'monographId', $this->getStageId()));
00083
00084
00085 if ($request->getUserVar('signoffId')) {
00086 import('classes.security.authorization.OmpSignoffAccessPolicy');
00087 $this->addPolicy(new OmpSignoffAccessPolicy($request, $args, $roleAssignments, SIGNOFF_ACCESS_MODIFY, $this->getStageId()));
00088 }
00089
00090
00091 if ($request->getUserVar('publicationFormatId')) {
00092 import('classes.security.authorization.internal.PublicationFormatRequiredPolicy');
00093 $this->addPolicy(new PublicationFormatRequiredPolicy($request, $args));
00094 }
00095
00096 return parent::authorize($request, $args, $roleAssignments);
00097 }
00098
00099
00100
00101
00102
00107 function initialize(&$request) {
00108 parent::initialize($request);
00109
00110 AppLocale::requireComponents(
00111 LOCALE_COMPONENT_PKP_COMMON,
00112 LOCALE_COMPONENT_APPLICATION_COMMON,
00113 LOCALE_COMPONENT_PKP_SUBMISSION,
00114 LOCALE_COMPONENT_OMP_EDITOR,
00115 LOCALE_COMPONENT_OMP_SUBMISSION
00116 );
00117
00118 $monograph =& $this->getMonograph();
00119
00120
00121 import('classes.monograph.MonographFile');
00122
00123
00124
00125 import('controllers.api.file.linkAction.AddFileLinkAction');
00126 $this->addAction(new AddFileLinkAction(
00127 $request, $monograph->getId(),
00128 $this->getStageId(),
00129 array(ROLE_ID_PRESS_MANAGER, ROLE_ID_SERIES_EDITOR, ROLE_ID_PRESS_ASSISTANT),
00130 $this->getFileStage(),
00131 $this->getAssocType(), $this->getAssocId()
00132 ));
00133
00134
00135 $user =& $request->getUser();
00136 $signoffDao =& DAORegistry::getDAO('MonographFileSignoffDAO');
00137 $signoffFactory =& $signoffDao->getAllByMonograph($monograph->getId(), $this->getSymbolic(), $user->getId(), null, true);
00138 if (!$signoffFactory->wasEmpty()) {
00139 import('controllers.api.signoff.linkAction.AddSignoffFileLinkAction');
00140 $this->addAction(new AddSignoffFileLinkAction(
00141 $request, $monograph->getId(),
00142 $this->getStageId(), $this->getSymbolic(), null,
00143 __('submission.upload.signoff'), __('submission.upload.signoff')));
00144 }
00145
00146 $router =& $request->getRouter();
00147
00148
00149 $submissionFileDao =& DAORegistry::getDAO('SubmissionFileDAO');
00150 $monographFiles =& $submissionFileDao->getLatestRevisions($monograph->getId(), $this->getFileStage());
00151
00152
00153
00154 if (!empty($monographFiles)) {
00155 $this->addAction(new LinkAction(
00156 'addAuditor',
00157 new AjaxModal(
00158 $router->url($request, null, null, 'addAuditor', null, $this->getRequestArgs()),
00159 __('editor.monograph.addAuditor'),
00160 'modal_add_user'
00161 ),
00162 __('editor.monograph.addAuditor'),
00163 'add_user'
00164 ));
00165 }
00166
00167
00168
00169
00170 $userIds = $this->_getSignoffCapableUsersId();
00171
00172
00173 $this->addColumn(
00174 new GridColumn(
00175 'name',
00176 'common.file',
00177 null,
00178 'controllers/grid/gridCell.tpl',
00179 new SignoffGridCellProvider($monograph->getId(), $this->getStageId()),
00180 array('alignment' => COLUMN_ALIGNMENT_LEFT, 'width' => 60)
00181 )
00182 );
00183
00184
00185 import('controllers.grid.files.SignoffOnSignoffGridColumn');
00186 $this->addColumn(new SignoffOnSignoffGridColumn('common.considered', $userIds, $this->getRequestArgs(), array('hoverTitle' => true)));
00187
00188
00189
00190
00191 import('lib.pkp.classes.controllers.grid.GridColumn');
00192 import('lib.pkp.classes.controllers.grid.NullGridCellProvider');
00193 $this->addColumn(new GridColumn(
00194 'approved',
00195 'editor.signoff.approved', null, 'controllers/grid/gridCell.tpl',
00196 new NullGridCellProvider())
00197 );
00198
00199
00200 $this->setEmptyRowText('grid.noFiles');
00201 }
00202
00203
00204
00205
00206
00211 function &getMonograph() {
00212 return $this->getAuthorizedContextObject(ASSOC_TYPE_MONOGRAPH);
00213 }
00214
00215
00220 function getStageId() {
00221 return $this->_stageId;
00222 }
00223
00224
00229 function getSymbolic() {
00230 return $this->_symbolic;
00231 }
00232
00233
00237 function getFileStage() {
00238 return $this->_fileStage;
00239 }
00240
00241
00245 function getEventType() {
00246 return $this->_eventType;
00247 }
00248
00249
00253 function getAssocType() {
00254 return $this->_assocType;
00255 }
00256
00257
00261 function setAssocId($assocId) {
00262 $this->_assocId = $assocId;
00263 }
00264
00265
00269 function getAssocId() {
00270 return $this->_assocId;
00271 }
00272
00277 function &getPublicationFormat() {
00278 return $this->getAuthorizedContextObject(ASSOC_TYPE_PUBLICATION_FORMAT);
00279 }
00280
00281
00285 function getRequestArgs() {
00286 $monograph =& $this->getMonograph();
00287 $signoff =& $this->getAuthorizedContextObject(ASSOC_TYPE_SIGNOFF);
00288 $args = array_merge(
00289 parent::getRequestArgs(),
00290 array('monographId' => $monograph->getId(),
00291 'stageId' => $this->getStageId())
00292 );
00293
00294 if (is_a($signoff, 'Signoff')) {
00295 $args['signoffId'] = $signoff->getId();
00296 }
00297
00298 return $args;
00299 }
00300
00301
00305 function &loadData(&$request, $filter) {
00306
00307 $monograph =& $this->getMonograph();
00308 $submissionFileDao =& DAORegistry::getDAO('SubmissionFileDAO');
00309 if ($this->getAssocType() && $this->getAssocId()) {
00310 $monographFiles =& $submissionFileDao->getLatestRevisionsByAssocId(
00311 $this->getAssocType(), $this->getAssocId(),
00312 $monograph->getId(), $this->getFileStage()
00313 );
00314 } else {
00315 $monographFiles =& $submissionFileDao->getLatestRevisions($monograph->getId(), $this->getFileStage());
00316 }
00317
00318
00319
00320 $data = array();
00321 foreach ($monographFiles as $monographFile) {
00322 $data[$monographFile->getFileId()] = $monographFile;
00323 }
00324 return $data;
00325 }
00326
00327
00328
00329
00330
00335 function &getCategoryRowInstance() {
00336 $row = new SignoffFilesGridCategoryRow($this->getStageId());
00337 $monograph =& $this->getMonograph();
00338 $row->setCellProvider(new SignoffFilesGridCellProvider($monograph->getId(), $this->getStageId()));
00339 $row->addFlag('gridRowStyle', true);
00340 return $row;
00341 }
00342
00343
00350 function getCategoryData(&$monographFile) {
00351 $monographFileSignoffDao =& DAORegistry::getDAO('MonographFileSignoffDAO');
00352 $signoffFactory =& $monographFileSignoffDao->getAllBySymbolic($this->getSymbolic(), $monographFile->getFileId());
00353 $signoffs = $signoffFactory->toAssociativeArray();
00354 return $signoffs;
00355 }
00356
00360 function getCategoryRowIdParameterName() {
00361 return 'fileId';
00362 }
00363
00364
00369 function &getRowInstance() {
00370 $row = new SignoffGridRow($this->getStageId());
00371 return $row;
00372 }
00373
00374
00375
00376
00377
00384 function addAuditor($args, &$request) {
00385
00386 $monograph =& $this->getAuthorizedContextObject(ASSOC_TYPE_MONOGRAPH);
00387
00388
00389 $router =& $request->getRouter();
00390 $autocompleteUrl = $router->url($request, null, null, 'getAuditorAutocomplete', null, $this->getRequestArgs());
00391 $templateMgr =& TemplateManager::getManager();
00392 $templateMgr->assign('autocompleteUrl', $autocompleteUrl);
00393
00394 import('controllers.grid.files.signoff.form.FileAuditorForm');
00395 $publicationFormat =& $this->getPublicationFormat();
00396 $publicationFormatId = null;
00397 if (is_a($publicationFormat, 'PublicationFormat')) {
00398 $publicationFormatId = $publicationFormat->getId();
00399 }
00400 $auditorForm = new FileAuditorForm($monograph, $this->getFileStage(), $this->getStageId(), $this->getSymbolic(), $this->getEventType(), $this->getAssocId(), $publicationFormatId);
00401 if ($auditorForm->isLocaleResubmit()) {
00402 $auditorForm->readInputData();
00403 } else {
00404 $auditorForm->initData($args, $request);
00405 }
00406
00407 $json = new JSONMessage(true, $auditorForm->fetch($request));
00408 return $json->getString();
00409 }
00410
00411
00418 function saveAddAuditor($args, &$request) {
00419
00420 $monograph =& $this->getAuthorizedContextObject(ASSOC_TYPE_MONOGRAPH);
00421
00422
00423 import('controllers.grid.files.signoff.form.FileAuditorForm');
00424 $auditorForm = new FileAuditorForm($monograph, $this->getFileStage(), $this->getStageId(), $this->getSymbolic(), $this->getEventType(), $this->getAssocId());
00425 $auditorForm->readInputData();
00426 if ($auditorForm->validate()) {
00427 $auditorForm->execute($request);
00428
00429
00430 $currentUser =& $request->getUser();
00431 NotificationManager::createTrivialNotification($currentUser->getId(), NOTIFICATION_TYPE_SUCCESS, array('contents' => __('notification.addedAuditor')));
00432
00433
00434 return DAO::getDataChangedEvent();
00435 }
00436
00437 $json = new JSONMessage(false);
00438 return $json->getString();
00439 }
00440
00441
00448 function getAuditorAutocomplete($args, &$request) {
00449
00450 $monograph =& $this->getAuthorizedContextObject(ASSOC_TYPE_MONOGRAPH);
00451
00452
00453 $stageAssignmentDao = & DAORegistry::getDAO('StageAssignmentDAO');
00454 $stageUsers = $stageAssignmentDao->getBySubmissionAndStageId($monograph->getId(), $this->getStageId());
00455
00456 $itemList = array();
00457 $userGroupDao =& DAORegistry::getDAO('UserGroupDAO');
00458 $userDao =& DAORegistry::getDAO('UserDAO');
00459 $term =& $request->getUserVar('term');
00460 while($stageUser =& $stageUsers->next()) {
00461 $userGroup =& $userGroupDao->getById($stageUser->getUserGroupId());
00462 $user =& $userDao->getById($stageUser->getUserId());
00463 $term = preg_quote($term, '/');
00464 if ($term == '' || preg_match('/' . $term .'/i', $user->getFullName()) || preg_match('/' . $term .'/i', $userGroup->getLocalizedName())) {
00465 $itemList[] = array(
00466 'label' => sprintf('%s (%s)', $user->getFullName(), $userGroup->getLocalizedName()),
00467 'value' => $user->getId() . '-' . $stageUser->getUserGroupId()
00468 );
00469 }
00470 unset($stageUser, $userGroup);
00471 }
00472
00473 if (count($itemList) == 0) {
00474 return $this->noAutocompleteResults();
00475 }
00476
00477 $json = new JSONMessage(true, $itemList);
00478 return $json->getString();
00479 }
00480
00481
00488 function returnSignoffRow($args, &$request) {
00489 $signoff =& $this->getAuthorizedContextObject(ASSOC_TYPE_SIGNOFF);
00490
00491 if($signoff) {
00492 return DAO::getDataChangedEvent();
00493 } else {
00494 $json = new JSONMessage(false, __('common.uploadFailed'));
00495 return $json->getString();
00496 }
00497 }
00498
00499
00506 function deleteSignoff($args, &$request) {
00507 $signoff =& $this->getAuthorizedContextObject(ASSOC_TYPE_SIGNOFF);
00508
00509 if($signoff && !$signoff->getDateCompleted()) {
00510
00511 $signoffUserId = $signoff->getUserId();
00512 if ($signoff->getAssocType() == ASSOC_TYPE_MONOGRAPH_FILE) {
00513 $fileId = $signoff->getAssocId();
00514 }
00515 $submissionFileDao =& DAORegistry::getDAO('SubmissionFileDAO');
00516 $monographFile =& $submissionFileDao->getLatestRevision($fileId);
00517
00518
00519 $signoffDao =& DAORegistry::getDAO('SignoffDAO');
00520 $signoffDao->deleteObjectById($signoff->getId());
00521
00522
00523 $user =& $request->getUser();
00524 NotificationManager::createTrivialNotification($user->getId(), NOTIFICATION_TYPE_SUCCESS, array('contents' => __('notification.removedAuditor')));
00525
00526
00527 $notificationMgr = new NotificationManager();
00528 $notificationMgr->updateAuditorRequestNotification($signoff, $request, true);
00529
00530
00531 $notificationMgr->updateSignoffNotification($signoff, $request);
00532
00533
00534 import('classes.log.MonographFileLog');
00535 import('classes.log.MonographFileEventLogEntry');
00536 $userDao =& DAORegistry::getDAO('UserDAO');
00537 $signoffUser =& $userDao->getById($signoffUserId);
00538
00539 if (isset($signoffUser) && isset($monographFile)) {
00540 MonographFileLog::logEvent($request, $monographFile, MONOGRAPH_LOG_FILE_AUDITOR_CLEAR, 'submission.event.fileAuditorCleared', array('file' => $monographFile->getOriginalFileName(), 'name' => $signoffUser->getFullName(), 'username' => $signoffUser->getUsername()));
00541 }
00542 return DAO::getDataChangedEvent($signoff->getId(), $signoff->getAssocId());
00543 } else {
00544 $json = new JSONMessage(false, 'manager.setup.errorDeletingItem');
00545 return $json->getString();
00546 }
00547 }
00548
00549
00555 function signOffsignOff($args, &$request) {
00556 $rowSignoff =& $this->getAuthorizedContextObject(ASSOC_TYPE_SIGNOFF);
00557 if (!$rowSignoff) fatalError('Invalid Signoff given');
00558
00559 $user =& $request->getUser();
00560 $signoffDao =& DAORegistry::getDAO('SignoffDAO');
00561 $signoff =& $signoffDao->build('SIGNOFF_SIGNOFF', ASSOC_TYPE_SIGNOFF, $rowSignoff->getId(), $user->getId());
00562 $signoff->setDateCompleted(Core::getCurrentDate());
00563 $signoffDao->updateObject($signoff);
00564
00565
00566 $notificationMgr = new NotificationManager();
00567
00568
00569
00570 $notificationMgr->deleteCopyeditRequestNotification($rowSignoff, &$request);
00571
00572
00573 import('classes.log.MonographFileLog');
00574 import('classes.log.MonographFileEventLogEntry');
00575 $submissionFileDao =& DAORegistry::getDAO('SubmissionFileDAO');
00576 $monographFile =& $submissionFileDao->getLatestRevision($rowSignoff->getAssocId());
00577 if (isset($monographFile)) {
00578 MonographFileLog::logEvent($request, $monographFile, MONOGRAPH_LOG_FILE_SIGNOFF_SIGNOFF, 'submission.event.signoffSignoff', array('file' => $monographFile->getOriginalFileName(), 'name' => $user->getFullName(), 'username' => $user->getUsername()));
00579 }
00580
00581 return DAO::getDataChangedEvent($rowSignoff->getId(), $rowSignoff->getAssocId());
00582 }
00583
00590 function deleteSignOffSignOff($args, &$request) {
00591 $rowSignoff =& $this->getAuthorizedContextObject(ASSOC_TYPE_SIGNOFF);
00592 if (!$rowSignoff) fatalError('Invalid Signoff given');
00593
00594 $user =& $request->getUser();
00595 $signoffDao =& DAORegistry::getDAO('SignoffDAO');
00596 $signoffOnSignoffFactory = $signoffDao->getAllByAssocType(ASSOC_TYPE_SIGNOFF, $rowSignoff->getId());
00597 $signoffOnSignoff =& $signoffOnSignoffFactory->next();
00598 if (!$signoffOnSignoff) fatalError('Invalid Signoff given');
00599
00600 $signoffDao->deleteObject($signoffOnSignoff);
00601
00602 return DAO::getDataChangedEvent($rowSignoff->getId(), $rowSignoff->getAssocId());
00603 }
00604
00605
00612 function viewLibrary($args, &$request) {
00613
00614 $templateMgr =& TemplateManager::getManager();
00615 $templateMgr->assign('canEdit', false);
00616 return $templateMgr->fetchJson('controllers/tab/settings/library.tpl');
00617 }
00618
00625 function editReminder($args, &$request) {
00626
00627 $signoff =& $this->getAuthorizedContextObject(ASSOC_TYPE_SIGNOFF);
00628 $monograph =& $this->getAuthorizedContextObject(ASSOC_TYPE_MONOGRAPH);
00629
00630
00631 import('controllers.grid.files.fileSignoff.form.AuditorReminderForm');
00632 $publicationFormat =& $this->getPublicationFormat();
00633 $publicationFormatId = null;
00634 if (is_a($publicationFormat, 'PublicationFormat')) {
00635 $publicationFormatId = $publicationFormat->getId();
00636 }
00637 $auditorReminderForm = new AuditorReminderForm($signoff, $monograph->getId(), $this->getStageId(), $publicationFormatId);
00638 $auditorReminderForm->initData($args, $request);
00639
00640
00641 $json = new JSONMessage(true, $auditorReminderForm->fetch($request));
00642 return $json->getString();
00643 }
00644
00651 function sendReminder($args, &$request) {
00652 $signoff =& $this->getAuthorizedContextObject(ASSOC_TYPE_SIGNOFF);
00653 $monograph =& $this->getAuthorizedContextObject(ASSOC_TYPE_MONOGRAPH);
00654
00655
00656 import('controllers.grid.files.fileSignoff.form.AuditorReminderForm');
00657 $publicationFormat =& $this->getPublicationFormat();
00658 $publicationFormatId = null;
00659 if (is_a($publicationFormat, 'PublicationFormat')) {
00660 $publicationFormatId = $publicationFormat->getId();
00661 }
00662 $auditorReminderForm = new AuditorReminderForm($signoff, $monograph->getId(), $this->getStageId(), $publicationFormatId);
00663 $auditorReminderForm->readInputData();
00664 if ($auditorReminderForm->validate()) {
00665 $auditorReminderForm->execute($args, $request);
00666 $json = new JSONMessage(true);
00667
00668
00669 $currentUser =& $request->getUser();
00670 $notificationMgr = new NotificationManager();
00671 $notificationMgr->createTrivialNotification($currentUser->getId(), NOTIFICATION_TYPE_SUCCESS, array('contents' => __('notification.sentNotification')));
00672 } else {
00673 $json = new JSONMessage(false, __('editor.review.reminderError'));
00674 }
00675 return $json->getString();
00676 }
00677
00678
00679
00680
00681
00686 function _getSignoffCapableUsersId() {
00687 $monograph =& $this->getAuthorizedContextObject(ASSOC_TYPE_MONOGRAPH);
00688
00689
00690
00691 $userIds = array();
00692 $stageAssignmentDao = & DAORegistry::getDAO('StageAssignmentDAO');
00693 $seriesEditorAssignments =& $stageAssignmentDao->getBySubmissionAndRoleId($monograph->getId(), ROLE_ID_SERIES_EDITOR, $this->getStageId());
00694 $assistantAssignments =& $stageAssignmentDao->getBySubmissionAndRoleId($monograph->getId(), ROLE_ID_PRESS_ASSISTANT, $this->getStageId());
00695
00696 $allAssignments = array_merge(
00697 $seriesEditorAssignments->toArray(),
00698 $assistantAssignments->toArray()
00699 );
00700
00701 foreach ($allAssignments as $assignment) {
00702 $userIds[] = $assignment->getUserId();
00703 }
00704
00705
00706
00707
00708 $userGroupDao =& DAORegistry::getDAO('UserGroupDAO');
00709 $pressManagerUserGroupsFactory =& $userGroupDao->getByRoleId($monograph->getPressId(), ROLE_ID_PRESS_MANAGER);
00710 while ($userGroup =& $pressManagerUserGroupsFactory->next()) {
00711 $usersFactory =& $userGroupDao->getUsersById($userGroup->getId(), $monograph->getPressId());
00712 while ($user =& $usersFactory->next()) {
00713 $userIds[] = $user->getId();
00714 unset($user);
00715 }
00716 unset($userGroup);
00717 }
00718
00719 return array_unique($userIds);
00720 }
00721 }
00722
00723 ?>