[ 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/view/admin/ -> adminresourceslistview.class.php (source)

   1  <?php
   2  
   3      lt_include( PLOG_CLASS_PATH."class/view/admin/admintemplatedview.class.php" );
   4      lt_include( PLOG_CLASS_PATH."class/gallery/dao/galleryalbums.class.php" );
   5      lt_include( PLOG_CLASS_PATH."class/gallery/dao/galleryresources.class.php" );    
   6      lt_include( PLOG_CLASS_PATH."class/gallery/dao/galleryresourcequotas.class.php" );
   7      lt_include( PLOG_CLASS_PATH."class/data/pager/pager.class.php" );
   8      
   9      define( "ROOT_ALBUM_ID", 0 );
  10      
  11      /**
  12       * \ingroup View
  13       * @private
  14       *    
  15       * lists the resources
  16       */
  17      class AdminResourcesListView extends AdminTemplatedView
  18      {
  19          var $_albumId;
  20          var $_page;
  21          var $_resourceType;
  22          var $_viewParams;
  23      
  24  		function AdminResourcesListView( $blogInfo, $params = Array())
  25          {
  26              $this->AdminTemplatedView( $blogInfo, "resources" );
  27              
  28              $this->_viewParams = $params;
  29          }
  30          
  31  		function render()
  32          {
  33              
  34              // fetch and save the albumId parameter in the request, if not available as a
  35              // constructor parameter
  36              isset( $this->_viewParams["albumId"] ) ? $this->_albumId = $this->_viewParams["albumId"] : $this->_albumId = null;
  37                  
  38              if( $this->_albumId == null )
  39                  $this->_albumId = $this->getSessionValue( "albumId", ROOT_ALBUM_ID );
  40  
  41              // in case we didn't get any album id at all!
  42              if( $this->_albumId == "" )
  43                  $this->_albumId = ROOT_ALBUM_ID;
  44                  
  45              // search terms
  46              $this->_searchTerms = "";
  47              if( isset( $this->_viewParams['searchTerms'] ))
  48                  $this->_searchTerms = $this->_viewParams['searchTerms'];
  49                  
  50              $this->setSessionValue( "albumId", $this->_albumId );
  51  
  52              $this->_resourceType = GALLERY_RESOURCE_ANY;
  53  
  54              // base url for the pager so that it can be changed by parent classes
  55              // such as AdminSimpleResourcesListView
  56              if ( !isset( $this->_pagerUrl ) )
  57                  $this->_pagerUrl = "?op=resources&amp;albumId=".$this->_albumId."&amp;page=";
  58          
  59          
  60              // get the page from the request
  61              $this->_page = $this->getCurrentPageFromRequest();
  62              
  63              $albums = Array();
  64  
  65              // and the current album
  66              $galleryAlbums = new GalleryAlbums();
  67              $galleryResources = new GalleryResources();
  68  
  69              $numResources = 0;
  70              if( $this->_albumId > ROOT_ALBUM_ID && $this->_page > 0 ) {            
  71                  $album = $galleryAlbums->getAlbum( $this->_albumId, $this->_blogInfo->getId());
  72                  if( !$album || empty($album) ) {
  73                      $this->_albumId = ROOT_ALBUM_ID;
  74                  }
  75                  else {                
  76                      // resources for this page
  77                      $resources = $galleryResources->getUserResources( $this->_blogInfo->getId(),
  78                                                                        $this->_albumId,
  79                                                                        $this->_resourceType,
  80                                                                        $this->_searchTerms,
  81                                                                        $this->_page,
  82                                                                        DEFAULT_ITEMS_PER_PAGE );
  83                                                                        
  84                      // total number of resources in this album, used by the pager
  85                      $numResources = $galleryResources->getNumUserResources( $this->_blogInfo->getId(),
  86                                                                              $this->_albumId,
  87                                                                              $this->_resourceType,
  88                                                                              $this->_searchTerms );
  89                  }
  90              }
  91              else {
  92                  $album = null;
  93                  // if we're at the root album but search terms, still call GalleryResources::getUserResources
  94                  if( $this->_searchTerms ) {
  95                      // load the resources matching the given string from *all* albums
  96                      $resources = $galleryResources->getUserResources( $this->_blogInfo->getId(),
  97                                                                        GALLERY_NO_ALBUM,
  98                                                                        $this->_resourceType,
  99                                                                        $this->_searchTerms,
 100                                                                        $this->_page,
 101                                                                        DEFAULT_ITEMS_PER_PAGE );
 102                      // total number of resources for the pager
 103                      $numResources = $galleryResources->getNumUserResources( $this->_blogInfo->getId(),
 104                                                                              GALLERY_NO_ALBUM,
 105                                                                              $this->_resourceType,
 106                                                                              $this->_searchTerms );                
 107                  }
 108                  else {
 109                      $albums = $galleryAlbums->getChildAlbums( $this->_albumId, $this->_blogInfo->getId(), $this->_searchTerms );
 110                      $resources = Array();
 111                  }
 112              }
 113              
 114              // get a list with the nested albums
 115              $userAlbums = $galleryAlbums->getNestedAlbumList( $this->_blogInfo->getId());
 116              
 117              // event about the albums we just loaded
 118              $this->notifyEvent( EVENT_ALBUMS_LOADED, Array( "albums" => &$userAlbums ));
 119              
 120              $this->setValue( "albumsList", $userAlbums );
 121  
 122              // fetch some statistics and continue
 123              $quotaUsage = GalleryResourceQuotas::getBlogResourceQuotaUsage( $this->_blogInfo->getId());
 124              $totalResources = $galleryResources->getNumUserResources( $this->_blogInfo->getId());
 125              $this->setValue( "quotausage", $quotaUsage );
 126              $this->setValue( "totalresources", $totalResources );
 127  
 128              // and now export info about the albums and so on but only 
 129              // if we're browsing the first page only (albums do not appear anymore after the first page)
 130              $this->setValue( "album", $album );
 131              if( $this->_albumId > ROOT_ALBUM_ID && $this->_page < 2 ) {
 132                  $this->setValue( "albums", $album->getChildren());
 133              }
 134              else {
 135                  $this->setValue( "albums", $albums );
 136              }
 137              
 138              // event about the resources
 139              $this->notifyEvent( EVENT_RESOURCES_LOADED, Array ( "resources" => &$resources ));
 140              $this->setValue( "resources", $resources );
 141  
 142              // finally, create and export the pager
 143              $pager = new Pager( $this->_pagerUrl, $this->_page, $numResources, DEFAULT_ITEMS_PER_PAGE );
 144              $this->setValue( "pager", $pager );
 145              $this->setValue( "searchTerms", $this->_searchTerms );
 146              
 147              parent::render();
 148          }
 149      }
 150  ?>


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