Skip to content

Commit

Permalink
Add template for event details
Browse files Browse the repository at this point in the history
  • Loading branch information
themightychris committed Sep 25, 2016
1 parent fbe9799 commit 8b0373e
Show file tree
Hide file tree
Showing 3 changed files with 190 additions and 2 deletions.
90 changes: 90 additions & 0 deletions html-templates/events/event.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
{extends "designs/site.tpl"}

{block title}{_ 'Event'} — {$dwoo.parent}{/block}

{block content}
{$Event = $data}

<header class="page-header">
<div class="btn-toolbar pull-right">
{if $.User}
<form action="{$Event->getUrl(edit)}">
<button class="btn btn-success" type="submit">{glyph "pencil"}&nbsp;{_ "Edit Event&hellip;"}</button>
</form>
{/if}
</div>
<h1><a href="/events">{_ "Events"}</a>&nbsp;&raquo; <a href="{$Event->getUrl()}">{$Event->Title|escape}</a></h1>
</header>

<article class="post panel panel-default">
<div class="panel-body">
<dl class="dl-horizontal">
{if $Event->Status != 'published'}
<dt>Status</dt>
<dd><strong>{$Event->Status}</strong></dd>
{/if}

<dt>Start time</dt>
<dd>{timestamp $Event->StartTime time=yes}</dd>

{if $Event->EndTime}
<dt>End time</dt>
<dd>{timestamp $Event->EndTime time=yes}</dd>
{/if}

{if $Event->Location}
<dt>Location</dt>
<dd><a href="https://www.google.com/maps?q={$Event->Location|escape:url}">{$Event->Location|escape}</a></dd>
{/if}

{if $Event->Description}
<dt>Description</dt>
<dd class="well">
<div class="markdown event-description">{$Event->Description|truncate:600|escape|markdown}</div>
</dd>
{/if}

{if $Event->Segments}
<dt>Segments</dt>
<dd>
<dl class="dl-horizontal">
{$lastDate = null}
{foreach item=Segment from=$Event->Segments}
{$thisDate = date("l<\\b\\r>F jS", $Segment->StartTime)}
{if $lastDate != $thisDate}
{if $lastDate}
</dl>
</dd>
{/if}
<dt>{$thisDate}</dt>
<dd>
<dl class="dl-horizontal">
{$lastDate = $thisDate}
{/if}
<dt>{time_range $Segment->StartTime $Segment->EndTime}</dt>
<dd>
<a href="{$Event->getUrl("segments/$Segment->Handle")}">{$Segment->Title|escape}</a>
{if $Segment->LocationName || $Segment->LocationAddress}
<p>
<strong>Location</strong>
<a target="_blank" href="https://maps.google.com?q={implode(', ', array_filter(array($Segment->LocationName, $Segment->LocationAddress)))|escape:url}">
{if $Segment->LocationName && $Segment->LocationAddress}
{$Segment->LocationName|escape} ({$Segment->LocationAddress|escape})
{else}
{$Segment->LocationName|default:$Segment->LocationAddress|escape}
{/if}
</a>
</p>
{/if}
{$Segment->Description|escape|markdown}
</dd>

{/foreach}
</dl></dd>
</dl>
</dd>
{/if}
</dl>
</div>
</article>
{/block}
15 changes: 13 additions & 2 deletions php-classes/Emergence/Events/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Emergence\Events;

use HandleBehavior;
use Emergence\Comments\Comment;


class Event extends \VersionedRecord
Expand Down Expand Up @@ -32,7 +33,11 @@ class Event extends \VersionedRecord
'type' => 'timestamp',
'default' => null
],
'Location' => [
'LocationName' => [
'type' => 'string',
'default' => null
],
'LocationAddress' => [
'type' => 'string',
'default' => null
],
Expand All @@ -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'
]
];

Expand Down Expand Up @@ -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()
Expand Down
87 changes: 87 additions & 0 deletions php-classes/Emergence/Events/EventSegment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?php

namespace Emergence\Events;

use HandleBehavior;


class EventSegment extends \VersionedRecord
{
// ActiveRecord configuration
public static $tableName = 'event_segments'; // the name of this model's table
public static $collectionRoute = '/event-segments';

// controllers will use these values to figure out what templates to use
public static $singularNoun = 'event segment'; // a singular noun for this model's object
public static $pluralNoun = 'event segments'; // a plural noun for this model's object

public static $fields = [
'EventID' => '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();
}
}

0 comments on commit 8b0373e

Please sign in to comment.