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

- Filtre presque terminé

parent 4547e000
Loading
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -157,11 +157,11 @@ class OrganizationController extends AbstractOscarController implements UseOrgan
            $error = _("Expression de recherche incorrecte") . ' : ' . $e->getMessage();
        } catch (NoNodesAvailableException $e) {
            $error = "Le moteur de recherche est introuvable";
        } catch (\Exception $exception){
            $this->getLoggerService()->error($exception->getMessage());
            return $this->jsonError("Quelquechose c'est mal passé...");
        }




        if ($this->getRequest()->isXmlHttpRequest() || $this->params()->fromQuery('f') === 'json') {
            // test : return $this->getResponseUnauthorized("nop");
            $result = ['datas' => []];
+150 −4
Original line number Diff line number Diff line
@@ -881,11 +881,11 @@ class ActivityRepository extends EntityRepository
     * @return array
     * @throws OscarException
     */
    public function getIdsForPersonAndOrWithRole(array $idPersons, int $idRole): array
    public function getIdsForPersonAndOrWithRole(array $idPersons, int $idRole, bool $not = false): array
    {
        return array_map(
            'current',
            $this->getQueryIdsForPersonOrWithRole($idPersons, $idRole)->select('a.id')
            $this->getQueryIdsForPersonOrWithRole($idPersons, $idRole, $not)->select('a.id')
                ->getQuery()->getResult()
        );
    }
@@ -905,6 +905,11 @@ class ActivityRepository extends EntityRepository
        );
    }

    /**
     * Retourne les IDs des projets pour la liste des IDs d'activité donnée.
     * @param array|null $ids
     * @return array
     */
    public function getIdsProjectsForActivity(?array $ids): array
    {
        if ($ids) {
@@ -921,8 +926,149 @@ class ActivityRepository extends EntityRepository
                    ->getQuery()
                    ->getResult()
            );
        } else {
        }
        else {
            return [];
        }
    }

    /**
     * Retourne la liste des IDS inverse
     * @param array $ids
     * @return array
     */
    public function getIdsInverse(array $ids): array
    {
        $qb = $this->getEntityManager()->createQueryBuilder()
            ->select('DISTINCT c.id')
            ->from(Activity::class, 'c');
        if (count($ids) > 0) {
            $qb->where('c.id NOT IN(:ids)')
                ->setParameter('ids', $ids);
        }

        return array_map('current', $qb->getQuery()->getResult());
    }

    public function getIdsAmount(mixed $min, mixed $max)
    {
        $qb = $this->getEntityManager()->createQueryBuilder()
            ->select('DISTINCT c.id')
            ->from(Activity::class, 'c');

        $parameters = [];

        if ($min !== null) {
            $qb->where('c.amount >= :min');
            $parameters['min'] = $min;
        }

        if ($max !== null) {
            $qb->where('c.amount >= :max');
            $parameters['max'] = $max;
        }


        return array_map('current', $qb->getQuery()->setParameters($parameters)->getResult());
    }

    /**
     * Liste des ID avec une des disciplines
     * @param array $disciplines
     * @return array
     */
    public function getIdsDisciplines(array $disciplines): array
    {
        $qb = $this->getEntityManager()->createQueryBuilder()
            ->select('DISTINCT c.id')
            ->from(Activity::class, 'c')
            ->innerJoin('c.disciplines', 'd')
            ->where('d IN (:disciplines)')
            ->setParameter('disciplines', $disciplines);
        return array_map('current', $qb->getQuery()->getResult());
    }

    /**
     * @param int $milestoneId (DateType->id)
     * @param array|null $progression
     * @return array
     */
    public function getIdsMilestone(int $milestoneId, ?array $progression): array
    {
        $q = $this->createQueryBuilder('c')
            ->select('c.id')
            ->innerJoin('c.milestones', 'm')
            ->where('m.type = :jalonId');

        if (is_array($progression) && count($progression) > 0) {
            $clause = 'm.finished IN(:progression)';

            if (in_array('0', $progression)) {
                $clause .= ' OR m.finished IS NULL';
            }
            $q->andWhere($clause)
                ->setParameter('progression', $progression);
        }

        $q->setParameter('jalonId', $milestoneId);

        $activities = $q->getQuery()->getResult();
        return array_map('current', $activities);
    }

    /**
     * @param string $field
     * @param mixed $value1
     * @param mixed $value2
     * @return integer[]
     * @throws \Exception
     */
    public function getIdsByDate(string $field, mixed $value1, mixed $value2): array
    {
        if (!$value1 && !$value2) {
            throw new \Exception("Aucune date à filtrer");
        }
        $q = $this->createQueryBuilder('c')
            ->select('c.id');

        $parameters = [];

        if ($value1) {
            $q->andWhere('c.' . $field . ' >= :from');
            $parameters['from'] = $value1;
        }
        if ($value2) {
            $q->andWhere('c.' . $field . ' <= :to');
            $parameters['to'] = $value2;
        }


        $q->setParameters($parameters);

        $activities = $q->getQuery()->getResult();
        return array_map('current', $activities);
    }

    public function getIdsFinancialImpact(mixed $value1, bool $inversed = false): array
    {
        if (!array_key_exists($value1, Activity::getFinancialImpactValues())) {
            throw new \Exception("Ce type d'incidence financière n'existe pas");
        }

        $param = Activity::getFinancialImpactValues()[$value1];

        $q = $this->createQueryBuilder('c')
            ->select('c.id');

        if ($inversed) {
            $q->andWhere('c.financialImpact != :param');
        }
        else {
            $q->where('c.financialImpact = :param');
        }

        $q->setParameter('param', $param);

        return array_map('current', $q->getQuery()->getResult());
    }
}
 No newline at end of file
+11 −6
Original line number Diff line number Diff line
@@ -675,11 +675,16 @@ class OrganizationService implements UseOscarConfigurationService, UseEntityMana
    {
        static $searchStrategy;
        if ($searchStrategy === null) {
            try {
                $opt = $this->getOscarConfigurationService()->getConfiguration('strategy.organization.search_engine');
                $class = new \ReflectionClass($opt['class']);
                $params = $opt['params'];
                $params[] = $this->getLoggerService();
                $searchStrategy = $class->newInstanceArgs($params);
            } catch (\Throwable $e) {
                $this->getLoggerService()->critical($e->getMessage());
                throw new OscarException("Impossible d'instancier l'accès au moteur de recherche");
            }
        }
        return $searchStrategy;
    }
@@ -699,7 +704,6 @@ class OrganizationService implements UseOscarConfigurationService, UseEntityMana
    public function getOrganizationsSearchPaged(string $search, int $page, array $filter = []): UnicaenDoctrinePaginator
    {
        $qb = $this->getSearchQuery($search, $filter);

        return new UnicaenDoctrinePaginator($qb, $page);
    }

@@ -803,6 +807,7 @@ class OrganizationService implements UseOscarConfigurationService, UseEntityMana

    public function getSearchQuery($search, $filter)
    {
        $this->getLoggerService()->debug(__METHOD__);
        $qb = $this->getBaseQuery();

        if ($search != "") {
+402 −357

File changed.

Preview size limit exceeded, changes collapsed.

+177 −174
Original line number Diff line number Diff line
@@ -10,6 +10,7 @@ namespace Oscar\Service;
use Cocur\Slugify\Slugify;
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\Query;
use Doctrine\ORM\QueryBuilder;
use Doctrine\Persistence\ObjectRepository;
use Oscar\Entity\ActivityDate;
use Oscar\Entity\ActivityDateRepository;
@@ -282,7 +283,8 @@ class ProjectGrantService implements UseGearmanJobLauncherService, UseOscarConfi

        if (!array_key_exists('role_person_id', $options)) {
            $role_organisation_id = [];
        } else {
        }
        else {
            $role_organisation_id = ArrayUtils::normalizeArray($options['role_organisation_id']);
        }

@@ -445,7 +447,8 @@ class ProjectGrantService implements UseGearmanJobLauncherService, UseOscarConfi
            }
            if (preg_match_all($regex, $pfiTested, $matches, PREG_SET_ORDER, 0)) {
                $out['valids'][] = $pfiTested;
            } else {
            }
            else {
                $badPfi = "Un ou plusieurs N°Financier ne correspondent pas au format attendu";
                $out['warnings'][] = $pfiTested;
            }
@@ -544,7 +547,8 @@ class ProjectGrantService implements UseGearmanJobLauncherService, UseOscarConfi
        if (!$activity) {
            if ($throw === true) {
                throw new OscarException("Impossible de charger l'activité (ID = $id)");
            } else {
            }
            else {
                return null;
            }
        }
@@ -563,7 +567,8 @@ class ProjectGrantService implements UseGearmanJobLauncherService, UseOscarConfi
        if (!$activity) {
            if ($throw === true) {
                throw new OscarException("Impossible de charger l'activité (UID = $importedUid)");
            } else {
            }
            else {
                return null;
            }
        }
@@ -695,7 +700,8 @@ class ProjectGrantService implements UseGearmanJobLauncherService, UseOscarConfi
        if (!$activity) {
            if ($throw === true) {
                throw new OscarException("Impossible de charger l'activité (OSCAR N° = $oscarNum)");
            } else {
            }
            else {
                return null;
            }
        }
@@ -718,7 +724,8 @@ class ProjectGrantService implements UseGearmanJobLauncherService, UseOscarConfi
            foreach ($types as $type) {
                $documentTypes[$type->getId()] = $type->getLabel();
            }
        } else {
        }
        else {
            $documentTypes = $types;
        }
        return $documentTypes;
@@ -784,30 +791,6 @@ class ProjectGrantService implements UseGearmanJobLauncherService, UseOscarConfi
        return array_map('current', $projects);
    }


    public function getActivityIdsByJalon($jalonTypeId, $progression = null)
    {
        $q = $this->getActivityRepository()->createQueryBuilder('c')
            ->select('c.id')
            ->innerJoin('c.milestones', 'm')
            ->where('m.type = :jalonId');

        if (is_array($progression) && count($progression) > 0) {
            $clause = 'm.finished IN(:progression)';

            if (in_array('0', $progression)) {
                $clause .= ' OR m.finished IS NULL';
            }
            $q->andWhere($clause)
                ->setParameter('progression', $progression);
        }

        $q->setParameter('jalonId', $jalonTypeId);

        $activities = $q->getQuery()->getResult();
        return array_map('current', $activities);
    }

    /**
     * @param $ids
     * @param int $page
@@ -909,7 +892,8 @@ class ProjectGrantService implements UseGearmanJobLauncherService, UseOscarConfi
        if (is_array($restricted_ids)) {
            if ($ids_search === null) {
                $ids_search = $restricted_ids;
            } else {
            }
            else {
                $ids_search = array_intersect($ids_search, $restricted_ids);
            }
        }
@@ -1070,7 +1054,8 @@ class ProjectGrantService implements UseGearmanJobLauncherService, UseOscarConfi

                    if ($ids_search === null) {
                        $ids_search = $ids;
                    } else {
                    }
                    else {
                        $ids_search = array_intersect($ids_search, $ids);
                    }
                } catch (\Exception $e) {
@@ -1100,7 +1085,8 @@ class ProjectGrantService implements UseGearmanJobLauncherService, UseOscarConfi
                    return $a1ID > $a2ID;
                };
                usort($resultRaw, $pertinenceFunction);
            } else {
            }
            else {
                $queryBuilder->orderBy('c.' . $sort, $direction);
                $resultRaw = $queryBuilder->getQuery()->getResult();
            }
@@ -1122,6 +1108,11 @@ class ProjectGrantService implements UseGearmanJobLauncherService, UseOscarConfi
        return $output;
    }

    public function getActivitiesIdsInverse(array $idsActivitySearch): array
    {
        return $this->getActivityRepository()->getIdsInverse($idsActivitySearch);
    }

    protected function debug__displayIds(array $ids)
    {
        echo " = ";
@@ -1675,12 +1666,6 @@ class ProjectGrantService implements UseGearmanJobLauncherService, UseOscarConfi
        return $this->getActivityRepository()->getActivitiesIdsWithTypeDocument($idsTypeDocument, $reverse);
    }

    public function getActivitiesWithNumerotation(array $numerotations): array
    {
        $ids = $this->getActivityRepository()->getActivitiesIdsWithNumerotations($numerotations);
        return $ids;
    }

    /**
     * Renomage des clefs pour les numérotations personnalisées;
     *
@@ -1788,7 +1773,7 @@ class ProjectGrantService implements UseGearmanJobLauncherService, UseOscarConfi
     * @param \DateTime $from
     * @param \DateTime $to
     * @param string $field
     * @return \Doctrine\ORM\QueryBuilder
     * @return QueryBuilder
     */
    public function getActivitiesBeetween2dates(\DateTime $from, \DateTime $to, $field = 'dateStart')
    {
@@ -1809,7 +1794,7 @@ class ProjectGrantService implements UseGearmanJobLauncherService, UseOscarConfi
     *
     * @param string $gap
     * @param string $start
     * @return \Doctrine\ORM\QueryBuilder
     * @return QueryBuilder
     */
    public function getActivityAlmostDone($gap = '+1 month', $start = 'now')
    {
@@ -1824,7 +1809,8 @@ class ProjectGrantService implements UseGearmanJobLauncherService, UseOscarConfi
    /**
     * @param string $gap
     * @param string $start
     * @return \Doctrine\ORM\QueryBuilder
     * @return QueryBuilder
     * @throws \DateMalformedStringException
     */
    public function getActivityBeginsSoon($gap = '+2 weeks', $start = 'now')
    {
@@ -1865,7 +1851,8 @@ class ProjectGrantService implements UseGearmanJobLauncherService, UseOscarConfi
                if (!$this->searchIndex_checkPath()) {
                    $this->index = \Zend_Search_Lucene::create($path);
                    $this->index = \Zend_Search_Lucene::create($path);
                } else {
                }
                else {
                    $this->index = \Zend_Search_Lucene::open($path);
                }
                // Lucene configuration globale
@@ -1886,12 +1873,12 @@ class ProjectGrantService implements UseGearmanJobLauncherService, UseOscarConfi
    }

    /**
     * Retourne les jalons de l'activités.
     * Retourne les jalons de l'activité.
     *
     * @param $idActivity
     * @return array
     */
    public function getMilestones($idActivity)
    public function getMilestones($idActivity): array
    {
        return $this->getMilestoneService()->getMilestonesByActivityId($idActivity);
    }
@@ -2141,7 +2128,7 @@ class ProjectGrantService implements UseGearmanJobLauncherService, UseOscarConfi
    }

    /**
     * @return \Doctrine\ORM\QueryBuilder
     * @return QueryBuilder
     */
    protected function getQueryBuilderDateType()
    {
@@ -2367,13 +2354,15 @@ class ProjectGrantService implements UseGearmanJobLauncherService, UseOscarConfi

        if ($datePayment) {
            $payment->setDatePayment(new \DateTime($datePayment));
        } else {
        }
        else {
            $payment->setDatePayment(null);
        }

        if ($datePredicted) {
            $payment->setDatePredicted(new \DateTime($datePredicted));
        } else {
        }
        else {
            $payment->setDatePredicted(null);
        }
        $payment->setRate($rate)
@@ -2420,13 +2409,15 @@ class ProjectGrantService implements UseGearmanJobLauncherService, UseOscarConfi

        if ($datePayment) {
            $payment->setDatePayment(new \DateTime($datePayment));
        } else {
        }
        else {
            $payment->setDatePayment(null);
        }

        if ($datePredicted) {
            $payment->setDatePredicted(new \DateTime($datePredicted));
        } else {
        }
        else {
            $payment->setDatePredicted(null);
        }

@@ -2710,7 +2701,8 @@ class ProjectGrantService implements UseGearmanJobLauncherService, UseOscarConfi
        if ($deep) {
            $ids = $this->getOrganizationService()->getOrganizationIdsDeep($idOrganization);
            $ids[] = $idOrganization;
        } else {
        }
        else {
            $ids = [$idOrganization];
        }
        return $this->getBaseQuery()
@@ -2770,7 +2762,7 @@ class ProjectGrantService implements UseGearmanJobLauncherService, UseOscarConfi
    /**
     * Retourne la requète pour obtenir la liste complète des contrats.
     *
     * @return \Doctrine\ORM\QueryBuilder
     * @return QueryBuilder
     */
    public function getGrants()
    {
@@ -2874,7 +2866,8 @@ class ProjectGrantService implements UseGearmanJobLauncherService, UseOscarConfi
            while ($close > 0) {
                if ($open[count($open) - 1] < $grantType->getLft()) {
                    array_pop($open);
                } else {
                }
                else {
                    $prefix .= " - ";
                    $prefix .= " - ";
                }
@@ -2884,7 +2877,8 @@ class ProjectGrantService implements UseGearmanJobLauncherService, UseOscarConfi
            if ($grantType->getLft() + 1 == $grantType->getRgt()) {
                $prefix .= ' # ';
                $qt = '';
            } else {
            }
            else {
                $open[] = $grantType->getRgt();
                $qt = sprintf(' (%s)', (($grantType->getRgt() - $grantType->getLft() - 1) / 2));
            }
@@ -3041,7 +3035,8 @@ class ProjectGrantService implements UseGearmanJobLauncherService, UseOscarConfi
        try {
            if (!$activityorganization->getRoleObj()) {
                $updateNotification = $roleOrganization->isPrincipal();
            } else {
            }
            else {
                $updateNotification = $activityorganization->getRoleObj()->isPrincipal(
                    ) !== $roleOrganization->isPrincipal();
            }
@@ -3163,13 +3158,14 @@ class ProjectGrantService implements UseGearmanJobLauncherService, UseOscarConfi
    ////////////////////////////////////////////////////////////////////////////

    /**
     * @return \Doctrine\ORM\QueryBuilder
     * @return QueryBuilder
     */
    public function getBaseQuery($includeObsolet = false)
    {
        if ($includeObsolet === true) {
            $roleClaude = ' AND ((m.dateStart is NULL OR m.dateStart <= :dateRef)AND(m.dateEnd is NULL OR m.dateEnd >= :dateRef))';
        } else {
        }
        else {
            $roleClaude = '';
        }
        $qb = $this->getEntityManager()->createQueryBuilder()
@@ -3239,7 +3235,8 @@ class ProjectGrantService implements UseGearmanJobLauncherService, UseOscarConfi
            } catch (\Exception $e) {
                throw new OscarException("Impossible d'ajouter le pôle '$label', " . $e->getMessage());
            }
        } else {
        }
        else {
            throw new OscarException("Le pôle '$label' existe déjà");
        }
    }
@@ -3258,7 +3255,8 @@ class ProjectGrantService implements UseGearmanJobLauncherService, UseOscarConfi
            } catch (\Exception $e) {
                throw new OscarException("Impossible d'ajouter la source de financement '$label', " . $e->getMessage());
            }
        } else {
        }
        else {
            throw new OscarException("La source de financement '$label' existe déjà");
        }
    }
@@ -3277,7 +3275,8 @@ class ProjectGrantService implements UseGearmanJobLauncherService, UseOscarConfi
            } catch (\Exception $e) {
                throw new OscarException("Impossible d'ajouter le type de contrat '$label', " . $e->getMessage());
            }
        } else {
        }
        else {
            throw new OscarException("Le type de contrat '$label' existe déjà");
        }
    }
@@ -3293,7 +3292,8 @@ class ProjectGrantService implements UseGearmanJobLauncherService, UseOscarConfi
        $repository = $this->getEntityManager()->getRepository(PcruTypeContract::class);
        if ($format == AsArrayFormatter::ARRAY_FLAT) {
            return $repository->getFlatArrayLabel();
        } else {
        }
        else {
            throw new OscarException("Format pour la liste des Type de contrat PCRU non-disponible");
        }
    }
@@ -3383,12 +3383,14 @@ class ProjectGrantService implements UseGearmanJobLauncherService, UseOscarConfi
        if ($format == AsArrayFormatter::ARRAY_FLAT) {
            if ($withEmptyAtFirst == true) {
                $array = ["Aucun"];
            } else {
            }
            else {
                $array = [];
            }
            $array = array_merge($array, $repository->getFlatArrayLabel());
            return $array;
        } else {
        }
        else {
            throw new OscarException("Format pour la liste des pôles de compétivité PCRU non-disponible");
        }
    }
@@ -3404,7 +3406,8 @@ class ProjectGrantService implements UseGearmanJobLauncherService, UseOscarConfi
        $repository = $this->getEntityManager()->getRepository(PcruSourceFinancement::class);
        if ($format == AsArrayFormatter::ARRAY_FLAT) {
            return $repository->getFlatArrayLabel();
        } else {
        }
        else {
            throw new OscarException("Format pour la liste des sources de financement PCRU non-disponible");
        }
    }
Loading