Browse Source

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

bastien 13 years ago
parent
commit
f5f86f62e8

+ 1 - 1
src/Muzich/CoreBundle/Form/Tag/TagFavoritesForm.php View File

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

+ 5 - 2
src/Muzich/CoreBundle/Resources/views/Tag/tagFavoritesForm.html.twig View File

2
   
2
   
3
   {{ form_errors(form) }}
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
   <input type="submit" />
12
   <input type="submit" />
10
 </form>
13
 </form>

+ 8 - 2
src/Muzich/CoreBundle/lib/Controller.php View File

11
   
11
   
12
   protected static $user = null;
12
   protected static $user = null;
13
   protected static $user_personal_query = null;
13
   protected static $user_personal_query = null;
14
+  protected static $tags = array();
14
   
15
   
15
   /**
16
   /**
16
    * Authenticate a user with Symfony Security
17
    * Authenticate a user with Symfony Security
135
    * 
136
    * 
136
    * @return array
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 View File

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

+ 32 - 29
src/Muzich/UserBundle/Controller/UserController.php View File

14
 class UserController extends Controller
14
 class UserController extends Controller
15
 {
15
 {
16
   
16
   
17
+  protected $tags_favorites = array();
18
+  
17
   protected function getChangeEmailForm()
19
   protected function getChangeEmailForm()
18
   {
20
   {
19
     $collectionConstraint = new Collection(array(
21
     $collectionConstraint = new Collection(array(
32
   {
34
   {
33
     return $this->createForm(
35
     return $this->createForm(
34
       new TagFavoritesForm(), 
36
       new TagFavoritesForm(), 
35
-      array('tags' => $this->getDoctrine()->getRepository('MuzichCoreBundle:User')
37
+      array('tags' => $this->tags_favorites = $this->getDoctrine()->getRepository('MuzichCoreBundle:User')
36
         ->getTagIdsFavorites($user->getId())
38
         ->getTagIdsFavorites($user->getId())
37
       ),
39
       ),
38
       array('tags' => $this->getTagsArray())
40
       array('tags' => $this->getTagsArray())
52
     $change_email_form = $this->getChangeEmailForm();
54
     $change_email_form = $this->getChangeEmailForm();
53
     
55
     
54
     return array(
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
     }
217
     }
213
     else
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
       return $this->container->get('templating')->renderResponse(
223
       return $this->container->get('templating')->renderResponse(
224
         'MuzichUserBundle:User:account.html.twig',
224
         'MuzichUserBundle:User:account.html.twig',
225
         array(
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
   public function startAction()
247
   public function startAction()
244
   {
248
   {
245
     $user = $this->getUser();
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
     return array(
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
     return $this->container->get('templating')->renderResponse(
411
     return $this->container->get('templating')->renderResponse(
412
       'MuzichUserBundle:User:account.html.twig',
412
       'MuzichUserBundle:User:account.html.twig',
413
       array(
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 View File

18
   <h3>{{ 'my_account.favorite_tags'|trans({}, 'userui') }}</h3>
18
   <h3>{{ 'my_account.favorite_tags'|trans({}, 'userui') }}</h3>
19
   
19
   
20
   {% include "MuzichCoreBundle:Tag:tagFavoritesForm.html.twig" with { 
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
   <h3>{{ 'my_account.change_password'|trans({}, 'userui') }}</h3>
27
   <h3>{{ 'my_account.change_password'|trans({}, 'userui') }}</h3>

+ 4 - 1
src/Muzich/UserBundle/Resources/views/User/start.html.twig View File

13
   <h3>Choisissez vos tags préférés</h3>
13
   <h3>Choisissez vos tags préférés</h3>
14
   
14
   
15
   {% include "MuzichCoreBundle:Tag:tagFavoritesForm.html.twig" with { 
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
   <p>
22
   <p>