[ Index ]
 

Code source de LifeType 1.2.4

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/class/gallery/dao/ -> galleryresourcequotas.class.php (source)

   1  <?php
   2  
   3      
   4      
   5      define( "GLOBAL_QUOTA_DEFAULT", 5000000 );
   6  
   7      /**
   8       * \ingroup Gallery
   9       *
  10       * returns information about quotas, both global-wise and per-blog quotas
  11       */
  12      class GalleryResourceQuotas 
  13      {
  14      
  15          /**
  16           * returns the current global quota set
  17           *
  18           * @static
  19           * @return
  20           */
  21  		function getGlobalResourceQuota()
  22          {
  23              lt_include( PLOG_CLASS_PATH."class/config/config.class.php" );        
  24              $config =& Config::getConfig();
  25              $quota = $config->getValue( "resources_quota", GLOBAL_QUOTA_DEFAULT );
  26              
  27              return $quota;
  28          }
  29          
  30          /**
  31           * Returns the quota usage of a user
  32           *
  33           * @param userId The user whose quota usage we would like to know
  34           * @return The number of bytes used
  35           * @static
  36           */
  37  		function getBlogResourceQuotaUsage( $userId )
  38          {
  39              //
  40              // :HACK:
  41              // this is done so that we can keep this method static while still easily
  42              // executing an sql query!
  43              //
  44              $model = new Model();
  45              $prefix = $model->getPrefix();
  46          
  47              // we can use one query to calculate this...
  48              $query = "SELECT SUM(file_size) AS total_size FROM {$prefix}gallery_resources
  49                        WHERE owner_id = '".Db::qstr( $userId )."'";
  50              $result = $model->Execute( $query );
  51              
  52              if( !$result ) 
  53                  return 0;
  54              $row = $result->FetchRow();
  55              $result->Close();
  56              if( isset( $row["total_size"] ))
  57                  $quota = $row["total_size"];
  58              else
  59                  $quota = 0;
  60                  
  61              return( $quota );
  62          }
  63          
  64          /**
  65           * returns whether the blog would be over its allocated quota
  66           * if we are to add a file of the given size
  67           *
  68           * @param blogId
  69           * @param fileSize
  70           * @return
  71           * @static
  72           */
  73  		function isBlogOverResourceQuota( $blogId, $fileSize )
  74          {
  75              // current allocated quota
  76              lt_include( PLOG_CLASS_PATH."class/dao/blogs.class.php" );
  77              $blogs = new Blogs();
  78              $blog = $blogs->getBlogInfo( $blogId );
  79              if( !$blog )
  80                  return false;
  81                  
  82              $blogQuota = $blog->getResourcesQuota();
  83              
  84              // but if the quota is 0, then for sure we won't be over the quota :)
  85              if( $blogQuota == 0 )
  86                  return false;
  87                  
  88              // if not, calculate how many bytes we currently have
  89              $currentBytes = GalleryResourceQuotas::getBlogResourceQuotaUsage( $blogId );
  90                                  
  91              if( ($currentBytes + $fileSize) > $blogQuota )
  92                  return true;
  93              else
  94                  return false;
  95          }
  96      }
  97  ?>


Généré le : Mon Nov 26 21:04:15 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics