[pLog-svn] r2196 - plog/trunk/class/dao/userdata

oscar at devel.plogworld.net oscar at devel.plogworld.net
Fri Jun 10 12:24:49 GMT 2005


Author: oscar
Date: 2005-06-10 12:24:48 +0000 (Fri, 10 Jun 2005)
New Revision: 2196

Modified:
   plog/trunk/class/dao/userdata/phpbb2userdataprovider.class.php
Log:
it is already possible to add and edit users so now the only thing that is missing
is integrating all the information which is not available in phpbb (full name,
status, etc) As I said before, I think that the only possibility is to create
an extra table to hold this information...


Modified: plog/trunk/class/dao/userdata/phpbb2userdataprovider.class.php
===================================================================
--- plog/trunk/class/dao/userdata/phpbb2userdataprovider.class.php	2005-06-10 12:23:47 UTC (rev 2195)
+++ plog/trunk/class/dao/userdata/phpbb2userdataprovider.class.php	2005-06-10 12:24:48 UTC (rev 2196)
@@ -29,8 +29,6 @@
             $db = $config->getValue( "database" );
             $this->_phpbbprefix = $config->getValue( "prefix" );
             
-
-            
             $this->_dbc =& Db::getNewDb( $host, $user, $pass, $db );                     
         }
 
@@ -91,12 +89,15 @@
          */
         function getUserInfoFromUsername( $username )
         {
-	        $query = "SELECT * FROM ".$this->_phpbbprefix."users WHERE username = '".Db::qstr( $username )."'";
+	        $query = "SELECT * FROM ".$this->_phpbbprefix."users WHERE username = '".Db::qstr( $username )."'";	       	       
 	                  
 	        $result = $this->_dbc->Execute( $query );
 	        
 	        if( !$result )
 	        	return false;
+	        		        	
+	        if( $result->RowCount() == 0 )
+	        	return false;
 	        	
 	        $row = $result->FetchRow();
 	        
@@ -120,19 +121,31 @@
 	        	
 	        $row = $result->FetchRow();
 	        
+	        // fetch the user permissions
+	        $perms = new UserPermissions();
+	        $row["site_admin"] = $perms->isSiteAdmin( $userid );
+	        
 	        return( $this->_mapUserInfoObject( $row ));
         }
         
-        function _mapUserInfoObject( $row )
+        function _mapUserInfoObject( $row, $extraInfo = false )
         {
-	    	$user = new UserInfo( $row["username"], $row["user_password"], $row["user_email"],
-	    	                      "", // TODO: this is the 'about myself' field that should be got from somewhere!
-	    	                      "", // TODO: the user full name is not available in phpbb
-	    	                      0, // TODO: the resource picture id is not available in phpbb
-	    	                      Array(), // TODO: the user properties are not available in phpbb
-	    	                      $row["user_id"] );
-	    	                      
-	    	return( $user );
+	        include_once( PLOG_CLASS_PATH."class/dao/userpermissions.class.php" );
+	        
+	        $row["user"] = $row["username"];
+	        $row["password"] = $row["user_password"];
+	        $row["email"] = $row["user_email"];
+	        $row["about"] = "";
+	        $row["full_name"] = "";
+	        $row["resource_picture_id"] = 0;
+	        $row["properties"] = serialize(Array());
+	        $row["id"] = $row["user_id"];
+	        $row["status"] = USER_STATUS_ACTIVE;
+	        
+	        $perms = new UserPermissions();
+	        $row["site_admin"] = $perms->isSiteAdmin( $row["user_id"] );	 	        
+
+	        return( BaseUserDataProvider::_mapUserInfoObject( $row, $extraInfo ));
         }
 
         /**
@@ -144,8 +157,18 @@
          * @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 )
+        {	        
+            $query = "SELECT * FROM ".$this->_phpbbprefix."users WHERE user_id >= 0 ORDER BY user_id ASC";
+
+            $result = $this->_dbc->Execute( $query, $page, $itemsPerPage );            
+
+            $users = Array();
+
+            while ($info = $result->FetchRow( $result ))
+                array_push( $users, $this->_mapUserInfoObject( $info ));
+
+            return $users;	        	        
         }
 
         /**
@@ -157,7 +180,33 @@
          */
         function updateUser( $userInfo )
         {
+	        $query = "UPDATE ".$this->_phpbbprefix."users SET
+	                  username = '".Db::qstr($userInfo->getUserName())."',
+	                  user_email = '".Db::qstr($userInfo->getEmail())."',
+	                  user_active = '".Db::qstr($userInfo->getPassword())."'
+	                  WHERE user_id = '".Db::qstr($userInfo->getId())."'";
+	                              
+            $result = $this->_dbc->Execute( $query );            
+            
+            BaseUserDataProvider::updateUser( $userInfo );
+
+			return( $result );
         }
+        
+        /**
+         * @private
+         * Why the hell couldn't they make the user_id field auto-incrementable???
+         */
+        function getLastPhpBBUserId()
+        {
+	       $query = "SELECT MAX(user_id)+1 AS next_id FROM ".$this->_phpbbprefix."users"; 
+	       
+	       $result = $this->_dbc->Execute( $query );
+	       
+	       $row = $result->FetchRow();
+	       
+	       return( $row["next_id"] );
+        }
 
         /**
          * Adds a user to the database.
@@ -167,7 +216,21 @@
 		 * UserInfo object passed by parameter and set its database id.
          */
         function addUser( &$user )
-        {
+        {	        
+	        $password = $user->getPassword();
+	        $id = $this->getLastPhpBBUserId();
+	        $query = "INSERT INTO ".$this->_phpbbprefix."users (user_id,username,user_password,user_email,user_active)
+	                  VALUES ($id, '".Db::qstr($user->getUserName())."','".md5($user->getPassword())."','".
+                      Db::qstr($user->getEmail())."',1);";                      
+                      
+            $result = $this->_dbc->Execute( $query );            
+
+            if( !$result )
+                return false;
+			
+			$user->setId( $id );
+
+            return( $id );
         }
 
         /**
@@ -195,20 +258,27 @@
          */
         function getNumUsers( $status = USER_STATUS_ALL )
         {
+	        //
+	        // :TODO:
+	        // add the status check here!
+	        //
+	        $query = "SELECT COUNT(*) AS total FROM ".$this->_phpbbprefix."users";
+	        
+	        $result = $this->_dbc->Execute( $query );
+	        
+	        // return no users if this doesn't work!
+	        if( !$result )
+	        	return 0;
+	        
+	        $row = $result->FetchRow();
+	        
+	        if( $row["total"] == "" )
+	        	$row["total"] = 0;
+	        	
+	        return( $row["total"] );
         }
         
         /**
-         * returns true if the given username exists
-         *
-         * @param userName
-         * @return true if it exists or false otherwise
-         */
-        function userExists( $userName )
-        {
-	        return( $this->getUserInfoFromUsername( $userName ));
-        }
-
-        /**
          * get the blogid of user own
          */
 		function getUserBlogId( $username )
@@ -219,8 +289,16 @@
          * check if the email account has been registered
          * @return true if the email account has been registered
          */
-        function emailExists($email)
+        function emailExists($email)        
         {
+	        $query = "SELECT * FROM ".$this->_phpbbprefix."users WHERE user_email = '".Db::qstr($email)."'";
+	        
+	        $result = $this->_dbc->Execute( $query );
+	        
+	        if( !$result )
+	        	return false;
+	        		        
+	        return( $result->RecordCount() > 0 );
         }
     }
 ?>




More information about the pLog-svn mailing list