{"id":16676312,"url":"https://github.com/alrik11es/calendar","last_synced_at":"2025-04-09T20:40:26.336Z","repository":{"id":19240209,"uuid":"22475249","full_name":"alrik11es/calendar","owner":"alrik11es","description":"Calendar is a PHP calendar generator but in array, object or JSON format.","archived":false,"fork":false,"pushed_at":"2017-05-19T09:29:28.000Z","size":89,"stargazers_count":13,"open_issues_count":1,"forks_count":0,"subscribers_count":3,"default_branch":"1.0","last_synced_at":"2024-05-21T05:14:55.809Z","etag":null,"topics":["calendar","composer","php","php-calendar-generator","twig","vuejs"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/alrik11es.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-07-31T15:54:57.000Z","updated_at":"2024-02-04T16:06:02.000Z","dependencies_parsed_at":"2022-08-01T03:47:54.467Z","dependency_job_id":null,"html_url":"https://github.com/alrik11es/calendar","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alrik11es%2Fcalendar","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alrik11es%2Fcalendar/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alrik11es%2Fcalendar/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alrik11es%2Fcalendar/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alrik11es","download_url":"https://codeload.github.com/alrik11es/calendar/tar.gz/refs/heads/1.0","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248109606,"owners_count":21049341,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["calendar","composer","php","php-calendar-generator","twig","vuejs"],"created_at":"2024-10-12T13:10:03.155Z","updated_at":"2025-04-09T20:40:26.312Z","avatar_url":"https://github.com/alrik11es.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"Calendar [![Build Status](https://travis-ci.org/alrik11es/calendar.svg?branch=master)](https://travis-ci.org/alrik11es/calendar)\n======================\n\n[![Latest Stable Version](https://poser.pugx.org/alrik11es/calendar/v/stable.svg)](https://packagist.org/packages/alrik11es/calendar) [![Total Downloads](https://poser.pugx.org/alrik11es/calendar/downloads.svg)](https://packagist.org/packages/alrik11es/calendar) [![Latest Unstable Version](https://poser.pugx.org/alrik11es/calendar/v/unstable.svg)](https://packagist.org/packages/alrik11es/calendar) [![License](https://poser.pugx.org/alrik11es/calendar/license.svg)](https://packagist.org/packages/alrik11es/calendar)\n\nCalendar is a PHP calendar structure generator in array, object or JSON format.\n\n* [Installation](#installation)\n    * [Requirements](#requirements)\n    * [With composer](#with-composer)\n* [How it works](#how-it-works)\n\n## Motivation\n\nDo you remember those long... long... hours trying to create a rendered calendar? Think about this, the main problem is that you have to generate the structure to do the rendering in your template engine, no matter what it is. So the thing here is I don't wanna give you a fully rendered calendar just the structure you need to do the render. How do you do the render... it's all on you.\n\nTake a look to this example render:\n\n![Calendar example](img/calendar.png \"Calendar example\")\n\n## Installation\n\n### Requirements\n\n- Any flavour of PHP 5.6+ should do\n- [optional] PHPUnit to execute the test suite\n\n### With Composer\n\nThe easiest way to install the calendar is via [composer](http://getcomposer.org/). Create the following `composer.json` file and run the `php composer.phar install` command to install it.\n\n```json\n{\n    \"require\": {\n        \"alrik11es/calendar\": \"0.1.*\"\n    }\n}\n```\n\n### No composer\n\nGit clone this repo where you want and include/require all the src folder into your project.\n\n## How it works\nLets get into business. Set up a calendar from today to 6 months into the future:\n\n```php\n$cal = new \\SSC\\Calendar();\n$structure = $cal-\u003egetCalendar();\n\nprint_r($structure);\n```\n\nThe output then is like the next one:\n\n```\nArray\n(\n[2014] =\u003e Array\n    (\n    [type] =\u003e year\n    [value] =\u003e 2014\n    [data] =\u003e\n    [elements] =\u003e Array\n        (\n        [3] =\u003e Array\n            (\n            [type] =\u003e quarter\n            [value] =\u003e 3\n            [data] =\u003e\n            [elements] =\u003e Array\n                (\n                [8] =\u003e Array\n                    (\n                    [type] =\u003e month\n                    [value] =\u003e 8\n                    [data] =\u003e\n                    [elements] =\u003e Array\n                        (\n                        [31] =\u003e Array\n                            (\n                            [type] =\u003e week\n                            [value] =\u003e 31\n                            [data] =\u003e\n                            [elements] =\u003e Array\n                                (\n                                [1] =\u003e Array\n                                    (\n                                    [type] =\u003e day\n                                    [value] =\u003e 1\n                                    [data] =\u003e \n                                    [weekday] =\u003e 5\n                                    )\n```\n\nThen you just have to take it and render in your Twig or whatever... (Next one is the spanish way, but you can change to whatever you want)\n\n```php\n\u003c?php foreach($structure as $year): ?\u003e\n    \u003c?php foreach($year['elements'] as $quarter): ?\u003e\n        \u003c?php foreach($quarter['elements'] as $month): ?\u003e\n            \u003cdiv\u003e\n                \u003c?php echo $year['value']; ?\u003e - \u003c?php echo $month['value']; ?\u003e\n                \u003ctable\u003e\n                    \u003ctr\u003e\n                        \u003cth\u003eMon\u003c/th\u003e\n                        \u003cth\u003eTue\u003c/th\u003e\n                        \u003cth\u003eWed\u003c/th\u003e\n                        \u003cth\u003eThu\u003c/th\u003e\n                        \u003cth\u003eFra\u003c/th\u003e\n                        \u003cth\u003eSun\u003c/th\u003e\n                        \u003cth\u003eSat\u003c/th\u003e\n                    \u003c/tr\u003e\n                    \u003c?php foreach($month['elements'] as $week): ?\u003e\n                        \u003ctr\u003e\n                            \u003c?php foreach(array(1,2,3,4,5,6,0) as $weekday): ?\u003e\n                                \u003ctd\u003e\n                                \u003c?php foreach($week['elements'] as $day): ?\u003e\n                                    \u003c?php if($day['weekday'] == $weekday): ?\u003e\n                                        \u003c?php echo $day['value'];?\u003e\n                                    \u003c?php endif; ?\u003e\n                                \u003c?php endforeach; ?\u003e\n                                \u003c/td\u003e\n                            \u003c?php endforeach; ?\u003e\n                        \u003c/tr\u003e\n                    \u003c?php endforeach; ?\u003e\n                \u003c/table\u003e\n            \u003c/div\u003e\n        \u003c?php endforeach; ?\u003e\n    \u003c?php endforeach; ?\u003e\n\u003c?php endforeach; ?\u003e\n```\n\n# Bam! Calendar!\n\nOh BTW I can give you a Twig example Just for the record :P\n\n```php\n$cal = new \\SSC\\Calendar();\n$cal-\u003egetConfig()-\u003esetInterval(new \\DateInterval('P12M'));\n$cal-\u003eday_callback = function($date){\n    $day = new \\stdClass();\n    $day-\u003ehas_passed = $date-\u003egetTimestamp()\u003ctime();\n    return $day;\n};\n\n// Spanish months (There is tons of ways of doing this but...)\n$context['months_es'] = array(\n    1=\u003e'Enero', 'Febrero', 'Marzo','Abril','Mayo','Junio','Julio','Agosto','Septiembre','Octubre','Noviembre','Diciembre'\n);\n// The week days order. In spanish calendar this is different than in english.\n$context['week_days'] = array(1,2,3,4,5,6,0);\n// The calendar structure...\n$context['cal'] = $cal-\u003egetCalendarStructure();\n```\n\nYeah, the Twig file...\n\n```twig\n{% for year in cal %}\n    {# You could add here the years #}\n    {% for quarter in year.elements %}\n        {% for month in quarter.elements %}\n        \u003ctable class=\"month\"\u003e\n            \u003ctbody\u003e\n            \u003ctr\u003e\n                \u003cth colspan=\"9\" class=\"month-title\"\u003e{{ year.value }} - {{ months_es[month.value] }}\u003c/th\u003e\n            \u003c/tr\u003e\n            \u003ctr\u003e\n                \u003cth\u003eL\u003c/th\u003e\n                \u003cth\u003eM\u003c/th\u003e\n                \u003cth\u003eX\u003c/th\u003e\n                \u003cth\u003eJ\u003c/th\u003e\n                \u003cth\u003eV\u003c/th\u003e\n                \u003cth class=\"thweekend\"\u003eS\u003c/th\u003e\n                \u003cth class=\"thweekend\"\u003eD\u003c/th\u003e\n            \u003c/tr\u003e\n            \u003c/tbody\u003e\n\n            {% for week in month.elements %}\n                \u003ctr\u003e\n                    {# You could add here the week number #}\n                    {% for week_day in week_days%}\n                        \u003ctd class=\"day-container\"\u003e\n                            {% for day in week.elements %}\n                                {% if day.weekday == week_day %}\n                                    \u003cdiv class=\"day {% if day.data.has_passed %}passed_day{% endif %} {% if week_day == 6 or week_day == 0 %}weekend{% endif %}\"\u003e\n                                        {{ day.value }}\n                                    \u003c/div\u003e\n                                {% endif %}\n                            {% endfor %}\n                        \u003c/td\u003e\n                    {% endfor %}\n                \u003c/tr\u003e\n            {% endfor %}\n        \u003c/table\u003e\n        {% endfor %}\n    {% endfor %}\n{% endfor %}\n```\n# Vue.js\n\nWith the boom of this kind of libraries just like angular or react. I give you an example of how a render should look like. Obviously you will need to make the API part. But at least this is a good starting point.\n\n```html\n\u003ctemplate\u003e\n\n    \u003cdiv\u003e\n        \u003cdiv v-for=\"year in calendar\"\u003e\n            \u003c!--\u003cdiv\u003e{{year.value}}\u003c/div\u003e--\u003e\n            \u003cdiv v-for=\"quarter in year.elements\"\u003e\n                \u003cdiv v-for=\"month in quarter.elements\" class=\"month\"\u003e\n                    {{ year.value }} - {{ month.value }}\n                    \u003ctable\u003e\n                        \u003ctr\u003e\n                            \u003cth\u003eMon\u003c/th\u003e\n                            \u003cth\u003eTue\u003c/th\u003e\n                            \u003cth\u003eWed\u003c/th\u003e\n                            \u003cth\u003eThu\u003c/th\u003e\n                            \u003cth\u003eFra\u003c/th\u003e\n                            \u003cth\u003eSun\u003c/th\u003e\n                            \u003cth\u003eSat\u003c/th\u003e\n                        \u003c/tr\u003e\n                        \u003ctr v-for=\"week in month.elements\"\u003e\n                            \u003ctd v-for=\"weekday in [1,2,3,4,5,6,0]\"\u003e\n                                \u003cdiv v-for=\"day in week.elements\"\u003e\n                                    \u003cspan v-if=\"day.weekday == weekday\"\u003e\n                                        {{ day.value }}\n                                    \u003c/span\u003e\n                                \u003c/div\u003e\n                            \u003c/td\u003e\n                        \u003c/tr\u003e\n                    \u003c/table\u003e\n                \u003c/div\u003e\n            \u003c/div\u003e\n        \u003c/div\u003e\n    \u003c/div\u003e\n\n\u003c/template\u003e\n\n\u003cscript\u003e\n    export default {\n        data() {\n            return {\n                calendar: {},\n            }\n        },\n        methods: {\n        },\n        mounted() {\n            axios.get('/api/calendar').then(response =\u003e {\n                this.calendar = response.data;\n                console.log(this.calendar);\n            }).catch(e =\u003e {\n            });\n        }\n    }\n\u003c/script\u003e\n\n\n\u003cstyle scoped lang=\"sass\"\u003e\n    .month{\n        float: left;\n        margin: 10px;\n    }\n\u003c/style\u003e\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falrik11es%2Fcalendar","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falrik11es%2Fcalendar","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falrik11es%2Fcalendar/lists"}