public function GET($args) { global $database; $sel = new \Selector('Team'); $sort = false; $sortColumn = ''; $sortOrder = ''; foreach ($_GET as $column => $value) { switch ($column) { case 'id': $sel->filter([['Team.id', '=', $value]]); break; case 'name': if (strlen($value) < 3) { $this->result = []; return; } $value = str_replace('%', '\\%', $value); $value = str_replace('[', '\\[', $value); $value = str_replace(']', '\\]', $value); $value = str_replace('_', '\\_', $value); $value = '%' . $value . '%'; $sel->filter([['Team.' . $column, 'LIKE', $value]]); break; case 'sort': if ($value == 'name') { $sort = true; $sortColumn = 'name'; } elseif ($value == 'id') { $sort = true; $sortColumn = 'id'; } break; case 'order': $sortOrder = $value; break; } } if ($sort) { if ($sortOrder === '') { $sel->order($sortColumn, 'DESC'); } else { $sel->order($sortColumn, $sortOrder); } } $sel->limit(0, 10); $result = $database->select($sel); $this->result = $database->resultToTeams($result); }
public function getUpcommingEvents($limit) { $time = time(); $time = strtotime(date('d-m-Y', $time)); $sel = new \Selector('Match'); $sel->filter([['date', '>=', $time]]); $sel->filter([['scoreId', 'IS NULL', '']]); $sel->order('date', 'ASC'); $sel->limit(0, $limit); $result = $this->select($sel); $matches = $this->resultToMatches($result); return $matches; }
public function GET($args) { global $database; $sel = new \Selector('Referee'); $sort = false; $sortColumn = ''; $sortOrder = ''; foreach ($_GET as $column => $value) { switch ($column) { case 'id': $sel->filter([['Referee.id', '=', $value]]); break; case 'firstname': case 'lastname': if (strlen($value) < 3) { $this->players = []; return; } $value = str_replace('%', '\\%', $value); $value = str_replace('[', '\\[', $value); $value = str_replace(']', '\\]', $value); $value = str_replace('_', '\\_', $value); $value = '%' . $value . '%'; $sel->filter([['Referee.' . $column, 'LIKE', $value]]); break; case 'sort': if ($value == 'firstname') { $sort = true; $sortColumn = 'firstname'; } else { if ($value == 'lastName') { $sort = true; $sortColumn = 'lastName'; } else { if ($value == 'id') { $sort = true; $sortColumn = 'id'; } } } break; case 'order': $sortOrder = $value; break; case 'search': $value = str_replace('%', '\\%', $value); $value = str_replace('[', '\\[', $value); $value = str_replace(']', '\\]', $value); $value = str_replace('_', '\\_', $value); $value = explode(' ', $value); $filters = []; foreach ($value as $term) { $filters[] = ['Referee.firstname', 'LIKE ', '%' . $term . '%']; $filters[] = ['Referee.lastname', 'LIKE ', '%' . $term . '%']; } $sel->filter($filters); break; } } if ($sort) { if ($sortOrder === '') { $sel->order($sortColumn, 'DESC'); } else { $sel->order($sortColumn, $sortOrder); } } $sel->limit(0, 10); $result = $database->select($sel); $this->result = $database->resultToReferees($result); }
public function GET($args) { global $database; $sel = new \Selector('Player'); $sort = false; $sortColumn = ''; $sortOrder = ''; $limit = 10; foreach ($_GET as $column => $value) { switch ($column) { case 'id': $sel->filter([['Player.id', '=', $value]]); break; case 'firstname': case 'lastname': if (strlen($value) < 3) { $this->players = []; return; } $value = str_replace('%', '\\%', $value); $value = str_replace('[', '\\[', $value); $value = str_replace(']', '\\]', $value); $value = str_replace('_', '\\_', $value); $value = '%' . $value . '%'; $sel->filter([['Player.' . $column, 'LIKE', $value]]); break; case 'sort': if ($value == 'match') { $sort = true; $sortColumn = 'playedMatches'; $sel->join('PlaysMatchInTeam', 'id', 'playerId'); $sel->group('Player.id'); $sel->select(['Player.*', 'COUNT(*) as playedMatches']); } elseif ($value == 'goal') { $sort = true; $sortColumn = 'goals'; $sel->join('Goal', 'id', 'playerId'); $sel->group('Player.id'); $sel->select(['Player.*', 'COUNT(*) as goals']); } elseif ($value == 'firstname') { $sort = true; $sortColumn = 'firstName'; } break; case 'order': $sortOrder = $value; break; case 'search': $value = str_replace('%', '\\%', $value); $value = str_replace('[', '\\[', $value); $value = str_replace(']', '\\]', $value); $value = str_replace('_', '\\_', $value); $value = explode(' ', $value); $filters = []; foreach ($value as $term) { $filters[] = ['Player.firstname', 'LIKE ', $term]; $filters[] = ['Player.lastname', 'LIKE ', $term]; } $sel->filter($filters); break; case 'limit': $limit = $value; break; } } if ($sort) { if ($sortOrder === '') { $sel->order($sortColumn, 'DESC'); } else { $sel->order($sortColumn, $sortOrder); } } $sel->limit(0, $limit); $result = $database->select($sel); $this->result = $database->resultToPlayers($result); }