Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Evenements : widget : pouvoir filtrer sur plusieurs types d'événements #1096

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions app/Resources/views/event/_partial/widget.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
{% block content %}
{% if title %}
<p style="margin-top:0;">
liste des prochains événements
{% if eventKind %}<strong>{{ eventKind.name }}</strong>{% endif %}
{% if maxDate %}(jusqu'au {{ maxDate | date_short }}){% endif %}
Liste des prochains événements
{% if date_max %}(jusqu'au {{ date_max | date_short }}){% endif %}
</p>
{% endif %}
<ul style="margin:0;">
Expand All @@ -20,7 +19,7 @@
<span>[en cours]</span>
{% endif %}
{% endif %}
{# {% if not eventKind %}[{{ event.kind }}] {% endif %} #}
{# {% if not event_kind_id_list %}[{{ event.kind }}] {% endif %} #}
</li>
{% endfor %}
</ul>
Expand Down
11 changes: 8 additions & 3 deletions src/AppBundle/Controller/AdminEventController.php
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ public function widgetGeneratorAction(Request $request)
'label' => "Quel type d'événement ?",
'class' => 'AppBundle:EventKind',
'choice_label' => 'name',
'multiple' => false,
'multiple' => true,
'required' => false
))
->add('date_max', TextType::class, array(
Expand Down Expand Up @@ -461,8 +461,13 @@ public function widgetGeneratorAction(Request $request)

if ($form->handleRequest($request)->isValid()) {
$data = $form->getData();

$widgetQueryString = 'event_kind_id=' . ($data['kind'] ? $data['kind']->getId() : '') . '&date_max=' . ($data['date_max'] ? $data['date_max'] : '') . '&limit=' . ($data['limit'] ? $data['limit'] : '') . '&title=' . ($data['title'] ? 1 : 0) . '&links=' . ($data['links'] ? 1 : 0);
$widgetQueryString = '';
if ($data['kind']) {
foreach ($data['kind'] as $kind) {
$widgetQueryString .= 'event_kind_id[]=' . $kind->getId() . '&';
}
}
$widgetQueryString .= 'date_max=' . ($data['date_max'] ? $data['date_max'] : '') . '&limit=' . ($data['limit'] ? $data['limit'] : '') . '&title=' . ($data['title'] ? 1 : 0) . '&links=' . ($data['links'] ? 1 : 0);

return $this->render('admin/event/widget_generator.html.twig', array(
'form' => $form->createView(),
Expand Down
21 changes: 11 additions & 10 deletions src/AppBundle/Controller/EventController.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,31 +33,32 @@ public function widgetAction(Request $request)
$em = $this->getDoctrine()->getManager();

$buckets = array();
$eventKind = null;
$eventDateMax = null;
$filter_event_kind_id_list = null;
$filter_date_max_cleaned = null;

$filter_title = $request->query->has('title') ? ($request->get('title') == 1) : false;
$filter_links = $request->query->has('links') ? ($request->get('links') == 1) : false;
$filter_date_max = $request->query->has('date_max') ? ($request->get('date_max') ? new DateTime($request->get('date_max')) : null) : null;
if ($filter_date_max) {
$eventDateMax = clone($filter_date_max);
$eventDateMax->modify('+1 day'); // also return events happening on max date
$filter_date_max_cleaned = clone($filter_date_max);
$filter_date_max_cleaned->modify('+1 day'); // also return events happening on max date
}
$filter_limit = $request->query->has('limit') ? ($request->get('limit') ? $request->get('limit') : null) : null;

$filter_event_kind_id = $request->get('event_kind_id');
if ($filter_event_kind_id) {
$eventKind = $em->getRepository('AppBundle:EventKind')->find($filter_event_kind_id);
$filter_event_kind_id_list = $request->get('event_kind_id'); // should be an array (or null)
if (is_string($filter_event_kind_id_list)) { // manage case if string (retro-compatibility)
$filter_event_kind_id_list = array($filter_event_kind_id_list);
}
$filter_event_kind_id_list = array_filter($filter_event_kind_id_list); // remove any empty values

$events = $em->getRepository('AppBundle:Event')->findFutureOrOngoing($eventKind, false, $eventDateMax, $filter_limit);
$events = $em->getRepository('AppBundle:Event')->findFutureOrOngoing($filter_event_kind_id_list, false, $filter_date_max_cleaned, $filter_limit);

return $this->render('event/_partial/widget.html.twig', [
'events' => $events,
'eventKind' => $eventKind,
'title' => $filter_title,
'links' => $filter_links,
'maxDate' => $filter_date_max,
'date_max' => $filter_date_max,
'event_kind_id_list' => $filter_event_kind_id_list
]);
}

Expand Down
8 changes: 4 additions & 4 deletions src/AppBundle/Repository/EventRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@ public function findAll()
return $this->findBy(array(), array('date' => 'DESC'));
}

public function findFutureOrOngoing(EventKind $eventKind = null, bool $dislayedHome = false, \DateTime $max = null, int $limit = null)
public function findFutureOrOngoing(array $eventKinds = null, bool $dislayedHome = false, \DateTime $max = null, int $limit = null)
{
$qb = $this->createQueryBuilder('e')
->leftJoin('e.kind', 'ek')
->addSelect('ek')
->where('e.date > :now OR e.date < :now AND e.end IS NOT NULL AND e.end > :now')
->setParameter('now', new \Datetime('now'));

if ($eventKind) {
if ($eventKinds) {
$qb
->andwhere('e.kind = :kind')
->setParameter('kind', $eventKind);
->andwhere('e.kind in (:kinds)')
->setParameter('kinds', $eventKinds);
}

if ($dislayedHome) {
Expand Down