Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Sponsors page #50

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/AppKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public function registerBundles()
#AmsterdamPHP
new AmsterdamPHP\Bundle\MeetupBundle\AmsterdamPHPMeetupBundle(),
new AmsterdamPHP\Bundle\SiteBundle\AmsterdamPHPSiteBundle(),
new AmsterdamPHP\Bundle\SponsorBundle\AmsterdamPHPSponsorBundle(),
);

if (in_array($this->getEnvironment(), array('dev', 'test'))) {
Expand Down
28 changes: 28 additions & 0 deletions app/DoctrineMigrations/Version20131218230956.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace Application\Migrations;

use Doctrine\DBAL\Migrations\AbstractMigration;
use Doctrine\DBAL\Schema\Schema;

/**
* Auto-generated Migration: Please modify to your needs!
*/
class Version20131218230956 extends AbstractMigration
{
public function up(Schema $schema)
{
// this up() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() != "mysql", "Migration can only be executed safely on 'mysql'.");

$this->addSql("CREATE TABLE sponsor (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(255) NOT NULL, details LONGTEXT NOT NULL, url VARCHAR(255) NOT NULL, imageUrl VARCHAR(255) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB");
}

public function down(Schema $schema)
{
// this down() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() != "mysql", "Migration can only be executed safely on 'mysql'.");

$this->addSql("DROP TABLE sponsor");
}
}
5 changes: 5 additions & 0 deletions app/config/routing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ amsterdam_php_site:
type: annotation
prefix: /

amsterdam_php_sponsors:
resource: "@AmsterdamPHPSponsorBundle/Controller/"
type: annotation
prefix: /

#amsterdam_php_meetup:
# resource: "@AmsterdamPHPMeetupBundle/Controller/"
# type: annotation
Expand Down
14 changes: 14 additions & 0 deletions features/sponsor-showcase.feature
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,22 @@ Feature:
I need to see a showcase of current sponsors and see a callout to become one

Scenario: See a call to action

Scenario: See list of sponsors on homepage
Given Meetup API returns "5" sponsors
# And Meetup API returns "10" photos
# And Pre-Selection is empty
When I go to "/"
Then the response status code should be 200
Then I should see an ".sponsor-box" element
And I should see 5 ".sponsor-list li" elements

Scenario: See list of sponsors on separate page
Given Meetup API returns "5" sponsors
When I go to "/sponsors"
Then I should see an ".sponsor-list" element
And I should see 5 ".sponsor-list li" elements

Scenario: Inactive sponsor is grayscaled but listed
Scenario: Suspended sponsor is ot listed

Expand Down
35 changes: 35 additions & 0 deletions src/AmsterdamPHP/Behat/MeetupContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,29 @@ protected function getPhotoArray($num, $prefix = 'regular')
return $photos;
}

/**
* @param $num
* @param string $prefix
* @return array
*/
protected function getSponsorArray($num)
{
$sponsors = [];
for ($i = 0; $i < $num; $i++) {
$sponsors[$i] = [
'details' => "O'Reilly is one of the largest publishers of Tech-related books",
'image_url' => 'http://photos2.meetupstatic.com/photos/sponsor/c/f/4/6/iab120x90_1433062.jpeg',
'redeem' => "Use DSUG discount code at O'Reilly's online store",
'name' => "O'Reilly",
'perk_url' => 'http://www.meetup.com/sponsor/OReilly-73300/',
'url' => 'http://www.oreilly.com/store/',
'info' => '40% off Print books',
];
}

return $sponsors;
}

/**
* @Given /^Meetup API returns upcoming events with:$/
*/
Expand Down Expand Up @@ -182,6 +205,18 @@ public function defineStandardResponseSet()

$cacheMock = $this->mocker->mockService('snc_redis.cache', Client::class);
$cacheMock->shouldReceive('get')->with('meetup.api.photos.all')->andReturn(serialize($this->getPhotoArray(10)));

$cacheMock = $this->mocker->mockService('snc_redis.cache', Client::class);
$cacheMock->shouldReceive('get')->with('meetup.api.sponsors.all')->andReturn(serialize($this->getSponsorArray(10)));
}

/**
* @Given /^Meetup API returns "([^"]*)" sponsor[s?]$/
*/
public function meetupApiReturnsSponsors($number)
{
$cacheMock = $this->mocker->mockService('snc_redis.cache', Client::class);
$cacheMock->shouldReceive('get')->with('meetup.api.sponsors.all')->andReturn(serialize($this->getSponsorArray($number)));
}
}

22 changes: 22 additions & 0 deletions src/AmsterdamPHP/Bundle/MeetupBundle/Service/SponsorService.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,35 @@ public function getAllSponsors()
$group = array_shift($groups);
$sponsors = $group['sponsors'];

// Inject sponsor id to each sponsor
foreach ($sponsors as $key => $sponsor) {
$sluggableText = $sponsor['name'];
$urlized = strtolower( trim( preg_replace("/[^a-zA-Z0-9\/_|+ -]/", '', iconv('UTF-8', 'ASCII//TRANSLIT', $sluggableText) ), '-' ) );
$urlized = preg_replace("/[\/_|+ -]+/", '-', $urlized);

$sponsors[$key]['id'] = $urlized;
}

//Cache resource
$this->getCache()->set($cacheKey, base64_encode(serialize($sponsors)));
$this->getCache()->expireat($cacheKey, strtotime('+24 hours'));

return $sponsors;
}

public function getSponsor($id)
{
$sponsors = $this->getAllSponsors();

foreach ($sponsors as $sponsor) {
if ($sponsor['id'] == $id) {
return $sponsor;
}
}

throw new Exception('Sponsor not found');
}

/**
* @return \DMS\Service\Meetup\AbstractMeetupClient
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<div class="row sponsor-box">
<div class="col-md-12 col-lg-12">
<h2>SPONSORS</h2>
<a href="{{ path('amsphp_sponsors') }}"><h2>SPONSORS</h2></a>
<ul class="sponsor-list bxslider">

{% for sponsor in sponsors %}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace AmsterdamPHP\Bundle\SponsorBundle;

use Symfony\Component\HttpKernel\Bundle\Bundle;

class AmsterdamPHPSponsorBundle extends Bundle
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

namespace AmsterdamPHP\Bundle\SponsorBundle\Controller;

use AmsterdamPHP\Bundle\MeetupBundle\Service\SponsorService;
use AmsterdamPHP\Bundle\SponsorBundle\Repository\SponsorRepository;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;

/**
* Class DefaultController
*
* @package AmsterdamPHP\Bundle\SponsorBundle\Controller
* @Route("/sponsors")
*/
class DefaultController extends Controller
{
/**
* @Route("/", name="amsphp_sponsors")
* @Template()
*/
public function indexAction()
{
// $sponsorService = $this->get('meetup.sponsors');
// $sponsors = $sponsorService->getRandomSponsors();

/** @var SponsorRepository $repository */
$repository = $this->getDoctrine()->getRepository('AmsterdamPHPSponsorBundle:Sponsor');
$sponsors = $repository->findAll();

return [
'sponsors' => $sponsors
];
}

/**
* @Route("/{id}", name="amsphp_sponsor")
* @Template()
*/
public function detailAction($id)
{
/** @var SponsorService $sponsorService */
$sponsorService = $this->get('meetup.sponsors');
$sponsor = $sponsorService->getSponsor($id);

return [
'sponsor' => $sponsor,
];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace AmsterdamPHP\Bundle\SponsorBundle\DependencyInjection;

use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\Loader;

/**
* This is the class that loads and manages your bundle configuration
*
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html}
*/
class AmsterdamPHPSponsorExtension extends Extension
{
/**
* {@inheritDoc}
*/
public function load(array $configs, ContainerBuilder $container)
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);

$loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.xml');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace AmsterdamPHP\Bundle\SponsorBundle\DependencyInjection;

use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;

/**
* This is the class that validates and merges configuration from your app/config files
*
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html#cookbook-bundles-extension-config-class}
*/
class Configuration implements ConfigurationInterface
{
/**
* {@inheritDoc}
*/
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('amsterdam_php_sponsor');

// Here you should define the parameters that are allowed to
// configure your bundle. See the documentation linked above for
// more information on that topic.

return $treeBuilder;
}
}
Loading