Skip to content

Commit

Permalink
Add filters for events
Browse files Browse the repository at this point in the history
  • Loading branch information
themightychris committed Sep 25, 2016
1 parent 8b0373e commit 0845653
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
6 changes: 5 additions & 1 deletion html-templates/events/events.tpl
Expand Up @@ -16,7 +16,11 @@

<div class="row">
<div class="col-sm-4 col-md-3">
[Event Filters]
<ul>
<li><a href="/events/*past">Past Events</a></li>
<li><a href="/events/*upcoming">Upcoming Events</a></li>
<li><a href="/events/*all">All Events</a></li>
</ul>
</div>
<div class="col-sm-8 col-md-9">
{foreach item=Event from=$data}
Expand Down
35 changes: 34 additions & 1 deletion php-classes/Emergence/Events/EventsRequestHandler.php
Expand Up @@ -12,6 +12,20 @@ class EventsRequestHandler extends \RecordsRequestHandler
public static $accountLevelWrite = 'Staff';
public static $browseOrder = ['StartTime'];

public static function handleRecordsRequest($action = null)
{
switch ($action ?: $action = static::shiftPath()) {
case '*all':
return static::handleBrowseRequest(['startTime' => 'any']);
case '*past':
return static::handleBrowseRequest(['startTime' => 'past', 'order' => ['StartTime' => 'DESC']]);
case '*upcoming':
return static::handleBrowseRequest(['startTime' => 'upcoming']);
default:
return parent::handleRecordsRequest($action);
}
}

public static function handleBrowseRequest($options = [], $conditions = [], $responseID = null, $responseData = [])
{
if (!$GLOBALS['Session']->hasAccountLevel('Staff')) {
Expand All @@ -20,7 +34,26 @@ public static function handleBrowseRequest($options = [], $conditions = [], $res
$conditions['Status'] = $_GET['status'];
}

$conditions[] = 'StartTime >= FROM_UNIXTIME('.(strtotime(!empty($_GET['startTimeMin']) ? $_GET['startTimeMin'] : 'now')?:time()).')';
switch ($options['startTime']) {
case 'any':
break;
case 'past':
$conditions[] = '(EndTime IS NULL AND StartTime <= CURRENT_TIMESTAMP) OR (EndTime IS NOT NULL AND EndTime <= CURRENT_TIMESTAMP)';
break;
case 'upcoming':
$conditions[] = '(EndTime IS NULL AND StartTime >= CURRENT_TIMESTAMP) OR (EndTime IS NOT NULL AND EndTime >= CURRENT_TIMESTAMP)';
break;
default:
if (empty($_GET['startTimeMin'])) {
$startTimeMin = time();
} elseif (!$startTimeMin = strtotime($_GET['startTimeMin'])) {
return static::throwInvalidRequestError('startTimeMin not parsable');
}

$conditions[] = 'StartTime >= FROM_UNIXTIME('.$startTimeMin.')';
break;
}


return parent::handleBrowseRequest($options, $conditions, $responseID, $responseData);
}
Expand Down

0 comments on commit 0845653

Please sign in to comment.