Skip to content

Commit

Permalink
Merge pull request #23 from phpminds/feature/past-events
Browse files Browse the repository at this point in the history
Feature/past events
  • Loading branch information
pavlakis committed Dec 23, 2015
2 parents 25ac982 + 1e0fb63 commit 2201536
Show file tree
Hide file tree
Showing 15 changed files with 262 additions and 87 deletions.
8 changes: 1 addition & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,4 @@ language: php
php: '7.0'
install: composer install
script: phpunit --configuration tests/phpunit/phpunit.xml
addons:
ssh_known_hosts:phpminds.org
deploy:
provider: script
script: scripts/deploy.sh
on:
branch: develop

35 changes: 12 additions & 23 deletions app/src/Action/CreateEventAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,25 +83,10 @@ public function dispatch(Request $request, Response $response, $args)
$venues = $this->eventService->getVenues();
$supporters = $this->eventManager->getSupporters();

$eventInfo = ['title' => '', 'description' => ''];

if ($request->getParam('meetup_id')) {
$event = $this->eventService->getEventById((int)$request->getParam('meetup_id'));

if(!empty($event)) {

if (!empty($this->eventManager->getDetailsByMeetupID($request->getParam('meetup_id')))) {
$this->flash->addMessage('event', 'Event already exists. Check its status.');
return $response->withStatus(302)->withHeader('Location', 'event-details?meetup_id=' . $request->getParam('meetup_id'));
}

$eventInfo['title'] = $event['subject'];
$eventInfo['description'] = $event['description'];
$eventInfo['venue_id'] = $event['venue_id'];
$date = \DateTime::createFromFormat('F jS Y', $event['date']);
$eventInfo['date'] = $date->format("d/m/Y");
}

$eventInfo = $this->eventService->getInfoByMeetupID($request->getParam('meetup_id'));
if ($eventInfo['event_exists']) {
$this->flash->addMessage('event', 'Event already exists. Check its status.');
return $response->withStatus(302)->withHeader('Location', 'event-details?meetup_id=' . $request->getParam('meetup_id'));
}

$errors = $this->flash->getMessage('event') ?? [];
Expand Down Expand Up @@ -131,15 +116,19 @@ public function dispatch(Request $request, Response $response, $args)
);

try {
$createEventInfo = $this->eventService->createMainEvents($event, $this->auth->getUserId(), $request->getParam('meetup_id'));
$createEventInfo = $this->eventService->createMainEvents(
$event,
$this->auth->getUserId(),
$request->getParam('meetup_id')
);
} catch (\Exception $e) {
throw $e;
}

if ((int)$createEventInfo['joindin'] === 202) {
if ((int)$createEventInfo['joindin_status'] === 202) {
// event pending. Save to DB and show message to user
$this->flash->addMessage('event', 'JoindIn Event is pending. Wait for approval before creating a Talk.');
} else if ((int)$createEventInfo['joindin'] !== 201) {
$this->flash->addMessage('event', 'JoindIn Event is pending. Once approved, talk will be created automatically.');
} else if ((int)$createEventInfo['joindin_status'] !== 201) {
$this->logger->debug("Could not create Joindin event. Please try again.");
$this->flash->addMessage('event', 'Could not create Joindin event. Please try again.');
}
Expand Down
5 changes: 4 additions & 1 deletion app/src/Action/HomeAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,13 @@ public function dispatch($request, $response, $args)
$this->view->getEnvironment()->addFilter($filter);


$previousEvents= $this->eventService->getPastEvents();



$resWithETag = $this->cache->withETag($response, $event['id']);

$this->view->render($response, 'home.twig', ['event' => $event]);
$this->view->render($response, 'home.twig', ['event' => $event,'previousEvents'=>$previousEvents]);
return $resWithETag;
}
}
11 changes: 8 additions & 3 deletions app/src/Factory/EventFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@

use App\Model\Event\Entity\Talk;
use App\Model\Event\Event;
use Slim\Http\Request;

class EventFactory
{
public static function getByRequest($request, $speaker, $venue, $supporter, $title, $description)
public static function getByRequest(Request $request, $speaker, $venue, $supporter, $title, $description)
{
$talk = new Talk(
strip_tags($request->getParam('talk_title'), '<p><a><br>'),
Expand All @@ -17,8 +18,12 @@ public static function getByRequest($request, $speaker, $venue, $supporter, $tit

$event = new Event(
$talk,
\DateTime::createFromFormat("Y-m-d", $request->getParam('start_date'))->format('d/m/Y'),
$request->getParam('start_time') < 10 ? '0' . $request->getParam('start_time') : $request->getParam('start_time'),
\DateTime::createFromFormat(
"d/m/Y H:i",
$request->getParam('start_date') . ' '
. ($request->getParam('start_time') < 10 ? '0' . $request->getParam('start_time') : $request->getParam('start_time'))

),
$venue,
$supporter
);
Expand Down
4 changes: 2 additions & 2 deletions app/src/Model/Event/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ class Event
private $supporter;


public function __construct(Talk $talk, $startDate, $startTime, Venue $venue, Supporter $supporter)
public function __construct(Talk $talk, \DateTime $date, Venue $venue, Supporter $supporter)
{
$this->talk = $talk;
$this->date = \DateTime::createFromFormat("d/m/Y H:i", $startDate . ' ' . $startTime);
$this->date = $date;
$this->venue = $venue;
$this->supporter = $supporter;
}
Expand Down
15 changes: 9 additions & 6 deletions app/src/Model/MeetupEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ public function __construct(MeetupConfig $config)
$this->publishStatus = $config->publishStatus;
}

public function getUrl($action = 'events', $auth = true)
public function getUrl($action = 'events', $auth = true,$additionalApiParams = ['status'=>'past,upcoming'])
{
$authStr = '';
if ($auth) {
$authStr = $this->getAuthString();
$authStr = $this->getAuthString($additionalApiParams);
}

return sprintf($this->baseUrl .'/%s/' . $authStr, $action);
return $this->baseUrl."/".urlencode($action)."/".$authStr;
//return sprintf($this->baseUrl .'/%s/' . $authStr, $action);
}

public function setEventID($eventID)
Expand All @@ -48,9 +48,12 @@ public function getGroupUrlName()
return $this->groupUrlName;
}

public function getAuthString()
public function getAuthString($params = [])
{
return '?group_urlname='. $this->groupUrlName .'&key=' . $this->apiKey;
$params = array_merge(['group_urlname'=>$this->groupUrlName,"key"=>$this->apiKey,"order"=>"time","desc"=>"true"],$params);
$queryString = http_build_query($params);

return '?'.$queryString;
}

public function getEventUrl()
Expand Down
58 changes: 51 additions & 7 deletions app/src/Service/EventsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,18 @@ public function getLatestEvent()
return $this->meetupService->getLatestEvent();
}

/**
* Get all events except for latest.
* @return array
*/
public function getPastEvents()
{
return $this->meetupService->getPastEvents();
}
/**
* @param $eventID
* @return array
*/
public function getEventById($eventID)
{
return $this->meetupService->getEventById($eventID);
Expand All @@ -73,6 +85,35 @@ public function getAll()
return $this->meetupService->getAll();
}

/**
* @param int $meetupID
* @return array
*/
public function getInfoByMeetupID($meetupID = null)
{
$eventInfo = ['title' => '', 'description' => '', 'event_exists'];

if (!is_null($meetupID)) {
$event = $this->getEventById((int)$meetupID);

if(!empty($event)) {

if (!empty($this->eventManager->getDetailsByMeetupID($meetupID))) {
$eventInfo['event_exists'] = true;
} else {
$eventInfo['title'] = $event['subject'];
$eventInfo['description'] = $event['description'];
$eventInfo['venue_id'] = $event['venue_id'];
$date = \DateTime::createFromFormat('F jS Y', $event['date']);
$eventInfo['date'] = $date->format("d/m/Y");
}
}
}

return $eventInfo;

}

/**
* @param $meetupEvents
* @param $speakers
Expand All @@ -94,7 +135,7 @@ public function mergeEvents(&$meetupEvents, $speakers, $venues)
/** @var Speaker $speaker */
$speaker = $speakers[$event->speaker_id];
$meetupEvents[$event->meetup_id]['speaker'] = $speaker->getFirstName() . ' '
. $speaker->getLastName() . ' (' . $speaker->getTwitter() . ')';
. $speaker->getLastName() . ' (' . $speaker->getTwitter() . ')';
} else {
$meetupEvents[$event->meetup_id]['speaker'] = '-';
}
Expand All @@ -110,7 +151,7 @@ public function mergeEvents(&$meetupEvents, $speakers, $venues)
*/
public function getVenues()
{
return $this->meetupService->getVenues();
return $this->meetupService->getVenues();
}

/**
Expand All @@ -126,7 +167,7 @@ public function createMainEvents(Event $event, $userID, $meetupID = null)
{
$this->createEvent($event);

if (!is_null($meetupID)) {
if (is_null($meetupID)) {
if ((int)$this->createMeetup()->getStatusCode() !== 201) {
throw new \Exception('Could not create meetup event.');
}
Expand All @@ -136,16 +177,15 @@ public function createMainEvents(Event $event, $userID, $meetupID = null)
}

try {
$createJoindInEvent = $this->createJoindinEvent($userID);
$joindinEvent = $this->createJoindinEvent($userID);
} catch (\Exception $e) {
throw $e;
}

$eventEntity = $this->eventService->updateEvents();
$eventEntity = $this->updateEvents();

return [
'meetup' => $this->createMeetup()->getStatusCode(),
'joindin' => $createJoindInEvent->getStatusCode(),
'joindin_status' => $joindinEvent->getStatusCode(),
'meetup_id' => $eventEntity->getMeetupID()
];
}
Expand Down Expand Up @@ -226,6 +266,10 @@ public function getEventInfo($meetupID) : array
return $this->eventManager->getByMeetupID($meetupID)[0] ?: [];
}

/**
* @param $userID
* @return string
*/
public function manageApprovedEvents($userID)
{

Expand Down
19 changes: 19 additions & 0 deletions app/src/Service/MeetupService.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public function getMeetupEvent()
protected function getEvents()
{
$eventUrl = $this->meetupEvent->getEventUrl();

$response = $this->httpClient->get($eventUrl);

return json_decode($response->getBody()->getContents(), true);
Expand Down Expand Up @@ -64,6 +65,24 @@ public function getLatestEvent()
return $this->meetupEvent->formatResponse($events['results'][0] ?? []);
}

/**
* get all events apart form last one in array
* @return array
*/
public function getPastEvents()
{
$pastEvents = [];

$events = $this->getEvents();

array_shift($events["results"]);

foreach($events["results"] as $event){
$pastEvents[] = $this->meetupEvent->formatResponse($event);

}
return $pastEvents ?? [];
}
/**
* @param Event $event
* @return \Psr\Http\Message\ResponseInterface
Expand Down
6 changes: 1 addition & 5 deletions app/templates/content/past-events.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,2 @@
Now our first event has finally happened, thanks to all those that came, we can publish
information about previous events. Other details to follow.

**In December 2015 we had Rob Allen speak on Building an API with Slim 3.**

Please leave your feedback on joind.in at https://joind.in/16610
information about previous events.
6 changes: 5 additions & 1 deletion app/templates/home.twig
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@

{{ "past-events" | content | raw }}


<ul>
{% for previousEvent in previousEvents %}
<li>{{ previousEvent.subject|e }} on {{ previousEvent.date }}</li>
{% endfor %}
</ul>

</div>

Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
],
"autoload": {
"psr-4": {
"App\\Tests\\" : "tests/phpunit",
"App\\": "app/src"
}
},
Expand Down
2 changes: 1 addition & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 2201536

Please sign in to comment.