<?php
//Class for obtain informations about one round

class PlayerRound
{
	private $round_key;
	
	/**
	 * @name GetPlayerRoundStats
	 * @return array
	 * @desc Return an array with stats for marvelous, perfect, great, good, boo, miss, ok and ng steps
	 */
	function GetPlayerRoundStats()
	{
		$r_res=mysql_query('SELECT marvelous,perfect,great,good,boo,miss,ok,ng,hmine,amine,(marvelous+perfect+great+good+boo+miss) as total_steps, (ok+ng) as total_freezes, (hmine+amine) as total_mines FROM player_stats WHERE round_key='.$this->round_key.' GROUP BY round_key');
		return mysql_fetch_assoc($r_res);
	}
	
	
	/**
	 * @name GetPlayerRound
	 * @param i_pid int
	 * @param i_start int[optional]
	 * @param i_end int[optional]
	 * @param s_order string[optional]
	 * @return array
	 * @desc Return an array with round key who corresponds
	 */
	function GetPlayerRound($i_pid,$i_start=1,$i_nb=NULL,$s_order='DESC')
	{
		$i_pos=0;
		$r_res=mysql_query('SELECT round_key FROM player_stats WHERE pid='.$i_pid.' ORDER BY round_key '.$s_order);
		while($a_infos=mysql_fetch_assoc($r_res))
		{
			$i_pos++;
			if($i_pos<$i_start) continue;
			if($i_pos>$i_start+$i_nb) break;
			$a_return[]=$a_infos['round_key'];
		}
		return $a_return;
	}
	
	/**
	 * @name GetPlayerRoundID
	 * @return int
	 * @desc Return the Round_ID
	 */
	function GetPlayerRoundID()
	{
		$r_res=mysql_query('SELECT round_ID FROM player_stats WHERE round_key='.$this->round_key);
		return mysql_result($r_res,0,0);
	}
	
	/**
	 * @name GetPlayerID
	 * @return int
	 * @desc Return the Player_ID
	 */
	function GetPlayerID()
	{
		$r_res=mysql_query('SELECT pid FROM player_stats WHERE round_key='.$this->round_key);
		return mysql_result($r_res,0,0);
	}
	
	/**
	 * @name GetPlayerRoundScore
	 * @return int
	 * @desc Return the Score
	 */
	function GetPlayerRoundScore()
	{
		$r_res=mysql_query('SELECT score FROM player_stats WHERE round_key='.$this->round_key);
		return mysql_result($r_res,0,0);
	}
	
	/**
	 * @name GetPlayerRoundGrade
	 * @return int
	 * @desc Return the Grade (0=AAAA -> 7=E)
	 */
	function GetPlayerRoundGrade()
	{
		$r_res=mysql_query('SELECT grade FROM player_stats WHERE round_key='.$this->round_key);
		return mysql_result($r_res,0,0);
	}
	
	/**
	 * @name GetPlayerRoundDifficulty
	 * @return int
	 * @desc Return the Difficulty (0=Beginner -> 5=Challenge)
	 */
	function GetPlayerRoundDifficulty()
	{
		$r_res=mysql_query('SELECT difficulty FROM player_stats WHERE round_key='.$this->round_key);
		return mysql_result($r_res,0,0);
	}
	
	/**
	 * @name GetPlayerRoundFeet
	 * @return int
	 * @desc Return the number of feet
	 */
	function GetPlayerRoundFeet()
	{
		$r_res=mysql_query('SELECT feet FROM player_stats WHERE round_key='.$this->round_key);
		return mysql_result($r_res,0,0);
	}
	
	/**
	 * @name GetPlayerRoundToasty
	 * @return int
	 * @desc Return the number of toasty
	 */
	function GetPlayerRoundToasty()
	{
		$r_res=mysql_query('SELECT toasty FROM player_stats WHERE round_key='.$this->round_key);
		return mysql_result($r_res,0,0);
	}
	
	/**
	 * @name GetPlayerRoundMineStats
	 * @return array
	 * @desc Return array with the number of hit/avoid mines
	 */
	function GetPlayerRoundMineStats()
	{
		$r_res=mysql_query('SELECT hmine,amine FROM player_stats WHERE round_key='.$this->round_key);
		return mysql_fetch_assoc($r_res);
	}
	
	/**
	 * @name GetPlayerRoundMaxCombo
	 * @return int
	 * @desc Return the Max Combo
	 */
	function GetPlayerRoundMaxCombo()
	{
		$r_res=mysql_query('SELECT maxcombo FROM player_stats WHERE round_key='.$this->round_key);
		return mysql_result($r_res,0,0);
	}
	
	/**
	 * @name GetPlayerRoundOptions
	 * @return string
	 * @desc Return the Grade (0=AAAA -> 7=E)
	 */
	function GetPlayerRoundOptions()
	{
		$r_res=mysql_query('SELECT options FROM player_stats WHERE round_key='.$this->round_key);
		return mysql_result($r_res,0,0);
	}
	
	/**
	 * @name GetPlayerRoundTiming
	 * @return int
	 * @desc Return the Grade (0=AAAA -> 7=E)
	 */
	function GetPlayerRoundTiming()
	{
		$r_res=mysql_query('SELECT timing FROM player_stats WHERE round_key='.$this->round_key);
		return mysql_result($r_res,0,0);
	}
	
	/**
	 * @name GetPlayerRoundDancePoints
	 * @return array
	 * @desc return the number of dance points obtained by the player and the maximum
	 */
	function GetPlayerRoundDancePoints()
	{
		$a_infos=$this->GetPlayerRoundStats();
		
		$i_total_steps=$a_infos["marvelous"]+$a_infos["perfect"]+$a_infos["great"]+$a_infos["good"]+$a_infos["boo"]+$a_infos["miss"];
		$i_total_freeze=$a_infos["ok"]+$a_infos["ng"];
		
		$a_return["maximum"]=($i_total_steps*2)+($i_total_freeze*6);
		$a_return["obtained"]=($a_infos["marvelous"]*2)+($a_infos["perfect"]*2)+$a_infos["great"]+($a_infos["ok"]*6)-($a_infos["boo"]*4)-($a_infos["miss"]*8);
		$a_return["percent"]=round(($a_return["obtained"]*100)/$a_return["maximum"],2);
		
		return $a_return;
	}
	
	/**
	 * @name SetRoundKey
	 * @param i_rk int
	 * @desc Set the round_key used by the class
	 */
	function SetRoundKey($i_rk)
	{
		$this->round_key=$i_rk;
	}
}
?>