infyomlabs / laravel-calendar-events Goto Github PK
View Code? Open in Web Editor NEWRecurring Calendar Events for Laravel.
Home Page: https://infyom.com/open-source/laravel-calendar-events/docs
License: MIT License
Recurring Calendar Events for Laravel.
Home Page: https://infyom.com/open-source/laravel-calendar-events/docs
License: MIT License
php8.0 support?
The example in readme.md
in the code
page of your package is not working.
In the page of your package you have
use InfyOm\LaravelCalendarEvents\CalendarEvent;
use InfyOm\LaravelCalendarEvents\CalendarEventRecurrencePattern;
$event = new CalendarEvent([
[
'id' => 1,
'title' => 'Daily Repeat End on 30 Jan',
'description' => 'Daily Repeat End on 30 Jan',
'start_date' => '2021-01-10',
'end_date' => '2021-01-20', // nullable
'start_time' => '10:00:00',
'end_time' => '12:00:00',
'is_full_day' => false,
'is_recurring' => true,
'location' => 'Surat, India', // extra field. It will be automatically added to meta
'meta' => [
'ticket_required' => true
]
]
]);
$event->recurring_pattern = new CalendarEventRecurrencePattern([
'recurring_type' => RecurringFrequencyType::RECURRING_TYPE_DAILY,
'max_occurrences' => 10, // Maximum 10 Occurrences
'repeat_interval' => 1, // Repeat Daily
'repeat_by_days' => ["MO", "WE", "SU"], // only repeat on Monday, Wednesday and Sunday
'repeat_by_months' => [],
]);
// Retrieve next 5 events. Returns CalendarEvent array.
$event->getNextEvents(5);
// Retrieve all events between 5th Jan to 15th Jan. Returns CalendarEvent array.
$event->getEventsBetween('2021-01-05', '2021-01-15');
// Retrieve next 2 Occurrences. Returns \Recurr\Recurrence array
$event->getNextOccurrences(2);
// If you Laravel Eloquent model matches the field names with above field name
$event = new CalendarEvent($calendarModle);
The line $event->getEventsBetween('2021-01-05', '2021-01-15');
you would expect to get 4 events.
2021-01-06 // WEDNESDAY
2021-01-10 // SUNDAY
2021-01-11 // MONDAY
2021-01-13 // WEDNESDAY
but you get an empty array.
I have used php artisan tinker
from Laravel
:
www@761a074101a4:/var/www$ php artisan tinker
Psy Shell v0.10.8 (PHP 7.4.16 — cli) by Justin Hileman
>>> use InfyOm\LaravelCalendarEvents\CalendarEvent;
>>> use InfyOm\LaravelCalendarEvents\CalendarEventRecurrencePattern;
>>> $event = new CalendarEvent([
... [
... 'id' => 1,
... 'title' => 'Daily Repeat End on 30 Jan',
... 'description' => 'Daily Repeat End on 30 Jan',
... 'start_date' => '2021-01-10',
... 'end_date' => '2021-01-20', // nullable
... 'start_time' => '10:00:00',
... 'end_time' => '12:00:00',
... 'is_full_day' => false,
... 'is_recurring' => true,
... 'location' => 'Surat, India', // extra field. It will be automatically added to meta
... 'meta' => [
... 'ticket_required' => true
... ]
... ]
... ]);
=> InfyOm\LaravelCalendarEvents\CalendarEvent {#4639
+id: null,
+title: null,
+description: null,
+start_date: null,
+end_date: null,
+start_time: null,
+end_time: null,
+is_full_day: null,
+is_recurring: null,
+meta: [
[
"id" => 1,
"title" => "Daily Repeat End on 30 Jan",
"description" => "Daily Repeat End on 30 Jan",
"start_date" => "2021-01-10",
"end_date" => "2021-01-20",
"start_time" => "10:00:00",
"end_time" => "12:00:00",
"is_full_day" => false,
"is_recurring" => true,
"location" => "Surat, India",
"meta" => [
"ticket_required" => true,
],
],
],
+excluded_dates: null,
+recurring_pattern: null,
}
>>> $event->recurring_pattern = new CalendarEventRecurrencePattern([
... 'recurring_type' => "DAILY",
... 'max_occurrences' => 10, // Maximum 10 Occurrences
... 'repeat_interval' => 1, // Repeat Daily
... 'repeat_by_days' => ["MO", "WE", "SU"], // only repeat on Monday, Wednesday and Sunday
... 'repeat_by_months' => [],
... ]);
=> InfyOm\LaravelCalendarEvents\CalendarEventRecurrencePattern {#4655
+event_id: null,
+recurring_type: "DAILY",
+max_occurrences: 10,
+repeat_interval: 1,
+repeat_by_days: [
"MO",
"WE",
"SU",
],
+repeat_by_months: [],
}
>>> $event->getEventsBetween('2021-01-05', '2021-01-15');
=> []
On line 277
of src/CalendarEvent.php
you have this line:
if (empty($this->end_date)) {
$this->end_date = Carbon::parse($endDate);
} else {
if ($this->end_date > $endDate) {
$this->end_date = Carbon::parse($endDate);
}
}
Then on line 144
of the same file you have this line:
private function applyEndDate(Rule $rule): Rule
{
if (!empty($this->end_date)) {
$endDate = Carbon::parse($this->end_date)->setTimeFromTimeString($this->end_time);
$rule->setUntil($endDate);
}
return $rule;
}
which is called from line 255
. On this method you call $rule->setUntil
method which in turn will do:
public function setUntil(\DateTimeInterface $until)
{
$this->until = $until;
$this->count = null;
return $this;
}
completely overiding the count
. Now, instead of getting a maximum of 10 events (remember, on the example we have max_occurrences = 10
) we will get until the date $until
, which in this case is $endDate
.
To fix this problem we just need to add a check to verify that if we don't have a max_occurrences
set, then we can set the end date
if (empty($this->recurring_pattern->max_occurrences)) {
$this->applyEndDate($rule);
}
how can i resolve this error and problem:
ArgumentCountError
Too few arguments to function InfyOm\LaravelCalendarEvents\CalendarEvent::__construct(),
0 passed in
/Users/XXX/.../vendor/infyomlabs/laravel-calendar-events/src/LaravelCalendarEventsServiceProvider.php on line 57 and exactly 1 expected
at vendor/infyomlabs/laravel-calendar-events/src/CalendarEvent.php:49
45▕
46▕ /** @var CalendarEventRecurrencePattern */
47▕ public $recurring_pattern;
48▕
➜ 49▕ public function __construct($attributes)
50▕ {
51▕ parent::__construct($attributes);
52▕
53▕ if (!empty($this->start_date)) {
+28 vendor frames
29 artisan:37
Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput),
Object(Symfony\Component\Console\Output\ConsoleOutput))
Script @php artisan ide-helper:generate handling the post-update-cmd event returned with error code 1
Hi,
I was looking to use your excellent package but I don't understand how you can implement a search with multiple events.
I explain: you have provided this method:
$event->getEventsBetween('2021-01-05', '2021-01-15');
With this I can retrieve all the recurrences between two dates of that particular event.
But what if I have multiple events with multiple recurrences each and I want to retrieve all the events (or recurrences of those events) beetwen two dates?
Something like this:
$collectionOfEvents->getEventsBetween('2021-01-05', '2021-01-15');
I also would like to ask you if you could provide an example with laravel and an interaction with a db.
Thank you in advance :)
I found that if I create an event with:
[
'recurring_type' => RecurringFrequencyType::RECURRING_TYPE_DAILY,
'repeat_interval' => 15,
'repeat_by_days' => [],
'repeat_by_months' => [],
'max_occurrences' => null,
]
When i call the function getEventsBetween the dates of the recurrences of the event are wrong.
From what I understood the function $this->getNextEvents($numberOfEvents); generate the recurrences starting from the original event date.
The problem is that in the function getEventsBetween, before calling getNextEvents() the starting date is changed with the starting date of the period that the user need:
if ($startDate > $this->start_date) {
$this->start_date = Carbon::parse($startDate);
}
Then when calling getNextEvents() all the events date are wrong.
If I delete this line:
if ($startDate > $this->start_date) {
$this->start_date = Carbon::parse($startDate);
}
everything works fine, but then I have performances issues.
Thanks in advance
Is there a way to define an event reoccurring biweekly? That means an event that is every other week, 14 days apart.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.