Skip to content

Commit

Permalink
Merge #121 after fixing conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
akrabat committed Jun 25, 2014
2 parents 9b582aa + b86d78d commit 374b254
Show file tree
Hide file tree
Showing 19 changed files with 113 additions and 119 deletions.
4 changes: 2 additions & 2 deletions app/src/Application/BaseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ abstract class BaseController
protected $accessToken;
protected $cfg;

function __construct(Slim $app)
public function __construct(Slim $app)
{
$this->application = $app;
$this->defineRoutes($app);
$this->cfg = $this->getConfig();
$this->cfg = $this->getConfig();

$this->accessToken = isset($_SESSION['access_token']) ? $_SESSION['access_token'] : null;
}
Expand Down
65 changes: 33 additions & 32 deletions app/src/Application/CacheService.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,46 +5,47 @@
* Class CacheService
*
* Stores semi-transiently a piece of data against a given key.
*
*/
class CacheService
{
protected $client;
protected $keyPrefix;
protected $keyPrefix;

public function __construct($keyPrefix = '')
{
$this->keyPrefix = $keyPrefix;
$this->client = new \Predis\Client();
$this->keyPrefix = $keyPrefix;
$this->client = new \Predis\Client();
}

public function save($collection, $data, $keyField, $keyValue) {
$fqKey = $this->keyPrefix.$collection.'-'.$keyField.'-'.substr(md5($keyValue), 0, 6);
$this->client->set($fqKey, serialize($data));
}

public function load($collection, $keyField, $keyValue) {
$fqKey = $this->keyPrefix.$collection.'-'.$keyField.'-'.substr(md5($keyValue), 0, 6);
$data = unserialize($this->client->get($fqKey));
return $data;
}

public function saveByKeys($collection, $data, array $keys) {
$fqKey = $this->keyPrefix.$collection;
foreach ($keys as $keyField=>$keyValue) {
$fqKey.= '-'.$keyField.'-'.substr(md5($keyValue), 0, 6);
}
$this->client->set($fqKey, serialize($data));
}

public function loadByKeys($collection, array $keys) {
$fqKey = $this->keyPrefix.$collection;
foreach ($keys as $keyField=>$keyValue) {
$fqKey.= '-'.$keyField.'-'.substr(md5($keyValue), 0, 6);
}
$data = unserialize($this->client->get($fqKey));
return $data;
}
public function save($collection, $data, $keyField, $keyValue)
{
$fqKey = $this->keyPrefix . $collection . '-' . $keyField . '-' . substr(md5($keyValue), 0, 6);
$this->client->set($fqKey, serialize($data));
}

}
public function load($collection, $keyField, $keyValue)
{
$fqKey = $this->keyPrefix . $collection . '-' . $keyField . '-' . substr(md5($keyValue), 0, 6);

return unserialize($this->client->get($fqKey));
}

public function saveByKeys($collection, $data, array $keys)
{
$fqKey = $this->keyPrefix . $collection;
foreach ($keys as $keyField => $keyValue) {
$fqKey .= '-' . $keyField . '-' . substr(md5($keyValue), 0, 6);
}
$this->client->set($fqKey, serialize($data));
}

public function loadByKeys($collection, array $keys)
{
$fqKey = $this->keyPrefix . $collection;
foreach ($keys as $keyField => $keyValue) {
$fqKey .= '-' . $keyField . '-' . substr(md5($keyValue), 0, 6);
}

return unserialize($this->client->get($fqKey));
}
}
25 changes: 14 additions & 11 deletions app/src/Event/EventApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ public function getCollection($limit = 10, $start = 1, $filter = null)
*
* @param EventEntity $event The event to take details from
*/
protected function saveEventUrl(EventEntity $event) {
protected function saveEventUrl(EventEntity $event)
{
$this->eventDb->save($event);
}

Expand All @@ -71,7 +72,8 @@ protected function saveEventUrl(EventEntity $event) {
* @param string $friendlyUrl The nice url bit of the event (e.g. phpbenelux-conference-2014)
* @return EventEntity The event we found, or false if something went wrong
*/
public function getByFriendlyUrl($friendlyUrl) {
public function getByFriendlyUrl($friendlyUrl)
{
$event = $this->eventDb->load('url_friendly_name', $friendlyUrl);

if (!$event) {
Expand All @@ -93,7 +95,8 @@ public function getByFriendlyUrl($friendlyUrl) {
* @param string $stub The short url bit of the event (e.g. phpbnl14)
* @return EventEntity The event we found, or false if something went wrong
*/
public function getByStub($stub) {
public function getByStub($stub)
{
$event = $this->eventDb->load('stub', $stub);

if (!$event) {
Expand All @@ -106,23 +109,23 @@ public function getByStub($stub) {
return $event;
}

/**
* Get comments for given event
* @param $comment_uri
* @param bool $verbose
* @return Comment[]
*/
/**
* Get comments for given event
* @param $comment_uri
* @param bool $verbose
* @return Comment[]
*/
public function getComments($comment_uri, $verbose = false)
{
if($verbose) {
if ($verbose) {
$comment_uri = $comment_uri . '?verbose=yes';
}

$comments = (array)json_decode($this->apiGet($comment_uri));

$commentData = array();

foreach($comments['comments'] as $comment) {
foreach ($comments['comments'] as $comment) {
$commentData[] = new EventCommentEntity($comment);
}

Expand Down
27 changes: 12 additions & 15 deletions app/src/Event/EventController.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ public function details($friendly_name)
{
$eventApi = $this->getEventApi();
$event = $eventApi->getByFriendlyUrl($friendly_name);
if($event) {
$quicklink = $this->application->request()->headers("host")
if ($event) {
$quicklink = $this->application->request()->headers("host")
. $this->application->urlFor(
"event-quicklink",
array("stub" => $event->getStub()
));
"event-quicklink",
array("stub" => $event->getStub())
);

$comments = $eventApi->getComments($event->getCommentsUri(), true);
$this->render(
Expand All @@ -89,7 +89,7 @@ public function map($friendly_name)

$event = $eventApi->getByFriendlyUrl($friendly_name);

if($event) {
if ($event) {
$this->render(
'Event/map.html.twig',
array(
Expand All @@ -102,12 +102,12 @@ public function map($friendly_name)
}
}

public function schedule($friendly_name)
{
public function schedule($friendly_name)
{
$eventApi = $this->getEventApi();
$event = $eventApi->getByFriendlyUrl($friendly_name);

if($event) {
if ($event) {
$keyPrefix = $this->cfg['redis']['keyPrefix'];
$cache = new CacheService($keyPrefix);
$talkDb = new TalkDb($cache);
Expand All @@ -127,24 +127,21 @@ public function schedule($friendly_name)
$events_url = $this->application->urlFor("events-index");
$this->application->redirect($events_url);
}

}
}

public function quicklink($stub)
{
$eventApi = $this->getEventApi();
$event = $eventApi->getByStub($stub);
if($event) {
if ($event) {
$this->application->redirect(
$this->application->urlFor("event-detail",
array("friendly_name" => $event->getUrlFriendlyName())),
$this->application->urlFor("event-detail", array("friendly_name" => $event->getUrlFriendlyName())),
301
);
} else {
$events_url = $this->application->urlFor("events-index");
$this->application->redirect($events_url);
}

}

public function addComment($friendly_name)
Expand Down
1 change: 0 additions & 1 deletion app/src/Event/EventDb.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,4 @@ public function save(EventEntity $event)
$this->cache->save($this->keyName, $data, 'url_friendly_name', $event->getUrlFriendlyName());
$this->cache->save($this->keyName, $data, 'stub', $event->getStub());
}

}
4 changes: 2 additions & 2 deletions app/src/Event/EventEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,8 @@ public function areCommentsEnabled()
return (bool)$this->data->comments_enabled;
}

public function isPastEvent() {
public function isPastEvent()
{
$endDate = DateTime::createFromFormat(DateTime::ISO8601, $this->getEndDate());
$now = new DateTime(null, $endDate->getTimezone());
$now->setTime(0, 0, 0);
Expand All @@ -213,5 +214,4 @@ public function getStub()

return $this->data->stub;
}

}
2 changes: 1 addition & 1 deletion app/src/Event/EventScheduler.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function getTalks($talks_uri)
*/
public function getEventDays($talks)
{
if(empty($talks)) {
if (empty($talks)) {
return array();
}

Expand Down
4 changes: 1 addition & 3 deletions app/src/Search/SearchApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function getEventCollection($keyword, $limit = 10, $start = 1, $filter =
$meta = array_pop($events);

$collectionData = array();
if(isset($events['events'])) {
if (isset($events['events'])) {
foreach ($events['events'] as $event) {
$collectionData['events'][] = new EventEntity($event);
}
Expand Down Expand Up @@ -82,6 +82,4 @@ public function getTalkCollection($keyword, $limit = 10, $start = 1, $filter = n

return $collectionData;
}


}
6 changes: 3 additions & 3 deletions app/src/Talk/TalkApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function getCollection($talks_uri)
*/
public function getTalk($talk_uri, $verbose = false)
{
if($verbose) {
if ($verbose) {
$talk_uri = $talk_uri . '?verbose=yes';
}

Expand All @@ -71,15 +71,15 @@ public function getTalk($talk_uri, $verbose = false)
*/
public function getComments($comment_uri, $verbose = false)
{
if($verbose) {
if ($verbose) {
$comment_uri = $comment_uri . '?verbose=yes';
}

$comments = (array)json_decode($this->apiGet($comment_uri));

$commentData = array();

foreach($comments['comments'] as $comment) {
foreach ($comments['comments'] as $comment) {
$commentData[] = new TalkCommentEntity($comment);
}

Expand Down
5 changes: 4 additions & 1 deletion app/src/Talk/TalkController.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@ public function quick($talkStub)
}

$this->application->redirect(
$this->application->urlFor('talk', array('eventSlug' => $event['url_friendly_name'], 'talkSlug' => $talk['slug']))
$this->application->urlFor(
'talk',
array('eventSlug' => $event['url_friendly_name'], 'talkSlug' => $talk['slug'])
)
);
}

Expand Down
2 changes: 1 addition & 1 deletion app/src/Talk/TalkDb.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function save(TalkEntity $talk)
$data = array_merge($savedTalk, $data);
}

$keys = array(
$keys = array(
'event_uri' => $talk->getEventUri(),
'slug' => $talk->getUrlFriendlyTalkTitle()
);
Expand Down
4 changes: 2 additions & 2 deletions app/src/Talk/TalkEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function getStartDateTime()

public function getEndDateTime()
{
if(!$this->data->duration) {
if (!$this->data->duration) {
return null;
}

Expand Down Expand Up @@ -81,7 +81,7 @@ public function getTracks()

public function getApiUri($verbose = false)
{
if($verbose) {
if ($verbose) {
return $this->data->verbose_uri;
}
return $this->data->uri;
Expand Down
19 changes: 7 additions & 12 deletions app/src/View/Filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,16 @@

function initialize(Twig_Environment $env)
{
$env->addFilter('img_path', new Twig_Filter_Function('\View\Filters\img_path'));
$env->addFilter(
'img_path', new Twig_Filter_Function('\View\Filters\img_path')
);
$env->addFilter(
'link', new Twig_Filter_Function(
'\View\Filters\link', array('is_safe' => array('html'))
'link',
new Twig_Filter_Function(
'\View\Filters\link',
array('is_safe' => array('html'))
)
);
$env->addFilter(
'format_date',
new Twig_Filter_Function('\View\Filters\format_date')
);
$env->addFilter(
'format_string', new Twig_Filter_Function('\View\Filters\format_string')
);
$env->addFilter('format_date', new Twig_Filter_Function('\View\Filters\format_date'));
$env->addFilter('format_string', new Twig_Filter_Function('\View\Filters\format_string'));
}

function img_path($suffix, $infix)
Expand Down
3 changes: 1 addition & 2 deletions app/src/View/Functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/
function initialize(Twig_Environment $env, Slim $app)
{
$env->addFunction(new Twig_SimpleFunction('urlFor', function ($routeName, $params=array()) use ($app) {
$env->addFunction(new Twig_SimpleFunction('urlFor', function ($routeName, $params = array()) use ($app) {
$url = $app->urlFor($routeName, $params);
return $url;
}));
Expand Down Expand Up @@ -58,4 +58,3 @@ function initialize(Twig_Environment $env, Slim $app)
})
);
}

Loading

0 comments on commit 374b254

Please sign in to comment.