forked from dospuntocero/EventCalendar
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Uncle Cheese
committed
Feb 20, 2013
1 parent
b045ac7
commit 41eb7be
Showing
19 changed files
with
253 additions
and
99 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
CachedCalendarTask: | ||
cache_future_years: 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
class CachedCalendarBuildTask extends BuildTask { | ||
|
||
protected $title = "Cache the Event Calendars"; | ||
|
||
|
||
protected $description = 'Generates a given number of years of events and populates a readonly table with all the event information. Useful when using recurring events or multiple calendars.'; | ||
|
||
|
||
public function run($request) { | ||
CachedCalendarTask::create()->process(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
<?php | ||
|
||
|
||
class CachedCalendarEntry extends DataObject { | ||
|
||
|
||
|
||
static $db = array ( | ||
'StartDate' => 'Date', | ||
'StartTime' => 'Time', | ||
'EndDate' => 'Date', | ||
'EndTime' => 'Time', | ||
'AllDay' => 'Boolean', | ||
'Announcement' => 'Boolean', | ||
'DateRange' => 'HTMLText', | ||
'TimeRange' => 'HTMLText', | ||
'ICSLink' => 'Varchar(100)', | ||
'Title' => 'Varchar(255)', | ||
'Content' => 'HTMLText' | ||
); | ||
|
||
|
||
static $has_one = array ( | ||
'CachedCalendar' => 'Calendar', | ||
'Calendar' => 'Calendar', | ||
'Event' => 'CalendarEvent' | ||
); | ||
|
||
|
||
|
||
static $default_sort = "StartDate ASC, StartTime ASC"; | ||
|
||
|
||
|
||
|
||
|
||
public static function create_from_datetime(CalendarDateTime $dt, Calendar $calendar) { | ||
$cached = CachedCalendarEntry::create(); | ||
$cached->hydrate($dt, $calendar); | ||
return $cached; | ||
} | ||
|
||
|
||
|
||
public static function create_from_announcement(CalendarAnnouncement $dt, Calendar $calendar) { | ||
$cached = CachedCalendarEntry::create(); | ||
$cached->hydrate($dt, $calendar); | ||
$cached->CalendarID = $dt->CalendarID; | ||
$cached->Announcement = 1; | ||
return $cached; | ||
} | ||
|
||
|
||
|
||
|
||
public function OtherDates() { | ||
if($this->Announcement) { | ||
return false; | ||
} | ||
|
||
return CachedCalendarEntry::get() | ||
->where("EventID = {$this->EventID}") | ||
->where("StartDate != '{$this->StartDate}'") | ||
->limit($this->CachedCalendar()->DefaultEventDisplay); | ||
} | ||
|
||
|
||
|
||
public function hydrate(CalendarDateTime $dt, Calendar $calendar) { | ||
$this->CachedCalendarID = $calendar->ID; | ||
foreach($dt->db() as $field => $type) { | ||
$this->$field = $dt->$field; | ||
} | ||
foreach($dt->has_one() as $field => $type) { | ||
$this->{$field."ID"} = $dt->{$field."ID"}; | ||
} | ||
$this->DateRange = $dt->DateRange(); | ||
$this->TimeRange = $dt->TimeRange(); | ||
$this->ICSLink = $dt->ICSLink(); | ||
$this->Title = $dt->getTitle(); | ||
$this->Content = $dt->getContent(); | ||
return $this; | ||
} | ||
|
||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
|
||
|
||
class CachedCalendarTask extends HourlyTask { | ||
|
||
public function process() { | ||
increase_time_limit_to(300); | ||
DB::query("DELETE FROM CachedCalendarEntry"); | ||
$future_years = $this->config()->cache_future_years; | ||
foreach(Calendar::get() as $calendar) { | ||
echo "<h2>Caching calendar '$calendar->Title'</h2>\n"; | ||
foreach($calendar->getAllCalendars() as $c) { | ||
foreach($c->AllChildren() as $event) { | ||
// All the dates of regular events | ||
if($event->Recursion) { | ||
echo "<h3>Creating recurring events for '$event->Title'</h3>\n"; | ||
$i = 0; | ||
$dt = $event->DateTimes()->first(); | ||
if(!$dt) continue; | ||
if($dt->EndDate) { | ||
$end_date = sfDate::getInstance($dt->EndDate); | ||
} | ||
else { | ||
$end_date = sfDate::getInstance()->addYear($future_years); | ||
} | ||
$start_date = sfDate::getInstance($dt->StartDate); | ||
$recursion = $event->getRecursionReader(); | ||
while($start_date->get() <= $end_date->get()) { | ||
if($recursion->recursionHappensOn($start_date->get())) { | ||
$dt->StartDate = $start_date->format('Y-m-d'); | ||
$cached = CachedCalendarEntry::create_from_datetime($dt, $calendar); | ||
$cached->EndDate = $cached->StartDate; | ||
$cached->write(); | ||
} | ||
$start_date->addDay(); | ||
$i++; | ||
} | ||
echo "<p>$i events created.</p>\n"; | ||
} | ||
else { | ||
foreach($event->DateTimes() as $dt) { | ||
echo "<p>Adding dates for event '$event->Title'</p>\n"; | ||
$cached = CachedCalendarEntry::create_from_datetime($dt, $calendar); | ||
$cached->write(); | ||
} | ||
} | ||
// Announcements | ||
} | ||
foreach($c->Announcements() as $a) { | ||
echo "<p>Adding announcement $a->Title</p>\n"; | ||
$cached = CachedCalendarEntry::create_from_announcement($a, $calendar); | ||
$cached->write(); | ||
} | ||
} | ||
} | ||
echo "Done!"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -112,4 +112,6 @@ public function recursionHappensOn($ts) | |
} | ||
|
||
|
||
|
||
|
||
} |
This file was deleted.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file.
Oops, something went wrong.