Untitled

mail@pastecode.io avatar
unknown
php
a year ago
2.0 kB
1
Indexable
Never
public function findUserByBaseInfo($criteria)
    {
        $nat_arr = array();
       $query = $this
            ->createQueryBuilder('u')
            ->select('u')
            ->where('u.roles = :role')
            ->setParameter('role', '["ROLE_USER"]');
            if(isset($criteria['sexe'])){
                $query->andWhere('u.sexe IN (:sx)')
                    ->setParameter('sx', $criteria['sexe']);
            }

        if(!empty($criteria['nat_a'])) {
            $nat_arr[] = $criteria['nat_a'];
        }
        if(!empty($criteria['nat_b'])) {
            $nat_arr[] = $criteria['nat_b'];
        }
        if((!empty($criteria['nat_a']) || !empty($criteria['nat_b'])) && !empty($criteria['nat_cond'])) {
            if($criteria['nat_cond'] == "et") {
                $query->andWhere('u.Nationalite IN (:nat)')
                    ->setParameter('nat', $nat_arr);
            }else if($criteria['nat_cond'] == "ou") {
                $query->andWhere('u.Nationalite = :nat_a OR u.Nationalite=:nat_b')
                    ->setParameter('nat_a', $criteria['nat_a'])
                    ->setParameter('nat_b', $criteria['nat_b']);
            }
        } else {
            if(!empty($nat_arr)){
                $query->andWhere('u.Nationalite IN (:nat)')
                    ->setParameter('nat', $nat_arr);
            }

        }


        if(!empty($criteria['min_age']) && !empty($criteria['max_age']))
        {
            $query->andWhere('u.Date_De_Naissance BETWEEN :max_age AND :min_age')
                ->setParameter('min_age', $this->userService->reverse_birthday($criteria['min_age']))
                ->setParameter('max_age', $this->userService->reverse_birthday($criteria['max_age']));
        }

        if(!empty($criteria['code_postal']))
        {
            $query->andWhere('u.Code_postal = :code_postal')
                ->setParameter('code_postal', $criteria['code_postal']);
        }

        return $query->getQuery()->getResult();

    }