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

   1  <?php
   2  
   3      lt_include( PLOG_CLASS_PATH."class/action/admin/adminaction.class.php" );
   4      lt_include( PLOG_CLASS_PATH."class/view/admin/adminresourceslistview.class.php" );
   5      lt_include( PLOG_CLASS_PATH."class/view/admin/admineditresourceview.class.php" );
   6      lt_include( PLOG_CLASS_PATH."class/gallery/dao/galleryresources.class.php" );
   7      lt_include( PLOG_CLASS_PATH."class/gallery/dao/galleryalbums.class.php" );
   8      lt_include( PLOG_CLASS_PATH."class/data/validator/integervalidator.class.php" );
   9  
  10      /**
  11       * \ingroup Action
  12       * @private
  13       *
  14       * Updates a resource in the database
  15       */
  16      class AdminUpdateResourceAction extends AdminAction
  17      {
  18  
  19          var $_resourceId;
  20          var $_resourceDescription;
  21          var $_albumId;
  22  
  23          /**
  24           * Constructor. If nothing else, it also has to call the constructor of the parent
  25           * class, BlogAction with the same parameters
  26           */
  27          function AdminUpdateResourceAction( $actionInfo, $request )
  28          {
  29              $this->AdminAction( $actionInfo, $request );
  30              
  31              // data validation
  32              $this->registerFieldValidator( "albumId", new IntegerValidator());
  33              $this->registerFieldValidator( "resourceId", new IntegerValidator());
  34              $this->registerField( "resourceDescription" );
  35              $view = new AdminEditResourceView( $this->_blogInfo );
  36              $view->setErrorMessage( $this->_locale->tr("error_updating_resource" ));
  37              $this->setValidationErrorView( $view );
  38  
  39                  
  40          }
  41          
  42  		function validate()
  43          {
  44              if( !parent::validate()) {
  45                  $resources = new GalleryResources();
  46                  $resource = $resources->getResource( $this->_request->getValue("resourceId"), $this->_blogInfo->getId());
  47                  if( !$resource ) {    
  48                      $this->setValidationErrorView( new AdminResourcesListView( $this->_blogInfo ));
  49                      $this->setCommonData();
  50                      return false;
  51                  }
  52                  $this->_view->setValue( "resource", $resource );
  53                  
  54                  return false;
  55              }
  56              
  57              return true;
  58          }
  59  
  60          /**
  61           * Carries out the specified action
  62           */
  63          function perform()
  64          {
  65              // load the resource
  66              $this->_resourceDescription = Textfilter::filterAllHTML($this->_request->getValue( "resourceDescription" ));
  67              $this->_albumId = $this->_request->getValue( "albumId" );
  68              $this->_resourceId = $this->_request->getValue( "resourceId" );
  69              $resources = new GalleryResources();
  70              $resource = $resources->getResource( $this->_resourceId, $this->_blogInfo->getId());
  71              // update the fields we'd like to update
  72              $resource->setAlbumId( $this->_albumId );
  73              $resource->setDescription( $this->_resourceDescription );
  74              // send the event
  75              $this->notifyEvent( EVENT_PRE_RESOURCE_UPDATE, Array( "resource" => &$resource ));                        
  76              // and update it in the db
  77              $result = $resources->updateResource( $resource );
  78  
  79              if( !$result ) {
  80                  $this->_view = new AdminResourcesListView( $this->_blogInfo );
  81                  $this->_view->setErrorMessage( $this->_locale->tr("error_updating_resource"));
  82              }
  83              else {
  84                      // check which submit button was pressed
  85                  if($this->_request->getValue("regenerate" ) != ""){
  86                      return Controller::setForwardAction( "regeneratePreview" );
  87                  }
  88  
  89                  $this->_view = new AdminResourcesListView( $this->_blogInfo );
  90                  $this->_view->setSuccessMessage( $this->_locale->pr("resource_updated_ok", $resource->getFileName()));
  91                  $this->notifyEvent( EVENT_POST_RESOURCE_UPDATE, Array( "resource" => &$resource ));                
  92                  
  93                      // clear the cache
  94                  CacheControl::resetBlogCache( $this->_blogInfo->getId(), false );
  95              }
  96  
  97              $this->setCommonData();
  98  
  99              // better to return true if everything fine
 100              return true;
 101          }
 102      }
 103  ?>


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