[ 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/action/ -> viewalbumaction.class.php (source)

   1  <?php
   2  
   3  
   4      lt_include( PLOG_CLASS_PATH."class/action/blogaction.class.php" );
   5      lt_include( PLOG_CLASS_PATH."class/view/blogview.class.php" );
   6      lt_include( PLOG_CLASS_PATH."class/data/validator/stringvalidator.class.php" );
   7      lt_include( PLOG_CLASS_PATH."class/view/errorview.class.php" );
   8  
   9      define( "VIEW_ALBUMS_TEMPLATE", "albums" );
  10      define( "VIEW_ALBUM_TEMPLATE", "album" );
  11  
  12      /**
  13       * \ingroup Action
  14       * @private
  15       *
  16       * This class shows an album with resources
  17       */
  18      class ViewAlbumAction extends BlogAction
  19      {
  20  
  21          var $_albumId;
  22  
  23  		function ViewAlbumAction( $actionInfo, $request )
  24          {
  25              $this->BlogAction( $actionInfo, $request );
  26              
  27              $this->registerFieldValidator( "albumId", new IntegerValidator(), true );
  28              $this->registerFieldValidator( "albumName", new StringValidator(), true );
  29              
  30              $this->setValidationErrorView( new ErrorView( $this->_blogInfo, "error_fetching_album" ));
  31          }
  32  
  33          // checks that the articleId is valid
  34          function validate()
  35          {
  36              if( !parent::validate())
  37                  return false;
  38      
  39              $this->_albumId = $this->_request->getValue( "albumId", 0 );
  40              $this->_albumName = $this->_request->getValue( "albumName" );
  41              // get the page from the request
  42              $this->_page = View::getCurrentPageFromRequest();            
  43              
  44              return true;
  45          }
  46  
  47          function perform()
  48          {
  49              $browseRootAlbum = ( $this->_albumId == 0 && $this->_albumName == "" ); 
  50              
  51              // check which template we should use
  52              if( $browseRootAlbum )
  53                  $template = VIEW_ALBUMS_TEMPLATE;
  54              else
  55                  $template = VIEW_ALBUM_TEMPLATE;
  56              
  57              // initialize the view and check if it was cached
  58              $this->_view = new BlogView( $this->_blogInfo, 
  59                                           $template, 
  60                                           SMARTY_VIEW_CACHE_CHECK,
  61                                           Array( "albumId" => $this->_albumId, 
  62                                                  "albumName" => $this->_albumName,
  63                                                  "page" => $this->_page ));
  64              if( $this->_view->isCached()) {
  65                  // nothing to do if it is cached!
  66                  $this->setCommonData();
  67                  return true;
  68              }
  69              
  70              lt_include( PLOG_CLASS_PATH."class/gallery/dao/galleryresources.class.php" );
  71              lt_include( PLOG_CLASS_PATH."class/gallery/dao/galleryalbums.class.php" );
  72              lt_include( PLOG_CLASS_PATH."class/data/validator/integervalidator.class.php" );
  73              lt_include( PLOG_CLASS_PATH."class/data/pager/pager.class.php" );            
  74              
  75              $galleryResources = new GalleryResources();
  76              $galleryAlbums = new GalleryAlbums();            
  77  
  78              // fetch the album we're trying to browse
  79              if( $browseRootAlbum ) {
  80                  // fetch only the first level albums
  81                  $blogAlbums = $galleryAlbums->getChildAlbums( 0, $this->_blogInfo->getId(), true );
  82                  if( count($blogAlbums) == 0 ) {
  83                      $this->_view = new ErrorView( $this->_blogInfo );
  84                      $this->_view->setValue( "message", "error_no_albums_defined" );
  85                  }
  86                  else {
  87                      $this->notifyEvent( EVENT_ALBUMS_LOADED, Array( "albums" => &$blogAlbums ));
  88                      $this->_view->setValue( "albums", $blogAlbums );
  89                      $this->_view->setPageTitle( $this->_blogInfo->getBlog()." | ".$this->_locale->tr("albums"));
  90                  }
  91              }
  92              else {
  93                  // the third parameter is telling _not_ to fetch all those albums that have
  94                  // been disabled and are not to be shown in the page when browsing the album
  95                  if( $this->_albumName ) {
  96                      $album = $galleryAlbums->getAlbumByName( $this->_albumName, $this->_blogInfo->getId(), true, true );
  97                  }
  98                  else {
  99                      $album = $galleryAlbums->getAlbum( $this->_albumId, $this->_blogInfo->getId(), true, true );
 100                  }                
 101                  // check if the album was correctly fetched
 102                  if( !$album ) {
 103                      $this->_view = new ErrorView( $this->_blogInfo );
 104                      $this->_view->setValue( "message", "error_fetching_album" );
 105                      $this->setCommonData();
 106  
 107                      return false;
 108                  }
 109                  $this->notifyEvent( EVENT_ALBUM_LOADED, Array( "album" => &$blogAlbum ));                
 110                  // put the album to the template
 111                  $this->_view->setValue( "album", $album );
 112                  // and set a page title
 113                  $this->_view->setPageTitle( $this->_blogInfo->getBlog()." | ".$album->getName());
 114                  
 115                  // load the resources and build the pager
 116                  $resources = $galleryResources->getUserResources( $this->_blogInfo->getId(),
 117                                                                    $album->getId(),
 118                                                                    GALLERY_RESOURCE_ANY,
 119                                                                    "",
 120                                                                    $this->_page,
 121                                                                    DEFAULT_ITEMS_PER_PAGE );                                                            
 122                                                                    
 123                  // total number of resources, used by the pager
 124                  $numResources = $galleryResources->getNumUserResources( $this->_blogInfo->getId(),
 125                                                                          $album->getId(),
 126                                                                          GALLERY_RESOURCE_ANY );
 127                  // build the pager
 128                  $url = $this->_blogInfo->getBlogRequestGenerator();
 129                  $pager = new Pager( $url->albumLink( $album ).$url->getPageSuffix(),
 130                                      $this->_page,
 131                                      $numResources,
 132                                      DEFAULT_ITEMS_PER_PAGE );
 133                  // and pass everything back to the templates
 134                  $this->_view->setValue( "pager", $pager );
 135                  $this->_view->setValue( "resources", $resources );
 136              }
 137  
 138              // if all went fine, continue
 139              $this->setCommonData();
 140              
 141              // and return everything normal
 142              return true;
 143          }
 144      }
 145  ?>


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