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

controllers/grid/submissions/SubmissionsListGridCellProvider.inc.php

00001 <?php
00002 
00015 import('lib.pkp.classes.controllers.grid.DataObjectGridCellProvider');
00016 
00017 class SubmissionsListGridCellProvider extends DataObjectGridCellProvider {
00018 
00020    var $_authorizedRoles;
00021 
00025    function SubmissionsListGridCellProvider($authorizedRoles = null) {
00026       if ($authorizedRoles) {
00027          $this->_authorizedRoles = $authorizedRoles;
00028       }
00029 
00030       parent::DataObjectGridCellProvider();
00031    }
00032 
00033 
00034    //
00035    // Getters and setters.
00036    //
00041    function getAuthorizedRoles() {
00042       return $this->_authorizedRoles;
00043    }
00044 
00045 
00046    //
00047    // Public functions.
00048    //
00054    function getCellState(&$row, &$column) {
00055       return '';
00056    }
00057 
00058 
00065    function getCellActions(&$request, &$row, &$column, $position = GRID_ACTION_POSITION_DEFAULT) {
00066       if ( $column->getId() == 'title' ) {
00067          $monograph =& $row->getData();
00068 
00069          if (is_a($monograph, 'ReviewerSubmission')) {
00070             // Reviewer: Add a review link action.
00071             return array($this->_getCellLinkAction($request, 'reviewer', 'submission', $monograph));
00072          } else {
00073             // Get the right page and operation (authordashboard or workflow).
00074             list($page, $operation) = SubmissionsListGridCellProvider::getPageAndOperationByUserRoles($request, $monograph);
00075 
00076             // Return redirect link action.
00077             return array($this->_getCellLinkAction($request, $page, $operation, $monograph));
00078          }
00079 
00080          // This should be unreachable code.
00081          assert(false);
00082       }
00083       return parent::getCellActions($request, $row, $column, $position);
00084    }
00085 
00086    //
00087    // Template methods from GridCellProvider
00088    //
00096    function getTemplateVarsFromRowColumn(&$row, $column) {
00097       $monograph =& $row->getData();
00098       $columnId = $column->getId();
00099       assert(is_a($monograph, 'DataObject') && !empty($columnId));
00100 
00101       $pressId = $monograph->getPressId();
00102       $pressDao = DAORegistry::getDAO('PressDAO');
00103       $press = $pressDao->getById($pressId);
00104 
00105       switch ($columnId) {
00106          case 'title':
00107             return array('label' => '');
00108             break;
00109          case 'press':
00110             return array('label' => $press->getLocalizedName());
00111             break;
00112          case 'author':
00113             return array('label' => $monograph->getAuthorString(true));
00114             break;
00115          case 'dateAssigned':
00116             assert(is_a($monograph, 'ReviewerSubmission'));
00117             $dateAssigned = strftime(Config::getVar('general', 'date_format_short'), strtotime($monograph->getDateAssigned()));
00118             if ( empty($dateAssigned) ) $dateAssigned = '--';
00119             return array('label' => $dateAssigned);
00120             break;
00121          case 'dateDue':
00122             $dateDue = strftime(Config::getVar('general', 'date_format_short'), strtotime($monograph->getDateDue()));
00123             if ( empty($dateDue) ) $dateDue = '--';
00124             return array('label' => $dateDue);
00125             break;
00126          case 'status':
00127             $stageId = $monograph->getStageId();
00128             switch ($stageId) {
00129                case WORKFLOW_STAGE_ID_SUBMISSION: default:
00130                   $returner = array('label' => __('submission.status.submission'));
00131                   break;
00132                case WORKFLOW_STAGE_ID_INTERNAL_REVIEW:
00133                   $returner = array('label' => __('submission.status.review'));
00134                   break;
00135                case WORKFLOW_STAGE_ID_EXTERNAL_REVIEW:
00136                   $returner = array('label' => __('submission.status.review'));
00137                   break;
00138                case WORKFLOW_STAGE_ID_EDITING:
00139                   $returner = array('label' => __('submission.status.editorial'));
00140                   break;
00141                case WORKFLOW_STAGE_ID_PRODUCTION:
00142                   $returner = array('label' => __('submission.status.production'));
00143                   break;
00144             }
00145 
00146             // Handle special cases.
00147             $stageAssignmentDao =& DAORegistry::getDAO('StageAssignmentDAO');
00148             if ($monograph->getSubmissionProgress() > 0 && $monograph->getSubmissionProgress() <= 3) {
00149                // Submission process not completed.
00150                $returner = array('label' => __('submissions.incomplete'));
00151             } elseif (!$stageAssignmentDao->editorAssignedToStage($monograph->getId())) {
00152                // No editor assigned to any submission stages.
00153                $returner = array('label' => __('submission.status.unassigned'));
00154             }
00155 
00156             return $returner;
00157       }
00158    }
00159 
00160 
00161    //
00162    // Public static methods
00163    //
00172    function getPageAndOperationByUserRoles(&$request, &$monograph, $userId = null) {
00173       if ($userId == null) {
00174          $user =& $request->getUser();
00175       } else {
00176          $userDao =& DAORegistry::getDAO('UserDAO');
00177          $user =& $userDao->getById($userId);
00178          if ($user == null) { // user does not exist
00179             return array();
00180          }
00181       }
00182 
00183       // This method is used to build links in componentes that lists
00184       // monographs from various presses, sometimes. So we need to make sure
00185       // that we are getting the right monograph press (not necessarily the
00186       // current press in request).
00187       $pressId = $monograph->getPressId();
00188 
00189       // If user is enrolled with a press manager user group, let
00190       // him access the workflow pages.
00191       $roleDao =& DAORegistry::getDAO('RoleDAO');
00192       $isPressManager = $roleDao->userHasRole($pressId, $user->getId(), ROLE_ID_PRESS_MANAGER);
00193       if($isPressManager) {
00194          return array('workflow', 'access');
00195       }
00196 
00197       $monographId = $monograph->getId();
00198 
00199       // If user has only author role user groups stage assignments,
00200       // then add an author dashboard link action.
00201       $stageAssignmentDao =& DAORegistry::getDAO('StageAssignmentDAO');
00202       $userGroupDao =& DAORegistry::getDAO('UserGroupDAO');
00203 
00204       $authorUserGroupIds = $userGroupDao->getUserGroupIdsByRoleId(ROLE_ID_AUTHOR);
00205       $stageAssignmentsFactory =& $stageAssignmentDao->getBySubmissionAndStageId($monographId, null, null, $user->getId());
00206 
00207       $authorDashboard = false;
00208       while ($stageAssignment =& $stageAssignmentsFactory->next()) {
00209          if (!in_array($stageAssignment->getUserGroupId(), $authorUserGroupIds)) {
00210             $authorDashboard = false;
00211             break;
00212          }
00213          $authorDashboard = true;
00214          unset($stageAssignment);
00215       }
00216       if ($authorDashboard) {
00217          return array('authorDashboard', 'submission');
00218       } else {
00219          return array('workflow', 'access');
00220       }
00221    }
00222 
00223    //
00224    // Private helper methods.
00225    //
00234    function _getCellLinkAction($request, $page, $operation, &$monograph) {
00235       $router =& $request->getRouter();
00236       $dispatcher =& $router->getDispatcher();
00237 
00238       $title = $monograph->getLocalizedTitle();
00239       if ( empty($title) ) $title = __('common.untitled');
00240 
00241       $pressId = $monograph->getPressId();
00242       $pressDao = DAORegistry::getDAO('PressDAO');
00243       $press = $pressDao->getById($pressId);
00244 
00245       import('lib.pkp.classes.linkAction.request.RedirectAction');
00246 
00247       return new LinkAction(
00248          'itemWorkflow',
00249          new RedirectAction(
00250             $dispatcher->url(
00251                $request, ROUTE_PAGE,
00252                $press->getPath(),
00253                $page, $operation,
00254                $monograph->getId()
00255             )
00256          ),
00257          $title
00258       );
00259    }
00260 }
00261 
00262 ?>

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