I'm in a Symfony2 project.

My main goal is to create a search bar, that displays over a table that
shows query result. In this bar, user can choose a field and a value to
make a filter.

Something like this [image: Imágenes integradas 1]

When user does that, I make an ajax call, where I recreate the query and
then this class adds should add the filter.

It should be a stand alone class that I could include in any of my projects.

If I do this inside a repository, I'll have to copy this function in each
one of the repositorys. Or I'm wrong ?





2014-04-03 23:56 GMT+02:00 Marco Pivetta <[email protected]>:

> No, I was more wondering why you are fiddling around with a query builder
> *outside* a repository. Where are you manipulating the QueryBuilder? And
> why?
>
> Marco Pivetta
>
> http://twitter.com/Ocramius
>
> http://ocramius.github.com/
>
>
> On 3 April 2014 21:09, Andres Lartigue Debian <[email protected]>wrote:
>
>> Thanks for your answer,
>>
>> Yes, that's why I'm sending $repository as a parameter.
>> Actually $repository  is an instance of the root class repository.
>>
>>
>>
>> 2014-04-03 18:40 GMT+02:00 Marco Pivetta <[email protected]>:
>>
>>> Hi Andres,
>>>
>>> Why would you want this logic to act out of the scope of a repository?
>>>
>>> Marco Pivetta
>>>
>>> http://twitter.com/Ocramius
>>>
>>> http://ocramius.github.com/
>>>
>>>
>>> On 3 April 2014 07:40, Andres Lartigue Debian <[email protected]
>>> > wrote:
>>>
>>>> Hello,
>>>>
>>>> I'm writing a class that's able to add filters to a given query builder.
>>>>
>>>> I'm having a problem when I want to add a filter in a field that's not
>>>> a part of the root class of the query, because I don't know the alias name
>>>> of the related class.
>>>>
>>>> I've used query builder getDQLPart function to retrieve all query
>>>> joins. This returns an array where I get the join alias, and the relation
>>>> name, but it doesn't tell me the name of the related class.
>>>>
>>>> I think it's possible to get the name of the related class by reading
>>>> Doctrine model information but I couldn't find a way to do this properly.
>>>>
>>>> The way I found is to rewrite a function that's in the
>>>> Doctrine\ORM\EntityRepository class : getClassMetadata()
>>>>
>>>> This function is declared as protected, If I modify it to make it
>>>> public, I'm able to achieve what I'm looking for.
>>>>
>>>> Of course, this is not a good solution, and my question is if there's
>>>> another way to implement this functionnality.
>>>>
>>>> This is the code I'm using to write my function
>>>>
>>>>     public static function getQueryAlias($qb, $attdef, $repository){
>>>>
>>>>         $relationName = '';
>>>>         $classmetadata = $repository->getClassMetadata();
>>>>         foreach ($classmetadata->getAssociationMappings() as $key =>
>>>> $relation){
>>>>             //$attdef is an array with fields definitions I use to set
>>>> up filters. $attdef['name'] matchs doctrine fieldname
>>>>             if($relation['fieldName'] == $attdef['name']){
>>>>                 $relationName = $key;
>>>>             }
>>>>         }
>>>>
>>>>         if($relationName != ''){
>>>>             foreach ($qb->getDQLPart('join') as $joins){
>>>>                 foreach($joins as $join){
>>>>                     $arr = explode('.', $join->getJoin( ));
>>>>                     if($arr[1] == $relationName){
>>>>                         return $join->getAlias();
>>>>                     }
>>>>                 }
>>>>
>>>>             }
>>>>         }
>>>>         return false;
>>>>     }
>>>>
>>>> Thanks for your answers
>>>>
>>>> Andrés
>>>>
>>>> --
>>>> You received this message because you are subscribed to the Google
>>>> Groups "doctrine-user" group.
>>>> To unsubscribe from this group and stop receiving emails from it, send
>>>> an email to [email protected].
>>>>
>>>> To post to this group, send email to [email protected].
>>>> Visit this group at http://groups.google.com/group/doctrine-user.
>>>> For more options, visit https://groups.google.com/d/optout.
>>>>
>>>
>>>  --
>>> You received this message because you are subscribed to a topic in the
>>> Google Groups "doctrine-user" group.
>>> To unsubscribe from this topic, visit
>>> https://groups.google.com/d/topic/doctrine-user/wHHa4b-WBD0/unsubscribe.
>>> To unsubscribe from this group and all its topics, send an email to
>>> [email protected].
>>>
>>> To post to this group, send email to [email protected].
>>> Visit this group at http://groups.google.com/group/doctrine-user.
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>
>>
>> --
>> Andrés Lartigue Debián
>> Binova Services Informatiques <http://www.binova-it.fr/>
>> Parc Technologique des rives de l'Oise
>> Rue les rives de l'Oise BP 50149
>> 60201 Compiègne Cédex
>> +33 (0)3.44.90.79.60
>> +33 (0)6.24.84.03.30
>>
>> <http://www.club-des-entrepreneurs.fr/>
>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "doctrine-user" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected].
>> To post to this group, send email to [email protected].
>> Visit this group at http://groups.google.com/group/doctrine-user.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>  --
> You received this message because you are subscribed to a topic in the
> Google Groups "doctrine-user" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/doctrine-user/wHHa4b-WBD0/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/doctrine-user.
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Andrés Lartigue Debián
Binova Services Informatiques <http://www.binova-it.fr/>
Parc Technologique des rives de l'Oise
Rue les rives de l'Oise BP 50149
60201 Compiègne Cédex
+33 (0)3.44.90.79.60
+33 (0)6.24.84.03.30

<http://www.club-des-entrepreneurs.fr/>

-- 
You received this message because you are subscribed to the Google Groups 
"doctrine-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/doctrine-user.
For more options, visit https://groups.google.com/d/optout.

<<inline: image.png>>

Reply via email to