diff --git a/html-templates/events/event.tpl b/html-templates/events/event.tpl new file mode 100644 index 00000000..351cf292 --- /dev/null +++ b/html-templates/events/event.tpl @@ -0,0 +1,90 @@ +{extends "designs/site.tpl"} + +{block title}{_ 'Event'} — {$dwoo.parent}{/block} + +{block content} + {$Event = $data} + + + +
+
+
+ {if $Event->Status != 'published'} +
Status
+
{$Event->Status}
+ {/if} + +
Start time
+
{timestamp $Event->StartTime time=yes}
+ + {if $Event->EndTime} +
End time
+
{timestamp $Event->EndTime time=yes}
+ {/if} + + {if $Event->Location} +
Location
+
{$Event->Location|escape}
+ {/if} + + {if $Event->Description} +
Description
+
+
{$Event->Description|truncate:600|escape|markdown}
+
+ {/if} + + {if $Event->Segments} +
Segments
+
+
+ {$lastDate = null} + {foreach item=Segment from=$Event->Segments} + {$thisDate = date("l<\\b\\r>F jS", $Segment->StartTime)} + {if $lastDate != $thisDate} + {if $lastDate} +
+
+ {/if} +
{$thisDate}
+
+
+ {$lastDate = $thisDate} + {/if} +
{time_range $Segment->StartTime $Segment->EndTime}
+
+ Handle")}">{$Segment->Title|escape} + {if $Segment->LocationName || $Segment->LocationAddress} +

+ Location + + {if $Segment->LocationName && $Segment->LocationAddress} + {$Segment->LocationName|escape} ({$Segment->LocationAddress|escape}) + {else} + {$Segment->LocationName|default:$Segment->LocationAddress|escape} + {/if} + +

+ {/if} + {$Segment->Description|escape|markdown} +
+ + {/foreach} +
+
+ + {/if} + +
+
+{/block} \ No newline at end of file diff --git a/php-classes/Emergence/Events/Event.php b/php-classes/Emergence/Events/Event.php index f4df52fb..177e69d9 100644 --- a/php-classes/Emergence/Events/Event.php +++ b/php-classes/Emergence/Events/Event.php @@ -3,6 +3,7 @@ namespace Emergence\Events; use HandleBehavior; +use Emergence\Comments\Comment; class Event extends \VersionedRecord @@ -32,7 +33,11 @@ class Event extends \VersionedRecord 'type' => 'timestamp', 'default' => null ], - 'Location' => [ + 'LocationName' => [ + 'type' => 'string', + 'default' => null + ], + 'LocationAddress' => [ 'type' => 'string', 'default' => null ], @@ -45,8 +50,13 @@ class Event extends \VersionedRecord public static $relationships = [ 'Comments' => [ 'type' => 'context-children', - 'class' => 'Comment', + 'class' => Comment::class, 'order' => ['ID' => 'DESC'] + ], + 'Segments' => [ + 'type' => 'one-many', + 'class' => EventSegment::class, + 'order' => 'StartTime' ] ]; @@ -86,6 +96,7 @@ class Event extends \VersionedRecord 'validator' => 'datetime', 'errorMessage' => 'Event start time is required' ] + // TODO: validate that EndTime > StartTime if set ]; public function getIsAllDay() diff --git a/php-classes/Emergence/Events/EventSegment.php b/php-classes/Emergence/Events/EventSegment.php new file mode 100644 index 00000000..07e23907 --- /dev/null +++ b/php-classes/Emergence/Events/EventSegment.php @@ -0,0 +1,87 @@ + 'uint', + 'Title', + 'Handle', + 'StartTime' => [ + 'type' => 'timestamp' + ], + 'EndTime' => [ + 'type' => 'timestamp' + ], + 'LocationName' => [ + 'type' => 'string', + 'default' => null + ], + 'LocationAddress' => [ + 'type' => 'string', + 'default' => null + ], + 'Description' => [ + 'type' => 'clob', + 'default' => null + ] + ]; + + public static $indexes = [ + 'EventHandle' => [ + 'fields' => ['EventID', 'Handle'], + 'unique' => true + ] + ]; + + public static $relationships = [ + 'Event' => [ + 'type' => 'one-many', + 'class' => Event::class + ] + ]; + + public static $dynamicFields = [ + 'Event' + ]; + + public static $validators = [ + 'Event' => 'require-relationship', + 'StartTime' => [ + 'validator' => 'datetime', + 'errorMessage' => 'Event start time is required' + ] + // TODO: validate that EndTime > StartTime if set + ]; + + public function validate($deep = true) + { + // call parent + parent::validate(); + + HandleBehavior::onValidate($this, $this->_validator); + + // save results + return $this->finishValidation(); + } + + public function save($deep = true) + { + HandleBehavior::onSave($this); + + // call parent + parent::save(); + } +} \ No newline at end of file