adapting classes to new interfaces

This commit is contained in:
2016-02-01 00:01:21 +01:00
parent 9f7fe05991
commit 7619b41cd4
6 changed files with 144 additions and 8 deletions

View File

@@ -23,6 +23,7 @@ use Symfony\Component\Form\FormBuilderInterface;
use Doctrine\ORM\QueryBuilder;
use Chill\MainBundle\Export\AggregatorInterface;
use Symfony\Component\Security\Core\Role\Role;
use Chill\ActivityBundle\Security\Authorization\ActivityVoter;
/**
*
@@ -86,9 +87,28 @@ class ReasonAggregator implements AggregatorInterface
return "Aggregate by activity reason";
}
public function requiredRole()
public function addRole()
{
return new Role('dummy');
return new Role(ActivityVoter::SEE);
}
public function getLabels($key, array $values, $data)
{
return array_combine($values, $values);
}
public function getQueryKeys($data)
{
// add select element
if ($data['level'] === 'reason') {
return array('activity_reason_id');
} elseif ($data['level'] === 'category') {
return array ('activity_category_id');
} else {
throw new \RuntimeException('the data provided are not recognised');
}
}
}

View File

@@ -20,9 +20,10 @@
namespace Chill\ActivityBundle\Export\Export;
use Chill\MainBundle\Export\ExportInterface;
use Doctrine\ORM\Query\Expr\Join;
use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Security\Core\Role\Role;
use Doctrine\ORM\Query;
use Chill\ActivityBundle\Security\Authorization\ActivityStatsVoter;
/**
*
@@ -77,7 +78,34 @@ class CountActivity implements ExportInterface
public function requiredRole()
{
return new Role('dummy');
return new Role(ActivityStatsVoter::STATS);
}
public function getAllowedFormattersTypes()
{
return array(\Chill\MainBundle\Export\FormatterInterface::TYPE_TABULAR);
}
public function getLabels($key, array $values, $data)
{
if ($key !== 'export_count_activity') {
throw new \LogicException("the key $key is not used by this export");
}
$labels = array_combine($values, $values);
$labels['_header'] = 'Number of activities';
return $labels;
}
public function getQueryKeys($data)
{
return array('export_count_activity');
}
public function getResult(QueryBuilder $qb, $data)
{
return $qb->getQuery()->getResult(Query::HYDRATE_SCALAR);
}
}

View File

@@ -27,6 +27,7 @@ use Chill\ActivityBundle\Entity\ActivityReason;
use Chill\MainBundle\Templating\TranslatableStringHelper;
use Doctrine\ORM\Query\Expr;
use Symfony\Component\Security\Core\Role\Role;
use Chill\ActivityBundle\Security\Authorization\ActivityVoter;
/**
*
@@ -90,8 +91,8 @@ class ActivityReasonFilter implements FilterInterface
return 'Filter by reason';
}
public function requiredRole()
public function addRole()
{
return new Role('dummy');
return new Role(ActivityVoter::SEE);
}
}