[pLog-svn] r6208 - plog/branches/lifetype-1.2/class/dao/userdata

reto at devel.lifetype.net reto at devel.lifetype.net
Mon Mar 10 19:32:21 EDT 2008


Author: reto
Date: 2008-03-10 19:32:21 -0400 (Mon, 10 Mar 2008)
New Revision: 6208

Modified:
   plog/branches/lifetype-1.2/class/dao/userdata/simplepostnukeuserdataprovider.class.php
Log:
updated the simplepostnukeuserdataprovider - the code was not updated during the last changes of the lifetypeuserdataprovider. User permissions for Blogs are now working properly again.

Modified: plog/branches/lifetype-1.2/class/dao/userdata/simplepostnukeuserdataprovider.class.php
===================================================================
--- plog/branches/lifetype-1.2/class/dao/userdata/simplepostnukeuserdataprovider.class.php	2008-03-09 16:54:16 UTC (rev 6207)
+++ plog/branches/lifetype-1.2/class/dao/userdata/simplepostnukeuserdataprovider.class.php	2008-03-10 23:32:21 UTC (rev 6208)
@@ -178,38 +178,61 @@
         //------------
 
         /**
-        * Retrieves the user information but given only a username
-        *
-        * @param username The username of the user
-        * @return Returns a UserInfo object with the requested information, or false otherwise.
-        */
+         * Returns all the information associated to the user given
+         *
+         * @param user Username of the user from who we'd like to get the information
+         * @param pass Password of the user we'd like to get the information
+         * @return Returns a UserInfo object with the requested information, or false otherwise.
+         */
+        function getUserInfo( $user, $pass )
+        {
+            $userInfo = $this->getUserInfoFromUsername( $user );
+            if ( $userInfo && ($userInfo->getPassword() == md5($pass)) ) {
+                return $userInfo;
+            } else {
+                return false;
+            }
+        }
+
+        /**
+         * Retrieves the user information but given only a username
+         *
+         * @param username The username of the user
+         * @return Returns a UserInfo object with the requested information, or false otherwise.
+         */
         function getUserInfoFromUsername( $username )
         {
-        	return( $this->get( "user", $username, CACHE_USERIDBYNAME, Array( CACHE_USERINFO => "getId" )));        	
+        	$user = $this->get( "user", $username, CACHE_USERIDBYNAME, Array( CACHE_USERINFO => "getId" ));
+			if( $user ) {
+				if( $user->getUsername() != $username ) {
+					$user = false;
+				}
+			}
+
+			return( $user );
         }
 
-        
         /**
-        * Retrieves the user infromation but given only a userid
-        *
-        * @param userId User ID of the user from whom we'd like to get the information
-        * @return Returns a UserInfo object with the requested information, or false otherwise.
-        */
+         * Retrieves the user infromation but given only a userid
+         *
+         * @param userId User ID of the user from whom we'd like to get the information
+         * @return Returns a UserInfo object with the requested information, or false otherwise.
+         */
         function getUserInfoFromId( $userid )
         {
         	return( $this->get( "id", $userid, CACHE_USERINFO, Array( CACHE_USERIDBYNAME => "getUsername" )));
         }
 
         /**
-        * Returns an array with all the users available in the database
-        *
-        * @param status
-        * @param includeExtraInfo
-        * @param searchTerms
-        * @param page
-        * @param itemsPerPage
-        * @return An array containing all the users.
-        */
+         * Returns an array with all the users available in the database
+         *
+		 * @param status
+		 * @param searchTerms
+         * @param orderBy
+         * @param page
+         * @param itemsPerPage
+         * @return An array containing all the users.
+         */
         function getAllUsers( $status = USER_STATUS_ALL, 
 		                      $searchTerms = "",
                               $orderBy = "",
@@ -228,15 +251,19 @@
 			}
 			if( $where != "" )
 				$where = "WHERE $where";
+
+            if( $orderBy == "" )
+                $orderBy = "id ASC";
 			
-            $query = "SELECT * FROM ".$this->getPrefix()."users $where ORDER BY id ASC";
+            $query = "SELECT * FROM ".$this->getPrefix()."users $where ORDER BY $orderBy";
+
             $result = $this->Execute( $query, $page, $itemsPerPage );
 			
             $users = Array();			
 			
 			if( !$result )
 				return $users;
-
+                
             while ($row = $result->FetchRow()) {
 				$user = $this->mapRow( $row );
                 $users[] = $user;
@@ -250,8 +277,8 @@
         }
         
         /**
-        * @see Model::buildSearchCondition
-        */
+         * @see Model::buildSearchCondition
+         */
         function buildSearchCondition( $searchTerms )
         {
             $searchTerms = trim( $searchTerms );
@@ -263,12 +290,12 @@
         }
 
         /**
-        * Updates the information related to a user
-        *
-        * @param userInfo An UserInfo object containing the <b>already udpated</b> information of the
-        * user we would like to update.
-        * @return Returns true if ok or false otherwise.
-        */
+         * Updates the information related to a user
+         *
+         * @param userInfo An UserInfo object containing the <b>already udpated</b> information of the
+         * user we would like to update.
+         * @return Returns true if ok or false otherwise.
+         */
         function updateUser( $user )
         {
         	$result = $this->update( $user );
@@ -285,12 +312,12 @@
         }
 
         /**
-        * Adds a user to the database.
-        *
-        * @param user An UserInfo object with the necessary information
-        * @return Returns the identifier assigned to the user, or false if there was any error. It will also modify the
-        * UserInfo object passed by parameter and set its database id.
-        */
+         * Adds a user to the database.
+         *
+         * @param user An UserInfo object with the necessary information
+         * @return Returns the identifier assigned to the user, or false if there was any error. It will also modify the
+		 * UserInfo object passed by parameter and set its database id.
+         */
         function addUser( &$user )
         {
         	$userId = $this->add( $user );
@@ -311,82 +338,39 @@
         }
 
         /**
-        * Returns an array with all the users that belong to the given
-        * blog.
-        *
-        * @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, $searchTerms = "" )
-        {
-            $users = Array();
-	        $prefix = $this->getPrefix();
-
-            // get the information about the owner, if requested so
-            if( $includeOwner ) {
-                $query = "SELECT {$prefix}users.* FROM {$prefix}users, {$prefix}blogs 
-                          WHERE {$prefix}users.id = {$prefix}blogs.owner_id AND {$prefix}blogs.id = '".Db::qstr($blogId)."';";
-                $result = $this->Execute( $query );
-
-                if( !$result )
-                    return false;
-
-                $row = $result->FetchRow();
-                $result->Close();
-                array_push( $users, $this->mapRow( $row ));
-            }
-
-            // now get the other users who have permission for that blog.
-            $query2 = "SELECT {$prefix}users.* FROM {$prefix}users, {$prefix}users_permissions 
-                       WHERE {$prefix}users.id = {$prefix}users_permissions.user_id 
-                       AND {$prefix}users_permissions.blog_id = '".Db::qstr($blogId)."';";
-            $result2 = $this->Execute( $query2 );
-            if( !$result2 ) // if error, return what we have so far...
-                return $users;
-
-            while( $row = $result2->FetchRow()) {
-                array_push( $users, $this->mapRow($row));
-            }
-            $result2->Close();
-
-            return $users;
-        }
-        
-        /**
-        * Removes users from the database
-        *
-        * @param userId The identifier of the user we are trying to remove
-        */
+         * Removes users from the database
+         *
+         * @param userId The identifier of the user we are trying to remove
+         */
         function deleteUser( $userId )
         {
             // first, delete all of his/her permissions
-            if( $this->delete( $userId )) {            
+            $user = $this->getUserInfoFromId( $userId );
+            if( $this->delete( "id", $userId )) {            
 	    		lt_include( PLOG_CLASS_PATH."class/dao/userpermissions.class.php" );
     	        $perms = new UserPermissions();
         	    $perms->revokeUserPermissions( $userId );
-        	    $this->_cache->removeData( $userId, CACHE_USERINFO );                        
+        	    $this->_cache->removeData( $userId, CACHE_USERINFO );
+        	    $this->_cache->removeData( $user->getUsername(), CACHE_USERIDBYNAME );
+                return true;
             }
-            else
-            	return( false );
-        }          
-
+            
+            return false;
+        }  
+        
         /**
-        * returns the total number of users
-        *
-        * @return total number of users
-        */
+         * returns the total number of users
+         *
+         * @return total number of users
+         */
         function getNumUsers( $status = USER_STATUS_ALL, $searchTerms = "" )
         {
             $table = $this->getPrefix()."users";
 			    
+			$where = "";
 	    	if( $status != USER_STATUS_ALL )
 	    		$where = "status = '".Db::qstr($status)."'";
 
-			$where = "";
 	    	if( $searchTerms != "" ) {
 				if( $where != "" )
 					$where .= " AND ";
@@ -397,9 +381,9 @@
         }
 
         /**
-        * check if the email account has been registered
-        * @return true if the email account has been registered
-        */
+         * check if the email account has been registered
+         * @return true if the email account has been registered
+         */
         function emailExists($email) 
 		{
             $query = "SELECT email 
@@ -412,8 +396,7 @@
                 return false;
 
             $count = $result->RecordCount();
-            $result->Close();
-
+            $result->Close(); 
             return ($count >= 1);
         }
 		



More information about the pLog-svn mailing list