Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/vendor/
.idea
14 changes: 14 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "irail/irail-bikes-resource",
"authors": [
{
"name": "Tjoosten",
"email": "Tjoosten3@gmail.com"
}
],
"autoload": {
"psr-4":{
"Irail\\BikesResource\\": "src/"
}
}
}
534 changes: 0 additions & 534 deletions gpoint.php

This file was deleted.

76 changes: 43 additions & 33 deletions Velo.class.php → src/Velo.class.php
Original file line number Diff line number Diff line change
@@ -1,89 +1,99 @@
<?php

namespace Irail\BikesResource;

/**
*
*
* @package packages/Bikes
* @copyright (C) 2012 by iRail vzw/asbl
* @license AGPLv3
* @author Pieter Colpaert <pieter aŧ iRail.be>
*/
class BikesVelo extends AReader
{

class BikesVelo extends AReader{

public function __construct($package, $resource, $RESTparameters) {
parent::__construct($package, $resource, $RESTparameters);
public function __construct($package, $resource, $RESTparameters)
{
parent::__construct($package, $resource, $RESTparameters);
$this->lat = null;
$this->long = null;
$this->offset = 0;
$this->rowcount = 1024;
}

public static function getParameters(){
return array( "lat" => "Latitude"
,"long" => "Longitude"
,"offset" => "Offset"
,"rowcount" => "Rowcount");
public static function getParameters()
{
return [
"lat" => "Latitude",
"long" => "Longitude",
"offset" => "Offset",
"rowcount" => "Rowcount",
];
}

public static function getRequiredParameters(){
public static function getRequiredParameters()
{
return array();
}

public function setParameter($key,$val){
if($key == "lat") {
public function setParameter($key, $val)
{
if ($key == "lat") {
$this->lat = $val;
} else if ($key == "long") {
} elseif ($key == "long") {
$this->long = $val;
} else if ($key == "offset") {
} elseif ($key == "offset") {
$this->offset = $val;
} else if ($key == "rowcount") {
} elseif ($key == "rowcount") {
$this->rowcount = $val;
}
}

public function read(){
public function read()
{
$data = TDT::HttpRequest("http://ClearChannelBikes:WbRpWHk6Ur@m.velo-antwerpen.be/data/stations.json");
$decoded = json_decode($data->data);
//todo: convert to wished format

$result = array();
$gpoint = new gPoint();
foreach($decoded as $sourceStation) {

foreach ($decoded as $sourceStation) {
$station = new Object();

$station->name = $sourceStation->name;
$station->freebikes = $sourceStation->bikes;
$station->freespots = $sourceStation->slots;
$station->state = $sourceStation->status;
$station->latitude = $sourceStation->latitude;
$station->longitude = $sourceStation->longitude;

$gpoint->setLongLat($station->longitude, $station->latitude);
if($this->lat != null && $this->long != null) {

if ($this->lat != null && $this->long != null) {
$station->distance = $gpoint->distanceFrom($this->long, $this->lat);
}

array_push($result, $station);
}

function compare($a, $b) {

function compare($a, $b)
{
if ($a->distance == $b->distance) {
return 0;
}
return ($a->distance < $b->distance) ? -1 : 1;
}
if($this->lat != null && $this->long != null) {

if ($this->lat != null && $this->long != null) {
usort($result, "compare");
}

return array_slice($result, $this->offset, $this->rowcount);
}

public static function getDoc(){
public static function getDoc()
{
return "This resource contains dynamic information about the availability of bikes in Antwerp";
}
}

?>
83 changes: 47 additions & 36 deletions Villo.class.php → src/Villo.class.php
Original file line number Diff line number Diff line change
@@ -1,99 +1,110 @@
<?php

namespace Irail\BikesResource;

use Irail\BikesResource\gPoint;

/**
*
*
* @package packages/Bikes
* @copyright (C) 2012 by iRail vzw/asbl
* @license AGPLv3
* @author Pieter Colpaert <pieter aŧ iRail.be>
*/

include_once('gpoint.php');

class BikesVillo extends AReader{
class BikesVillo extends AReader
{

public function __construct($package, $resource, $RESTparameters) {
parent::__construct($package, $resource, $RESTparameters);
public function __construct($package, $resource, $RESTparameters)
{
parent::__construct($package, $resource, $RESTparameters);
$this->lat = null;
$this->long = null;
$this->offset = 0;
$this->rowcount = 1024;
}

public static function getParameters(){
return array( "lat" => "Latitude"
,"long" => "Longitude"
,"offset" => "Offset"
,"rowcount" => "Rowcount");
public static function getParameters()
{
return [
"lat" => "Latitude",
"long" => "Longitude",
"offset" => "Offset",
"rowcount" => "Rowcount",
];
}

public static function getRequiredParameters(){
public static function getRequiredParameters()
{
return array();
}

public function setParameter($key,$val){
if($key == "lat") {
public function setParameter($key, $val)
{
if ($key == "lat") {
$this->lat = $val;
} else if ($key == "long") {
} elseif ($key == "long") {
$this->long = $val;
} else if ($key == "offset") {
} elseif ($key == "offset") {
$this->offset = $val;
} else if ($key == "rowcount") {
} elseif ($key == "rowcount") {
$this->rowcount = $val;
}
}

public function read(){
public function read()
{
$data = TDT::HttpRequest("http://www.mobielbrussel.irisnet.be/villo/json/");
$decoded = json_decode($data->data);
//todo: convert to wished format

$result = array();
$gpoint = new gPoint();
foreach($decoded->features as $feature) {

foreach ($decoded->features as $feature) {
$station = new Object();

$station->name = $feature->properties->NAME;
$station->freebikes = $feature->properties->FREEBK;
$station->freespots = $feature->properties->FREEBS;
$station->state = $feature->properties->STATE;

// Configure the gPoint library to use the Lambert Projection for Belgium
$gpoint->configLambertProjection(150000.013, 5400088.438, 4.367487, 90, 49.833333, 51.166666);
$x = $feature->geometry->coordinates[0];
$y = $feature->geometry->coordinates[1];

$gpoint->setLambert($x, $y);
// Convert the Lambert Coordinates to Latitude and Longitude (using the gPoint Library)
$gpoint->convertLCCtoLL();

$station->latitude = $gpoint->lat;
$station->longitude = $gpoint->long;
if($this->lat != null && $this->long != null) {

if ($this->lat != null && $this->long != null) {
$station->distance = $gpoint->distanceFrom($this->long, $this->lat);
}

array_push($result, $station);
}

function compare($a, $b) {

function compare($a, $b)
{
if ($a->distance == $b->distance) {
return 0;
}
return ($a->distance < $b->distance) ? -1 : 1;
}
if($this->lat != null && $this->long != null) {

if ($this->lat != null && $this->long != null) {
usort($result, "compare");
}

return array_slice($result, $this->offset, $this->rowcount);
}

public static function getDoc(){
public static function getDoc()
{
return "This resource contains dynamic information about the availability of bikes in Brussels";
}
}

?>
Loading