Skip to content

Commit

Permalink
Fixed file generation
Browse files Browse the repository at this point in the history
  • Loading branch information
peavers committed Jul 11, 2016
1 parent 7862553 commit 9d93237
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 9 deletions.
21 changes: 20 additions & 1 deletion code/pagetypes/FullCalendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ class FullCalendar extends Page

private static $can_be_root = true;

private static $extensions = array(
'Lumberjack',
);

private static $db = array(
'LegacyEvents' => 'Boolean',
'CalendarView' => 'Varchar(255)',
Expand Down Expand Up @@ -98,6 +102,21 @@ public function getDocumentRoot()
{
return $this;
}

/**
* Create the .ics file and save it to the Calendar
*/
public function onBeforeWrite()
{
// Write the ics file for the event
$service = new IcsGenerator($this->Title);
$service->generateEventList($this->ID, null);

// Attach the file to this page
$this->CalFileID = $service->getFileObject()->ID;

parent::onBeforeWrite();
}
}

/**
Expand Down Expand Up @@ -204,7 +223,7 @@ public function getUpcomingEvents()
$filter = array(
'ParentID' => $this->ID,
'IncludeOnCalendar' => true,
'EndDate:GreaterThanOrEqual' => date("Y-m-d")
'StartDate:GreaterThanOrEqual' => date("Y-m-d")
);

return FullCalendarEvent::get()->filter($filter)->limit(5)->sort('StartDate ASC');
Expand Down
6 changes: 5 additions & 1 deletion code/pagetypes/FullCalendarEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ class FullCalendarEvent extends Page

private static $can_be_root = false;

private static $show_in_sitetree = false;

private static $allowed_children = array();

private static $summary_fields = array(
'Title' => 'Title',
'StartDate' => 'StartDate',
Expand Down Expand Up @@ -99,5 +103,5 @@ public function getCMSValidator()
*/
class FullCalendarEvent_Controller extends Page_Controller
{

}
8 changes: 1 addition & 7 deletions code/service/IcsGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,13 @@ public function getFileObject()
return $this->fileObject;
}



/**
* @param $fullCalendarID int the id of the FullCalendar page to return events for
* @param $singleEventID int the fullCalendarID of a single event
*/
public function generateEventList($fullCalendarID = null, $singleEventID = null)
{
if (!is_null($fullCalendarID)) {
$events = FullCalendarEvent::get()->filter(array('ParentID' => $fullCalendarID));
} else {
$events = FullCalendarEvent::get()->filter(array('ID' => $singleEventID))->first();
}
$events = !is_null($fullCalendarID) ? FullCalendarEvent::get()->filter(array('ParentID' => $fullCalendarID)) : FullCalendarEvent::get()->filter(array('ID' => $singleEventID))->first();

file_put_contents($this->filePath, '');

Expand Down

0 comments on commit 9d93237

Please sign in to comment.