lifetype/branches/lifetype-1.0.6/class/action/viewalbumaction.class.php
Go to the documentation of this file.00001 <?php
00002
00003
00004 include_once( PLOG_CLASS_PATH."class/action/blogaction.class.php" );
00005 include_once( PLOG_CLASS_PATH."class/view/blogview.class.php" );
00006 include_once( PLOG_CLASS_PATH."class/view/errorview.class.php" );
00007 include_once( PLOG_CLASS_PATH."class/gallery/dao/galleryresources.class.php" );
00008 include_once( PLOG_CLASS_PATH."class/gallery/dao/galleryalbums.class.php" );
00009 include_once( PLOG_CLASS_PATH."class/data/validator/integervalidator.class.php" );
00010 include_once( PLOG_CLASS_PATH."class/data/validator/stringvalidator.class.php" );
00011
00012 define( "VIEW_ALBUMS_TEMPLATE", "albums" );
00013 define( "VIEW_ALBUM_TEMPLATE", "album" );
00014
00021 class ViewAlbumAction extends BlogAction
00022 {
00023
00024 var $_albumId;
00025
00026 function ViewAlbumAction( $actionInfo, $request )
00027 {
00028 $this->BlogAction( $actionInfo, $request );
00029
00030 $this->registerFieldValidator( "albumId", new IntegerValidator(), true );
00031 $this->registerFieldValidator( "albumName", new StringValidator(), true );
00032
00033 $this->setValidationErrorView( new ErrorView( $this->_blogInfo, "error_fetching_album" ));
00034 }
00035
00036
00037 function validate()
00038 {
00039 if( !parent::validate())
00040 return false;
00041
00042 $this->_albumId = $this->_request->getValue( "albumId", 0 );
00043 $this->_albumName = $this->_request->getValue( "albumName" );
00044
00045 return true;
00046 }
00047
00048 function perform()
00049 {
00050 $galleryResources = new GalleryResources();
00051 $galleryAlbums = new GalleryAlbums();
00052
00053 $browseRootAlbum = ( $this->_albumId == 0 && $this->_albumName == "" );
00054
00055
00056 if( $browseRootAlbum )
00057 $template = VIEW_ALBUMS_TEMPLATE;
00058 else
00059 $template = VIEW_ALBUM_TEMPLATE;
00060
00061
00062 $this->_view = new BlogView( $this->_blogInfo,
00063 $template,
00064 SMARTY_VIEW_CACHE_CHECK,
00065 Array( "albumId" => $this->_albumId, "albumName" => $this->_albumName ));
00066 if( $this->_view->isCached()) {
00067
00068 return true;
00069 }
00070
00071
00072 if( $browseRootAlbum ) {
00073
00074 $blogAlbums = $galleryAlbums->getChildAlbums( 0, $this->_blogInfo->getId(), true );
00075 if( count($blogAlbums) == 0 ) {
00076 $this->_view = new ErrorView( $this->_blogInfo );
00077 $this->_view->setValue( "message", "error_no_albums_defined" );
00078 }
00079 else {
00080 $this->notifyEvent( EVENT_ALBUMS_LOADED, Array( "albums" => &$blogAlbums ));
00081 $this->_view->setValue( "albums", $blogAlbums );
00082 }
00083 }
00084 else {
00085
00086
00087 if( $this->_albumName ) {
00088 $album = $galleryAlbums->getAlbumByName( $this->_albumName, $this->_blogInfo->getId(), true, true );
00089 }
00090 else {
00091 $album = $galleryAlbums->getAlbum( $this->_albumId, $this->_blogInfo->getId(), true, true );
00092 }
00093
00094 if( !$album ) {
00095 $this->_view = new ErrorView( $this->_blogInfo );
00096 $this->_view->setValue( "message", "error_fetching_album" );
00097 $this->setCommonData();
00098
00099 return false;
00100 }
00101 $this->notifyEvent( EVENT_ALBUM_LOADED, Array( "album" => &$blogAlbum ));
00102
00103 $this->_view->setValue( "album", $album );
00104 }
00105
00106
00107 $this->setCommonData();
00108
00109
00110 return true;
00111 }
00112 }
00113 ?>