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

oscar at devel.plogworld.net oscar at devel.plogworld.net
Wed Jun 15 16:54:14 GMT 2005


Author: oscar
Date: 2005-06-15 16:54:14 +0000 (Wed, 15 Jun 2005)
New Revision: 2236

Modified:
   plog/trunk/class/dao/userdata/baseuserdataprovider.class.php
   plog/trunk/class/dao/userdata/phpbb2userdataprovider.class.php
Log:
this is working quite fine now...


Modified: plog/trunk/class/dao/userdata/baseuserdataprovider.class.php
===================================================================
--- plog/trunk/class/dao/userdata/baseuserdataprovider.class.php	2005-06-15 16:53:42 UTC (rev 2235)
+++ plog/trunk/class/dao/userdata/baseuserdataprovider.class.php	2005-06-15 16:54:14 UTC (rev 2236)
@@ -133,6 +133,8 @@
          */
         function _mapUserInfoObject( $query_result, $extendedInfo = false )
         {
+	        include_once( PLOG_CLASS_PATH."class/dao/userinfo.class.php" );
+	        
             $userInfo = new UserInfo( $query_result["user"], $query_result["password"],
                                       $query_result["email"],
                                       $query_result["about"],
@@ -143,7 +145,7 @@
 
                                       
                                       
-            if( $extraInfo ) {
+            if( $extendedInfo ) {
                 // load this data if explicitely required!
                 $userBlogs = $this->getUsersBlogs($userInfo->getId());
                 $userInfo->setBlogs($userBlogs);

Modified: plog/trunk/class/dao/userdata/phpbb2userdataprovider.class.php
===================================================================
--- plog/trunk/class/dao/userdata/phpbb2userdataprovider.class.php	2005-06-15 16:53:42 UTC (rev 2235)
+++ plog/trunk/class/dao/userdata/phpbb2userdataprovider.class.php	2005-06-15 16:54:14 UTC (rev 2236)
@@ -46,7 +46,7 @@
         function authenticateUser( $user, $pass )
         {
 	        $query = "SELECT * FROM ".$this->_phpbbprefix."users WHERE username = '".Db::qstr( $user )."'
-	                  AND user_password = '".md5( $pass )."' AND user_active = 1";
+	                  AND user_password = '".md5( $pass )."' AND user_active > 0";
 	                  
 	        $result = $this->_dbc->Execute( $query );
 	        
@@ -133,6 +133,43 @@
 	        return( $this->_mapUserInfoObject( $row ));
         }
         
+        function phpBB2AddBlog( $row )
+        {
+		    // create a new blog
+		    include_once( PLOG_CLASS_PATH."class/dao/blogs.class.php" );
+            include_once( PLOG_CLASS_PATH."class/dao/articles.class.php" );
+            include_once( PLOG_CLASS_PATH."class/dao/articlecategories.class.php" );
+		    
+		    $blogs = new Blogs();
+		    $blog = new BlogInfo( $row["user"],  // name of the new blog
+		       	                  $row["id"],  // id of the owner
+		           	              "",  // no about
+		            	          Array()); // no properties either
+		    $newBlogId = $blogs->addBlog( $blog );
+		     	    	     
+            // add a default category and a default post            
+            $articleCategories = new ArticleCategories();
+            $articleCategory = new ArticleCategory( "General", "", $newBlogId, true );
+            $catId = $articleCategories->addArticleCategory( $articleCategory );
+            $config =& Config::getConfig();
+            $locale =& Locales::getLocale( $config->getValue( "default_locale" ));
+            $articleTopic = $locale->tr( "register_default_article_topic" );
+            $articleText  = $locale->tr( "register_default_article_text" );
+            $article = new Article( $articleTopic, 
+                                    $articleText, 
+                                    Array( $catId ), 
+                                    $this->_ownerId, 
+                                    $newBlogId, 
+                                    POST_STATUS_PUBLISHED, 
+                                    0, 
+                                    Array(), 
+                                    "welcome" );
+            $t = new Timestamp();
+            $article->setDateObject( $t );
+            $articles = new Articles();
+            $articles->addArticle( $article );	           
+        }
+        
         function _mapUserInfoObject( $row, $extraInfo = false )
         {
 	        include_once( PLOG_CLASS_PATH."class/dao/userpermissions.class.php" );
@@ -147,12 +184,31 @@
 	        $row["resource_picture_id"] = $plogPhpBB2Data["resource_picture_id"];
 	        $row["properties"] = serialize(Array());
 	        $row["id"] = $row["user_id"];   
-	        $row["status"] = $row["user_active"];
+	        $row["status"] = ($row["user_active"] > 0) ? USER_STATUS_ACTIVE : USER_STATUS_DISABLED;
 	        
 	        $perms = new UserPermissions();
-	        $row["site_admin"] = $perms->isSiteAdmin( $row["user_id"] );	 	        
-
-	        return( BaseUserDataProvider::_mapUserInfoObject( $row, $extraInfo ));
+	        $row["site_admin"] = $perms->isSiteAdmin( $row["user_id"] );
+	        
+	        	        
+	       	// does this phpbb user have a blog yet? If so, create one if the configuration
+	        // of the user data provider says so
+	        $providerConfig = $this->getProviderConfiguration();
+	        if( $providerConfig->getValue( "createBlogIfNotExisting" )) {
+		        $userInfo = BaseUserDataProvider::_mapUserInfoObject( $row, true );
+		        // check if this user is assigned to any blog
+		        $userBlogs = $userInfo->getBlogs();
+		        $this->log->debug("phpbb: checking if user ".$row["user"]." has at least one blog..." );
+		        if( empty($userBlogs )) {
+			        $this->log->debug( "phpbb: creating new blog for user!" );
+			        $this->phpBB2AddBlog( $row );
+			        $userInfo->setBlogs( $this->getUsersBlogs( $userInfo->getId()));
+     			}
+	        }
+	        else {
+		        $userInfo = BaseUserDataProvider::_mapUserInfoObject( $row );
+	        }	        
+	        
+	        return( $userInfo );
         }
 
         /**
@@ -233,14 +289,10 @@
 	        // update the phpbb table
 	        $password = $user->getPassword();
 	        $id = $this->getLastPhpBBUserId();
-	        if($user->getStatus() == USER_STATUS_ACTIVE )
-	        	$phpBBStatus = 1;
-	        else
-	        	$phpBBStatus = 0;
 	        	
 	        $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())."',$phpBBStatus);";
+                      Db::qstr($user->getEmail())."','1');";                      
                       
             $result = $this->_dbc->Execute( $query );            
 




More information about the pLog-svn mailing list