Commit 9c980f3c authored by Stephane Bouvry's avatar Stephane Bouvry
Browse files

Fix : Les filtre avec des dates de fin fonctionnent

parent 1808a102
Loading
Loading
Loading
Loading
Loading
+7 −45
Original line number Diff line number Diff line
@@ -2545,29 +2545,6 @@ class ProjectGrantController extends AbstractOscarController implements UseNotif
                ->leftJoin('a.persons', 'm2')
                ->where('m1.person in(:ids) OR m2.person in (:ids)');

            // QueryBuilder utilisés pour récupérer les IDS des activités pour
            // les filtres de personne avec ou sans rôle, idem pour les
            // organisations.
            $queryPersonNoRole = $this->getEntityManager()->createQueryBuilder()
                ->select('a.id')
                ->from(Activity::class, 'a', 'a.id')
                ->leftJoin('a.project', 'p')
                ->leftJoin('p.partners', 'o1')
                ->leftJoin('a.organizations', 'o2')
                ->leftJoin('p.members', 'm1')
                ->leftJoin('a.persons', 'm2')
                ->where('(m1.person = :id OR m2.person = :id)');

            $queryPersonRole = $this->getEntityManager()->createQueryBuilder()
                ->select('a.id')
                ->from(Activity::class, 'a', 'a.id')
                ->leftJoin('a.project', 'p')
                ->leftJoin('p.partners', 'o1')
                ->leftJoin('a.organizations', 'o2')
                ->leftJoin('p.members', 'm1')
                ->leftJoin('a.persons', 'm2')
                ->where('((m1.person = :id AND m1.roleObj = :roleObj) OR (m2.person = :id AND m2.roleObj = :roleObj))');

            $queryOrganisationNoRole = $this->getEntityManager()->createQueryBuilder()
                ->select('a.id')
                ->from(Activity::class, 'a', 'a.id')
@@ -2842,6 +2819,9 @@ class ProjectGrantController extends AbstractOscarController implements UseNotif
                        $crit['val1Label'] = "Non déterminé";
                        $organization = null;

                        $organizationId = (int) $value1;
                        $roleId = (int) $value2;

                        // Récupération de l'organisation
                        try {
                            $organization = $this->getOrganizationService()->getOrganization($value1);
@@ -2850,30 +2830,12 @@ class ProjectGrantController extends AbstractOscarController implements UseNotif
                        } catch (\Exception $e) {
                        }

                        if ($value2 > 0) {
                            $roleOrganisation = $this->getEntityManager()->getRepository(
                                OrganizationRole::class
                            )->find($value2);


                            if (!$organization) {
                                $query = $queryOrganisationRoleNorOrg;
                                $queryParam = [
                                    'roleObj' => $roleOrganisation
                                ];
                            } else {
                                $query = $queryOrganisationRole;
                                $queryParam['roleObj'] = $roleOrganisation;
                            }
                        } else {
                            if ($organization == null) {
                                $crit['error'] = "Impossible de filtrer Organisation et/ou rôle requis.";
                            }
                            $query = $queryOrganisationNoRole;
                        try {
                            $ids = $this->getActivityService()->getActivityRepository()->getIdsWithOrganizationAndRole($organizationId, $roleId);
                        } catch (\Exception $e) {
                            $crit['error'] = $e->getMessage();
                        }

                        $ids = array_keys($query->setParameters($queryParam)->getQuery()->getArrayResult());

                        break;

                    // Filtre sur le statut de l'activité
+35 −0
Original line number Diff line number Diff line
@@ -106,6 +106,41 @@ class ActivityRepository extends EntityRepository
        return array_map('current', $queryBuilder->getQuery()->getArrayResult());
    }

    public function getIdsWithOrganizationAndRole(int $organizationId = 0, int $roleObjId = 0) :array
    {
        if( $organizationId <= 0 && $roleObjId <= 0 ){
            throw new OscarException("Vous devez préciser une organisation et/ou un rôle");
        }

        $clauseA = [];
        $clauseB = [];

        if( $roleObjId > 0) {
            $clauseA[] = 'p1.roleObj = :roleId';
            $clauseB[] = 'p2.roleObj = :roleId';
            $params['roleId'] = $roleObjId;
        }

        if( $organizationId > 0 ) {
            $clauseA[] = 'orga1.id = :orgId';
            $clauseB[] = 'orga2.id = :orgId';
            $params['orgId'] = $organizationId;
        }

        $queryBuilder = $this->baseQueryWithOrganizationOf();
        $clause = '('
            .implode($clauseA, ' AND ')
            .') OR ('
            .implode($clauseB, 'AND ')
            . ')';

        $queryBuilder->where($clause);

        $queryBuilder->setParameters($params);

        return array_map('current', $queryBuilder->getQuery()->getArrayResult());
    }

    /**
     * Retourne les IDS des activités qui impliquent un des types de documents donnés.
     *
+11 −1
Original line number Diff line number Diff line
@@ -928,6 +928,17 @@

                        }

                        // Select
                        var input = filter.find('input.val2');

                        if( input.length > 0 ){
                            var val2Elem = filter.find('.val2');
                            if( val2Elem ){
                                val2 = val2Elem[0].value ? val2Elem[0].value : "";
                            }

                        }

                        filter.find('.criteria').val(datas.type
                            + ';' + filter.find('.val1').val()
                            + ';' + val2);
@@ -1052,7 +1063,6 @@
                            }
                        }

                        console.log("AJ", datas);
                        var val2 = "" +datas.val2;
                        if( val2.indexOf(',') > 0 ){
                            checked = val2.split(',');