Class Liga{
public function __construct() {
global $wpdb;
$this->db = $wpdb;
}
public function get_teams(){
$teams = $this->db->get_results("SELECT * FROM uks_posts WHERE post_type='druzyny' AND post_status='publish' ORDER BY post_title ASC ");
return $teams;
}
public function get_games(){
$games = $this->db->get_results("SELECT * FROM uks_liga WHERE active!='0' ORDER BY game DESC ");
return $games;
}
public function get_game($g){
$game = $this->db->get_results("SELECT * FROM uks_liga WHERE id='$g' ");
return $game[0];
}
public function add_game($team1,$team2,$game,$place){
if($this->db->insert('uks_liga',
array(
'team1'=>$team1,
'team2'=>$team2,
'game'=>$game,
'place'=>$place,
'active'=>'1'
),
array(
'%d',
'%s',
'%s',
'%s',
'%d'
)
)!==false){
return true;
}else{
return false;
}
}
public function update_game($id,$team1,$team2,$game,$place,$score1,$score2){
if($this->db->update('uks_liga',
array(
'team1'=>$team1,
'team2'=>$team2,
'game'=>$game,
'place'=>$place,
'team1_score'=>$score1,
'team2_score'=>$score2
),
array("id"=> $id),
array(
'%d',
'%s',
'%s',
'%s',
'%d'
)
)!==false){
return true;
}else{
return false;
}
}
public function delete_game($id){
if($this->db->update('uks_liga',
array(
'active'=>0
),
array("id"=> $id),
array('%d')
)!==false){
return true;
}else{
return false;
}
}
public function get_coming_games($team=0,$limit=6){
$add = $team!=0 ? "AND team1='$team'" : "";
$games = $this->db->get_results("SELECT * FROM uks_liga WHERE active!='0' AND game >= NOW() $add ORDER BY game DESC LIMIT $limit");
return $games;
}
public function get_past_games($team=0,$limit=10){
$add = $team!=0 ? "AND team1='$team'" : "";
$games = $this->db->get_results("SELECT * FROM uks_liga WHERE active!='0' AND game <= NOW() $add ORDER BY game DESC LIMIT $limit");
return $games;
}
}
?> function liga_games(){
$l = new Liga();
?>