Giter Site home page Giter Site logo

benhall14 / php-calendar Goto Github PK

View Code? Open in Web Editor NEW
54.0 10.0 22.0 43 KB

A simple PHP class to generate calendars. Easy to populate, the calendar shows events by passing in an array.

Home Page: https://conobe.co.uk/projects/php-calendar/

License: MIT License

CSS 8.50% PHP 91.50%
php calendar calendars

php-calendar's People

Contributors

benhall14 avatar nazaralwi avatar pascalchevrel avatar rickyosser 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

php-calendar's Issues

error draw calendar

Hi,

i'm trying to draw simple calendar with this code :
<?php $calendar = new Calendar(); echo $calendar->draw(date('d-m-Y')); ?>
but i've that error :
Fatal error: Uncaught Error: Call to a member function modify() on boolean in C:\xampp3\htdocs\zimbra_admin\vendor\benhall14\php-calendar\src\phpCalendar\Calendar.php:138 Stack trace: #0 C:\xampp3\htdocs\zimbra_admin\contatore.php(20): benhall14\phpCalendar\Calendar->draw(false) #1 {main} thrown in C:\xampp3\htdocs\zimbra_admin\vendor\benhall14\php-calendar\src\phpCalendar\Calendar.php on line 138

how can i fix?

Event Filtering Issue Based on Time Comparison, Resulting in Incorrect Exclusions"

When i add events that are only like 2 hours long e.g.

start 2023-12-24 14:00
end 2023-12-24 16:00

They are not shown when i use the script after 16:00

The issue lies in the comparison of timestamps within the findEvents function. The comparison of timestamps for events uses both date and time, causing events that occur on the same day but at different times to be improperly filtered out.

To rectify this, I modified the function to focus solely on the date part of the timestamps for comparison, disregarding the time component. This was achieved by extracting and comparing only the dates (in the format 'Y-m-d').

Here's the problem demonstrated:

`
private function findEvents(DateTime $date)
{
$found_events = array();

if (isset($this->events)) {
    foreach ($this->events as $event) {
        // Comparison that considers both date and time
        if ($date->getTimestamp() >= $event->start->getTimestamp() && $date->getTimestamp() <= $event->end->getTimestamp()) {
            $found_events[] = $event;
        }
    }
}

return $found_events ?: false;

}

`

and here is the corrected version

`private function findEvents(DateTime $date)
{
$found_events = array();

if (isset($this->events)) {
    foreach ($this->events as $event) {
        // Extracting and comparing only the dates (Y-m-d) to avoid time-based exclusion
        $eventStartDate = (new DateTime($event->start->format('Y-m-d')))->getTimestamp();
        $eventEndDate = (new DateTime($event->end->format('Y-m-d')))->getTimestamp();
        $inputDate = (new DateTime($date->format('Y-m-d')))->getTimestamp();

        if ($inputDate >= $eventStartDate && $inputDate <= $eventEndDate) {
            $found_events[] = $event;
        }
    }
}

return $found_events ?: false;

}
`

This modification ensures that the comparison focuses solely on the dates of events and input, disregarding the time part. This way, events occurring on the same day will be appropriately included irrespective of the specific times they occur.

more than one event per day

How can we make it so that if there is more than one event it shows on serperate lines as currently it shows all on one line

controller code

$calendar = new Calendar;
      $calendar->addTableClasses('w-full h-full');
      $calendar->stylesheet();
      $events = array();
      $shifts = ShiftModel::all();
      foreach ($shifts as $shift) {
          $events[] = array(
              'start' => $shift->start_time->format('Y-m-d'),
              'end' => $shift->end_time->format('Y-m-d'),
              'summary' => $shift->name,
              'mask' => true
              );
  }
  

  $calendar->addEvents($events);

View Code
echo $calendar->draw(date('Y-m-d'),

image

Title attribute on events doesn't escape HTML tags

Hi,

First of all thanks for your library :)

I got a user reporting a bug to me which is that the tooltips that appear when hovering over an event has escaped HTML displayed if the event has html injected in it (in my case, a <br> line break). See the screenshot:

image

I have a local patch, I'll make a PR.

Cheers
Pascal

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.