Code Monkey home page Code Monkey logo

simplecalendar's Introduction

Simple Calendar

Latest Stable Version License ci.yml

A very simple, easy to use PHP calendar rendering class.

Requirements

  • php: >=7.2
  • ext-calendar: *

Installing

Install the latest version with:

composer require 'donatj/simplecalendar'

Examples

<?php

require '../vendor/autoload.php';

echo '<link rel="stylesheet" href="../src/css/SimpleCalendar.css" />';

$calendar = new donatj\SimpleCalendar('June 2010');

echo $calendar->render();
<?php
require '../vendor/autoload.php';

echo '<link rel="stylesheet" href="../src/css/SimpleCalendar.css" />';

$calendar = new donatj\SimpleCalendar;

$calendar->setStartOfWeek('Sunday');
$calendar->addDailyHtml('Sample Event', 'today', 'tomorrow');

$calendar->setWeekDayNames([ 'Sun', 'Mon', 'Tu', 'W', 'Th', 'F', 'Sa' ]);
$calendar->setStartOfWeek('Monday');

echo $calendar->render();

Documentation

Class: \donatj\SimpleCalendar

Simple Calendar

Method: SimpleCalendar->__construct

function __construct([ $calendarDate = null [, $today = null]])
Parameters:
  • \DateTimeInterface | int | string | null $calendarDate
  • \DateTimeInterface | false | int | string | null $today

Method: SimpleCalendar->setDate

function setDate([ $date = null]) : void

Sets the date for the calendar.

Parameters:
  • \DateTimeInterface | int | string | null $date - DateTimeInterface or Date string parsed by strtotime for the calendar date. If null set to current timestamp.

Throws: \Exception


Method: SimpleCalendar->setCalendarClasses

function setCalendarClasses(array $classes) : void

Sets the class names used in the calendar

[  
   'calendar'     => 'SimpleCalendar',  
   'leading_day'  => 'SCprefix',  
   'trailing_day' => 'SCsuffix',  
   'today'        => 'today',  
   'event'        => 'event',  
   'events'       => 'events',  
]  
Parameters:
  • array<string,string> $classes - Map of element to class names used by the calendar.

Method: SimpleCalendar->setToday

function setToday([ $today = null]) : void

Sets "today"'s date. Defaults to today.

Parameters:
  • \DateTimeInterface | false | int | string | null $today - null will default to today, false will disable the rendering of Today.

Throws: \Exception


Method: SimpleCalendar->setWeekDayNames

function setWeekDayNames([ ?array $weekDayNames = null]) : void
Parameters:
  • string[] | null $weekDayNames

Method: SimpleCalendar->addDailyHtml

function addDailyHtml(string $html, $startDate [, $endDate = null]) : void

Add a daily event to the calendar

Parameters:
  • string $html - The raw HTML to place on the calendar for this event
  • \DateTimeInterface | int | string $startDate - Date string for when the event starts
  • \DateTimeInterface | int | string | null $endDate - Date string for when the event ends. Defaults to start date

Throws: \Exception


Method: SimpleCalendar->clearDailyHtml

function clearDailyHtml() : void

Clear all daily events for the calendar


Method: SimpleCalendar->setStartOfWeek

function setStartOfWeek($offset) : void

Sets the first day of the week

Parameters:
  • int | string $offset - Day the week starts on. ex: "Monday" or 0-6 where 0 is Sunday

Method: SimpleCalendar->show

function show([ bool $echo = true]) : string

Returns/Outputs the Calendar

DEPRECATED

Use render() method instead.

Parameters:
  • bool $echo - Whether to echo resulting calendar
Returns:
  • string - HTML of the Calendar

Method: SimpleCalendar->render

function render() : string

Returns the generated Calendar

simplecalendar's People

Contributors

bitdeli-chef avatar dependabot[bot] avatar donatj avatar inod avatar keesiemeijer avatar shrimp2t avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

simplecalendar's Issues

Multi-Day Events

I love this little simple calendar class and recently used it in a Timeclock application I built to show user's time clock entries in a Calendar format.

I have tweaked a few minor things but something I would like to do or if someone else can do it with more time that would be great too...

I would like to add the ability for an even to span multiple days just like in the image below

2013-09-21_09-33-55

UPDATE

After some testing, I now see that the class is capable of spanning multiple days for an event, I just need to figure out the best way to make the UI show that in the image

Wrong today's date.

I am displaying this month's calendar but 01-09-2016 is selected by default instead of today's date.
$calendar = new \donatj\SimpleCalendar('September '.$currentYear);
$calendars['month'] = $monthName;
$calendars['calendar'] = $calendar;
$calendars['calendar']->show();

No 2weekly option

Can you add 2weekly or explain how it's possible to generate events every 2 weeks.

Cheers.

vendor/autoload.php

There is no 'vendor' folder, so there is no 'autoload.php' file. There is no 'autoload.php' file located anywhere in this project.

Translating the names of the month

I wonder if there is a possibility to name the months in the same way as the days of the week, so if you scroll between the months, this is displayed in my case in Swedish...

like:

$calendar->setMonthNames(['januari', 'februari, 'mars', 'april', 'maj', 'juni', 'juli', 'august', 'september', 'oktober', 'november', 'december']);

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.