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

classes/security/authorization/internal/MonographFileBaseAccessPolicy.inc.php

00001 <?php
00015 import('lib.pkp.classes.security.authorization.AuthorizationPolicy');
00016 
00017 class MonographFileBaseAccessPolicy extends AuthorizationPolicy {
00019    var $_request;
00020 
00022    var $_fileIdAndRevision;
00023 
00030    function MonographFileBaseAccessPolicy(&$request, $fileIdAndRevision = null) {
00031       parent::AuthorizationPolicy('user.authorization.monographFile');
00032       $this->_request =& $request;
00033       $this->_fileIdAndRevision = $fileIdAndRevision;
00034    }
00035 
00036 
00037    //
00038    // Private methods
00039    //
00045    function &_getCache() {
00046       static $cache;
00047       if (!isset($cache)) $cache = array();
00048       return $cache;
00049    }
00050 
00051 
00052    //
00053    // Protected methods
00054    //
00060    function &getMonographFile(&$request) {
00061       // Try to get the monograph file info.
00062       $fileIdAndRevision = $this->_fileIdAndRevision;
00063       if (!is_null($fileIdAndRevision)) {
00064          $fileData = explode('-', $fileIdAndRevision);
00065          $fileId = (int) $fileData[0];
00066          $revision = isset($fileData[1]) ? (int) $fileData[1] : 0; // -0 for most recent revision
00067          $cacheId = $fileIdAndRevision;
00068       } else {
00069          // Get the identifying info from the request
00070          $fileId = (int) $request->getUserVar('fileId');
00071          $revision = (int) $request->getUserVar('revision');
00072          assert($fileId);
00073          $cacheId = "$fileId-$revision"; // -0 for most recent revision
00074       }
00075 
00076       // Fetch the object, caching if possible
00077       $cache =& $this->_getCache();
00078       if (!isset($cache[$cacheId])) {
00079          // Cache miss
00080          $submissionFileDao =& DAORegistry::getDAO('SubmissionFileDAO');
00081          if ($revision) {
00082             $cache[$cacheId] =& $submissionFileDao->getRevision($fileId, $revision);
00083          } else {
00084             $cache[$cacheId] =& $submissionFileDao->getLatestRevision($fileId);
00085          }
00086       }
00087 
00088       return $cache[$cacheId];
00089    }
00090 
00095    function &getRequest() {
00096       return $this->_request;
00097    }
00098 }
00099 
00100 ?>

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