[pLog-svn] r6301 - plog/trunk/class/dao
mark at devel.lifetype.net
mark at devel.lifetype.net
Mon Apr 7 16:08:35 EDT 2008
Author: mark
Date: 2008-04-07 16:08:35 -0400 (Mon, 07 Apr 2008)
New Revision: 6301
Modified:
plog/trunk/class/dao/articlecategories.class.php
Log:
Add a new method getCategoryByRealName() to help developer to get the category by "real name" instead of "mangled name"...
A better way is to refactoring our code to make them following the DB schema naming.
Modified: plog/trunk/class/dao/articlecategories.class.php
===================================================================
--- plog/trunk/class/dao/articlecategories.class.php 2008-04-07 08:46:39 UTC (rev 6300)
+++ plog/trunk/class/dao/articlecategories.class.php 2008-04-07 20:08:35 UTC (rev 6301)
@@ -55,7 +55,7 @@
}
/**
- * returns a category based on its name
+ * returns a category based on its mangled name
*
* @param categoryName
* @param blogId
@@ -91,6 +91,50 @@
else
return false;
}
+
+ /**
+ * returns a category based on its name
+ *
+ * @param categoryName
+ * @param blogId
+ * @return An ArticleCategory object
+ */
+ function getCategoryByRealName( $categoryName, $blogId = -1 )
+ {
+ if(!$categoryName)
+ return false;
+
+ // load all the articles with the same title
+ $query = "SELECT id FROM ".$this->getPrefix()."articles_categories
+ WHERE name='".LtDb::qstr($categoryName)."'";
+
+ // execute the query and process the result if any
+ $result = $this->Execute( $query );
+ if( !$result )
+ return( false );
+
+ $categories = Array();
+ while( $row = $result->FetchRow()) {
+ $categories[] = $this->getCategory( $row['id'] );
+ }
+
+ // there might be more than one in several different blogs...
+ $found = false;
+ //while( !$found ) {
+ foreach( $categories as $category ) {
+ //$category = array_pop( $categories );
+ if( $blogId > -1 && $category->getBlogId() == $blogId ) {
+ $found = true;
+ break;
+ }
+ }
+
+ // check if we found something...
+ if( $found )
+ return( $category );
+ else
+ return false;
+ }
/**
* @see Model::getSearchConditions
More information about the pLog-svn
mailing list