[ 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/ -> admindeletecommentaction.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/adminarticlecommentslistview.class.php" );
   5      lt_include( PLOG_CLASS_PATH."class/dao/articles.class.php" );    
   6      lt_include( PLOG_CLASS_PATH."class/dao/articlecomments.class.php" );
   7      lt_include( PLOG_CLASS_PATH."class/data/validator/integervalidator.class.php" );
   8      lt_include( PLOG_CLASS_PATH."class/data/validator/arrayvalidator.class.php" );
   9  
  10      /**
  11       * \ingroup Action
  12       * @private
  13       *
  14       * Action that shows a list of all the comments for a given post
  15       */
  16      class AdminDeleteCommentAction extends AdminAction 
  17      {
  18  
  19          var $_articleId;
  20          var $_commentIds;
  21          var $_mode;        
  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 AdminDeleteCommentAction( $actionInfo, $request )
  28          {
  29              $this->AdminAction( $actionInfo, $request );
  30              
  31              $this->_mode = $actionInfo->getActionParamValue();
  32              $this->registerFieldValidator( "articleId", new IntegerValidator());
  33              if( $this->_mode == "deleteComment" )
  34                  $this->registerFieldValidator( "commentId", new IntegerValidator());
  35              else
  36                  $this->registerFieldValidator( "commentIds", new ArrayValidator());
  37                  
  38              $view = new AdminArticleCommentsListView( $this->_blogInfo );
  39              $view->setErrorMessage( $this->_locale->tr("error_deleting_comments"));
  40              $this->setValidationErrorView( $view );
  41  
  42              $this->requirePermission( "update_comment" );            
  43          }
  44          
  45          /**
  46           * sets up the parameters and calls the method below
  47           */
  48  		function perform()
  49          {
  50              $this->_articleId = $this->_request->getValue( "articleId" );
  51              if( $this->_mode == "deleteComment" ) {
  52                  $commentId = $this->_request->getValue( "commentId" );
  53                  $this->_commentIds = Array();
  54                  $this->_commentIds[] = $commentId;
  55              }
  56              else
  57                  $this->_commentIds = $this->_request->getValue( "commentIds" );
  58                  
  59              $this->_deleteComments();
  60              
  61              return true;
  62          }
  63  
  64          /**
  65           * deletes comments
  66           * @private
  67           */
  68          function _deleteComments()
  69          {
  70              $comments = new ArticleComments();
  71              $errorMessage = "";
  72              $successMessage = "";
  73              $totalOk = 0;
  74              
  75              if( $this->_articleId > 0 ) {
  76                  // if we can't even load the article, then forget it...
  77                  $articles = new Articles();
  78                  $article = $articles->getBlogArticle( $this->_articleId, $this->_blogInfo->getId());
  79                  if( !$article ) {
  80                      $this->_view = new AdminArticleCommentsListView( $this->_blogInfo );
  81                      $this->_view->setErrorMessage( $this->_locale->tr("error_fetching_article" ));
  82                      $this->setCommonData();
  83                      
  84                      return false;
  85                  }
  86              }
  87              else {
  88                  // there was no article, so this probably was the view that shows all comments...
  89                  $article = null;
  90              }
  91              
  92              // loop through the comments and remove them
  93              foreach( $this->_commentIds as $commentId ) {
  94                  // fetch the comment
  95                  $comment = $comments->getComment( $commentId );
  96                  
  97                  if( !$comment ) {
  98                      $errorMessage .= $this->_locale->pr("error_deleting_comment2", $commentId);
  99                  }
 100                  else {
 101                      // fire the pre-event
 102                      $this->notifyEvent( EVENT_PRE_COMMENT_DELETE, Array( "comment" => &$comment ));
 103                      
 104                      // check if the comment really belongs to this blog...
 105                      $article = $comment->getArticle();
 106                      if(!($topic = $comment->getTopic()))
 107                          $topic = $this->_locale->tr("comment_default_title");
 108                      if( $article->getBlogId() != $this->_blogInfo->getId()) {
 109                          // if not, then we shouldn't be allowed to remove anything!                        
 110                          $errorMessage .= $this->_locale->pr("error_deleting_comment", $topic)."<br/>";
 111                      }
 112                      else {
 113                          if( !$comments->deleteComment( $commentId ))
 114                              $errorMessage .= $this->_locale->pr("error_deleting_comment", $topic)."<br/>";
 115                          else {
 116                              $totalOk++;
 117                              if( $totalOk < 2 )
 118                                  $successMessage .= $this->_locale->pr("comment_deleted_ok", $topic)."<br/>";
 119                              else
 120                                  $successMessage = $this->_locale->pr("comments_deleted_ok", $totalOk );
 121                              
 122                              // fire the post-event
 123                              $this->notifyEvent( EVENT_POST_COMMENT_DELETE, Array( "comment" => &$comment ));
 124                          }
 125                      }
 126                  }
 127              }
 128  
 129              // if everything fine, then display the same view again with the feedback
 130              if( $this->_articleId == 0 )
 131                  $this->_view = new AdminArticleCommentsListView( $this->_blogInfo, Array( "article" => null ));
 132              else
 133                  $this->_view = new AdminArticleCommentsListView( $this->_blogInfo, Array( "article" => $article ));
 134                  
 135              if( $successMessage != "" ) {
 136                  $this->_view->setSuccessMessage( $successMessage );
 137                  // clear the cache
 138                  CacheControl::resetBlogCache( $this->_blogInfo->getId());
 139              }
 140              if( $errorMessage != "" ) $this->_view->setErrorMessage( $errorMessage );
 141              $this->setCommonData();
 142  
 143              // better to return true if everything fine
 144              return true;
 145          }
 146      }
 147  ?>


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