[pLog-svn] r3311 - in plog/trunk/class/dao: . customfields userdata

oscar at devel.lifetype.net oscar at devel.lifetype.net
Mon May 1 20:26:21 GMT 2006


Author: oscar
Date: 2006-05-01 20:26:21 +0000 (Mon, 01 May 2006)
New Revision: 3311

Added:
   plog/trunk/class/dao/daocacheconstants.properties.php
Modified:
   plog/trunk/class/dao/articlecategories.class.php
   plog/trunk/class/dao/articles.class.php
   plog/trunk/class/dao/blogcategories.class.php
   plog/trunk/class/dao/blogs.class.php
   plog/trunk/class/dao/commentscommon.class.php
   plog/trunk/class/dao/customfields/customfields.class.php
   plog/trunk/class/dao/customfields/customfieldsvalues.class.php
   plog/trunk/class/dao/globalarticlecategories.class.php
   plog/trunk/class/dao/mylinks.class.php
   plog/trunk/class/dao/mylinkscategories.class.php
   plog/trunk/class/dao/recentarticles.class.php
   plog/trunk/class/dao/userdata/baseuserdataprovider.class.php
   plog/trunk/class/dao/userpermissions.class.php
Log:
Fixed the issue with category sorting. I moved all the CACHE_xxx constants to their own file, daocacheconstants.properties.php, so that it is easiser to access just the constant whenever needed instead of loading the whole class for just one constant. No more major changes other than ArticleCategories::getBlogCategories, and a small bugfix in MyLinksCategories::getMyLinksCategories


Modified: plog/trunk/class/dao/articlecategories.class.php
===================================================================
--- plog/trunk/class/dao/articlecategories.class.php	2006-05-01 20:17:11 UTC (rev 3310)
+++ plog/trunk/class/dao/articlecategories.class.php	2006-05-01 20:26:21 UTC (rev 3311)
@@ -3,6 +3,7 @@
 	include_once( PLOG_CLASS_PATH."class/dao/model.class.php" );
     include_once( PLOG_CLASS_PATH."class/dao/articlecategory.class.php" );
     include_once( PLOG_CLASS_PATH."class/data/textfilter.class.php" );
+	include_once( PLOG_CLASS_PATH."class/dao/daocacheconstants.properties.php" );
 	
 	/* 	
 	 * different modes in which the listing of categories can be obtained
@@ -15,14 +16,8 @@
 	define( "BLOG_CATEGORIES_REVERSE_ALPHABETICAL_ORDER", 5 );
 	define( "BLOG_CATEGORIES_MOST_ARTICLES_FIRST", 6 );
 	
-	/**
-	 * cache ids used by this class
-	 */
-	define( "CACHE_ARTICLE_CATEGORIES", "article_categories" );
-	define( "CACHE_ARTICLE_CATEGORIES_BYNAME", "article_categories_byname" );
-	define( "CACHE_ARTICLE_CATEGORIES_BLOG", "article_categories_blog" );
-	define( "CACHE_ARTICLE_CATEGORIES_LINK", "article_categories_link" );
 
+
 	/**
 	 * \ingroup DAO
 	 *	
@@ -132,16 +127,45 @@
 		 * @param itemsPerPage
          * @return An array containing all the categories from a given blog.
          */
-        function getBlogCategories( $blogId, $onlyInMainPage = false, $order = BLOG_CATEGORIES_DEFAULT_ORDER, $searchTerms = "", $page = -1, $itemsPerPage = 15 )
+        function getBlogCategories( $blogId, 
+		                            $onlyInMainPage = false, 
+									$order = BLOG_CATEGORIES_DEFAULT_ORDER, 
+									$searchTerms = "", 
+									$page = -1, 
+									$itemsPerPage = 15 )
         {
+			switch( $order ) {
+				case BLOG_CATEGORIES_MOST_RECENT_UPDATED_FIRST:
+					$sorting = Array( "last_modification" => "DESC" );
+					break;
+				case BLOG_CATEGORIES_OLDEST_FIRST:
+					$sorting = Array( "id" => "ASC" );
+					break;
+				case BLOG_CATEGORIES_NEWEST_FIRST:
+					$sorting = Array( "id" => "DESC" );
+					break;
+				case BLOG_CATEGORIES_ALPHABETICAL_ORDER:
+					$sorting = Array( "name" => "ASC" );
+					break;
+				case BLOG_CATEGORIES_REVERSE_ALPHABETICAL_ORDER:
+					$sorting = Array( "name" => "DESC" );
+					break;
+				case BLOG_CATEGORIES_MOST_ARTICLES_FIRST:
+					$sorting = Array( "num_published_articles" => "DESC" );
+					break;
+				default:
+					$sorting = Array();
+					break;
+			}
+			
+			print_r($sorting);
+		
 			$categories = $this->getMany( "blog_id",
 			                              $blogId,
 			                              CACHE_ARTICLE_CATEGORIES_BLOG,
 			                              Array( CACHE_ARTICLE_CATEGORIES => "getId" ),
-			                              Array(),
-										  $searchTerms,
-			                              $page,
-			                              $itemsPerPage );
+			                              $sorting,
+										  $searchTerms );
 			                              
 			if( !$categories )
 				return Array();
@@ -159,6 +183,13 @@
             }
             else
             	$result = $categories;
+				
+			// apply the slicing
+        	if( $page > -1 ) {
+        		// return only a subset of the items
+				$start = (($page - 1) * $itemsPerPage );
+                $result = array_slice( $result, $start, $itemsPerPage );        		
+        	}			
             	
             return( $result );
 		}		

Modified: plog/trunk/class/dao/articles.class.php
===================================================================
--- plog/trunk/class/dao/articles.class.php	2006-05-01 20:17:11 UTC (rev 3310)
+++ plog/trunk/class/dao/articles.class.php	2006-05-01 20:26:21 UTC (rev 3311)
@@ -3,14 +3,7 @@
     include_once( PLOG_CLASS_PATH.'class/dao/model.class.php' );
     include_once( PLOG_CLASS_PATH.'class/dao/article.class.php' );
     include_once( PLOG_CLASS_PATH.'class/dao/articlestatus.class.php' );
-
-	/**
-	 * cache ids used by this class
-	 */
-    define( "CACHE_ARTICLES",            "articles" );
-    define( "CACHE_ARTICLES_BYNAME",     "articles_byname" );    
-    define( "CACHE_ARTICLETEXT",         "article_text" );    
-    define( "CACHE_ARTICLESPERMONTH",    "articles_per_month" );
+	include_once( PLOG_CLASS_PATH.'class/dao/daocacheconstants.properties.php' );
     
     /**
 	 * \ingroup DAO

Modified: plog/trunk/class/dao/blogcategories.class.php
===================================================================
--- plog/trunk/class/dao/blogcategories.class.php	2006-05-01 20:17:11 UTC (rev 3310)
+++ plog/trunk/class/dao/blogcategories.class.php	2006-05-01 20:26:21 UTC (rev 3311)
@@ -2,10 +2,8 @@
 
 	include_once( PLOG_CLASS_PATH."class/dao/model.class.php" );
 	include_once( PLOG_CLASS_PATH."class/dao/blogcategory.class.php" );
-	
-	define( "CACHE_BLOGCATEGORIES", "cache_blog_categories" );
-	define( "CACHE_BLOGCATEGORIES_ALL", "cache_blog_categories_all" );	
-	
+	include_once( PLOG_CLASS_PATH."class/dao/daocacheconstants.properties.php" );	
+		
 	class BlogCategories extends Model
 	{
 	

Modified: plog/trunk/class/dao/blogs.class.php
===================================================================
--- plog/trunk/class/dao/blogs.class.php	2006-05-01 20:17:11 UTC (rev 3310)
+++ plog/trunk/class/dao/blogs.class.php	2006-05-01 20:26:21 UTC (rev 3311)
@@ -2,11 +2,8 @@
 
     include_once( PLOG_CLASS_PATH."class/dao/model.class.php" );    
     include_once( PLOG_CLASS_PATH."class/dao/blogstatus.class.php" );
+	include_once( PLOG_CLASS_PATH."class/dao/daocacheconstants.properties.php" );
     
-    define( "CACHE_BLOGINFOS",     "bloginfo" );
-    define( "CACHE_BLOGIDBYNAME",  "bloginfo_idbyname" );    
-    define( "CACHE_BLOGIDBYDOMAIN","bloginfo_idbydomain" ); 
-    
     define( "ALL_BLOG_CATEGORIES", 0 );   
 
     /**
@@ -116,6 +113,12 @@
 									
 				// update blog categories
 				$this->updateBlogCategoriesLink( $blog, $prevVersion );
+				
+				// some settings in the BlogSettings object might affect other database items, such
+				// as the sorting order of categories and link cateegories. Hence, we should reset
+				// those caches too
+				$this->_cache->removeData( $blog->getId(), CACHE_ARTICLE_CATEGORIES_BLOG );
+				$this->_cache->removeData( $blog->getId(), CACHE_MYLINKCATEGORIES_ALL );
 			}
 
             // always return true,

Modified: plog/trunk/class/dao/commentscommon.class.php
===================================================================
--- plog/trunk/class/dao/commentscommon.class.php	2006-05-01 20:17:11 UTC (rev 3310)
+++ plog/trunk/class/dao/commentscommon.class.php	2006-05-01 20:26:21 UTC (rev 3311)
@@ -3,6 +3,7 @@
 	include_once( PLOG_CLASS_PATH."class/dao/model.class.php" );
 	include_once( PLOG_CLASS_PATH."class/dao/articles.class.php" );	
 	include_once( PLOG_CLASS_PATH."class/dao/articlecommentstatus.class.php" );
+	include_once( PLOG_CLASS_PATH."class/dao/daocacheconstants.properties.php" );	
 
 	/** 
 	 * different orders that comments can have
@@ -17,12 +18,6 @@
 	define( "COMMENT_TYPE_TRACKBACK", 2 );	
 	define( "COMMENT_TYPE_ANY", -1 );
 	
-	/**
-	 * caches used
-	 */
-	define( "CACHE_ARTICLE_COMMENTS", "article_comments" );
-	define( "CACHE_ARTICLE_COMMENTS_BYARTICLE", "article_comments_byarticle" );
-
     /**
 	 * \ingroup DAO
 	 *

Modified: plog/trunk/class/dao/customfields/customfields.class.php
===================================================================
--- plog/trunk/class/dao/customfields/customfields.class.php	2006-05-01 20:17:11 UTC (rev 3310)
+++ plog/trunk/class/dao/customfields/customfields.class.php	2006-05-01 20:26:21 UTC (rev 3311)
@@ -3,6 +3,7 @@
 	include_once( PLOG_CLASS_PATH."class/dao/model.class.php" );
 	include_once( PLOG_CLASS_PATH."class/dao/customfields/customfield.class.php" );
 	include_once( PLOG_CLASS_PATH."class/dao/customfields/customfieldsvalues.class.php" );
+	include_once( PLOG_CLASS_PATH."class/dao/daocacheconstants.properties.php" );	
 	
 	/**
 	 * different custom field types available
@@ -16,10 +17,6 @@
 	define( "CUSTOM_FIELD_LIST", 5 );
 	define( "CUSTOM_FIELD_MULTILIST", 6 );
 	
-	define( "CACHE_CUSTOMFIELDS", "customfields" );
-	define( "CACHE_CUSTOMFIELDS_BLOG", "customfields_blog" );
-	define( "CACHE_CUSTOMFIELDS_BY_NAME", "customfields_name" );	
-
 	/**
      * Model for the custom fields
      */

Modified: plog/trunk/class/dao/customfields/customfieldsvalues.class.php
===================================================================
--- plog/trunk/class/dao/customfields/customfieldsvalues.class.php	2006-05-01 20:17:11 UTC (rev 3310)
+++ plog/trunk/class/dao/customfields/customfieldsvalues.class.php	2006-05-01 20:26:21 UTC (rev 3311)
@@ -3,8 +3,7 @@
     include_once( PLOG_CLASS_PATH."class/dao/model.class.php" );
     include_once( PLOG_CLASS_PATH."class/dao/customfields/customfields.class.php" );
     include_once( PLOG_CLASS_PATH."class/dao/customfields/customfieldvaluefactory.class.php" );        
-        
-    define( "CACHE_CUSTOMFIELDVALUES_ARTICLE", "customfieldvalues_article" );
+	include_once( PLOG_CLASS_PATH."class/dao/daocacheconstants.properties.php" );	
 
     /**
      * Model for the values given to certain custom fields

Added: plog/trunk/class/dao/daocacheconstants.properties.php
===================================================================
--- plog/trunk/class/dao/daocacheconstants.properties.php	2006-05-01 20:17:11 UTC (rev 3310)
+++ plog/trunk/class/dao/daocacheconstants.properties.php	2006-05-01 20:26:21 UTC (rev 3311)
@@ -0,0 +1,83 @@
+<?php
+
+	/**
+	 * article categories
+	 */
+	define( "CACHE_ARTICLE_CATEGORIES", "article_categories" );
+	define( "CACHE_ARTICLE_CATEGORIES_BYNAME", "article_categories_byname" );
+	define( "CACHE_ARTICLE_CATEGORIES_BLOG", "article_categories_blog" );
+	define( "CACHE_ARTICLE_CATEGORIES_LINK", "article_categories_link" );
+	
+	/**
+	 * articles
+	 */
+    define( "CACHE_ARTICLES",            "articles" );
+    define( "CACHE_ARTICLES_BYNAME",     "articles_byname" );    
+    define( "CACHE_ARTICLETEXT",         "article_text" );    
+    define( "CACHE_ARTICLESPERMONTH",    "articles_per_month" );	
+	
+	/**
+	 * blog categories
+	 */
+	define( "CACHE_BLOGCATEGORIES", "cache_blog_categories" );
+	define( "CACHE_BLOGCATEGORIES_ALL", "cache_blog_categories_all" );		
+
+	/**
+	 * blogs
+	 */
+    define( "CACHE_BLOGINFOS",     "bloginfo" );
+    define( "CACHE_BLOGIDBYNAME",  "bloginfo_idbyname" );    
+    define( "CACHE_BLOGIDBYDOMAIN","bloginfo_idbydomain" ); 
+    
+	/**
+	 * article comments
+	 */
+	define( "CACHE_ARTICLE_COMMENTS", "article_comments" );
+	define( "CACHE_ARTICLE_COMMENTS_BYARTICLE", "article_comments_byarticle" );
+	 
+	/**
+	 * custom fields
+	 */
+	define( "CACHE_CUSTOMFIELDS", "customfields" );
+	define( "CACHE_CUSTOMFIELDS_BLOG", "customfields_blog" );
+	define( "CACHE_CUSTOMFIELDS_BY_NAME", "customfields_name" );	
+
+	/**
+	 * custom field values
+	 */
+    define( "CACHE_CUSTOMFIELDVALUES_ARTICLE", "customfieldvalues_article" );
+	
+	/**
+	 * article global categories
+	 */
+	define( "CACHE_GLOBALCATEGORIES", "cache_global_categories" );
+	define( "CACHE_GLOBALCATEGORIES_ALL", "cache_global_categories_all" );	
+	
+	/**
+	 * links
+	 */
+	define( "CACHE_MYLINKS_ALL", "cache_mylinks_all" );
+	define( "CACHE_MYLINKS", "cache_mylinks" );
+
+	/**
+	 * recent articles
+	 */
+	define( "CACHE_RECENT_ARTICLES_BY_BLOG", "recent_articles_by_blog" );
+	
+	/**
+	 * link categories
+	 */
+	define( "CACHE_MYLINKCATEGORIES_ALL", "mylinks_categories_all" );
+	define( "CACHE_MYLINKCATEGORIES", "mylinks_categories" );
+
+	/**
+	 * users
+	 */
+    define( "CACHE_USERINFO", "userinfo" );
+    define( "CACHE_USERIDBYNAME", "userinfo_idbyname" );
+	 
+	/**
+	 * user permissions
+	 */
+	define( "CACHE_USER_PERMISSIONS", "user_permissions" );	 
+?>
\ No newline at end of file

Modified: plog/trunk/class/dao/globalarticlecategories.class.php
===================================================================
--- plog/trunk/class/dao/globalarticlecategories.class.php	2006-05-01 20:17:11 UTC (rev 3310)
+++ plog/trunk/class/dao/globalarticlecategories.class.php	2006-05-01 20:26:21 UTC (rev 3311)
@@ -2,10 +2,8 @@
 
 	include_once( PLOG_CLASS_PATH."class/dao/model.class.php" );
 	include_once( PLOG_CLASS_PATH."class/dao/globalarticlecategory.class.php" );
+	include_once( PLOG_CLASS_PATH."class/dao/daocacheconstants.properties.php" );	
 	
-	define( "CACHE_GLOBALCATEGORIES", "cache_global_categories" );
-	define( "CACHE_GLOBALCATEGORIES_ALL", "cache_global_categories_all" );	
-	
 	class GlobalArticleCategories extends Model
 	{
 	

Modified: plog/trunk/class/dao/mylinks.class.php
===================================================================
--- plog/trunk/class/dao/mylinks.class.php	2006-05-01 20:17:11 UTC (rev 3310)
+++ plog/trunk/class/dao/mylinks.class.php	2006-05-01 20:26:21 UTC (rev 3311)
@@ -3,10 +3,8 @@
 	include_once( PLOG_CLASS_PATH."class/dao/model.class.php" );
     include_once( PLOG_CLASS_PATH."class/dao/mylink.class.php" );
 	include_once( PLOG_CLASS_PATH."class/dao/mylinkscategories.class.php" );
+	include_once( PLOG_CLASS_PATH."class/dao/daocacheconstants.properties.php" );	
 	
-	define( "CACHE_MYLINKS_ALL", "cache_mylinks_all" );
-	define( "CACHE_MYLINKS", "cache_mylinks" );
-
     /**
 	 * \ingroup DAO
 	 *

Modified: plog/trunk/class/dao/mylinkscategories.class.php
===================================================================
--- plog/trunk/class/dao/mylinkscategories.class.php	2006-05-01 20:17:11 UTC (rev 3310)
+++ plog/trunk/class/dao/mylinkscategories.class.php	2006-05-01 20:26:21 UTC (rev 3311)
@@ -3,6 +3,7 @@
 	include_once( PLOG_CLASS_PATH."class/dao/model.class.php" );
     include_once( PLOG_CLASS_PATH."class/dao/mylinkscategory.class.php" );
     include_once( PLOG_CLASS_PATH."class/dao/mylinks.class.php" );
+	include_once( PLOG_CLASS_PATH."class/dao/daocacheconstants.properties.php" );	
 	
 	define( "MYLINKS_CATEGORIES_NO_ORDER", 0 );
 	define( "MYLINKS_CATEGORIES_ALPHABETICAL_ORDER", 1 );
@@ -12,12 +13,6 @@
 	define( "MYLINKS_CATEGORIES_LAST_UPDATED_FIRST", 5 );
 	define( "MYLINKS_CATEGORIES_LAST_UPDATED_LAST", 6 );
 	
-	/**
-	 * cache ids
-	 */
-	define( "CACHE_MYLINKCATEGORIES_ALL", "mylinks_categories_all" );
-	define( "CACHE_MYLINKCATEGORIES", "mylinks_categories" );
-
     /**
 	 * \ingroup DAO
 	 *
@@ -72,12 +67,17 @@
                                              CACHE_MYLINKCATEGORIES_ALL, 
                                              Array( CACHE_MYLINKCATEGORIES => "getId" ),
                                              $order,
-											 $searchTerms,
-                                             $page,
-                                             $itemsPerPage );
+											 $searchTerms );
                                              
             if( !$blogCategories )
             	$blogCategories = Array();
+				
+			// apply the slicing
+        	if( $page > -1 ) {
+        		// return only a subset of the items
+				$start = (($page - 1) * $itemsPerPage );
+                $blogCategories = array_slice( $blogCategories, $start, $itemsPerPage );        		
+        	}						
                                              
             return( $blogCategories );
         }

Modified: plog/trunk/class/dao/recentarticles.class.php
===================================================================
--- plog/trunk/class/dao/recentarticles.class.php	2006-05-01 20:17:11 UTC (rev 3310)
+++ plog/trunk/class/dao/recentarticles.class.php	2006-05-01 20:26:21 UTC (rev 3311)
@@ -1,13 +1,12 @@
 <?php
 
 	include_once( PLOG_CLASS_PATH."class/dao/articles.class.php" );
+	include_once( PLOG_CLASS_PATH."class/dao/daocacheconstants.properties.php" );	
 
 	/**
 	 * small wrapper to Articles that loads and caches recent articles. As an API user, you probably
 	 * don't need to use this class unless you're implementing your own front-end to LifeType.
 	 */
-	 
-	define( "CACHE_RECENT_ARTICLES_BY_BLOG", "recent_articles_by_blog" );
 	
 	/**
 	 * @see Articles

Modified: plog/trunk/class/dao/userdata/baseuserdataprovider.class.php
===================================================================
--- plog/trunk/class/dao/userdata/baseuserdataprovider.class.php	2006-05-01 20:17:11 UTC (rev 3310)
+++ plog/trunk/class/dao/userdata/baseuserdataprovider.class.php	2006-05-01 20:26:21 UTC (rev 3311)
@@ -3,10 +3,8 @@
 	include_once( PLOG_CLASS_PATH."class/dao/model.class.php" );
 	include_once( PLOG_CLASS_PATH."class/dao/userstatus.class.php" );
     include_once( PLOG_CLASS_PATH."class/dao/blogstatus.class.php" );
+	include_once( PLOG_CLASS_PATH."class/dao/daocacheconstants.properties.php" );	
     
-    define( "CACHE_USERINFO", "userinfo" );
-    define( "CACHE_USERIDBYNAME", "userinfo_idbyname" );
-
 	/**
 	 * This is the base class that defines the methods that all user-data providers must implement.
 	 * It also provides some common methods that will be shared by all user-data providers and that therefore

Modified: plog/trunk/class/dao/userpermissions.class.php
===================================================================
--- plog/trunk/class/dao/userpermissions.class.php	2006-05-01 20:17:11 UTC (rev 3310)
+++ plog/trunk/class/dao/userpermissions.class.php	2006-05-01 20:26:21 UTC (rev 3311)
@@ -2,6 +2,7 @@
 
     include_once( PLOG_CLASS_PATH."class/dao/model.class.php" );
     include_once( PLOG_CLASS_PATH."class/dao/userpermission.class.php" );
+	include_once( PLOG_CLASS_PATH."class/dao/daocacheconstants.properties.php" );	
 
     //
     // :KLUDGE: This should be done in a better way...
@@ -9,8 +10,6 @@
     define( "PERMISSION_SITE_ADMIN", 1 );
     define( "PERMISSION_BLOG_USER", 2 );
     define( "PERMISSION_BLOG_OWNER", 3 );
-	
-	define( "CACHE_USER_PERMISSIONS", "user_permissions" );
 
     /**
      * Handles user permissions.



More information about the pLog-svn mailing list