<?php
//class for obtain informations about total stats of a player

class PlayerTotal
{
	private $player_id;
	
	/**
	 * @name GetPlayerTotalRounds
	 * @return int
	 * @desc Return the number of played rounds
	 */
	function GetPlayerTotalRounds()
	{
		$r_res=mysql_query('SELECT rounds FROM player_totals WHERE pid='.$this->player_id);
		if(mysql_num_rows($r_res)>0) return mysql_result($r_res,0,0);
		else return 0;
	}
	
	/**
	 * @name GetPlayerTotalStats
	 * @param b_average boolean[optional]
	 * @return array
	 * @desc Return an array with stats for marvelous, perfect, great, good, boo, miss, ok and ng steps. Return the average stats if b_average is set to true (default : true)
	 */
	function GetPlayerTotalStats($b_average=true)
	{
		$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_totals WHERE pid='.$this->player_id.' GROUP BY pid');
		$a_infos=mysql_fetch_assoc($r_res);
		if($b_average===true)
		{
			foreach($a_infos as $s_key => $s_value)
			{
				$a_infos[$s_key]=round($s_value/$this->GetPlayerTotalRounds(),0);
			}
		}
		return $a_infos;
	}
	
	/**
	 * @name GetPlayerTotalScore
	 * @return int
	 * @desc Return the Average Score.
	 */
	function GetPlayerTotalScore()
	{
		$r_res=mysql_query('SELECT score FROM player_totals WHERE pid='.$this->player_id);
		$i_info=mysql_result($r_res,0,0);
		return $i_info;
	}
	
	/**
	 * @name GetPlayerTotalGrade
	 * @param b_average boolean[optional]
	 * @return int
	 * @desc Return the Grade (0=AAAA -> 7=E). Return the average grade if b_average is set to true (default : true)
	 */
	function GetPlayerTotalGrade($b_average=true)
	{
		$r_res=mysql_query('SELECT grade FROM player_totals WHERE pid='.$this->player_id);
		$i_info=mysql_result($r_res,0,0);
		if($b_average===true)
		{
			$i_info=round($i_info/$this->GetPlayerTotalRounds(),0);
		}
		return $i_info;
	}
	
	/**
	 * @name GetPlayerTotalDifficulty
	 * @param b_average boolean[optional]
	 * @return int
	 * @desc Return the Difficulty (0=Beginner -> 5=Challenge). Return the average difficulty if b_average is set to true (default : true)
	 */
	function GetPlayerTotalDifficulty($b_average=true)
	{
		$r_res=mysql_query('SELECT difficulty FROM player_totals WHERE pid='.$this->player_id);
		$i_info=mysql_result($r_res,0,0);
		if($b_average===true)
		{
			$i_info=round($i_info/$this->GetPlayerTotalRounds(),0);
		}
		return $i_info;
	}
	
	/**
	 * @name GetPlayerTotalFeet
	 * @param b_average boolean[optional]
	 * @return int
	 * @desc Return the number of feet. Return the average feets if b_average is set to true (default : true)
	 */
	function GetPlayerTotalFeet($b_average=true)
	{
		$r_res=mysql_query('SELECT feet FROM player_totals WHERE pid='.$this->player_id);
		$i_info=mysql_result($r_res,0,0);
		if($b_average===true)
		{
			$i_info=round($i_info/$this->GetPlayerTotalRounds(),0);
		}
		return $i_info;
	}
	
	/**
	 * @name GetPlayerTotalToasty
	 * @param b_average boolean[optional]
	 * @return int
	 * @desc Return the number of toasty. Return the average toasty if b_average is set to true (default : true)
	 */
	function GetPlayerTotalToasty($b_average=true)
	{
		$r_res=mysql_query('SELECT toasty FROM player_totals WHERE pid='.$this->player_id);
		$i_info=mysql_result($r_res,0,0);
		if($b_average===true)
		{
			$i_info=round($i_info/$this->GetPlayerTotalRounds(),0);
		}
		return $i_info;
	}
	
	/**
	 * @name GetPlayerTotalMaxCombo
	 * @param b_average boolean[optional]
	 * @return int
	 * @desc Return the Max Combo. Return the average max combo if b_average is set to true (default : true)
	 */
	function GetPlayerTotalMaxCombo($b_average=true)
	{
		$r_res=mysql_query('SELECT maxcombo FROM player_totals WHERE pid='.$this->player_id);
		$i_info=mysql_result($r_res,0,0);
		if($b_average===true)
		{
			$i_info=round($i_info/$this->GetPlayerTotalRounds(),0);
		}
		return $i_info;
	}
	
	/**
	 * @name GetPlayerSeed
	 * @return int
	 * @desc Return the Seed Score
	 */
	function GetPlayerSeed()
	{
		$r_res=mysql_query('SELECT seed FROM player_totals WHERE pid='.$this->player_id);
		return mysql_result($r_res,0,0);
	}
	
	/**
	 * @name GetPlayerRoundDancePoints
	 * @return array
	 * @desc return the number of dane points obtained by the player and the maximum
	 */
	function GetPlayerTotalDancePoints($b_average=true)
	{
		$a_infos=$this->GetPlayerTotalStats(false);
		
		$a_return["maximum"]=($a_infos["total_steps"]*2)+($a_infos["total_freezes"]*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);
		
		if($b_average===true)
		{
			$a_return["maximum"]=round($a_return["maximum"]/$this->GetPlayerTotalRounds(),0);
			$a_return["obtained"]=round($a_return["obtained"]/$this->GetPlayerTotalRounds(),0);
		}
		
		return $a_return;
	}
	
	/**
	 * @name SetPlayerId
	 * @param i_pid int
	 * @desc Set the player_id used by the class
	 */
	function SetPlayerId($i_pid)
	{
		$this->player_id=$i_pid;
	}
}
?>