[ 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/ -> adminchangepostsstatusaction.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/adminpostslistview.class.php" );
   5      lt_include( PLOG_CLASS_PATH."class/dao/articles.class.php" );
   6      lt_include( PLOG_CLASS_PATH."class/template/cachecontrol.class.php" );
   7      lt_include( PLOG_CLASS_PATH."class/data/validator/arrayvalidator.class.php" );
   8      lt_include( PLOG_CLASS_PATH."class/data/validator/integervalidator.class.php" );
   9  
  10      /**
  11       * \ingroup Action
  12       * @private
  13       *
  14       * Massive changes posts status
  15       */
  16      class AdminChangePostsStatusAction extends AdminAction 
  17      {
  18  
  19          var $_postIds;
  20          var $_postStatus;
  21  
  22          /**
  23           * Constructor. If nothing else, it also has to call the constructor of the parent
  24           * class, BlogAction with the same parameters
  25           */
  26          function AdminChangePostsStatusAction( $actionInfo, $request )
  27          {
  28              $this->AdminAction( $actionInfo, $request );
  29              $this->registerFieldValidator( "postIds", new ArrayValidator());
  30              $this->registerFieldValidator( "postStatus", new IntegerValidator() );
  31              $view = new AdminPostsListView( $this->_blogInfo );
  32              $view->setErrorMessage( $this->_locale->tr("error_incorrect_article_id"));
  33              $this->setValidationErrorView( $view );        
  34          }
  35  
  36          /**
  37           * Carries out the specified action
  38           */
  39          function _changePostsStatus()
  40          {
  41              // Chanages the post status field by selection
  42              $articles = new Articles();
  43              $errorMessage = "";
  44              $successMessage = "";
  45              $totalOk = 0;
  46              
  47              foreach( $this->_postIds as $postId ) {
  48                  // get the post
  49                  $post = $articles->getBlogArticle( $postId, $this->_blogInfo->getId());
  50                  
  51                  if( $post ) {
  52                      // fire the event
  53                      $this->notifyEvent( EVENT_PRE_POST_UPDATE, Array( "article" => &$post ));
  54                      
  55                      // update the post status
  56                      $post->setStatus( $this->_postStatus );
  57                      $result = $articles->updateArticle( $post );
  58                      
  59                      if( !$result ) {
  60                          $errorMessage .= $this->_locale->pr("error_updating_post", $post->getTopic())."<br/>";
  61                      }
  62                      else {
  63                          $totalOk++;
  64                          if( $totalOk < 2 ) 
  65                              $successMessage .= $this->_locale->pr("post_updated_ok", $post->getTopic())."<br/>";
  66                          else
  67                              $successMessage = $this->_locale->pr("posts_updated_ok", $totalOk );
  68                          // fire the post event
  69                          $this->notifyEvent( EVENT_POST_POST_UPDATE, Array( "article" => &$post ));                    
  70                      }
  71                  }
  72                  else {
  73                      $errorMessage .= $this->_locale->pr( "error_updating_post2", $postId )."<br/>";
  74                  }
  75              }
  76              
  77              // clean up the cache
  78              CacheControl::resetBlogCache( $this->_blogInfo->getId());
  79  
  80              $this->_view = new AdminPostsListView( $this->_blogInfo );
  81              if( $errorMessage != "" ) 
  82                  $this->_view->setErrorMessage( $errorMessage );
  83              if( $successMessage != "" )
  84                  $this->_view->setSuccessMessage( $successMessage );
  85                  
  86              $this->setCommonData();
  87              
  88              return true;
  89          }
  90          
  91  		function perform()
  92          {
  93              // prepare the parameters.. If there's only one category id, then add it to
  94              // an array.
  95              $this->_postIds = $this->_request->getValue( "postIds" );
  96              $this->_postStatus = $this->_request->getValue( "postStatus" );
  97                  
  98              $this->_changePostsStatus();
  99          }
 100      }
 101  ?>


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