Browse Source

Mise en place de la recherche tag strict.

bastien 13 years ago
parent
commit
7013b413f0

+ 1 - 0
app/Resources/translations/userui.fr.yml View File

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

+ 4 - 0
src/Muzich/CoreBundle/Form/Search/ElementSearchForm.php View File

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

+ 13 - 2
src/Muzich/CoreBundle/Repository/ElementRepository.php View File

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
    * @param ElementSearcher $searcher
34
    * @param ElementSearcher $searcher
31
    * @return Doctrine\ORM\Query
35
    * @return Doctrine\ORM\Query
32
    */
36
    */
67
     $join_tags  = '';
71
     $join_tags  = '';
68
     if (count(($tags = $searcher->getTags())))
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
       foreach ($tags as $tag_id => $tag_name)
81
       foreach ($tags as $tag_id => $tag_name)
71
       {
82
       {
72
         // LEFT JOIN car un element n'est pas obligatoirement lié a un/des tags
83
         // LEFT JOIN car un element n'est pas obligatoirement lié a un/des tags
79
         }
90
         }
80
         else
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
         $params_ids['tid'.$tag_id] = $tag_id;
95
         $params_ids['tid'.$tag_id] = $tag_id;
85
       }
96
       }

+ 5 - 0
src/Muzich/CoreBundle/Resources/views/SearchElement/form.html.twig View File

45
     'form_name'     : form_name
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
   {{ form_widget(search_form.tags, { 'attr': {'class': 'tagBox_tags_ids'} }) }}
53
   {{ form_widget(search_form.tags, { 'attr': {'class': 'tagBox_tags_ids'} }) }}
49
   {{ form_row(search_form._token) }}
54
   {{ form_row(search_form._token) }}

+ 27 - 3
src/Muzich/CoreBundle/Searcher/ElementSearcher.php View File

92
   protected $ids_display;
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
    * @see SearcherInterface
104
    * @see SearcherInterface
96
    * @param array $params 
105
    * @param array $params 
97
    */
106
    */
104
     
113
     
105
     // Mise a jour des attributs
114
     // Mise a jour des attributs
106
     $this->setAttributes(array(
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
     ), $params);
119
     ), $params);
109
     
120
     
110
   }
121
   }
117
   {
128
   {
118
     // Mise a jour des attributs
129
     // Mise a jour des attributs
119
     $this->setAttributes(array(
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
     ), $params);
134
     ), $params);
122
   }
135
   }
123
   
136
   
136
       'group_id'    => $this->getGroupId(),
149
       'group_id'    => $this->getGroupId(),
137
       'favorite'    => $this->isFavorite(),
150
       'favorite'    => $this->isFavorite(),
138
       'ids'         => $this->getIds(),
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
   {
245
   {
232
     return $this->ids_display;
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
    * Construction de l'objet Query
260
    * Construction de l'objet Query