Example #1
0
		public function compare($one, $two)
		{
			if( !($one instanceof Item) )
			{
				if( is_integer($one) )
				{
					$one = Item::getByID($one);
				}
				else
				{
					return false;
				}
			}
			
			if( !($two instanceof Item) )
			{
				if( is_integer($two) )
				{
					$two = Item::getByID($two);
				}
				else
				{
					return false;
				}
			}
			
			$ratings[0] = Rating::getByUserForItem($this->user->userid, $one->itemid);
			$ratings[1] = Rating::getByUserForItem($this->user->userid, $two->itemid);
			$views[0] = View::getByUserForItem($this->user->userid, $one->itemid);
			$views[1] = View::getByUserForItem($this->user->userid, $two->itemid);
			
			$willTheyLikeTwoComparedToOne = 0;
			
			//first, try to compare ratings
			if( $ratings[0] || $ratings[1] )
			{
				if( $ratings[0] && $ratings[1] )
				{
					//only use the first rating because if there's more than one that's bullshit.
					$oneRate = Base::toArray($ratings[0]);
					$oneRate = $oneRate[0];
					$twoRate = Base::toArray($ratings[1]);
					$twoRate = $twoRate[0];
					
					if( $oneRate == 0 )
					{
						$oneRate = .0000000000000001;
					}
					if( $twoRate == 0 )
					{
						$twoRate = .0000000000000001;
					}
					
					$oneRate = 1 / $oneRate->rating;
					$twoRate = 1 / $twoRate->rating;
					
					$diff = $oneRate - $twoRate;
				}
				else
				{
					//one item doesn't have ratings
					//don't do anything right now.
				}
				
				$willTheyLikeTwoComparedToOne += $diff * .1;
			}
			else
			{
				//no ratings for either item
			}
			
			//try to compare number of views
			//people are more likely to view something if they want it (even subconsciously)
			//so the comparison of views could offer a rough estimate
			if( $views[0] || $views[1] )
			{
				if( $views[0] && $views[1] )
				{
					//get counts
					$vwOne = count(Base::toArray($views[0]));
					$vwTwo = count(Base::toArray($views[1])); // ah, vwTwo, the most difficult Pokemon to catch.
					
					//close or equal
					if( ( $vwTwo - 1 < $vwOne ) && ( $vwTwo < $vwTwo + 1 ) )
					{
						//bump up the likelihood
						$willTheyLikeTwoComparedToOne += .05;
					}
					elseif( $vwTwo < $vwOne )
					{
						//maybe not
						$willTheyLikeTwoComparedToOne -= .05;
					}
					else
					{
						//very likely
						$willTheyLikeTwoComparedToOne += .1;
					}
				}
				else
				{
					//one of the items hasn't been viewed
					//don't do anything right now.
				}
			}
			else
			{
				//The user has no views for either item
			}
			
			return $willTheyLikeTwoComparedToOne;
		}