Explorar el Código

Mise en place de la recherche tag strict.

bastien hace 12 años
padre
commit
7013b413f0

+ 1 - 0
app/Resources/translations/userui.fr.yml Ver fichero

@@ -75,6 +75,7 @@ filter:
75 75
   new_comments:     Nvx commentaires
76 76
   new_favoriteds:   Nvx favoris
77 77
   new_tags:         Propositions de tags
78
+  tag_strict:       Chaques tag doit être trouvé
78 79
   
79 80
 element_add:
80 81
   url:

+ 4 - 0
src/Muzich/CoreBundle/Form/Search/ElementSearchForm.php Ver fichero

@@ -17,6 +17,10 @@ class ElementSearchForm extends AbstractType
17 17
       ),
18 18
       'required' => true,
19 19
     ));
20
+    
21
+    $builder->add('tag_strict', 'checkbox', array(
22
+      'required'  => false
23
+    ));
20 24
         
21 25
     $builder->add('tags', 'hidden');
22 26
   }

+ 13 - 2
src/Muzich/CoreBundle/Repository/ElementRepository.php Ver fichero

@@ -26,7 +26,11 @@ class ElementRepository extends EntityRepository
26 26
   }
27 27
   
28 28
   /**
29
-   *
29
+   * TODO: Faire un bel objet pour gérer tout ça =)
30
+   * => Utiliser l'objet ElementSearcher (ou du moin réorganiser ça en plusieurs 
31
+   * objets)
32
+   * 
33
+   * 
30 34
    * @param ElementSearcher $searcher
31 35
    * @return Doctrine\ORM\Query
32 36
    */
@@ -67,6 +71,13 @@ class ElementRepository extends EntityRepository
67 71
     $join_tags  = '';
68 72
     if (count(($tags = $searcher->getTags())))
69 73
     {
74
+      // Recherche strict ou non ?
75
+      $strict_word = 'OR';
76
+      if ($searcher->getTagStrict())
77
+      {
78
+        $strict_word = 'AND';
79
+      }
80
+      
70 81
       foreach ($tags as $tag_id => $tag_name)
71 82
       {
72 83
         // LEFT JOIN car un element n'est pas obligatoirement lié a un/des tags
@@ -79,7 +90,7 @@ class ElementRepository extends EntityRepository
79 90
         }
80 91
         else
81 92
         {
82
-          $where_tags .= ' OR t_.id = :tid'.$tag_id;
93
+          $where_tags .= ' '.$strict_word.' t_.id = :tid'.$tag_id;
83 94
         }
84 95
         $params_ids['tid'.$tag_id] = $tag_id;
85 96
       }

+ 5 - 0
src/Muzich/CoreBundle/Resources/views/SearchElement/form.html.twig Ver fichero

@@ -45,5 +45,10 @@
45 45
     'form_name'     : form_name
46 46
   } %}
47 47
   
48
+  <div>
49
+  {{ form_widget(search_form.tag_strict) }}
50
+      <label for="element_search_form_tag_strict">{{ 'filter.tag_strict'|trans({}, 'userui') }}</label>
51
+  </div>
52
+
48 53
   {{ form_widget(search_form.tags, { 'attr': {'class': 'tagBox_tags_ids'} }) }}
49 54
   {{ form_row(search_form._token) }}

+ 27 - 3
src/Muzich/CoreBundle/Searcher/ElementSearcher.php Ver fichero

@@ -92,6 +92,15 @@ class ElementSearcher extends Searcher implements SearcherInterface
92 92
   protected $ids_display;
93 93
   
94 94
   /**
95
+   * Ce booléen permet de savoir si la recherche de tag est stricte.
96
+   * Si elle est stricte chaque tag choisis devrons être attaché au partage
97
+   * pour qu'il soit pris en compte.
98
+   *  
99
+   * @var type boolean
100
+   */
101
+  protected $tag_strict = false;
102
+  
103
+  /**
95 104
    * @see SearcherInterface
96 105
    * @param array $params 
97 106
    */
@@ -104,7 +113,9 @@ class ElementSearcher extends Searcher implements SearcherInterface
104 113
     
105 114
     // Mise a jour des attributs
106 115
     $this->setAttributes(array(
107
-      'network', 'tags', 'count', 'user_id', 'group_id', 'favorite', 'id_limit', 'searchnew', 'ids', 'ids_display'
116
+      'network', 'tags', 'count', 'user_id', 'group_id', 
117
+      'favorite', 'id_limit', 'searchnew', 'ids', 'ids_display',
118
+      'tag_strict'
108 119
     ), $params);
109 120
     
110 121
   }
@@ -117,7 +128,9 @@ class ElementSearcher extends Searcher implements SearcherInterface
117 128
   {
118 129
     // Mise a jour des attributs
119 130
     $this->setAttributes(array(
120
-      'network', 'tags', 'count', 'user_id', 'group_id', 'favorite', 'id_limit', 'searchnew', 'ids', 'ids_display'
131
+      'network', 'tags', 'count', 'user_id', 'group_id', 
132
+      'favorite', 'id_limit', 'searchnew', 'ids', 'ids_display',
133
+      'tag_strict'
121 134
     ), $params);
122 135
   }
123 136
   
@@ -136,7 +149,8 @@ class ElementSearcher extends Searcher implements SearcherInterface
136 149
       'group_id'    => $this->getGroupId(),
137 150
       'favorite'    => $this->isFavorite(),
138 151
       'ids'         => $this->getIds(),
139
-      'ids_display' => $this->getIdsDisplay()
152
+      'ids_display' => $this->getIdsDisplay(),
153
+      'tag_strict'  => $this->getTagStrict()
140 154
     );
141 155
   }
142 156
   
@@ -231,6 +245,16 @@ class ElementSearcher extends Searcher implements SearcherInterface
231 245
   {
232 246
     return $this->ids_display;
233 247
   }
248
+  
249
+  public function setTagStrict($strict)
250
+  {
251
+    $this->tag_strict = $strict;
252
+  }
253
+  
254
+  public function getTagStrict()
255
+  {
256
+    return $this->tag_strict;
257
+  }
234 258
 
235 259
   /**
236 260
    * Construction de l'objet Query