コード例 #1
0
ファイル: team.php プロジェクト: nsystem1/ZeeJong
 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);
 }
コード例 #2
0
ファイル: database.php プロジェクト: nsystem1/ZeeJong
 public function getCardsInMatch($matchId)
 {
     $sel = new \Selector('Cards');
     $sel->filter([['matchId', '=', $matchId]]);
     $sel->order('time', 'ASC');
     $result = $this->select($sel);
     return $this->resultToCards($result);
 }
コード例 #3
0
ファイル: referee.php プロジェクト: nsystem1/ZeeJong
 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);
 }
コード例 #4
0
ファイル: player.php プロジェクト: nsystem1/ZeeJong
 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);
 }