Procházet zdrojové kódy

Evolution #91: Favoris: Nouvelle présentation: Inclusion sur les pages show.

bastien před 13 roky
rodič
revize
41763d9723

+ 19 - 0
src/Muzich/CoreBundle/Repository/GroupRepository.php Zobrazit soubor

@@ -71,5 +71,24 @@ class GroupRepository extends EntityRepository
71 71
     return $group_array;
72 72
   }
73 73
   
74
+  /**
75
+   * Retourne tous les tags des elements postés
76
+   * 
77
+   * @return doctrine_collection
78
+   */
79
+  public function getElementsTags($group_id)
80
+  {
81
+    return $this->getEntityManager()
82
+      ->createQuery('
83
+        SELECT t FROM MuzichCoreBundle:Tag t
84
+        LEFT JOIN t.elements e
85
+        WHERE e.group = :gid
86
+        ORDER BY t.name ASC'
87
+      )
88
+      ->setParameter('gid', $group_id)
89
+      ->getResult()
90
+    ;
91
+  }
92
+  
74 93
 }
75 94
   

+ 19 - 0
src/Muzich/CoreBundle/Repository/UserRepository.php Zobrazit soubor

@@ -180,5 +180,24 @@ class UserRepository extends EntityRepository
180 180
     return $result[1];
181 181
   }
182 182
   
183
+  /**
184
+   * Retourne tous les tags des elements postés
185
+   * 
186
+   * @return doctrine_collection
187
+   */
188
+  public function getElementsTags($user_id)
189
+  {
190
+    return $this->getEntityManager()
191
+      ->createQuery('
192
+        SELECT t FROM MuzichCoreBundle:Tag t
193
+        LEFT JOIN t.elements e
194
+        WHERE e.owner = :uid
195
+        ORDER BY t.name ASC'
196
+      )
197
+      ->setParameter('uid', $user_id)
198
+      ->getResult()
199
+    ;
200
+  }
201
+  
183 202
 }
184 203
   

src/Muzich/CoreBundle/Resources/views/Tag/tagsList.html.twig → src/Muzich/CoreBundle/Resources/views/Tag/tagsList.favorite.html.twig Zobrazit soubor

@@ -1,5 +1,8 @@
1 1
 {% if tags|length %}
2
-  <input type="hidden" id="get_elements_url" value="{{ path('favorite_get', {'user_id': user_id, 'tags_ids_json' : ''}) }}" />
2
+  <input type="hidden" id="get_elements_url" value="{{ path('favorite_get', {
3
+    'user_id': user_id, 
4
+    'tags_ids_json' : ''
5
+  }) }}" />
3 6
   <ul id="favorite_tags">
4 7
     {% for tag in tags %}
5 8
       <li>

+ 17 - 0
src/Muzich/CoreBundle/Resources/views/Tag/tagsList.show.html.twig Zobrazit soubor

@@ -0,0 +1,17 @@
1
+{% if tags|length %}
2
+  <input type="hidden" id="get_elements_url" value="{{ path('show_elements_get', {
3
+    'type'          : object_type,
4
+    'object_id'     : object_id, 
5
+    'tags_ids_json' : ''
6
+  }) }}" />
7
+  <ul id="favorite_tags">
8
+    {% for tag in tags %}
9
+      <li>
10
+        <a href="#{{ tag.id }}" class="button tag">
11
+          {{ tag.name }}
12
+        </a>
13
+      </li>
14
+    {% endfor %}
15
+  </ul>
16
+  <div class="clearboth" ></div>
17
+{% endif %}

+ 1 - 1
src/Muzich/FavoriteBundle/Controller/FavoriteController.php Zobrazit soubor

@@ -216,7 +216,7 @@ class FavoriteController extends Controller
216 216
       'elements'
217 217
     );
218 218
     
219
-    $elements = $search_object->getElements($this->getDoctrine(), $user_id);
219
+    $elements = $search_object->getElements($this->getDoctrine(), $this->getUserId());
220 220
     $count = count($elements);
221 221
     $html = '';
222 222
     if ($count)

+ 0 - 1
src/Muzich/FavoriteBundle/Resources/config/routing.yml Zobrazit soubor

@@ -15,7 +15,6 @@ favorite_user_list:
15 15
   pattern:   /user/{slug}/favorites
16 16
   defaults: { _controller: MuzichFavoriteBundle:Favorite:userList }
17 17
 
18
-# post
19 18
 favorite_get:
20 19
   pattern:   /favorites/{user_id}/getElements/{tags_ids_json}/{id_limit}/{invert}
21 20
   defaults: { _controller: MuzichFavoriteBundle:Favorite:getElements, id_limit: null, invert: false }

+ 1 - 1
src/Muzich/FavoriteBundle/Resources/views/Favorite/myList.html.twig Zobrazit soubor

@@ -12,7 +12,7 @@
12 12
 
13 13
   <h2>{{ 'favorites.your_favorites'|trans({}, 'network') }}</h2>
14 14
 
15
-  {% include "MuzichCoreBundle:Tag:tagsList.html.twig" with {
15
+  {% include "MuzichCoreBundle:Tag:tagsList.favorite.html.twig" with {
16 16
     'user_id' : app.user.id
17 17
   } %}
18 18
   

+ 1 - 1
src/Muzich/FavoriteBundle/Resources/views/Favorite/userList.html.twig Zobrazit soubor

@@ -12,7 +12,7 @@
12 12
 
13 13
   <h2>{{ 'favorites.user_favorites'|trans({'%name%' : viewed_user.name}, 'network') }}</h2>
14 14
 
15
-  {% include "MuzichCoreBundle:Tag:tagsList.html.twig" with {
15
+  {% include "MuzichCoreBundle:Tag:tagsList.favorite.html.twig" with {
16 16
     'user_id' : viewed_user.id
17 17
   } %}
18 18
 

+ 80 - 6
src/Muzich/HomeBundle/Controller/ShowController.php Zobrazit soubor

@@ -6,6 +6,7 @@ use Muzich\CoreBundle\lib\Controller;
6 6
 use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
7 7
 use Muzich\CoreBundle\Form\Element\ElementAddForm;
8 8
 use Muzich\CoreBundle\Entity\Element;
9
+use Muzich\CoreBundle\Searcher\ElementSearcher;
9 10
 
10 11
 class ShowController extends Controller
11 12
 {
@@ -25,13 +26,25 @@ class ShowController extends Controller
25 26
       'count'    => ($count)?$count:$this->container->getParameter('search_default_count')
26 27
     ));
27 28
     
29
+    $tags = $this->getDoctrine()->getRepository('MuzichCoreBundle:User')
30
+      ->getElementsTags($viewed_user->getId())      
31
+    ;
32
+    
33
+    $tags_id = array();
34
+    foreach ($tags as $tag)
35
+    {
36
+      $tags_id[] = $tag->getId();
37
+    }
38
+    
28 39
     return array(
29
-      'viewed_user' => $viewed_user,
30
-      'elements'    => $search_object->getElements($this->getDoctrine(), $this->getUserId()),
31
-      'following'   => $this->getUser()->isFollowingUserByQuery($this->getDoctrine(), $viewed_user->getId()),
32
-      'user'        => $this->getUser(),
33
-      'more_count'  => ($count)?$count+$this->container->getParameter('search_default_count'):$this->container->getParameter('search_default_count')*2,
34
-      'more_route'  => 'show_user_more'
40
+      'tags'          => $tags,
41
+      'tags_id_json'  => json_encode($tags_id),
42
+      'viewed_user'   => $viewed_user,
43
+      'elements'      => $search_object->getElements($this->getDoctrine(), $this->getUserId()),
44
+      'following'     => $this->getUser()->isFollowingUserByQuery($this->getDoctrine(), $viewed_user->getId()),
45
+      'user'          => $this->getUser(),
46
+      'more_count'    => ($count)?$count+$this->container->getParameter('search_default_count'):$this->container->getParameter('search_default_count')*2,
47
+      'more_route'    => 'show_user_more'
35 48
     );
36 49
   }
37 50
   
@@ -56,7 +69,19 @@ class ShowController extends Controller
56 69
       $add_form = $this->getAddForm();
57 70
     }
58 71
     
72
+    $tags = $this->getDoctrine()->getRepository('MuzichCoreBundle:Group')
73
+      ->getElementsTags($group->getId())      
74
+    ;
75
+    
76
+    $tags_id = array();
77
+    foreach ($tags as $tag)
78
+    {
79
+      $tags_id[] = $tag->getId();
80
+    }
81
+    
59 82
     return array(
83
+      'tags'          => $tags,
84
+      'tags_id_json'  => json_encode($tags_id),
60 85
       'group'         => $group,
61 86
       'his_group'     => ($group->getOwner()->getId() == $this->getUserId()) ? true : false,
62 87
       'elements'      => $search_object->getElements($this->getDoctrine(), $this->getUserId()),
@@ -69,4 +94,53 @@ class ShowController extends Controller
69 94
     );
70 95
   }
71 96
   
97
+  public function getElementsAction($type, $object_id, $tags_ids_json, $id_limit = null, $invert = false)
98
+  {
99
+    $object_id = null;
100
+    if ($type != 'user' && $type != 'group')
101
+    {
102
+      throw new \Exception("Wrong Type.");
103
+    }
104
+    
105
+    $tag_ids = json_decode($tags_ids_json);
106
+    $search_object = new ElementSearcher();
107
+    
108
+    $tags = array();
109
+    foreach ($tag_ids as $id)
110
+    {
111
+      $tags[$id] = $id;
112
+    }
113
+    
114
+    $search_object->init(array(
115
+      'tags'       => $tags,
116
+      $type.'_id'  => $object_id,
117
+      'count'      => $this->container->getParameter('search_default_count'),
118
+      'id_limit'   => $id_limit
119
+    ));
120
+    
121
+    $message = $this->trans(
122
+      'elements.ajax.more.noelements', 
123
+      array(), 
124
+      'elements'
125
+    );
126
+    
127
+    $elements = $search_object->getElements($this->getDoctrine(), $this->getUserId());
128
+    $count = count($elements);
129
+    $html = '';
130
+    if ($count)
131
+    {
132
+      $html = $this->render('MuzichCoreBundle:SearchElement:default.html.twig', array(
133
+        'user'        => $this->getUser(),
134
+        'elements'    => $elements,
135
+        'invertcolor' => $invert
136
+      ))->getContent();
137
+    }
138
+    
139
+    return $this->jsonResponse(array(
140
+      'count'   => $count,
141
+      'message' => $message,
142
+      'html'    => $html
143
+    ));
144
+  }
145
+  
72 146
 }

+ 4 - 0
src/Muzich/HomeBundle/Resources/config/routing.yml Zobrazit soubor

@@ -24,4 +24,8 @@ show_group_more:
24 24
   pattern: /group/{slug}/more/{count}
25 25
   defaults: { _controller: MuzichHomeBundle:Show:showGroup, count: null }
26 26
 
27
+show_elements_get:
28
+  pattern:   /show/{type}/{object_id}/getElements/{tags_ids_json}/{id_limit}/{invert}
29
+  defaults: { _controller: MuzichHomeBundle:Show:getElements, id_limit: null, invert: false }
30
+
27 31
   

+ 15 - 4
src/Muzich/HomeBundle/Resources/views/Show/showGroup.html.twig Zobrazit soubor

@@ -24,6 +24,11 @@
24 24
   </div>
25 25
     
26 26
   <h2>{{ group.name }}</h2>
27
+
28
+  {% include "MuzichCoreBundle:Tag:tagsList.show.html.twig" with {
29
+    'object_id'   : group.id,
30
+    'object_type' : 'group'
31
+  } %}
27 32
   
28 33
   {% if his_group or group.open %}
29 34
   
@@ -58,10 +63,16 @@
58 63
   {% if more_count is defined %} 
59 64
   {% if elements|length %}
60 65
    <span class="elements_more">
61
-     <a href="{{ path('search_elements_show_more_empty', {
62
-       'type'     : 'group', 
63
-       'object_id': group.id
64
-     }) }}" class="elements_more" >
66
+     <input type="hidden" id="more_elements_url" value="{{ path('show_elements_get', {
67
+        'type'          : 'group',
68
+        'object_id'     : group.id, 
69
+        'tags_ids_json' : ''
70
+      }) }}" />
71
+     <a href="{{ path('show_elements_get', {
72
+        'type'          : 'group',
73
+        'object_id'     : group.id, 
74
+        'tags_ids_json' : tags_id_json
75
+      }) }}" class="elements_more button" >
65 76
        {{ 'more'|trans({}, 'userui') }}
66 77
      </a>
67 78
    </span>

+ 15 - 5
src/Muzich/HomeBundle/Resources/views/Show/showUser.html.twig Zobrazit soubor

@@ -35,7 +35,11 @@
35 35
   
36 36
 
37 37
   <h2>{{ 'user.show.title'|trans({'%name%' : viewed_user.name}, 'users') }}</h2>
38
-  
38
+
39
+  {% include "MuzichCoreBundle:Tag:tagsList.show.html.twig" with {
40
+    'object_id'   : viewed_user.id,
41
+    'object_type' : 'user'
42
+  } %}
39 43
   
40 44
   {% include "MuzichCoreBundle:SearchElement:default.html.twig" %}
41 45
     
@@ -46,10 +50,16 @@
46 50
   {% if more_count is defined %} 
47 51
   {% if elements|length %}
48 52
    <span class="elements_more">
49
-     <a href="{{ path('search_elements_show_more_empty', {
50
-       'type'     : 'user', 
51
-       'object_id': viewed_user.id
52
-     }) }}" class="elements_more" >
53
+     <input type="hidden" id="more_elements_url" value="{{ path('show_elements_get', {
54
+        'type'          : 'user',
55
+        'object_id'     : viewed_user.id, 
56
+        'tags_ids_json' : ''
57
+      }) }}" />
58
+     <a href="{{ path('show_elements_get', {
59
+        'type'          : 'user',
60
+        'object_id'     : viewed_user.id, 
61
+        'tags_ids_json' : tags_id_json
62
+      }) }}" class="elements_more button" >
53 63
        {{ 'more'|trans({}, 'userui') }}
54 64
      </a>
55 65
    </span>

+ 17 - 0
web/bundles/muzichcore/css/main.css Zobrazit soubor

@@ -733,4 +733,21 @@ div.question .title {
733 733
 	font-weight: bold;
734 734
 	font-style: italic;
735 735
 	text-shadow: 0px 2px 0px #fff;
736
+}
737
+
738
+/* Liste de tags */
739
+
740
+ul#favorite_tags
741
+{
742
+  padding:0;
743
+  margin:0;
744
+  list-style-type:none;
745
+}
746
+
747
+ul#favorite_tags li
748
+{
749
+  display: inline;
750
+  margin-left: 2px;
751
+  margin-top: 2px;
752
+  float:left; /*pour IE*/
736 753
 }

+ 90 - 1
web/bundles/muzichcore/js/muzich.js Zobrazit soubor

@@ -800,6 +800,95 @@ $(document).ready(function(){
800 800
   // Check périodique 
801 801
   // TODO.
802 802
 
803
- 
803
+ /////////////////////
804
+ // Filtre par tags (show, favorite)
805
+ function refresh_elements_with_tags_selected(link)
806
+  {
807
+    
808
+    
809
+    // Puis on fait notre rekékéte ajax.
810
+    $('ul.elements').html('');
811
+    $('div.no_elements').hide();
812
+    $('img.elements_more_loader').show();
813
+    $.getJSON($('input#get_elements_url').val()+'/'+array2json(tags_ids), function(response){
814
+      
815
+      $('ul.elements').html(response.html);
816
+      
817
+      if (response.count)
818
+       {
819
+         $('img.elements_more_loader').hide();
820
+         $('span.elements_more').show();
821
+         $('a.elements_more').show();
822
+       }
823
+    });
824
+    
825
+    return false;
826
+  }
827
+   
828
+  $('ul#favorite_tags a.tag').click(function(){
829
+    // Ensuite on l'active ou le désactive'
830
+    if ($(this).hasClass('active'))
831
+    {
832
+      $(this).removeClass('active');
833
+    }
834
+    else
835
+    {
836
+      $(this).addClass('active');
837
+    }
838
+    
839
+    // On construit notre liste de tags
840
+    tags_ids = new Array();
841
+    $('ul#favorite_tags a.tag.active').each(function(index){
842
+      id = str_replace('#', '', $(this).attr('href'));
843
+      tags_ids[id] = id;
844
+    });
845
+    
846
+    // On adapte le lien afficher plus de résultats
847
+    a_more = $('a.elements_more');
848
+    a_more.attr('href', $('input#more_elements_url').val()+'/'+array2json(tags_ids));
849
+    
850
+    return check_timelaps_and_find_with_tags($(this), new Date().getTime(), false);
851
+  });
852
+  
853
+  last_keypress = 0;
854
+  function check_timelaps_and_find_with_tags(link, time_id, timed)
855
+  {
856
+    if (!timed)
857
+    {
858
+      // C'est une nouvelle touche (pas redirigé) on lui donne un id
859
+      // et on met a jour l'id de la dernière pressé
860
+      last_keypress = new Date().getTime(); 
861
+      var this_time_id = last_keypress;
862
+    }
863
+    else
864
+    {
865
+      // Si elle a été redirigé, on met son id dans cette variable
866
+      var this_time_id = time_id;
867
+    }
868
+    
869
+    // C'est une touche redirigé dans le temps qui a été suivit d'une autre touche
870
+    if (time_id != last_keypress && timed)
871
+    {
872
+      // elle disparait
873
+    }
874
+    else
875
+    {
876
+      //
877
+      if ((new Date().getTime() - last_keypress) < 800 || timed == false)
878
+      {
879
+        // Si elle vient d'être tapé (timed == false) elle doit attendre (au cas ou une autre touche soit tapé)
880
+        // Si c'est une redirigé qui n'a pas été remplacé par une nouvelle lettre
881
+        // elle doit attendre au cas ou soit pressé.
882
+        setTimeout(function(){check_timelaps_and_find_with_tags(link, this_time_id, true)}, 900);
883
+      }
884
+      else
885
+      {
886
+        // il n'y a plus a attendre, on envoie la demande de tag.
887
+        return refresh_elements_with_tags_selected(link);
888
+      }
889
+    }
890
+    
891
+    return null;
892
+  }
804 893
    
805 894
  });

+ 0 - 14
web/bundles/muzichfavorite/css/favorite.css Zobrazit soubor

@@ -1,14 +0,0 @@
1
-
2
-ul#favorite_tags
3
-{
4
-  padding:0;
5
-  margin:0;
6
-  list-style-type:none;
7
-}
8
-
9
-ul#favorite_tags li
10
-{
11
-  display: inline;
12
-  margin-left:2px;
13
-  float:left; /*pour IE*/
14
-}

+ 0 - 87
web/bundles/muzichfavorite/js/favorite.js Zobrazit soubor

@@ -1,92 +1,5 @@
1 1
 $(document).ready(function(){
2 2
    
3
-  function refresh_elements_with_tags_selected(link)
4
-  {
5
-    
6
-    
7
-    // Puis on fait notre rekékéte ajax.
8
-    $('ul.elements').html('');
9
-    $('div.no_elements').hide();
10
-    $('img.elements_more_loader').show();
11
-    $.getJSON($('input#get_elements_url').val()+'/'+array2json(tags_ids), function(response){
12
-      
13
-      $('ul.elements').html(response.html);
14
-      
15
-      if (response.count)
16
-       {
17
-         $('img.elements_more_loader').hide();
18
-         $('span.elements_more').show();
19
-         $('a.elements_more').show();
20
-       }
21
-    });
22
-    
23
-    return false;
24
-  }
25
-   
26
-  $('ul#favorite_tags a.tag').click(function(){
27
-    // Ensuite on l'active ou le désactive'
28
-    if ($(this).hasClass('active'))
29
-    {
30
-      $(this).removeClass('active');
31
-    }
32
-    else
33
-    {
34
-      $(this).addClass('active');
35
-    }
36
-    
37
-    // On construit notre liste de tags
38
-    tags_ids = new Array();
39
-    $('ul#favorite_tags a.tag.active').each(function(index){
40
-      id = str_replace('#', '', $(this).attr('href'));
41
-      tags_ids[id] = id;
42
-    });
43
-    
44
-    // On adapte le lien afficher plus de résultats
45
-    a_more = $('a.elements_more');
46
-    a_more.attr('href', $('input#more_elements_url').val()+'/'+array2json(tags_ids));
47
-    
48
-    return check_timelaps_and_find_with_tags($(this), new Date().getTime(), false);
49
-  });
50 3
   
51
-  last_keypress = 0;
52
-  function check_timelaps_and_find_with_tags(link, time_id, timed)
53
-  {
54
-    if (!timed)
55
-    {
56
-      // C'est une nouvelle touche (pas redirigé) on lui donne un id
57
-      // et on met a jour l'id de la dernière pressé
58
-      last_keypress = new Date().getTime(); 
59
-      var this_time_id = last_keypress;
60
-    }
61
-    else
62
-    {
63
-      // Si elle a été redirigé, on met son id dans cette variable
64
-      var this_time_id = time_id;
65
-    }
66
-    
67
-    // C'est une touche redirigé dans le temps qui a été suivit d'une autre touche
68
-    if (time_id != last_keypress && timed)
69
-    {
70
-      // elle disparait
71
-    }
72
-    else
73
-    {
74
-      //
75
-      if ((new Date().getTime() - last_keypress) < 800 || timed == false)
76
-      {
77
-        // Si elle vient d'être tapé (timed == false) elle doit attendre (au cas ou une autre touche soit tapé)
78
-        // Si c'est une redirigé qui n'a pas été remplacé par une nouvelle lettre
79
-        // elle doit attendre au cas ou soit pressé.
80
-        setTimeout(function(){check_timelaps_and_find_with_tags(link, this_time_id, true)}, 900);
81
-      }
82
-      else
83
-      {
84
-        // il n'y a plus a attendre, on envoie la demande de tag.
85
-        return refresh_elements_with_tags_selected(link);
86
-      }
87
-    }
88
-    
89
-    return null;
90
-  }
91 4
    
92 5
 });