Commit d47b8ffb authored by Stephane Bouvry's avatar Stephane Bouvry
Browse files

Fix : Lors d'une recherche sur le type/le pays des organisations, les...

Fix : Lors d'une recherche sur le type/le pays des organisations, les organisations tiers s'affichent correctement
parent cb253f3e
Loading
Loading
Loading
Loading
Loading
+6 −11
Original line number Diff line number Diff line
@@ -2941,24 +2941,18 @@ class ProjectGrantController extends AbstractOscarController implements UseNotif

                    case 'cnt' :
                        if ($params[1]) {
                            if (!isset($parameters['countries'])) {
                                $parameters['countries'] = [];
                            }
                            $value1 = $crit['val1'] = explode(',', $params[1]);
                            $qb->andWhere('orga1.country IN (:countries) OR orga2.country IN (:countries)');
                            $parameters['countries'] = $value1;
                            $ids = $this->getActivityService()->getActivityRepository()
                                ->getIdsWithOrganizationOfCountry($value1);
                        }
                        break;

                    case 'tnt' :
                        if ($params[1]) {
                            if (!isset($parameters['typeorga'])) {
                                $parameters['typeorga'] = [];
                            }
                            $value1 = $crit['val1'] = explode(',', $params[1]);
                            $typeIds = $this->getOrganizationService()->getTypesIdsByLabel($value1);
                            $qb->andWhere('orga1.typeObj IN (:typeorga) OR orga2.typeObj IN (:typeorga)');
                            $parameters['typeorga'] = $typeIds;
                            $ids = $this->getActivityService()->getActivityRepository()
                                ->getIdsWithOrganizationOfType($typeIds);
                        }
                        break;

@@ -3015,7 +3009,8 @@ class ProjectGrantController extends AbstractOscarController implements UseNotif
                }
                $criterias[] = $crit;
                if ($type == 'ap' || $type == 'ao' || $type == 'pm' || $type == 'om' || $type == 'num'
                    || $type == 'fdt' || $type == 'cb' || $type == 'cb2' || $type == 'td') {
                    || $type == 'fdt' || $type == 'cb' || $type == 'cb2' || $type == 'td' || $type == 'tnt'
                    || $type == 'cnt') {
                    if ($filterIds === null) {
                        $filterIds = $ids;
                    } else {
+49 −0
Original line number Diff line number Diff line
@@ -43,6 +43,55 @@ class ActivityRepository extends EntityRepository
        return array_map('current', $queryBuilder->getQuery()->getArrayResult());
    }


    protected function baseQueryWithOrganizationOf() :QueryBuilder
    {
        return $this->createQueryBuilder('c')
            ->select('DISTINCT c.id')
            ->leftJoin('c.project', 'pr')
            ->leftJoin('c.organizations', 'p1')
            ->leftJoin('p1.organization', 'orga1')
            ->leftJoin('pr.partners', 'p2')
            ->leftJoin('p2.organization', 'orga2');
    }

    /**
     * Retourne les IDS des activités impliquant une organisation d'un des types spécifiés.
     *
     * @param array $organizationTypeIds ID des types d'organisation
     * @return array
     */
    public function getIdsWithOrganizationOfType(array $organizationTypeIds): array
    {
        $queryBuilder = $this->baseQueryWithOrganizationOf()
            ->where('orga1.typeObj IN (:typeorga) OR orga2.typeObj IN (:typeorga)');

        $queryBuilder->setParameters(
            [
                'typeorga' => $organizationTypeIds
            ]
        );
        return array_map('current', $queryBuilder->getQuery()->getArrayResult());
    }

    /**
     * Retourne les IDS des activités impliquant une organisation ayant un des pays spécifiés.
     *
     * @param array $organizationTypeIds ID des types d'organisation
     * @return array
     */
    public function getIdsWithOrganizationOfCountry( array $countries ): array {
        $queryBuilder = $this->baseQueryWithOrganizationOf()
            ->where('orga1.country IN (:countries) OR orga2.country IN (:countries)');

        $queryBuilder->setParameters(
            [
                'countries' => $countries
            ]
        );
        return array_map('current', $queryBuilder->getQuery()->getArrayResult());
    }

    /**
     * Retourne les IDS des activités qui impliquent un des types de documents donnés.
     *