00001 <?php
00002
00003
00004 lt_include( PLOG_CLASS_PATH."class/action/blogaction.class.php" );
00005 lt_include( PLOG_CLASS_PATH."class/view/blogview.class.php" );
00006 lt_include( PLOG_CLASS_PATH."class/data/validator/stringvalidator.class.php" );
00007 lt_include( PLOG_CLASS_PATH."class/view/errorview.class.php" );
00008
00009 define( "VIEW_ALBUMS_TEMPLATE", "albums" );
00010 define( "VIEW_ALBUM_TEMPLATE", "album" );
00011
00018 class ViewAlbumAction extends BlogAction
00019 {
00020
00021 var $_albumId;
00022
00023 function ViewAlbumAction( $actionInfo, $request )
00024 {
00025 $this->BlogAction( $actionInfo, $request );
00026
00027 $this->registerFieldValidator( "albumId", new IntegerValidator(), true );
00028 $this->registerFieldValidator( "albumName", new StringValidator(), true );
00029
00030 $this->setValidationErrorView( new ErrorView( $this->_blogInfo, "error_fetching_album" ));
00031 }
00032
00033 function validate()
00034 {
00035 if( !parent::validate())
00036 return false;
00037
00038 $this->_albumId = $this->_request->getValue( "albumId", 0 );
00039 $this->_albumName = $this->_request->getValue( "albumName" );
00040
00041 $this->_page = View::getCurrentPageFromRequest();
00042
00043 return true;
00044 }
00045
00046 function perform()
00047 {
00048 $browseRootAlbum = ( $this->_albumId == 0 && $this->_albumName == "" );
00049
00050
00051 if( $browseRootAlbum )
00052 $template = VIEW_ALBUMS_TEMPLATE;
00053 else
00054 $template = VIEW_ALBUM_TEMPLATE;
00055
00056
00057 $this->_view = new BlogView( $this->_blogInfo,
00058 $template,
00059 SMARTY_VIEW_CACHE_CHECK,
00060 Array( "albumId" => $this->_albumId,
00061 "albumName" => $this->_albumName,
00062 "page" => $this->_page ));
00063 if( $this->_view->isCached()) {
00064
00065 $this->setCommonData();
00066 return true;
00067 }
00068
00069 lt_include( PLOG_CLASS_PATH."class/gallery/dao/galleryresources.class.php" );
00070 lt_include( PLOG_CLASS_PATH."class/gallery/dao/galleryalbums.class.php" );
00071 lt_include( PLOG_CLASS_PATH."class/data/validator/integervalidator.class.php" );
00072 lt_include( PLOG_CLASS_PATH."class/data/pager/pager.class.php" );
00073
00074 $galleryResources = new GalleryResources();
00075 $galleryAlbums = new GalleryAlbums();
00076
00077
00078 if( $browseRootAlbum ) {
00079
00080 $blogAlbums = $galleryAlbums->getChildAlbums( 0, $this->_blogInfo->getId(), true );
00081 if( count($blogAlbums) == 0 ) {
00082 $this->_view = new ErrorView( $this->_blogInfo );
00083 $this->_view->setValue( "message", "error_no_albums_defined" );
00084 }
00085 else {
00086 $this->notifyEvent( EVENT_ALBUMS_LOADED, Array( "albums" => &$blogAlbums ));
00087 $this->_view->setValue( "albums", $blogAlbums );
00088 $this->_view->setPageTitle( $this->_blogInfo->getBlog()." | ".$this->_locale->tr("albums"));
00089 }
00090 }
00091 else {
00092
00093
00094 if( $this->_albumName ) {
00095 $album = $galleryAlbums->getAlbumByName( $this->_albumName, $this->_blogInfo->getId(), true, true );
00096 }
00097 else {
00098 $album = $galleryAlbums->getAlbum( $this->_albumId, $this->_blogInfo->getId(), true, true );
00099 }
00100
00101 if( !$album ) {
00102 $this->_view = new ErrorView( $this->_blogInfo );
00103 $this->_view->setValue( "message", "error_fetching_album" );
00104 $this->setCommonData();
00105
00106 return false;
00107 }
00108 $this->notifyEvent( EVENT_ALBUM_LOADED, Array( "album" => &$blogAlbum ));
00109
00110 $this->_view->setValue( "album", $album );
00111
00112 $this->_view->setPageTitle( $this->_blogInfo->getBlog()." | ".$album->getName());
00113
00114
00115 $resources = $galleryResources->getUserResources( $this->_blogInfo->getId(),
00116 $album->getId(),
00117 GALLERY_RESOURCE_ANY,
00118 "",
00119 $this->_page,
00120 DEFAULT_ITEMS_PER_PAGE );
00121
00122
00123 $numResources = $galleryResources->getNumUserResources( $this->_blogInfo->getId(),
00124 $album->getId(),
00125 GALLERY_RESOURCE_ANY );
00126
00127 $url = $this->_blogInfo->getBlogRequestGenerator();
00128 $pager = new Pager( $url->albumLink( $album ).$url->getPageSuffix(),
00129 $this->_page,
00130 $numResources,
00131 DEFAULT_ITEMS_PER_PAGE );
00132
00133 $this->_view->setValue( "pager", $pager );
00134 $this->_view->setValue( "resources", $resources );
00135 }
00136
00137
00138 $this->setCommonData();
00139
00140
00141 return true;
00142 }
00143 }
00144 ?>