[pLog-svn] r6301 - plog/trunk/class/dao

Jon Daley plogworld at jon.limedaley.com
Mon Apr 7 16:24:18 EDT 2008


 	Hrm, that's not as nice as the Topic/Slug solution for an article. 
I am more in favor of someone having to change their code once, rather 
than everyone having to wonder why "real" name is needed, and perhaps 
using just plain "name" instead.

On Mon, 7 Apr 2008, mark at devel.lifetype.net wrote:

> 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
>
> _______________________________________________
> pLog-svn mailing list
> pLog-svn at devel.lifetype.net
> http://limedaley.com/mailman/listinfo/plog-svn
>

-- 
Jon Daley
http://jon.limedaley.com/

We're not afraid of challenges. It's like I always say:
if you want to go out in the rain, be prepared to get burned.


More information about the pLog-svn mailing list