• Main Page
  • Modules
  • Classes
  • Files
  • File List

controllers/grid/files/fileSignoff/FileSignoffGridHandler.inc.php

00001 <?php
00019 import('controllers.grid.files.SubmissionFilesGridHandler');
00020 import('controllers.grid.files.SignoffStatusFromFileGridColumn');
00021 import('controllers.grid.files.UploaderUserGroupGridColumn');
00022 
00023 class FileSignoffGridHandler extends SubmissionFilesGridHandler {
00025    var $_symbolic;
00026 
00034    function FileSignoffGridHandler($dataProvider, $stageId, $symbolic, $capabilities) {
00035       $this->_symbolic = $symbolic;
00036       parent::SubmissionFilesGridHandler($dataProvider, $stageId, $capabilities);
00037    }
00038 
00039    //
00040    // Implement template methods from PKPHandler
00041    //
00045    function initialize(&$request) {
00046       parent::initialize($request);
00047       $currentUser =& $request->getUser();
00048       $monograph =& $this->getMonograph();
00049 
00050       $stageAssignmentDao = & DAORegistry::getDAO('StageAssignmentDAO'); /* @var $stageAssignmentDao StageAssignmentDAO */
00051       $userGroupDao =& DAORegistry::getDAO('UserGroupDAO'); /* @var $userGroupDao UserGroupDAO */
00052 
00053       // Set up the roles we may include as columns
00054       $roles = array(
00055          ROLE_ID_PRESS_MANAGER => 'user.role.manager',
00056          ROLE_ID_SERIES_EDITOR => 'user.role.seriesEditor',
00057          ROLE_ID_PRESS_ASSISTANT => 'user.role.pressAssistant'
00058       );
00059 
00060       // Get all the uploader user group id's
00061       $uploaderUserGroupIds = array();
00062       $dataElements =& $this->getGridDataElements($request);
00063       foreach ($dataElements as $id => $rowElement) {
00064          $submissionFile =& $rowElement['submissionFile'];
00065          $uploaderUserGroupIds[] = $submissionFile->getUserGroupId();
00066       }
00067       $uploaderUserGroupIds = array_unique($uploaderUserGroupIds);
00068 
00069       $userGroupIds = array();
00070       foreach ($roles as $roleId => $roleName) {
00071          $userIds = array();
00072          $assignments =& $stageAssignmentDao->getBySubmissionAndRoleId($monograph->getId(), $roleId, $this->getStageId());
00073 
00074          // Only include a role column if there is at least one user assigned from that role to this stage.
00075          if (!$assignments->wasEmpty()) {
00076             while ($assignment =& $assignments->next()) {
00077                $userIds[] = $assignment->getUserId();
00078                $userGroupIds[] = $assignment->getUserGroupId();
00079                unset($assignment);
00080             }
00081 
00082             $userIds = array_unique($userIds);
00083             $this->addColumn(
00084                new SignoffStatusFromFileGridColumn(
00085                   'role-' . $roleId,
00086                   $roleName,
00087                   null,
00088                   $this->getSymbolic(),
00089                   $userIds,
00090                   $this->getRequestArgs(),
00091                   in_array($currentUser->getId(), $userIds),
00092                   array('hoverTitle', true)
00093                )
00094             );
00095          }
00096          unset($assignments);
00097       }
00098 
00099       // Add a column for uploader User Groups not present in the previous groups
00100       $uploaderUserGroupIds = array_diff($uploaderUserGroupIds, array_unique($userGroupIds));
00101       $userGroupDao =& DAORegistry::getDAO('UserGroupDAO');
00102       foreach ($uploaderUserGroupIds as $userGroupId) {
00103          $userGroup =& $userGroupDao->getById($userGroupId);
00104          assert(is_a($userGroup, 'UserGroup'));
00105          $this->addColumn(new UploaderUserGroupGridColumn($userGroup));
00106          unset($userGroup);
00107       }
00108    }
00109 
00110    //
00111    // Getter/Setters
00112    //
00117    function getSymbolic() {
00118       return $this->_symbolic;
00119    }
00120 
00121 
00122    //
00123    // Public Methods
00124    //
00130    function signOffFile($args, &$request) {
00131       // Retrieve the file to be signed off.
00132       $fileId = (int)$request->getUserVar('fileId');
00133 
00134       // Make sure that the file revision is in the grid.
00135       $submissionFiles =& $this->getGridDataElements($request);
00136       if (!isset($submissionFiles[$fileId])) fatalError('Invalid file id!');
00137       assert(isset($submissionFiles[$fileId]['submissionFile']));
00138       $submissionFile =& $submissionFiles[$fileId]['submissionFile'];
00139       assert(is_a($submissionFile, 'SubmissionFile'));
00140 
00141       // Retrieve the user.
00142       $user =& $request->getUser();
00143 
00144       // Insert or update the sign off corresponding
00145       // to this file revision.
00146       $signoffDao =& DAORegistry::getDAO('SignoffDAO'); /* @var $signoffDao SignoffDAO */
00147       $signoff =& $signoffDao->build(
00148          $this->getSymbolic(), ASSOC_TYPE_MONOGRAPH_FILE, $submissionFile->getFileId(), $user->getId()
00149       );
00150       $signoff->setDateCompleted(Core::getCurrentDate());
00151       $signoffDao->updateObject($signoff);
00152 
00153       $this->setupTemplate();
00154       $user =& $request->getUser();
00155       NotificationManager::createTrivialNotification($user->getId(), NOTIFICATION_TYPE_SUCCESS, array('contents' => __('notification.signedFile')));
00156 
00157       return DAO::getDataChangedEvent($fileId);
00158    }
00159 }
00160 
00161 ?>

Generated on Mon Sep 17 2012 13:58:55 for Open Monograph Press by  doxygen 1.7.1