[pLog-svn] r871 - plugins/trunk/hostblock/class/action

mark at devel.plogworld.net mark at devel.plogworld.net
Fri Jan 28 16:55:20 GMT 2005


Author: mark
Date: 2005-01-28 16:55:19 +0000 (Fri, 28 Jan 2005)
New Revision: 871

Modified:
   plugins/trunk/hostblock/class/action/admindeleteblockedhostaction.class.php
   plugins/trunk/hostblock/class/action/admindeleteblogblockedhostaction.class.php
Log:


Modified: plugins/trunk/hostblock/class/action/admindeleteblockedhostaction.class.php
===================================================================
--- plugins/trunk/hostblock/class/action/admindeleteblockedhostaction.class.php	2005-01-28 09:51:48 UTC (rev 870)
+++ plugins/trunk/hostblock/class/action/admindeleteblockedhostaction.class.php	2005-01-28 16:55:19 UTC (rev 871)
@@ -76,7 +76,6 @@
 					else
 						$successMessage = $this->_locale->pr("blocked_host_deleted_ok", $blockedHost->getHost());
 					$this->notifyEvent( EVENT_POST_BLOCK_HOST_DELETE, Array( "host" => &$blockedHost ));
-										
 				}
             }
 

Modified: plugins/trunk/hostblock/class/action/admindeleteblogblockedhostaction.class.php
===================================================================
--- plugins/trunk/hostblock/class/action/admindeleteblogblockedhostaction.class.php	2005-01-28 09:51:48 UTC (rev 870)
+++ plugins/trunk/hostblock/class/action/admindeleteblogblockedhostaction.class.php	2005-01-28 16:55:19 UTC (rev 871)
@@ -1,17 +1,20 @@
 <?php
 
-	include_once( PLOG_CLASS_PATH."class/action/admin/adminaction.class.php" );
-    include_once( PLOG_CLASS_PATH."class/view/admin/adminmessageview.class.php" );
-    include_once( PLOG_CLASS_PATH."class/view/admin/adminerrorview.class.php" );
+	include_once( PLOG_CLASS_PATH."class/action/admin/blogowneradminaction.class.php" );
+    include_once( PLOG_CLASS_PATH."class/data/validator/arrayvalidator.class.php" );    
     include_once( PLOG_CLASS_PATH."plugins/hostblock/class/dao/blockedhosts.class.php" );
+    include_once( PLOG_CLASS_PATH."plugins/hostblock/class/view/adminnewblogblockedhostview.class.php" );
+    include_once( PLOG_CLASS_PATH."plugins/hostblock/class/view/adminblogblockedhostsview.class.php" );    
 
     /**
      * Deletes a post from the database
      */
-    class AdminDeleteBlogBlockedHostAction extends AdminAction 
+    class AdminDeleteBlogBlockedHostAction extends BlogOwnerAdminAction 
 	{
 
     	var $_blockedIds;
+    	var $_hostId;
+    	var $_op;    	
 
     	/**
          * Constructor. If nothing else, it also has to call the constructor of the parent
@@ -19,59 +22,73 @@
          */
         function AdminDeleteBlogBlockedHostAction( $actionInfo, $request )
         {
-        	$this->AdminAction( $actionInfo, $request );
-        }
+        	$this->BlogOwnerAdminAction( $actionInfo, $request );
 
-        /**
-         * Validates that the information coming from the user is valid
-         */
-        function validate()
-        {
-            $this->_blockedIds = $this->_request->getValue( "deleteBlogBlockedHost" );
-
-            if( count($this->_blockedIds) == 0 ) {
-                $this->_view = new AdminErrorView( $this->_blogInfo );
-                $message = $this->_locale->tr( "error_no_blocked_hosts_selected" );
-				$message .= "<br/><br/><a href=\"javascript:history.go(-1);\">".$this->_locale-tr("back")."</a>";
-                $this->setCommonData();
-
-                return false;
-            }
-
-            return true;
+			$this->_op = $actionInfo->getActionParamValue();
+			
+			$view = new AdminBlogBlockedHostsView( $this->_blogInfo );			
+			if( $this->_op == "deleteBlogBlockedHost" ) {
+				$this->registerFieldValidator( "hostId", new IntegerValidator());
+				$view->setErrorMessage( $this->_locale->tr("error_incorrect_host_id"));	
+			}
+			else {
+				$this->registerFieldValidator( "deleteBlogBlockedHost", new ArrayValidator());
+				$view->setErrorMessage( $this->_locale->tr("error_no_block_host_selected"));
+			}
+			$this->setValidationErrorView( $view );          	
         }
 
         /**
          * Carries out the specified action
          */
-        function perform()
+		function perform()
+		{
+			if( $this->_op == "deleteBlogBlockedHost" ) {
+				$this->_blockedIds = Array();
+				$this->_hostId = $this->_request->getValue( "hostId" );
+				$this->_blockedIds[] = $this->_hostId;
+			}
+			else
+				$this->_blockedIds = $this->_request->getValue( "deleteBlogBlockedHost" );
+				
+			$this->_deleteBlogBlockedHosts();
+		}
+
+        function _deleteBlogBlockedHosts()
         {
-        	// delete the post (it is not physically deleted but rather, we set
-            // the status field to 'DELETED'
             $blockedHosts = new BlockedHosts();
-            $message = "";
+
+            // loop through the array of things to remove
+            $errorMessage = "";
+			$successMessage = "";
+			$numOk = 0;
             foreach( $this->_blockedIds as $blockedId ) {
             	// get the post
                 $blockedHost = $blockedHosts->getBlockedHost( $blockedId, $this->_blogInfo->getId());
 				$this->notifyEvent( EVENT_PRE_BLOCK_HOST_DELETE, Array( "host" => &$blockedHost ));
             	$result = $blockedHosts->remove( $blockedId, $this->_blogInfo->getId());
                 if( !$result )
-                	$message .= $this->_locale->pr("error_deleting_blocked_host", $blockedHost->getHost());
+                    $errorMessage .= $this->_locale->pr("error_deleting_blocked_host", $blockedHost->getHost())."<br/>";
                 else {
-                	$message .= $this->_locale->pr("blocked_host_deleted_ok", $blockedHost->getHost());
-					$this->notifyEvent( EVENT_POST_BLOCK_HOST_DELETE, Array( "host" => &$blockedHost )); 
+					$numOk++;
+					if( $numOk > 1 )
+						$successMessage = $this->_locale->pr("blocked_hosts_deleted_ok", $numOk );
+					else
+						$successMessage = $this->_locale->pr("blocked_host_deleted_ok", $blockedHost->getHost());
+					$this->notifyEvent( EVENT_POST_BLOCK_HOST_DELETE, Array( "host" => &$blockedHost ));					
 				}
-
-                $message .= "<br/><br/>";
             }
 
-
-            $this->_view = new AdminMessageView( $this->_blogInfo );
-            $message .= "<a href=\"admin.php?op=blogBlockedHosts\">".$this->_locale->tr("back")."</a>";
-            $this->_view->setValue( "message", $message );
+            $this->_view = new AdminBlogBlockedHostsView( $this->_blogInfo );
+            if( $errorMessage != "" ) $this->_view->setErrorMessage( $errorMessage );
+			if( $successMessage != "" ) $this->_view->setSuccessMessage( $successMessage );
             $this->setCommonData();
+       
+			// clear the cache
+			CacheControl::resetBlogCache( $this->_blogInfo->getId());
 
-            return true;
+            // better to return true if everything fine
+            return true;                    
 
         }
     }




More information about the pLog-svn mailing list