Browse Source

Evolution #807: Rendre ou enlever "public" de sa playlist

Bastien Sevajol 11 years ago
parent
commit
3f2a7fdb7f

+ 3 - 6
src/Muzich/CoreBundle/Form/Playlist/PlaylistForm.php View File

14
       'required' => true,
14
       'required' => true,
15
     ));
15
     ));
16
     
16
     
17
-    if (!$options['data']->getId())
18
-    {
19
-      $builder->add('public', 'checkbox', array(
20
-        'required' => false,
21
-      ));
22
-    }
17
+    $builder->add('public', 'checkbox', array(
18
+      'required' => false,
19
+    ));
23
   }
20
   }
24
 
21
 
25
   public function getName()
22
   public function getName()

+ 8 - 15
src/Muzich/CoreBundle/Managers/PlaylistManager.php View File

135
     $playlist_copied = new Playlist();
135
     $playlist_copied = new Playlist();
136
     $playlist_copied->setOwner($user);
136
     $playlist_copied->setOwner($user);
137
     $playlist_copied->setName($playlist->getName());
137
     $playlist_copied->setName($playlist->getName());
138
-    $playlist_copied->setPublic(true);
138
+    $playlist_copied->setPublic(false);
139
     $playlist_copied->setTags($playlist->getTags());
139
     $playlist_copied->setTags($playlist->getTags());
140
     $playlist_copied->setElements($playlist->getElements());
140
     $playlist_copied->setElements($playlist->getElements());
141
     $playlist_copied->setCopied($playlist);
141
     $playlist_copied->setCopied($playlist);
142
     $playlist->addCopy($playlist_copied);
142
     $playlist->addCopy($playlist_copied);
143
-    
144
-    //foreach ($user->getPlaylistsOwneds() as $fuck)
145
-    //{
146
-    //  var_dump($fuck->getName());
147
-    //}
148
-    //
149
     $user->getPlaylistsOwneds()->add($playlist_copied);
143
     $user->getPlaylistsOwneds()->add($playlist_copied);
150
-    //
151
-    //var_dump($playlist_copied->getOwner()->getUsername());
152
-    //
153
-    //foreach ($user->getPlaylistsOwneds() as $fuck)
154
-    //{
155
-    //  var_dump($fuck->getName());
156
-    //}
157
-    //die();
158
     
144
     
159
     $this->entity_manager->persist($playlist_copied);
145
     $this->entity_manager->persist($playlist_copied);
160
     $this->entity_manager->persist($user);
146
     $this->entity_manager->persist($user);
246
     }
232
     }
247
   }
233
   }
248
   
234
   
235
+  public function privatizePlaylist(Playlist $playlist)
236
+  {
237
+    $this->copyPlaylistForPickedUsers($playlist);
238
+    $playlist->setPublic(false);
239
+    $this->entity_manager->persist($playlist);
240
+  }
241
+  
249
 }
242
 }

+ 23 - 2
src/Muzich/CoreBundle/Tests/Controller/PlaylistControllerTest.php View File

403
   
403
   
404
   protected function checkPlaylistOwnedBy($playlist, $user)
404
   protected function checkPlaylistOwnedBy($playlist, $user)
405
   {
405
   {
406
-    $this->assertEquals($playlist->getOwner()->getId(), $user->getId());
406
+    $this->assertEquals($playlist->getOwner()->getUsername(), $user->getUsername());
407
   }
407
   }
408
   
408
   
409
   protected function checkPlaylistNotOwnedBy($playlist, $user)
409
   protected function checkPlaylistNotOwnedBy($playlist, $user)
425
     $this->checkPlaylistOwnedBy($this->playlists['bux_bob_pub'], $this->users['bux']);
425
     $this->checkPlaylistOwnedBy($this->playlists['bux_bob_pub'], $this->users['bux']);
426
   }
426
   }
427
   
427
   
428
+  public function testCopyWhenPickedPlaylistPrivatized()
429
+  {
430
+    $this->init();
431
+    $this->initCopysContextData();
432
+    $this->connectUser('bob', 'toor');
433
+    
434
+    $this->checkPlaylistPickedBy($this->playlists['bob_pub'], $this->users['bux']);
435
+    $this->checkPlaylistNotOwnedBy($this->playlists['bob_pub'], $this->users['bux']);
436
+    
437
+    $this->playlists['bob_pub']->setPublic(false);
438
+    $this->updatePlaylist($this->playlists['bob_pub']);
439
+    $this->playlists['bux_bob_pub'] = $this->findOneBy('Playlist', array(
440
+      'name' => 'A travers l\'espace',
441
+      'owner' => $this->users['bux']->getId()
442
+    ));
443
+    $this->assertTrue(!is_null($this->playlists['bux_bob_pub']));
444
+    $this->assertEquals(false, $this->playlists['bux_bob_pub']->isPublic());
445
+    $this->checkPlaylistOwnedBy($this->playlists['bux_bob_pub'], $this->users['bux']);
446
+  }
447
+  
428
   protected function deletePlaylist($playlist)
448
   protected function deletePlaylist($playlist)
429
   {
449
   {
430
     $this->tests_cases->playlistDelete($playlist->getId());
450
     $this->tests_cases->playlistDelete($playlist->getId());
463
   
483
   
464
   public function testUpdate()
484
   public function testUpdate()
465
   {
485
   {
466
-     $this->init();
486
+    $this->init();
467
     $this->initReadContextData();
487
     $this->initReadContextData();
468
     $this->connectUser('bux', 'toor');
488
     $this->connectUser('bux', 'toor');
469
     $this->goToPage($this->generateUrl('playlist', array('user_slug' => $this->users['bux']->getSlug(), 'playlist_id' => $this->playlists['bux_1_pub']->getId())));
489
     $this->goToPage($this->generateUrl('playlist', array('user_slug' => $this->users['bux']->getSlug(), 'playlist_id' => $this->playlists['bux_1_pub']->getId())));
487
     
507
     
488
     $form = $this->selectForm('form.playlist_edit input[type="submit"]');
508
     $form = $this->selectForm('form.playlist_edit input[type="submit"]');
489
     $form['playlist[name]'] = $playlist->getName();
509
     $form['playlist[name]'] = $playlist->getName();
510
+    $form['playlist[public]'] = $playlist->isPublic();
490
     $this->submit($form);
511
     $this->submit($form);
491
   }
512
   }
492
   
513
   

+ 6 - 0
src/Muzich/PlaylistBundle/Controller/EditController.php View File

174
       throw $this->createNotFoundException();
174
       throw $this->createNotFoundException();
175
     
175
     
176
     $playlist_name = $playlist->getName();
176
     $playlist_name = $playlist->getName();
177
+    $playlist_public = $playlist->isPublic();
177
     $form = $this->getPlaylistForm($playlist);
178
     $form = $this->getPlaylistForm($playlist);
178
     $form->bind($request);
179
     $form->bind($request);
179
     if ($form->isValid())
180
     if ($form->isValid())
180
     {
181
     {
182
+      if ($playlist_public && !$playlist->isPublic())
183
+      {
184
+        $this->getPlaylistManager()->privatizePlaylist($playlist);
185
+      }
186
+      
181
       $this->persist($form->getData());
187
       $this->persist($form->getData());
182
       $this->flush();
188
       $this->flush();
183
       
189
       

+ 3 - 5
src/Muzich/PlaylistBundle/Resources/views/Show/form.html.twig View File

5
 {{ form_errors(form) }}
5
 {{ form_errors(form) }}
6
 {{ form_errors(form.name) }}
6
 {{ form_errors(form.name) }}
7
 
7
 
8
-{% if display_public_widget %}
9
-  {{ form_errors(form.public) }}
10
-  {{ form_widget(form.public) }}
11
-  <label for="playlist_public">{{ 'playlist.public_label'|trans({}, 'elements') }}</label>
12
-{% endif %}
8
+{{ form_errors(form.public) }}
9
+{{ form_widget(form.public) }}
10
+<label for="playlist_public">{{ 'playlist.public_label'|trans({}, 'elements') }}</label>
13
 
11
 
14
 <div class="field">
12
 <div class="field">
15
   {{ form_widget(form.name, {'attr':{'class':'niceinput'}}) }}
13
   {{ form_widget(form.name, {'attr':{'class':'niceinput'}}) }}