[pLog-svn] r2988 - in plog/trunk/class: action action/admin dao dao/customfields dao/userdata database template/menu

oscar at devel.lifetype.net oscar at devel.lifetype.net
Mon Feb 27 21:36:47 GMT 2006


Author: oscar
Date: 2006-02-27 21:36:46 +0000 (Mon, 27 Feb 2006)
New Revision: 2988

Modified:
   plog/trunk/class/action/addcommentaction.class.php
   plog/trunk/class/action/admin/admindeletecustomfieldsaction.class.php
   plog/trunk/class/action/searchaction.class.php
   plog/trunk/class/dao/article.class.php
   plog/trunk/class/dao/articlecomments.class.php
   plog/trunk/class/dao/articles.class.php
   plog/trunk/class/dao/customfields/customfields.class.php
   plog/trunk/class/dao/customfields/customfieldsvalues.class.php
   plog/trunk/class/dao/customfields/customfieldvalue.class.php
   plog/trunk/class/dao/customfields/customfieldvaluefactory.class.php
   plog/trunk/class/dao/model.class.php
   plog/trunk/class/dao/searchengine.class.php
   plog/trunk/class/dao/searchresult.class.php
   plog/trunk/class/dao/userdata/ploguserdataprovider.class.php
   plog/trunk/class/database/dbobject.class.php
   plog/trunk/class/template/menu/menu.class.php
Log:
One big commit:
- Lots of warnings and notices fixed, which actually helped to find bugs that would have surely popped up later on
- The search engine is working again, at least for blog searches (site-wide searches don't work, but neither is summary.php)
- Custom fields are working again, cache included.

Modified: plog/trunk/class/action/addcommentaction.class.php
===================================================================
--- plog/trunk/class/action/addcommentaction.class.php	2006-02-26 01:42:41 UTC (rev 2987)
+++ plog/trunk/class/action/addcommentaction.class.php	2006-02-27 21:36:46 UTC (rev 2988)
@@ -124,6 +124,7 @@
 			// collect all the errors from all the fields and for those that failed validation,
 			// put them in a nicer string.
 			$results = $this->_form->getFormValidationResults();
+			$errorMessage = "";
 			foreach( $results as $field => $result ) {
 				if( !$result ) {
 					$errorMessage .= $this->_form->getFieldErrorMessage( $field )."<br/><br/>";

Modified: plog/trunk/class/action/admin/admindeletecustomfieldsaction.class.php
===================================================================
--- plog/trunk/class/action/admin/admindeletecustomfieldsaction.class.php	2006-02-26 01:42:41 UTC (rev 2987)
+++ plog/trunk/class/action/admin/admindeletecustomfieldsaction.class.php	2006-02-27 21:36:46 UTC (rev 2988)
@@ -5,6 +5,7 @@
 	include_once( PLOG_CLASS_PATH."class/view/admin/admincustomfieldslistview.class.php" );
 	include_once( PLOG_CLASS_PATH."class/data/validator/arrayvalidator.class.php" );
 	include_once( PLOG_CLASS_PATH."class/action/admin/adminaction.class.php" );
+	include_once( PLOG_CLASS_PATH."class/data/validator/integervalidator.class.php" );
 	
     /**
      * \ingroup Action

Modified: plog/trunk/class/action/searchaction.class.php
===================================================================
--- plog/trunk/class/action/searchaction.class.php	2006-02-26 01:42:41 UTC (rev 2987)
+++ plog/trunk/class/action/searchaction.class.php	2006-02-27 21:36:46 UTC (rev 2988)
@@ -65,9 +65,9 @@
             if( count($searchResults) == 1 ) {
                 // we have to refill the $_REQUEST array, since the next action
                 // is going to need some of the parameters
-                $request =& HttpVars::getRequest();
+                $request = HttpVars::getRequest();
                 $searchResult = array_pop( $searchResults );
-                $article = $searchResult->getArticle();
+                $article = $searchResult->getResult();
                 $request["articleId"] = $article->getId();
                 $request["blogId"] = $this->_blogInfo->getId();
                 HttpVars::setRequest( $request );

Modified: plog/trunk/class/dao/article.class.php
===================================================================
--- plog/trunk/class/dao/article.class.php	2006-02-26 01:42:41 UTC (rev 2987)
+++ plog/trunk/class/dao/article.class.php	2006-02-27 21:36:46 UTC (rev 2988)
@@ -45,6 +45,7 @@
 		var $_prevArticle;
 		var $_globalCategory;
 		var $_inSummary;
+		var $_customFields;
 
         /**
          * Constructor.
@@ -351,13 +352,13 @@
 			// if we only want to return the active ones, then we have to loop through
 			// the array once more			
 			if( $onlyActive ) {
-				$comments = Array();
+				$tbs = Array();
 				foreach( $this->_trackbacks as $trackback ) {
 					if( $trackback->getStatus() == COMMENT_STATUS_NONSPAM )
 						$tbs[] = $trackback;
 				}
 			}
-			else 
+			else
 				$tbs = $this->_trackbacks;
 				
 			return( $tbs );
@@ -826,8 +827,7 @@
 			if( is_null($this->_fields) )
 				$this->getCustomFields();
 		
-			if ( !array_key_exists(  $fieldName, $this->_fields ) )
-			{
+			if ( !array_key_exists(  $fieldName, $this->_fields )) {
 				return null;
 			}
 			

Modified: plog/trunk/class/dao/articlecomments.class.php
===================================================================
--- plog/trunk/class/dao/articlecomments.class.php	2006-02-26 01:42:41 UTC (rev 2987)
+++ plog/trunk/class/dao/articlecomments.class.php	2006-02-27 21:36:46 UTC (rev 2988)
@@ -93,7 +93,11 @@
 		 * returns the lastest $maxItems comments received in the blog
 		 *
 		 * @param blogId
-		 * @param maxItems
+		 * @param order
+		 * @param status
+		 * @param searchTerms,
+		 * @param page
+		 * @param itemsPerPage
 		 * @return An array of ArticleComment objects
 		 */
 		function getBlogComments( $blogId, $order = COMMENT_ORDER_NEWEST_FIRST, $status = COMMENT_STATUS_ALL, $searchTerms = "", $page = -1, $itemsPerPage = DEFAULT_ITEMS_PER_PAGE )

Modified: plog/trunk/class/dao/articles.class.php
===================================================================
--- plog/trunk/class/dao/articles.class.php	2006-02-26 01:42:41 UTC (rev 2987)
+++ plog/trunk/class/dao/articles.class.php	2006-02-27 21:36:46 UTC (rev 2988)
@@ -247,21 +247,6 @@
 		}
 		
 		/**
-		 * a shortcut for getBlogArticles in case we're only interested in searching all the items
-		 * without further refining the search (which is possible if we use the one below)
-		 *
-		 * @param blogId
-		 * @param searchTerms
-		 * @return An array of Article objects or an empty array if no article matched the search terms
-		 */
-		function searchBlogArticles( $blogId, $searchTerms )
-		{
-            // :TODO: implement this :-)
-												 
-			return $posts;
-		}
-		
-		/**
 		 * @see getBlogArticles
 		 */
 		function getNumBlogArticles( $blogId,
@@ -358,12 +343,22 @@
 		     * WHERE article_id IN (id, of, the, articles, whose, article_text, matched)
 			 */
 			 
-			include_once( PLOG_CLASS_PATH."class/dao/searchengine.class.php" );			
-			$searchEngine = new SearchEngine();
+			// prepare the query string			 
+			include_once( PLOG_CLASS_PATH."class/dao/searchengine.class.php" );
+			$searchTerms = SearchEngine::adaptSearchString( $searchTerms );
+			
+            // Split the search term by space
+            $query_array = explode(' ', $searchTerms);
+
+            // For each search terms, I should make a like query for it   
+            $whereString = "(";
+            $whereString .= "((normalized_topic LIKE '%{$query_array[0]}%') OR (normalized_text LIKE '%{$query_array[0]}%'))";
+            for ( $i = 1; $i < count($query_array); $i = $i + 1) {
 				
-			// prepare the query string
-			$searchTerms = $searchEngine->_adaptSearchString( $searchTerms );
-			$whereString = $searchEngine->_generateSearchArticlesWhereString( $searchTerms );
+                $whereString .= " AND ((normalized_topic LIKE '%{$query_array[$i]}%') OR (normalized_text LIKE '%{$query_array[$i]}%'))";
+            }
+            $whereString .= " OR ((normalized_topic LIKE '%{$searchTerms}%') OR (normalized_text LIKE '%{$searchTerms}%'))";
+            $whereString .= ")";			
 				
 			$query = "SELECT article_id FROM ".$this->getPrefix()."articles_text
 			          WHERE $whereString";
@@ -768,10 +763,10 @@
             include_once( PLOG_CLASS_PATH."class/dao/blogs.class.php" );
             
             $result = $this->add( $newArticle );
-            
+			
             if( !$result )
             	return false;
-
+				
 			$this->addArticleText( $newArticle );
 
             // and create the link between the post and its categories
@@ -779,12 +774,13 @@
 
             // and save the custom fields
             $customFields = new CustomFieldsValues();
+			$fields = $newArticle->getCustomFields();
             if( is_array( $fields )) {
             	foreach( $fields as $field ) {
                 	$customFields->addCustomFieldValue( $field->getFieldId(), 
                     	                                $field->getValue(), 
-                        	                            $artId, 
-                            	                        $blogId );
+                        	                            $newArticle->getId(), 
+                            	                        $newArticle->getBlogId());
             	}
         	}
             
@@ -799,7 +795,6 @@
             // and finally clear the cache :)
 			include_once( PLOG_CLASS_PATH."class/dao/recentarticles.class.php" );
 			RecentArticles::resetRecentArticlesCache( $newArticle->getBlogId());
-            $this->_cache->removeData( $newArticle->getBlogId(), CACHE_ARTICLES_BYBLOG );
             $this->_cache->removeData( $newArticle->getBlogId(), CACHE_ARTICLESPERMONTH );
 
             return( $newArticle->getId());
@@ -909,15 +904,14 @@
 			// update the article text
 			$this->updateArticleText( $article );
 
-            /*if( !$this->updatePostCategoriesLink( $article ) ||
-                !$this->updateArticleCustomFields( $article->getId(), $article->getBlog(), 
-                                                   $article->getFields()) )
-                return false;*/
-				
             if( !$this->updatePostCategoriesLink( $article, $oldArticle )) {
                 return false;
 			}
-				
+			
+			if( !$this->updateArticleCustomFields( $article->getId(), $article->getBlogId(), 
+                                                   $article->getCustomFields())) {
+                return false;
+			}
 
             // clean up the cache
 			include_once( PLOG_CLASS_PATH."class/dao/recentarticles.class.php" );
@@ -951,6 +945,8 @@
             // first remove the values
             if( !$customFields->removeArticleCustomFields( $artId ))
                 return false;
+				print("2222");
+							print_r($fields);
 
             foreach( $fields as $field ) {
                 $customFields->addCustomFieldValue( $field->getFieldId(), 
@@ -1070,7 +1066,6 @@
 
 				include_once( PLOG_CLASS_PATH."class/dao/recentarticles.class.php" );
 				RecentArticles::resetRecentArticlesCache( $blogId );                
-	            $this->_cache->removeData( $blogId, CACHE_ARTICLES_BYBLOG );
     	        $this->_cache->removeData( $blogId, CACHE_ARTICLESPERMONTH );
         	    $this->_cache->removeData( $artId, CACHE_ARTICLES );                
             }

Modified: plog/trunk/class/dao/customfields/customfields.class.php
===================================================================
--- plog/trunk/class/dao/customfields/customfields.class.php	2006-02-26 01:42:41 UTC (rev 2987)
+++ plog/trunk/class/dao/customfields/customfields.class.php	2006-02-27 21:36:46 UTC (rev 2988)
@@ -156,7 +156,7 @@
 			if( !$field )
 				return false;
 			
-			if( !$this->delete( "id", $id ));
+			if( !$this->delete( "id", $id ))
 				return false;
 				
 			// clean the caches
@@ -168,7 +168,7 @@
 			
 			// remove the values that were associated to this field
 			$fieldValues = new CustomFieldsValues();
-			return $fieldValues->removeCustomFieldValues( $id );
+			return( $fieldValues->removeCustomFieldValues( $id ));
 		}
 		
 		/**

Modified: plog/trunk/class/dao/customfields/customfieldsvalues.class.php
===================================================================
--- plog/trunk/class/dao/customfields/customfieldsvalues.class.php	2006-02-26 01:42:41 UTC (rev 2987)
+++ plog/trunk/class/dao/customfields/customfieldsvalues.class.php	2006-02-27 21:36:46 UTC (rev 2988)
@@ -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", "customfieldvalues" );    
+        
     define( "CACHE_CUSTOMFIELDVALUES_ARTICLE", "customfieldvalues_article" );
 
     /**
@@ -35,19 +34,19 @@
          * the custom fields available for an article
          *
          * @param articleId The id of the article
-         * @param the blog id to which the fields belong     
          * @param includeHidden Whether to return hidden fields or not
          * @return An array of CustomFieldValue objects, or false if error
          */
-        function getArticleCustomFieldsValues( $articleId, $blogId, $includeHidden = true )
+        function getArticleCustomFieldsValues( $articleId, $includeHidden = true )
         {                   
             $prefix = $this->getPrefix();
             $query = "SELECT v.id AS id, d.id AS field_id, v.field_value AS field_value, 
                              d.field_name AS field_name, d.field_type AS field_type, 
-                             d.field_description AS field_description 
+                             d.field_description AS field_description,
+							 v.article_id AS article_id, v.blog_id AS blog_id
                              FROM {$prefix}custom_fields_values v 
                              RIGHT OUTER JOIN {$prefix}custom_fields_definition d 
-                             ON v.article_id = $articleId AND v.field_id = d.id";
+                             ON v.article_id = ".Db::qstr($articleId)." AND v.field_id = d.id";
                       
             $result = $this->Execute( $query );
             
@@ -80,9 +79,6 @@
         	// but it makes it easier for us if we'd like to use Model::add()
         	$value = new CustomFieldValue( $fieldId, 
         	                               $fieldValue,
-        	                               '',  // doesn't matter
-        	                               -1,  // doesn't matter
-        	                               '', // doesn't matter
         	                               $articleId,
         	                               $blogId );
 			if( $result = $this->add( $value )) {
@@ -106,7 +102,6 @@
         		return false;
         		
         	if( $result = $this->delete( "id", $id )) {
-        		$this->_cache->removeData( $id, CACHE_CUSTOMFIELDVALUES );
         		$this->_cache->removeData( $field->getArticleId(), CACHE_CUSTOMFIELDVALUES_ARTICLE );
         	}
         	return( $result );
@@ -122,11 +117,7 @@
         {
         	$result = $this->delete( "field_id", $fieldId );
 
-        	/**
-        	 * :TODO:
-        	 * clean the caches!!!!!!!
-        	 */        	
-        	return( $result );
+        	return( true );
         }
         
         /**
@@ -137,13 +128,12 @@
          */
         function removeArticleCustomFields( $articleId )
         {
-        	$result = $this->delete( "article_id", $articleId );
-        	
-        	/**
-        	 * :TODO:
-        	 * clean the caches!!!!!!!
-        	 */        	
-        	return( $result );
+        	if( $result = $this->delete( "article_id", $articleId )) {
+				$this->_cache->removeData( $articleId, CACHE_CUSTOMFIELDVALUES_ARTICLE );
+				$result = true;
+			}
+			
+			return( $result );
         }
         
         /**

Modified: plog/trunk/class/dao/customfields/customfieldvalue.class.php
===================================================================
--- plog/trunk/class/dao/customfields/customfieldvalue.class.php	2006-02-26 01:42:41 UTC (rev 2987)
+++ plog/trunk/class/dao/customfields/customfieldvalue.class.php	2006-02-27 21:36:46 UTC (rev 2988)
@@ -27,6 +27,7 @@
 			$this->_articleId = $articleId;
 			$this->_id = $id;
 			$this->_customField = null;
+			$this->_blogId = $blogId;
 			
 			$this->_fields = Array(
 			   "field_id" => "getFieldId",
@@ -74,6 +75,17 @@
 			return $this->_articleId;
 		}
 		
+		function getArticle()
+		{
+			if( $this->_article == null ) {
+				include_once( PLOG_CLASS_PATH."class/dao/articles.class.php" );
+				$articles = new Articles();
+				$this->_article = $articles->getBlogArticle( $this->_articleId, $this->_blogId );
+			}
+			
+			return( $this->_article );
+		}
+		
 		function getValue()
 		{			
 			return $this->_fieldValue;

Modified: plog/trunk/class/dao/customfields/customfieldvaluefactory.class.php
===================================================================
--- plog/trunk/class/dao/customfields/customfieldvaluefactory.class.php	2006-02-26 01:42:41 UTC (rev 2987)
+++ plog/trunk/class/dao/customfields/customfieldvaluefactory.class.php	2006-02-27 21:36:46 UTC (rev 2988)
@@ -53,6 +53,7 @@
 			// make things easier for clients of the class! But we can use the array with the
 			// mappins to easily figure out the right$ class for the job
 			$constructor = CustomFieldValueFactory::_findConstructorClass( (int)$row["field_type"] );
+			print_r($row);
 			$value = new $constructor( $row["field_id"],
 			                           $row["field_value"],
 									   $row["article_id"],

Modified: plog/trunk/class/dao/model.class.php
===================================================================
--- plog/trunk/class/dao/model.class.php	2006-02-26 01:42:41 UTC (rev 2987)
+++ plog/trunk/class/dao/model.class.php	2006-02-27 21:36:46 UTC (rev 2988)
@@ -374,11 +374,11 @@
             		elseif( strtolower(get_class( $value )) == "timestamp" )
             			$value = $value->getTimestamp();
 	                $value = Db::qstr($value);
-    	            $fieldValuesString .= "'" . $value . "', ";
+    	            $fieldsValuesString .= "'" . $value . "', ";
     	        }
             }
 
-            $sql .= substr($fieldsString, 0, -2) . ") VALUES (".substr($fieldValuesString, 0, -2).")";            
+            $sql .= substr($fieldsString, 0, -2) . ") VALUES (".substr($fieldsValuesString, 0, -2).")";            
             
             $result = $this->Execute( $sql );            
             if( !$result )
@@ -442,9 +442,9 @@
 		 */
         function delete( $field, $value )
         {
-			$query = "DELETE FROM ".$this->table." WHERE {$field} = '{$value}'";			
+			$query = "DELETE FROM ".$this->table." WHERE {$field} = '{$value}'";
 			$result = $this->Execute( $query );								
-			return( $this->_db->Affected_Rows());
+			return( $result );
         }
 
         /**

Modified: plog/trunk/class/dao/searchengine.class.php
===================================================================
--- plog/trunk/class/dao/searchengine.class.php	2006-02-26 01:42:41 UTC (rev 2987)
+++ plog/trunk/class/dao/searchengine.class.php	2006-02-27 21:36:46 UTC (rev 2988)
@@ -1,8 +1,8 @@
 <?php
 
-    include_once( PLOG_CLASS_PATH."class/dao/model.class.php" );
-    include_once( PLOG_CLASS_PATH."class/dao/searchresult.class.php" );
-    include_once( PLOG_CLASS_PATH."class/dao/articles.class.php" );
+	include_once( PLOG_CLASS_PATH."class/dao/articlestatus.class.php" );
+	include_once( PLOG_CLASS_PATH."class/dao/model.class.php" );
+	include_once( PLOG_CLASS_PATH."class/dao/searchresult.class.php" );
     
     /**
 	 * \ingroup DAO
@@ -18,13 +18,7 @@
      */
     class SearchEngine extends Model
     {
-    
-        function SearchEngine()
-        {
-            $this->Model();
-        }
-
-        /**
+		/**
          * takes the search string as originally input by a user and makes it "better", in the sense
          * that for example converts it to "term1 AND term2" instead of "term1 OR term2" which is the
          * default behaviour. In order to do so, the "+" operator must be added before each one of the
@@ -34,7 +28,7 @@
          * @return Returns an 'improved' version of the search terms
 		 * @static
          */ 
-        function _adaptSearchString( $searchTerms )
+        function adaptSearchString( $searchTerms )
         {
 			// load this module only if needed...
 			include_once( PLOG_CLASS_PATH."class/data/textfilter.class.php" );		
@@ -80,11 +74,11 @@
 		 * @see searchCustomFields
 		 * @see searchComments
 		 */
-		function search( $blogId, $query, $minRelevance = 0, $maxResults = 0, $status = POST_STATUS_PUBLISHED, $userId = -1, $date = 0 )
+		function search( $blogId, $searchTerms, $status = POST_STATUS_PUBLISHED )
 		{
-			$matchingArticles = $this->searchArticles( $blogId, $query, $minRelevance, $maxResults, $status, $userId, $date );
-			$matchingComments = $this->searchComments( $blogId, $query, $minRelevance, $maxResults, $status, $userId, $date );
-			$matchingFields   = $this->searchCustomFields( $blogId, $query, $minRelevance, $maxResults, $status, $userId, $date );
+			$matchingArticles = $this->searchBlogArticles( $blogId, $searchTerms, $status );
+			$matchingComments = $this->searchBlogComments( $blogId, $searchTerms, $status );
+			$matchingFields   = $this->searchBlogCustomFields( $blogId, $searchTerms, $status );
 			
 			$results = array_merge( $matchingArticles, $matchingComments, $matchingFields ); 
 			
@@ -114,101 +108,8 @@
 		{
 			return $this->search( -1, $query, $minRelevance = 0, $maxResults = 0, $status = POST_STATUS_PUBLISHED, $userId = -1, $date = 0 );
 		}
-		
-		/**
-		 * this method will generate the correct WHERE string depending on the $query parameter. The $query
-		 * parameter is an array including all the search terms that were received from the user.
-		 * It has been moved to its own method so that it can be be reused by other methods from this class
-		 * and from other classes.
-		 *
-		 * @param query An string containing the search terms
-		 * @private
-		 * @return An string with the correct WHERE conditions ready to be used in a query
-		 */
-		function _generateSearchArticlesWhereString( $query )
-		{
-            // Split the search term by space
-            $query_array = explode(' ',$query);
 
-            // For each search terms, I should make a like query for it   
-            $where_string = "(";
-            $where_string .= "((normalized_topic LIKE '%{$query_array[0]}%') OR (normalized_text LIKE '%{$query_array[0]}%'))";
-            for ( $i = 1; $i < count($query_array); $i = $i + 1) {
-				
-                $where_string .= " AND ((normalized_topic LIKE '%{$query_array[$i]}%') OR (normalized_text LIKE '%{$query_array[$i]}%'))";
-            }
-            $where_string .= " OR ((normalized_topic LIKE '%{$query}%') OR (normalized_text LIKE '%{$query}%'))";
-            $where_string .= ")";
-			
-			return $where_string;
-		}
-		
-		/**
-		 * @private
-		 *
-		 * Generates an SQL query that can be used to search articles. This method was originally part of searchArticles but it was moved
-		 * so that it is possible to have a method such as searchArticles that returns an array of SearchResult objects and searchBlogArticles
-		 * that returns an array of Article objects.
-		 * It has been moved to its own method so that it can be used by other classes and methods
-		 * @see Articles::searchBlogArticles
-		 * @see Articles::getBlogArticles
-		 * @see searchArticles
-		 */
-		function _generateSearchArticlesQuery( $blogId, $query, $minRelevance = 0, $maxResults = 0, $status = POST_STATUS_PUBLISHED, $userId = -1, $date = 0 )
-		{
-            $prefix      = $this->getPrefix();
-			$query       = $this->_adaptSearchString($query);            
-
-            // MARKWU: I also need to take care when there are multiplu search term
-			$where_string = $this->_generateSearchArticlesWhereString( $query );
-
-            // Make the whole sql query string
-            $searchQuery = "SELECT a.id AS id, a.date AS date,
-			                a.user_id AS user_id, a.blog_id AS blog_id, a.num_reads AS num_reads, 
-							a.properties AS properties, t.normalized_text AS normalized_text,
-							t.normalized_topic AS normalized_topic, a.status AS status, a.slug AS slug,
-							1 AS relevance
-                            FROM {$prefix}articles a 
-                                LEFT JOIN {$prefix}articles_text t ON a.id=t.article_id 
-                                LEFT JOIN {$prefix}blogs b ON a.blog_id=b.id
-                            WHERE {$where_string} AND a.status = $status 
-                                AND b.show_in_summary=1 AND b.status=".BLOG_STATUS_ACTIVE;
-
-			if( $blogId > 0 ) 
-				$searchQuery .= " AND a.blog_id = '".Db::qstr($blogId)."'";
-			if( $userId > 0 ) 
-				$searchQuery .= " AND a.user_id = $userId ";
-			if( $date > 0 )	
-				$searchQuery .= " AND a.date+0 LIKE '$date%' ";
-				
-            $searchQuery .=" ORDER BY relevance DESC";
-			
-			return $searchQuery;
-		}
-        
         /**
-         * Returns an array of SearchResult objects containing information about the search, such as the
-         * relevance (not very relevant, though :)), and the ArticleObject
-         *
-         * @param blogId The id of the blog whose articles we would like to search
-         * @param query The query string we'd like to use.
-         * @param minRelevance Minimum value of the relevance field, to get rid of less meaningful
-         * results
-         * @param maxResults Maximum number of results that will be returned.
-		 * @param status
-		 * @param userId
-		 * @param date
-         * @return An array of SearchResult objects
-         */
-        function searchArticles( $blogId, $query, $minRelevance = 0, $maxResults = 0, $status = POST_STATUS_PUBLISHED, $userId = -1, $date = 0 )
-        {
-			// build the search query
-			$searchQuery = $this->_generateSearchArticlesQuery( $blogId, $query, $minRelevance = 0, $maxResults = 0, $status = POST_STATUS_PUBLISHED, $userId = -1, $date = 0 );
-			
-			return $this->_getQueryResults( $searchQuery, SEARCH_RESULT_ARTICLE );
-        }
-
-        /**
          * Returns an array of Article objects with the articles that matched the search terms
          *
          * @param blogId The id of the blog whose articles we would like to search
@@ -221,25 +122,27 @@
 		 * @param date
          * @return An array of Article objects
          */		
-		function searchBlogArticles( $blogId, $query, $minRelevance = 0, $maxResults = 0, $status = POST_STATUS_PUBLISHED, $userId = -1, $date = 0 )
+		function searchBlogArticles( $blogId, $searchTerms, $status = POST_STATUS_PUBLISHED )
 		{
-			// build the search query
-			$searchQuery = $this->_generateSearchArticlesQuery( $blogId, $query, $minRelevance = 0, $maxResults = 0, $status = POST_STATUS_PUBLISHED, $userId = -1, $date = 0 );
-            $result = $this->Execute( $query );
-            
-            // return an empty array if nothing available
-            if( !$result )
-                return Array();
-             
-            $results = Array();
-            $articles = new Articles();
-            while( $row = $result->FetchRow()) {
-                $article = $articles->_fillArticleInformation( $row );
-				array_push( $results, $article );
-            }
-            
-            return $results;
+			include_once( PLOG_CLASS_PATH."class/dao/articles.class.php" );
+			$articles = new Articles();
+			$articlesResult = $articles->getBlogArticles( $blogId,   // blog id
+			                                    -1,    // no date
+												-1, // no amount limit
+												0,   // no category id
+												$status,  // status field
+												0,   // user id, if any
+												0,   // no max date
+												$searchTerms,   // search terms
+												-1 );    // no page
+												
+			// wrap this data in as many SearchResult objects
+			$results = Array();
+			foreach( $articlesResult as $article ) {
+				$results[] = new SearchResult( $article, SEARCH_RESULT_ARTICLE, $searchTerms );
+			}
 			
+			return( $results );
 		}
 				
         /**
@@ -253,16 +156,12 @@
          * @param maxResults Maximum number of results that will be returned.
          * @return An array of SearchResult objects
          */
-		 function searchCustomFields( $blogId, $query, $minRelevance = 0, $maxResults = 0, $status = POST_STATUS_PUBLISHED, $userId = -1, $date = 0 )
+		 function searchBlogCustomFields( $blogId, $searchTerms, $status = POST_STATUS_PUBLISHED )
          { 
             $prefix      = $this->getPrefix();
-			$query       = $this->_adaptSearchString($query);
+			$query       = $this->adaptSearchString( $searchTerms );
 
-            $searchQuery = "SELECT a.id AS id, t.topic AS topic, t.text AS text, a.date AS date,
-			                       a.user_id AS user_id, a.blog_id AS blog_id, a.num_reads AS num_reads, 
-							       a.properties AS properties, t.normalized_text AS normalized_text,
-							       t.normalized_topic AS normalized_topic, a.status AS status, a.slug AS slug,
-							       1 AS relevance 
+            $searchQuery = "SELECT a.*
 							 FROM {$prefix}custom_fields_values v
                                 LEFT JOIN {$prefix}articles a ON v.article_id = a.id
                                 LEFT JOIN {$prefix}articles_text t ON a.id=t.article_id 
@@ -272,17 +171,19 @@
 
             if( $blogId > 0 ) 
 				$searchQuery .= " AND a.blog_id = '".Db::qstr($blogId)."' ";
-			if( $userId > 0 ) 
-				$searchQuery .= " AND a.user_id = '".Db::qstr($userId)."' ";
-			if( $date > 0 )	
-				$searchQuery .= " AND a.date+0 LIKE '$date%' ";
+			
+			$result = $this->Execute( $searchQuery );
+			if( !$result )
+				return Array();
 				
-			$searchQuery .= " ORDER BY relevance";
-							 
-							 
-			//print $searchQuery;
-			//print "<hr />";
-			return $this->_getQueryResults( $searchQuery, SEARCH_RESULT_CUSTOM_FIELD );
+			include_once( PLOG_CLASS_PATH."class/dao/articles.class.php" );
+			$articles = new Articles();
+			$results = Array();
+			while( $row = $result->FetchRow()) {				
+				$results[] = new SearchResult( $articles->mapRow( $row ), SEARCH_RESULT_CUSTOM_FIELD, $searchTerms );
+			}
+			
+			return( $results );
         }
 
         /**
@@ -291,41 +192,31 @@
          *
          * @param blogId The id of the blog whose articles we would like to search
          * @param query The query string we'd like to use.
-         * @param minRelevance Minimum value of the relevance field, to get rid of less meaningful
-         * results
-         * @param maxResults Maximum number of results that will be returned.
          * @return An array of SearchResult objects
          */
-        function searchComments( $blogId, $query, $minRelevance = 0, $maxResults = 0, $status = POST_STATUS_PUBLISHED, $userId = -1, $date = 0 )
+        function searchBlogComments( $blogId, $searchTerms, $postStatus = POST_STATUS_PUBLISHED )
         {
-            $prefix      = $this->getPrefix();
 			include_once( PLOG_CLASS_PATH."class/dao/articlecomments.class.php" );
-			$where_string = ArticleComments::getSearchConditions( $query );
-
-            // Make the whole sql query string
-            $searchQuery = "SELECT a.id AS id, t.topic AS topic, t.text AS text, a.date AS date,
-			                       a.user_id AS user_id, a.blog_id AS blog_id, a.num_reads AS num_reads, 
-							       a.properties AS properties, t.normalized_text AS normalized_text,
-							       t.normalized_topic AS normalized_topic, a.status AS status, a.slug AS slug, 
-							       1 AS relevance 
-							 FROM {$prefix}articles_comments c
-                                LEFT JOIN {$prefix}articles a ON c.article_id = a.id
-                                LEFT JOIN {$prefix}articles_text t ON a.id=t.article_id 
-                                LEFT JOIN {$prefix}blogs b ON a.blog_id=b.id
-							 WHERE {$where_string} AND a.status = $status AND c.status = 0
-                                AND b.show_in_summary=1 AND b.status=".BLOG_STATUS_ACTIVE;
-			if( $blogId > 0 )
-				$searchQuery .=" AND a.blog_id = '".Db::qstr($blogId)."' ";
-			if( $userId > 0 )
-				$searchQuery .= " AND a.user_id = '".Db::qstr($userId)."' ";
-			if( $date > 0 )	
-				$searchQuery .= " AND a.date+0 LIKE '$date%' ";
-				
-			$searchQuery .= " ORDER BY relevance";
+			include_once( PLOG_CLASS_PATH."class/dao/articlecomments.class.php" );			
+			$comments = new ArticleComments();
+			$commentsResult = $comments->getBlogComments( $blogId,    // blog id
+			                                              COMMENT_ORDER_NEWEST_FIRST,
+										       		      COMMENT_STATUS_NONSPAM,
+												          $searchTerms );												
+														  
+			// map the results to a SearchResult object
+			//
+			// :TODO:
+			// perhaps we could optimize this a bit...?
+			//
+			$results = Array();
+			foreach( $commentsResult as $comment ) {
+				$article = $comment->getArticle();
+				if( $article->getStatus() == $postStatus )
+					$results[] = new SearchResult( $article, SEARCH_RESULT_COMMENT, $searchTerms );
+			}
 			
-			// print $searchQuery;
-			// print "<hr />";
-			return $this->_getQueryResults( $searchQuery, SEARCH_RESULT_COMMENT );
+			return( $results );
         }
 		
 		/**
@@ -342,7 +233,7 @@
 			$result = Array();
 			
 			foreach( $results as $item ) {
-				$article = $item->getArticle();
+				$article = $item->getResult();
 				if( !array_key_exists( $article->getId(), $alreadySeen ) || $alreadySeen[$article->getId()] == false ) {
 					array_push( $result, $item );
 					$alreadySeen[$article->getId()] = true;
@@ -351,35 +242,5 @@
 			
 			return $result;
 		}
-		
-		/**
-		 * 
-		 * @param query
-		 * @param queryType Whether we got these results searching in the articles, comments, 
-		 * or custom fields.
-		 * @private
-		 * @return 
-		 */
-		function _getQueryResults ( $query, $queryType )
-		{
-            $result = $this->Execute( $query );
-            
-            // return an empty array if nothing available
-            if( !$result )
-                return Array();
-             
-            $results = Array();
-            $articles = new Articles();
-            while( $row = $result->FetchRow()) {
-                $article = $articles->_fillArticleInformation( $row );
-                $searchResult = new SearchResult( $row["relevance"], $article, $queryType );
-                
-                // print_r(array_keys($row));
-                // print "<hr />";
-                array_push( $results, $searchResult );
-            }
-            
-            return $results;
-		}
     }
 ?>

Modified: plog/trunk/class/dao/searchresult.class.php
===================================================================
--- plog/trunk/class/dao/searchresult.class.php	2006-02-26 01:42:41 UTC (rev 2987)
+++ plog/trunk/class/dao/searchresult.class.php	2006-02-27 21:36:46 UTC (rev 2988)
@@ -18,23 +18,22 @@
     {
         
         var $_relevance;
-        var $_article;
+        var $_result;
 		var $_resultType;
+		var $_searchTerms;
         
 		/**
 		 * Constructor
 		 * 
-		 * @param relevance The relevance factor
-		 * @param article The Article object that matched the search terms
+		 * @param result The DbObject that was returned by the search
 		 * @param type Whether the search result is coming from an article, comment or custom field
+		 * @param relevance The relevance factor		 
 		 * @see getType()
 		 */
-        function SearchResult( $relevance, $article, $type )
-        {
-            
-            
+        function SearchResult( $result, $type, $searchTerms = "", $relevance = 0 )
+        {                        
             $this->_relevance = $relevance;
-            $this->_article   = $article;
+            $this->_result    = $result;
 			$this->_type      = $type;
         }
         
@@ -43,10 +42,19 @@
 		 *
 		 * @return an Article object
 		 */
+        function getResult()
+        {
+            return $this->_result;
+        }
+		
+		/**
+		 * Alias for getResult()
+		 * @see getResult
+		 */
         function getArticle()
         {
-            return $this->_article;
-        }
+            return( $this->getResult());
+        }		
         
 		/**
 		 * returns the relevance of the result
@@ -71,5 +79,15 @@
 		{
 			return $this->_type;
 		}
+		
+		/**
+		 * Returns the search terms that generated this result
+		 *
+		 * @return A string
+		 */
+		function getSearchTerms()
+		{
+			return( $this->_searchTerms );
+		}
     }
 ?>
\ No newline at end of file

Modified: plog/trunk/class/dao/userdata/ploguserdataprovider.class.php
===================================================================
--- plog/trunk/class/dao/userdata/ploguserdataprovider.class.php	2006-02-26 01:42:41 UTC (rev 2987)
+++ plog/trunk/class/dao/userdata/ploguserdataprovider.class.php	2006-02-27 21:36:46 UTC (rev 2988)
@@ -395,7 +395,7 @@
 		{
 			include_once( PLOG_CLASS_PATH."class/dao/searchengine.class.php" );			
 			// prepare the query string
-			$searchTerms = SearchEngine::_adaptSearchString( $searchTerms );
+			$searchTerms = SearchEngine::adaptSearchString( $searchTerms );
 			
 			return( "(user LIKE '%".$searchTerms."%' OR full_name LIKE '%".$searchTerms."%')");
 		}

Modified: plog/trunk/class/database/dbobject.class.php
===================================================================
--- plog/trunk/class/database/dbobject.class.php	2006-02-26 01:42:41 UTC (rev 2987)
+++ plog/trunk/class/database/dbobject.class.php	2006-02-27 21:36:46 UTC (rev 2988)
@@ -1,7 +1,5 @@
-<?php
-
+<?php    
     
-    
     /**
 	 * \ingroup Database
 	 * 
@@ -45,7 +43,7 @@
     	
     	function getProperties()
     	{
-    		return( $properties );
+    		return( $this->_properties );
     	}
     	
     	function getClass()

Modified: plog/trunk/class/template/menu/menu.class.php
===================================================================
--- plog/trunk/class/template/menu/menu.class.php	2006-02-26 01:42:41 UTC (rev 2987)
+++ plog/trunk/class/template/menu/menu.class.php	2006-02-27 21:36:46 UTC (rev 2988)
@@ -50,7 +50,7 @@
 		 * @static
 		 * @return A valid Menu object
 		 */
-		function getMenu( $menuFile = "" )
+		function &getMenu( $menuFile = "" )
 		{
 			static $instance;
 			



More information about the pLog-svn mailing list