Salut à tous

Je suis débutant dans le développement et sur Symfony. Je suis confronté à un souci depuis quelques jours, et je me tourne aujourd'hui vers vous pour y voir plus clair.

J'ai un problème de persistance de données lors du changement de page.

j’ai fait une page qui affiche les réservations faites par un particulier ou reçu par un propriétaire, pour que la navigation soit plus sympa pour l’utilisateur, des filtres ont été mis en place.

Et c’est là que se produit le drame.
Lors de l’affichage par défaut ($status="all") la pagination fonctionne correctement.

lorsque l’on sélectionne un filtre de statut, la page retournée affiche bien les données filtrées mais une fois que je change de page, les données se réinitialisent (dans le sens ou je retourne sur mon tableau “index”)

Je suis un peu perdu et je ne sais pas comment “bloquer” les données.
J'ai tenté d'utiliser la session mais, celle ci se réinitialise également

Petite précision supplémentaire, mon lead dev, ne veut pas que j'utilise Ajax ou Knp paginator. il souhaite du from scratch

Mon controleur

public function reservationAction(Request $request, $userSituation, $page = 1)
    {
        $user=$this->user;
        $userId=$user -> getid();
        $userSeed=$user ->getrealSeed();
        $session = $request->getSession();

        $data = $request->request->all();

        if(isset($data['situation']) && strtolower($data['situation']) != $userSituation){

                return $this->redirect('/myspace/booking/index/'.strtolower($data['situation']));

        }
        if(empty($data['situation']))
        {
            $data['status']= "all";
            $data['situation']= $userSituation;
        };

        $deposits = $this->em->getRepository('AppBundle:Deposit');

        $formatByCountry = $this->get('rll.format_by_country');
        $depositManager = $this->get('rll.manager.deposit');
        $currencyManager = $this->get('rll.manager.currency');
        $userCurrencyRate = $currencyManager->getRate($this->user->getCurrency());
        if (!$userCurrencyRate) {
            $userCurrencyRate = 1;
        }
        $userSymbol = $currencyManager->getSymbol($this->user->getCurrency());

        $nbMaxParPage = $this->getParameter('nbMaxReservation');

        if (is_numeric($userId) && empty($data)){

            $reservations = $deposits->getReservations($userId, strtoupper($userSituation), 'all', $nbMaxParPage, $page);
        } elseif (isset($data)){

            $status=$data['status'];
            $userSituation = $data['situation'];
            $reservations = $deposits->getReservations($userId, strtoupper($userSituation), $status, $session, $nbMaxParPage, $page);

        }

        dump($reservations);

        $listReservations = array();
        foreach ($reservations as $reservation) {
            $showCompleteInfos = false;
            $deposit = $depositManager->findOneBy(array('codeRelation' => $reservation['code']),array('code' => 'desc'));
            $status = $reservation['status'];

            if ($status == 'VALIDATED' || $status == 'TENANT_CONFIRMATION') {
                $showCompleteInfos = true;
            }

            /*
             * Gestion des prix en fonction de REAL_SEED et currency
             */
            if ($userSituation == 'tenant') {
                if ($this->user->getCurrency() == 'EUR') {
                    $payment = $reservation['paymentFromTenantInEuro'];
                } elseif ($this->user->getCurrency() == $deposit->getCurrency() ) {
                    $payment = $reservation['paymentFromTenant'];
                } else {
                    $payment = round($reservation['paymentFromTenantInEuro'] / $userCurrencyRate, 2);
                }
            }else{
                if ($this->user->getCurrency() == 'EUR') {
                    $payment = $reservation['paymentToLandlordInEuro'];
                } elseif ($this->user->getCurrency() == $deposit->getCurrency()) {
                    $payment = $deposit->getPaymentToLandlord();
                } else {
                    $payment = round($reservation['paymentToLandlordInEuro'] / $userCurrencyRate, 2);
                }
            }

            $statusColor = $this->getStatusColor($status);
            $listReservations[] = array(
                'idRelation' => $reservation['code'],
                'status' => $status,
                'statusColor' => $statusColor,
                'adTitle' => ucfirst($reservation['title']),
                'address' => ucfirst($reservation['completeAddress']),
                'town' => ucfirst($reservation['town']),
                'photo' => $this->get('rll.user_photo')->getUserPhoto($reservation['photo']),
                'fname' => $reservation['fname'],
                'lname' => $reservation['lname'],
                'payment' => $formatByCountry->manageAmount($payment, 2, $userSymbol),
                'showCompleteInfos' => $showCompleteInfos,
                'reference' => $reservation['ref'],
            );

        }

//        $methodtest= $deposits->findallRes($userId,$userSituation,$data['status'], $page, $nbMaxParPage);
        $totalReservations = $deposits->getNbTotalReservations($userId,$userSituation,$data['status'], $page, $nbMaxParPage, $session );

        $listResults= count($totalReservations);
//        $listResults2= count($methodtest);

        $pagination = array(
            'page' => $page,
            'occurences' => $listResults,
//            'occurences2' => $listResults2,
            'nbPages' => ceil(count($totalReservations) / $nbMaxParPage ),
            'nomRoute' => 'myspace_booking_reservation',
            'paramsRoute' => array()
        );
        $session->set('pagination', $pagination);
        $tiestto= $session->getBag('attributes')->get('reservation');
        $pagination2= $session->getBag('attributes')->get('pagination');

        dump($data);
        dump($session);

        return $this->render('myspace/booking/reservation.html.twig', [
            'data' => $data,
            'page' => $page,
            'listResults' => $listResults,
            'reservations' => $listReservations,
            'userSituation'=> $userSituation,
            'pagination'   => $pagination,
            'realSeed'   => $userSituation,
        ]);
    }

ma requête

public function getReservations($idUser,$userSituation,$status, $session, $nbMaxParPage, $page )
    {
        dump($status);
        $qb= $this->createQueryBuilder('dep');
        $qb->select('dep.ref')
            ->addSelect('dep.code')
            ->addSelect('dep.status')
            ->addSelect('dep.paymentFromTenantInEuro')
            ->addSelect('dep.paymentFromTenant')
            ->addSelect('dep.paymentToLandlordInEuro')
            ->addSelect('dep.paymentToLandlord')
            ->addSelect('ad.title')
            ->addSelect('ad.completeAddress')
            ->addSelect('ad.town')
            ->addSelect('usr.fname')
            ->addSelect('usr.lname')
            ->addSelect('usr.photo')
            ->innerJoin('AppBundle:Ad','ad', JOIN::WITH, $qb->expr()->eq('dep.codeAd','ad.code') );
        if ($userSituation === 'LANDLORD'){
            $qb
                ->innerJoin('AppBundle:User','usr', JOIN::WITH, $qb->expr()->eq('dep.tenantId', 'usr.id'))
                ->where('dep.landlordId = :idUser');
        } else {
            $qb ->innerJoin('AppBundle:User','usr', JOIN::WITH, $qb->expr()->eq('dep.landlordId', 'usr.id'))
                ->where('dep.tenantId = :idUser');
        }
        $qb->setParameter('idUser', $idUser);
        if ($status != 'all') {
            $qb->andWhere("dep.status = :status")
                ->setParameter('status', $status);
        }else{
            $qb->andWhere("dep.status IN ('LANDLORD_CANCELLATION','OUTDATED_CANCELLATION','TENANT_CANCELLATION','VALIDATED','TENANT_ABORTION','TENANT_CONFIRMATION','CONTENTION','LANDLORD_ABORTION','WAITING_FOR_LANDLORD')");
        }
        $qb->groupBy('dep.code');
        $qb->orderBy('dep.code', 'desc');

        $query= $qb->getQuery();
        $results = $query->getResult();
        dump($results);
        $session->set('reservation', $results);

        $premierResultat = ($page - 1) * $nbMaxParPage;
        $query->setFirstResult($premierResultat)->setMaxResults($nbMaxParPage);
        $qb->getQuery()->useResultCache(true, 3000 );
        return $query->getResult();
    }

ma requete pour la pagination

public function getNbTotalReservations($idUser,$userSituation,$status, $page, $nbMaxParPage )
   {

       $qb= $this->createQueryBuilder('dep');
       $qb->select('dep');

       if ($userSituation == 'LANDLORD'){
           $qb ->where('dep.landlordId = :idUser');
       }else{
           $qb ->where('dep.tenantId = :idUser');
       }
       $qb->setParameter('idUser', $idUser);
       if ($status != 'all') {
           $qb->andWhere("dep.status = :status")
               ->setParameter('status', $status);
       }else{
           $qb->andWhere("dep.status IN ('LANDLORD_CANCELLATION','OUTDATED_CANCELLATION','TENANT_CANCELLATION','VALIDATED','TENANT_ABORTION','TENANT_CONFIRMATION','CONTENTION','LANDLORD_ABORTION','WAITING_FOR_LANDLORD')");
       }

       $query= $qb->getQuery();
       $premierResultat = ($page - 1) * $nbMaxParPage;
       $query->setFirstResult($premierResultat)->setMaxResults($nbMaxParPage);
       return new Paginator($query, $fetchJoinCollection = true);
   }

ma vue

{% extends 'base.html.twig' %}

{% block stylesheets %}
    {{ parent() }}
    {% stylesheets
        '%kernel.root_dir%/Resources/css/myspace.css'
        '%kernel.root_dir%/Resources/css/chat.css'
    %}
        <link rel="stylesheet" type="text/css" href="{{ pathInfo~asset_url }}" />
    {% endstylesheets %}
{% endblock %}

{% block body %}
    {% include 'myspace/sub_menu.html.twig' %}
    <div class="row">
        <section id="mySpaceSection">
            <div class="bookingnav">
                <ul class="nav nav-pills hideMobile" id="tabsMySpace">
                    <li role="presentation" class="active"><a href="{{ path('myspace_booking_reservation', {'userSituation': userSituation|lower}) }}">{{ textFront.booking }}</a></li>
                    <li role="presentation"><a href="{{ path('myspace_booking_transaction') }}">{{ textFront.transaction }}</a></li>
                </ul>
            </div>

            <form action="/myspace/booking/index/{% if userSituation is defined %}{{ userSituation|lower }}{% endif %}" method="post">
                <div class="form-group col-md-2">

                    <select class="form-control col-md-2 bookingfilter" name="situation">
                        <option {% if data.situation is defined and data.situation == 'landlord' %}selected{% endif %} value="LANDLORD">{{ textFront.landlord|capitalize }}</option>
                        <option {% if data.situation is defined and data.situation == 'tenant' %}selected{% endif %} value="TENANT">{{ textFront.tenant|capitalize }}</option>
                    </select>
                </div>
                <div class="form-group col-md-2">
                    <select class="form-control col-md-2 bookingfilter" name="status">
                        <option class="hidden" value="all">{{ textFront.status }}</option>
                        <option {% if data.status is defined and data.status == 'all' %}selected{% endif %} value="all">{{ textFront.all }}</option>
                        <option {% if data.status is defined and data.status == 'VALIDATED' %}selected{% endif %} value="VALIDATED">{{ textFront.validated }}</option>
                        <option {% if data.status is defined and data.status == 'TENANT_CONFIRMATION' %}selected{% endif %} value="TENANT_CONFIRMATION">{{ textFront.validated }}</option>
                        <option {% if data.status is defined and data.status == 'OUTDATED_CANCELLATION' %}selected{% endif %} value="OUTDATED_CANCELLATION">{{ textFront.outdated }}</option>
                        <option {% if data.status is defined and data.status == 'TENANT_CANCELLATION' %}selected{% endif %} value="TENANT_CANCELLATION">{{ textFront.canceled }}</option>
                        <option {% if data.status is defined and data.status == 'LANDLORD_CANCELLATION' %}selected{% endif %} value="LANDLORD_CANCELLATION">{{ textFront.canceled }}</option>
                        <option {% if data.status is defined and data.status == 'TENANT_ABORTION' %}selected{% endif %} value="TENANT_ABORTION">{{ textFront.abortion }}</option>
                        <option {% if data.status is defined and data.status == 'LANDLORD_ABORTION' %}selected{% endif %} value="LANDLORD_ABORTION">{{ textFront.abortion }}</option>
                        <option {% if data.status is defined and data.status == 'CONTENTION' %}selected{% endif %} value="CONTENTION">{{ textFront.contention }}</option>
                    </select>
                </div>
                <input class="btn-form" id="formBtn" type="submit" name="filtre" value="Filtrer">
            </form>
            <div id="loadReservations">
                <table class="table rlltable" id="tableReservations">
                    <thead>
                    <tr valign="middle">
                        <th class="colStatus">{{ textFront.status }}</th>
                        <th class="colDate">{{ textFront.date_location }}</th>
                        <th class="user">
                            {% if userSituation == 'landlord' %}
                                {{ textFront.tenant|capitalize }}
                            {% else %}
                                {{ textFront.landlord|capitalize }}
                            {% endif %}
                        </th>
                        <th class="priceR">{{ textFront.details }}</th>
                    </tr>
                    </thead>
                    <tbody>
                    {% for reservation in reservations %}
                        {% if reservation.status == 'VALIDATED' or reservation.status == 'TENANT_CONFIRMATION' %}
                            {% set reservationStatus = textFront.validated %}
                        {% elseif reservation.status == 'OUTDATED_CANCELLATIO' or reservation.status == 'OUTDATED_CANCELATION' %}
                            {% set reservationStatus = textFront.outdated %}
                        {% elseif reservation.status == 'TENANT_ABORTION' %}
                            {% set reservationStatus = textFront.abortion %}
                        {% elseif reservation.status == 'LANDLORD_CANCELLATIO' or reservation.status == 'LANDLORD_CANCELLATION' or reservation.status == 'TENANT_CANCELLATION' or reservation.status == 'TENANT_CANCELATION' %}
                            {% set reservationStatus = textFront.canceled %}
                        {% elseif reservation.status == 'CONTENTION' %}
                            {% set reservationStatus = textFront.contention %}
                        {% elseif reservation.status == 'WAITING_FOR_LANDLORD' %}
                            {% set reservationStatus = textFront.waitingl %}
                        {% elseif reservation.status == 'WAITING_FOR_TENANT' %}
                            {% set reservationStatus = textFront.waitingt %}
                        {% else %}
                            {% set reservationStatus = reservation.status %}
                        {% endif %}

                        <tr valign="middle" id="{{ reservation.idRelation }}">
                            <td>
                                <strong class="{{ reservation.statusColor }}">{{ reservationStatus }}</strong>
                            </td>
                            <td class="date">
                                {#{{ reservation.arrivalDate| localizeddate('full', 'none', app.request.getLocale(), null)|capitalize }} - {{ reservation.endingDate| localizeddate('full', 'none', app.request.getLocale(), null)|capitalize }}#}
                                <br />
                                <strong>{{ reservation.adTitle }}</strong>
                                <br />
                                {% if reservation.showCompleteInfos == true %}
                                    {{ reservation.address }},
                                {% endif %}
                                {{ reservation.town }}
                            </td>
                            <td class="user">
                                <span style="background: url('{{ reservation.photo }}') no-repeat center center; background-size: 50px;" class="avatar"></span>
                                <strong>{{ reservation.fname }}</strong>
                                {% if reservation.showCompleteInfos == true %}
                                    <strong>{{ reservation.lname }}</strong>
                                {% endif %}
                                <a href="/messaging/{{ userSituation}}/detail/{{ reservation.idRelation }}" target="_blank"><span class="sendMsg"></span>{{ textFront.send_msg }}</a>
                            </td>
                            <td class="priceR">
                                <strong>{{ reservation.payment }} {{ textFront.total }}</strong>
                                <br />
                                {{ textFront.reference }} : {{ reservation.reference }}
                            </td>
                        </tr>
                    {% endfor %}
                    {% if reservations is empty %}
                        <tr>
                            <td colspan="4" align="center">
                                {{ textFront.no_transaction }}
                            </td>
                        </tr>
                    {% endif %}
                    </tbody>
                </table>
                <div class="text-center">
                    <ul class="pagination">
                        {% if pagination.page>1 %}
                            <li><a href="{{ path(pagination.nomRoute, pagination.paramsRoute|merge({'userSituation': userSituation|lower, 'page': pagination.page-1 })) }}">&laquo;</a></li>
                        {% endif %}
                        {% for p in range(max(pagination.page-4, 1), min(pagination.page+4, pagination.nbPages)) %}
                        <li{% if p == pagination.page %} class="active" {% endif %} ><a href="{{ path(pagination.nomRoute, pagination.paramsRoute|merge({'userSituation': userSituation|lower, 'page': p })) }}">{{ p }}</a></li>
                        {% endfor %}

                        {% if pagination.page < pagination.nbPages %}
                            <li><a href="{{ path(pagination.nomRoute, pagination.paramsRoute|merge({'userSituation': userSituation|lower, 'page':pagination.page+1 })) }}">&raquo;</a></li>
                        {% endif %}
                    </ul>
                </div>
            </div>
        </section>
    </div>
    {% block javascripts %}
        <script
                src="https://code.jquery.com/jquery-3.3.1.min.js"
                integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
                crossorigin="anonymous"></script>
        {% javascripts
            '%kernel.root_dir%/Resources/js/myspace/booking/transaction.js' %}
            <script type="text/javascript" src="{{ pathInfo~asset_url }}"></script>
        {% endjavascripts %}
    {% endblock %}
{% endblock %}

merci de votre attention
voici une patate sympathique

Aucune réponse