Skip to content

Commit

Permalink
Merge pull request #2 from PROCERGS/refactoring
Browse files Browse the repository at this point in the history
Removed NFG Badges
  • Loading branch information
guilhermednt committed Feb 19, 2016
2 parents fe19e8c + cd8e274 commit 177241d
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 102 deletions.
80 changes: 4 additions & 76 deletions Event/BadgesSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
use LoginCidadao\BadgesControlBundle\Model\AbstractBadgesEventSubscriber;
use LoginCidadao\BadgesControlBundle\Event\EvaluateBadgesEvent;
use LoginCidadao\BadgesControlBundle\Event\ListBearersEvent;
use LoginCidadao\BadgesControlBundle\Model\BadgeInterface;
use LoginCidadao\BadgesBundle\Model\Badge;
use Symfony\Component\Translation\TranslatorInterface;
use Doctrine\ORM\EntityManager;
use LoginCidadao\BadgesControlBundle\Model\BadgeInterface;

class BadgesSubscriber extends AbstractBadgesEventSubscriber
{
Expand All @@ -33,19 +33,12 @@ public function __construct(TranslatorInterface $translator,
$this->registerBadge('valid_email',
$translator->trans("$namespace.valid_email.description", array(),
'badges'), array('counter' => 'countValidEmail'));
$this->registerBadge('nfg_access_lvl',
$translator->trans("$namespace.nfg_access_lvl.description", array(),
'badges'), array('counter' => 'countNfgAccessLvl'));
$this->registerBadge('voter_registration',
$translator->trans("$namespace.voter_registration.description",
array(), 'badges'), array('counter' => 'countVoterRegistration'));
}

public function onBadgeEvaluate(EvaluateBadgesEvent $event)
{
$this->checkCpf($event);
$this->checkEmail($event);
$this->checkNfg($event);
}

public function onListBearers(ListBearersEvent $event)
Expand All @@ -70,9 +63,7 @@ public function onListBearers(ListBearersEvent $event)
protected function checkCpf(EvaluateBadgesEvent $event)
{
$person = $event->getPerson();
$nfg = !method_exists($person, 'getNfgAccessToken') ||
(strlen($person->getNfgAccessToken()) > 0);
if (is_numeric($person->getCpf()) && $nfg) {
if (is_numeric($person->getCpf())) {
$event->registerBadge($this->getBadge('has_cpf', true));
}
}
Expand All @@ -85,19 +76,6 @@ protected function checkEmail(EvaluateBadgesEvent $event)
}
}

protected function checkNfg(EvaluateBadgesEvent $event)
{
$person = $event->getPerson();
if (method_exists($person, 'getNfgProfile') && $person->getNfgProfile()) {
$event->registerBadge($this->getBadge('nfg_access_lvl',
$person->getNfgProfile()->getAccessLvl()));

if ($person->getNfgProfile()->getVoterRegistrationSit() > 0) {
$event->registerBadge($this->getBadge('voter_registration', true));
}
}
}

protected function getBadge($name, $data)
{
if (array_key_exists($name, $this->getAvailableBadges())) {
Expand All @@ -109,13 +87,10 @@ protected function getBadge($name, $data)

protected function countHasCpf()
{
return $this->em->getRepository('PROCERGSLoginCidadaoCoreBundle:PersonMeuRS')
->createQueryBuilder('m')
return $this->em->getRepository('LoginCidadaoCoreBundle:Person')
->createQueryBuilder('p')
->select('COUNT(p)')
->join('LoginCidadaoCoreBundle:Person', 'p', 'WITH',
'm.person = p')
->andWhere('p.cpf IS NOT NULL')
->andWhere('m.nfgAccessToken IS NOT NULL')
->getQuery()->getSingleScalarResult();
}

Expand All @@ -128,51 +103,4 @@ protected function countValidEmail()
->andWhere('p.emailConfirmedAt IS NOT NULL')
->getQuery()->getSingleScalarResult();
}

protected function countNfgAccessLvl($filterData = null)
{
$empty = array(
"1" => 0,
"2" => 0,
"3" => 0
);

$query = $this->em->getRepository('PROCERGSLoginCidadaoCoreBundle:PersonMeuRS')
->createQueryBuilder('m')
->select('n.accessLvl, COUNT(n) total')
->join('PROCERGSLoginCidadaoCoreBundle:NfgProfile', 'n', 'WITH',
'm.nfgProfile = n')
->groupBy('n.accessLvl');

if ($filterData !== null) {
$query->andWhere('n.accessLvl = :filterData')
->setParameters(compact('filterData'));
}

$count = $query->getQuery()->getResult();
if (!empty($count)) {
$original = $count;
$count = $empty;
foreach ($original as $line) {
$level = $line['accessLvl'];
$count[$level] = $line['total'];
}
return $count;
} else {
return $empty;
}
}

protected function countVoterRegistration()
{
return $this->em->getRepository('PROCERGSLoginCidadaoCoreBundle:PersonMeuRS')
->createQueryBuilder('m')
->select('COUNT(p)')
->join('PROCERGSLoginCidadaoCoreBundle:NfgProfile', 'n', 'WITH',
'm.nfgProfile = n')
->join('LoginCidadaoCoreBundle:Person', 'p', 'WITH',
'm.person = p')
->andWhere('n.voterRegistrationSit > 0')
->getQuery()->getSingleScalarResult();
}
}
18 changes: 0 additions & 18 deletions Resources/public/css/badges.css
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,3 @@
content: "@";
font-size: 30px;
}

.badges-list .badge-nfg_access_lvl {
background-color: #FAB60F;
border: solid 1px #D58D8D;
}

.badges-list .badge-nfg_access_lvl:before {
content: "NFG";
}

.badges-list .badge-voter_registration {
background-color: #C3EC87;
border: solid 1px #A0BBA6;
}

.badges-list .badge-voter_registration:before {
content: "TSE";
}
4 changes: 0 additions & 4 deletions Resources/translations/badges.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,3 @@ login-cidadao.has_cpf.title: Valid CPF
login-cidadao.has_cpf.description: Badge given to those who informed their CPF.
login-cidadao.valid_email.title: Confirmed Email
login-cidadao.valid_email.description: Badge given to those who confirmed their email address clicking on the link sent to the given email.
login-cidadao.nfg_access_lvl.title: Nota Fiscal Gaúcha's Level
login-cidadao.nfg_access_lvl.description: Badge given to those who have their Nota Fiscal Gaúcha account linked to Citizen Login.
login-cidadao.voter_registration.title: Valid Voter Registration
login-cidadao.voter_registration.description: Badge given to those who typed their voter registration.
4 changes: 0 additions & 4 deletions Resources/translations/badges.pt_BR.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,3 @@ login-cidadao.has_cpf.title: CPF Válido
login-cidadao.has_cpf.description: Medalha concedida a quem informou seu CPF.
login-cidadao.valid_email.title: Email Confirmado
login-cidadao.valid_email.description: Medalha concedida a quem confirmou seu endereço de email através do link enviado ao email de cadastro.
login-cidadao.nfg_access_lvl.title: Nível na Nota Fiscal Gaúcha
login-cidadao.nfg_access_lvl.description: Medalha concedida a quem tem sua conta da NFG vinculada ao Login Cidadão.
login-cidadao.voter_registration.title: Título de Eleitor Válido
login-cidadao.voter_registration.description: Medalha concedida a quem informou seu Título de Eleitor.

0 comments on commit 177241d

Please sign in to comment.