NewsFeaturesDownloadsDevelopmentSupportAbout Us

lifetype/branches/lifetype-1.0.6/class/action/viewresourceaction.class.php

Go to the documentation of this file.
00001 <?php
00002 
00003         include_once( PLOG_CLASS_PATH."class/action/blogaction.class.php" );
00004     include_once( PLOG_CLASS_PATH."class/view/errorview.class.php" );
00005     include_once( PLOG_CLASS_PATH."class/gallery/dao/galleryresources.class.php" );
00006     include_once( PLOG_CLASS_PATH."class/data/validator/integervalidator.class.php" );
00007     include_once( PLOG_CLASS_PATH."class/data/validator/stringvalidator.class.php" );
00008 
00009         define( "VIEW_RESOURCE_TEMPLATE", "resource" );
00010 
00017         class ViewResourceAction extends BlogAction
00018     {
00019 
00020         var $_resourceId;
00021                 var $_albumId;
00022                 var $_albumName;
00023                 var $_resourceName;
00024 
00025                 function ViewResourceAction( $actionInfo, $request )
00026         {
00027                         $this->BlogAction( $actionInfo, $request );
00028                         
00029                         $this->registerFieldValidator( "resId", new IntegerValidator(), true );
00030                         $this->registerFieldValidator( "resouce", new StringValidator(), true );
00031                         $this->registerFieldValidator( "albumId", new IntegerValidator(), true );
00032                         $this->registerFieldValidator( "albumName", new StringValidator(), true );
00033                         
00034                         $this->setValidationErrorView( new ErrorView( $this->_blogInfo, "error_fetching_resource" ));                   
00035         }
00036 
00037         // checks that the articleId is valid
00038         function validate()
00039         {
00040                         if( !parent::validate())
00041                                 return false;
00042         
00043                 $this->_resourceId = $this->_request->getValue( "resId" );
00044             $this->_resourceName = $this->_request->getValue( "resource" );
00045                         $this->_albumId = $this->_request->getValue( "albumId" );
00046                         $this->_albumName = $this->_request->getValue( "albumName" );
00047             
00048             if( $this->_resourceName == "" ) {
00049                 $validator = new IntegerValidator();
00050                 // if the information is not correct, we better show a message and quit
00051                 if( !$validator->validate( $this->_resourceId )) {
00052                         $this->_view = new ErrorView( $this->_blogInfo, "error_incorrect_resource_id" );
00053                     $this->setCommonData();
00054 
00055                     return false;
00056                 }
00057             }
00058                         
00059                         // if no album id parameter in the url, forget about the whole thing
00060                         if( $this->_albumId == "" && $this->_albumName == "")
00061                                 $this->_albumId = -1;
00062 
00063             return true;
00064         }
00065 
00066         function perform()
00067         {
00068                 $galleryResources = new GalleryResources();
00069                         $galleryAlbums = new GalleryAlbums();
00070                         
00071                         // initialize the view
00072             $this->_view = new BlogView( $this->_blogInfo,
00073                                                                                  VIEW_RESOURCE_TEMPLATE,
00074                                                                                  SMARTY_VIEW_CACHE_CHECK,
00075                                                                                  Array( "resourceId" => $this->_resourceId,
00076                                                                                         "resourceName" => $this->_resourceName, 
00077                                                                                         "albumName" => $this->_albumName,
00078                                                                                         "albumId" => $this->_albumId ));
00079                         // if it's cached, do nothing
00080                         if( $this->_view->isCached()) {
00081                                 return true;
00082                         }
00083                         
00084                         // otherwise continue as normal...
00085                         
00086                         // try to find the album to which this resource belongs
00087                         if( $this->_albumName ) {
00088                                 $album = $galleryAlbums->getAlbumByName( $this->_albumName, $this->_blogInfo->getId(), false, false);
00089                                 if( !$album ) {
00090                                         $this->_view = new ErrorView( $this->_blogInfo );
00091                                         $this->_view->setValue( "message", "error_fetching_resource" );
00092                                         $this->setCommonData();
00093                                         return false;
00094                                 }
00095                                 $this->_albumId = $album->getId();                              
00096                         }
00097 
00098             // fetch the album we're trying to browse
00099             if( $this->_resourceName != "" ) {
00100                 $resource = $galleryResources->getResourceFile( $this->_blogInfo->getId(), $this->_resourceName, $this->_albumId );
00101             }
00102             else {
00103                 $resource = $galleryResources->getResource( $this->_resourceId, $this->_blogInfo->getId(), $this->_albumId );
00104             }
00105 
00106             // check if the album was correctly fetched
00107             if( !$resource ) {
00108                 $this->_view = new ErrorView( $this->_blogInfo );
00109                 $this->_view->setValue( "message", "error_fetching_resource" );
00110                 $this->setCommonData();
00111 
00112                 return false;
00113             }
00114 
00115             // if all went fine, continue loading the next and previous resources so that
00116                         // navigation can be made easier...
00117                         $nextResource = $galleryResources->getNextResource( $resource );
00118                         $prevResource = $galleryResources->getPreviousResource( $resource );
00119                         
00120                         // generate events for all the resources we just loaded
00121                         $this->notifyEvent( EVENT_RESOURCE_LOADED, Array( "resource" => &$resource ));
00122                         if( $nextResource ) $this->notifyEvent( EVENT_RESOURCE_LOADED, Array( "resource" => &$nextResource )); 
00123                         if( $prevResource ) $this->notifyEvent( EVENT_RESOURCE_LOADED, Array( "resource" => &$prevResource ));
00124             $this->_view->setValue( "resource", $resource );
00125                         $this->_view->setValue( "prevresource", $prevResource );
00126                         $this->_view->setValue( "nextresource", $nextResource );
00127             $this->setCommonData();
00128 
00129             // and return everything normal
00130             return true;
00131         }
00132     }
00133 ?>