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

controllers/grid/files/SignoffStatusFromFileGridColumn.inc.php

00001 <?php
00002 
00016 import('controllers.grid.files.BaseSignoffStatusColumn');
00017 
00018 class SignoffStatusFromFileGridColumn extends BaseSignoffStatusColumn {
00019    /* @var string */
00020    var $_symbolic;
00021 
00022    /* @var $_allowSignoffs boolean */
00023    var $_allowSignoffs;
00024 
00036    function SignoffStatusFromFileGridColumn($id, $title, $titleTranslated, $symbolic, $userIds, $requestArgs, $allowSignoffs = false, $flags = array()) {
00037       $this->_symbolic = $symbolic;
00038       $this->_allowSignoffs = $allowSignoffs;
00039 
00040       parent::BaseSignoffStatusColumn(
00041          $id,
00042          $title,
00043          $titleTranslated,
00044          $userIds,
00045          $requestArgs,
00046          $flags
00047       );
00048    }
00049 
00050    //
00051    // Setters and Getters
00052    //
00053    function getSymbolic() {
00054       return $this->_symbolic;
00055    }
00056 
00057    //
00058    // Overridden methods from GridColumn
00059    //
00063    function getCellActions($request, $row) {
00064       $status = $this->_getSignoffStatus($row);
00065       $actions = array();
00066       if (in_array($status, array('accepted', 'new')) && $this->_allowSignoffs) {
00067          // Retrieve the submission file.
00068          $monographFile =& $this->getMonographFile($row);
00069 
00070          // Assemble the request arguments for the signoff action.
00071          $actionArgs = $this->getRequestArgs();
00072          $actionArgs['fileId'] = $monographFile->getFileId();
00073 
00074          // Instantiate the signoff action.
00075          $router =& $request->getRouter();
00076          import('lib.pkp.classes.linkAction.request.AjaxAction');
00077          $signoffAction = new LinkAction(
00078             'fileSignoff',
00079             new AjaxAction(
00080                $router->url(
00081                   $request, null, null, 'signOffFile',
00082                   null, $actionArgs
00083                )
00084             ),
00085             __('common.signoff'),
00086             'task '.$status
00087          );
00088          $actions[] = $signoffAction;
00089       }
00090       return $actions;
00091    }
00092 
00093 
00094    //
00095    // Protected helper methods
00096    //
00102    function &getMonographFile($row) {
00103       $submissionFileData =& $row->getData();
00104       assert(isset($submissionFileData['submissionFile']));
00105       $monographFile =& $submissionFileData['submissionFile']; /* @var $monographFile MonographFile */
00106       assert(is_a($monographFile, 'MonographFile'));
00107       return $monographFile;
00108    }
00109 
00110    //
00111    // Private helper methods
00112    //
00118    function _getSignoffStatus(&$row) {
00119       $monographFile =& $this->getMonographFile($row);
00120 
00121       $userIds = $this->getUserIds();
00122       if (in_array($monographFile->getUploaderUserId(), $userIds)) {
00123          return 'uploaded';
00124 
00125       } else {
00126          // The current user has to sign off the file
00127          $signoffDao =& DAORegistry::getDAO('SignoffDAO'); /* @var $signoffDao SignoffDAO */
00128          $viewsDao =& DAORegistry::getDAO('ViewsDAO'); /* @var $viewsDao ViewsDAO */
00129          $lastViewed = false;
00130          foreach ($userIds as $userId) {
00131             $signoffs =& $signoffDao->getAllBySymbolic(
00132                $this->getSymbolic(),
00133                ASSOC_TYPE_MONOGRAPH_FILE, $monographFile->getFileId(),
00134                $userId
00135             );
00136 
00137             // Check if any of the signoffs signed off.
00138             while($signoff =& $signoffs->next()) {
00139                         if ($signoff->getDateCompleted()) {
00140                   return 'completed';
00141                      }
00142                unset($signoff);
00143             }
00144 
00145             if (!$lastViewed) {
00146                // Find out whether someone in the user group already downloaded
00147                            // (=viewed) the file.
00148                // no users means a blank column (should not happen).
00149 
00150                $lastViewed = $viewsDao->getLastViewDate(
00151                   ASSOC_TYPE_MONOGRAPH_FILE, $monographFile->getFileIdAndRevision(),
00152                   $userId
00153                );
00154             }
00155          }
00156          // At least one user viewed the file
00157          if($lastViewed) {
00158             return 'accepted';
00159          }
00160 
00161          // No views means a white square.
00162          return 'new';
00163       }
00164    }
00165 }
00166 
00167 ?>

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