[pLog-svn] r1891 - in plog/trunk: class/dao class/summary/view class/view/admin templates/admin

oscar at devel.plogworld.net oscar at devel.plogworld.net
Wed Apr 20 21:29:34 GMT 2005


Author: oscar
Date: 2005-04-20 21:29:33 +0000 (Wed, 20 Apr 2005)
New Revision: 1891

Modified:
   plog/trunk/class/dao/blogs.class.php
   plog/trunk/class/dao/model.class.php
   plog/trunk/class/dao/users.class.php
   plog/trunk/class/summary/view/summarybloglistview.class.php
   plog/trunk/class/summary/view/summaryuserlistview.class.php
   plog/trunk/class/view/admin/adminsiteblogslistview.class.php
   plog/trunk/class/view/admin/adminsiteuserslistview.class.php
   plog/trunk/templates/admin/siteblogs.template
   plog/trunk/templates/admin/siteusers.template
Log:
now it is possible to search any blog or user based on certain search terms in addition to the already existing filters (mostly status) 

The views and templates have been modified to include this feature, and some of the methods of the core Users and Blogs classes have been modifed to support this feature. 

Modified: plog/trunk/class/dao/blogs.class.php
===================================================================
--- plog/trunk/class/dao/blogs.class.php	2005-04-20 19:15:13 UTC (rev 1890)
+++ plog/trunk/class/dao/blogs.class.php	2005-04-20 21:29:33 UTC (rev 1891)
@@ -390,6 +390,8 @@
           * Returns all the blogs defined for the site in an array, sorted by its
           * blog identifier.
           *
+          * @param status
+          * @param searchTerms
           * @param page
           * @param itemsPerPage
           *
@@ -397,10 +399,14 @@
           * is sorted by the blog identifier, so that $blogs[$blogId] will give us the information
           * of the blog with $blogId as its identifier.
           */
-         function getAllBlogs( $status = BLOG_STATUS_ALL, $page = -1, $itemsPerPage = DEFAULT_ITEMS_PER_PAGE )
+         function getAllBlogs( $status = BLOG_STATUS_ALL, $searchTerms = "", $page = -1, $itemsPerPage = DEFAULT_ITEMS_PER_PAGE )
          {
             if( $status != BLOG_STATUS_ALL )
-                $where = "WHERE status = '".Db::qstr($status)."'";
+                $whereStatus = "status = '".Db::qstr($status)."'";
+            if( $searchTerms != "" )
+                $whereSearch = $this->buildSearchCondition( $searchTerms );
+                
+            $where = $this->buildWhereCondition( Array( $whereStatus, $whereSearch ));
 
             $query = "SELECT * FROM ".$this->getPrefix()."blogs $where ORDER BY blog $limits";
 
@@ -417,8 +423,19 @@
 
             return $blogs;
         }
+        
 
         /**
+         * @see Model::buildSearchCondition
+         */
+        function buildSearchCondition( $searchTerms )
+        {
+            $searchCond = "(blog LIKE '%".Db::qstr(trim($searchTerms))."%')";
+            
+            return( $searchCond );
+        }      
+
+        /**
          * returns only an array with all the blog ids
          *
          * @return an array with blog ids
@@ -438,16 +455,23 @@
         /**
          * returns the total number of blogs in the site
          *
+         * @param status
+         * @param searchTerms
+         *
          * @return The number of blogs
          */
-        function getNumBlogs( $status = BLOG_STATUS_ALL )
+        function getNumBlogs( $status = BLOG_STATUS_ALL, $searchTerms = "" )
         {
             $prefix = $this->getPrefix();
             $table = "{$prefix}blogs";
+            
             if( $status != BLOG_STATUS_ALL )
-                $cond = "status = '".Db::qstr($status)."'";
-
-            return( $this->getNumItems( $table, $cond ));
+                $whereStatus = "status = '".Db::qstr($status)."'";
+            if( $searchTerms != "" )
+                $whereSearch = $this->buildSearchCondition( $searchTerms );                
+            $where = $this->buildWhereCondition( Array( $whereStatus, $whereSearch ), false );
+            
+            return( $this->getNumItems( $table, $where ));
         }
 
         /**

Modified: plog/trunk/class/dao/model.class.php
===================================================================
--- plog/trunk/class/dao/model.class.php	2005-04-20 19:15:13 UTC (rev 1890)
+++ plog/trunk/class/dao/model.class.php	2005-04-20 21:29:33 UTC (rev 1891)
@@ -106,6 +106,8 @@
 				$error = $this->DbError();
 				$log->error( "The following query = \n{$query}\ngenerated the following error message = \n{$error}" );
 			}
+			
+			//$this->log->debug( "query = $query" );
 				
 			return( $result );
         }
@@ -178,5 +180,49 @@
 
 			return $total;
 		}
+		
+		/**
+		 * method to generate search conditions, should be implemented by child classes
+		 *
+		 * @param searchTerms
+		 */
+		function buildSearchCondition( $searchTerms )
+		{
+		    return( "" );
+		}
+		
+		/**
+		 * given several conditions, concatenates them with an "AND" operator. If one of the
+		 * items of the array is an empty string, the condition will not be used
+		 *
+		 * @param conds
+		 * @return a string
+		 */
+		function buildWhereCondition( $conds = Array(), $useWhere = true )
+		{
+		    $valid = 0;
+		    $where = "";
+		    
+		    foreach( $conds as $cond ) {
+		        $this->log->debug( "Processing condition = ".$cond );
+		        if( $cond ) {
+		            // only if the condition is not empty...
+		            
+		            if( $valid > 0 )
+		                $where .= " AND ";
+		            
+		            // append the condition
+		            $where .= "$cond";
+		            
+		            // we've got a valid condition
+		            $valid++;
+		        }
+		    }
+		    
+		    if( $valid > 0 && $useWhere )
+    		    $where = "WHERE $where";
+		        
+		    return( $where );
+		}
     }
 ?>

Modified: plog/trunk/class/dao/users.class.php
===================================================================
--- plog/trunk/class/dao/users.class.php	2005-04-20 19:15:13 UTC (rev 1890)
+++ plog/trunk/class/dao/users.class.php	2005-04-20 21:29:33 UTC (rev 1891)
@@ -230,16 +230,21 @@
          *
 		 * @param status
 		 * @param includeExtraInfo
+		 * @param searchTerms
          * @param page
          * @param itemsPerPage
          * @return An array containing all the users.
          */
-        function getAllUsers( $status = USER_STATUS_ALL, $includeExtraInfo = false, $page = -1, $itemsPerPage = DEFAULT_ITEMS_PER_PAGE )
-        {
+        function getAllUsers( $status = USER_STATUS_ALL, $includeExtraInfo = false, $searchTerms = "", $page = -1, $itemsPerPage = DEFAULT_ITEMS_PER_PAGE )
+        {   
 	    	if( $status != USER_STATUS_ALL )
-	    		$where = "WHERE status = '".Db::qstr($status)."'";
+	    		$whereStatus = "status = '".Db::qstr($status)."'";
+	    	if( $searchTerms != "" )
+	    	    $whereSearch = $this->buildSearchCondition( $searchTerms );
+	    	    
+	    	$where = $this->buildWhereCondition( Array( $whereStatus, $whereSearch ));
 	        
-            $query = "SELECT * FROM ".$this->getPrefix()."users $where ORDER BY id ASC $limits";
+            $query = "SELECT * FROM ".$this->getPrefix()."users $where ORDER BY id ASC";
 
             $result = $this->Execute( $query, $page, $itemsPerPage );
 
@@ -250,6 +255,19 @@
 
             return $users;
         }
+        
+        /**
+         * @see Model::buildSearchCondition
+         */
+        function buildSearchCondition( $searchTerms )
+        {
+            $searchTerms = trim( $searchTerms );
+            $searchCond = "(user LIKE '%".Db::qstr($searchTerms)."%' 
+                           OR full_name LIKE '%".Db::qstr($searchTerms)."%' OR 
+                           email LIKE '%".Db::qstr($searchTerms)."%')";
+            
+            return( $searchCond );
+        }
 
         /**
          * Updates the information related to a user
@@ -316,10 +334,12 @@
          *
          * @param blogId The blog identifier.
          * @param includeOwner Wether to include the owner of the blog or not.
+         * @param status
+         * @param searchTerms
          * @return An array with the information about the users who belong in
          * one way or another to that blog.
          */
-        function getBlogUsers( $blogId, $includeOwner = true, $status = USER_STATUS_ALL )
+        function getBlogUsers( $blogId, $includeOwner = true, $status = USER_STATUS_ALL, $searchTerms = "" )
         {
             $users = Array();
 	        $prefix = $this->getPrefix();
@@ -403,14 +423,17 @@
          *
          * @return total number of users
          */
-        function getNumUsers( $status = USER_STATUS_ALL )
+        function getNumUsers( $status = USER_STATUS_ALL, $searchTerms = "" )
         {
-            $prefix = $this->getPrefix();
-			$table = "{$prefix}users";
-            if( $status != USER_STATUS_ALL )
-            	$cond = "status = '".Db::qstr($status)."'";
+            $table = $this->getPrefix()."users";
+			if( $status != USER_STATUS_ALL )
+				$whereStatus = "status = '".Db::qstr($status)."'";
+			if( $searchTerms != "" )
+			    $whereSearch = $this->buildSearchCondition( $searchTerms );
+			    
+			$where = $this->buildWhereCondition( Array( $whereStatus, $whereSearch ), false );
 				
-			return( $this->getNumItems( $table, $cond ));
+			return( $this->getNumItems( $table, $where ));
         }
         
         /**

Modified: plog/trunk/class/summary/view/summarybloglistview.class.php
===================================================================
--- plog/trunk/class/summary/view/summarybloglistview.class.php	2005-04-20 19:15:13 UTC (rev 1890)
+++ plog/trunk/class/summary/view/summarybloglistview.class.php	2005-04-20 21:29:33 UTC (rev 1891)
@@ -42,7 +42,7 @@
 			
 			// get the data itself
 			$blogs = new Blogs();
-            $siteBlogs = $blogs->getAllBlogs( BLOG_STATUS_ACTIVE, $this->_page, $this->_numBlogsPerPage );
+            $siteBlogs = $blogs->getAllBlogs( BLOG_STATUS_ACTIVE, "", $this->_page, $this->_numBlogsPerPage );
 			$numBlogs = $blogs->getNumBlogs( BLOG_STATUS_ACTIVE );
 			
             if( !$siteBlogs ) {

Modified: plog/trunk/class/summary/view/summaryuserlistview.class.php
===================================================================
--- plog/trunk/class/summary/view/summaryuserlistview.class.php	2005-04-20 19:15:13 UTC (rev 1890)
+++ plog/trunk/class/summary/view/summaryuserlistview.class.php	2005-04-20 21:29:33 UTC (rev 1891)
@@ -38,8 +38,8 @@
 			
 			// get the data itself
 			$users = new Users();
-            $siteUsers = $users->getAllUsers( USER_STATUS_ACTIVE, true, $this->_page, $this->_numUsersPerPage );
-			$numUsers = $users->getNumUsers( USER_STATUS_ACTIVE );
+            $siteUsers = $users->getAllUsers( USER_STATUS_ACTIVE, true, "", $this->_page, $this->_numUsersPerPage );
+			$numUsers = count( $siteUsers );
 			
             if( !$siteUsers ) {
                 // if there was an error, show the error view

Modified: plog/trunk/class/view/admin/adminsiteblogslistview.class.php
===================================================================
--- plog/trunk/class/view/admin/adminsiteblogslistview.class.php	2005-04-20 19:15:13 UTC (rev 1890)
+++ plog/trunk/class/view/admin/adminsiteblogslistview.class.php	2005-04-20 21:29:33 UTC (rev 1891)
@@ -14,6 +14,7 @@
 	{
 		var $_page;
 		var $_status;
+		var $_searchTerms;
 		
 		function AdminSiteBlogsListView( $blogInfo )
 		{
@@ -49,9 +50,10 @@
             // we need to get all the blogs
 			// get the data itself
 			$this->_status = $this->getStatusFromRequest();
+			$this->_searchTerms = HttpVars::getRequestValue( "searchTerms" );
 			$blogs = new Blogs();
-            $siteBlogs = $blogs->getAllBlogs( $this->_status, $this->_page, DEFAULT_ITEMS_PER_PAGE );
-			$numBlogs = $blogs->getNumBlogs( $this->_status );
+            $siteBlogs = $blogs->getAllBlogs( $this->_status, $this->_searchTerms, $this->_page, DEFAULT_ITEMS_PER_PAGE );
+			$numBlogs = $blogs->getNumBlogs( $this->_status, $this->_searchTerms );
             if( !$siteBlogs ) {
             	$siteBlogs = Array();
             }
@@ -60,7 +62,7 @@
 			$this->notifyEvent( EVENT_BLOGS_LOADED, Array( "blogs" => &$siteBlogs ));            
             
 			// calculate the links to the different pages
-			$pager = new Pager( "?op=editSiteBlogs&status=".$this->_status."&page=",
+			$pager = new Pager( "?op=editSiteBlogs&searchTerms=".$this->_searchTerms."&status=".$this->_status."&page=",
 			                    $this->_page, 
 								$numBlogs, 
 								DEFAULT_ITEMS_PER_PAGE );
@@ -69,6 +71,7 @@
 			$this->setValue( "pager", $pager );
 			$this->setValue( "currentstatus", $this->_status );
 			$this->setValue( "blogstatus", BlogStatus::getStatusList( true ));
+			$this->setValue( "searchTerms", $this->_searchTerms );
 		
 			// let the parent view do its job
 			parent::render();                        

Modified: plog/trunk/class/view/admin/adminsiteuserslistview.class.php
===================================================================
--- plog/trunk/class/view/admin/adminsiteuserslistview.class.php	2005-04-20 19:15:13 UTC (rev 1890)
+++ plog/trunk/class/view/admin/adminsiteuserslistview.class.php	2005-04-20 21:29:33 UTC (rev 1891)
@@ -4,9 +4,9 @@
     include_once( PLOG_CLASS_PATH."class/dao/users.class.php" );
     include_once( PLOG_CLASS_PATH."class/data/pager/pager.class.php" );
 	
-    /**
-     * \ingroup View
-     * @private
+    /**
+     * \ingroup View
+     * @private
      *
 	 * shows a list with the users in the blog
 	 */
@@ -24,7 +24,7 @@
 		 * retrieves the current status from the request
 		 *
 		 * @private
-		 * @return nothing
+		 * @return a string with the status code as it came from the request
 		 */
 		function getStatusFromRequest()
 		{
@@ -42,16 +42,21 @@
 			return $status;
 		}
 		
+		/**
+		 * @private
+		 */
+		
 		function render()
 		{
 			// get the current page
 			$this->_page = $this->getCurrentPageFromRequest();
 			$this->_status = $this->getStatusFromRequest();
+			$this->_searchTerms = HttpVars::getRequestValue( "searchTerms");
 			
         	// get the users of the blog
             $users = new Users();
-            $siteUsers = $users->getAllUsers( $this->_status, true, $this->_page, DEFAULT_ITEMS_PER_PAGE );
-            $numUsers = $users->getNumUsers( $this->_status );
+            $siteUsers = $users->getAllUsers( $this->_status, true, $this->_searchTerms, $this->_page, DEFAULT_ITEMS_PER_PAGE );
+            $numUsers = $users->getNumUsers( $this->_status, $this->_searchTerms );
             
             // in case of problems, empty array...
             if( !$siteUsers )
@@ -61,7 +66,7 @@
             $this->notifyEvent( EVENT_USERS_LOADED, Array( "users" => &$blogUsers ));
             
 			// calculate the links to the different pages
-			$pager = new Pager( "?op=editSiteUsers&&status=".$this->_status."&page=",
+			$pager = new Pager( "?op=editSiteUsers&searchTerms=".$this->_searchTerms."&&status=".$this->_status."&page=",
 			                    $this->_page, 
 								$numUsers, 
 								DEFAULT_ITEMS_PER_PAGE );
@@ -71,6 +76,7 @@
             $this->setValue( "userstatus", UserStatus::getStatusList( true ));
             $this->setValue( "pager", $pager );
             $this->setValue( "currentstatus", $this->_status );
+            $this->setValue( "searchTerms", $this->_searchTerms );
 			parent::render();
 		}
 	}

Modified: plog/trunk/templates/admin/siteblogs.template
===================================================================
--- plog/trunk/templates/admin/siteblogs.template	2005-04-20 19:15:13 UTC (rev 1890)
+++ plog/trunk/templates/admin/siteblogs.template	2005-04-20 21:29:33 UTC (rev 1891)
@@ -15,7 +15,14 @@
     {/foreach}
     </select>
    </div>
+   
    <div class="list_nav_option">
+   <label for="search">{$locale->tr("search_terms")}</label>
+   <br />
+   <input type="text" name="searchTerms" value="{$searchTerms}" size="15" id="search" />
+   </div>   
+   
+   <div class="list_nav_option">
     <br />
     <input type="hidden" name="op" value="editSiteBlogs">
     <input type="submit" name="Show" value="{$locale->tr("show")}">

Modified: plog/trunk/templates/admin/siteusers.template
===================================================================
--- plog/trunk/templates/admin/siteusers.template	2005-04-20 19:15:13 UTC (rev 1890)
+++ plog/trunk/templates/admin/siteusers.template	2005-04-20 21:29:33 UTC (rev 1891)
@@ -15,7 +15,14 @@
     {/foreach}
     </select>
    </div>
+   
    <div class="list_nav_option">
+   <label for="search">{$locale->tr("search_terms")}</label>
+   <br />
+   <input type="text" name="searchTerms" value="{$searchTerms}" size="15" id="search" />
+   </div>   
+   
+   <div class="list_nav_option">
     <br />
     <input type="hidden" name="op" value="editSiteUsers">
     <input type="submit" name="Show" value="{$locale->tr("show")}">




More information about the pLog-svn mailing list