Browse Source

Removed mongo specific code

Michael Francis 14 years ago
parent
commit
c34c761790
1 changed files with 4 additions and 82 deletions
  1. 4 82
      models/User.php

+ 4 - 82
models/User.php

@@ -89,12 +89,7 @@ class User extends \lithium\data\Model {
 		joindate = today,
 		accesslevel = "user"
 	*/
-	public function updateuser($entity, $data)
-	{
-		$conditions = array('_id' => $entity->_id, 'state' => 'default');
-		$options = array('multiple' => false, 'safe' => true, 'upsert'=>true);
-		return static::update($data, $conditions, $options);
-	}
+	
 
 	/** 
 	 * Creates a post and stores it into the appropriate user(s) array(s)
@@ -109,9 +104,9 @@ class User extends \lithium\data\Model {
 		//TODO add validators to these methods/models
 		
 		//Create the post
-		$post = Post::create(array('datetime' => new MongoDate(),
+		$post = Post::create(array(//'datetime' => new MongoDate(),
 								   'username' => $entity->username,
-								   'user_id' => $entity->_id,
+								   'user_id' => $entity->id,
 								   'level' => null));
 		//1. Parse 
 		//Break the string into an array of words
@@ -148,59 +143,8 @@ class User extends \lithium\data\Model {
 		
 		//Save the post to the posts database. 
 		$post->save();
-		
-		//If the user has friends 
-		if (count($entity->friends) > 0)
-		{
-			//Save this posts to the feed of all the Users Friends 
-			$post->storeAll($entity->friends);
-		}
-		//Add this post to the user's feed array
-		$post->store($entity);
-
-
-
-
-		//$save = $entity->save(null, array('validate' => false));
-		/* In the future, there should be a way to make this method quicker and non-blocking*/
-		//For each friend, post it in their feed (friends is an array of usernames as strings)
-		/*if (!empty($entity->friends))
-		{
-			foreach ($entity->friends as $friend)
-			{
-				//Grab the friend from the database
-				$curFriend = User::find('first', array('conditions' => array('username' => $friend)));
-				
-				//Add the post to their feed.
-				//Array unshift puts the new post at the first element of the feed array.
-				$curFriend->feed = array_unshift($post->_id, $curFriend->feed); 
-				
-				//Save the friend to the database, 
-				$curFriend->save(array('validates' => false));
-
-				//Eventually, we can call a node.js endpoint here 
-				//To tell all subscribers that there is a new a post
-				//Something like "curl POST $post->_id nodeserver://endpoint/myFeed"
-			}
-		} */
 	}
 
-	/**
-	 * Store's the post to the specified user's feed 
-	 * @param User $user The user to add the post to
-	 * @param Post $post The post too add to the feed 
-	 * @return boolean True if the operation sucsceeded, false otherwise
-	 */
-	private function storePost($user, $post)
-	{
-		$updateData = array('$push' => array('feed' =>  $post['_id']->__toString()));
-		$conditions =  array('_id' => $user['_id']);
-		$result = User::update($updateData, $conditions, array('atomic' => false));
-
-		return $result; 
-	}
-
-
 	/**
 	 * Returns the appropriate post level for the post 
 	 * @see app\models\Post
@@ -275,29 +219,7 @@ class User extends \lithium\data\Model {
 				'level' => 'public',
 			);
 
-		//If the user passed in options 
-		if (!empty($options))
-		{
-			//merge the options with the defaults (upsert them) 
-			array_merge($defaults, $options);
-		}	
-
-		//var_dump($entity);
-		//exit();
-		//If the user has more posts than the limit, return the limit, if the have less return 
-		$count = (count($entity->feed) >= $defaults['limit']) ? $defaults['limit'] : count($entity->feed); 
-		if ($count == 0)
-		{
-			return false;
-		}
-		//else
-		var_dump(Post::find('all', array('conditions' => array('$in' => $entity->feed))));
-		exit();
-		for ($i = 0; $i < $count; $i++)
-		{
-			$posts[] = Post::find('all', array('conditions' => array('$in' => $entity->feed)));
-			$posts[] = Post::find($qaulifier, array('conditions' => array('_id' => $entity->feed[$i], 'level' => $defaults[level])));
-		}
+		//If the user passed in options
 		return $posts;
 	}