PHP Classes

Share Bike: Manage a bike sharing system

Recommend this page to a friend!
  Info   View files Example   View files View files (10)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 111 All time: 9,596 This week: 212Up
Version License PHP version Categories
sharebike 1.0.0Freeware5PHP 5, Libraries
Description 

Author

This package can be used to manage a bike sharing system.

It provides a collection of classes that model the different aspects of system that allows people to share bikes to take rides to different places.

Currently it can find the nearest bike, unlock the bike, travel to another place, manage a ride of a bike to a destination place, and record bike route.

Innovation Award
PHP Programming Innovation award nominee
June 2018
Number 7
Many people use bike sharing services, so they can use the bikes for small trips and travel around to near places, being those for pleasure or to do some kind of work.

This package implements a bike sharing management system in PHP by the means of a collection of classes that implement the different aspects of a bike sharing system.

Manuel Lemos
Picture of Charles
  Performance   Level  
Name: Charles <contact>
Classes: 4 packages by
Country: China China
Age: 51
All time rank: 170419 in China China
Week rank: 32 Up1 in China China Up
Innovation award
Innovation award
Nominee: 4x

Winner: 1x

Example

<?php
use ShareBike\Bike;
use
ShareBike\Mobile;
use
ShareBike\Cloud;
use
ShareBike\Person;
use
ShareBike\Place;
use
ShareBike\Factory;

require_once(
'/var/www/html/practise/hospital/sharebike/Cloud.php');
require_once(
'/var/www/html/practise/hospital/sharebike/Bike.php');
require_once(
'/var/www/html/practise/hospital/sharebike/Mobile.php');
require_once(
'/var/www/html/practise/hospital/sharebike/Person.php');
require_once(
'/var/www/html/practise/hospital/sharebike/Place.php');
require_once(
'/var/www/html/practise/hospital/sharebike/Factory.php');
?>

<!DOCTYPE html>
<html>
<head>
    <title>Share Bike</title>
    <script type="text/javascript">
       
    </script>
    <link href = 'style.css' rel = 'stylesheet' type ='text/css' />
</head>
<body>
    <div class = 'main'>
<?php
$factory
= new Factory();
$bike1 = $factory->make('bike','bike1', ['x' =>'141', 'y' => '220']);
echo
"<div id ='".htmlspecialchars($bike1->getBarcode())."'>";
echo
htmlspecialchars($bike1->getBarcode());
echo
"</div>";

$bike2 = $factory->make('bike','bike2', ['x' =>'41', 'y' => '20']);
echo
"<div id ='".htmlspecialchars($bike2->getBarcode())."'>";
echo
htmlspecialchars($bike2->getBarcode());
echo
"</div>";

$bike3 = $factory->make('bike','bike3', ['x' =>'81', 'y' => '60']);
echo
"<div id ='".htmlspecialchars($bike3->getBarcode())."'>";
echo
htmlspecialchars($bike3->getBarcode());
echo
"</div>";

$bike4 = $factory->make('bike','bike4', ['x' =>'501', 'y' => '400']);
echo
"<div id ='".htmlspecialchars($bike4->getBarcode())."'>";
echo
htmlspecialchars($bike4->getBarcode());
echo
"</div>";

$bike5 = $factory->make('bike','bike5', ['x' =>'270', 'y' => '300']);
echo
"<div id ='".htmlspecialchars($bike5->getBarcode())."'>";
echo
htmlspecialchars($bike5->getBarcode());
echo
"</div>";

$honor = $factory->make('mobile', 'Honor', ['x' => '20', 'y' => '100']);
echo
"<div id ='mobile'>";
echo
htmlspecialchars($honor->getName());
echo
"</div>";
$arr = $honor->findBike([$bike1, $bike2, $bike3, $bike4, $bike5]);
//var_dump($arr);

//init person obj
$person = new Person('Charles', $honor);


$place = new Place('SummerPalace');
$place->addRoute('Zhongguancun', ['x' => '160','y' => '151'], 30, 20);
$place->addRoute('Xierqi', ['x' => '260','y' =>'221'], 20, 25);
$place->addRoute('YuanmingPark', ['x' => '360','y' =>'327'], 23, 28);
$place->addRoute('SummerPalace', ['x' => '460','y' =>'443'], 15, 23);

$honor->charge(20);

$arr = $person->ride($bike3, $place);
// var_dump($arr);
$routes = $place->getRoute();
foreach (
$routes as $key => $route) {
    echo
"<div id = '".htmlspecialchars(strtolower($route[0]))."'>";
    echo
htmlspecialchars($route[0]);
    echo
"</div>";
}
$fee = $honor->request('fee', $arr['timeSpend'] * 60);
$honor->pay($fee);
echo
"First time balance is ".htmlspecialchars($honor->getBalance())."; ";

$honor->charge(20);
$placeAnother = new Place('Shougang Iron Factory');
$placeAnother->addRoute('Gongzhufen', ['x' => '207','y' => '210'], 40, 20);
$placeAnother->addRoute('Wukesong', ['x' => '406','y' =>'198'], 30, 25);
$placeAnother->addRoute('Babaoshan', ['x' => '600','y' =>'180'], 25, 27);
$placeAnother->addRoute('ShougangIronFactory', ['x' => '707','y' =>'230'], 22, 17);

$arrNew = $person->ride($bike3, $placeAnother);

$routes = $placeAnother->getRoute();
foreach (
$routes as $key => $route) {
    echo
"<div id = '".htmlspecialchars(strtolower($route[0]))."'>";
    echo
htmlspecialchars($route[0]);
    echo
"</div>";
}
$fee = $honor->request('fee', $arrNew['timeSpend'] * 60);
$honor->pay($fee);
echo
"Second time balance is ".htmlspecialchars($honor->getBalance())."; ";


$honor->charge(30);

$placeAnother = new Place('Yizhuang');
$placeAnother->addRoute('Qianmen', ['x' => '460','y' => '70'], 10, 20);
$placeAnother->addRoute('Caishikou', ['x' => '440','y' =>'150'], 10, 25);
$placeAnother->addRoute('TiantanPark', ['x' => '480','y' =>'257'], 25, 27);
$placeAnother->addRoute('Yizhuang', ['x' => '390','y' =>'530'], 30, 17);

$arrAnother = $person->ride($bike3, $placeAnother);
$fee = $honor->request('fee', $arrAnother['timeSpend'] * 60);

$routes = $placeAnother->getRoute();
foreach (
$routes as $key => $route) {
    echo
"<div id = '".htmlspecialchars(strtolower($route[0]))."'>";
    echo
htmlspecialchars($route[0]);
    echo
"</div>";
}
$honor->pay($fee);
echo
"Third time balance is ".htmlspecialchars($honor->getBalance())."<br>";
// var_dump($person->getRideHistory());
// var_dump($bike3->getRecordPosition());


?>


    </div>

</body>
</html>


Details

Readme Share bike is very poplar in many countries, a lot of people have the mobile, using the mobile to find the nearest bike, unlock the bike, travel to another place. also we ride the bike to destination place, then record route in array. When you run the index.php, you will find mobile, bike position also can see all the the passed places in the page.

  Files folder image Files  
File Role Description
Plain text file Bike.php Class Class source
Plain text file Cloud.php Class Class source
Plain text file Factory.php Class Class source
Accessible without login Plain text file index.php Example Example script
Plain text file Mobile.php Class Class source
Plain text file Person.php Class Class source
Plain text file Place.php Class Class source
Accessible without login Plain text file Readme Doc. Documentation
Plain text file ShareBikeTest.php Class Class source
Accessible without login Plain text file style.css Data Auxiliary data

 Version Control Unique User Downloads Download Rankings  
 100%
Total:111
This week:0
All time:9,596
This week:212Up