Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

All other Modules /

Discuss all other Modules here.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

EventCalendar bug: "CalendarID" not stored > OtherDatesCount not available


Reply


629 Views

Avatar
silverseba

Community Member, 26 Posts

22 June 2010 at 10:11pm

Edited: 22/06/2010 10:14pm

Hi UncleCheese,

I think I found a bug in the event_calendar module (SS 2.4, EventCalendar: latest trunk from svn):

The Calendar ID (of the parent Calendar) isn´t stored in the database for CalendarEvent and CalendarDateTime.
As a result the method OtherDates() returns the wrong value for "OtherDatesCount".

In class Calendar you can set the variable for "OtherDatesCount" (the number of additional dates that are shown in the calendar).
When you use the controller OtherDates in a template (which calls the method CalendarEvent::OtherDates()), it always displays 3 additional dates, even if I set a different value in the cms.
So the method OtherDates() always uses the default value for OtherDatesCount, that is set in the $defaults array in class Calendar.

I think I´ve got an idea where the bug comes from, but can´t come up with a fix.

The bug happens when an object for the parent Calendar is created in method OtherDates() on line 290 in event_calendar/code/CalendarEvent.php

public function OtherDates()
   {
      if(!$date = CalendarUtil::getDateFromURL()) {
         $date_obj = DataObject::get_one($this->getDateTimeClass(),"EventID = {$this->ID}", "StartDate ASC");
         if(!$date_obj) return false;
       else $date = $date_obj->StartDate;
      }
      if($date) {
         $cal = $this->Calendar();
         if($this->Recursion == 1) {
            $datetime_obj = DataObject::get_one($this->getDateTimeClass(), "EventID = {$this->ID}");
            $datetime_obj->StartDate = $date;
            return $cal->getNextRecurringEvents($this, $datetime_obj);
         }
         else {
            if($dates = DataObject::get($this->getDateTimeClass(), "EventID = {$this->ID} AND StartDate != '".$date."'","StartDate ASC","",$cal->OtherDatesCount))
               return CalendarUtil::CollapseDatesAndTimes($dates);
         }
      }
      else
         return false;
   }

The object $cal is an object with the default values set in the class Calendar. It has the ID "0", so it isn´t the parent Calendar object for the current CalendarEvent.

I had a look at the database, where I found another part of th bug:
The CalendarID value for all CalendarEvents and CalendarDateTime is always "0"

So when trying to create the parent Calendar object with $this->Calendar() in class CalendarEvent, a Calendar with the ID "0" is created, as this is the CalendarId that is stored for the current event.

I think the fix would be to store the correct ID for the parent Calendar in CalendarEvent and CalendarDateTime.
But I don´t know how to do this, as it should automatically be done by setting the $has_one and $has_many relationships.

@UncleCheese: Do you know how to fix this?