PHP Ride Locale API: API to keep track of vehicle ride sharing

Recommend this page to a friend!
  Info   View files Documentation   View files View files (5)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2020-02-09 (4 months ago) RSS 2.0 feedNot yet rated by the usersTotal: 86 All time: 9,505 This week: 291Up
Version License PHP version Categories
locale_api 1.0.0The PHP License5PHP 5, Databases, Files and Folders, G...
Description Author

This package provides an API to keep track of vehicle ride sharing.

It provides several classes that can perform several types of operations to access a PostgreSQL database, as well a CSV file access class.

The package also provides a class that can perform several types of operations to store information about vehicle rides. Currently it can:

- Retrieves the latitude and longitude of a location with a given identifier
- Retrieve given list of details of all rides stored in the database
- Retrieve details about all types of ride
- Retrieve the details of all rides travelled by a user
- Retrieve the details of all canceled rides
- Retrieve the details of all rides that were not canceled
- Retrieve the details of all rides by vehicle model identifier

Innovation Award
PHP Programming Innovation award nominee
February 2020
Number 13
Ride sharing has been an alternative for sharing cars and other vehicles that can be used to transport multiple people between different places.

This package implements a system that can be used to manage the activity of sharing rides with multiple vehicles between multiple people

It provides an API that can be used to develop mobile applications that can run on different mobile devices.

Manuel Lemos
  Performance   Level  
Name: Malik Naik is available for providing paid consulting. Contact Malik Naik .
Classes: 6 packages by
Country: India India
Age: 21
All time rank: 3857271 in India India
Week rank: 95 Up14 in India India Up
Innovation award
Innovation award
Nominee: 4x


Locale API

Locale API is an Application Programming Interface(API) which provides methods and classes to stores and retrieves the rides data from the Postgresql database and is written in PHP.

\Locale\Database class

This is a Singleton class and provides the methods or functions to store and retrieve data from postgresql. The functions provided by this class are: * getInstance() - Returns the instance of this class. * getConnection() - Returns the database connection * createTable() - Creates the table in Postgresql database by passing the schema of the table as an argument along with table name. * insertRows() - Inserts multiple rows into the table and it takes two parameters one is the table name and other is the array of row arrays. * insertRow() - Inserts single row into the table * defaultSchema() - Adds default schema key/value pairs to the schema array. * isConnectionEstablished() - Returns if the connection is successfully established. * closeConnection() - Closes the connection

\Locale\CSVHandler class

This class provides methods to read the .csv file and convert the data from the .csv file to array. The constructor of this class takes the file name of the .csv file to process. The functions provided by this class are: * isFileOpen() - Returns TRUE when the file pointer to the .csv file is set. * toArray() - Reads the .csv file and generates an array containing the .csv file data and it has two optional parameters `$num_rows` and `$omit_first_row`. The `$num_rows` argument limits the number of rows of .csv file to convert and `$omit_first_row` specifies whether to omit reading the first row as most .csv file contains the header as the first row.

\Locale\Rides class

This class provides methods necessary to fetch the required data from the database related to the rides. The constructor of this class takes the object of type `\Locale\Database` class. The functions provided by this class are: * getLatLong() - This function retrieves the latitude and longitude specified by the id. * getAllRides() - Returns all the rides from the table and if we want to retrive the data by columns/fields then pass an array as argument with the column/fields names. * getRidesByTravelType() - Returns the rows by travel type. * getRidesByUserId() - Return all the rides travelled by the user * getRidesCancelled() - Returns all the cancelled rides * getRidesNotCancelled() - Returns all rides other than cancelled rides * getRidesByVehicleModelId() - Returns all the rides by the vehicle_model_id

How to use this API?

To use the Locale API from other sources like web and mobile applications we need to generate the reponse as JSON format.

The following snippet retrieves all the rides from the table 'rides' with the columns/fields as id, user_id, travel_type_id, from_lat, and from_long and generates the response of the format JSON.


use Locale;

// Set content type to JSON
header('Content-Type: application/json');

$connection_string = '<CONNECTION_STRING_FOR_POSTGRESQL>';
$fields = array('id', 'user_id', 'travel_type_id', 'from_lat', 'from_long');

$database = Database::getInstance();
$db_connection = $database->getConnection($connection_string);

$rides = new Rides($database, 'rides');

$result = $rides->getAllRides($fields);

echo json_encode($result);

How to convert .csv file to array?

The CSVHandler class from the Locale namespace provides the method to convert the .csv file to array.

The following snippet shows how to convert .csv file to array:


use Locale;

$csv = new CSVHandler('<CSV_FILE_NAME>');

// $result stores the .csv file in the form of an array
$result = $csv->toArray();

NOTE: For more information on the parameters of the functions refer to the doc block at the top of the function in the class.

  Files folder image Files  
File Role Description
Files folder imageLocale (3 files)
Accessible without login Plain text file autoload.php Aux. Auxiliary script
Accessible without login Plain text file Doc. Read me

  Files folder image Files  /  Locale  
File Role Description
  Plain text file CSVHandler.php Class Class source
  Plain text file Database.php Class Class source
  Plain text file Rides.php Class Class source

 Version Control Unique User Downloads Download Rankings  
This week:0
All time:9,505
This week:291Up

For more information send a message to info at phpclasses dot org.