Browse Source

Evolution #127: Refact: isConnected

bastien 12 years ago
parent
commit
a29d6314d4

+ 6 - 33
src/Muzich/AdminBundle/Controller/ModerateController.php View File

@@ -45,18 +45,9 @@ class ModerateController extends Controller
45 45
   
46 46
   public function tagAcceptAction($tag_id)
47 47
   {
48
-    if ($this->getUser() == 'anon.')
48
+    if (($response = $this->mustBeConnected()))
49 49
     {
50
-      if ($this->getRequest()->isXmlHttpRequest())
51
-      {
52
-        return $this->jsonResponse(array(
53
-          'status' => 'mustbeconnected'
54
-        ));
55
-      }
56
-      else
57
-      {
58
-        return $this->redirect($this->generateUrl('index'));
59
-      }
50
+      return $response;
60 51
     }
61 52
     
62 53
     $tagManager = new TagManager();
@@ -75,18 +66,9 @@ class ModerateController extends Controller
75 66
   
76 67
   public function tagRefuseAction($tag_id)
77 68
   {
78
-    if ($this->getUser() == 'anon.')
69
+    if (($response = $this->mustBeConnected()))
79 70
     {
80
-      if ($this->getRequest()->isXmlHttpRequest())
81
-      {
82
-        return $this->jsonResponse(array(
83
-          'status' => 'mustbeconnected'
84
-        ));
85
-      }
86
-      else
87
-      {
88
-        return $this->redirect($this->generateUrl('index'));
89
-      }
71
+      return $response;
90 72
     }
91 73
     
92 74
     $tagManager = new TagManager();
@@ -113,18 +95,9 @@ class ModerateController extends Controller
113 95
    */
114 96
   public function tagReplaceAction($tag_id, $tag_new_id)
115 97
   {
116
-    if ($this->getUser() == 'anon.')
98
+    if (($response = $this->mustBeConnected()))
117 99
     {
118
-      if ($this->getRequest()->isXmlHttpRequest())
119
-      {
120
-        return $this->jsonResponse(array(
121
-          'status' => 'mustbeconnected'
122
-        ));
123
-      }
124
-      else
125
-      {
126
-        return $this->redirect($this->generateUrl('index'));
127
-      }
100
+      return $response;
128 101
     }
129 102
     
130 103
     $tag_array = json_decode($tag_new_id);

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

@@ -145,21 +145,9 @@ class CoreController extends Controller
145 145
    */
146 146
   public function elementAddAction($group_slug)
147 147
   {   
148
-    
149
-    //die(var_dump($this->getRequest()->getParameter()));
150
-    
151
-    if ($this->getUser() == 'anon.')
148
+    if (($response = $this->mustBeConnected()))
152 149
     {
153
-      if ($this->getRequest()->isXmlHttpRequest())
154
-      {
155
-        return $this->jsonResponse(array(
156
-          'status' => 'mustbeconnected'
157
-        ));
158
-      }
159
-      else
160
-      {
161
-        return $this->redirect($this->generateUrl('index'));
162
-      }
150
+      return $response;
163 151
     }
164 152
     
165 153
     if ($this->getRequest()->getMethod() != 'POST')
@@ -355,18 +343,9 @@ class CoreController extends Controller
355 343
   
356 344
   public function getFavoriteTagsAction()
357 345
   {
358
-    if ($this->getUser() == 'anon.')
346
+    if (($response = $this->mustBeConnected()))
359 347
     {
360
-      if ($this->getRequest()->isXmlHttpRequest())
361
-      {
362
-        return $this->jsonResponse(array(
363
-          'status' => 'mustbeconnected'
364
-        ));
365
-      }
366
-      else
367
-      {
368
-        return $this->redirect($this->generateUrl('index'));
369
-      }
348
+      return $response;
370 349
     }
371 350
     
372 351
     // On construit l'element searcher avec les tags favoris
@@ -383,18 +362,9 @@ class CoreController extends Controller
383 362
    */
384 363
   public function addTagAction($name, $arguments = null)
385 364
   {
386
-    if ($this->getUser() == 'anon.')
365
+    if (($response = $this->mustBeConnected()))
387 366
     {
388
-      if ($this->getRequest()->isXmlHttpRequest())
389
-      {
390
-        return $this->jsonResponse(array(
391
-          'status' => 'mustbeconnected'
392
-        ));
393
-      }
394
-      else
395
-      {
396
-        return $this->redirect($this->generateUrl('index'));
397
-      }
367
+      return $response;
398 368
     }
399 369
     
400 370
     $tagManager = new TagManager();

+ 10 - 55
src/Muzich/CoreBundle/Controller/ElementController.php View File

@@ -34,18 +34,9 @@ class ElementController extends Controller
34 34
    */
35 35
   public function editAction($element_id)
36 36
   {    
37
-    if ($this->getUser() == 'anon.')
37
+    if (($response = $this->mustBeConnected()))
38 38
     {
39
-      if ($this->getRequest()->isXmlHttpRequest())
40
-      {
41
-        return $this->jsonResponse(array(
42
-          'status' => 'mustbeconnected'
43
-        ));
44
-      }
45
-      else
46
-      {
47
-        return $this->redirect($this->generateUrl('index'));
48
-      }
39
+      return $response;
49 40
     }
50 41
     
51 42
     $element = $this->checkExistingAndOwned($element_id);
@@ -91,18 +82,9 @@ class ElementController extends Controller
91 82
    */
92 83
   public function updateAction($element_id)
93 84
   {
94
-    if ($this->getUser() == 'anon.')
85
+    if (($response = $this->mustBeConnected()))
95 86
     {
96
-      if ($this->getRequest()->isXmlHttpRequest())
97
-      {
98
-        return $this->jsonResponse(array(
99
-          'status' => 'mustbeconnected'
100
-        ));
101
-      }
102
-      else
103
-      {
104
-        return $this->redirect($this->generateUrl('index'));
105
-      }
87
+      return $response;
106 88
     }
107 89
     
108 90
     /**
@@ -186,18 +168,9 @@ class ElementController extends Controller
186 168
   
187 169
   public function removeAction($element_id)
188 170
   {
189
-    if ($this->getUser() == 'anon.')
171
+    if (($response = $this->mustBeConnected()))
190 172
     {
191
-      if ($this->getRequest()->isXmlHttpRequest())
192
-      {
193
-        return $this->jsonResponse(array(
194
-          'status' => 'mustbeconnected'
195
-        ));
196
-      }
197
-      else
198
-      {
199
-        return $this->redirect($this->generateUrl('index'));
200
-      }
173
+      return $response;
201 174
     }
202 175
     
203 176
     try {
@@ -285,18 +258,9 @@ class ElementController extends Controller
285 258
       return $this->redirect($this->generateUrl('index'));
286 259
     }
287 260
     
288
-    if ($this->getUser() == 'anon.')
261
+    if (($response = $this->mustBeConnected()))
289 262
     {
290
-      if ($this->getRequest()->isXmlHttpRequest())
291
-      {
292
-        return $this->jsonResponse(array(
293
-          'status' => 'mustbeconnected'
294
-        ));
295
-      }
296
-      else
297
-      {
298
-        return $this->redirect($this->generateUrl('index'));
299
-      }
263
+      return $response;
300 264
     }
301 265
     
302 266
     $es = $this->getElementSearcher();
@@ -331,18 +295,9 @@ class ElementController extends Controller
331 295
       return $this->redirect($this->generateUrl('index'));
332 296
     }
333 297
     
334
-    if ($this->getUser() == 'anon.')
298
+    if (($response = $this->mustBeConnected()))
335 299
     {
336
-      if ($this->getRequest()->isXmlHttpRequest())
337
-      {
338
-        return $this->jsonResponse(array(
339
-          'status' => 'mustbeconnected'
340
-        ));
341
-      }
342
-      else
343
-      {
344
-        return $this->redirect($this->generateUrl('index'));
345
-      }
300
+      return $response;
346 301
     }
347 302
     
348 303
     $es = $this->getElementSearcher();

+ 4 - 22
src/Muzich/CoreBundle/Controller/SearchController.php View File

@@ -43,18 +43,9 @@ class SearchController extends Controller
43 43
    */
44 44
   public function searchElementsAction($id_limit = null, $invertcolors = false)
45 45
   {
46
-    if ($this->getUser() == 'anon.')
46
+    if (($response = $this->mustBeConnected()))
47 47
     {
48
-      if ($this->getRequest()->isXmlHttpRequest())
49
-      {
50
-        return $this->jsonResponse(array(
51
-          'status' => 'mustbeconnected'
52
-        ));
53
-      }
54
-      else
55
-      {
56
-        return $this->redirect($this->generateUrl('index'));
57
-      }
48
+      return $response;
58 49
     }
59 50
     
60 51
     $request = $this->getRequest();
@@ -178,18 +169,9 @@ class SearchController extends Controller
178 169
    */
179 170
   public function searchTagAction($string_search, $timestamp)
180 171
   {
181
-    if ($this->getUser() == 'anon.')
172
+    if (($response = $this->mustBeConnected()))
182 173
     {
183
-      if ($this->getRequest()->isXmlHttpRequest())
184
-      {
185
-        return $this->jsonResponse(array(
186
-          'status' => 'mustbeconnected'
187
-        ));
188
-      }
189
-      else
190
-      {
191
-        return $this->redirect($this->generateUrl('index'));
192
-      }
174
+      return $response;
193 175
     }
194 176
     
195 177
     if ($this->getRequest()->isXmlHttpRequest())

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

@@ -312,4 +312,25 @@ class Controller extends BaseController
312 312
     return $this->get('translator')->trans($string, $params, $package);
313 313
   }
314 314
   
315
+  /**
316
+   *
317
+   * @return Response
318
+   */
319
+  protected function mustBeConnected()
320
+  {
321
+    if ($this->getUser() == 'anon.')
322
+    {
323
+      if ($this->getRequest()->isXmlHttpRequest())
324
+      {
325
+        return $this->jsonResponse(array(
326
+          'status' => 'mustbeconnected'
327
+        ));
328
+      }
329
+      else
330
+      {
331
+        return $this->redirect($this->generateUrl('index'));
332
+      }
333
+    }
334
+  }
335
+  
315 336
 }

+ 6 - 33
src/Muzich/FavoriteBundle/Controller/FavoriteController.php View File

@@ -22,18 +22,9 @@ class FavoriteController extends Controller
22 22
    */
23 23
   public function addAction($id, $token)
24 24
   {
25
-    if ($this->getUser() == 'anon.')
25
+    if (($response = $this->mustBeConnected()))
26 26
     {
27
-      if ($this->getRequest()->isXmlHttpRequest())
28
-      {
29
-        return $this->jsonResponse(array(
30
-          'status' => 'mustbeconnected'
31
-        ));
32
-      }
33
-      else
34
-      {
35
-        return $this->redirect($this->generateUrl('index'));
36
-      }
27
+      return $response;
37 28
     }
38 29
     
39 30
     $user = $this->getUser();
@@ -100,18 +91,9 @@ class FavoriteController extends Controller
100 91
    */
101 92
   public function removeAction($id, $token)
102 93
   {
103
-    if ($this->getUser() == 'anon.')
94
+    if (($response = $this->mustBeConnected()))
104 95
     {
105
-      if ($this->getRequest()->isXmlHttpRequest())
106
-      {
107
-        return $this->jsonResponse(array(
108
-          'status' => 'mustbeconnected'
109
-        ));
110
-      }
111
-      else
112
-      {
113
-        return $this->redirect($this->generateUrl('index'));
114
-      }
96
+      return $response;
115 97
     }
116 98
     
117 99
     $user = $this->getUser();
@@ -221,18 +203,9 @@ class FavoriteController extends Controller
221 203
   
222 204
   public function getElementsAction($user_id, $tags_ids_json, $id_limit = null, $invert = false)
223 205
   {
224
-    if ($this->getUser() == 'anon.')
206
+    if (($response = $this->mustBeConnected()))
225 207
     {
226
-      if ($this->getRequest()->isXmlHttpRequest())
227
-      {
228
-        return $this->jsonResponse(array(
229
-          'status' => 'mustbeconnected'
230
-        ));
231
-      }
232
-      else
233
-      {
234
-        return $this->redirect($this->generateUrl('index'));
235
-      }
208
+      return $response;
236 209
     }
237 210
     
238 211
     $tag_ids = json_decode($tags_ids_json);

+ 2 - 11
src/Muzich/HomeBundle/Controller/ShowController.php View File

@@ -97,18 +97,9 @@ class ShowController extends Controller
97 97
   
98 98
   public function getElementsAction($type, $object_id, $tags_ids_json, $id_limit = null, $invert = false)
99 99
   {
100
-    if ($this->getUser() == 'anon.')
100
+    if (($response = $this->mustBeConnected()))
101 101
     {
102
-      if ($this->getRequest()->isXmlHttpRequest())
103
-      {
104
-        return $this->jsonResponse(array(
105
-          'status' => 'mustbeconnected'
106
-        ));
107
-      }
108
-      else
109
-      {
110
-        return $this->redirect($this->generateUrl('index'));
111
-      }
102
+      return $response;
112 103
     }
113 104
     
114 105
     if ($type != 'user' && $type != 'group')