PHPackages                             roomify/bat - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. roomify/bat

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

roomify/bat
===========

A booking and availability management library

1.4.0(5y ago)156146.0k—2.9%33[28 issues](https://github.com/Roomify/bat/issues)[2 PRs](https://github.com/Roomify/bat/pulls)MITPHPPHP &gt;=5.4.0CI failing

Since Jan 17Pushed 4y ago24 watchersCompare

[ Source](https://github.com/Roomify/bat)[ Packagist](https://packagist.org/packages/roomify/bat)[ Docs](https://github.com/roomify/bat)[ RSS](/packages/roomify-bat/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (4)Versions (15)Used By (0)

BAT
===

[](#bat)

[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/47ba308517629a8eeac8a3fe7cfb5a68c5b7b74b41332a280b79d4f55a614311/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f526f6f6d6966792f6261742f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/Roomify/bat)[![Quality Score](https://camo.githubusercontent.com/0e59dd8f28c1dd6a2ad3d762c126d055c0753ec145c5be3536d22d13d93276eb/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f726f6f6d6966792f6261742e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/roomify/bat)[![Total Downloads](https://camo.githubusercontent.com/ba6b3653928e6d42880619733cbcc212adb34e0a93afe3d7c62ad513db61bec5/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f726f6f6d6966792f6261742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/roomify/bat)

BAT stands for Booking and Availability Management Tools.

It is a set of tools created by the [Roomify.us](https://roomify.us) team to provide a foundation through which a wide range of availability management, reservation and booking use cases can be addressed. BAT will work with a variety of CMSs and PHP Frameworks, of which the first is Drupal (check out our [Drupal module](https://github.com/roomify/bat_drupal)).

BAT builds on our experience with [Rooms](http://drupal.org/project/rooms), which handles the problem of bookings specifically for the accommodation for rental use case(vacation rentals, hotels, B&amp;B, etc). With BAT we took everything we learned and build a system that will let you build an application like Rooms - or something for table booking at a restaurant, or conference room bookings, or sharing power tools with friends, or booking activities, or... well you get the idea.

BAT on its own is a **booking and availability management framework** - much in the same way Drupal is a content management framework or Drupal Commerce is an e-commerce framework. Our aim is to build specific solutions on top of BAT to tackle specific application domains.

Basic Concepts
--------------

[](#basic-concepts)

### Units

[](#units)

Units are the things that can be booked. For BAT they simply have an id, a default state (for a given event type - we will get to this later) and can define Constraints. Constraints are like extra rules about whether a specific unit is available (we get back to these as well).

For each application units will represent something concrete like hotel rooms, cars, tables, etc.

### Events

[](#events)

Events define what *value* a unit has for a given time period. There can be multiple types of events and the value of the event together with the type of event will provide some meaning within an application.

For example, one set of events can denote "Availability", while another "Price". The value of events of type Availability will indicate whether a unit is available (1), unavailable (0) or booked (2) - i.e they indicate the state of a unit. The value of events of type Price could denote instead the cost per night to change the state of a unit for a given time period. So to make Unit 1 change state from available to booked for a given set of days you can retrieve all pricing events for that set of days and multiple the number of nights by the value associated with that event.

### Calendar

[](#calendar)

A Calendar allows us to retrieve Events of a given type for a given set of Units as well as search over Units to see the ones that match specific event values.

You can, for example, use a Calendar to find all Units that from Jan 1 2016 to Jan 15 2016 have Availability Events that only hold value of 2 - which given our definition above - would indicate booked units.

#### CalendarResponse

[](#calendarresponse)

A search using the Calendar will return a CalendarResponse - this will indicate for each unit that was involved in the search whether it is part of the *included* units or the *excluded* units together with the reason it ended up in one or the other set. This allows our applications to reason about why something didn't make the cut and display it to the end user.

### Constraints

[](#constraints)

When a Calendar does a search it does it for a given time range and a valid set of values. We can identify further Constrainers either at the global level or at the Unit level. For example a specific Unit may indicate that it will only make itself available if the range search starts on a Monday, or it is of at least 7 days, etc.

The Calendar Response will hold information about which Constraint moved a Unit from the included set to the excluded set.

### Valuator

[](#valuator)

A Valuator performs an operation on event values to determine the value of a Unit for a given period given a specific valuation strategy. The simplest case for hotels would be to sum up the cost per night. Our applications can define multiple valuators and refer to different EventTypes to cater for a range of valuation strategies.

### Store

[](#store)

Store stores the value of a unit for a given moment in time. The Store goes down to minute granularity which means our Units can have a different value for each minute in time. The Store data structure is designed to quickly allows us to determine the value of a unit for a given time range and quickly change it.

Currently we support a SQLite store (used in our tests) and a DrupalStore. Additional Store support is on its way.

Install
-------

[](#install)

Via Composer

```
$ composer require Roomify/Bat
```

Usage
-----

[](#usage)

Create a unit with ID 1, default value 1 and a minimum length of event constraint.

```
$constraint = new MinMaxDaysConstraint([], 5)

$unit = new Unit(1,1, array($constraint));
```

Create a Store for events of type availability and pricing, create an event for Unit 1 and save it

```
$state_store = new SqlLiteDBStore($this->pdo, 'availability_event', SqlDBStore::BAT_STATE);

$start_date = new \DateTime('2016-01-01 12:12');
$end_date = new \DateTime('2016-01-04 07:07');

$state_event = new Event($start_date, $end_date, $unit, 0); \\ Event value is 0 (i.e. unavailable)

$state_calendar = new Calendar(array($unit), $state_store);
$state_calendar->addEvents(array($state_event), Event::BAT_HOURLY); \\ BAT_HOURLY denotes granularity
```

We can then search for matching Units. In this case we are searching for all units from date $s1 to date $s2 that have events only of value 1 (Available). Given that our unit in that period also has a value of 0 our calendar will not find any matching units.

```
$s1 = new \DateTime('2016-01-01 00:00');
$s2 = new \DateTime('2016-01-31 12:00');

$response = $state_calendar->getMatchingUnits($s1, $s2, array(1), array());
```

Change log
----------

[](#change-log)

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

Testing
-------

[](#testing)

```
$ composer test
```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Roomify](https://roomify.us)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

42

—

FairBetter than 90% of packages

Maintenance16

Infrequent updates — may be unmaintained

Popularity49

Moderate usage in the ecosystem

Community23

Small or concentrated contributor base

Maturity66

Established project with proven stability

 Bus Factor1

Top contributor holds 75.8% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~238 days

Recently: every ~405 days

Total

8

Last Release

2092d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/0518d99e4cd8b3a805b37591d12c2123e9f87ca68101ecea8c3e1c6cddb7c71f?d=identicon)[istos](/maintainers/istos)

---

Top Contributors

[![istos](https://avatars.githubusercontent.com/u/80763?v=4)](https://github.com/istos "istos (75 commits)")[![acrollet](https://avatars.githubusercontent.com/u/101649?v=4)](https://github.com/acrollet "acrollet (15 commits)")[![salvoscala](https://avatars.githubusercontent.com/u/6781952?v=4)](https://github.com/salvoscala "salvoscala (6 commits)")[![anhskohbo](https://avatars.githubusercontent.com/u/1529454?v=4)](https://github.com/anhskohbo "anhskohbo (1 commits)")[![marcovega](https://avatars.githubusercontent.com/u/1530214?v=4)](https://github.com/marcovega "marcovega (1 commits)")[![TwoD](https://avatars.githubusercontent.com/u/451168?v=4)](https://github.com/TwoD "TwoD (1 commits)")

---

Tags

bookingreservationsroomifybatbooking engineavailability managementsharing economy

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/roomify-bat/health.svg)

```
[![Health](https://phpackages.com/badges/roomify-bat/health.svg)](https://phpackages.com/packages/roomify-bat)
```

###  Alternatives

[laraveljutsu/zap

A flexible, performant, and developer-friendly schedule management system for Laravel

1.4k69.1k](/packages/laraveljutsu-zap)[softnweb/laravel-coming-soon

Simple Comming Soon page

201.2k](/packages/softnweb-laravel-coming-soon)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
