Browse Source

Evolution #151: Evenements

bastien 12 years ago
parent
commit
e7a63f388e

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

@@ -65,6 +65,7 @@ filter:
65 65
   mytags:  Tous mes tags
66 66
   network_all:   Réseau global
67 67
   network_my:    Mon réseau
68
+  new_comments:   Nvx commentaires
68 69
   
69 70
 element_add:
70 71
   url:

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

@@ -538,4 +538,27 @@ class CoreController extends Controller
538 538
     
539 539
   }
540 540
   
541
+  public function filterRemoveIdsAction()
542
+  {
543
+    if (($response = $this->mustBeConnected(true)))
544
+    {
545
+      return $response;
546
+    }
547
+    
548
+    $es = $this->getElementSearcher();
549
+    $es->setIds(null);
550
+    $this->setElementSearcherParams($es->getParams());
551
+    
552
+    $html = $this->render('MuzichCoreBundle:SearchElement:default.html.twig', array(
553
+      'user'        => $this->getUser(),
554
+      'elements'    => $es->getElements($this->getDoctrine(), $this->getUserId()),
555
+      'invertcolor' => false
556
+    ))->getContent();
557
+
558
+    return $this->jsonResponse(array(
559
+      'status'  => 'success',
560
+      'html'    => $html
561
+    ));
562
+  }
563
+  
541 564
 }

+ 58 - 20
src/Muzich/CoreBundle/Repository/ElementRepository.php View File

@@ -38,6 +38,27 @@ class ElementRepository extends EntityRepository
38 38
     $params_select['uid'] = $user_id;
39 39
     $order_by = "ORDER BY e_.created DESC, e_.id DESC";
40 40
     
41
+    // Première chose, si on impose les element_ids on a pas besoin de faire 
42
+    // le filtrage
43
+    if ($searcher->hasIds())
44
+    {
45
+      // Dans ce cas ou les ids sont déjà donné, on ne peut pas avoir de nouveaux
46
+      // éléments
47
+      if ($searcher->isSearchingNew())
48
+      {
49
+        return $query = $this->getEntityManager()
50
+          ->createQuery("SELECT e FROM MuzichCoreBundle:Element e WHERE 1 = 2")
51
+        ;
52
+      }
53
+      
54
+      if (($id_limit = $searcher->getIdLimit()))
55
+      {
56
+        return $this->getSelectElementForSearchQuery($params_select, $user_id, $searcher->getIds(), $id_limit, $searcher->getCount());
57
+      }
58
+      return $this->getSelectElementForSearchQuery($params_select, $user_id, $searcher->getIds());
59
+    }
60
+    
61
+    
41 62
     // Booléen nous permettant de savoir si un where a déjà été écrit
42 63
     $is_where = false;
43 64
     
@@ -202,26 +223,7 @@ class ElementRepository extends EntityRepository
202 223
         $ids[] = $r_id['id'];
203 224
       }
204 225
 
205
-      // C'est la requête qui récupérera les données element avec ses jointures.
206
-      $query_select = "SELECT e, t, o, g, fav
207
-        FROM MuzichCoreBundle:Element e 
208
-        LEFT JOIN e.group g 
209
-        LEFT JOIN e.tags t WITH (t.tomoderate = 'FALSE' OR t.tomoderate IS NULL
210
-          OR t.privateids LIKE :uidt)
211
-        LEFT JOIN e.elements_favorites fav WITH fav.user = :uid
212
-        JOIN e.owner o
213
-        WHERE e.id IN (:ids)
214
-        ORDER BY e.created DESC, e.id DESC"
215
-      ;
216
-
217
-      $params_select['ids'] = $ids;
218
-      $params_select['uidt'] = '%"'.$user_id.'"%';
219
-      $query = $this->getEntityManager()
220
-        ->createQuery($query_select)
221
-        ->setParameters($params_select)
222
-      ;
223
-
224
-      return $query;
226
+      return $this->getSelectElementForSearchQuery($params_select, $user_id, $ids);
225 227
     }
226 228
     
227 229
     // Il faut retourner une Query
@@ -230,6 +232,42 @@ class ElementRepository extends EntityRepository
230 232
     ;
231 233
   }
232 234
   
235
+  protected function getSelectElementForSearchQuery($params_select, $user_id, $ids, $id_limit = null, $count_limit = null)
236
+  {    
237
+    $where = "";
238
+    if ($id_limit)
239
+    {
240
+      $where = "AND e.id < :id_limit";
241
+      $params_select['id_limit'] = $id_limit;
242
+    }
243
+      
244
+    // C'est la requête qui récupérera les données element avec ses jointures.
245
+    $query_select = "SELECT e, t, o, g, fav
246
+      FROM MuzichCoreBundle:Element e 
247
+      LEFT JOIN e.group g 
248
+      LEFT JOIN e.tags t WITH (t.tomoderate = 'FALSE' OR t.tomoderate IS NULL
249
+        OR t.privateids LIKE :uidt)
250
+      LEFT JOIN e.elements_favorites fav WITH fav.user = :uid
251
+      JOIN e.owner o
252
+      WHERE e.id IN (:ids) $where
253
+      ORDER BY e.created DESC, e.id DESC"
254
+    ;
255
+
256
+    $params_select['ids'] = $ids;
257
+    $params_select['uidt'] = '%"'.$user_id.'"%';
258
+    $query = $this->getEntityManager()
259
+      ->createQuery($query_select)
260
+      ->setParameters($params_select)
261
+    ;
262
+    
263
+    if ($count_limit)
264
+    {
265
+      $query->setMaxResults($count_limit);
266
+    }
267
+
268
+    return $query;
269
+  }
270
+  
233 271
   /**
234 272
    * Retourne une requete selectionnant les Elements en fonction du
235 273
    * propriétaire.

+ 4 - 0
src/Muzich/CoreBundle/Resources/config/routing.yml View File

@@ -60,6 +60,10 @@ ajax_element_remove_vote_good:
60 60
   pattern: /ajax/element/vote/remove/good/{element_id}/{token}
61 61
   defaults: { _controller: MuzichCoreBundle:Element:removeVoteGood }
62 62
 
63
+ajax_filter_remove_ids:
64
+  pattern: /ajax/filter/remove/ids
65
+  defaults: { _controller: MuzichCoreBundle:Core:filterRemoveIds }
66
+
63 67
 ####
64 68
 
65 69
 info_about:

+ 2 - 1
src/Muzich/CoreBundle/Resources/config/security.yml View File

@@ -77,7 +77,8 @@ security:
77 77
         - { path: ^/(?:fr|en)/show/group/, role: IS_AUTHENTICATED_ANONYMOUSLY }
78 78
         - { path: ^/(?:fr|en)/favoritesajax, role: IS_AUTHENTICATED_ANONYMOUSLY }
79 79
         - { path: ^/(?:fr|en)/ajax, role: IS_AUTHENTICATED_ANONYMOUSLY }
80
-                                
80
+        - { path: ^/(?:fr|en)/event/view/elements, role: IS_AUTHENTICATED_ANONYMOUSLY }
81
+                                        
81 82
         - { path: ^/, roles: ROLE_USER }
82 83
         
83 84
 #        # Liste des pages accessibles à tous les utilisateurs (ne pas toucher)

+ 10 - 2
src/Muzich/CoreBundle/Resources/views/SearchElement/form.html.twig View File

@@ -7,12 +7,20 @@
7 7
       {{ form_widget(search_form.network, { 'attr': {'style': 'display: none;'} }) }}
8 8
     </div>
9 9
     
10
-    <a href="#" class="button all_network {% if network_public %}active{% endif %}">
10
+    <a href="#" class="button all_network {% if network_public and not display_comments %}active{% endif %}">
11 11
       {{ 'filter.network_all'|trans({}, 'userui') }}
12 12
     </a>
13
-    <a href="#" class="button my_network {% if not network_public %}active{% endif %}">
13
+    <a href="#" class="button my_network {% if not network_public and not display_comments %}active{% endif %}">
14 14
       {{ 'filter.network_my'|trans({}, 'userui') }}
15 15
     </a>
16
+      
17
+  </div>
18
+
19
+  <div class="more_filters">
20
+    <a href="{{ path('ajax_filter_remove_ids') }}" class="button active new_comments" style="{% if not display_comments %}display: none;{% endif %}">
21
+      {{ 'filter.new_comments'|trans({}, 'userui') }}
22
+      <img src="{{ asset('bundles/muzichcore/img/1328276855_list-remove.png') }}" alt="remove" />
23
+    </a>
16 24
   </div>
17 25
   
18 26
   {% include "MuzichCoreBundle:Tag:tagsPrompt.html.twig" with { 

+ 1 - 1
src/Muzich/CoreBundle/Resources/views/layout.html.twig View File

@@ -79,7 +79,7 @@
79 79
   <div id="container">
80 80
     
81 81
     {% if is_granted("IS_AUTHENTICATED_REMEMBERED") %}
82
-      {% render "MuzichUserBundle:User:infoBar" %}
82
+      {% render "MuzichUserBundle:Event:infoBar" %}
83 83
     {% endif %}
84 84
     
85 85
     {% block main_content %}{% endblock %}

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

@@ -74,6 +74,15 @@ class ElementSearcher extends Searcher implements SearcherInterface
74 74
   protected $searchnew = false;
75 75
   
76 76
   /**
77
+   * Ce tableaux peut conteni des ids. Si ces ids sont renseignés tout les 
78
+   * autres paramétres ne sont plus pris en compte.
79
+   * Ces ids servent a filtrer directement la liste d'élément a afficher.
80
+   * 
81
+   * @var array
82
+   */
83
+  protected $ids;
84
+  
85
+  /**
77 86
    * @see SearcherInterface
78 87
    * @param array $params 
79 88
    */
@@ -86,7 +95,7 @@ class ElementSearcher extends Searcher implements SearcherInterface
86 95
     
87 96
     // Mise a jour des attributs
88 97
     $this->setAttributes(array(
89
-      'network', 'tags', 'count', 'user_id', 'group_id', 'favorite', 'id_limit', 'searchnew'
98
+      'network', 'tags', 'count', 'user_id', 'group_id', 'favorite', 'id_limit', 'searchnew', 'ids'
90 99
     ), $params);
91 100
     
92 101
   }
@@ -99,7 +108,7 @@ class ElementSearcher extends Searcher implements SearcherInterface
99 108
   {
100 109
     // Mise a jour des attributs
101 110
     $this->setAttributes(array(
102
-      'network', 'tags', 'count', 'user_id', 'group_id', 'favorite', 'id_limit', 'searchnew'
111
+      'network', 'tags', 'count', 'user_id', 'group_id', 'favorite', 'id_limit', 'searchnew', 'ids'
103 112
     ), $params);
104 113
   }
105 114
   
@@ -116,7 +125,8 @@ class ElementSearcher extends Searcher implements SearcherInterface
116 125
       'count'    => $this->getCount(),
117 126
       'user_id'  => $this->getUserId(),
118 127
       'group_id' => $this->getGroupId(),
119
-      'favorite' => $this->isFavorite()
128
+      'favorite' => $this->isFavorite(),
129
+      'ids'      => $this->getIds()
120 130
     );
121 131
   }
122 132
   
@@ -182,6 +192,25 @@ class ElementSearcher extends Searcher implements SearcherInterface
182 192
   {
183 193
     return $this->favorite;
184 194
   }
195
+  
196
+  public function setIds($ids)
197
+  {
198
+    $this->ids = $ids;
199
+  }
200
+  
201
+  public function getIds()
202
+  {
203
+    return $this->ids;
204
+  }
205
+  
206
+  public function hasIds()
207
+  {
208
+    if (count($this->ids))
209
+    {
210
+      return true;
211
+    }
212
+    return false;
213
+  }
185 214
 
186 215
   /**
187 216
    * Construction de l'objet Query

+ 1 - 0
src/Muzich/HomeBundle/Controller/HomeController.php View File

@@ -30,6 +30,7 @@ class HomeController extends Controller
30 30
     
31 31
     return array(
32 32
       'search_tags_id'   => $search_object->getTags(),
33
+      'display_comments' => $search_object->hasIds(),
33 34
       'user'             => $this->getUser(),
34 35
       'add_form'         => $add_form->createView(),
35 36
       'add_form_name'    => 'add',

+ 82 - 0
src/Muzich/UserBundle/Controller/EventController.php View File

@@ -0,0 +1,82 @@
1
+<?php
2
+
3
+namespace Muzich\UserBundle\Controller;
4
+
5
+use Muzich\CoreBundle\lib\Controller;
6
+
7
+class EventController extends Controller
8
+{
9
+    
10
+  public function infoBarAction()
11
+  {
12
+    $events = $this->getDoctrine()->getRepository('MuzichCoreBundle:Event')
13
+      ->getNotViewEvents($this->getUserId())
14
+    ;
15
+    
16
+    return $this->render('MuzichUserBundle:Info:bar.html.twig', array(
17
+      'events' => $events
18
+    ));
19
+  }
20
+  
21
+  public function viewElementsAction($event_id)
22
+  {
23
+    if (($response = $this->mustBeConnected()))
24
+    {
25
+      return $response;
26
+    }
27
+    
28
+    if (!($event = $this->getDoctrine()->getRepository('MuzichCoreBundle:Event')
29
+      ->findOneById($event_id)))
30
+    {
31
+      if ($this->getRequest()->isXmlHttpRequest())
32
+      {
33
+        return $this->jsonResponse(array(
34
+          'status' => 'error',
35
+          'errors' => array('NotFound')
36
+        ));
37
+      }
38
+      throw $this->createNotFoundException('Ressource ajax uniquement.');
39
+    }
40
+    
41
+    if ($event->getUser()->getId() != $this->getUserId())
42
+    {
43
+      if ($this->getRequest()->isXmlHttpRequest())
44
+      {
45
+        return $this->jsonResponse(array(
46
+          'status' => 'error',
47
+          'errors' => array('NotAllowed')
48
+        ));
49
+      }
50
+      throw $this->createNotFoundException('Ressource ajax uniquement.');
51
+    }
52
+    
53
+    // A partir d'ici on a ce qu'il faut.
54
+    // On modifie l'Element Searcher en lui donnat les ids correspondant a l'event
55
+    
56
+    $es = $this->getElementSearcher();
57
+    $es->setIds($event->getIds());
58
+    $this->setElementSearcherParams($es->getParams());
59
+    $event->setView(true);
60
+    $this->getDoctrine()->getEntityManager()->persist($event);
61
+    $this->getDoctrine()->getEntityManager()->flush();
62
+    
63
+    // Si ajax
64
+    if ($this->getRequest()->isXmlHttpRequest())
65
+    {
66
+      $html = $this->render('MuzichCoreBundle:SearchElement:default.html.twig', array(
67
+        'user'        => $this->getUser(),
68
+        'elements'    => $es->getElements($this->getDoctrine(), $this->getUserId()),
69
+        'invertcolor' => false
70
+      ))->getContent();
71
+      
72
+      return $this->jsonResponse(array(
73
+        'status'  => 'success',
74
+        'html'    => $html
75
+      ));
76
+    }
77
+    
78
+    // Sinon on redirige vers home
79
+    return $this->redirect($this->generateUrl('home'));
80
+  }
81
+    
82
+}

+ 0 - 11
src/Muzich/UserBundle/Controller/UserController.php View File

@@ -566,16 +566,5 @@ class UserController extends Controller
566 566
       'status' => 'success'
567 567
     ));
568 568
   }
569
-  
570
-  public function infoBarAction()
571
-  {
572
-    $events = $this->getDoctrine()->getRepository('MuzichCoreBundle:Event')
573
-      ->getNotViewEvents($this->getUserId())
574
-    ;
575
-    
576
-    return $this->render('MuzichUserBundle:Info:bar.html.twig', array(
577
-      'events' => $events
578
-    ));
579
-  }
580 569
     
581 570
 }

+ 6 - 1
src/Muzich/UserBundle/Resources/config/routing.yml View File

@@ -32,4 +32,9 @@ change_email_confirm:
32 32
   
33 33
 update_address:
34 34
   pattern: /ajax/update-address/{token}
35
-  defaults: { _controller: MuzichUserBundle:User:updateAddress }
35
+  defaults: { _controller: MuzichUserBundle:User:updateAddress }
36
+  
37
+event_view_elements:
38
+  pattern: /event/view/elements/{event_id}
39
+  defaults: { _controller: MuzichUserBundle:Event:viewElements }
40
+  

+ 15 - 7
src/Muzich/UserBundle/Resources/views/Info/bar.html.twig View File

@@ -1,17 +1,25 @@
1 1
 <div id="events">
2 2
     
3 3
     <div class="score">
4
-      <img src="{{ asset('bundles/muzichcore/img/1332286466_stock_scores.png') }}" alt="" />
4
+      <img src="{{ asset('bundles/muzichcore/img/1332286466_stock_scores.png') }}" alt="score" />
5 5
       <span>{{ app.user.reputation }}</span>
6 6
     </div>
7 7
     
8 8
     <div class="comments">
9
-      <img src="{{ asset('bundles/muzichcore/img/1332286007_comments_reply.png') }}" alt="" />
10
-      {% if events[event_const('TYPE_COMMENT_ADDED_ELEMENT')] is defined %}
11
-        <span>{{ events[event_const('TYPE_COMMENT_ADDED_ELEMENT')].count }}</span>
12
-      {% else %}
13
-        <span>0</span>
14
-      {% endif %}
9
+      
10
+        {% if events[event_const('TYPE_COMMENT_ADDED_ELEMENT')] is defined %}
11
+          <a 
12
+            href="{{ path('event_view_elements', {'event_id':events[event_const('TYPE_COMMENT_ADDED_ELEMENT')].id}) }}" 
13
+            title="BLLLLLLLLL"
14
+            class="view_elements_event"
15
+          >
16
+            <img src="{{ asset('bundles/muzichcore/img/1332286007_comments_reply.png') }}" alt="comments" />
17
+            <span>{{ events[event_const('TYPE_COMMENT_ADDED_ELEMENT')].count }}</span>
18
+          </a>
19
+        {% else %}
20
+          <img src="{{ asset('bundles/muzichcore/img/1332286007_comments_reply.png') }}" alt="comments" />
21
+          <span>0</span>
22
+        {% endif %}
15 23
     </div>
16 24
   
17 25
   </div>

+ 1 - 1
web/bundles/muzichcore/css/main.css View File

@@ -4,7 +4,7 @@
4 4
   position: relative;
5 5
   min-height: 100%;
6 6
   padding-bottom: 30px;
7
-  
7
+  min-height: 120px;
8 8
   
9 9
   width: 640px;
10 10
   margin-top: 45px;

+ 25 - 0
web/bundles/muzichcore/js/muzich.js View File

@@ -1683,5 +1683,30 @@ $(document).ready(function(){
1683 1683
     return false;
1684 1684
   });
1685 1685
   
1686
+  
1687
+  // Enlever les ids du ElementSearch
1688
+  $('div.more_filters a.new_comments').live('click', function(){
1689
+    
1690
+    $('img.elements_more_loader').show();
1691
+    $('ul.elements').html('');
1692
+    link = $(this);
1693
+    
1694
+    $.getJSON(link.attr('href'), function(response){
1695
+        
1696
+      if (response.status == 'mustbeconnected')
1697
+      {
1698
+        $(location).attr('href', url_index);
1699
+      }
1700
+      
1701
+      if (response.status == 'success')
1702
+      {
1703
+        $('form[name="search"]').submit();
1704
+        $('div.more_filters a.new_comments').hide();
1705
+      }
1706
+      
1707
+    });
1708
+    
1709
+    return false;
1710
+  });
1686 1711
 
1687 1712
 });

+ 14 - 0
web/bundles/muzichhome/css/home.css View File

@@ -76,6 +76,20 @@ div.select_network a.my_network
76 76
   background-position: 2px 3px;
77 77
 }
78 78
 
79
+div.more_filters a.new_comments
80
+{
81
+  margin-top: 5px;
82
+  padding-left: 20px;
83
+  background-image: url(/bundles/muzichcore/img/1332286007_comments_reply.png);
84
+  background-repeat: no-repeat;
85
+  background-position: 2px 3px;
86
+}
87
+
88
+div.more_filters a.new_comments img
89
+{
90
+  margin-bottom: -3px;
91
+}
92
+
79 93
 div.select_network a.active
80 94
 {
81 95
   background-color: #39c9cc