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.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

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

extending event_calender


Go to End
Reply


20 Posts   3484 Views

Avatar
Andre

Community Member, 126 Posts

12 August 2009 at 8:46pm

Hi,

I was trying to extend the Event Calender. In my Site Structure I need a recursive Funktion in every Page Object for a special Navigation block to display. If this Navigation block isn't set in a Page itself it should be taken from the parent.

Also I want to use the evant_calendar on my page, so I have to extend the calendar and Event Pages with my recursive funktion.

What I need next is the ability to add Content to every DAteTime Object of an Event (like it is possible on the announcements in the calendar).

So I tried to inherit from the Calendar.php, CalendarEvent.php and CalendarDateTime.php. But my code isn't working like I expected.

<?php

   class MyCalendar extends Calendar{

      public static $has_one = array(
         'LinkToMenublock' => 'SiteTreeFolder'
      );

static $has_many = array (
'Announcements' => 'MyCalendarDateTime',
'CalendarEvents' => 'MyCalendarEvent',
'Feeds' => 'ICSFeed'
);

static $allowed_children = array (
'MyCalendarEvent'
);

      public function getCMSFields() {
         $fields = parent::getCMSFields();
         $fields->addFieldToTab('Root.Content.Menublock', new TreeDropdownField("LinkToMenublockID", _t("ExtendedPage.SELECTMENUBLOCK", "Select a Menublock:"), "SiteTreeFolder"));
         return $fields;
      }

      public function MenuBlock(){
         $page = $this;
         $Menublock = $this->LinkToMenublock();
         while(!$Menublock->ID && $page->ParentID != 0){
            $page = $page->Parent();
            if(!method_exists($page, 'LinkToMenublock') && $page->ParentID != 0){
               $page = $page->Parent();
               $Menublock = $page->LinkToMenublock();
            }else{
               $Menublock = $page->LinkToMenublock();
            }
         }
         return $Menublock->Children();
      }
   }

class MyCalendar_Controller extends Calendar_Controller {
   
   public function init() {
      parent::init();
   }
   
}

?>

<?php

   class MyCalendarEvent extends CalendarEvent{

      public static $has_one = array(
         'Calendar' => 'MyCalendar',
         'LinkToMenublock' => 'SiteTreeFolder'
      );

static $has_many = array (
'DateTimes' => 'MyCalendarDateTime',
'Exceptions' => 'RecurringException'
);

      public function getCMSFields() {
         $fields = parent::getCMSFields();
         $fields->addFieldToTab('Root.Content.Menublock', new TreeDropdownField("LinkToMenublockID", _t("ExtendedPage.SELECTMENUBLOCK", "Select a Menublock:"), "SiteTreeFolder"));
         return $fields;
      }

      public function MenuBlock(){
         $page = $this;
         $Menublock = $this->LinkToMenublock();
         while(!$Menublock->ID && $page->ParentID != 0){
            $page = $page->Parent();
            if(!method_exists($page, 'LinkToMenublock') && $page->ParentID != 0){
               $page = $page->Parent();
               $Menublock = $page->LinkToMenublock();
            }else{
               $Menublock = $page->LinkToMenublock();
            }
         }
         return $Menublock->Children();
      }
   }

class MyCalendarEvent_Controller extends CalendarEvent_Controller {
   
   public function init() {
      parent::init();
   }
   
}

?>

<?php

   class MyCalendarDateTime extends CalendarDateTime{

static $has_one = array (
'Event' => 'MyCalendarEvent',
'Calendar' => 'MyCalendar'
);

public function getDateTimePopup(){
$f = new FieldSet();
$f->push(new TextField('Title',_t('CalendarDateTime.TITLE','Title')));
$f->push(new CalendarDateField('StartDate',_t('CalendarDateTime.STARTDATE','Start Date')));
$f->push(new TimeField('StartTime',_t('CalendarDateTime.STARTTIME','Start Time')));
$f->push(new CalendarDateField('EndDate',_t('CalendarDateTime.ENDDATE','EndDate')));
$f->push(new TimeField('EndTime',_t('CalendarDateTime.ENDTIME','End Time')));
$f->push(new CheckboxField('is_all_day',_t('CalendarDateTime.ALLDAY','All Day')));
$f->push(new SimpleHtmlEditorField('Content',_t('CalendarDateTime.CONTENT','Content')));
$f->push(new HiddenField('is_announcement',null,'1'));

return $f;
}
}

?>

When I add these classes to mysite/code I get the following error:

[User Error] Couldn't run query: SELECT `CalendarDateTime`.*, `MyCalendarDateTime`.*, `CalendarDateTime`.ID, if(`CalendarDateTime`.ClassName,`CalendarDateTime`.ClassName,'CalendarDateTime') AS RecordClassName FROM `CalendarDateTime` LEFT JOIN `ChurchCalendarDateTime` ON `MyCalendarDateTime`.ID = `CalendarDateTime`.ID LEFT JOIN `CalendarEvent` ON `CalendarEvent`.ID = `CalendarDateTime`.EventID WHERE ( Recursion != 1 AND ( (StartDate = '2010-02-12') OR (StartDate BETWEEN '2009-08-12' AND '2010-02-12') OR (EndDate BETWEEN '2009-08-12' AND '2010-02-12') ) AND EventID IN (6) ) GROUP BY `CalendarDateTime`.ID ORDER BY StartDate ASC, StartTime ASC, EventID ASC Column 'EventID' in where clause is ambiguous

Thrown on Line 401 in /usr/www/users/kirchk/sapphire/core/model/MySQLDatabase.php

392    }
393    
394    function databaseError($msg, $errorLevel = E_USER_ERROR) {
395       // try to extract and format query
396       if(preg_match('/Couldn\'t run query: ([^\|]*)\|\s*(.*)/', $msg, $matches)) {
397          $formatter = new SQLFormatter();
398          $msg = "Couldn't run query: \n" . $formatter->formatPlain($matches[1]) . "\n\n" . $matches[2];
399       }
400       
401       user_error($msg, $errorLevel);
402    }
403 }
404
405 /**
406 * A result-set from a MySQL database.
407 * @package sapphire

Avatar
UncleCheese

Forum Moderator, 4092 Posts

13 August 2009 at 1:13am

Edited: 13/08/2009 1:13am

Yeah, that's a bug, alright. Try an SVN update and see it fixes your problem.

Avatar
Andre

Community Member, 126 Posts

13 August 2009 at 7:38am

Edited: 13/08/2009 7:47am

Hi, i updated to revision 67 now, but the error stays the same. It looks like the one you've posted to my Bug Thred.
http://eventcalendar.bluehousegroup.com/

The strange Thing is, the error shows up on every Calender. It doesn't matter, if I have used the standart class or my extension. The Normal Calendar is only working again when I remove my extension from mysite directory.

Avatar
UncleCheese

Forum Moderator, 4092 Posts

13 August 2009 at 7:53am

Whoops. Okay, try another update. It's working again on the demo site.

Avatar
Andre

Community Member, 126 Posts

13 August 2009 at 7:02pm

Hi, I'm sorry to have to annoy you again.

I updated to Rev 68 now, but the error stays still the same. It only appears, when I have installed my extension. And then the error appears on my normal Calendar Page and my extended Calendar Page.

When removing the extension, the normal Calendar seems to work finde. But, now I got an error when clicking oin an Event in the Calendar.

This Error Message Appears:

[Warning] file_get_contents() [function.file-get-contents]: Filename cannot be empty
GET /test-event/2009-08-26

Line 277 in /usr/www/users/kirchk/sapphire/core/SSViewer.php

Source

268    /**
269     * Used by <% include Identifier %> statements to get the full
270     * unparsed content of a template file.
271     *
272     * @uses getTemplateFile()
273     * @param string $identifier A template name without '.ss' extension or path.
274     * @return string content of template
275     */
276    public static function getTemplateContent($identifier) {
277       return file_get_contents(SSViewer::getTemplateFile($identifier));
278    }
279    
280    /**
281     * @ignore
282     */
283    static private $flushed = false;

Trace

* file_get_contents()
Line 277 of SSViewer.php
* SSViewer::getTemplateContent(BreadCrumbs)
Line 2 of SSViewer.php(396) : runtime-created function
* __lambda_func(Array)
* preg_replace_callback(/<% include +([A-Za-z0-9_]+) +%>/,�lambda_7547,<!-- template /usr/www/users/kirchk/event_calendar/templates/Layout/CalendarEvent.ss --> <% require css(event_calendar/css/calendar.css) %> <% require javascript(event_calendar/javascript/calendar_core.js) %> <div id="primaryContent" class="clearfix"> <div class="innerpad"> <div id="calendar-sidebar"> <h3><% _t('BROWSECALENDAR','Browse the Calendar') %></h3> <div id="monthNav"> <p><% _t('USECALENDAR','Use the calendar below to navigate dates') %></p> $CalendarWidget <h4><% _t('FILTERCALENDAR','Fitler calendar') %>:</h4> $CalendarFilterForm </div> </div> <div id="calendar-main"> <div id="topHeading" class="clearfix"> <span class="back"><a href="$CalendarBackLink"><% _t('BACKTO','Back to') %> $Parent.Title</a></span> <span class="feed"><a href="$RSSLink"><% _t('SUBSCRIBE','Subscribe to the Calendar') %></a></span> <h2>$Parent.Title</h2> </div> <% if Level(2) %> <% include BreadCrumbs %> <% end_if %> <div class="vevent"> <% if OtherDates %> <div id="additionalDates"> <h4><% _t('ADDITIONALDATES','Additional Dates') %></h4> <dl class="date clearfix"> <% control OtherDates %> <dt><a href="$Link" title="$Event.Title">$_Dates</a></dt> <% end_control %> </dl> </div> <% end_if %> <h3 class="summary">$Title</h3> <% control CurrentDate %> <h4><a href="$ICSLink" title="Add to Calendar">$_Dates</a></h4> <% if StartTime %> <ul id="times"> <li>$_Times</li> </ul> <% end_if %> <% end_control %> $Content $Form $PageComments </div> </div> </div> </div> <!-- end template /usr/www/users/kirchk/event_calendar/templates/Layout/CalendarEvent.ss -->)
Line 396 of SSViewer.php
* SSViewer::parseTemplateContent(<% require css(event_calendar/css/calendar.css) %> <% require javascript(event_calendar/javascript/calendar_core.js) %> <div id="primaryContent" class="clearfix"> <div class="innerpad"> <div id="calendar-sidebar"> <h3><% _t('BROWSECALENDAR','Browse the Calendar') %></h3> <div id="monthNav"> <p><% _t('USECALENDAR','Use the calendar below to navigate dates') %></p> $CalendarWidget <h4><% _t('FILTERCALENDAR','Fitler calendar') %>:</h4> $CalendarFilterForm </div> </div> <div id="calendar-main"> <div id="topHeading" class="clearfix"> <span class="back"><a href="$CalendarBackLink"><% _t('BACKTO','Back to') %> $Parent.Title</a></span> <span class="feed"><a href="$RSSLink"><% _t('SUBSCRIBE','Subscribe to the Calendar') %></a></span> <h2>$Parent.Title</h2> </div> <% if Level(2) %> <% include BreadCrumbs %> <% end_if %> <div class="vevent"> <% if OtherDates %> <div id="additionalDates"> <h4><% _t('ADDITIONALDATES','Additional Dates') %></h4> <dl class="date clearfix"> <% control OtherDates %> <dt><a href="$Link" title="$Event.Title">$_Dates</a></dt> <% end_control %> </dl> </div> <% end_if %> <h3 class="summary">$Title</h3> <% control CurrentDate %> <h4><a href="$ICSLink" title="Add to Calendar">$_Dates</a></h4> <% if StartTime %> <ul id="times"> <li>$_Times</li> </ul> <% end_if %> <% end_control %> $Content $Form $PageComments </div> </div> </div> </div>,/usr/www/users/kirchk/event_calendar/templates/Layout/CalendarEvent.ss)
Line 321 of SSViewer.php
* SSViewer->process(CalendarEvent_Controller)
Line 346 of SSViewer.php
* SSViewer->process(CalendarEvent_Controller)
Line 175 of Controller.php
* Controller->handleAction(HTTPRequest)
Line 129 of RequestHandler.php
* RequestHandler->handleRequest(HTTPRequest)
Line 122 of Controller.php
* Controller->handleRequest(HTTPRequest)
Line 29 of ModelAsController.php
* ModelAsController->handleRequest(HTTPRequest)
Line 277 of Director.php
* Director::handleRequest(HTTPRequest,Session)
Line 121 of Director.php
* Director::direct(/test-event/2009-08-26)
Line 118 of main.php

Is it possible, that I have done something wrong inside my Extension or do they seem ok from the code?

Avatar
UncleCheese

Forum Moderator, 4092 Posts

14 August 2009 at 12:30am

Yeah, i've had this error come up before. Are you sure there is a BreadCrumbs.ss, and you're sure it's not empty?

Avatar
Andre

Community Member, 126 Posts

24 August 2009 at 11:56pm

I'm sure, there is no BreadCrumps.ss Where does it have to be and in which template it is requested?

Avatar
UncleCheese

Forum Moderator, 4092 Posts

25 August 2009 at 1:09am

I know a lot of the default themes check for breadcrumbs.ss. Are you using a theme? Check the templates directory on Page.ss, etc and make sure they're not using something like <% include Breadcrumbs %>

Go to Top