/**
  * Returns the quota usage of a user
  *
  * @param userId The user whose quota usage we would like to know
  * @param albumId The album identifier, optional
  * @return The number of bytes used
  * @static
  */
 function getBlogResourceQuotaUsage($userId, $albumId = -1)
 {
     // get the user resources
     $resources = new GalleryResources();
     $blogResources = $resources->getUserResources($userId, $albumId);
     if (!$blogResources) {
         return 0;
     }
     // and now go one by one calculating the sizes
     $total = 0;
     foreach ($blogResources as $resource) {
         $total += $resource->getFileSize();
     }
     return $total;
 }
 function render()
 {
     // get the page from the request
     $this->_page = $this->getCurrentPageFromRequest();
     // and the current album
     $galleryAlbums = new GalleryAlbums();
     $galleryResources = new GalleryResources();
     if ($this->_albumId > ROOT_ALBUM_ID && $this->_page > 0) {
         $album = $galleryAlbums->getAlbum($this->_albumId, $this->_blogInfo->getId());
         if (!$album || $album == "") {
             $this->_albumId = ROOT_ALBUM_ID;
         } else {
             //$resources = $album->getResources();
             $resources = $galleryResources->getUserResources($this->_blogInfo->getId(), $this->_albumId, $this->_resourceType, $this->_page, DEFAULT_ITEMS_PER_PAGE);
             $numResources = $galleryResources->getNumUserResources($this->_blogInfo->getId(), $this->_albumId, $this->_resourceType);
         }
     } else {
         $albums = $galleryAlbums->getChildAlbums($this->_albumId, $this->_blogInfo->getId());
         $resources = array();
     }
     // get a list with the nested albums
     $userAlbums = $galleryAlbums->getNestedAlbumList($this->_blogInfo->getId());
     // event about the albums we just loaded
     $this->notifyEvent(EVENT_ALBUMS_LOADED, array("albums" => &$userAlbums));
     $this->setValue("albumsList", $userAlbums);
     // fetch some statistics and continue
     $quotaUsage = GalleryResourceQuotas::getBlogResourceQuotaUsage($this->_blogInfo->getId());
     $totalResources = $galleryResources->getNumResources($this->_blogInfo->getId());
     $currentQuota = GalleryResourceQuotas::getBlogResourceQuota($this->_blogInfo->getId());
     $this->setValue("quotausage", $quotaUsage);
     $this->setValue("totalresources", $totalResources);
     $this->setValue("quota", $currentQuota);
     // and now export info about the albums and so on but only
     // if we're browsing the first page only (albums do not appear anymore after the first page)
     $this->setValue("album", $album);
     if ($this->_albumId > ROOT_ALBUM_ID && $this->_page < 2) {
         $this->setValue("albums", $album->getChildren());
     } else {
         $this->setValue("albums", $albums);
     }
     // event about the resources
     $this->notifyEvent(EVENT_RESOURCES_LOADED, array("resources" => &$resources));
     $this->setValue("resources", $resources);
     // finally, create and export the pager
     $pager = new Pager($this->_pagerUrl, $this->_page, $numResources, DEFAULT_ITEMS_PER_PAGE);
     $this->setValue("pager", $pager);
     parent::render();
 }
 /**
  * this breaks our rule big time (remember: this little objects resulting
  * of dao/ classes should _never_ do any database access by themselves... 
  * all the information they need has already been fetched. However, 
  * this proved to be here a great performance improvement in the sense that
  * fetching a single album did not trigger fetchign the whole shebang
  * and whatnot from the database of albums and resources...
  * Sometimes, breaking the rules is a good thing :)
  */
 function getResources()
 {
     //return $this->_resources;
     if ($this->_resources == null) {
         $res = new GalleryResources();
         $this->_resources = $res->getUserResources($this->getOwnerId(), $this->getId());
     }
     return $this->_resources;
 }