Kaynağa Gözat

Mise ne place de la saisie dynamique des tags sur 'mon compte 'et la page 'start'

bastien 12 yıl önce
ebeveyn
işleme
f5f86f62e8

+ 1 - 1
src/Muzich/CoreBundle/Form/Tag/TagFavoritesForm.php Dosyayı Görüntüle

@@ -8,7 +8,7 @@ use Symfony\Component\Form\FormBuilder;
8 8
 class TagFavoritesForm extends AbstractType
9 9
 {
10 10
   public function buildForm(FormBuilder $builder, array $options)
11
-  {        
11
+  {    
12 12
     $builder->add('tags', 'choice', array(
13 13
       'choices'           => $options['tags'],
14 14
       'expanded'          => true,

+ 5 - 2
src/Muzich/CoreBundle/Resources/views/Tag/tagFavoritesForm.html.twig Dosyayı Görüntüle

@@ -2,9 +2,12 @@
2 2
   
3 3
   {{ form_errors(form) }}
4 4
 
5
-  {{ form_row(form.tags) }}
5
+  {% include "MuzichCoreBundle:Tag:tagsPrompt.html.twig" with { 
6
+    'form_name'   : form_name,
7
+    'search_tags' : favorite_tags_id
8
+  } %}
6 9
 
7
-  {{ form_rest(form) }}
10
+  {{ form_row(form._token) }}
8 11
 
9 12
   <input type="submit" />
10 13
 </form>

+ 8 - 2
src/Muzich/CoreBundle/lib/Controller.php Dosyayı Görüntüle

@@ -11,6 +11,7 @@ class Controller extends BaseController
11 11
   
12 12
   protected static $user = null;
13 13
   protected static $user_personal_query = null;
14
+  protected static $tags = array();
14 15
   
15 16
   /**
16 17
    * Authenticate a user with Symfony Security
@@ -135,9 +136,14 @@ class Controller extends BaseController
135 136
    * 
136 137
    * @return array
137 138
    */
138
-  protected function getTagsArray()
139
+  protected function getTagsArray($force_refresh = false)
139 140
   {
140
-    return $this->getDoctrine()->getRepository('MuzichCoreBundle:Tag')->getTagsArray();
141
+    if (!count(self::$tags) || $force_refresh)
142
+    {
143
+      return $this->getDoctrine()->getRepository('MuzichCoreBundle:Tag')->getTagsArray();
144
+    }
145
+    
146
+    return self::$tags;
141 147
   }
142 148
   
143 149
   /**

+ 1 - 1
src/Muzich/HomeBundle/Resources/views/Home/index.html.twig Dosyayı Görüntüle

@@ -27,7 +27,7 @@
27 27
 
28 28
   {% include "MuzichCoreBundle:SearchElement:form.html.twig" with { 
29 29
     'form_name'      : search_form_name,
30
-    'search_tags' : search_tags_id
30
+    'search_tags'    : search_tags_id
31 31
   } %}
32 32
 
33 33
   {% include "MuzichCoreBundle:SearchElement:default.html.twig" %}

+ 32 - 29
src/Muzich/UserBundle/Controller/UserController.php Dosyayı Görüntüle

@@ -14,6 +14,8 @@ use Symfony\Component\Validator\Constraints\Collection;
14 14
 class UserController extends Controller
15 15
 {
16 16
   
17
+  protected $tags_favorites = array();
18
+  
17 19
   protected function getChangeEmailForm()
18 20
   {
19 21
     $collectionConstraint = new Collection(array(
@@ -32,7 +34,7 @@ class UserController extends Controller
32 34
   {
33 35
     return $this->createForm(
34 36
       new TagFavoritesForm(), 
35
-      array('tags' => $this->getDoctrine()->getRepository('MuzichCoreBundle:User')
37
+      array('tags' => $this->tags_favorites = $this->getDoctrine()->getRepository('MuzichCoreBundle:User')
36 38
         ->getTagIdsFavorites($user->getId())
37 39
       ),
38 40
       array('tags' => $this->getTagsArray())
@@ -52,10 +54,13 @@ class UserController extends Controller
52 54
     $change_email_form = $this->getChangeEmailForm();
53 55
     
54 56
     return array(
55
-      'user'                => $user,
56
-      'form_password'       => $form_password->createView(),
57
-      'form_tags_favorites' => $form_tags_favorites->createView(),
58
-      'change_email_form'   => $change_email_form->createView()
57
+      'tags'                     => $this->getTagsArray(),
58
+      'user'                     => $user,
59
+      'form_password'            => $form_password->createView(),
60
+      'form_tags_favorites'      => $form_tags_favorites->createView(),
61
+      'form_tags_favorites_name' => $form_tags_favorites->getName(),
62
+      'favorite_tags_id'         => $this->tags_favorites,
63
+      'change_email_form'        => $change_email_form->createView()
59 64
     );
60 65
   }
61 66
   
@@ -212,21 +217,20 @@ class UserController extends Controller
212 217
     }
213 218
     else
214 219
     {
215
-      $form_tags_favorites = $this->createForm(
216
-        new TagFavoritesForm(), 
217
-        array('tags' => $this->getDoctrine()->getRepository('MuzichCoreBundle:User')
218
-          ->getTagIdsFavorites($user->getId())
219
-        ),
220
-        array('tags' => $this->getTagsArray())
221
-      );
220
+      $form_tags_favorites = $this->getTagsFavoritesForm($user);
221
+      $change_email_form = $this->getChangeEmailForm();
222 222
       
223 223
       return $this->container->get('templating')->renderResponse(
224 224
         'MuzichUserBundle:User:account.html.twig',
225 225
         array(
226
-          'form_password'       => $form->createView(),
227
-          'errors_pers'         => $errors,
228
-          'user'                => $user,
229
-          'form_tags_favorites' => $form_tags_favorites->createView()
226
+          'tags'                     => $this->getTagsArray(),
227
+          'form_password'            => $form->createView(),
228
+          'errors_pers'              => $errors,
229
+          'user'                     => $user,
230
+          'form_tags_favorites'      => $form_tags_favorites->createView(),
231
+          'form_tags_favorites_name' => $form_tags_favorites->getName(),
232
+          'favorite_tags_id'         => $this->tags_favorites,
233
+          'change_email_form'        => $change_email_form->createView()
230 234
         )
231 235
       );
232 236
     }
@@ -243,17 +247,13 @@ class UserController extends Controller
243 247
   public function startAction()
244 248
   {
245 249
     $user = $this->getUser();
246
-    
247
-    $form = $this->createForm(
248
-      new TagFavoritesForm(), 
249
-      array('tags' => $this->getDoctrine()->getRepository('MuzichCoreBundle:User')
250
-        ->getTagIdsFavorites($user->getId())
251
-      ),
252
-      array('tags' => $this->getTagsArray())
253
-    );
250
+    $form_tags_favorites = $this->getTagsFavoritesForm($user);
254 251
     
255 252
     return array(
256
-      'form' => $form->createView()
253
+      'tags'                     => $this->getTagsArray(),
254
+      'favorite_tags_id'         => $this->tags_favorites,
255
+      'form_tags_favorites'      => $form_tags_favorites->createView(),
256
+      'form_tags_favorites_name' => $form_tags_favorites->getName(),
257 257
     );
258 258
   }
259 259
   
@@ -411,10 +411,13 @@ class UserController extends Controller
411 411
     return $this->container->get('templating')->renderResponse(
412 412
       'MuzichUserBundle:User:account.html.twig',
413 413
       array(
414
-        'user'                => $user,
415
-        'form_password'       => $form_password->createView(),
416
-        'form_tags_favorites' => $form_tags_favorites->createView(),
417
-        'change_email_form'   => $change_email_form->createView()
414
+        'tags'                     => $this->getTagsArray(),
415
+        'user'                     => $user,
416
+        'form_password'            => $form_password->createView(),
417
+        'form_tags_favorites'      => $form_tags_favorites->createView(),
418
+        'form_tags_favorites_name' => $form_tags_favorites->getName(),
419
+        'favorite_tags_id'         => $this->tags_favorites,
420
+        'change_email_form'        => $change_email_form->createView()
418 421
       )
419 422
     );
420 423
   }

+ 4 - 2
src/Muzich/UserBundle/Resources/views/User/account.html.twig Dosyayı Görüntüle

@@ -18,8 +18,10 @@
18 18
   <h3>{{ 'my_account.favorite_tags'|trans({}, 'userui') }}</h3>
19 19
   
20 20
   {% include "MuzichCoreBundle:Tag:tagFavoritesForm.html.twig" with { 
21
-    'form': form_tags_favorites,
22
-    'redirect' : 'account'
21
+    'form'             : form_tags_favorites,
22
+    'redirect'         : 'account',
23
+    'form_name'        : form_tags_favorites_name,
24
+    'favorite_tags_id' : favorite_tags_id
23 25
   } %}
24 26
   
25 27
   <h3>{{ 'my_account.change_password'|trans({}, 'userui') }}</h3>

+ 4 - 1
src/Muzich/UserBundle/Resources/views/User/start.html.twig Dosyayı Görüntüle

@@ -13,7 +13,10 @@
13 13
   <h3>Choisissez vos tags préférés</h3>
14 14
   
15 15
   {% include "MuzichCoreBundle:Tag:tagFavoritesForm.html.twig" with { 
16
-    'redirect' : 'home'
16
+    'form'             : form_tags_favorites,
17
+    'redirect'         : 'home',
18
+    'form_name'        : form_tags_favorites_name,
19
+    'favorite_tags_id' : favorite_tags_id
17 20
   } %}
18 21
   
19 22
   <p>