Coder Social home page Coder Social logo

infyomlabs / laravel-calendar-events Goto Github PK

View Code? Open in Web Editor NEW
91.0 91.0 21.0 32 KB

Recurring Calendar Events for Laravel.

Home Page: https://infyom.com/open-source/laravel-calendar-events/docs

License: MIT License

PHP 100.00%
calendar events hacktoberfest laravel recurring

laravel-calendar-events's Introduction

InfyOm

InfyTracker Site

Support Us

We have created 14+ Laravel packages and invested a lot of resources into creating these all packages and maintaining them.

You can support us by either sponsoring us or buying one of our paid products. Or help us by spreading the word about us on social platforms via tweets and posts.

Buy our Paid Products

InfyProjects

You can also check out our other paid products on CodeCanyon.

Sponsors

Become a sponsor and get your logo on our README on Github with a link to your site.

Backers

Become a backer and get your image on our README on Github with a link to your site.

Follow Us

Made with InfyOm Generator

Also, Do not forget to add your website to Made with InfyOm Generator List list.

Security

If you discover any security-related issues, create an issue using the issue tracker.

Credits

License

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

laravel-calendar-events's People

Contributors

ankitinfyom avatar iliabaan avatar mitulgolakiya avatar mtvbrianking avatar schmeits avatar stephenjude avatar vishalinfyom 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

laravel-calendar-events's Issues

Biweekly reoccurrence?

Is there a way to define an event reoccurring biweekly? That means an event that is every other week, 14 days apart.

[Bug] Recurrences dates are not right

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

[Bug]: ArgumentCountError

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

Work with multiple events

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 :)

[Bug]: Example in `readme.md` is not working as expected

Problem

The example in readme.md in the code page of your package is not working.

Explanation

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.

Enviroment

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');
=> []

The problem

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.

The fix

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);
}

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.