Commit fe5f6345 authored by Julien Fastré's avatar Julien Fastré

add a filtering of tasks by center

parent 7c113e34
......@@ -4,4 +4,5 @@ Branch master
- fix bug in filter task form: allow to show the list of users, which was hidden when the user had access to multiple centers;
- add assignee in task list;
- fix some translation;
- add a filtering by center on list;
......@@ -25,6 +25,7 @@ use Chill\TaskBundle\Event\TaskEvent;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\Translation\TranslatorInterface;
use Chill\TaskBundle\Event\UI\UIEvent;
use Chill\MainBundle\Repository\CenterRepository;
class SingleTaskController extends Controller
......@@ -360,6 +361,7 @@ class SingleTaskController extends Controller
PaginatorFactory $paginatorFactory,
SingleTaskRepository $taskRepository,
PersonRepository $personRepository,
CenterRepository $centerRepository,
FormFactoryInterface $formFactory
) {
/* @var $viewParams array The parameters for the view */
......@@ -370,7 +372,6 @@ class SingleTaskController extends Controller
$viewParams['user'] = null;
$params['user'] = null;
$viewParams['center'] = null;
$params['center'] = null;
$params['types'] = null;
// Get parameters from url
......@@ -386,6 +387,14 @@ class SingleTaskController extends Controller
$viewParams['person'] = $person;
$params['person'] = $person;
} elseif (!empty($request->query->get('center_id', NULL))) {
$center = $centerRepository->find($request->query->getInt('center_id'));
dump($center);
if ($center === null) {
throw $this->createNotFoundException('center not found');
}
$params['center'] = $center;
}
if(!empty($request->query->get('types', []))) {
......
......@@ -136,6 +136,17 @@ class SingleTaskListType extends AbstractType
'label' => 'Associated person'
])
;
$reachablesCenters = $this->getReachablesCenters();
if (count($reachablesCenters) > 1) {
$builder
->add('center_id', EntityType::class, [
'class' => \Chill\MainBundle\Entity\Center::class,
'choices' => $reachablesCenters,
'label' => 'Center',
'required' => false,
'placeholder' => 'All centers'
]);
}
} else {
// add a hidden field
$builder
......@@ -144,6 +155,7 @@ class SingleTaskListType extends AbstractType
->addModelTransformer(new PersonToIdTransformer($this->em))
;
}
}
protected function getUserChoices($options)
......@@ -257,6 +269,14 @@ class SingleTaskListType extends AbstractType
return $qb->getQuery()->getResult();
}
protected function getReachablesCenters()
{
$user = $this->tokenStorage->getToken()->getUser();
$role = new Role(TaskVoter::SHOW);
return $this->authorizationHelper->getReachableCenters($user, $role);
}
public function configureOptions(OptionsResolver $resolver)
{
......
......@@ -8,6 +8,7 @@ use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
use Symfony\Component\Security\Core\Role\Role;
use Chill\TaskBundle\Security\Authorization\TaskVoter;
use Doctrine\DBAL\Types\Type;
use Chill\MainBundle\Entity\Center;
/**
* SingleTaskRepository
......@@ -107,6 +108,14 @@ class SingleTaskRepository extends \Doctrine\ORM\EntityRepository
if (\array_key_exists('person', $params) and !empty($params['person'])) {
$qb->andWhere($qb->expr()->eq('st.person', ':person'));
$qb->setParameter('person', $params['person']);
} elseif (\array_key_exists('center', $params)) {
if ($params['center'] instanceof Center) {
$qb->join('st.person', 'person');
$qb->andWhere($qb->expr()->eq('person.center', ':center'));
$qb->setParameter('center', $params['center']);
} else {
throw new \UnexpectedValueException("params 'center' should be an instance of ".Center::class);
}
}
if (\array_key_exists('unassigned', $params) and $params['unassigned'] === true) {
......@@ -142,7 +151,7 @@ class SingleTaskRepository extends \Doctrine\ORM\EntityRepository
if (\array_key_exists('is_closed', $params)) {
$qb->andWhere($this->buildIsClosed($qb, !$params['is_closed']));
}
}
protected function addTypeFilter(QueryBuilder $qb, $params)
......
......@@ -99,3 +99,5 @@ My tasks over deadline: Mes tâches à échéance dépassée
#transition page
Apply transition on task <em>%title%</em>: Appliquer la transition sur la tâche <em>%title%</em>
All centers: Tous les centres
......@@ -168,6 +168,10 @@
{{ form_row(form.person_id) }}
{% endif %}
{% if form.center_id is defined %}
{{ form_row(form.center_id) }}
{% endif %}
<ul class="record_actions">
<li>
<button type="submit" class="sc-button">{{ 'Filter'|trans }}</button>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment