[pLog-svn] r574 - in plog/trunk/class/dao: . status

oscar at devel.plogworld.net oscar at devel.plogworld.net
Thu Dec 23 23:34:26 GMT 2004


Author: oscar
Date: 2004-12-23 23:34:25 +0000 (Thu, 23 Dec 2004)
New Revision: 574

Added:
   plog/trunk/class/dao/status/
   plog/trunk/class/dao/status/genericstatuslist.class.php
Modified:
   plog/trunk/class/dao/articlecommentstatus.class.php
   plog/trunk/class/dao/articlestatus.class.php
   plog/trunk/class/dao/blogstatus.class.php
   plog/trunk/class/dao/userstatus.class.php
Log:
factored out a bit of code and moved it to a generic class that is now called by all the *status.class.php classes


Modified: plog/trunk/class/dao/articlecommentstatus.class.php
===================================================================
--- plog/trunk/class/dao/articlecommentstatus.class.php	2004-12-23 23:33:47 UTC (rev 573)
+++ plog/trunk/class/dao/articlecommentstatus.class.php	2004-12-23 23:34:25 UTC (rev 574)
@@ -5,7 +5,7 @@
      */
 
 
-    include_once( PLOG_CLASS_PATH."class/object/object.class.php" );
+    include_once( PLOG_CLASS_PATH."class/dao/status/genericstatuslist.class.php" );
 	
     /**
      * different statuses that a comments can have. Works in exactly the same way as the
@@ -14,9 +14,9 @@
      */
 	define( "COMMENT_STATUS_ALL", -1, true ); 
 	define( "COMMENT_STATUS_NONSPAM", 0, true );
-    define( "COMMENT_STATUS_SPAM", 1, true );	
+    define( "COMMENT_STATUS_SPAM", 1, true );
     
-    class ArticleCommentStatus extends Object
+    class ArticleCommentStatus extends GenericStatusList
     {
     
         /**
@@ -31,22 +31,7 @@
          */
         function getStatusList( $includeStatusAll = false )
         {
-            // get all the constants defined so far
-            $constants = get_defined_constants();
-            $statusList = Array();
-			
-			if( $includeStatusAll )
-				$statusList[ "comment_status_all"] = -1;			
-
-            foreach( $constants as $constant => $value ) {
-                if( substr( $constant, 0, 15 ) == "COMMENT_STATUS_" && $constant != "COMMENT_STATUS_ALL" ) {
-					$this->log->debug("Adding $constant");
-					$constant = strtolower($constant);
-                    $statusList[ "$constant" ] = $value;
-                }
-            }
-			
-            return $statusList;
+			return( GenericStatusList::getStatusList( "COMMENT_STATUS_", "COMMENT_STATUS_ALL", $includeStatusAll ));
         }
 		
 		/**

Modified: plog/trunk/class/dao/articlestatus.class.php
===================================================================
--- plog/trunk/class/dao/articlestatus.class.php	2004-12-23 23:33:47 UTC (rev 573)
+++ plog/trunk/class/dao/articlestatus.class.php	2004-12-23 23:34:25 UTC (rev 574)
@@ -5,7 +5,7 @@
      */
 
 
-    include_once( PLOG_CLASS_PATH."class/object/object.class.php" );
+    include_once( PLOG_CLASS_PATH."class/dao/status/genericstatuslist.class.php" );
 	
     /**
      * different statuses that a post can have. These are the default status.
@@ -16,7 +16,7 @@
     define( "POST_STATUS_DRAFT", 2, true );
     define( "POST_STATUS_DELETED", 3, true );	
     
-    class ArticleStatus extends Object
+    class ArticleStatus extends GenericStatusList
     {
     
         /**
@@ -29,21 +29,7 @@
          */
         function getStatusList( $includeStatusAll = false )
         {
-            // get all the constants defined so far
-            $constants = get_defined_constants();
-            $statusList = Array();
-			
-			if( $includeStatusAll )
-				$statusList[ "post_status_all"] = -1;			
-
-            foreach( $constants as $constant => $value ) {
-                if( substr( $constant, 0, 12 ) == "POST_STATUS_" && $constant != "POST_STATUS_ALL" ) {
-					$constant = strtolower($constant);
-                    $statusList[ "$constant" ] = $value;
-                }
-            }
-			
-            return $statusList;
+			return( GenericStatusList::getStatusList( "POST_STATUS_", "POST_STATUS_ALL", $includeStatusAll ));
         }
     }
 ?>
\ No newline at end of file

Modified: plog/trunk/class/dao/blogstatus.class.php
===================================================================
--- plog/trunk/class/dao/blogstatus.class.php	2004-12-23 23:33:47 UTC (rev 573)
+++ plog/trunk/class/dao/blogstatus.class.php	2004-12-23 23:34:25 UTC (rev 574)
@@ -1,70 +1,56 @@
-<?php
-
-    /**
-     * @package dao
-     */
-
-
-    include_once( PLOG_CLASS_PATH."class/object/object.class.php" );
-	
-    /**
-     * different statuses that a blog can have. These are the default status.
-	 * 
-     */
-	define( "BLOG_STATUS_ALL", -1, true ); 
-    define( "BLOG_STATUS_ACTIVE", 1, true );
-    define( "BLOG_STATUS_DISABLED", 2, true );
-    define( "BLOG_STATUS_UNCONFIRMED", 3, true );
-    
-    class BlogStatus extends Object
-    {
-    
-        /**
-         * returns a list with all the user statuses that have been defined
-         * so far in the code.
-         *
-         * @return Returns an array where every position is an array with two
-         * keys: "constant" and "value", where "constant" is the name of the constant
-         * that defines this status and "value" is the value assigned to it
-         */
-        function getStatusList( $includeStatusAll = false )
-        {
-            // get all the constants defined so far
-            $constants = get_defined_constants();
-            $statusList = Array();
-			
-			if( $includeStatusAll )
-				$statusList[ "blog_status_all"] = -1;			
-
-            foreach( $constants as $constant => $value ) {
-                if( substr( $constant, 0, 12 ) == "BLOG_STATUS_" && $constant != "BLOG_STATUS_ALL" ) {
-					$constant = strtolower($constant);
-                    $statusList[ "$constant" ] = $value;
-                }
-            }
-			
-            return $statusList;
-        }
-        
-        /**
-         * @param status The status code we'd like to check
-         * 
-         * @return Returns true if the status is valid or false otherwise
-         */
-        function isValidStatus( $status )
-        {
-	    	$statusList = BlogStatus::getStatusList( true );
-	    	return( in_array( $status, $statusList ));
-        }
-        
-        /**
-         * returns the default status code for this class
-         *
-         * @return The default status
-         */
-        function getDefaultStatus()
-        {
-	     	return( BLOG_STATUS_ALL );   
-        }        
-    }
+<?php
+
+    /**
+     * @package dao
+     */
+
+
+    include_once( PLOG_CLASS_PATH."class/dao/status/genericstatuslist.class.php" );
+	
+    /**
+     * different statuses that a blog can have. These are the default status.
+	 * 
+     */
+	define( "BLOG_STATUS_ALL", -1, true ); 
+    define( "BLOG_STATUS_ACTIVE", 1, true );
+    define( "BLOG_STATUS_DISABLED", 2, true );
+    define( "BLOG_STATUS_UNCONFIRMED", 3, true );
+    
+    class BlogStatus extends GenericStatusList
+    {
+    
+        /**
+         * returns a list with all the user statuses that have been defined
+         * so far in the code.
+         *
+         * @return Returns an array where every position is an array with two
+         * keys: "constant" and "value", where "constant" is the name of the constant
+         * that defines this status and "value" is the value assigned to it
+         */
+        function getStatusList( $includeStatusAll = false )
+        {
+            return( GenericStatusList::getStatusList( "BLOG_STATUS_", "BLOG_STATUS_ALL", $includeStatusAll ));
+        }
+        
+        /**
+         * @param status The status code we'd like to check
+         * 
+         * @return Returns true if the status is valid or false otherwise
+         */
+        function isValidStatus( $status )
+        {
+	    	$statusList = BlogStatus::getStatusList( true );
+	    	return( in_array( $status, $statusList ));
+        }
+        
+        /**
+         * returns the default status code for this class
+         *
+         * @return The default status
+         */
+        function getDefaultStatus()
+        {
+	     	return( BLOG_STATUS_ALL );   
+        }        
+    }
 ?>
\ No newline at end of file

Added: plog/trunk/class/dao/status/genericstatuslist.class.php
===================================================================
--- plog/trunk/class/dao/status/genericstatuslist.class.php	2004-12-23 23:33:47 UTC (rev 573)
+++ plog/trunk/class/dao/status/genericstatuslist.class.php	2004-12-23 23:34:25 UTC (rev 574)
@@ -0,0 +1,65 @@
+<?php
+
+    /**
+     * @package dao
+     */
+
+
+    include_once( PLOG_CLASS_PATH."class/object/object.class.php" );
+	
+    class GenericStatusList extends Object
+    {
+    
+        /**
+         * returns a list with all the user statuses that have been defined
+         * so far in the code.
+         *
+         * @return Returns an array where every position is an array with two
+         * keys: "constant" and "value", where "constant" is the name of the constant
+         * that defines this status and "value" is the value assigned to it
+         */
+        function getStatusList( $prefix, $statusAllId, $includeStatusAll = false )
+        {
+            // get all the constants defined so far
+            $constants = get_defined_constants();
+            $statusList = Array();
+			
+			if( $includeStatusAll ) {
+				$statusAllLowercase = strtolower( $statusAllId );
+				$statusList["$statusAllLowercase"] = -1;
+			}
+
+            foreach( $constants as $constant => $value ) {
+                if( substr( $constant, 0, 12 ) == $prefix && $constant != $statusAllId ) {
+					$constant = strtolower($constant);
+                    $statusList[ "$constant" ] = $value;
+                }
+            }
+			
+            return $statusList;
+        }
+        
+        /**
+         * @param status The status code we'd like to check
+         * 
+         * @return Returns true if the status is valid or false otherwise. By default this
+		 * class returns always true so please override it in your own implementations!
+         */
+        function isValidStatus( $status )
+        {
+			return( true );
+        }
+        
+        /**
+         * returns the default status code for this class. By default, it is just 'true'
+		 * so it is advisable that classes inheriting from this one override this method
+		 * with their own
+         *
+         * @return The default status
+         */
+        function getDefaultStatus()
+        {
+	     	return( true );
+        }        
+    }
+?>
\ No newline at end of file

Modified: plog/trunk/class/dao/userstatus.class.php
===================================================================
--- plog/trunk/class/dao/userstatus.class.php	2004-12-23 23:33:47 UTC (rev 573)
+++ plog/trunk/class/dao/userstatus.class.php	2004-12-23 23:34:25 UTC (rev 574)
@@ -5,7 +5,7 @@
      */
 
 
-    include_once( PLOG_CLASS_PATH."class/object/object.class.php" );
+    include_once( PLOG_CLASS_PATH."class/dao/status/genericstatuslist.class.php" );
 	
     /**
      * different statuses that a user can have. These are the default status.
@@ -16,7 +16,7 @@
     define( "USER_STATUS_DISABLED", 2, true );
     define( "USER_STATUS_UNCONFIRMED", 3, true );
     
-    class UserStatus extends Object
+    class UserStatus extends GenericStatusList
     {
     
         /**
@@ -29,21 +29,7 @@
          */
         function getStatusList( $includeStatusAll = false )
         {
-            // get all the constants defined so far
-            $constants = get_defined_constants();
-            $statusList = Array();
-			
-			if( $includeStatusAll )
-				$statusList[ "user_status_all"] = -1;			
-
-            foreach( $constants as $constant => $value ) {
-                if( substr( $constant, 0, 12 ) == "USER_STATUS_" && $constant != "USER_STATUS_ALL" ) {
-					$constant = strtolower($constant);
-                    $statusList[ "$constant" ] = $value;
-                }
-            }
-			
-            return $statusList;
+			return( GenericStatusList::getStatusList( "USER_STATUS_", "USER_STATUS_ALL", $includeStatusAll ));
         }
         
         /**




More information about the pLog-svn mailing list