示例#1
0
 function nba_career_stats($player, $position, $team)
 {
     //build tables based on position
     $html = '';
     $html .= '<table class="player_stats_table table table-condensed table-striped">';
     //add table headers
     $html .= '<thead><tr><th><div class="th-inner">YEAR</div></th><th><div class="th-inner">TEAM</div></th><th><div class="th-inner">GAMES</div></th>' . '<th><div class="th-inner">MIN</div></th><th><div class="th-inner">FGM-FGA</div></th><th><div class="th-inner">FG%</div></th><th><div class="th-inner">3PM-3PA</div></th><th><div class="th-inner">3P%</div></th><th><div class="th-inner">FTM-FTA</div></th><th><div class="th-inner">FT%</div></th><th><div class="th-inner">REBPG</div></th><th><div class="th-inner">ASTPG</div></th>' . '<th><div class="th-inner">BLKPG</div></th><th><div class="th-inner">STLPG</div></th><th><div class="th-inner">TOPG</div></th><th><div class="th-inner">PTSPG</div></th>' . '</tr></thead>';
     $html .= '<tbody>';
     //current season
     $qcur = $this->db->query('SELECT season FROM ci_sport_event WHERE sport = "nba" ORDER BY season DESC LIMIT 1');
     $current = $qcur->row();
     $current_season = $current->season;
     if (!function_exists('nba_career_rows')) {
         function nba_career_rows($query, $year, $team = '')
         {
             $stat_fields = array('games', 'minutes', 'field-goals-made-attempted', 'field-goals-percentage', 'three-point-field-goals-made-attempted', 'three-point-field-goals-percentage', 'free-throws-made-attempted', 'free-throws-percentage', 'rebounds-total-average', 'assists-average', 'blocked-shots-average', 'steals-average', 'turnovers-average', 'points-average');
             foreach ($query->result() as $stats_array) {
                 $c_stats[$stats_array->statkey] = $stats_array->statvalue;
             }
             //start building the output
             $c_stats['games'] = round($c_stats['games'], 0);
             if ($c_stats['games'] == 0) {
                 $c_stats['games'] = 1;
             }
             $c_stats['minutes'] = round($c_stats['minutes'], 1);
             $c_stats['field-goals-made-attempted'] = round($c_stats['field-goals-made'], 0) . '-' . round($c_stats['field-goals-attempted'], 0);
             $c_stats['field-goals-percentage'] = ltrim(round($c_stats['field-goals-percentage'], 3), 0);
             $c_stats['three-point-field-goals-made-attempted'] = round($c_stats['three-point-field-goals-made'], 0) . '-' . round($c_stats['three-point-field-goals-attempted'], 0);
             $c_stats['three-point-field-goals-percentage'] = ltrim(round($c_stats['three-point-field-goals-percentage'], 3), 0);
             $c_stats['free-throws-made-attempted'] = round($c_stats['free-throws-made'], 0) . '-' . round($c_stats['free-throws-attempted'], 0);
             $c_stats['free-throws-percentage'] = ltrim(round($c_stats['free-throws-percentage'], 3), 1);
             $c_stats['rebounds-total-average'] = round($c_stats['rebounds-total'] / $c_stats['games'], 1);
             $c_stats['assists-average'] = round($c_stats['assists'] / $c_stats['games'], 1);
             $c_stats['blocked-shots-average'] = round($c_stats['blocked-shots'] / $c_stats['games'], 1);
             $c_stats['steals-average'] = round($c_stats['steals'] / $c_stats['games'], 1);
             $c_stats['personal-fouls-average'] = round($c_stats['personal-fouls'] / $c_stats['games'], 1);
             $c_stats['turnovers-average'] = round($c_stats['turnovers'] / $c_stats['games'], 1);
             $c_stats['points-average'] = round($c_stats['points'] / $c_stats['games'], 1);
             /*
             echo "<pre>";
             					print_r($c_stats);
             					echo "</pre>";
             */
             if ($c_stats['three-point-field-goals-attempted'] == 0) {
                 $c_stats['three-point-field-goals-made-attempted'] = round($c_stats['three_point_field_goals_made'], 0) . '-' . round($c_stats['three_point_field_goals_attempted'], 0);
                 $c_stats['three-point-field-goals-percentage'] = number_format(round($c_stats['three_point_field_goals_made'], 0) / round($c_stats['three_point_field_goals_attempted'], 0), 3);
                 //$c_stats['three-point-field-goals-percentage'] = ltrim(round($c_stats['three-point-field-goals-percentage'],3),0);
             }
             if ($c_stats['free-throws-percentage'] == 0) {
                 $c_stats['free-throws-percentage'] = number_format(round($c_stats['free_throws_made'], 0) / round($c_stats['free_throws_attempted'], 0), 3);
                 $c_stats['free-throws-made-attempted'] = round($c_stats['free_throws_made'], 0) . '-' . round($c_stats['free_throws_attempted'], 0);
             }
             if ($c_stats['blocked-shots-average'] == 0) {
                 $c_stats['blocked-shots-average'] = round($c_stats['blocks'] / $c_stats['games'], 1);
             }
             if ($c_stats['rebounds-total-average'] == 0) {
                 $bords = number_format(round($c_stats['rebounds_defensive'], 0) + round($c_stats['rebounds_offensive'], 0), 3);
                 $c_stats['rebounds-total-average'] = number_format(round($bords, 0) / round($c_stats['games'], 0), 2);
             }
             if ($c_stats['minutes'] == 0) {
                 $c_stats['minutes'] = round($c_stats['seconds_played'] / 60);
             }
             if ($c_stats['field-goals-made'] == 0) {
                 $c_stats['field-goals-made'] = $c_stats['field_goals_made'];
                 $c_stats['field-goals-percentage'] = number_format(round($c_stats['field-goals-made'], 0) / round($c_stats['field-goals-attempted'], 0), 3);
             }
             if ($c_stats['field-goals-made-attempted'] == 0) {
                 $c_stats['field-goals-made-attempted'] = round($c_stats['field_goals_made'], 0) . '-' . round($c_stats['field-goals-attempted'], 0);
             }
             if ($year == $current_season) {
                 if ($ret != "") {
                     return $c_stats;
                 }
             }
             $html = '<tr><td>' . $year . '</td>';
             $html .= '<td>' . $team . '</td>';
             //add all the stats
             foreach ($stat_fields as $n) {
                 if (isset($c_stats[$n])) {
                     $html .= '<td>' . $c_stats[$n] . '</td>';
                 } else {
                     $html .= '<td>0</td>';
                 }
             }
             $html .= '</tr>';
             // 					echo $html;
             return $html;
         }
     }
     //get career totals
     $this->db->where('player_id', $player);
     $this->db->where('year', 0);
     $query = $this->db->get('sport_player_career');
     if ($query->num_rows() > 0) {
         $html .= nba_career_rows($query, 'CAREER');
     }
     //check if player has stats over last 25 years
     for ($i = $current_season; $i > $current_season - 25; $i--) {
         /*$this->db->where('player_id',$player);
         		$this->db->where('year',$i);
         		$query=$this->db->get('sport_player_career');
         		if($query->num_rows() > 0) {
         			$html .= nba_career_rows($query,$i);
         		}*/
         //see if player was traded midseason, if so loop through all team stats
         $this->db->select('DISTINCT(team_id) as team_id, alias');
         $this->db->from('sport_player_career');
         $this->db->from('sport_team');
         $this->db->where('team_id = cid');
         $this->db->where('year', $i);
         $this->db->where('player_id', $player);
         $this->db->where('team_id !=', 0);
         $tquery = $this->db->get();
         foreach ($tquery->result() as $tq) {
             $this->db->where('player_id', $player);
             $this->db->where('year', $i);
             $this->db->where('team_id', $tq->team_id);
             $query = $this->db->get('sport_player_career');
             if ($query->num_rows() > 0) {
                 $html .= nba_career_rows($query, $i, $tq->alias);
             }
         }
     }
     $html .= '</tbody>';
     $html .= '</table>';
     return $html;
 }
	function nba_career_stats($player, $position, $team) {
			
		//build tables based on position
		$html = '';
		$html .= '<table class="player_stats_table table table-condensed table-striped">';
		
		//add table headers
		$html .= 	'<thead><tr><th><div class="th-inner">YEAR</div></th><th><div class="th-inner">GAMES</div></th>'.
					'<th><div class="th-inner">MIN</div></th><th><div class="th-inner">FGM-FGA</div></th><th><div class="th-inner">FG%</div></th><th><div class="th-inner">3PM-3PA</div></th><th><div class="th-inner">3P%</div></th><th><div class="th-inner">FTM-FTA</div></th><th><div class="th-inner">FT%</div></th><th><div class="th-inner">REBPG</div></th><th><div class="th-inner">ASTPG</div></th>'.
					'<th><div class="th-inner">BLKPG</div></th><th><div class="th-inner">STLPG</div></th><th><div class="th-inner">PFPG</div></th><th><div class="th-inner">TOPG</div></th><th><div class="th-inner">PTSPG</div></th>'.
					'</tr></thead>';
			$html .= '<tbody>';
			//current season
			$qcur = $this->db->query('SELECT season FROM ci_sport_event WHERE sport = "nba" ORDER BY season DESC LIMIT 1');
			$current = $qcur->row();
			$current_season = $current->season;
				
			if(!function_exists('nba_career_rows')) {
				function nba_career_rows($query,$year) {
				
					$stat_fields = array('games','minutes','field-goals-made-attempted','field-goals-percentage','three-point-field-goals-made-attempted','three-point-field-goals-percentage','free-throws-made-attempted','free-throws-percentage',
						'rebounds-total-average','assists-average','blocked-shots-average','steals-average','personal-fouls-average','turnovers-average','points-average');
				
					foreach($query->result() as $stats_array) {
						$c_stats[$stats_array->statkey] = $stats_array->statvalue;
					}
								
					//start building the output
				
					$c_stats['games'] = round($c_stats['games'],0);
					$c_stats['minutes'] = number_format($c_stats['minutes'],1);
					$c_stats['field-goals-made-attempted'] = round($c_stats['field-goals-made'],0).'-'.round($c_stats['field-goals-attempted'],0);
					$c_stats['field-goals-percentage'] = ltrim($c_stats['field-goals-percentage'],0);
					$c_stats['three-point-field-goals-made-attempted'] = round($c_stats['three-point-field-goals-made'],0).'-'.round($c_stats['three-point-field-goals-attempted'],0);
					$c_stats['three-point-field-goals-percentage'] = ltrim($c_stats['three-point-field-goals-percentage'],0);
					$c_stats['free-throws-made-attempted'] = round($c_stats['free-throws-made'],0).'-'.round($c_stats['free-throws-attempted'],0);
					$c_stats['free-throws-percentage'] = ltrim($c_stats['free-throws-percentage'],0);
					$c_stats['rebounds-total-average'] = number_format(round($c_stats['rebounds-total']/$c_stats['games'],1),1);
					$c_stats['assists-average'] = number_format(round($c_stats['assists']/$c_stats['games'],1),1);
					$c_stats['blocked-shots-average'] = number_format(round($c_stats['blocked-shots']/$c_stats['games'],1),1);
					$c_stats['steals-average'] = number_format(round($c_stats['steals']/$c_stats['games'],1),1);
					$c_stats['personal-fouls-average'] = number_format(round($c_stats['personal-fouls']/$c_stats['games'],1),1);
					$c_stats['turnovers-average'] = number_format(round($c_stats['turnovers']/$c_stats['games'],1),1);
					$c_stats['points-average'] = number_format(round($c_stats['points']/$c_stats['games'],1),1);

					
					$html = '<tr><td>'.$year.'</td>';
					//add all the stats			
					foreach($stat_fields as $n) {
						if(isset($c_stats[$n])) {
							$html .= '<td>'.$c_stats[$n].'</td>';
						} else {
						$html .= '<td>0</td>';
						}
					}					
					$html .= '</tr>';
					
					return $html;
				}
			}		

				
			//get career totals
			$this->db->where('player_id',$player);
			$this->db->where('year',0);
			$query=$this->db->get('sport_player_career');
			if($query->num_rows() > 0) {
				$html .= nba_career_rows($query,'CAREER');
			}
			
			//check if player has stats over last 25 years
			for($i = $current_season; $i > $current_season-25; $i--) {
				$this->db->where('player_id',$player);
				$this->db->where('year',$i);
				$query=$this->db->get('sport_player_career');
				if($query->num_rows() > 0) {
					$html .= nba_career_rows($query,$i);
				}	
			}
		
		$html .= '</tbody>';
		$html .= '</table>';
		
		return $html;
	}