Browse Source

Evolution #166: La recherche

bastien 12 years ago
parent
commit
fe604a801a

+ 1 - 1
src/Muzich/CoreBundle/Controller/CoreController.php View File

669
    * supprime cette configuration de façon a ce que le chercheur fonctionne 
669
    * supprime cette configuration de façon a ce que le chercheur fonctionne 
670
    * normalement.
670
    * normalement.
671
    * 
671
    * 
672
-   * @return type 
672
+   * @return \Symfony\Component\HttpFoundation\Response 
673
    */
673
    */
674
   public function filterRemoveIdsAction()
674
   public function filterRemoveIdsAction()
675
   {
675
   {

+ 43 - 0
src/Muzich/CoreBundle/Controller/SearchController.php View File

10
 use Symfony\Component\HttpFoundation\Response;
10
 use Symfony\Component\HttpFoundation\Response;
11
 use Muzich\CoreBundle\Util\TagLike;
11
 use Muzich\CoreBundle\Util\TagLike;
12
 
12
 
13
+use Symfony\Component\HttpFoundation\Request;
14
+use Muzich\CoreBundle\Searcher\GlobalSearcher;
15
+
13
 class SearchController extends Controller
16
 class SearchController extends Controller
14
 {
17
 {
15
   
18
   
269
     throw $this->createNotFoundException('Cette ressource n\'est pas accessible');
272
     throw $this->createNotFoundException('Cette ressource n\'est pas accessible');
270
   }
273
   }
271
   
274
   
275
+  /**
276
+   * Retourne une réponse contenant le dom du formulaire de recherche global
277
+   * 
278
+   * @return \Symfony\Component\HttpFoundation\Response 
279
+   */
280
+  public function renderGlobalSearchFormAction()
281
+  {
282
+    return $this->render(
283
+      'MuzichCoreBundle:GlobalSearch:form.html.twig', 
284
+      array('form' => $this->getGlobalSearchForm()->createView())
285
+    );
286
+  }
287
+  
288
+  /**
289
+   * Page d'affichage des résultats pour une recherche globale.
290
+   * * Users
291
+   * * Groups
292
+   * * Partages
293
+   * 
294
+   * @return \Symfony\Component\HttpFoundation\Response
295
+   * @Template("MuzichCoreBundle:GlobalSearch:results.html.twig")
296
+   */
297
+  public function globalAction(Request $request)
298
+  {
299
+    $form = $this->getGlobalSearchForm($searcher = new GlobalSearcher());
300
+    $form->bindRequest($request);
301
+    $results = array(
302
+      'users'  => null,
303
+      'groups' => null
304
+    );
305
+    if ($form->isValid())
306
+    {
307
+      $results = $searcher->getResults($this->getDoctrine());
308
+    }
309
+    return array(
310
+      'form' => $form->createView(),
311
+      'results'     => $results
312
+    );
313
+  }
314
+  
272
 }
315
 }

+ 10 - 1
src/Muzich/CoreBundle/Resources/config/routing.yml View File

130
   pattern: /ajax/element/proposed/tags/refuses/{element_id}/{token}
130
   pattern: /ajax/element/proposed/tags/refuses/{element_id}/{token}
131
   defaults: { _controller: MuzichCoreBundle:Element:proposedTagsRefuse }
131
   defaults: { _controller: MuzichCoreBundle:Element:proposedTagsRefuse }
132
   
132
   
133
+## search
134
+  
135
+global_search:
136
+  pattern:  /search
137
+  defaults: { _controller: MuzichCoreBundle:Search:global }
138
+  
139
+  
133
 ## lol
140
 ## lol
134
 
141
 
135
 teapot:
142
 teapot:
136
   pattern: /what/are/you
143
   pattern: /what/are/you
137
-  defaults: { _controller: MuzichCoreBundle:Info:teapot }
144
+  defaults: { _controller: MuzichCoreBundle:Info:teapot }
145
+  
146
+  

+ 12 - 0
src/Muzich/CoreBundle/Resources/views/GlobalSearch/form.html.twig View File

1
+<form action="{{ path('global_search') }}" method="post" {{ form_enctype(form) }}>
2
+    
3
+  {% form_theme form 'MuzichCoreBundle:Form:errors.html.twig' %}
4
+  {{ form_errors(form) }}
5
+
6
+  {{ form_errors(form.string) }}
7
+  {{ form_widget(form.string) }}
8
+  <input type="submit" class="button" value="{{ 'search.form.submit_value'|trans({}, 'network') }}" />
9
+  
10
+  {{ form_rest(form) }}
11
+
12
+</form>

+ 43 - 0
src/Muzich/CoreBundle/Resources/views/GlobalSearch/results.html.twig View File

1
+{% extends "MuzichCoreBundle::layout.html.twig" %}
2
+
3
+{% block title %}Recherche{% endblock %}
4
+
5
+{% block main_content %}
6
+
7
+  {% include "MuzichCoreBundle:Menu:containerMenu.html.twig" with {'active': null} %}
8
+  
9
+  {% include "MuzichCoreBundle:GlobalSearch:form.html.twig" with {'form': form } %}
10
+  
11
+  {% if results.users|length or results.groups|length %}
12
+  
13
+    {% if results.users %}
14
+
15
+      <b>{{ 'search.users'|trans({}, 'network') }}</b>
16
+      
17
+      <ul id="search_users" class="inline">
18
+      {% for user in results.users %} 
19
+        <li>
20
+          <a href="{{ path('show_user', { 'slug': user.slug }) }}">{{ user.username }}</a>
21
+        </li>
22
+      {% endfor %}
23
+      </ul>
24
+
25
+    {% endif %}
26
+  
27
+    {% if results.groups %}
28
+
29
+      <b>{{ 'search.groups'|trans({}, 'network') }}</b>
30
+      
31
+      <ul id="search_groups" class="inline">
32
+      {% for group in results.groups %} 
33
+        <li>
34
+          <a href="{{ path('show_group', { 'slug': group.slug }) }}">{{ group.name }}</a>
35
+        </li>
36
+      {% endfor %}
37
+      </ul>
38
+
39
+    {% endif %}
40
+  
41
+  {% endif %}
42
+
43
+{% endblock %}

+ 114 - 0
src/Muzich/CoreBundle/Searcher/GlobalSearcher.php View File

1
+<?php
2
+
3
+namespace Muzich\CoreBundle\Searcher;
4
+
5
+use Symfony\Component\Validator\Constraints as Assert;
6
+use Symfony\Bundle\DoctrineBundle\Registry;
7
+
8
+/**
9
+ * 
10
+ */
11
+class GlobalSearcher extends Searcher implements SearcherInterface
12
+{
13
+  
14
+  /**
15
+   * Chaine de caractère représentant la recherche.
16
+   * 
17
+   * @var string
18
+   * @Assert\NotBlank()
19
+   * @Assert\Type("string")
20
+   * @Assert\MinLength(3)
21
+   */
22
+  protected $string;
23
+  
24
+  /**
25
+   * @see SearcherInterface
26
+   * @param array $params 
27
+   */
28
+  public function init($params)
29
+  {
30
+    // Control des parametres transmis.
31
+    $this->checkParams($params, array(
32
+      'string' => "Muzich\CoreBundle\Searcher\GlobalSearch::init():"
33
+        ." \$params: Un string est nécéssaire"
34
+    ));
35
+    
36
+    // Mise a jour des attributs
37
+    $this->setAttributes(array('string', 'min_lenght'), $params);
38
+  }
39
+  
40
+  /**
41
+   * @see SearcherInterface
42
+   * @param array $params 
43
+   */
44
+  public function update($params)
45
+  {
46
+    // Mise a jour des attributs
47
+    $this->setAttributes(array(
48
+      'string', 'min_length'
49
+    ), $params);
50
+  }
51
+  
52
+  /**
53
+   * @see SearcherInterface
54
+   * 
55
+   * @return array 
56
+   */
57
+  public function getParams()
58
+  {
59
+    return array(
60
+      'string' => $this->string,
61
+      'min_length' => $this->min_length
62
+    );
63
+  }
64
+  
65
+  public function getString()
66
+  {
67
+    return $this->string;
68
+  }
69
+  
70
+  public function setString($string)
71
+  {
72
+    $this->string = $string;
73
+  }
74
+  
75
+  /**
76
+   * Retourne les user et groupes correspondant a la recherche
77
+   *
78
+   * @param Registry $doctrine
79
+   * @return array
80
+   */
81
+  public function getResults(Registry $doctrine)
82
+  {
83
+    
84
+    // instancier objet SearchUser and groups;
85
+    // puis faire recherche sur elements
86
+    
87
+    // On remplace le caratcère '%' au cas ou un malin l'insére.
88
+    $string = str_replace('%', '#', $this->string);
89
+    
90
+    $users = $doctrine
91
+      ->getRepository('MuzichCoreBundle:User')
92
+      ->findByString($string)
93
+      ->execute()
94
+    ;
95
+    
96
+    $groups = $doctrine
97
+      ->getRepository('MuzichCoreBundle:Group')
98
+      ->findByString($string)
99
+      ->execute()
100
+    ;
101
+    
102
+    return array(
103
+      'users'  => $users,
104
+      'groups' => $groups
105
+    );
106
+  }
107
+  
108
+  
109
+  
110
+  
111
+  
112
+  
113
+  
114
+}

+ 18 - 0
src/Muzich/CoreBundle/lib/Controller.php View File

8
 use Muzich\CoreBundle\Form\Search\ElementSearchForm;
8
 use Muzich\CoreBundle\Form\Search\ElementSearchForm;
9
 use Muzich\CoreBundle\Form\Element\ElementAddForm;
9
 use Muzich\CoreBundle\Form\Element\ElementAddForm;
10
 use Symfony\Component\HttpFoundation\Response;
10
 use Symfony\Component\HttpFoundation\Response;
11
+use Muzich\CoreBundle\Searcher\GlobalSearcher;
11
 
12
 
12
 class Controller extends BaseController
13
 class Controller extends BaseController
13
 {
14
 {
289
   }
290
   }
290
   
291
   
291
   /**
292
   /**
293
+   * Retourne l'objet Form du formulaire de recherche global.
294
+   * 
295
+   * @return \Symfony\Component\Form\Form 
296
+   */
297
+  protected function getGlobalSearchForm($searcher = null)
298
+  {
299
+    if ($searcher === null)
300
+    {
301
+      $searcher = new GlobalSearcher();
302
+    }
303
+    
304
+    return $this->createFormBuilder($searcher)
305
+      ->add('string', 'text')
306
+    ->getForm();
307
+  }
308
+  
309
+  /**
292
    * Retourne le formulaire d'ajout d'élément
310
    * Retourne le formulaire d'ajout d'élément
293
    * 
311
    * 
294
    * @param \Muzich\CoreBundle\Searcher\Searcher $search_object
312
    * @param \Muzich\CoreBundle\Searcher\Searcher $search_object

+ 0 - 40
src/Muzich/MynetworkBundle/Controller/MynetworkController.php View File

67
     return $followers_users_new;
67
     return $followers_users_new;
68
   }
68
   }
69
   
69
   
70
-  /**
71
-   * Action qui affiche la page de recherche, et effectue la recherche
72
-   * d'utilisateurs et de groupes.
73
-   * 
74
-   * @Template()
75
-   */
76
-  public function searchAction()
77
-  {
78
-    $request = $this->getRequest();
79
-    $search = new UserAndGroupSearcher();
80
-    $results = array('users' => null, 'groups' => null);
81
-    
82
-    $search_form = $this->createFormBuilder($search)
83
-      ->add('string', 'text')
84
-    ->getForm();
85
-    
86
-    // Si l'utilisateur effectue la recherche
87
-    if ($request->getMethod() == 'POST')
88
-    {
89
-      $search_form->bindRequest($request);
90
-      if ($search_form->isValid())
91
-      {
92
-        $results = $search->getResults($this->getDoctrine());
93
-      }
94
-    }
95
-    
96
-    if ($this->getRequest()->isXmlHttpRequest())
97
-    {
98
-      
99
-    }
100
-    else
101
-    {
102
-      return array(
103
-        'search_form' => $search_form->createView(),
104
-        'results'     => $results,
105
-        'search_done' => $search->getString() ? true : false
106
-      );
107
-    }
108
-  }
109
-  
110
 }
70
 }

+ 0 - 9
src/Muzich/MynetworkBundle/Resources/config/routing.yml View File

1
-
2
 mynetwork_index:
1
 mynetwork_index:
3
   pattern:  /my-network/{event_id}
2
   pattern:  /my-network/{event_id}
4
   defaults: { _controller: MuzichMynetworkBundle:Mynetwork:index, event_id: null }
3
   defaults: { _controller: MuzichMynetworkBundle:Mynetwork:index, event_id: null }
5
   requirements:
4
   requirements:
6
     event_id:  \d+
5
     event_id:  \d+
7
-  
8
-mynetwork_search:
9
-  pattern:  /my-network/search
10
-  defaults: { _controller: MuzichMynetworkBundle:Mynetwork:search }
11
-  
12
-#mynetwork_search:
13
-#  pattern:  /my-network/search/do
14
-#  defaults: { _controller: MuzichMynetworkBundle:Mynetwork:search }
15
   
6
   

+ 0 - 4
src/Muzich/MynetworkBundle/Resources/views/Mynetwork/index.html.twig View File

3
 {% block title %}Mon réseau{% endblock %}
3
 {% block title %}Mon réseau{% endblock %}
4
 
4
 
5
 {% block content %}
5
 {% block content %}
6
-
7
-  <a class="link_navigation" href="{{ path('mynetwork_search') }}" >
8
-    {{ 'search.search'|trans({}, 'network') }}
9
-  </a>
10
   
6
   
11
   {% if followeds_users %}
7
   {% if followeds_users %}
12
     <b>{{ 'users'|trans({}, 'network') }}</b>
8
     <b>{{ 'users'|trans({}, 'network') }}</b>

+ 0 - 64
src/Muzich/MynetworkBundle/Resources/views/Mynetwork/search.html.twig View File

1
-{% extends "MuzichMynetworkBundle::layout.html.twig" %}
2
-
3
-{% block title %}Mon réseau{% endblock %}
4
-
5
-{% block content %}
6
-
7
-  <a class="link_navigation" href="{{ path('mynetwork_index') }}" >
8
-    {{ 'search.return'|trans({}, 'network') }}
9
-  </a>
10
-  
11
-  <b>{{ 'search.search_u_n_g'|trans({}, 'network') }}</b>
12
-  
13
-  <form action="{{ path('mynetwork_search') }}" method="post" {{ form_enctype(search_form) }}>
14
-    
15
-    {% form_theme search_form 'MuzichCoreBundle:Form:errors.html.twig' %}
16
-    {{ form_errors(search_form) }}
17
-
18
-    <div class="field">
19
-      {{ form_errors(search_form.string) }}
20
-      {{ form_widget(search_form.string) }}
21
-      <input type="submit" class="button" value="{{ 'search.form.submit_value'|trans({}, 'network') }}" />
22
-    </div>
23
-
24
-    {{ form_rest(search_form) }}
25
-
26
-  </form>
27
-  
28
-  {% if results.users|length or results.groups|length %}
29
-  
30
-    {% if results.users %}
31
-
32
-      <b>{{ 'search.users'|trans({}, 'network') }}</b>
33
-      
34
-      <ul id="search_users" class="inline">
35
-      {% for user in results.users %} 
36
-        <li>
37
-          <a href="{{ path('show_user', { 'slug': user.slug }) }}">{{ user.username }}</a>
38
-        </li>
39
-      {% endfor %}
40
-      </ul>
41
-
42
-    {% endif %}
43
-  
44
-    {% if results.groups %}
45
-
46
-      <b>{{ 'search.groups'|trans({}, 'network') }}</b>
47
-      
48
-      <ul id="search_groups" class="inline">
49
-      {% for group in results.groups %} 
50
-        <li>
51
-          <a href="{{ path('show_group', { 'slug': group.slug }) }}">{{ group.name }}</a>
52
-        </li>
53
-      {% endfor %}
54
-      </ul>
55
-
56
-    {% endif %}
57
-  
58
-  {% elseif search_done %}
59
-      
60
-      <p>{{ 'search.no_result'|trans({}, 'network') }}</p>
61
-      
62
-  {% endif %}
63
-
64
-{% endblock %}

+ 6 - 0
src/Muzich/UserBundle/Resources/views/Account/topBar.html.twig View File

1
 
1
 
2
 {% if is_granted("IS_AUTHENTICATED_REMEMBERED") %}
2
 {% if is_granted("IS_AUTHENTICATED_REMEMBERED") %}
3
+
4
+  <div id="top_search">
5
+    {% render "MuzichCoreBundle:Search:renderGlobalSearchForm" %}
6
+  </div>
7
+
3
   <div id="top_bar">
8
   <div id="top_bar">
4
 
9
 
5
     <a href="{{ path('my_account') }}" >
10
     <a href="{{ path('my_account') }}" >
11
     </a>
16
     </a>
12
 
17
 
13
   </div>
18
   </div>
19
+
14
 {% endif %}
20
 {% endif %}

+ 33 - 0
web/bundles/muzichcore/css/main.css View File

217
 	text-align: center;
217
 	text-align: center;
218
 }
218
 }
219
 
219
 
220
+#top_search
221
+{
222
+  float: left;
223
+  width: 207px;
224
+  background-color: white;
225
+  padding: 0px;
226
+  
227
+  margin-left: auto;
228
+  margin-right: auto;
229
+  
230
+  border-radius: 0px 0px 4px 4px;
231
+  -moz-border-radius: 0px 0px 4px 4px;
232
+  -webkit-border-radius: 0px 0px 4px 4px;
233
+  
234
+	text-align: center;
235
+}
236
+
237
+#top_search input[type="text"]
238
+{
239
+  font-size: 12px;
240
+  height: 12px;
241
+  width: 120px;
242
+}
243
+
244
+#top_search  input[type="submit"]
245
+{
246
+  font-size: 12px;
247
+  height: 16px;
248
+  padding: 0 2px 1px;
249
+}
250
+
251
+
252
+
220
 #top_bar a 
253
 #top_bar a 
221
 {
254
 {
222
   text-decoration: none;
255
   text-decoration: none;