Example #1
0
 /**
  * Get json-string with matches for the specified teams. If two teams are sent in
  * a json-string with matches between the two teams are returned.
  * 
  * @param string $team - Specified team(s). Separate team names with ,
  */
 public static function getTeam($team, $limit = 500)
 {
     if ($limit == 0) {
         $limit = 5000;
     }
     $teams = explode(',', $team);
     $returnArr = array();
     //Control that max two teams are sent in
     if (count($teams) < 3) {
         $twoTeams = count($teams) == 2;
         $matches = json_decode(MatchesApi::getMatches($limit), true);
         foreach ($matches as $value) {
             if ($twoTeams) {
                 if ($value['HomeTeam'] === $teams[0] && $value['AwayTeam'] === $teams[1] || $value['HomeTeam'] === $teams[1] && $value['AwayTeam'] === $teams[0]) {
                     $returnArr[] = $value;
                 }
             } else {
                 if ($value['HomeTeam'] === $teams[0] || $value['AwayTeam'] === $teams[0]) {
                     $returnArr[] = $value;
                 }
             }
             if (count($returnArr) >= $limit) {
                 break;
             }
         }
     }
     return json_encode($returnArr);
 }
Example #2
0
 public static function getTeam($team)
 {
     $teams = explode(',', $team);
     $returnArr = array();
     //Control that max two teams are sent in
     if (count($teams) < 3) {
         $twoTeams = count($teams) == 2;
         $matches = json_decode(MatchesApi::getMatches());
         foreach ($matches as $key => $value) {
             if ($twoTeams) {
                 if ($value->HomeTeam === $teams[0] && $value->AwayTeam === $teams[1] || $value->HomeTeam === $teams[1] && $value->AwayTeam === $teams[0]) {
                     $returnArr[] = $value;
                 }
             } else {
                 if ($value->HomeTeam === $teams[0] || $value->AwayTeam === $teams[0]) {
                     $returnArr[] = $value;
                 }
             }
         }
     }
     return json_encode($returnArr);
 }
Example #3
0
    if ($path != '/' && substr($path, -1) == '/') {
        // permanently redirect paths with a trailing slash
        // to their non-trailing counterpart
        $uri = $uri->withPath(substr($path, 0, -1));
        return $response->withRedirect((string) $uri, 301);
    }
    return $next($request, $response);
});
$app->get('/api/stryktipset', function (Request $request, Response $response) {
    $response = $response->withHeader('Content-type', 'application/json');
    require 'api/cStryktipsetApi.php';
    $response->getBody()->write(StryktipsetApi::getRow());
    return $response;
});
$app->get('/api/matches', function (Request $request, Response $response) {
    $response = $response->withHeader('Content-type', 'application/json');
    require 'api/cMatchesApi.php';
    $response->getBody()->write(MatchesApi::getMatches());
    return $response;
});
$app->get('/api/matches/{team}', function (Request $request, Response $response, $args) {
    $response = $response->withHeader('Content-type', 'application/json');
    require 'api/cMatchesApi.php';
    $response->getBody()->write(MatchesApi::getTeam($args['team']));
    return $response;
});
$app->get('/', function (Request $request, Response $response) {
    $response->getBody()->write("kör denna för att hämta matcher <a href='api/matches'>länk</a><br />\n\tKör <a href='api/stryktipset'>denna</a> för att hämta stryktipsmatcherna<br />\n\tHämta Liverpools matcher <a href='api/matches/Liverpool'>här</a><br />\n\tHämta matcher med Arsenal och Liverpool <a href='api/matches/Liverpool,Arsenal'>här</a>");
    return $response;
});
$app->run();
Example #4
0
});
$app->group('/api/matches', function () {
    require 'app/api/cMatchesApi.php';
    header("Content-Type: application/json");
    $this->get('', function (Request $request, Response $response) {
        flush();
        return MatchesApi::getMatches();
    })->setName('matches');
    $this->get('/{team}', function (Request $request, Response $response, $args) {
        $limit = null;
        $parm = $request->getQueryParams();
        if (array_key_exists('limit', $parm)) {
            $limit = intval($parm['limit']);
        }
        flush();
        return MatchesApi::getTeam($args['team'], $limit);
    })->setName('matches-team');
});
$app->get('/api/tables', function (Request $request, Response $response, $args) {
    $response = $response->withHeader('Content-type', 'application/json');
    require 'app/api/cTablesApi.php';
    $table = TablesApi::getPremierLeagueTable();
    $response->getBody()->write($table);
    return $response;
});
$app->get('/stryktipset', function (Request $request, Response $response) {
    $response->getBody()->write(file_get_contents("webInterface/views/stryktipsView.html"));
    return $response;
});
$app->get('/matches', function (Request $request, Response $response) {
    $response->getBody()->write(file_get_contents("webInterface/views/matchesView.html"));