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