Skip to content

Commit

Permalink
Fixes #296
Browse files Browse the repository at this point in the history
  • Loading branch information
guilhermednt committed Dec 2, 2015
1 parent 412a94b commit 4936076
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 17 deletions.
26 changes: 14 additions & 12 deletions src/LoginCidadao/StatsBundle/Entity/StatisticsRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,44 +16,46 @@
class StatisticsRepository extends EntityRepository
{

public function findStatsByIndexKeyDate($index, $key = null,
public function findStatsByIndexKeyDate($index, $keys = null,
\DateTime $afterDate = null)
{
$query = $this->getFindStatsByIndexKeyDateQuery($index, $key, $afterDate);
$query = $this->getFindStatsByIndexKeyDateQuery($index, $keys,
$afterDate);

return $query->getQuery()->getResult();
}

public function findIndexedStatsByIndexKeyDate($index, $key = null,
public function findIndexedStatsByIndexKeyDate($index, $keys = null,
\DateTime $afterDate = null)
{
$data = $this->findStatsByIndexKeyDate($index, $key, $afterDate);
$data = $this->findStatsByIndexKeyDate($index, $keys, $afterDate);

return $this->indexResults($data);
}

public function findIndexedUniqueStatsByIndexKeyDate($index, $key = null,
public function findIndexedUniqueStatsByIndexKeyDate($index, $keys = null,
\DateTime $afterDate = null)
{
$query = $this->getFindStatsByIndexKeyDateQuery($index, $key, $afterDate);
$query = $this->getFindStatsByIndexKeyDateQuery($index, $keys,
$afterDate);
$this->applyGreatestNPerGroupDate($query);
$data = $query->getQuery()->getResult();

return $this->indexResults($data);
}

public function findIndexedUniqueStatsByIndexKeyDays($index, $key = null,
public function findIndexedUniqueStatsByIndexKeyDays($index, $keys = null,
$days = null)
{
$query = $this->getFindStatsByIndexKeyDateQuery($index, $key, null,
$query = $this->getFindStatsByIndexKeyDateQuery($index, $keys, null,
$days);
$this->applyGreatestNPerGroupDate($query);
$data = $query->getQuery()->getResult();

return $this->indexResults($data);
}

public function getFindStatsByIndexKeyDateQuery($index, $key = null,
public function getFindStatsByIndexKeyDateQuery($index, $keys = null,
\DateTime $afterDate = null,
$days = null)
{
Expand All @@ -62,9 +64,9 @@ public function getFindStatsByIndexKeyDateQuery($index, $key = null,
->setParameter('index', $index)
;

if ($key !== null) {
$query->andWhere('s.key = :key')
->setParameter('key', $key);
if ($keys !== null) {
$query->andWhere('s.key IN (:keys)')
->setParameter('keys', $keys);
}

if ($afterDate !== null) {
Expand Down
8 changes: 4 additions & 4 deletions src/LoginCidadao/StatsBundle/Handler/StatsHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,16 @@ public function getIndexed($index, $key = null, \DateTime $afterDate = null)
$afterDate);
}

public function getIndexedUniqueDate($index, $key = null,
public function getIndexedUniqueDate($index, $keys = null,
\DateTime $afterDate = null)
{
return $this->repo->findIndexedUniqueStatsByIndexKeyDate($index, $key,
return $this->repo->findIndexedUniqueStatsByIndexKeyDate($index, $keys,
$afterDate);
}

public function getIndexedUniqueLastDays($index, $key = null, $days = null)
public function getIndexedUniqueLastDays($index, $keys = null, $days = null)
{
return $this->repo->findIndexedUniqueStatsByIndexKeyDays($index, $key,
return $this->repo->findIndexedUniqueStatsByIndexKeyDays($index, $keys,
$days);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,13 @@ public function usersByServicesAction(Request $request)
->getRepository('PROCERGSOAuthBundle:Client');
$totals = $repo->getCountPerson($this->getUser());

$keys = array();
foreach ($totals as $total) {
$client = $total['client'];
$keys[] = $client->getId();
}
$evoData = $this->getStatsHandler()->getIndexedUniqueLastDays('client.users',
null, 30);
$keys, 30);

$context = SerializationContext::create()->setGroups('date');
$serializer = $this->get('jms_serializer');
Expand Down

0 comments on commit 4936076

Please sign in to comment.