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

   1  <?php
   2  
   3      lt_include( PLOG_CLASS_PATH."class/action/blogaction.class.php" );
   4      lt_include( PLOG_CLASS_PATH."class/view/errorview.class.php" );
   5      lt_include( PLOG_CLASS_PATH."class/gallery/dao/galleryresources.class.php" );
   6      lt_include( PLOG_CLASS_PATH."class/data/validator/integervalidator.class.php" );
   7      lt_include( PLOG_CLASS_PATH."class/data/validator/stringvalidator.class.php" );
   8  
   9      define( "VIEW_RESOURCE_TEMPLATE", "resource" );
  10  
  11      /**
  12       * \ingroup Action
  13       * @private
  14       *
  15       * This class shows a resource and its information
  16       */
  17      class ViewResourceAction extends BlogAction
  18      {
  19  
  20          var $_resourceId;
  21          var $_albumId;
  22          var $_albumName;
  23          var $_resourceName;
  24  
  25  		function ViewResourceAction( $actionInfo, $request )
  26          {
  27              $this->BlogAction( $actionInfo, $request );
  28              
  29              $this->registerFieldValidator( "resId", new IntegerValidator(), true );
  30              $this->registerFieldValidator( "resource", new StringValidator(), true );
  31              $this->registerFieldValidator( "albumId", new IntegerValidator(), true );
  32              $this->registerFieldValidator( "albumName", new StringValidator(), true );
  33              
  34              $this->setValidationErrorView( new ErrorView( $this->_blogInfo, "error_fetching_resource" ));            
  35          }
  36  
  37          // checks that the articleId is valid
  38          function validate()
  39          {
  40              if( !parent::validate())
  41                  return false;
  42      
  43              $this->_resourceId = $this->_request->getValue( "resId" );
  44              $this->_resourceName = $this->_request->getValue( "resource" );
  45              $this->_albumId = $this->_request->getValue( "albumId" );
  46              $this->_albumName = $this->_request->getValue( "albumName" );
  47              
  48              if( $this->_resourceName == "" ) {
  49                  $validator = new IntegerValidator();
  50                  // if the information is not correct, we better show a message and quit
  51                  if( !$validator->validate( $this->_resourceId )) {
  52                      $this->_view = new ErrorView( $this->_blogInfo, "error_incorrect_resource_id" );
  53                      $this->setCommonData();
  54  
  55                      return false;
  56                  }
  57              }
  58              
  59              // if no album id parameter in the url, forget about the whole thing
  60              if( $this->_albumId == "" && $this->_albumName == "")
  61                  $this->_albumId = -1;
  62  
  63              return true;
  64          }
  65  
  66          function perform()
  67          {
  68              $galleryResources = new GalleryResources();
  69              
  70              // initialize the view
  71              $this->_view = new BlogView( $this->_blogInfo,
  72                                           VIEW_RESOURCE_TEMPLATE,
  73                                           SMARTY_VIEW_CACHE_CHECK,
  74                                           Array( "resourceId" => $this->_resourceId,
  75                                                  "resourceName" => $this->_resourceName, 
  76                                                  "albumName" => $this->_albumName,
  77                                                  "albumId" => $this->_albumId ));
  78              // if it's cached, do nothing
  79              if( $this->_view->isCached()) {
  80                  $this->setCommonData();
  81                  return true;
  82              }
  83              
  84              // otherwise continue as normal...
  85              
  86              // try to find the album to which this resource belongs
  87              if( $this->_albumName ) {
  88                  lt_include( PLOG_CLASS_PATH."class/gallery/dao/galleryalbums.class.php" );            
  89                  $galleryAlbums = new GalleryAlbums();                
  90                  $album = $galleryAlbums->getAlbumByName( $this->_albumName, $this->_blogInfo->getId(), false, false );
  91                  if( !$album ) {
  92                      $this->_view = new ErrorView( $this->_blogInfo );
  93                      $this->_view->setValue( "message", "error_fetching_resource" );
  94                      $this->setCommonData();
  95                      return false;
  96                  }
  97                  $this->_albumId = $album->getId();                
  98              }
  99  
 100              // fetch the album we're trying to browse
 101              if( $this->_resourceName != "" ) {
 102                  $resource = $galleryResources->getResourceFile( $this->_blogInfo->getId(), $this->_resourceName, $this->_albumId );
 103              }
 104              else {
 105                  $resource = $galleryResources->getResource( $this->_resourceId, $this->_blogInfo->getId(), $this->_albumId );
 106              }
 107  
 108              // check if the album was correctly fetched
 109              if( !$resource ) {
 110                  $this->_view = new ErrorView( $this->_blogInfo );
 111                  $this->_view->setValue( "message", "error_fetching_resource" );
 112                  $this->setCommonData();
 113  
 114                  return false;
 115              }
 116  
 117              // if all went fine, continue loading the next and previous resources so that
 118              // navigation can be made easier...
 119              $nextResource = $galleryResources->getNextResource( $resource );
 120              $prevResource = $galleryResources->getPreviousResource( $resource );
 121              
 122              // generate events for all the resources we just loaded
 123              $this->notifyEvent( EVENT_RESOURCE_LOADED, Array( "resource" => &$resource ));
 124              if( $nextResource ) $this->notifyEvent( EVENT_RESOURCE_LOADED, Array( "resource" => &$nextResource )); 
 125              if( $prevResource ) $this->notifyEvent( EVENT_RESOURCE_LOADED, Array( "resource" => &$prevResource ));
 126              $this->_view->setValue( "resource", $resource );
 127              $this->_view->setValue( "prevresource", $prevResource );
 128              $this->_view->setValue( "nextresource", $nextResource );
 129              
 130              // set the page title for the view
 131              $this->_view->setPageTitle( $this->_blogInfo->getBlog()." | ".$resource->getFileName());
 132              
 133              $this->setCommonData();
 134  
 135              // and return everything normal
 136              return true;
 137          }
 138      }
 139  ?>


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