PHP
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
src
tests
.gitattributes
.gitignore
.travis.yml
CHANGELOG.md
CONTRIBUTING.md
LICENSE
README.md
composer.json
phpunit.xml

README.md

MyCal

Author Docs Latest Version Software License Build Status

Introduction

MyCal is a PSR-2 compliant package used for generating calendars in an object orientated way. Built in are helpers for generating a HTML table for the requested dates.

This package is still a work in progress.

Requirements

Composer

MyCal requires the following:

  • "php": ">=5.6.0"
  • "cartalyst/collections": "1.1.*",
  • "snscripts/result": "1.0.*"

And the following if you wish to run in dev mode and run tests.

  • "phpunit/phpunit": "~5.7"
  • "squizlabs/php_codesniffer": "~2.0"

MyCal suggests the following for database integrations.

  • "illuminate/database": "Use Eloquent as the method for saving your calendars / events"

Installation

Composer

Simplest installation is via composer.

composer require snscripts/mycal 0.*

or adding to your projects composer.json file.

{
    "require": {
        "snscripts/mycal": "0.*"
    }
}

Setup

To initiate the package setup the Calendar Factory along with the Date Factory and the calendar integration you wish to use.

Currently only Laravel Eloquent integration is available, you can setup the Calendar Factory like so:

$CalendarFactory = new \Snscripts\MyCal\CalendarFactory(
    new \Snscripts\MyCal\Integrations\Null\Calendar,
    new \Snscripts\MyCal\DateFactory
);

Usage

Basics

Once setup as above, load up a new calendar by using the Calendar Factory load method

$Calendar = $CalendarFactory->load();

This creates a new Calendar object with default options. You can then generate a collection of dates by calling

$dates = $Calendar->dates($startDate, $endDate)->get();

Both start and end date should be in YYYY-MM-DD format. If you wish to generate a html table for the dates automatically you can pass the date collection from the above example into the display method along with a formatter object.

echo $Calendar->display(
    new \Snscripts\MyCal\Formatters\BootstrapFormatter,
    $dates
);

To load any saved events simply call withEvents() before the get.

$dates = $Calendar
    ->dates($startDate, $endDate)
    ->withEvents()
    ->get();

Date collection

Each item in the collection of dates is an instance of a MyCal Date object, these objects come with a few helper methods.

$dates = $Calendar->dates($startDate, $endDate)->get();
foreach ($dates as $Date) {

    var_dump($Date->isWeekend()); // true if date is a saturday or sunday.
    var_dump($Date->isWeekStart()); // true if date matches the week start option defined on the calendar

    echo $Date->display($format);
}

Events

Below are quick code examples of how to load a blank new Event object, populate, save and finally display the start / end times.

$Event = $CalendarFactory->newEvent();

$Event->name = 'My Awesome Event';
$Event->startsOn('2017-04-30')
    ->startsAt('12:15')
    ->endsOn('2017-04-30')
    ->endsAt('21:00');

$Event->save();

$Event->displayStart('jS M Y H:i');
$Event->displayEnd('jS M Y H:i');

Full Documentation

Full documentation for MyCal can be found within the gh-pages branch of the repo https://github.com/mikebarlow/MyCal/ or alternatively at http://mikebarlow.co.uk/MyCal.

Changelog

You can view the changelog HERE

Contributing

Please see CONTRIBUTING for details.

License

The MIT License (MIT). Please see License File for more information.