Skip to content
This repository was archived by the owner on May 8, 2018. It is now read-only.

Commit 98911c2

Browse files
committed
Implementing sponsors list
1 parent cbfd4df commit 98911c2

21 files changed

+826
-8
lines changed

config/di-container/company.xml

+10
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
<service id="supporter.json.service" class="PHPSC\Conference\Application\Service\SupporterJsonService">
1010
<argument type="service" id="supporter.management.service" />
1111
<argument type="service" id="company.management.service" />
12+
<argument type="service" id="authentication.service" />
13+
</service>
14+
<service id="sponsor.app.service" class="PHPSC\Conference\Application\Service\SponsorManagementService">
15+
<argument type="service" id="sponsor.repository" />
1216
</service>
1317

1418
<service id="supporter.management.service" class="PHPSC\Conference\Domain\Service\SupporterManagementService">
@@ -26,6 +30,12 @@
2630
<service id="supporter.repository" factory-service="entityManager" factory-method="getRepository">
2731
<argument>PHPSC\Conference\Domain\Entity\Supporter</argument>
2832
</service>
33+
<service id="sponsorshipQuota.repository" factory-service="entityManager" factory-method="getRepository">
34+
<argument>PHPSC\Conference\Domain\Entity\SponsorshipQuota</argument>
35+
</service>
36+
<service id="sponsor.repository" factory-service="entityManager" factory-method="getRepository">
37+
<argument>PHPSC\Conference\Domain\Entity\Sponsor</argument>
38+
</service>
2939

3040
<service id="supporter.factory" class="PHPSC\Conference\Domain\Factory\SupporterFactory" />
3141
<service id="company.factory" class="PHPSC\Conference\Domain\Factory\CompanyFactory">

config/routes.xml

+2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727

2828
<route pattern="/supporters/*" class="\PHPSC\Conference\Application\Action\Supporters" />
2929
<route pattern="/supporter/(id)" class="\PHPSC\Conference\Application\Action\Supporter" />
30+
<route pattern="/sponsors/*" class="\PHPSC\Conference\Application\Action\Sponsors" />
31+
<route pattern="/sponsor/(id)" class="\PHPSC\Conference\Application\Action\Sponsor" />
3032

3133
<route pattern="/adm/credentialing" class="\PHPSC\Conference\Application\Action\Admin\Credentialing" />
3234
<route pattern="/adm/supporters" class="\PHPSC\Conference\Application\Action\Admin\Supporters" />

db-versions/Version20140706204940.php

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace DoctrineMigrations;
4+
5+
use Doctrine\DBAL\Migrations\AbstractMigration;
6+
use Doctrine\DBAL\Schema\Schema;
7+
8+
/**
9+
* Auto-generated Migration: Please modify to your needs!
10+
*/
11+
class Version20140706204940 extends AbstractMigration
12+
{
13+
public function up(Schema $schema)
14+
{
15+
// this up() migration is auto-generated, please modify it to your needs
16+
$this->abortIf($this->connection->getDatabasePlatform()->getName() != "mysql", "Migration can only be executed safely on 'mysql'.");
17+
18+
$this->addSql("CREATE TABLE sponsorship_quota (id INT AUTO_INCREMENT NOT NULL, title VARCHAR(45) NOT NULL, benefits LONGTEXT NOT NULL COMMENT '(DC2Type:json_array)', cost NUMERIC(8, 2) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB");
19+
}
20+
21+
public function down(Schema $schema)
22+
{
23+
// this down() migration is auto-generated, please modify it to your needs
24+
$this->abortIf($this->connection->getDatabasePlatform()->getName() != "mysql", "Migration can only be executed safely on 'mysql'.");
25+
26+
$this->addSql("DROP TABLE sponsorship_quota");
27+
}
28+
}

db-versions/Version20140706211615.php

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace DoctrineMigrations;
4+
5+
use Doctrine\DBAL\Migrations\AbstractMigration;
6+
use Doctrine\DBAL\Schema\Schema;
7+
8+
/**
9+
* Auto-generated Migration: Please modify to your needs!
10+
*/
11+
class Version20140706211615 extends AbstractMigration
12+
{
13+
public function up(Schema $schema)
14+
{
15+
// this up() migration is auto-generated, please modify it to your needs
16+
$this->abortIf($this->connection->getDatabasePlatform()->getName() != "mysql", "Migration can only be executed safely on 'mysql'.");
17+
18+
$this->addSql("ALTER TABLE company ADD details LONGTEXT DEFAULT NULL AFTER email");
19+
}
20+
21+
public function down(Schema $schema)
22+
{
23+
// this down() migration is auto-generated, please modify it to your needs
24+
$this->abortIf($this->connection->getDatabasePlatform()->getName() != "mysql", "Migration can only be executed safely on 'mysql'.");
25+
26+
$this->addSql("ALTER TABLE company DROP details");
27+
}
28+
}

db-versions/Version20140706212049.php

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
namespace DoctrineMigrations;
4+
5+
use Doctrine\DBAL\Migrations\AbstractMigration;
6+
use Doctrine\DBAL\Schema\Schema;
7+
8+
/**
9+
* Auto-generated Migration: Please modify to your needs!
10+
*/
11+
class Version20140706212049 extends AbstractMigration
12+
{
13+
public function up(Schema $schema)
14+
{
15+
// this up() migration is auto-generated, please modify it to your needs
16+
$this->abortIf($this->connection->getDatabasePlatform()->getName() != "mysql", "Migration can only be executed safely on 'mysql'.");
17+
18+
$this->addSql("CREATE TABLE sponsor (id INT AUTO_INCREMENT NOT NULL, company_id INT NOT NULL, event_id INT NOT NULL, quota_id INT NOT NULL, creation_time DATETIME NOT NULL, INDEX IDX_818CC9D4979B1AD6 (company_id), INDEX IDX_818CC9D471F7E88B (event_id), INDEX IDX_818CC9D454E2C62F (quota_id), UNIQUE INDEX sponsor_index0 (company_id, event_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB");
19+
$this->addSql("ALTER TABLE sponsor ADD CONSTRAINT FK_818CC9D4979B1AD6 FOREIGN KEY (company_id) REFERENCES company (id)");
20+
$this->addSql("ALTER TABLE sponsor ADD CONSTRAINT FK_818CC9D471F7E88B FOREIGN KEY (event_id) REFERENCES event (id)");
21+
$this->addSql("ALTER TABLE sponsor ADD CONSTRAINT FK_818CC9D454E2C62F FOREIGN KEY (quota_id) REFERENCES sponsorship_quota (id)");
22+
}
23+
24+
public function down(Schema $schema)
25+
{
26+
// this down() migration is auto-generated, please modify it to your needs
27+
$this->abortIf($this->connection->getDatabasePlatform()->getName() != "mysql", "Migration can only be executed safely on 'mysql'.");
28+
29+
$this->addSql("DROP TABLE sponsor");
30+
}
31+
}

public/css/main.css

+55
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,59 @@ footer div.social_links a {
4040
width: 24px !important;
4141
height: 24px !important;
4242
background: transparent url(../img/social-icons/glyphicons_social_04_yahoo.png) no-repeat center center;
43+
}
44+
45+
46+
div.sponsors {
47+
padding-top: 10px;
48+
text-align: center;
49+
}
50+
51+
div.sponsors h4 {
52+
display:block;
53+
font-size: 140%;
54+
margin-top: 40px;
55+
margin-bottom: 30px;
56+
margin-left: 12px;
57+
}
58+
59+
div.sponsors h5 {
60+
font-weight: bold;
61+
}
62+
63+
div.sponsors.platinum h4 {
64+
background-color: #e5e4e2;
65+
color: #b7b4ae;
66+
}
67+
68+
div.sponsors.platinum div {
69+
text-align: left;
70+
}
71+
72+
div.sponsors.platinum div > div:first-child {
73+
line-height: 120px;
74+
}
75+
76+
div.sponsors.gold h4 {
77+
background-color: #ffd700;
78+
}
79+
80+
div.sponsors.gold > div {
81+
line-height: 100px;
82+
}
83+
84+
div.sponsors.silver h4 {
85+
background-color: #c0c0c0;
86+
}
87+
88+
div.sponsors.silver > div {
89+
line-height: 80px;
90+
}
91+
92+
div.sponsors.brass h4 {
93+
background-color: #b5a642;
94+
}
95+
96+
div.sponsors.brass > div {
97+
line-height: 60px;
4398
}

public/js/sponsors.list.js

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
$(document).ready(function () {
2+
var quotas = [
3+
{id: 1, label: "Platina", rowCss: "platinum", perRow: 2, logo: {w: 250, h: 120}, details: true},
4+
{id: 2, label: "Ouro", rowCss: "gold", perRow: 4, logo: {w: 200, h: 100}, details: false},
5+
{id: 3, label: "Prata", rowCss: "silver", perRow: 6, logo: {w: 160, h: 80}, details: false},
6+
{id: 4, label: "Bronze", rowCss: "brass", perRow: 12, logo: {w: 80, h: 60}, details: false}
7+
];
8+
9+
findSponsors(0);
10+
11+
function findSponsors(i)
12+
{
13+
if (i >= quotas.length) {
14+
$('div.sponsors h4')[0].style.marginTop = 0;
15+
$('#sponsorsContainer').removeClass('hide');
16+
return;
17+
}
18+
19+
var quota = quotas[i];
20+
21+
$.ajax(
22+
{
23+
url: baseUrl + 'sponsors',
24+
dataType: 'json',
25+
data: {'quota': quota.id},
26+
type: 'GET',
27+
success: function (sponsors) {
28+
renderSponsors(quota, sponsors);
29+
findSponsors(i + 1);
30+
}
31+
}
32+
);
33+
}
34+
35+
function renderSponsors(quota, sponsors)
36+
{
37+
if (sponsors.length == 0) {
38+
return ;
39+
}
40+
41+
var element = $('<div class="row sponsors ' + quota.rowCss + '"></div>');
42+
element.append('<h4 class="label label-default">' + quota.label + '</h4>')
43+
44+
for (var i = 0; i < sponsors.length; ++i) {
45+
var sponsor = sponsors[i];
46+
47+
if (i % quota.perRow == 0 && element.children().length > 0) {
48+
$('#sponsorsContainer').append(element);
49+
element = $('<div class="row sponsors ' + quota.rowCss + '"></div>');
50+
}
51+
52+
element.append(
53+
'<div class="col-md-' + (12 / quota.perRow) + '">' + getSponsorContent(quota, sponsor) + '</div>'
54+
);
55+
}
56+
57+
if (element.children().length > 0) {
58+
$('#sponsorsContainer').append(element);
59+
}
60+
}
61+
62+
function getSponsorContent(quota, sponsor)
63+
{
64+
var link = '<a href="' + sponsor.website + '" target="_blank" title="' + sponsor.name + '">'
65+
+ '<img src="' + baseUrl + 'sponsor/' + sponsor.id + '?w=' + quota.logo.w + '&h='
66+
+ quota.logo.h + '" alt="' + sponsor.name + '">'
67+
+ '</a>';
68+
69+
if (!quota.details) {
70+
return link;
71+
}
72+
73+
return '<div class="col-md-6" style="text-align: center">' + link + '</div>'
74+
+ '<div class="col-md-6"><h5>' + sponsor.name + '</h5><p>' + sponsor.details + '</p></div>';
75+
}
76+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
namespace PHPSC\Conference\Application\Action;
3+
4+
use Lcobucci\ActionMapper2\Routing\Annotation\Route;
5+
use Lcobucci\ActionMapper2\Routing\Controller;
6+
use PHPSC\Conference\Domain\Entity\Sponsor as SponsorEntity;
7+
8+
/**
9+
* @author Luís Otávio Cobucci Oblonczyk <[email protected]>
10+
*/
11+
class Sponsor extends Controller
12+
{
13+
/**
14+
* @Route("/", methods={"GET"}, contentType={"image/*"})
15+
* @param int $id
16+
*/
17+
public function displayLogo($id)
18+
{
19+
/* @var $sponsor SponsorEntity */
20+
$sponsor = $this->get('sponsor.repository')->find($id);
21+
22+
return $this->get('image.rendering.service')->resize(
23+
$sponsor->getCompany()->getLogo(),
24+
$this->request->query->get('w'),
25+
$this->request->query->get('h'),
26+
$this->request,
27+
$this->response
28+
);
29+
}
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
namespace PHPSC\Conference\Application\Action;
3+
4+
use Lcobucci\ActionMapper2\Routing\Annotation\Route;
5+
use Lcobucci\ActionMapper2\Routing\Controller;
6+
use PHPSC\Conference\Domain\Service\EventManagementService;
7+
use PHPSC\Conference\Application\Service\SponsorManagementService;
8+
use PHPSC\Conference\Domain\Repository\SponsorshipQuotaRepository;
9+
use Lcobucci\ActionMapper2\Errors\BadRequestException;
10+
11+
class Sponsors extends Controller
12+
{
13+
/**
14+
* @Route("/", methods={"GET"}, contentType={"application/json"})
15+
*/
16+
public function showSponsors()
17+
{
18+
$event = $this->getEventManager()->findCurrentEvent();
19+
$quota = $this->getQuotaRepository()->find($this->request->query->get('quota', 1));
20+
21+
if ($quota === null) {
22+
throw new BadRequestException('Invalid quota');
23+
}
24+
25+
$sponsors = $this->getSponsorService()->findByQuota($event, $quota);
26+
27+
return json_encode($sponsors);
28+
}
29+
30+
/**
31+
* @return SponsorManagementService
32+
*/
33+
protected function getSponsorService()
34+
{
35+
return $this->get('sponsor.app.service');
36+
}
37+
38+
/**
39+
* @return EventManagementService
40+
*/
41+
protected function getEventManager()
42+
{
43+
return $this->get('event.management.service');
44+
}
45+
46+
/**
47+
* @return SponsorshipQuotaRepository
48+
*/
49+
protected function getQuotaRepository()
50+
{
51+
return $this->get('sponsorshipQuota.repository');
52+
}
53+
}

0 commit comments

Comments
 (0)