Преглед изворни кода

Evolution #414: Navigation en mode non inscrit

Sevajol Bastien пре 11 година
родитељ
комит
3b6179c18d

+ 32 - 22
src/Muzich/CommentBundle/Resources/views/Comment/comment.html.twig Прегледај датотеку

@@ -5,31 +5,41 @@
5 5
    {{ date_or_relative_date(comment.e, 'comment.edited') }}{% endif %})
6 6
 </span>
7 7
 
8
-{% if app.user.id != comment.u.i %}
8
+{% if app.user %}
9
+  {% if app.user.id != comment.u.i %}
10
+    <a title="{{ 'comment.report.link_title'|trans({}, 'userui') }}" 
11
+      class="comment_report" 
12
+      href="{{ path('ajax_alert_comment', {'element_id':element_id, 'date': comment.d, 'token':app.user.getPersonalHash(element_id)}) }}">
13
+      <img src="{{ asset('bundles/muzichcore/img/1331832708_comment_alert.png') }}" alt="report" />
14
+    </a>
15
+  {% endif %}
16
+{% else %}
9 17
   <a title="{{ 'comment.report.link_title'|trans({}, 'userui') }}" 
10
-    class="comment_report" 
11
-    href="{{ path('ajax_alert_comment', {'element_id':element_id, 'date': comment.d, 'token':app.user.getPersonalHash(element_id)}) }}">
18
+    class="mustbeconnected" 
19
+    href="#">
12 20
     <img src="{{ asset('bundles/muzichcore/img/1331832708_comment_alert.png') }}" alt="report" />
13 21
   </a>
14 22
 {% endif %}
15 23
 
16
-{% if app.user.id == comment.u.i %}
17
-  <a title="{{ 'comment.edit.link'|trans({}, 'elements') }}" class="comment_edit_link" 
18
-     href="{{ path('ajax_edit_comment', {'element_id': element_id, 'date':comment.d, 'token':app.user.getPersonalHash(element_id)})  }}" style="display: none;"
19
-  >
20
-    <img src="{{ asset('bundles/muzichcore/img/1327151338_desktop.png') }}" alt="edit" />
21
-  </a>
22
-
23
-  <a title="{{ 'comment.remove.link'|trans({}, 'elements') }}" class="comment_remove_link" 
24
-     href="{{ path('ajax_delete_comment', {'element_id': element_id, 'date':comment.d, 'token':app.user.getPersonalHash(element_id)})  }}" style="display: none;"
25
-  >
26
-    <img src="{{ asset('bundles/muzichcore/img/1327168960_fileclose.png') }}" alt="delete" />
27
-  </a>
28
-
29
-  <img 
30
-    class="comment_loader" 
31
-    style="display: none;" 
32
-    src="{{ asset('/bundles/muzichcore/img/ajax-loader.gif') }}" 
33
-    alt="loading"
34
-  />
24
+{% if app.user %}
25
+  {% if app.user.id == comment.u.i %}
26
+    <a title="{{ 'comment.edit.link'|trans({}, 'elements') }}" class="comment_edit_link" 
27
+       href="{{ path('ajax_edit_comment', {'element_id': element_id, 'date':comment.d, 'token':app.user.getPersonalHash(element_id)})  }}" style="display: none;"
28
+    >
29
+      <img src="{{ asset('bundles/muzichcore/img/1327151338_desktop.png') }}" alt="edit" />
30
+    </a>
31
+  
32
+    <a title="{{ 'comment.remove.link'|trans({}, 'elements') }}" class="comment_remove_link" 
33
+       href="{{ path('ajax_delete_comment', {'element_id': element_id, 'date':comment.d, 'token':app.user.getPersonalHash(element_id)})  }}" style="display: none;"
34
+    >
35
+      <img src="{{ asset('bundles/muzichcore/img/1327168960_fileclose.png') }}" alt="delete" />
36
+    </a>
37
+  
38
+    <img 
39
+      class="comment_loader" 
40
+      style="display: none;" 
41
+      src="{{ asset('/bundles/muzichcore/img/ajax-loader.gif') }}" 
42
+      alt="loading"
43
+    />
44
+  {% endif %}
35 45
 {% endif %}

+ 1 - 6
src/Muzich/CoreBundle/Controller/CoreController.php Прегледај датотеку

@@ -438,12 +438,7 @@ class CoreController extends Controller
438 438
    * @return Response 
439 439
    */
440 440
   public function getFavoriteTagsAction()
441
-  {
442
-    if (($response = $this->mustBeConnected()))
443
-    {
444
-      return $response;
445
-    }
446
-    
441
+  {    
447 442
     // On construit l'element searcher avec les tags favoris
448 443
     $es = $this->getElementSearcher(null, true);
449 444
     // Et on retourne les tags

+ 4 - 26
src/Muzich/CoreBundle/Controller/ElementController.php Прегледај датотеку

@@ -329,11 +329,6 @@ class ElementController extends Controller
329 329
       return $this->redirect($this->generateUrl('index'));
330 330
     }
331 331
     
332
-    if (($response = $this->mustBeConnected()))
333
-    {
334
-      return $response;
335
-    }
336
-    
337 332
     if ($this->getRequest()->getMethod() != 'POST')
338 333
     {
339 334
       throw new \Symfony\Component\HttpKernel\Exception\NotFoundHttpException();
@@ -358,7 +353,7 @@ class ElementController extends Controller
358 353
       'id_limit'  => $refid
359 354
     ));
360 355
     
361
-    $count = $es->getElements($this->getDoctrine(), $this->getUserId(), 'count');
356
+    $count = $es->getElements($this->getDoctrine(), $this->getUserId(true), 'count');
362 357
     
363 358
     return $this->jsonResponse(array(
364 359
       'status'   => 'success',
@@ -1028,11 +1023,6 @@ class ElementController extends Controller
1028 1023
    */
1029 1024
   public function getDatasAutoplayAction(Request $request, $element_id, $type, $data, $show_type = null, $show_id = null)
1030 1025
   {
1031
-    if (($response = $this->mustBeConnected(true)))
1032
-    {
1033
-      return $response;
1034
-    }
1035
-    
1036 1026
     $elements = array();
1037 1027
     $elements_json = array();
1038 1028
     
@@ -1044,7 +1034,7 @@ class ElementController extends Controller
1044 1034
         'count' => $this->container->getParameter('autoplay_max_elements'),
1045 1035
         'id_limit' => $element_id+1
1046 1036
       ));
1047
-      $elements = $search_object->getElements($this->getDoctrine(), $this->getUserId());
1037
+      $elements = $search_object->getElements($this->getDoctrine(), $this->getUserId(true));
1048 1038
     }
1049 1039
     elseif ($type == 'show')
1050 1040
     {
@@ -1098,7 +1088,7 @@ class ElementController extends Controller
1098 1088
         'id_limit' => $element_id+1
1099 1089
       ));
1100 1090
       
1101
-      $elements = $search_object->getElements($this->getDoctrine(), $this->getUserId());
1091
+      $elements = $search_object->getElements($this->getDoctrine(), $this->getUserId(true));
1102 1092
     }
1103 1093
     
1104 1094
     if (count($elements))
@@ -1116,11 +1106,6 @@ class ElementController extends Controller
1116 1106
   
1117 1107
   public function getOneDomAction(Request $request, $element_id, $type)
1118 1108
   {
1119
-    if (($response = $this->mustBeConnected()))
1120
-    {
1121
-      return $response;
1122
-    }
1123
-    
1124 1109
     if (!in_array($type, array('autoplay')))
1125 1110
     {
1126 1111
       return $this->jsonResponse(array(
@@ -1147,7 +1132,7 @@ class ElementController extends Controller
1147 1132
       'ids' => array($element_id)
1148 1133
     ));
1149 1134
     
1150
-    if (!($element = $es->getElements($this->getDoctrine(), $this->getUserId(), 'single')))
1135
+    if (!($element = $es->getElements($this->getDoctrine(), $this->getUserId(true), 'single')))
1151 1136
     {
1152 1137
       throw $this->createNotFoundException('Not found');
1153 1138
     }
@@ -1165,15 +1150,8 @@ class ElementController extends Controller
1165 1150
     ));
1166 1151
   }
1167 1152
   
1168
-  
1169
-  
1170 1153
   public function geJamendotStreamDatasAction(Request $request, $element_id)
1171 1154
   {
1172
-    if (($response = $this->mustBeConnected(true)))
1173
-    {
1174
-      return $response;
1175
-    }
1176
-    
1177 1155
     if (!($element = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
1178 1156
       ->findOneById($element_id)))
1179 1157
     {

+ 2 - 12
src/Muzich/CoreBundle/Controller/SearchController.php Прегледај датотеку

@@ -64,11 +64,6 @@ class SearchController extends Controller
64 64
    */
65 65
   public function searchElementsAction($context, $id_limit = null, $session_id = null)
66 66
   {
67
-    if (($response = $this->mustBeConnected()))
68
-    {
69
-      return $response;
70
-    }
71
-    
72 67
     $request = $this->getRequest();
73 68
     $search_object = $this->getElementSearcher(null, false, $session_id);
74 69
     
@@ -126,7 +121,7 @@ class SearchController extends Controller
126 121
         'id_limit' => $id_limit
127 122
       ));
128 123
       
129
-      $elements = $search_object->getElements($this->getDoctrine(), $this->getUserId());
124
+      $elements = $search_object->getElements($this->getDoctrine(), $this->getUserId(true));
130 125
       
131 126
       return $this->searchElementsMore($context, null, $elements, $message, $session_id);      
132 127
     }
@@ -246,11 +241,6 @@ class SearchController extends Controller
246 241
    */
247 242
   public function searchTagAction($timestamp)
248 243
   {
249
-    if (($response = $this->mustBeConnected()))
250
-    {
251
-      return $response;
252
-    }
253
-    
254 244
     $string_search = $this->getRequest()->request->get('string_search');
255 245
     
256 246
     if ($this->getRequest()->isXmlHttpRequest())
@@ -260,7 +250,7 @@ class SearchController extends Controller
260 250
         // On utilise l'objet TagLike
261 251
         $TagLike = new TagLike($this->getDoctrine()->getEntityManager());
262 252
         // Pour trier nos tags d'une manière plus humaine
263
-        $sort_response = $TagLike->getSimilarTags($string_search, $this->getUserId());
253
+        $sort_response = $TagLike->getSimilarTags($string_search, $this->getUserId(true));
264 254
       
265 255
         $status = 'success';
266 256
         $error  = '';

+ 7 - 2
src/Muzich/CoreBundle/Resources/config/security.yml Прегледај датотеку

@@ -17,7 +17,7 @@ security:
17 17
             pattern:      .*
18 18
             form_login:
19 19
                 provider:       fos_userbundle
20
-                login_path:     index
20
+                login_path:     home
21 21
                 use_forward:    false
22 22
                 check_path:     /login_check
23 23
                 failure_path:   null
@@ -25,7 +25,7 @@ security:
25 25
                 
26 26
             logout:
27 27
                 path:   /logout
28
-                target: /hello
28
+                target: /home
29 29
             anonymous:  ~
30 30
             remember_me:
31 31
               key:      %secret%
@@ -89,6 +89,11 @@ security:
89 89
         - { path: ^/(?:fr|en)/event/view/elements, role: IS_AUTHENTICATED_ANONYMOUSLY }
90 90
         - { path: ^/test-error, role: IS_AUTHENTICATED_ANONYMOUSLY }
91 91
         - { path: ^/share-from, role: IS_AUTHENTICATED_ANONYMOUSLY }
92
+        
93
+        ## New public roads for visitors
94
+        - { path: ^/(?:fr|en)$, role: IS_AUTHENTICATED_ANONYMOUSLY }
95
+        - { path: ^/(?:fr|en)/$, role: IS_AUTHENTICATED_ANONYMOUSLY }
96
+        - { path: ^/$, role: IS_AUTHENTICATED_ANONYMOUSLY }
92 97
                                         
93 98
         - { path: ^/, roles: ROLE_USER }
94 99
         

+ 6 - 1
src/Muzich/CoreBundle/Resources/public/css/main.css Прегледај датотеку

@@ -544,7 +544,7 @@ img.tag_add_to_favorites
544 544
   margin-left: 1px;
545 545
 }
546 546
 
547
-td.element_content a.display_comments, td.element_content a.add_comment, td.element_content a.hide_comments, div.comments a.add_comment
547
+td.element_content a.display_comments, td.element_content a.add_comment, td.element_content a.add_comment_disabled, td.element_content a.hide_comments, div.comments a.add_comment
548 548
 {
549 549
   color: #404040;
550 550
 }
@@ -2045,4 +2045,9 @@ div.helpbox_image_container img
2045 2045
 
2046 2046
 .fotter_muzich_little{
2047 2047
   font-size: 9px;
2048
+}
2049
+
2050
+div.side_margin_top
2051
+{
2052
+  margin-top: 25px;
2048 2053
 }

+ 8 - 1
src/Muzich/CoreBundle/Resources/public/js/TagPrompt.js Прегледај датотеку

@@ -35,7 +35,14 @@ function TagPrompt(select_tag_callback, tag_prompt_connector)
35 35
   {
36 36
     if (!tag_id)
37 37
     {
38
-      openTagSubmission(tag_name);
38
+      if (!visitor)
39
+      {
40
+        openTagSubmission(tag_name);
41
+      }
42
+      else
43
+      {
44
+        open_connection_or_subscription_window();
45
+      }
39 46
     }
40 47
     else
41 48
     {

+ 28 - 3
src/Muzich/CoreBundle/Resources/public/js/muzich.js Прегледај датотеку

@@ -6,7 +6,8 @@
6 6
  */
7 7
 
8 8
 // Messages flashs
9
-var myMessages = ['info','warning','error','success']; // define the messages types	
9
+var myMessages = ['info','warning','error','success']; // define the messages types
10
+var window_login_or_subscription_opened = false;
10 11
 
11 12
 function hideAllMessages()
12 13
 {
@@ -1697,7 +1698,7 @@ $(document).ready(function(){
1697 1698
           
1698 1699
             if (response.status == 'mustbeconnected')
1699 1700
             {
1700
-              $(location).attr('href', url_index);
1701
+              alert('pouet!');
1701 1702
             }
1702 1703
 
1703 1704
             if (response.status == 'success' && response.count)
@@ -2077,7 +2078,7 @@ $(document).ready(function(){
2077 2078
         }
2078 2079
       }
2079 2080
     );
2080
-      
2081
+  
2081 2082
   $('a.tag_to_favorites').jConfirmAction({
2082 2083
     question : string_tag_addtofav_confirm_sentence, 
2083 2084
     yesAnswer : string_tag_addtofav_confirm_yes, 
@@ -2628,6 +2629,12 @@ $(document).ready(function(){
2628 2629
    
2629 2630
    // Ouverture de la zone "ajouter un element""
2630 2631
    $('#element_add_link').click(function(){
2632
+    
2633
+    if ($(this).hasClass('mustbeconnected'))
2634
+    {
2635
+      return false;
2636
+    }
2637
+    
2631 2638
      $('#element_add_box').slideDown("slow");
2632 2639
      $('#element_add_link').hide();
2633 2640
      $('#element_add_close_link').show();
@@ -2903,4 +2910,22 @@ $(document).ready(function(){
2903 2910
       $('div#add_tag').fadeOut();
2904 2911
     });
2905 2912
    
2913
+  /*
2914
+    * MUSTBECONNECTED links
2915
+    */
2916
+   
2917
+    $('a.mustbeconnected').live('click', function(){open_connection_or_subscription_window();});
2918
+    $('a.mustbeconnected').off('click').on('click',function(){
2919
+      open_connection_or_subscription_window();
2920
+    });
2921
+   
2906 2922
 });
2923
+
2924
+function open_connection_or_subscription_window()
2925
+{
2926
+  if (window_login_or_subscription_opened == false)
2927
+  {
2928
+    window_login_or_subscription_opened = true;
2929
+    alert('must be connected');
2930
+  }
2931
+}

+ 1 - 1
src/Muzich/CoreBundle/Resources/views/Component/element_add_buttons.html.twig Прегледај датотеку

@@ -5,7 +5,7 @@
5 5
   {% set close_class = ''%}
6 6
 {% endif %}
7 7
 
8
-<a href="#" id="element_add_link" class="button gradient {{ add_class }}">
8
+<a href="#" id="element_add_link" class="button gradient {{ add_class }} {% if not app.user %}mustbeconnected{% endif %}">
9 9
   {{ 'home.add_element'|trans({}, 'navigationui') }}
10 10
   <img src="{{ asset('/img/icon_dart_right_white.png') }}" alt="" />
11 11
 </a>

+ 5 - 0
src/Muzich/CoreBundle/Resources/views/Layout/head_js.html.twig Прегледај датотеку

@@ -69,6 +69,11 @@
69 69
 {% endif %}
70 70
 
71 71
 <script type="text/javascript">
72
+  {% if app.user %}
73
+    visitor = false;
74
+  {% else %}
75
+    visitor = true;
76
+  {% endif %}
72 77
   string_follow_stop = "{{ 'user.stop_follow'|trans({}, 'users') }}";
73 78
   string_follow_following = "{{ 'user.following'|trans({}, 'users') }}";
74 79
   string_follow_follow = "{{ 'user.follow'|trans({}, 'users') }}";

+ 1 - 3
src/Muzich/CoreBundle/Resources/views/Layout/header.html.twig Прегледај датотеку

@@ -8,8 +8,6 @@
8 8
   
9 9
   {% include 'MuzichCoreBundle:Menu:access.html.twig' %}
10 10
   
11
-  {% if app.user %}
12
-    {% include 'MuzichCoreBundle:Menu:main_menu.html.twig' %}
13
-  {% endif %}
11
+  {% include 'MuzichCoreBundle:Menu:main_menu.html.twig' %}
14 12
   
15 13
 </div>

+ 5 - 2
src/Muzich/CoreBundle/Resources/views/Layout/side.html.twig Прегледај датотеку

@@ -4,13 +4,16 @@
4 4
       {% render "MuzichUserBundle:Event:infoBar" %}
5 5
     {% endif %}
6 6
   </div>
7
+{% else %}
8
+  <div class="side_margin_top"></div>
9
+{% endif %}
7 10
 
8 11
   <div id="searchbox" class="nicebox">
9 12
     {% render "MuzichCoreBundle:Search:renderGlobalSearchForm" %}
10 13
   </div>
11 14
   
12 15
   {% include 'MuzichCoreBundle:Layout:social.html.twig' %}
13
-  
14
-  {% render 'MuzichCoreBundle:Core:renderSideMenu' %}
15 16
 
17
+{% if app.user %}
18
+  {% render 'MuzichCoreBundle:Core:renderSideMenu' %}
16 19
 {% endif %}

+ 66 - 26
src/Muzich/CoreBundle/Resources/views/Menu/main_menu.html.twig Прегледај датотеку

@@ -4,34 +4,74 @@
4 4
     {% set network_public = '' %}
5 5
   {% endif %}
6 6
   
7
-  <li class="{% if network_public == '1' and not ids_display %}selected{% endif %}">
8
-    <a id="link_all_network" href="{{ path('home') }}" class="all_network">
9
-      {{ 'filter.network_all'|trans({}, 'userui') }}
10
-    </a>
11
-  </li>
7
+  {% if app.user %}
8
+    <li class="{% if network_public == '1' and not ids_display %}selected{% endif %}">
9
+      <a id="link_all_network" href="{{ path('home') }}" class="all_network">
10
+        {{ 'filter.network_all'|trans({}, 'userui') }}
11
+      </a>
12
+    </li>
13
+  {% else %}
14
+    <li class="{% if network_public == '1' and not ids_display %}selected{% endif %}">
15
+      <a href="{{ path('home') }}" >
16
+        {{ 'filter.network_all'|trans({}, 'userui') }}
17
+      </a>
18
+    </li>
19
+  {% endif %}
12 20
   <li class="separator"></li>
13
-  <li class="{% if network_public == '0' and not ids_display %}selected{% endif %}">
14
-    <a id="link_my_network" href="{{ path('mynetwork_home') }}" class="my_network" >
15
-      {{ 'filter.network_my'|trans({}, 'userui') }}
16
-    </a>
17
-  </li>
21
+  {% if app.user %}
22
+    <li class="{% if network_public == '0' and not ids_display %}selected{% endif %}">
23
+      <a id="link_my_network" href="{{ path('mynetwork_home') }}" class="my_network" >
24
+        {{ 'filter.network_my'|trans({}, 'userui') }}
25
+      </a>
26
+    </li>
27
+  {% else %}
28
+    <li>
29
+      <a id="link_my_network" href="#" class="mustbeconnected" >
30
+        {{ 'filter.network_my'|trans({}, 'userui') }}
31
+      </a>
32
+    </li>
33
+  {% endif %}
18 34
   <li class="separator"></li>
19
-  <li class="{% if app.request.get('topmenu') == 'showuser' and app.request.get('slug') == app.user.slug %}selected{% endif %}">
20
-    <a href="{{ path('show_user', {'slug': app.user.slug}) }}">
21
-      {{ 'container_menu.my_feeds'|trans({}, 'navigationui') }}
22
-    </a>
23
-  </li>
35
+  {% if app.user %}
36
+    <li class="{% if app.request.get('topmenu') == 'showuser' and app.request.get('slug') == app.user.slug %}selected{% endif %}">
37
+      <a href="{{ path('show_user', {'slug': app.user.slug}) }}">
38
+        {{ 'container_menu.my_feeds'|trans({}, 'navigationui') }}
39
+      </a>
40
+    </li>
41
+  {% else %}
42
+    <li>
43
+      <a href="#" class="mustbeconnected">
44
+        {{ 'container_menu.my_feeds'|trans({}, 'navigationui') }}
45
+      </a>
46
+    </li>
47
+  {% endif %}
24 48
   <li class="separator"></li>
25
-  {% if his_group is not defined %}{% set his_group = false %}{% endif %}
26
-  <li class="{% if app.request.get('topmenu') == 'mygroups' or his_group == true %}selected{% endif %}">
27
-    <a href="{{ path('groups_own_list') }}" >
28
-      {{ 'network.mygroups'|trans({}, 'navigationui') }}
29
-    </a>
30
-  </li>
49
+  {% if app.user %}
50
+    {% if his_group is not defined %}{% set his_group = false %}{% endif %}
51
+    <li class="{% if app.request.get('topmenu') == 'mygroups' or his_group == true %}selected{% endif %}">
52
+      <a href="{{ path('groups_own_list') }}" >
53
+        {{ 'network.mygroups'|trans({}, 'navigationui') }}
54
+      </a>
55
+    </li>
56
+  {% else %}
57
+    <li>
58
+      <a href="#" class="mustbeconnected">
59
+        {{ 'network.mygroups'|trans({}, 'navigationui') }}
60
+      </a>
61
+    </li>
62
+  {% endif %}
31 63
   <li class="separator"></li>
32
-  <li class="{% if app.request.get('topmenu') == 'myfavorites' %}selected{% endif %}">
33
-    <a href="{{ path('favorites_my_list') }}" >
34
-      {{ 'container_menu.my_favorites'|trans({}, 'navigationui') }}
35
-    </a>
36
-  </li>
64
+  {% if app.user %}
65
+    <li class="{% if app.request.get('topmenu') == 'myfavorites' %}selected{% endif %}">
66
+      <a href="{{ path('favorites_my_list') }}" >
67
+        {{ 'container_menu.my_favorites'|trans({}, 'navigationui') }}
68
+      </a>
69
+    </li>
70
+  {% else %}
71
+    <li>
72
+      <a href="#" class="mustbeconnected">
73
+        {{ 'container_menu.my_favorites'|trans({}, 'navigationui') }}
74
+      </a>
75
+    </li>
76
+  {% endif %}
37 77
 </ul>

+ 164 - 105
src/Muzich/CoreBundle/Resources/views/SearchElement/element.html.twig Прегледај датотеку

@@ -56,34 +56,46 @@
56 56
           {{ element.points|format_score }}
57 57
         </li>
58 58
             <li class="vote thumb">
59
-              {% if element.owner.id != app.user.id %}
60
-                {% if element.hasVoteGood(app.user.id) %}
61
-                  <a class="vote" href="{{ path('ajax_element_remove_vote_good', {
62
-                    'element_id' : element.id,
63
-                    'token'      : app.user.getPersonalHash(element.id)
64
-                  }) }}" title="{{ 'element.vote.good'|trans({}, 'elements') }}">
65
-                    <img src="{{ asset('img/icon_thumb_red.png') }}" alt="vote" />
66
-                  </a>
59
+              {% if app.user %}
60
+                {% if element.owner.id != app.user.id %}
61
+                  {% if element.hasVoteGood(app.user.id) %}
62
+                    <a class="vote" href="{{ path('ajax_element_remove_vote_good', {
63
+                      'element_id' : element.id,
64
+                      'token'      : app.user.getPersonalHash(element.id)
65
+                    }) }}" title="{{ 'element.vote.good'|trans({}, 'elements') }}">
66
+                      <img src="{{ asset('img/icon_thumb_red.png') }}" alt="vote" />
67
+                    </a>
68
+                  {% else %}
69
+                    <a class="vote" href="{{ path('ajax_element_add_vote_good', {
70
+                      'element_id' : element.id,
71
+                      'token'      : app.user.getPersonalHash(element.id)
72
+                    }) }}" title="{{ 'element.vote.good'|trans({}, 'elements') }}">
73
+                      <img src="{{ asset('img/icon_thumb.png') }}" alt="vote" />
74
+                    </a>
75
+                  {% endif %}
67 76
                 {% else %}
68
-                  <a class="vote" href="{{ path('ajax_element_add_vote_good', {
69
-                    'element_id' : element.id,
70
-                    'token'      : app.user.getPersonalHash(element.id)
71
-                  }) }}" title="{{ 'element.vote.good'|trans({}, 'elements') }}">
72
-                    <img src="{{ asset('img/icon_thumb.png') }}" alt="vote" />
73
-                  </a>
77
+                  <img src="{{ asset('img/icon_thumb_gray.png') }}" alt="vote" />
74 78
                 {% endif %}
75 79
               {% else %}
76
-                <img src="{{ asset('img/icon_thumb_gray.png') }}" alt="vote" />
80
+                <a href="#" class="mustbeconnected">
81
+                  <img src="{{ asset('img/icon_thumb.png') }}" alt="vote" />
82
+                </a>
77 83
               {% endif %}
78 84
             </li>
79 85
         <li class="star">
80
-          {% if element.hasFavoriteUser(app.user.id) %}
81
-            <a class="favorite_link" href="{{ path('favorite_remove', { 'id': element.id, 'token': app.user.personalHash(element.id) }) }}" >
82
-              <img id="favorite_{{ element.id }}_is" src="{{ asset('img/icon_star_2_red.png') }}" title="{{ 'element.favorite.remove'|trans({}, 'elements') }}" alt="{{ 'element.favorite.remove'|trans({}, 'elements') }}"/>
83
-            </a>
86
+          {% if app.user %}
87
+            {% if element.hasFavoriteUser(app.user.id) %}
88
+              <a class="favorite_link" href="{{ path('favorite_remove', { 'id': element.id, 'token': app.user.personalHash(element.id) }) }}" >
89
+                <img id="favorite_{{ element.id }}_is" src="{{ asset('img/icon_star_2_red.png') }}" title="{{ 'element.favorite.remove'|trans({}, 'elements') }}" alt="{{ 'element.favorite.remove'|trans({}, 'elements') }}"/>
90
+              </a>
91
+            {% else %}
92
+              <a class="favorite_link" href="{{ path('favorite_add', { 'id': element.id, 'token': app.user.personalHash(element.id) }) }}" >
93
+                <img id="favorite_{{ element.id }}_isnot" src="{{ asset('img/icon_star_2.png') }}" title="{{ 'element.favorite.add'|trans({}, 'elements') }}" alt="{{ 'element.favorite.add'|trans({}, 'elements') }}" />
94
+              </a>
95
+            {% endif %}
84 96
           {% else %}
85
-            <a class="favorite_link" href="{{ path('favorite_add', { 'id': element.id, 'token': app.user.personalHash(element.id) }) }}" >
86
-              <img id="favorite_{{ element.id }}_isnot" src="{{ asset('img/icon_star_2.png') }}" title="{{ 'element.favorite.add'|trans({}, 'elements') }}" alt="{{ 'element.favorite.add'|trans({}, 'elements') }}" />
97
+            <a class="mustbeconnected" href="#" >
98
+              <img src="{{ asset('img/icon_star_2.png') }}" title="{{ 'element.favorite.add'|trans({}, 'elements') }}" alt="{{ 'element.favorite.add'|trans({}, 'elements') }}" />
87 99
             </a>
88 100
           {% endif %}
89 101
         </li>
@@ -149,68 +161,96 @@
149 161
           </li>
150 162
         {% endif %}
151 163
         
152
-        {% if app.user.id != element.owner.id %}
153
-      
154
-          {% if display_edit_actions %}
155
-            <li class="element_propose_tags">
156
-              <a title="{{ 'element.proposition_tags.link_title'|trans({}, 'userui') }}" 
157
-                class="element_propose_tags" 
158
-                href="{{ path('ajax_element_propose_tags_open', {'element_id' : element.id}) }}">
159
-                <img src="{{ asset('bundles/muzichcore/img/1333484018_rss-tag.png') }}" alt="tags_proposition" />
160
-              </a>
161
-            </li>
162
-
163
-            <li class="element_reshare">
164
-              <a title="{{ 'element.reshare.link_title'|trans({}, 'userui') }}" 
165
-                class="element_reshare" 
166
-                href="{{ path('ajax_reshare_element', {'element_id':element.id, 'token':app.user.getPersonalHash('reshare_'~element.id)}) }}">
167
-                <img src="{{ asset('/img/icon_reload.png') }}" alt="re" />
168
-              </a>
169
-            </li>
170
-            
171
-            <li class="element_report">
172
-              <a title="{{ 'element.report.link_title'|trans({}, 'userui') }}" 
173
-                class="element_report" 
174
-                href="{{ path('ajax_report_element', {'element_id':element.id, 'token':app.user.getPersonalHash(element.id)}) }}">
175
-                <img src="{{ asset('/img/icon_alert.png') }}" alt="report" />
176
-              </a>
177
-            </li>
178
-
164
+        {% if app.user %}
165
+          {% if app.user.id != element.owner.id %}
166
+        
167
+            {% if display_edit_actions %}
168
+              <li class="element_propose_tags">
169
+                <a title="{{ 'element.proposition_tags.link_title'|trans({}, 'userui') }}" 
170
+                  class="element_propose_tags" 
171
+                  href="{{ path('ajax_element_propose_tags_open', {'element_id' : element.id}) }}">
172
+                  <img src="{{ asset('bundles/muzichcore/img/1333484018_rss-tag.png') }}" alt="tags_proposition" />
173
+                </a>
174
+              </li>
175
+  
176
+              <li class="element_reshare">
177
+                <a title="{{ 'element.reshare.link_title'|trans({}, 'userui') }}" 
178
+                  class="element_reshare" 
179
+                  href="{{ path('ajax_reshare_element', {'element_id':element.id, 'token':app.user.getPersonalHash('reshare_'~element.id)}) }}">
180
+                  <img src="{{ asset('/img/icon_reload.png') }}" alt="re" />
181
+                </a>
182
+              </li>
183
+              
184
+              <li class="element_report">
185
+                <a title="{{ 'element.report.link_title'|trans({}, 'userui') }}" 
186
+                  class="element_report" 
187
+                  href="{{ path('ajax_report_element', {'element_id':element.id, 'token':app.user.getPersonalHash(element.id)}) }}">
188
+                  <img src="{{ asset('/img/icon_alert.png') }}" alt="report" />
189
+                </a>
190
+              </li>
191
+  
192
+            {% endif %}
193
+  
179 194
           {% endif %}
180 195
 
181
-        {% endif %}
182
-
183
-        {% if app.user.id == element.owner.id %}
184
-
185
-          {% if display_edit_actions %}
186
-
187
-            {% if element.hasTagProposition %}
188
-              <li class="element_view_propositions_link">
189
-                <a title="{{ 'element.view_propositions.link'|trans({}, 'elements') }}" class="element_view_propositions_link" 
190
-                  href="{{ path('ajax_element_proposed_tags_view', {'element_id' : element.id})  }}"
196
+          {% if app.user.id == element.owner.id %}
197
+  
198
+            {% if display_edit_actions %}
199
+  
200
+              {% if element.hasTagProposition %}
201
+                <li class="element_view_propositions_link">
202
+                  <a title="{{ 'element.view_propositions.link'|trans({}, 'elements') }}" class="element_view_propositions_link" 
203
+                    href="{{ path('ajax_element_proposed_tags_view', {'element_id' : element.id})  }}"
204
+                  >
205
+                    <img src="{{ asset('bundles/muzichcore/img/1333493527_tag_add.png') }}" alt="tags proposition" />
206
+                  </a>
207
+                </li>
208
+              {% endif %}
209
+  
210
+              <li class="element_edit_link">
211
+                <a title="{{ 'element.edit.link'|trans({}, 'elements') }}" class="element_edit_link" 
212
+                  href="{{ path('element_edit', {'element_id' : element.id})  }}"
191 213
                 >
192
-                  <img src="{{ asset('bundles/muzichcore/img/1333493527_tag_add.png') }}" alt="tags proposition" />
214
+                  <img src="{{ asset('/img/icon_pen.png') }}" alt="edit" />
215
+                </a>
216
+              </li>
217
+  
218
+              <li class="element_remove_link">
219
+                <a title="{{ 'element.remove.link'|trans({}, 'elements') }}" class="element_remove_link" 
220
+                  href="{{ path('element_remove', {'element_id' : element.id, 'token':app.user.getPersonalHash(element.id)})  }}"
221
+                >
222
+                  <img src="{{ asset('/img/icon_close_2.png') }}" alt="delete" />
193 223
                 </a>
194 224
               </li>
195 225
             {% endif %}
196
-
197
-            <li class="element_edit_link">
198
-              <a title="{{ 'element.edit.link'|trans({}, 'elements') }}" class="element_edit_link" 
199
-                href="{{ path('element_edit', {'element_id' : element.id})  }}"
200
-              >
201
-                <img src="{{ asset('/img/icon_pen.png') }}" alt="edit" />
202
-              </a>
203
-            </li>
204
-
205
-            <li class="element_remove_link">
206
-              <a title="{{ 'element.remove.link'|trans({}, 'elements') }}" class="element_remove_link" 
207
-                href="{{ path('element_remove', {'element_id' : element.id, 'token':app.user.getPersonalHash(element.id)})  }}"
208
-              >
209
-                <img src="{{ asset('/img/icon_close_2.png') }}" alt="delete" />
210
-              </a>
211
-            </li>
226
+  
212 227
           {% endif %}
228
+        {% else %}
229
+          
230
+          <li class="element_propose_tags">
231
+            <a title="{{ 'element.proposition_tags.link_title'|trans({}, 'userui') }}" 
232
+              class="mustbeconnected" 
233
+              href="#">
234
+              <img src="{{ asset('bundles/muzichcore/img/1333484018_rss-tag.png') }}" alt="tags_proposition" />
235
+            </a>
236
+          </li>
213 237
 
238
+          <li class="element_reshare">
239
+            <a title="{{ 'element.reshare.link_title'|trans({}, 'userui') }}" 
240
+              class="mustbeconnected" 
241
+              href="#">
242
+              <img src="{{ asset('/img/icon_reload.png') }}" alt="re" />
243
+            </a>
244
+          </li>
245
+          
246
+          <li class="element_report">
247
+            <a title="{{ 'element.report.link_title'|trans({}, 'userui') }}" 
248
+              class="mustbeconnected" 
249
+              href="#">
250
+              <img src="{{ asset('/img/icon_alert.png') }}" alt="report" />
251
+            </a>
252
+          </li>
253
+          
214 254
         {% endif %}
215 255
         
216 256
         {% if his_group %}
@@ -275,22 +315,33 @@
275 315
         {% for tag in element.tags %} 
276 316
           <li class="element_tag">
277 317
             <a id="element_tag_{{ tag.id }}" href="#" 
278
-              class="element_tag button {% if app.user.haveTagsFavorite(tag.id) %}element_tag_large_for_fav_still{% endif %}"
318
+              class="element_tag button {% if app.user %}{% if app.user.haveTagsFavorite(tag.id) %}element_tag_large_for_fav_still{% endif %}{% endif %}"
279 319
             >
280 320
               {{ tag.name }}
281 321
             </a>
282
-            {% if app.user.haveTagsFavorite(tag.id) %}
283
-              <img class="tag_to_favorites" src="{{ asset('/img/icon_heart.png') }}" 
284
-                alt="add-to-favorites"
285
-                title="{{ 'element.tag.isfav.title'|trans({'%tagname%':tag.name}, 'elements') }}"
286
-              />
322
+            {% if app.user %}
323
+              {% if app.user.haveTagsFavorite(tag.id) %}
324
+                <img class="tag_to_favorites" src="{{ asset('/img/icon_heart.png') }}" 
325
+                  alt="add-to-favorites"
326
+                  title="{{ 'element.tag.isfav.title'|trans({'%tagname%':tag.name}, 'elements') }}"
327
+                />
328
+              {% else %}
329
+                <a 
330
+                  href="{{ path('ajax_tag_add_to_favorites', {
331
+                    'tag_id' : tag.id,
332
+                    'token'  : app.user.getPersonalHash(tag.id)
333
+                  }) }}" 
334
+                  class="tag_to_favorites" 
335
+                  style="display: none;"
336
+                  title="{{ 'element.tag.addtofav.title'|trans({}, 'elements') }}"   
337
+                >
338
+                  <img class="tag_add_to_favorites"  src="{{ asset('/img/icon_heart.png') }}" alt="add-to-favorites"/>
339
+                </a>
340
+              {% endif %}
287 341
             {% else %}
288 342
               <a 
289
-                href="{{ path('ajax_tag_add_to_favorites', {
290
-                  'tag_id' : tag.id,
291
-                  'token'  : app.user.getPersonalHash(tag.id)
292
-                }) }}" 
293
-                class="tag_to_favorites" 
343
+                href="#" 
344
+                class="tag_to_favorites mustbeconnected" 
294 345
                 style="display: none;"
295 346
                 title="{{ 'element.tag.addtofav.title'|trans({}, 'elements') }}"   
296 347
               >
@@ -325,10 +376,16 @@
325 376
             </a>
326 377
           {%endif %}
327 378
         {% endautoescape %}
328
-
329
-        <a href="#add_comment_{{ element.id }}" class="add_comment">
330
-          {{ 'element.comments.add'|trans({}, 'elements') }}
331
-        </a>
379
+        
380
+        {% if app.user %}
381
+          <a href="#add_comment_{{ element.id }}" class="add_comment">
382
+            {{ 'element.comments.add'|trans({}, 'elements') }}
383
+          </a>
384
+        {% else %}
385
+          <a href="#" class="mustbeconnected add_comment_disabled">
386
+            {{ 'element.comments.add'|trans({}, 'elements') }}
387
+          </a>
388
+        {% endif %}
332 389
       
333 390
       {% endif %}
334 391
       
@@ -366,21 +423,23 @@
366 423
     <div class="comments_loader">
367 424
       <img class="comments_loader" style="display: none;" src="{{ asset('/bundles/muzichcore/img/ajax-loader.gif') }}" alt="loading"/>
368 425
     </div>
369
-      
370
-    <form 
371
-      action="{{ path('ajax_add_comment', {'element_id':element.id, 'token':app.user.getPersonalHash(element.id)}) }}" 
372
-      method="post" 
373
-      name="add_comment"
374
-      style="display: none;"
375
-      class="add_comment"
376
-    >
377
-      {% include "MuzichCommentBundle:Comment:form.html.twig" with {
378
-        'submit_value' : 'element.comments.add_submit'|trans({}, 'elements'),
379
-        'cancel_value' : 'element.comments.add_cancel'|trans({}, 'elements'),
380
-        'following'    : element.userFollowComments(app.user.id),
381
-        'own'          : (app.user.id == element.owner.id)
382
-      } %}
383
-    </form>
426
+    
427
+    {% if app.user %}
428
+      <form 
429
+        action="{{ path('ajax_add_comment', {'element_id':element.id, 'token':app.user.getPersonalHash(element.id)}) }}" 
430
+        method="post" 
431
+        name="add_comment"
432
+        style="display: none;"
433
+        class="add_comment"
434
+      >
435
+        {% include "MuzichCommentBundle:Comment:form.html.twig" with {
436
+          'submit_value' : 'element.comments.add_submit'|trans({}, 'elements'),
437
+          'cancel_value' : 'element.comments.add_cancel'|trans({}, 'elements'),
438
+          'following'    : element.userFollowComments(app.user.id),
439
+          'own'          : (app.user.id == element.owner.id)
440
+        } %}
441
+      </form>
442
+    {% endif %}
384 443
       
385 444
     <a href="#add_comment_{{ element.id }}" class="add_comment">
386 445
       {{ 'element.comments.add'|trans({}, 'elements') }}

+ 44 - 16
src/Muzich/CoreBundle/Searcher/ElementSearcherQueryBuilder.php Прегледај датотеку

@@ -143,7 +143,7 @@ class ElementSearcherQueryBuilder
143 143
   
144 144
   private function buildNetwork()
145 145
   {
146
-    if ($this->es->getNetwork() == ElementSearcher::NETWORK_PERSONAL)
146
+    if ($this->es->getNetwork() == ElementSearcher::NETWORK_PERSONAL && $this->user_id)
147 147
     {
148 148
       $this->query_ids
149 149
         ->join('e.owner', 'o')
@@ -222,15 +222,18 @@ class ElementSearcherQueryBuilder
222 222
       // On a besoin de récupérer la liste des element_id qui ont les tags
223 223
       // demandés.
224 224
       $tag_ids = '';
225
-      foreach ($tags as $tag_id => $tag_name)
225
+      if (count($tags))
226 226
       {
227
-        if ($tag_ids === '')
228
-        {
229
-          $tag_ids .= (int)$tag_id;
230
-        }
231
-        else
227
+        foreach ($tags as $tag_id => $tag_name)
232 228
         {
233
-          $tag_ids .= ','.(int)$tag_id;
229
+          if ($tag_ids === '')
230
+          {
231
+            $tag_ids .= (int)$tag_id;
232
+          }
233
+          else
234
+          {
235
+            $tag_ids .= ','.(int)$tag_id;
236
+          }
234 237
         }
235 238
       }
236 239
       
@@ -383,21 +386,46 @@ class ElementSearcherQueryBuilder
383 386
     }
384 387
     
385 388
     // On prépare des paramètres de la requete d'éléments
386
-    $this->parameters_elements['uidt'] = '%"'. $this->user_id.'"%';
387
-    $this->parameters_elements['uid']  =  $this->user_id;
388 389
     $this->parameters_elements['ids']  = $element_ids;
389 390
     
390 391
     // On prépare la requete des elements
391
-    $this->query_elements = $this->em->createQueryBuilder()
392
-      ->select('e', 'p', 'po', 't', 'o', 'g', 'fav')
392
+    $this->query_elements = $this->em->createQueryBuilder();
393
+    
394
+    if ($this->user_id)
395
+    {
396
+      $this->query_elements->select('e', 'p', 'po', 't', 'o', 'g', 'fav');
397
+    }
398
+    else{
399
+      $this->query_elements->select('e', 'p', 'po', 't', 'o', 'g');
400
+    }
401
+    
402
+    $this->query_elements
393 403
       ->from('MuzichCoreBundle:Element', 'e')
394 404
       ->leftJoin('e.group', 'g')
395 405
       ->leftJoin('e.parent', 'p')
396 406
       ->leftJoin('p.owner', 'po')
397
-      ->leftJoin('e.tags', 't', Join::WITH, 
398
-        "(t.tomoderate = 'FALSE' OR t.tomoderate IS NULL OR t.privateids LIKE :uidt)")
399
-      ->leftJoin('e.elements_favorites', 'fav', Join::WITH,
400
-        'fav.user = :uid')
407
+    ;
408
+    
409
+    if ($this->user_id)
410
+    {
411
+      $this->parameters_elements['uidt'] = '%"'. $this->user_id.'"%';
412
+      $this->parameters_elements['uid']  =  $this->user_id;
413
+      $this->query_elements
414
+        ->leftJoin('e.tags', 't', Join::WITH, 
415
+          "(t.tomoderate = 'FALSE' OR t.tomoderate IS NULL OR t.privateids LIKE :uidt)")
416
+        ->leftJoin('e.elements_favorites', 'fav', Join::WITH,
417
+          'fav.user = :uid')
418
+      ;
419
+    }
420
+    else
421
+    {
422
+      $this->query_elements
423
+        ->leftJoin('e.tags', 't', Join::WITH, 
424
+          "(t.tomoderate = 'FALSE' OR t.tomoderate IS NULL)")
425
+      ;
426
+    }
427
+    
428
+    $this->query_elements
401 429
       ->join('e.owner', 'o')
402 430
       ->where('e.id IN (:ids)')
403 431
       ->orderBy("e.created", 'DESC')

+ 8 - 2
src/Muzich/CoreBundle/Util/TagLike.php Прегледај датотеку

@@ -167,13 +167,19 @@ class TagLike
167 167
       $params['str'.$i] = '%'.$word.'%';
168 168
     }
169 169
 
170
-    $params['uid'] = '%"'.$user_id.'"%';
170
+    $private_tags_sql = '';
171
+    if ($user_id)
172
+    {
173
+      $params['uid'] = '%"'.$user_id.'"%';
174
+      $private_tags_sql = 'OR t.privateids LIKE :uid';
175
+    }
176
+    
171 177
     $tags_query = $this->entity_manager->createQuery("
172 178
       SELECT t.name, t.slug, t.id FROM MuzichCoreBundle:Tag t
173 179
       $where
174 180
 
175 181
       AND (t.tomoderate = '0' OR t.tomoderate IS NULL
176
-      OR t.privateids LIKE :uid)
182
+      $private_tags_sql)
177 183
 
178 184
       ORDER BY t.name ASC"
179 185
     )

+ 67 - 17
src/Muzich/CoreBundle/lib/Controller.php Прегледај датотеку

@@ -11,6 +11,7 @@ use Symfony\Component\HttpFoundation\Response;
11 11
 use Muzich\CoreBundle\Searcher\GlobalSearcher;
12 12
 use Muzich\CoreBundle\Entity\Element;
13 13
 use Muzich\CoreBundle\Entity\Presubscription;
14
+use Muzich\CoreBundle\Entity\User;
14 15
 
15 16
 class Controller extends BaseController
16 17
 {
@@ -46,6 +47,21 @@ class Controller extends BaseController
46 47
     $this->get("session")->set('user.element_search.params'.$session_id, $params);
47 48
   }
48 49
   
50
+  protected function isVisitor()
51
+  {
52
+    $user = $this->getUser();
53
+    if ($user === 'anon.')
54
+    {
55
+      return true;
56
+    }
57
+    elseif ($user instanceof User)
58
+    {
59
+      return true;
60
+    }
61
+    
62
+    throw new \Exception('Unable to determine user type');
63
+  }
64
+  
49 65
   /**
50 66
    * Retourn l'objet ElementSearcher en cours.
51 67
    * 
@@ -70,11 +86,7 @@ class Controller extends BaseController
70 86
       // Premièrement on récupère les tags favoris de l'utilisateur
71 87
       $this->ElementSearcher = new ElementSearcher();
72 88
       $this->ElementSearcher->init(array(
73
-        'tags' => $this->getDoctrine()->getRepository('MuzichCoreBundle:User')
74
-          ->getTagsFavorites(
75
-            $this->getUserId(),
76
-            $this->container->getParameter('search_default_favorites_tags_count')
77
-          ),
89
+        'tags' => $this->getUserFavoriteTags(),
78 90
         'count' => ($count)?$count:$this->container->getParameter('search_default_count')
79 91
       ));
80 92
 
@@ -97,6 +109,21 @@ class Controller extends BaseController
97 109
     return $this->ElementSearcher;
98 110
   }
99 111
   
112
+  protected function getUserFavoriteTags()
113
+  {
114
+    if (!$this->isVisitor())
115
+    {
116
+      return $this->getDoctrine()->getRepository('MuzichCoreBundle:User')
117
+        ->getTagsFavorites(
118
+          $this->getUserId(),
119
+          $this->container->getParameter('search_default_favorites_tags_count')
120
+        )
121
+      ;
122
+    }
123
+    
124
+    return array();
125
+  }
126
+  
100 127
   protected function getNewElementSearcher()
101 128
   {
102 129
     return $this->getElementSearcher(null, true);
@@ -142,11 +169,19 @@ class Controller extends BaseController
142 169
       // on va le récupérer en base.
143 170
       if ($force_refresh || !self::$user_personal_query)
144 171
       {
145
-        self::$user_personal_query = $this->getDoctrine()->getRepository('MuzichCoreBundle:User')->findOneById(
146
-          $this->container->get('security.context')->getToken()->getUser()->getId(),
147
-          array_key_exists('join', $params) ? $params['join'] : array()
148
-        )->getSingleResult();
149
-        return self::$user_personal_query;
172
+        $user = $this->container->get('security.context')->getToken()->getUser();
173
+        if ($user !== 'anon.')
174
+        {
175
+          self::$user_personal_query = $this->getDoctrine()->getRepository('MuzichCoreBundle:User')->findOneById(
176
+            $this->container->get('security.context')->getToken()->getUser()->getId(),
177
+            array_key_exists('join', $params) ? $params['join'] : array()
178
+          )->getSingleResult();
179
+          return self::$user_personal_query;
180
+        }
181
+        else
182
+        {
183
+          return 'anon.';
184
+        }
150 185
       }
151 186
       return self::$user_personal_query;
152 187
     }
@@ -155,25 +190,40 @@ class Controller extends BaseController
155 190
   /**
156 191
    *  Retourne l'id de l'utilisateur en cours
157 192
    */
158
-  protected function getUserId()
193
+  protected function getUserId($return_null_if_visitor = false)
159 194
   {
195
+    
160 196
     /**
161 197
      * Bug lors des tests: L'user n'est pas 'lié' a celui en base par doctrine.
162 198
      * Docrine le voit si on faire une requete directe.
163 199
      */
164 200
     if ($this->container->getParameter('env') == 'test')
165 201
     {
166
-      $user = $this->getDoctrine()->getRepository('MuzichCoreBundle:User')->findOneById(
167
-        $this->container->get('security.context')->getToken()->getUser()->getId(),
168
-        array()
169
-      )->getSingleResult();
170
-      return $user->getId();
202
+      $user_context = $this->container->get('security.context')->getToken()->getUser();
203
+      
204
+      if ($user_context !== 'anon.')
205
+      {
206
+        $user = $this->getDoctrine()->getRepository('MuzichCoreBundle:User')->findOneById(
207
+          $user_context,
208
+          array()
209
+        )->getSingleResult();
210
+      }
211
+    }
212
+    else
213
+    {
214
+      $user = $this->getUser();
171 215
     }
172 216
     
173
-    if (($user = $this->getUser()) != 'anon.')
217
+    if ($user !== 'anon.')
174 218
     {
175 219
       return $user->getId();
176 220
     }
221
+    
222
+    if ($return_null_if_visitor)
223
+    {
224
+      return null;
225
+    }
226
+    
177 227
     throw new \Exception('User not connected');
178 228
   }
179 229
   

+ 1 - 1
src/Muzich/HomeBundle/Controller/HomeController.php Прегледај датотеку

@@ -25,7 +25,7 @@ class HomeController extends Controller
25 25
     $search_form = $this->getSearchForm($search_object);
26 26
     $add_form = $this->getAddForm();
27 27
     
28
-    $elements = $search_object->getElements($this->getDoctrine(), $this->getUserId());
28
+    $elements = $search_object->getElements($this->getDoctrine(), $this->getUserId(true));
29 29
     //$count_elements = count($elements);
30 30
         
31 31
     return array(

+ 4 - 2
src/Muzich/HomeBundle/Resources/views/Home/index.html.twig Прегледај датотеку

@@ -12,8 +12,10 @@
12 12
     'box_title': 'home.add_element_box.title'|trans({}, 'navigationui')
13 13
   } %}
14 14
 
15
-  {% if app.user.wantSeeHelp('home') %}
16
-    {% include 'MuzichCoreBundle:HelpTour:home.html.twig' %}
15
+  {% if app.user %}
16
+    {% if app.user.wantSeeHelp('home') %}
17
+      {% include 'MuzichCoreBundle:HelpTour:home.html.twig' %}
18
+    {% endif %}
17 19
   {% endif %}
18 20
 
19 21
   {# TODO: Cette partie de javascript ne devra plus exister après la réecriture du code javascript #}

+ 0 - 1
src/Muzich/IndexBundle/Resources/views/Index/index.html.twig Прегледај датотеку

@@ -4,7 +4,6 @@
4 4
 {% block mainbox_classes %}mainbox_margintop mainbox_padding{% endblock %}
5 5
 
6 6
 {% block sidebar_top %}
7
-  {% include 'MuzichIndexBundle:Index:presubscription.html.twig' %}
8 7
 {% endblock %}
9 8
 
10 9
 {% block content %}