[pLog-svn] r6586 - plog/branches/lifetype-1.2/class/action/admin

mark at devel.lifetype.net mark at devel.lifetype.net
Thu Jun 19 03:48:51 EDT 2008


Author: mark
Date: 2008-06-19 03:48:51 -0400 (Thu, 19 Jun 2008)
New Revision: 6586

Modified:
   plog/branches/lifetype-1.2/class/action/admin/admineditcommentsaction.class.php
Log:
It is a quite big change of admineditcommentsaction.class.php

1. No matter $articleId exist or not, we should return comments list view instead of posts list view here.

2. implement private _getView() method to get the correct view according to $articleId, $showStatus and $searchTerms. If there are any errors happened, just return the comments list view with default parameters.

3. We have to use $this->_getView to initiate the errorView inside validate() method, instead of initiate it in action constructor. Because technique can let the adminedittrackbacksaction.class.php set it's own _viewClass inside action constructor.

Modified: plog/branches/lifetype-1.2/class/action/admin/admineditcommentsaction.class.php
===================================================================
--- plog/branches/lifetype-1.2/class/action/admin/admineditcommentsaction.class.php	2008-06-19 06:28:01 UTC (rev 6585)
+++ plog/branches/lifetype-1.2/class/action/admin/admineditcommentsaction.class.php	2008-06-19 07:48:51 UTC (rev 6586)
@@ -2,8 +2,8 @@
 
 	lt_include( PLOG_CLASS_PATH."class/action/admin/adminaction.class.php" );
     lt_include( PLOG_CLASS_PATH."class/view/admin/adminarticlecommentslistview.class.php" );
-	lt_include( PLOG_CLASS_PATH."class/view/admin/adminpostslistview.class.php" );
-    lt_include( PLOG_CLASS_PATH."class/data/validator/integervalidator.class.php" );
+    lt_include( PLOG_CLASS_PATH."class/data/validator/integervalidator.class.php" );
+    lt_include( PLOG_CLASS_PATH."class/data/validator/stringvalidator.class.php" );
     lt_include( PLOG_CLASS_PATH."class/data/filter/htmlfilter.class.php" );
 	
     /**
@@ -22,22 +22,29 @@
         function AdminEditCommentsAction( $actionInfo, $request )
         {
         	$this->AdminAction( $actionInfo, $request );
-			
+
+			// we do this so that AdminEditTrackbacksAction can basically extend this class and provide
+			// a different view... it will allow us to save some extra code!
+        	$this->_viewClass = "AdminArticleCommentsListView";
+
 			// data validation
 			$this->registerFieldValidator( "articleId", new IntegerValidator(), true);
-			$this->registerFieldValidator( "showStatus", new IntegerValidator( true ), true);
-			$view = new AdminPostsListView( $this->_blogInfo );
-			$view->setErrorMessage( $this->_locale->tr("error_fetching_comments"));
-			$this->setValidationErrorView( $view );
-			
-			// we do this so that AdminEditTrackbacksAction can basically extend this class and provide
-			// a different view... it will allow us to save some extra code!
-			$this->_viewClass = "AdminArticleCommentsListView";
-			
+			$this->registerFieldValidator( "showStatus", new IntegerValidator( true ), true);
+			$this->registerFieldValidator( "searchTerms", new StringValidator(), true);
+
 			$this->requirePermission( "view_comments" );
         }
-
-        /**
+
+		function validate()
+		{
+			$view = $this->_getView( null, -1, "" );
+			$view->setErrorMessage( $this->_locale->tr("error_fetching_comments") );
+			$this->setValidationErrorView( $view );
+
+			return( parent::validate() );
+		}
+
+		/**
          * Carries out the specified action
          */
         function perform()
@@ -47,29 +54,42 @@
 			$showStatus = $this->_request->getValue( "showStatus" );
 			$searchTerms = $this->_request->getFilteredValue( "searchTerms", new HtmlFilter());
 			
-			if( $articleId && $articleId > 0 ) {
-				$articles = new Articles();
-				$article = $articles->getBlogArticle( $articleId, $this->_blogInfo->getId());
-				if( !$article ) {
-					$this->_view = new AdminPostsListView( $this->_blogInfo );
-					$this->_view->setErrorMessage( $this->_locale->tr("error_fetching_article" ));				
-				}			
-				else
-					$this->_view = new $this->_viewClass( $this->_blogInfo, Array( "article" => $article,
-																				   "showStatus" => $showStatus,
-																				   "searchTerms" => $searchTerms ));
-			}
-			else {
-				// if there is no article id, then we will show all comments from all posts...
-				$this->_view = new $this->_viewClass( $this->_blogInfo, Array( "article" => null,
-																			   "showStatus" => $showStatus,
-																			   "searchTerms" => $searchTerms ));					
-			}
-			
-            $this->setCommonData();
+			$this->_view = $this->_getView( $articleId, $showStatus, $searchTerms );
+			$this->setCommonData();
 
             // better to return true if everything fine
             return true;
+        }
+
+		/**
+         * Get the correct view of this action
+         */
+        function _getView( $articleId, $showStatus, $searchTerms )
+        {
+        	if( $articleId && $articleId > 0 ) {
+				$articles = new Articles();
+				$article = $articles->getBlogArticle( $articleId, $this->_blogInfo->getId());
+				if( !$article ) {
+					// if article does not exist we better return the comments list with default parameters
+					// instead of post list in original design.
+					$view = new $this->_viewClass( $this->_blogInfo, Array( "article" => null,
+																			"showStatus" => -1,
+																			"searchTerms" => "" ));
+					$view->setErrorMessage( $this->_locale->tr("error_fetching_article" ));				
+				}			
+				else
+					$view = new $this->_viewClass( $this->_blogInfo, Array( "article" => $article,
+																			"showStatus" => $showStatus,
+																			"searchTerms" => $searchTerms ));
+			}
+			else {
+				// if there is no article id, then we will show all comments from all posts...
+				$view = new $this->_viewClass( $this->_blogInfo, Array( "article" => null,
+																		"showStatus" => $showStatus,
+																		"searchTerms" => $searchTerms ));					
+			}
+
+			return $view;
         }
     }
 ?>
\ No newline at end of file



More information about the pLog-svn mailing list