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


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